Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 1 | /* |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 2 | * (C) Copyright 2010-2015 |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 3 | * NVIDIA Corporation <www.nvidia.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 6 | */ |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 7 | |
| 8 | /* Tegra AP (Application Processor) code */ |
| 9 | |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 10 | #include <common.h> |
Masahiro Yamada | 78eeb91 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 11 | #include <linux/bug.h> |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 13 | #include <asm/arch/gp_padctrl.h> |
Ian Campbell | d07e7b0 | 2015-04-21 07:18:36 +0200 | [diff] [blame] | 14 | #include <asm/arch/mc.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 15 | #include <asm/arch-tegra/ap.h> |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 16 | #include <asm/arch-tegra/clock.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 17 | #include <asm/arch-tegra/fuse.h> |
| 18 | #include <asm/arch-tegra/pmc.h> |
| 19 | #include <asm/arch-tegra/scu.h> |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 20 | #include <asm/arch-tegra/tegra.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 21 | #include <asm/arch-tegra/warmboot.h> |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 22 | |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 23 | int tegra_get_chip(void) |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 24 | { |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 25 | int rev; |
| 26 | struct apb_misc_gp_ctlr *gp = |
| 27 | (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE; |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 28 | |
| 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 Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 32 | * Tegra30, 0x35 for T114, and 0x40 for Tegra124. |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 33 | */ |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 34 | rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT; |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 35 | debug("%s: CHIPID is 0x%02X\n", __func__, rev); |
| 36 | |
| 37 | return rev; |
| 38 | } |
| 39 | |
| 40 | int tegra_get_sku_info(void) |
| 41 | { |
| 42 | int sku_id; |
| 43 | struct fuse_regs *fuse = (struct fuse_regs *)NV_PA_FUSE_BASE; |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 44 | |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 45 | sku_id = readl(&fuse->sku_info) & 0xff; |
| 46 | debug("%s: SKU info byte is 0x%02X\n", __func__, sku_id); |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 47 | |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 48 | return sku_id; |
| 49 | } |
| 50 | |
| 51 | int 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 Martin | 55d98a1 | 2012-08-31 08:30:00 +0000 | [diff] [blame] | 59 | case CHIPID_TEGRA20: |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 60 | switch (sku_id) { |
Stephen Warren | a8512db | 2013-05-17 14:10:15 +0000 | [diff] [blame] | 61 | case SKU_ID_T20_7: |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 62 | case SKU_ID_T20: |
| 63 | return TEGRA_SOC_T20; |
| 64 | case SKU_ID_T25SE: |
| 65 | case SKU_ID_AP25: |
| 66 | case SKU_ID_T25: |
| 67 | case SKU_ID_AP25E: |
| 68 | case SKU_ID_T25E: |
| 69 | return TEGRA_SOC_T25; |
| 70 | } |
| 71 | break; |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 72 | case CHIPID_TEGRA30: |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 73 | switch (sku_id) { |
Stephen Warren | d9cd502 | 2013-03-27 09:37:02 +0000 | [diff] [blame] | 74 | case SKU_ID_T33: |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 75 | case SKU_ID_T30: |
Alban Bedel | c5fb308 | 2013-11-13 17:27:18 +0100 | [diff] [blame] | 76 | case SKU_ID_TM30MQS_P_A3: |
Stephen Warren | 8ac8885 | 2014-01-21 17:19:19 -0700 | [diff] [blame] | 77 | default: |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 78 | return TEGRA_SOC_T30; |
| 79 | } |
| 80 | break; |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 81 | case CHIPID_TEGRA114: |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 82 | switch (sku_id) { |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 83 | case SKU_ID_T114_ENG: |
Stephen Warren | b08795a | 2013-05-17 14:10:14 +0000 | [diff] [blame] | 84 | case SKU_ID_T114_1: |
Stephen Warren | 8ac8885 | 2014-01-21 17:19:19 -0700 | [diff] [blame] | 85 | default: |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 86 | return TEGRA_SOC_T114; |
| 87 | } |
| 88 | break; |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 89 | case CHIPID_TEGRA124: |
| 90 | switch (sku_id) { |
| 91 | case SKU_ID_T124_ENG: |
| 92 | default: |
| 93 | return TEGRA_SOC_T124; |
| 94 | } |
| 95 | break; |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 96 | case CHIPID_TEGRA210: |
| 97 | switch (sku_id) { |
| 98 | case SKU_ID_T210_ENG: |
| 99 | default: |
| 100 | return TEGRA_SOC_T210; |
| 101 | } |
| 102 | break; |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 103 | } |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 104 | |
Tom Warren | 8b81711 | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 105 | /* unknown chip/sku id */ |
| 106 | printf("%s: ERROR: UNKNOWN CHIP/SKU ID COMBO (0x%02X/0x%02X)\n", |
| 107 | __func__, chip_id, sku_id); |
Simon Glass | 1fed82a | 2012-04-02 13:18:50 +0000 | [diff] [blame] | 108 | return TEGRA_SOC_UNKNOWN; |
| 109 | } |
| 110 | |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 111 | #ifndef CONFIG_ARM64 |
Allen Martin | c9c9846 | 2012-08-31 08:30:12 +0000 | [diff] [blame] | 112 | static void enable_scu(void) |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 113 | { |
| 114 | struct scu_ctlr *scu = (struct scu_ctlr *)NV_PA_ARM_PERIPHBASE; |
| 115 | u32 reg; |
| 116 | |
Tom Warren | 642a444 | 2013-05-23 12:26:18 +0000 | [diff] [blame] | 117 | /* Only enable the SCU on T20/T25 */ |
| 118 | if (tegra_get_chip() != CHIPID_TEGRA20) |
| 119 | return; |
| 120 | |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 121 | /* If SCU already setup/enabled, return */ |
| 122 | if (readl(&scu->scu_ctrl) & SCU_CTRL_ENABLE) |
| 123 | return; |
| 124 | |
| 125 | /* Invalidate all ways for all processors */ |
| 126 | writel(0xFFFF, &scu->scu_inv_all); |
| 127 | |
| 128 | /* Enable SCU - bit 0 */ |
| 129 | reg = readl(&scu->scu_ctrl); |
| 130 | reg |= SCU_CTRL_ENABLE; |
| 131 | writel(reg, &scu->scu_ctrl); |
| 132 | } |
| 133 | |
Tom Warren | 7ee52b0 | 2012-05-30 14:06:09 -0700 | [diff] [blame] | 134 | static u32 get_odmdata(void) |
| 135 | { |
| 136 | /* |
| 137 | * ODMDATA is stored in the BCT in IRAM by the BootROM. |
| 138 | * The BCT start and size are stored in the BIT in IRAM. |
| 139 | * Read the data @ bct_start + (bct_size - 12). This works |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 140 | * on BCTs for currently supported SoCs, which are locked down. |
| 141 | * If this changes in new chips, we can revisit this algorithm. |
Tom Warren | 7ee52b0 | 2012-05-30 14:06:09 -0700 | [diff] [blame] | 142 | */ |
Thierry Reding | 8264d1f | 2015-07-22 15:58:05 -0600 | [diff] [blame] | 143 | unsigned long bct_start; |
| 144 | u32 odmdata; |
Tom Warren | 7ee52b0 | 2012-05-30 14:06:09 -0700 | [diff] [blame] | 145 | |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 146 | bct_start = readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BCTPTR); |
Tom Warren | 7ee52b0 | 2012-05-30 14:06:09 -0700 | [diff] [blame] | 147 | odmdata = readl(bct_start + BCT_ODMDATA_OFFSET); |
| 148 | |
| 149 | return odmdata; |
| 150 | } |
| 151 | |
Allen Martin | c9c9846 | 2012-08-31 08:30:12 +0000 | [diff] [blame] | 152 | static void init_pmc_scratch(void) |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 153 | { |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 154 | struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
Tom Warren | 7ee52b0 | 2012-05-30 14:06:09 -0700 | [diff] [blame] | 155 | u32 odmdata; |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 156 | int i; |
| 157 | |
| 158 | /* SCRATCH0 is initialized by the boot ROM and shouldn't be cleared */ |
| 159 | for (i = 0; i < 23; i++) |
| 160 | writel(0, &pmc->pmc_scratch1+i); |
| 161 | |
| 162 | /* ODMDATA is for kernel use to determine RAM size, LP config, etc. */ |
Tom Warren | 7ee52b0 | 2012-05-30 14:06:09 -0700 | [diff] [blame] | 163 | odmdata = get_odmdata(); |
| 164 | writel(odmdata, &pmc->pmc_scratch20); |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Ian Campbell | d07e7b0 | 2015-04-21 07:18:36 +0200 | [diff] [blame] | 167 | #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE |
| 168 | void protect_secure_section(void) |
| 169 | { |
| 170 | struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE; |
| 171 | |
| 172 | /* Must be MB aligned */ |
| 173 | BUILD_BUG_ON(CONFIG_ARMV7_SECURE_BASE & 0xFFFFF); |
| 174 | BUILD_BUG_ON(CONFIG_ARMV7_SECURE_RESERVE_SIZE & 0xFFFFF); |
| 175 | |
| 176 | writel(CONFIG_ARMV7_SECURE_BASE, &mc->mc_security_cfg0); |
| 177 | writel(CONFIG_ARMV7_SECURE_RESERVE_SIZE >> 20, &mc->mc_security_cfg1); |
| 178 | } |
| 179 | #endif |
| 180 | |
Thierry Reding | a16875a | 2015-04-21 07:18:38 +0200 | [diff] [blame] | 181 | #if defined(CONFIG_ARMV7_NONSEC) |
| 182 | static void smmu_flush(struct mc_ctlr *mc) |
| 183 | { |
| 184 | (void)readl(&mc->mc_smmu_config); |
| 185 | } |
| 186 | |
| 187 | static void smmu_enable(void) |
| 188 | { |
| 189 | struct mc_ctlr *mc = (struct mc_ctlr *)NV_PA_MC_BASE; |
| 190 | u32 value; |
| 191 | |
| 192 | /* |
| 193 | * Enable translation for all clients since access to this register |
| 194 | * is restricted to TrustZone-secured requestors. The kernel will use |
| 195 | * the per-SWGROUP enable bits to enable or disable translations. |
| 196 | */ |
| 197 | writel(0xffffffff, &mc->mc_smmu_translation_enable_0); |
| 198 | writel(0xffffffff, &mc->mc_smmu_translation_enable_1); |
| 199 | writel(0xffffffff, &mc->mc_smmu_translation_enable_2); |
| 200 | writel(0xffffffff, &mc->mc_smmu_translation_enable_3); |
| 201 | |
| 202 | /* |
| 203 | * Enable SMMU globally since access to this register is restricted |
| 204 | * to TrustZone-secured requestors. |
| 205 | */ |
| 206 | value = readl(&mc->mc_smmu_config); |
| 207 | value |= TEGRA_MC_SMMU_CONFIG_ENABLE; |
| 208 | writel(value, &mc->mc_smmu_config); |
| 209 | |
| 210 | smmu_flush(mc); |
| 211 | } |
| 212 | #else |
| 213 | static void smmu_enable(void) |
| 214 | { |
| 215 | } |
| 216 | #endif |
| 217 | |
Allen Martin | c9c9846 | 2012-08-31 08:30:12 +0000 | [diff] [blame] | 218 | void s_init(void) |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 219 | { |
Simon Glass | ec8dab4 | 2011-11-05 03:56:50 +0000 | [diff] [blame] | 220 | /* Init PMC scratch memory */ |
| 221 | init_pmc_scratch(); |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 222 | |
Simon Glass | ec8dab4 | 2011-11-05 03:56:50 +0000 | [diff] [blame] | 223 | enable_scu(); |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 224 | |
Tom Warren | 82b5134 | 2013-03-25 16:22:26 -0700 | [diff] [blame] | 225 | /* init the cache */ |
| 226 | config_cache(); |
Bryan Wu | 97adb22 | 2014-06-24 11:45:29 +0900 | [diff] [blame] | 227 | |
Thierry Reding | a16875a | 2015-04-21 07:18:38 +0200 | [diff] [blame] | 228 | /* enable SMMU */ |
| 229 | smmu_enable(); |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame] | 230 | } |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 231 | #endif |