/*
* Copyright (c) 2015-2021 NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/tegra-camera-rtcpu.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/iommu.h>
#include <linux/irqchip/tegra-agic.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/platform/tegra/emc_bwmgr.h>
#include <linux/pm_runtime.h>
#include <linux/sched.h>
#include <linux/seq_buf.h>
#include <linux/slab.h>
#include <linux/tegra-firmwares.h>
#include <linux/tegra-hsp.h>
#include <linux/tegra-ivc-bus.h>
#include <linux/tegra_pm_domains.h>
#include <linux/tegra-rtcpu-monitor.h>
#include <linux/tegra-rtcpu-trace.h>
#include <linux/version.h>
#include <linux/wait.h>
#include <dt-bindings/memory/tegra-swgroup.h>
#include "rtcpu/clk-group.h"
#include "rtcpu/device-group.h"
#include "rtcpu/reset-group.h"
#include "soc/tegra/camrtc-commands.h"
#include "soc/tegra/camrtc-ctrl-commands.h"
#include <linux/tegra-rtcpu-coverage.h>
#ifndef RTCPU_DRIVER_SM5_VERSION
#define RTCPU_DRIVER_SM5_VERSION U32_C(5)
#endif
#if defined(LINUX_VERSION) && (LINUX_VERSION < 409)
#define DISABLE_APE_RUNTIME_PM 1
#else
#define DISABLE_APE_RUNTIME_PM 0
#endif
enum tegra_cam_rtcpu_id {
TEGRA_CAM_RTCPU_SCE,
TEGRA_CAM_RTCPU_APE,
TEGRA_CAM_RTCPU_RCE,
};
#define CAMRTC_NUM_REGS 2
#define CAMRTC_NUM_RESETS 2
#define CAMRTC_NUM_IRQS 1
struct tegra_cam_rtcpu_pdata {
const char *name;
void (*assert_resets)(struct device *);
int (*deassert_resets)(struct device *);
int (*suspend_core)(struct device *);
const char * const *reset_names;
const char * const *reg_names;
const char * const *irq_names;
enum tegra_cam_rtcpu_id id;
};
/* Register specifics */
#define TEGRA_APS_FRSC_SC_CTL_0 0x0
#define TEGRA_APS_FRSC_SC_MODEIN_0 0x14
#define TEGRA_PM_R5_CTRL_0 0x40
#define TEGRA_PM_PWR_STATUS_0 0x20
#define TEGRA_R5R_SC_DISABLE 0x5
#define TEGRA_FN_MODEIN 0x29527
#define TEGRA_PM_FWLOADDONE 0x2
#define TEGRA_PM_WFIPIPESTOPPED 0x200000
#define AMISC_ADSP_STATUS 0x14
#define AMISC_ADSP_L2_IDLE BIT(31)
#define AMISC_ADSP_L2_CLKSTOPPED BIT(30)
static int tegra_sce_cam_suspend_core(struct device *dev);
static void tegra_sce_cam_assert_resets(struct device *dev);
static int tegra_sce_cam_deassert_resets(struct device *dev);
static int tegra_ape_cam_suspend_core(struct device *dev);
static irqreturn_t tegra_camrtc_adsp_wfi_handler(int irq, void *data);
static void tegra_ape_cam_assert_resets(struct device *dev);
static int tegra_ape_cam_deassert_resets(struct device *dev);
static void tegra_rce_cam_assert_resets(struct device *dev);
static int tegra_rce_cam_deassert_resets(struct device *dev);
static const char * const sce_reset_names[] = {
"nvidia,reset-group-1",
"nvidia,reset-group-2",
NULL,
};
static const char * const sce_reg_names[] = {
"sce-pm",
"sce-cfg",
NULL
};
static const struct tegra_cam_rtcpu_pdata sce_pdata = {
.name =
|