1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2010-2015
4 * NVIDIA Corporation <www.nvidia.com>
7 /* Tegra AP (Application Processor) code */
10 #include <linux/bug.h>
12 #include <asm/arch/gp_padctrl.h>
13 #include <asm/arch/mc.h>
14 #include <asm/arch-tegra/ap.h>
15 #include <asm/arch-tegra/clock.h>
16 #include <asm/arch-tegra/fuse.h>
17 #include <asm/arch-tegra/pmc.h>
18 #include <asm/arch-tegra/scu.h>
19 #include <asm/arch-tegra/tegra.h>
20 #include <asm/arch-tegra/warmboot.h>
22 int tegra_get_chip(void)
25 struct apb_misc_gp_ctlr *gp =
26 (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
29 * This is undocumented, Chip ID is bits 15:8 of the register
30 * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
31 * Tegra30, 0x35 for T114, and 0x40 for Tegra124.
33 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
34 debug("%s: CHIPID is 0x%02X\n", __func__, rev);
39 int tegra_get_sku_info(void)
42 struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
44 sku_id = readl(&fuse->sku_info) & 0xff;
45 debug("%s: SKU info byte is 0x%02X\n", __func__, sku_id);
50 int tegra_get_chip_sku(void)
54 chip_id = tegra_get_chip();
55 sku_id = tegra_get_sku_info();
75 case SKU_ID_TM30MQS_P_A3:
85 return TEGRA_SOC_T114;
92 return TEGRA_SOC_T124;
99 return TEGRA_SOC_T210;
104 /* unknown chip/sku id */
105 printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02X/0x%02X)\n",
106 __func__, chip_id, sku_id);
107 return TEGRA_SOC_UNKNOWN;
111 static void enable_scu(void)
113 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
116 /* Only enable the SCU on T20/T25 */
117 if (tegra_get_chip() != CHIPID_TEGRA20)
120 /* If SCU already setup/enabled, return */
121 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
124 /* Invalidate all ways for all processors */
125 writel(0xFFFF, &scu->scu_inv_all);
127 /* Enable SCU - bit 0 */
128 reg = readl(&scu->scu_ctrl);
129 reg |= SCU_CTRL_ENABLE;
130 writel(reg, &scu->scu_ctrl);
133 static u32 get_odmdata(void)
136 * ODMDATA is stored in the BCT in IRAM by the BootROM.
137 * The BCT start and size are stored in the BIT in IRAM.
138 * Read the data @ bct_start + (bct_size - 12). This works
139 * on BCTs for currently supported SoCs, which are locked down.
140 * If this changes in new chips, we can revisit this algorithm.
142 unsigned long bct_start;
145 bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
146 odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
151 static void init_pmc_scratch(void)
153 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
157 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
158 #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
159 if (!tegra_cpu_is_non_secure())
162 for (i = 0; i < 23; i++)
163 writel(0, &pmc->pmc_scratch1 + i);
166 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
167 odmdata = get_odmdata();
168 writel(odmdata, &pmc->pmc_scratch20);
171 #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
172 void protect_secure_section(void)
174 struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
176 /* Must be MB aligned */
177 BUILD_BUG_ON(CONFIG_ARMV7_SECURE_BASE & 0xFFFFF);
178 BUILD_BUG_ON(CONFIG_ARMV7_SECURE_RESERVE_SIZE & 0xFFFFF);
180 writel(CONFIG_ARMV7_SECURE_BASE, &mc->mc_security_cfg0);
181 writel(CONFIG_ARMV7_SECURE_RESERVE_SIZE >> 20, &mc->mc_security_cfg1);
185 #if defined(CONFIG_ARMV7_NONSEC)
186 static void smmu_flush(struct mc_ctlr *mc)
188 (void)readl(&mc->mc_smmu_config);
191 static void smmu_enable(void)
193 struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
197 * Enable translation for all clients since access to this register
198 * is restricted to TrustZone-secured requestors. The kernel will use
199 * the per-SWGROUP enable bits to enable or disable translations.
201 writel(0xffffffff, &mc->mc_smmu_translation_enable_0);
202 writel(0xffffffff, &mc->mc_smmu_translation_enable_1);
203 writel(0xffffffff, &mc->mc_smmu_translation_enable_2);
204 writel(0xffffffff, &mc->mc_smmu_translation_enable_3);
207 * Enable SMMU globally since access to this register is restricted
208 * to TrustZone-secured requestors.
210 value = readl(&mc->mc_smmu_config);
211 value |= TEGRA_MC_SMMU_CONFIG_ENABLE;
212 writel(value, &mc->mc_smmu_config);
217 static void smmu_enable(void)
224 /* Init PMC scratch memory */