1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
10 #include <linux/arm-smccc.h>
13 #include <asm/arch-tegra/pmc.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 #if IS_ENABLED(CONFIG_TEGRA_PMC_SECURE)
18 static bool tegra_pmc_detect_tz_only(void)
20 static bool initialized = false;
21 static bool is_tz_only = false;
25 saved = readl(NV_PA_PMC_BASE + PMC_SCRATCH0);
26 value = saved ^ 0xffffffff;
28 if (value == 0xffffffff)
31 /* write pattern and read it back */
32 writel(value, NV_PA_PMC_BASE + PMC_SCRATCH0);
33 value = readl(NV_PA_PMC_BASE + PMC_SCRATCH0);
35 /* if we read all-zeroes, access is restricted to TZ only */
37 debug("access to PMC is restricted to TZ\n");
40 /* restore original value */
41 writel(saved, NV_PA_PMC_BASE + PMC_SCRATCH0);
51 uint32_t tegra_pmc_readl(unsigned long offset)
53 #if IS_ENABLED(CONFIG_TEGRA_PMC_SECURE)
54 if (tegra_pmc_detect_tz_only()) {
55 struct arm_smccc_res res;
57 arm_smccc_smc(TEGRA_SMC_PMC, TEGRA_SMC_PMC_READ, offset, 0, 0,
60 printf("%s(): SMC failed: %lu\n", __func__, res.a0);
66 return readl(NV_PA_PMC_BASE + offset);
69 void tegra_pmc_writel(u32 value, unsigned long offset)
71 #if IS_ENABLED(CONFIG_TEGRA_PMC_SECURE)
72 if (tegra_pmc_detect_tz_only()) {
73 struct arm_smccc_res res;
75 arm_smccc_smc(TEGRA_SMC_PMC, TEGRA_SMC_PMC_WRITE, offset,
76 value, 0, 0, 0, 0, &res);
78 printf("%s(): SMC failed: %lu\n", __func__, res.a0);
84 writel(value, NV_PA_PMC_BASE + offset);
87 void reset_cpu(ulong addr)
91 value = tegra_pmc_readl(PMC_CNTRL);
92 value |= PMC_CNTRL_MAIN_RST;
93 tegra_pmc_writel(value, PMC_CNTRL);