blob: f35bdba4d48aade69cb8417365e22ec881161f6b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Warren112a1882011-04-14 12:18:06 +00002/*
Tom Rini10e47792018-05-06 17:58:06 -04003 * (C) Copyright 2010-2015
4 * NVIDIA Corporation <www.nvidia.com>
5 */
Tom Warren61c6d0e2012-12-11 13:34:15 +00006
7/* Tegra AP (Application Processor) code */
8
Tom Rinidec7ea02024-05-20 13:35:03 -06009#include <config.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Masahiro Yamada78eeb912016-01-24 23:27:48 +090011#include <linux/bug.h>
Tom Warren112a1882011-04-14 12:18:06 +000012#include <asm/io.h>
Simon Glass1fed82a2012-04-02 13:18:50 +000013#include <asm/arch/gp_padctrl.h>
Ian Campbelld07e7b02015-04-21 07:18:36 +020014#include <asm/arch/mc.h>
Tom Warrenab371962012-09-19 15:50:56 -070015#include <asm/arch-tegra/ap.h>
Tom Warren61c6d0e2012-12-11 13:34:15 +000016#include <asm/arch-tegra/clock.h>
Tom Warrenab371962012-09-19 15:50:56 -070017#include <asm/arch-tegra/fuse.h>
18#include <asm/arch-tegra/pmc.h>
19#include <asm/arch-tegra/scu.h>
Tom Warrene3d95bc2013-01-28 13:32:10 +000020#include <asm/arch-tegra/tegra.h>
Tom Warrenab371962012-09-19 15:50:56 -070021#include <asm/arch-tegra/warmboot.h>
Tom Warren112a1882011-04-14 12:18:06 +000022
Tom Warren8b817112013-04-10 10:32:32 -070023int tegra_get_chip(void)
Simon Glass1fed82a2012-04-02 13:18:50 +000024{
Tom Warren8b817112013-04-10 10:32:32 -070025 int rev;
26 struct apb_misc_gp_ctlr *gp =
27 (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE;
Simon Glass1fed82a2012-04-02 13:18:50 +000028
29 /*
30 * This is undocumented, Chip ID is bits 15:8 of the register
31 * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
Tom Warrene5ffffd2014-01-24 12:46:16 -070032 * Tegra30, 0x35 for T114, and 0x40 for Tegra124.
Simon Glass1fed82a2012-04-02 13:18:50 +000033 */
Simon Glass1fed82a2012-04-02 13:18:50 +000034 rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
Ion Agorria947fdb62024-10-03 10:52:12 +030035 debug("%s: CHIPID is 0x%02x\n", __func__, rev);
Tom Warren8b817112013-04-10 10:32:32 -070036
37 return rev;
38}
39
40int tegra_get_sku_info(void)
41{
42 int sku_id;
43 struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE;
Simon Glass1fed82a2012-04-02 13:18:50 +000044
Tom Warren8b817112013-04-10 10:32:32 -070045 sku_id = readl(&fuse->sku_info) & 0xff;
Ion Agorria947fdb62024-10-03 10:52:12 +030046 debug("%s: SKU info byte is 0x%02x\n", __func__, sku_id);
Simon Glass1fed82a2012-04-02 13:18:50 +000047
Tom Warren8b817112013-04-10 10:32:32 -070048 return sku_id;
49}
50
51int tegra_get_chip_sku(void)
52{
53 uint sku_id, chip_id;
54
55 chip_id = tegra_get_chip();
56 sku_id = tegra_get_sku_info();
57
58 switch (chip_id) {
Allen Martin55d98a12012-08-31 08:30:00 +000059 case CHIPID_TEGRA20:
Tom Warren8b817112013-04-10 10:32:32 -070060 switch (sku_id) {
Ion Agorriae7ce9302024-09-24 21:46:45 +020061 case SKU_ID_AP20:
Simon Glass1fed82a2012-04-02 13:18:50 +000062 case SKU_ID_T20:
Ion Agorriae7ce9302024-09-24 21:46:45 +020063 case SKU_ID_AP20H:
Simon Glass1fed82a2012-04-02 13:18:50 +000064 return TEGRA_SOC_T20;
65 case SKU_ID_T25SE:
66 case SKU_ID_AP25:
67 case SKU_ID_T25:
68 case SKU_ID_AP25E:
69 case SKU_ID_T25E:
70 return TEGRA_SOC_T25;
71 }
72 break;
Tom Warren61c6d0e2012-12-11 13:34:15 +000073 case CHIPID_TEGRA30:
Tom Warren8b817112013-04-10 10:32:32 -070074 switch (sku_id) {
Stephen Warrend9cd5022013-03-27 09:37:02 +000075 case SKU_ID_T33:
Tom Warren61c6d0e2012-12-11 13:34:15 +000076 case SKU_ID_T30:
Alban Bedelc5fb3082013-11-13 17:27:18 +010077 case SKU_ID_TM30MQS_P_A3:
Stephen Warren8ac88852014-01-21 17:19:19 -070078 default:
Tom Warren61c6d0e2012-12-11 13:34:15 +000079 return TEGRA_SOC_T30;
80 }
81 break;
Tom Warrene3d95bc2013-01-28 13:32:10 +000082 case CHIPID_TEGRA114:
Tom Warren8b817112013-04-10 10:32:32 -070083 switch (sku_id) {
Tom Warrene3d95bc2013-01-28 13:32:10 +000084 case SKU_ID_T114_ENG:
Stephen Warrenb08795a2013-05-17 14:10:14 +000085 case SKU_ID_T114_1:
Stephen Warren8ac88852014-01-21 17:19:19 -070086 default:
Tom Warrene3d95bc2013-01-28 13:32:10 +000087 return TEGRA_SOC_T114;
88 }
89 break;
Tom Warrene5ffffd2014-01-24 12:46:16 -070090 case CHIPID_TEGRA124:
91 switch (sku_id) {
92 case SKU_ID_T124_ENG:
93 default:
94 return TEGRA_SOC_T124;
95 }
96 break;
Tom Warrenab0cc6b2015-03-04 16:36:00 -070097 case CHIPID_TEGRA210:
98 switch (sku_id) {
99 case SKU_ID_T210_ENG:
100 default:
101 return TEGRA_SOC_T210;
102 }
103 break;
Simon Glass1fed82a2012-04-02 13:18:50 +0000104 }
Tom Warrene5ffffd2014-01-24 12:46:16 -0700105
Tom Warren8b817112013-04-10 10:32:32 -0700106 /* unknown chip/sku id */
Ion Agorria947fdb62024-10-03 10:52:12 +0300107 printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02x/0x%02x)\n",
108 __func__, chip_id, sku_id);
Simon Glass1fed82a2012-04-02 13:18:50 +0000109 return TEGRA_SOC_UNKNOWN;
110}
111
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700112#ifndef CONFIG_ARM64
Allen Martinc9c98462012-08-31 08:30:12 +0000113static void enable_scu(void)
Tom Warren112a1882011-04-14 12:18:06 +0000114{
115 struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE;
116 u32 reg;
117
Tom Warren642a4442013-05-23 12:26:18 +0000118 /* Only enable the SCU on T20/T25 */
119 if (tegra_get_chip() != CHIPID_TEGRA20)
120 return;
121
Tom Warren112a1882011-04-14 12:18:06 +0000122 /* If SCU already setup/enabled, return */
123 if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE)
124 return;
125
126 /* Invalidate all ways for all processors */
127 writel(0xFFFF, &scu->scu_inv_all);
128
129 /* Enable SCU - bit 0 */
130 reg = readl(&scu->scu_ctrl);
131 reg |= SCU_CTRL_ENABLE;
132 writel(reg, &scu->scu_ctrl);
133}
134
Tom Warren7ee52b02012-05-30 14:06:09 -0700135static u32 get_odmdata(void)
136{
137 /*
138 * ODMDATA is stored in the BCT in IRAM by the BootROM.
139 * The BCT start and size are stored in the BIT in IRAM.
140 * Read the data @ bct_start + (bct_size - 12). This works
Tom Warrene5ffffd2014-01-24 12:46:16 -0700141 * on BCTs for currently supported SoCs, which are locked down.
142 * If this changes in new chips, we can revisit this algorithm.
Tom Warren7ee52b02012-05-30 14:06:09 -0700143 */
Thierry Reding8264d1f2015-07-22 15:58:05 -0600144 unsigned long bct_start;
145 u32 odmdata;
Tom Warren7ee52b02012-05-30 14:06:09 -0700146
Tom Warren61c6d0e2012-12-11 13:34:15 +0000147 bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR);
Tom Warren7ee52b02012-05-30 14:06:09 -0700148 odmdata = readl(bct_start + BCT_ODMDATA_OFFSET);
149
150 return odmdata;
151}
152
Allen Martinc9c98462012-08-31 08:30:12 +0000153static void init_pmc_scratch(void)
Tom Warren112a1882011-04-14 12:18:06 +0000154{
Tom Warren22562a42012-09-04 17:00:24 -0700155 struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
Tom Warren7ee52b02012-05-30 14:06:09 -0700156 u32 odmdata;
Tom Warren112a1882011-04-14 12:18:06 +0000157 int i;
158
159 /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */
Stephen Warren8eadc5f2018-07-31 12:39:07 -0600160#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
161 if (!tegra_cpu_is_non_secure())
162#endif
163 {
164 for (i = 0; i < 23; i++)
165 writel(0, &pmc->pmc_scratch1 + i);
166 }
Tom Warren112a1882011-04-14 12:18:06 +0000167
168 /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
Tom Warren7ee52b02012-05-30 14:06:09 -0700169 odmdata = get_odmdata();
170 writel(odmdata, &pmc->pmc_scratch20);
Tom Warren112a1882011-04-14 12:18:06 +0000171}
172
Ian Campbelld07e7b02015-04-21 07:18:36 +0200173#ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
174void protect_secure_section(void)
175{
176 struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
177
178 /* Must be MB aligned */
179 BUILD_BUG_ON(CONFIG_ARMV7_SECURE_BASE & 0xFFFFF);
180 BUILD_BUG_ON(CONFIG_ARMV7_SECURE_RESERVE_SIZE & 0xFFFFF);
181
182 writel(CONFIG_ARMV7_SECURE_BASE, &mc->mc_security_cfg0);
183 writel(CONFIG_ARMV7_SECURE_RESERVE_SIZE >> 20, &mc->mc_security_cfg1);
184}
185#endif
186
Thierry Redinga16875a2015-04-21 07:18:38 +0200187#if defined(CONFIG_ARMV7_NONSEC)
188static void smmu_flush(struct mc_ctlr *mc)
189{
190 (void)readl(&mc->mc_smmu_config);
191}
192
193static void smmu_enable(void)
194{
195 struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE;
196 u32 value;
197
198 /*
199 * Enable translation for all clients since access to this register
200 * is restricted to TrustZone-secured requestors. The kernel will use
201 * the per-SWGROUP enable bits to enable or disable translations.
202 */
203 writel(0xffffffff, &mc->mc_smmu_translation_enable_0);
204 writel(0xffffffff, &mc->mc_smmu_translation_enable_1);
205 writel(0xffffffff, &mc->mc_smmu_translation_enable_2);
206 writel(0xffffffff, &mc->mc_smmu_translation_enable_3);
207
208 /*
209 * Enable SMMU globally since access to this register is restricted
210 * to TrustZone-secured requestors.
211 */
212 value = readl(&mc->mc_smmu_config);
213 value |= TEGRA_MC_SMMU_CONFIG_ENABLE;
214 writel(value, &mc->mc_smmu_config);
215
216 smmu_flush(mc);
217}
218#else
219static void smmu_enable(void)
220{
221}
222#endif
223
Allen Martinc9c98462012-08-31 08:30:12 +0000224void s_init(void)
Tom Warren112a1882011-04-14 12:18:06 +0000225{
Simon Glassec8dab42011-11-05 03:56:50 +0000226 /* Init PMC scratch memory */
227 init_pmc_scratch();
Tom Warren112a1882011-04-14 12:18:06 +0000228
Simon Glassec8dab42011-11-05 03:56:50 +0000229 enable_scu();
Tom Warren112a1882011-04-14 12:18:06 +0000230
Tom Warren82b51342013-03-25 16:22:26 -0700231 /* init the cache */
232 config_cache();
Bryan Wu97adb222014-06-24 11:45:29 +0900233
Thierry Redinga16875a2015-04-21 07:18:38 +0200234 /* enable SMMU */
235 smmu_enable();
Tom Warren112a1882011-04-14 12:18:06 +0000236}
Tom Warrenab0cc6b2015-03-04 16:36:00 -0700237#endif