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