Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 2 | /* |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 3 | * Copyright 2017-2019 NXP |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 4 | * |
| 5 | * Peng Fan <peng.fan@nxp.com> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 12 | #include <asm/arch/imx-regs.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/mach-imx/hab.h> |
| 18 | #include <asm/mach-imx/boot_mode.h> |
| 19 | #include <asm/mach-imx/syscounter.h> |
Peng Fan | a35215d | 2020-07-09 13:39:26 +0800 | [diff] [blame] | 20 | #include <asm/ptrace.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 21 | #include <asm/armv8/mmu.h> |
Peng Fan | c98e032 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 22 | #include <dm/uclass.h> |
Peng Fan | a35215d | 2020-07-09 13:39:26 +0800 | [diff] [blame] | 23 | #include <efi_loader.h> |
Ye Li | 0513f36 | 2019-07-15 01:16:46 -0700 | [diff] [blame] | 24 | #include <env.h> |
| 25 | #include <env_internal.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 26 | #include <errno.h> |
| 27 | #include <fdt_support.h> |
| 28 | #include <fsl_wdog.h> |
| 29 | #include <imx_sip.h> |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 30 | #include <linux/arm-smccc.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 31 | #include <linux/bitops.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 35 | #if defined(CONFIG_IMX_HAB) |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 36 | struct imx_sec_config_fuse_t const imx_sec_config_fuse = { |
| 37 | .bank = 1, |
| 38 | .word = 3, |
| 39 | }; |
| 40 | #endif |
| 41 | |
| 42 | int timer_init(void) |
| 43 | { |
| 44 | #ifdef CONFIG_SPL_BUILD |
| 45 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 46 | unsigned long freq = readl(&sctr->cntfid0); |
| 47 | |
| 48 | /* Update with accurate clock frequency */ |
| 49 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 50 | |
| 51 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 52 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 53 | #endif |
| 54 | |
| 55 | gd->arch.tbl = 0; |
| 56 | gd->arch.tbu = 0; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | void enable_tzc380(void) |
| 62 | { |
| 63 | struct iomuxc_gpr_base_regs *gpr = |
| 64 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 65 | |
| 66 | /* Enable TZASC and lock setting */ |
| 67 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN); |
| 68 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK); |
Peng Fan | c0e47fc | 2019-12-27 10:19:42 +0800 | [diff] [blame] | 69 | if (is_imx8mm() || is_imx8mn() || is_imx8mp()) |
Peng Fan | 99047fc | 2019-08-27 06:25:30 +0000 | [diff] [blame] | 70 | setbits_le32(&gpr->gpr[10], BIT(1)); |
Ye Li | 4c97c46 | 2019-08-27 06:25:34 +0000 | [diff] [blame] | 71 | /* |
| 72 | * set Region 0 attribute to allow secure and non-secure |
| 73 | * read/write permission. Found some masters like usb dwc3 |
| 74 | * controllers can't work with secure memory. |
| 75 | */ |
| 76 | writel(0xf0000000, TZASC_BASE_ADDR + 0x108); |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void set_wdog_reset(struct wdog_regs *wdog) |
| 80 | { |
| 81 | /* |
| 82 | * Output WDOG_B signal to reset external pmic or POR_B decided by |
| 83 | * the board design. Without external reset, the peripherals/DDR/ |
| 84 | * PMIC are not reset, that may cause system working abnormal. |
| 85 | * WDZST bit is write-once only bit. Align this bit in kernel, |
| 86 | * otherwise kernel code will have no chance to set this bit. |
| 87 | */ |
| 88 | setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK); |
| 89 | } |
| 90 | |
| 91 | static struct mm_region imx8m_mem_map[] = { |
| 92 | { |
| 93 | /* ROM */ |
| 94 | .virt = 0x0UL, |
| 95 | .phys = 0x0UL, |
| 96 | .size = 0x100000UL, |
| 97 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 98 | PTE_BLOCK_OUTER_SHARE |
| 99 | }, { |
Gary Bisson | 5c72a45 | 2018-11-14 17:55:28 +0100 | [diff] [blame] | 100 | /* CAAM */ |
| 101 | .virt = 0x100000UL, |
| 102 | .phys = 0x100000UL, |
| 103 | .size = 0x8000UL, |
| 104 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 105 | PTE_BLOCK_NON_SHARE | |
| 106 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 107 | }, { |
Marek Vasut | b1738e0 | 2021-02-25 21:52:26 +0100 | [diff] [blame] | 108 | /* OCRAM_S */ |
| 109 | .virt = 0x180000UL, |
| 110 | .phys = 0x180000UL, |
| 111 | .size = 0x8000UL, |
| 112 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 113 | PTE_BLOCK_OUTER_SHARE |
| 114 | }, { |
Gary Bisson | 5c72a45 | 2018-11-14 17:55:28 +0100 | [diff] [blame] | 115 | /* TCM */ |
| 116 | .virt = 0x7C0000UL, |
| 117 | .phys = 0x7C0000UL, |
| 118 | .size = 0x80000UL, |
| 119 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 120 | PTE_BLOCK_NON_SHARE | |
| 121 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 122 | }, { |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 123 | /* OCRAM */ |
| 124 | .virt = 0x900000UL, |
| 125 | .phys = 0x900000UL, |
| 126 | .size = 0x200000UL, |
| 127 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 128 | PTE_BLOCK_OUTER_SHARE |
| 129 | }, { |
| 130 | /* AIPS */ |
| 131 | .virt = 0xB00000UL, |
| 132 | .phys = 0xB00000UL, |
| 133 | .size = 0x3f500000UL, |
| 134 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 135 | PTE_BLOCK_NON_SHARE | |
| 136 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 137 | }, { |
| 138 | /* DRAM1 */ |
| 139 | .virt = 0x40000000UL, |
| 140 | .phys = 0x40000000UL, |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 141 | .size = PHYS_SDRAM_SIZE, |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 142 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 143 | PTE_BLOCK_OUTER_SHARE |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 144 | #ifdef PHYS_SDRAM_2_SIZE |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 145 | }, { |
| 146 | /* DRAM2 */ |
| 147 | .virt = 0x100000000UL, |
| 148 | .phys = 0x100000000UL, |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 149 | .size = PHYS_SDRAM_2_SIZE, |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 150 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 151 | PTE_BLOCK_OUTER_SHARE |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 152 | #endif |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 153 | }, { |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 154 | /* empty entrie to split table entry 5 if needed when TEEs are used */ |
| 155 | 0, |
| 156 | }, { |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 157 | /* List terminator */ |
| 158 | 0, |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | struct mm_region *mem_map = imx8m_mem_map; |
| 163 | |
Marek Vasut | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 164 | static unsigned int imx8m_find_dram_entry_in_mem_map(void) |
| 165 | { |
| 166 | int i; |
| 167 | |
| 168 | for (i = 0; i < ARRAY_SIZE(imx8m_mem_map); i++) |
| 169 | if (imx8m_mem_map[i].phys == CONFIG_SYS_SDRAM_BASE) |
| 170 | return i; |
| 171 | |
| 172 | hang(); /* Entry not found, this must never happen. */ |
| 173 | } |
| 174 | |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 175 | void enable_caches(void) |
| 176 | { |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 177 | /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch */ |
| 178 | if (rom_pointer[1]) { |
| 179 | /* |
| 180 | * TEE are loaded, So the ddr bank structures |
| 181 | * have been modified update mmu table accordingly |
| 182 | */ |
| 183 | int i = 0; |
| 184 | /* |
| 185 | * please make sure that entry initial value matches |
| 186 | * imx8m_mem_map for DRAM1 |
| 187 | */ |
Marek Vasut | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 188 | int entry = imx8m_find_dram_entry_in_mem_map(); |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 189 | u64 attrs = imx8m_mem_map[entry].attrs; |
| 190 | |
Marek Vasut | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 191 | while (i < CONFIG_NR_DRAM_BANKS && |
| 192 | entry < ARRAY_SIZE(imx8m_mem_map)) { |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 193 | if (gd->bd->bi_dram[i].start == 0) |
| 194 | break; |
| 195 | imx8m_mem_map[entry].phys = gd->bd->bi_dram[i].start; |
| 196 | imx8m_mem_map[entry].virt = gd->bd->bi_dram[i].start; |
| 197 | imx8m_mem_map[entry].size = gd->bd->bi_dram[i].size; |
| 198 | imx8m_mem_map[entry].attrs = attrs; |
| 199 | debug("Added memory mapping (%d): %llx %llx\n", entry, |
| 200 | imx8m_mem_map[entry].phys, imx8m_mem_map[entry].size); |
| 201 | i++; entry++; |
| 202 | } |
| 203 | } |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 204 | |
| 205 | icache_enable(); |
| 206 | dcache_enable(); |
| 207 | } |
| 208 | |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 209 | __weak int board_phys_sdram_size(phys_size_t *size) |
| 210 | { |
| 211 | if (!size) |
| 212 | return -EINVAL; |
| 213 | |
| 214 | *size = PHYS_SDRAM_SIZE; |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | int dram_init(void) |
| 219 | { |
Marek Vasut | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 220 | unsigned int entry = imx8m_find_dram_entry_in_mem_map(); |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 221 | phys_size_t sdram_size; |
| 222 | int ret; |
| 223 | |
| 224 | ret = board_phys_sdram_size(&sdram_size); |
| 225 | if (ret) |
| 226 | return ret; |
| 227 | |
| 228 | /* rom_pointer[1] contains the size of TEE occupies */ |
| 229 | if (rom_pointer[1]) |
| 230 | gd->ram_size = sdram_size - rom_pointer[1]; |
| 231 | else |
| 232 | gd->ram_size = sdram_size; |
| 233 | |
Tim Harvey | 32927bc | 2020-09-25 08:08:35 -0700 | [diff] [blame] | 234 | /* also update the SDRAM size in the mem_map used externally */ |
Marek Vasut | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 235 | imx8m_mem_map[entry].size = sdram_size; |
Tim Harvey | 32927bc | 2020-09-25 08:08:35 -0700 | [diff] [blame] | 236 | |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 237 | #ifdef PHYS_SDRAM_2_SIZE |
| 238 | gd->ram_size += PHYS_SDRAM_2_SIZE; |
| 239 | #endif |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | int dram_init_banksize(void) |
| 245 | { |
| 246 | int bank = 0; |
| 247 | int ret; |
| 248 | phys_size_t sdram_size; |
| 249 | |
| 250 | ret = board_phys_sdram_size(&sdram_size); |
| 251 | if (ret) |
| 252 | return ret; |
| 253 | |
| 254 | gd->bd->bi_dram[bank].start = PHYS_SDRAM; |
| 255 | if (rom_pointer[1]) { |
| 256 | phys_addr_t optee_start = (phys_addr_t)rom_pointer[0]; |
| 257 | phys_size_t optee_size = (size_t)rom_pointer[1]; |
| 258 | |
| 259 | gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start; |
| 260 | if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_size)) { |
| 261 | if (++bank >= CONFIG_NR_DRAM_BANKS) { |
| 262 | puts("CONFIG_NR_DRAM_BANKS is not enough\n"); |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | gd->bd->bi_dram[bank].start = optee_start + optee_size; |
| 267 | gd->bd->bi_dram[bank].size = PHYS_SDRAM + |
| 268 | sdram_size - gd->bd->bi_dram[bank].start; |
| 269 | } |
| 270 | } else { |
| 271 | gd->bd->bi_dram[bank].size = sdram_size; |
| 272 | } |
| 273 | |
| 274 | #ifdef PHYS_SDRAM_2_SIZE |
| 275 | if (++bank >= CONFIG_NR_DRAM_BANKS) { |
| 276 | puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n"); |
| 277 | return -1; |
| 278 | } |
| 279 | gd->bd->bi_dram[bank].start = PHYS_SDRAM_2; |
| 280 | gd->bd->bi_dram[bank].size = PHYS_SDRAM_2_SIZE; |
| 281 | #endif |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | phys_size_t get_effective_memsize(void) |
| 287 | { |
| 288 | /* return the first bank as effective memory */ |
| 289 | if (rom_pointer[1]) |
| 290 | return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM); |
| 291 | |
| 292 | #ifdef PHYS_SDRAM_2_SIZE |
| 293 | return gd->ram_size - PHYS_SDRAM_2_SIZE; |
| 294 | #else |
| 295 | return gd->ram_size; |
| 296 | #endif |
| 297 | } |
| 298 | |
Frieder Schrempf | 159879e | 2021-06-07 14:36:44 +0200 | [diff] [blame] | 299 | ulong board_get_usable_ram_top(ulong total_size) |
| 300 | { |
| 301 | /* |
| 302 | * Some IPs have their accessible address space restricted by |
| 303 | * the interconnect. Let's make sure U-Boot only ever uses the |
| 304 | * space below the 4G address boundary (which is 3GiB big), |
| 305 | * even when the effective available memory is bigger. |
| 306 | */ |
| 307 | if (PHYS_SDRAM + gd->ram_size > 0x80000000) |
| 308 | return 0x80000000; |
| 309 | |
| 310 | return PHYS_SDRAM + gd->ram_size; |
| 311 | } |
| 312 | |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 313 | static u32 get_cpu_variant_type(u32 type) |
| 314 | { |
| 315 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 316 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 317 | struct fuse_bank1_regs *fuse = |
| 318 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 319 | |
| 320 | u32 value = readl(&fuse->tester4); |
| 321 | |
Peng Fan | 6781508 | 2020-02-05 17:34:54 +0800 | [diff] [blame] | 322 | if (type == MXC_CPU_IMX8MQ) { |
| 323 | if ((value & 0x3) == 0x2) |
| 324 | return MXC_CPU_IMX8MD; |
| 325 | else if (value & 0x200000) |
| 326 | return MXC_CPU_IMX8MQL; |
| 327 | |
| 328 | } else if (type == MXC_CPU_IMX8MM) { |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 329 | switch (value & 0x3) { |
| 330 | case 2: |
| 331 | if (value & 0x1c0000) |
| 332 | return MXC_CPU_IMX8MMDL; |
| 333 | else |
| 334 | return MXC_CPU_IMX8MMD; |
| 335 | case 3: |
| 336 | if (value & 0x1c0000) |
| 337 | return MXC_CPU_IMX8MMSL; |
| 338 | else |
| 339 | return MXC_CPU_IMX8MMS; |
| 340 | default: |
| 341 | if (value & 0x1c0000) |
| 342 | return MXC_CPU_IMX8MML; |
| 343 | break; |
| 344 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 345 | } else if (type == MXC_CPU_IMX8MN) { |
| 346 | switch (value & 0x3) { |
| 347 | case 2: |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 348 | if (value & 0x1000000) { |
| 349 | if (value & 0x10000000) /* MIPI DSI */ |
| 350 | return MXC_CPU_IMX8MNUD; |
| 351 | else |
| 352 | return MXC_CPU_IMX8MNDL; |
| 353 | } else { |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 354 | return MXC_CPU_IMX8MND; |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 355 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 356 | case 3: |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 357 | if (value & 0x1000000) { |
| 358 | if (value & 0x10000000) /* MIPI DSI */ |
| 359 | return MXC_CPU_IMX8MNUS; |
| 360 | else |
| 361 | return MXC_CPU_IMX8MNSL; |
| 362 | } else { |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 363 | return MXC_CPU_IMX8MNS; |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 364 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 365 | default: |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 366 | if (value & 0x1000000) { |
| 367 | if (value & 0x10000000) /* MIPI DSI */ |
| 368 | return MXC_CPU_IMX8MNUQ; |
| 369 | else |
| 370 | return MXC_CPU_IMX8MNL; |
| 371 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 372 | break; |
| 373 | } |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 374 | } else if (type == MXC_CPU_IMX8MP) { |
| 375 | u32 value0 = readl(&fuse->tester3); |
| 376 | u32 flag = 0; |
| 377 | |
| 378 | if ((value0 & 0xc0000) == 0x80000) |
| 379 | return MXC_CPU_IMX8MPD; |
| 380 | |
| 381 | /* vpu disabled */ |
| 382 | if ((value0 & 0x43000000) == 0x43000000) |
| 383 | flag = 1; |
| 384 | |
| 385 | /* npu disabled*/ |
| 386 | if ((value & 0x8) == 0x8) |
| 387 | flag |= (1 << 1); |
| 388 | |
| 389 | /* isp disabled */ |
| 390 | if ((value & 0x3) == 0x3) |
| 391 | flag |= (1 << 2); |
| 392 | |
| 393 | switch (flag) { |
| 394 | case 7: |
| 395 | return MXC_CPU_IMX8MPL; |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 396 | case 2: |
| 397 | return MXC_CPU_IMX8MP6; |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 398 | default: |
| 399 | break; |
| 400 | } |
| 401 | |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | return type; |
| 405 | } |
| 406 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 407 | u32 get_cpu_rev(void) |
| 408 | { |
| 409 | struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR; |
| 410 | u32 reg = readl(&ana_pll->digprog); |
| 411 | u32 type = (reg >> 16) & 0xff; |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 412 | u32 major_low = (reg >> 8) & 0xff; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 413 | u32 rom_version; |
| 414 | |
| 415 | reg &= 0xff; |
| 416 | |
Peng Fan | 69cec07 | 2019-12-27 10:14:02 +0800 | [diff] [blame] | 417 | /* iMX8MP */ |
| 418 | if (major_low == 0x43) { |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 419 | type = get_cpu_variant_type(MXC_CPU_IMX8MP); |
Peng Fan | 69cec07 | 2019-12-27 10:14:02 +0800 | [diff] [blame] | 420 | } else if (major_low == 0x42) { |
| 421 | /* iMX8MN */ |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 422 | type = get_cpu_variant_type(MXC_CPU_IMX8MN); |
Peng Fan | 5d2f206 | 2019-06-27 17:23:49 +0800 | [diff] [blame] | 423 | } else if (major_low == 0x41) { |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 424 | type = get_cpu_variant_type(MXC_CPU_IMX8MM); |
| 425 | } else { |
| 426 | if (reg == CHIP_REV_1_0) { |
| 427 | /* |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 428 | * For B0 chip, the DIGPROG is not updated, |
| 429 | * it is still TO1.0. we have to check ROM |
| 430 | * version or OCOTP_READ_FUSE_DATA. |
| 431 | * 0xff0055aa is magic number for B1. |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 432 | */ |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 433 | if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) { |
Ye Li | c963ed1 | 2021-03-19 15:57:16 +0800 | [diff] [blame] | 434 | /* |
| 435 | * B2 uses same DIGPROG and OCOTP_READ_FUSE_DATA value with B1, |
| 436 | * so have to check ROM to distinguish them |
| 437 | */ |
| 438 | rom_version = readl((void __iomem *)ROM_VERSION_B0); |
| 439 | rom_version &= 0xff; |
| 440 | if (rom_version == CHIP_REV_2_2) |
| 441 | reg = CHIP_REV_2_2; |
| 442 | else |
| 443 | reg = CHIP_REV_2_1; |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 444 | } else { |
| 445 | rom_version = |
| 446 | readl((void __iomem *)ROM_VERSION_A0); |
| 447 | if (rom_version != CHIP_REV_1_0) { |
| 448 | rom_version = readl((void __iomem *)ROM_VERSION_B0); |
Patrick Wildt | d4a78b9 | 2019-11-19 09:42:06 +0100 | [diff] [blame] | 449 | rom_version &= 0xff; |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 450 | if (rom_version == CHIP_REV_2_0) |
| 451 | reg = CHIP_REV_2_0; |
| 452 | } |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 453 | } |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 454 | } |
Peng Fan | 6781508 | 2020-02-05 17:34:54 +0800 | [diff] [blame] | 455 | |
| 456 | type = get_cpu_variant_type(type); |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | return (type << 12) | reg; |
| 460 | } |
| 461 | |
| 462 | static void imx_set_wdog_powerdown(bool enable) |
| 463 | { |
| 464 | struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 465 | struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR; |
| 466 | struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR; |
| 467 | |
| 468 | /* Write to the PDE (Power Down Enable) bit */ |
| 469 | writew(enable, &wdog1->wmcr); |
| 470 | writew(enable, &wdog2->wmcr); |
| 471 | writew(enable, &wdog3->wmcr); |
| 472 | } |
| 473 | |
Peng Fan | c98e032 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 474 | int arch_cpu_init_dm(void) |
| 475 | { |
| 476 | struct udevice *dev; |
| 477 | int ret; |
| 478 | |
Peng Fan | 3c07334 | 2019-10-16 03:01:51 +0000 | [diff] [blame] | 479 | if (CONFIG_IS_ENABLED(CLK)) { |
| 480 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 481 | "clock-controller@30380000", |
| 482 | &dev); |
| 483 | if (ret < 0) { |
| 484 | printf("Failed to find clock node. Check device tree\n"); |
| 485 | return ret; |
| 486 | } |
Peng Fan | c98e032 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 492 | int arch_cpu_init(void) |
| 493 | { |
Peng Fan | c0b30d7 | 2019-04-17 09:41:16 +0000 | [diff] [blame] | 494 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 495 | /* |
Peng Fan | d0ca289 | 2019-08-27 06:25:37 +0000 | [diff] [blame] | 496 | * ROM might disable clock for SCTR, |
| 497 | * enable the clock before timer_init. |
| 498 | */ |
| 499 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 500 | clock_enable(CCGR_SCTR, 1); |
| 501 | /* |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 502 | * Init timer at very early state, because sscg pll setting |
| 503 | * will use it |
| 504 | */ |
| 505 | timer_init(); |
| 506 | |
| 507 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 508 | clock_init(); |
| 509 | imx_set_wdog_powerdown(false); |
Peng Fan | 9cf2aa3 | 2020-07-09 13:52:41 +0800 | [diff] [blame] | 510 | |
| 511 | if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() || |
| 512 | is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() || |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 513 | is_imx8mnsl() || is_imx8mpd() || is_imx8mnud() || is_imx8mnus()) { |
Peng Fan | 9cf2aa3 | 2020-07-09 13:52:41 +0800 | [diff] [blame] | 514 | /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */ |
| 515 | struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840); |
| 516 | struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880); |
| 517 | struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0); |
| 518 | struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR; |
| 519 | |
| 520 | writel(0x1, &pgc_core2->pgcr); |
| 521 | writel(0x1, &pgc_core3->pgcr); |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 522 | if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) { |
Peng Fan | 9cf2aa3 | 2020-07-09 13:52:41 +0800 | [diff] [blame] | 523 | writel(0x1, &pgc_core1->pgcr); |
| 524 | writel(0xE, &gpc->cpu_pgc_dn_trg); |
| 525 | } else { |
| 526 | writel(0xC, &gpc->cpu_pgc_dn_trg); |
| 527 | } |
| 528 | } |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 529 | } |
| 530 | |
Peng Fan | c0b30d7 | 2019-04-17 09:41:16 +0000 | [diff] [blame] | 531 | if (is_imx8mq()) { |
| 532 | clock_enable(CCGR_OCOTP, 1); |
| 533 | if (readl(&ocotp->ctrl) & 0x200) |
| 534 | writel(0x200, &ocotp->ctrl_clr); |
| 535 | } |
| 536 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 537 | return 0; |
| 538 | } |
| 539 | |
Peng Fan | c9823b0 | 2019-09-16 03:09:36 +0000 | [diff] [blame] | 540 | #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP) |
| 541 | struct rom_api *g_rom_api = (struct rom_api *)0x980; |
| 542 | |
| 543 | enum boot_device get_boot_device(void) |
| 544 | { |
| 545 | volatile gd_t *pgd = gd; |
| 546 | int ret; |
| 547 | u32 boot; |
| 548 | u16 boot_type; |
| 549 | u8 boot_instance; |
| 550 | enum boot_device boot_dev = SD1_BOOT; |
| 551 | |
| 552 | ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, |
| 553 | ((uintptr_t)&boot) ^ QUERY_BT_DEV); |
Marek Behún | a8cf155 | 2021-05-20 13:24:10 +0200 | [diff] [blame] | 554 | set_gd(pgd); |
Peng Fan | c9823b0 | 2019-09-16 03:09:36 +0000 | [diff] [blame] | 555 | |
| 556 | if (ret != ROM_API_OKAY) { |
| 557 | puts("ROMAPI: failure at query_boot_info\n"); |
| 558 | return -1; |
| 559 | } |
| 560 | |
| 561 | boot_type = boot >> 16; |
| 562 | boot_instance = (boot >> 8) & 0xff; |
| 563 | |
| 564 | switch (boot_type) { |
| 565 | case BT_DEV_TYPE_SD: |
| 566 | boot_dev = boot_instance + SD1_BOOT; |
| 567 | break; |
| 568 | case BT_DEV_TYPE_MMC: |
| 569 | boot_dev = boot_instance + MMC1_BOOT; |
| 570 | break; |
| 571 | case BT_DEV_TYPE_NAND: |
| 572 | boot_dev = NAND_BOOT; |
| 573 | break; |
| 574 | case BT_DEV_TYPE_FLEXSPINOR: |
| 575 | boot_dev = QSPI_BOOT; |
| 576 | break; |
| 577 | case BT_DEV_TYPE_USB: |
| 578 | boot_dev = USB_BOOT; |
| 579 | break; |
| 580 | default: |
| 581 | break; |
| 582 | } |
| 583 | |
| 584 | return boot_dev; |
| 585 | } |
| 586 | #endif |
| 587 | |
Marek Vasut | 520ded0 | 2021-07-03 04:55:33 +0200 | [diff] [blame] | 588 | #if defined(CONFIG_IMX8M) |
| 589 | #include <spl.h> |
| 590 | int spl_mmc_emmc_boot_partition(struct mmc *mmc) |
| 591 | { |
| 592 | u32 *rom_log_addr = (u32 *)0x9e0; |
| 593 | u32 *rom_log; |
| 594 | u8 event_id; |
| 595 | int i, part; |
| 596 | |
| 597 | part = default_spl_mmc_emmc_boot_partition(mmc); |
| 598 | |
| 599 | /* If the ROM event log pointer is not valid. */ |
| 600 | if (*rom_log_addr < 0x900000 || *rom_log_addr >= 0xb00000 || |
| 601 | *rom_log_addr & 0x3) |
| 602 | return part; |
| 603 | |
| 604 | /* Parse the ROM event ID version 2 log */ |
| 605 | rom_log = (u32 *)(uintptr_t)(*rom_log_addr); |
| 606 | for (i = 0; i < 128; i++) { |
| 607 | event_id = rom_log[i] >> 24; |
| 608 | switch (event_id) { |
| 609 | case 0x00: /* End of list */ |
| 610 | return part; |
| 611 | /* Log entries with 1 parameter, skip 1 */ |
| 612 | case 0x80: /* Start to perform the device initialization */ |
| 613 | case 0x81: /* The boot device initialization completes */ |
| 614 | case 0x8f: /* The boot device initialization fails */ |
| 615 | case 0x90: /* Start to read data from boot device */ |
| 616 | case 0x91: /* Reading data from boot device completes */ |
| 617 | case 0x9f: /* Reading data from boot device fails */ |
| 618 | i += 1; |
| 619 | continue; |
| 620 | /* Log entries with 2 parameters, skip 2 */ |
| 621 | case 0xa0: /* Image authentication result */ |
| 622 | case 0xc0: /* Jump to the boot image soon */ |
| 623 | i += 2; |
| 624 | continue; |
| 625 | /* Boot from the secondary boot image */ |
| 626 | case 0x51: |
| 627 | /* |
| 628 | * Swap the eMMC boot partitions in case there was a |
| 629 | * fallback event (i.e. primary image was corrupted |
| 630 | * and that corruption was recognized by the BootROM), |
| 631 | * so the SPL loads the rest of the U-Boot from the |
| 632 | * correct eMMC boot partition, since the BootROM |
| 633 | * leaves the boot partition set to the corrupted one. |
| 634 | */ |
| 635 | if (part == 1) |
| 636 | part = 2; |
| 637 | else if (part == 2) |
| 638 | part = 1; |
| 639 | continue; |
| 640 | default: |
| 641 | continue; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | return part; |
| 646 | } |
| 647 | #endif |
| 648 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 649 | bool is_usb_boot(void) |
| 650 | { |
| 651 | return get_boot_device() == USB_BOOT; |
| 652 | } |
| 653 | |
| 654 | #ifdef CONFIG_OF_SYSTEM_SETUP |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 655 | bool check_fdt_new_path(void *blob) |
| 656 | { |
| 657 | const char *soc_path = "/soc@0"; |
| 658 | int nodeoff; |
| 659 | |
| 660 | nodeoff = fdt_path_offset(blob, soc_path); |
| 661 | if (nodeoff < 0) |
| 662 | return false; |
| 663 | |
| 664 | return true; |
| 665 | } |
| 666 | |
| 667 | static int disable_fdt_nodes(void *blob, const char *const nodes_path[], int size_array) |
| 668 | { |
| 669 | int i = 0; |
| 670 | int rc; |
| 671 | int nodeoff; |
| 672 | const char *status = "disabled"; |
| 673 | |
| 674 | for (i = 0; i < size_array; i++) { |
| 675 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 676 | if (nodeoff < 0) |
| 677 | continue; /* Not found, skip it */ |
| 678 | |
| 679 | printf("Found %s node\n", nodes_path[i]); |
| 680 | |
| 681 | add_status: |
| 682 | rc = fdt_setprop(blob, nodeoff, "status", status, strlen(status) + 1); |
| 683 | if (rc) { |
| 684 | if (rc == -FDT_ERR_NOSPACE) { |
| 685 | rc = fdt_increase_size(blob, 512); |
| 686 | if (!rc) |
| 687 | goto add_status; |
| 688 | } |
| 689 | printf("Unable to update property %s:%s, err=%s\n", |
| 690 | nodes_path[i], "status", fdt_strerror(rc)); |
| 691 | } else { |
| 692 | printf("Modify %s:%s disabled\n", |
| 693 | nodes_path[i], "status"); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | #ifdef CONFIG_IMX8MQ |
| 701 | bool check_dcss_fused(void) |
| 702 | { |
| 703 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 704 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 705 | struct fuse_bank1_regs *fuse = |
| 706 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 707 | u32 value = readl(&fuse->tester4); |
| 708 | |
| 709 | if (value & 0x4000000) |
| 710 | return true; |
| 711 | |
| 712 | return false; |
| 713 | } |
| 714 | |
| 715 | static int disable_mipi_dsi_nodes(void *blob) |
| 716 | { |
| 717 | static const char * const nodes_path[] = { |
| 718 | "/mipi_dsi@30A00000", |
| 719 | "/mipi_dsi_bridge@30A00000", |
| 720 | "/dsi_phy@30A00300", |
| 721 | "/soc@0/bus@30800000/mipi_dsi@30a00000", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 722 | "/soc@0/bus@30800000/dphy@30a00300", |
| 723 | "/soc@0/bus@30800000/mipi-dsi@30a00000", |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 724 | }; |
| 725 | |
| 726 | return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path)); |
| 727 | } |
| 728 | |
| 729 | static int disable_dcss_nodes(void *blob) |
| 730 | { |
| 731 | static const char * const nodes_path[] = { |
| 732 | "/dcss@0x32e00000", |
| 733 | "/dcss@32e00000", |
| 734 | "/hdmi@32c00000", |
| 735 | "/hdmi_cec@32c33800", |
| 736 | "/hdmi_drm@32c00000", |
| 737 | "/display-subsystem", |
| 738 | "/sound-hdmi", |
| 739 | "/sound-hdmi-arc", |
| 740 | "/soc@0/bus@32c00000/display-controller@32e00000", |
| 741 | "/soc@0/bus@32c00000/hdmi@32c00000", |
| 742 | }; |
| 743 | |
| 744 | return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path)); |
| 745 | } |
| 746 | |
| 747 | static int check_mipi_dsi_nodes(void *blob) |
| 748 | { |
| 749 | static const char * const lcdif_path[] = { |
| 750 | "/lcdif@30320000", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 751 | "/soc@0/bus@30000000/lcdif@30320000", |
| 752 | "/soc@0/bus@30000000/lcd-controller@30320000" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 753 | }; |
| 754 | static const char * const mipi_dsi_path[] = { |
| 755 | "/mipi_dsi@30A00000", |
| 756 | "/soc@0/bus@30800000/mipi_dsi@30a00000" |
| 757 | }; |
| 758 | static const char * const lcdif_ep_path[] = { |
| 759 | "/lcdif@30320000/port@0/mipi-dsi-endpoint", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 760 | "/soc@0/bus@30000000/lcdif@30320000/port@0/endpoint", |
| 761 | "/soc@0/bus@30000000/lcd-controller@30320000/port@0/endpoint" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 762 | }; |
| 763 | static const char * const mipi_dsi_ep_path[] = { |
| 764 | "/mipi_dsi@30A00000/port@1/endpoint", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 765 | "/soc@0/bus@30800000/mipi_dsi@30a00000/ports/port@0/endpoint", |
| 766 | "/soc@0/bus@30800000/mipi-dsi@30a00000/ports/port@0/endpoint@0" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 767 | }; |
| 768 | |
| 769 | int lookup_node; |
| 770 | int nodeoff; |
| 771 | bool new_path = check_fdt_new_path(blob); |
| 772 | int i = new_path ? 1 : 0; |
| 773 | |
| 774 | nodeoff = fdt_path_offset(blob, lcdif_path[i]); |
| 775 | if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) { |
| 776 | /* |
| 777 | * If can't find lcdif node or lcdif node is disabled, |
| 778 | * then disable all mipi dsi, since they only can input |
| 779 | * from DCSS |
| 780 | */ |
| 781 | return disable_mipi_dsi_nodes(blob); |
| 782 | } |
| 783 | |
| 784 | nodeoff = fdt_path_offset(blob, mipi_dsi_path[i]); |
| 785 | if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) |
| 786 | return 0; |
| 787 | |
| 788 | nodeoff = fdt_path_offset(blob, lcdif_ep_path[i]); |
| 789 | if (nodeoff < 0) { |
| 790 | /* |
| 791 | * If can't find lcdif endpoint, then disable all mipi dsi, |
| 792 | * since they only can input from DCSS |
| 793 | */ |
| 794 | return disable_mipi_dsi_nodes(blob); |
| 795 | } |
| 796 | |
| 797 | lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint"); |
| 798 | nodeoff = fdt_path_offset(blob, mipi_dsi_ep_path[i]); |
| 799 | |
| 800 | if (nodeoff > 0 && nodeoff == lookup_node) |
| 801 | return 0; |
| 802 | |
| 803 | return disable_mipi_dsi_nodes(blob); |
| 804 | } |
| 805 | #endif |
| 806 | |
| 807 | int disable_vpu_nodes(void *blob) |
| 808 | { |
| 809 | static const char * const nodes_path_8mq[] = { |
| 810 | "/vpu@38300000", |
| 811 | "/soc@0/vpu@38300000" |
| 812 | }; |
| 813 | |
| 814 | static const char * const nodes_path_8mm[] = { |
| 815 | "/vpu_g1@38300000", |
| 816 | "/vpu_g2@38310000", |
| 817 | "/vpu_h1@38320000" |
| 818 | }; |
| 819 | |
| 820 | static const char * const nodes_path_8mp[] = { |
| 821 | "/vpu_g1@38300000", |
| 822 | "/vpu_g2@38310000", |
| 823 | "/vpu_vc8000e@38320000" |
| 824 | }; |
| 825 | |
| 826 | if (is_imx8mq()) |
| 827 | return disable_fdt_nodes(blob, nodes_path_8mq, ARRAY_SIZE(nodes_path_8mq)); |
| 828 | else if (is_imx8mm()) |
| 829 | return disable_fdt_nodes(blob, nodes_path_8mm, ARRAY_SIZE(nodes_path_8mm)); |
| 830 | else if (is_imx8mp()) |
| 831 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 832 | else |
| 833 | return -EPERM; |
| 834 | } |
| 835 | |
Ye Li | ee337ce | 2021-03-19 15:57:09 +0800 | [diff] [blame] | 836 | #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE |
| 837 | static int low_drive_gpu_freq(void *blob) |
| 838 | { |
| 839 | static const char *nodes_path_8mn[] = { |
| 840 | "/gpu@38000000", |
| 841 | "/soc@0/gpu@38000000" |
| 842 | }; |
| 843 | |
| 844 | int nodeoff, cnt, i; |
| 845 | u32 assignedclks[7]; |
| 846 | |
| 847 | nodeoff = fdt_path_offset(blob, nodes_path_8mn[0]); |
| 848 | if (nodeoff < 0) |
| 849 | return nodeoff; |
| 850 | |
| 851 | cnt = fdtdec_get_int_array_count(blob, nodeoff, "assigned-clock-rates", assignedclks, 7); |
| 852 | if (cnt < 0) |
| 853 | return cnt; |
| 854 | |
| 855 | if (cnt != 7) |
| 856 | printf("Warning: %s, assigned-clock-rates count %d\n", nodes_path_8mn[0], cnt); |
| 857 | |
| 858 | assignedclks[cnt - 1] = 200000000; |
| 859 | assignedclks[cnt - 2] = 200000000; |
| 860 | |
| 861 | for (i = 0; i < cnt; i++) { |
| 862 | debug("<%u>, ", assignedclks[i]); |
| 863 | assignedclks[i] = cpu_to_fdt32(assignedclks[i]); |
| 864 | } |
| 865 | debug("\n"); |
| 866 | |
| 867 | return fdt_setprop(blob, nodeoff, "assigned-clock-rates", &assignedclks, sizeof(assignedclks)); |
| 868 | } |
| 869 | #endif |
| 870 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 871 | int disable_gpu_nodes(void *blob) |
| 872 | { |
| 873 | static const char * const nodes_path_8mn[] = { |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 874 | "/gpu@38000000", |
| 875 | "/soc@/gpu@38000000" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 876 | }; |
| 877 | |
| 878 | return disable_fdt_nodes(blob, nodes_path_8mn, ARRAY_SIZE(nodes_path_8mn)); |
| 879 | } |
| 880 | |
| 881 | int disable_npu_nodes(void *blob) |
| 882 | { |
| 883 | static const char * const nodes_path_8mp[] = { |
| 884 | "/vipsi@38500000" |
| 885 | }; |
| 886 | |
| 887 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 888 | } |
| 889 | |
| 890 | int disable_isp_nodes(void *blob) |
| 891 | { |
| 892 | static const char * const nodes_path_8mp[] = { |
| 893 | "/soc@0/bus@32c00000/camera/isp@32e10000", |
| 894 | "/soc@0/bus@32c00000/camera/isp@32e20000" |
| 895 | }; |
| 896 | |
| 897 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 898 | } |
| 899 | |
| 900 | int disable_dsp_nodes(void *blob) |
| 901 | { |
| 902 | static const char * const nodes_path_8mp[] = { |
| 903 | "/dsp@3b6e8000" |
| 904 | }; |
| 905 | |
| 906 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 907 | } |
| 908 | |
Ye Li | 26517af | 2021-03-19 15:57:12 +0800 | [diff] [blame] | 909 | static void disable_thermal_cpu_nodes(void *blob, u32 disabled_cores) |
| 910 | { |
| 911 | static const char * const thermal_path[] = { |
| 912 | "/thermal-zones/cpu-thermal/cooling-maps/map0" |
| 913 | }; |
| 914 | |
| 915 | int nodeoff, cnt, i, ret, j; |
| 916 | u32 cooling_dev[12]; |
| 917 | |
| 918 | for (i = 0; i < ARRAY_SIZE(thermal_path); i++) { |
| 919 | nodeoff = fdt_path_offset(blob, thermal_path[i]); |
| 920 | if (nodeoff < 0) |
| 921 | continue; /* Not found, skip it */ |
| 922 | |
| 923 | cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", cooling_dev, 12); |
| 924 | if (cnt < 0) |
| 925 | continue; |
| 926 | |
| 927 | if (cnt != 12) |
| 928 | printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt); |
| 929 | |
| 930 | for (j = 0; j < cnt; j++) |
| 931 | cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]); |
| 932 | |
| 933 | ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev, |
| 934 | sizeof(u32) * (12 - disabled_cores * 3)); |
| 935 | if (ret < 0) { |
| 936 | printf("Warning: %s, cooling-device setprop failed %d\n", |
| 937 | thermal_path[i], ret); |
| 938 | continue; |
| 939 | } |
| 940 | |
| 941 | printf("Update node %s, cooling-device prop\n", thermal_path[i]); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | static void disable_pmu_cpu_nodes(void *blob, u32 disabled_cores) |
| 946 | { |
| 947 | static const char * const pmu_path[] = { |
| 948 | "/pmu" |
| 949 | }; |
| 950 | |
| 951 | int nodeoff, cnt, i, ret, j; |
| 952 | u32 irq_affinity[4]; |
| 953 | |
| 954 | for (i = 0; i < ARRAY_SIZE(pmu_path); i++) { |
| 955 | nodeoff = fdt_path_offset(blob, pmu_path[i]); |
| 956 | if (nodeoff < 0) |
| 957 | continue; /* Not found, skip it */ |
| 958 | |
| 959 | cnt = fdtdec_get_int_array_count(blob, nodeoff, "interrupt-affinity", |
| 960 | irq_affinity, 4); |
| 961 | if (cnt < 0) |
| 962 | continue; |
| 963 | |
| 964 | if (cnt != 4) |
| 965 | printf("Warning: %s, interrupt-affinity count %d\n", pmu_path[i], cnt); |
| 966 | |
| 967 | for (j = 0; j < cnt; j++) |
| 968 | irq_affinity[j] = cpu_to_fdt32(irq_affinity[j]); |
| 969 | |
| 970 | ret = fdt_setprop(blob, nodeoff, "interrupt-affinity", &irq_affinity, |
| 971 | sizeof(u32) * (4 - disabled_cores)); |
| 972 | if (ret < 0) { |
| 973 | printf("Warning: %s, interrupt-affinity setprop failed %d\n", |
| 974 | pmu_path[i], ret); |
| 975 | continue; |
| 976 | } |
| 977 | |
| 978 | printf("Update node %s, interrupt-affinity prop\n", pmu_path[i]); |
| 979 | } |
| 980 | } |
| 981 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 982 | static int disable_cpu_nodes(void *blob, u32 disabled_cores) |
| 983 | { |
| 984 | static const char * const nodes_path[] = { |
| 985 | "/cpus/cpu@1", |
| 986 | "/cpus/cpu@2", |
| 987 | "/cpus/cpu@3", |
| 988 | }; |
| 989 | u32 i = 0; |
| 990 | int rc; |
| 991 | int nodeoff; |
| 992 | |
| 993 | if (disabled_cores > 3) |
| 994 | return -EINVAL; |
| 995 | |
| 996 | i = 3 - disabled_cores; |
| 997 | |
| 998 | for (; i < 3; i++) { |
| 999 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 1000 | if (nodeoff < 0) |
| 1001 | continue; /* Not found, skip it */ |
| 1002 | |
| 1003 | debug("Found %s node\n", nodes_path[i]); |
| 1004 | |
| 1005 | rc = fdt_del_node(blob, nodeoff); |
| 1006 | if (rc < 0) { |
| 1007 | printf("Unable to delete node %s, err=%s\n", |
| 1008 | nodes_path[i], fdt_strerror(rc)); |
| 1009 | } else { |
| 1010 | printf("Delete node %s\n", nodes_path[i]); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Ye Li | 26517af | 2021-03-19 15:57:12 +0800 | [diff] [blame] | 1014 | disable_thermal_cpu_nodes(blob, disabled_cores); |
| 1015 | disable_pmu_cpu_nodes(blob, disabled_cores); |
| 1016 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1020 | int ft_system_setup(void *blob, struct bd_info *bd) |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1021 | { |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1022 | #ifdef CONFIG_IMX8MQ |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1023 | int i = 0; |
| 1024 | int rc; |
| 1025 | int nodeoff; |
| 1026 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1027 | if (get_boot_device() == USB_BOOT) { |
| 1028 | disable_dcss_nodes(blob); |
| 1029 | |
| 1030 | bool new_path = check_fdt_new_path(blob); |
| 1031 | int v = new_path ? 1 : 0; |
| 1032 | static const char * const usb_dwc3_path[] = { |
| 1033 | "/usb@38100000/dwc3", |
| 1034 | "/soc@0/usb@38100000" |
| 1035 | }; |
| 1036 | |
| 1037 | nodeoff = fdt_path_offset(blob, usb_dwc3_path[v]); |
| 1038 | if (nodeoff >= 0) { |
| 1039 | const char *speed = "high-speed"; |
| 1040 | |
| 1041 | printf("Found %s node\n", usb_dwc3_path[v]); |
| 1042 | |
| 1043 | usb_modify_speed: |
| 1044 | |
| 1045 | rc = fdt_setprop(blob, nodeoff, "maximum-speed", speed, strlen(speed) + 1); |
| 1046 | if (rc) { |
| 1047 | if (rc == -FDT_ERR_NOSPACE) { |
| 1048 | rc = fdt_increase_size(blob, 512); |
| 1049 | if (!rc) |
| 1050 | goto usb_modify_speed; |
| 1051 | } |
| 1052 | printf("Unable to set property %s:%s, err=%s\n", |
| 1053 | usb_dwc3_path[v], "maximum-speed", fdt_strerror(rc)); |
| 1054 | } else { |
| 1055 | printf("Modify %s:%s = %s\n", |
| 1056 | usb_dwc3_path[v], "maximum-speed", speed); |
| 1057 | } |
| 1058 | } else { |
| 1059 | printf("Can't found %s node\n", usb_dwc3_path[v]); |
| 1060 | } |
| 1061 | } |
| 1062 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1063 | /* Disable the CPU idle for A0 chip since the HW does not support it */ |
| 1064 | if (is_soc_rev(CHIP_REV_1_0)) { |
| 1065 | static const char * const nodes_path[] = { |
| 1066 | "/cpus/cpu@0", |
| 1067 | "/cpus/cpu@1", |
| 1068 | "/cpus/cpu@2", |
| 1069 | "/cpus/cpu@3", |
| 1070 | }; |
| 1071 | |
| 1072 | for (i = 0; i < ARRAY_SIZE(nodes_path); i++) { |
| 1073 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 1074 | if (nodeoff < 0) |
| 1075 | continue; /* Not found, skip it */ |
| 1076 | |
Marek Vasut | e2e7a77 | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 1077 | debug("Found %s node\n", nodes_path[i]); |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1078 | |
| 1079 | rc = fdt_delprop(blob, nodeoff, "cpu-idle-states"); |
Marek Vasut | e2e7a77 | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 1080 | if (rc == -FDT_ERR_NOTFOUND) |
| 1081 | continue; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1082 | if (rc) { |
| 1083 | printf("Unable to update property %s:%s, err=%s\n", |
| 1084 | nodes_path[i], "status", fdt_strerror(rc)); |
| 1085 | return rc; |
| 1086 | } |
| 1087 | |
Marek Vasut | e2e7a77 | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 1088 | debug("Remove %s:%s\n", nodes_path[i], |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1089 | "cpu-idle-states"); |
| 1090 | } |
| 1091 | } |
| 1092 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1093 | if (is_imx8mql()) { |
| 1094 | disable_vpu_nodes(blob); |
| 1095 | if (check_dcss_fused()) { |
| 1096 | printf("DCSS is fused\n"); |
| 1097 | disable_dcss_nodes(blob); |
| 1098 | check_mipi_dsi_nodes(blob); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | if (is_imx8md()) |
| 1103 | disable_cpu_nodes(blob, 2); |
| 1104 | |
| 1105 | #elif defined(CONFIG_IMX8MM) |
| 1106 | if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl()) |
| 1107 | disable_vpu_nodes(blob); |
| 1108 | |
| 1109 | if (is_imx8mmd() || is_imx8mmdl()) |
| 1110 | disable_cpu_nodes(blob, 2); |
| 1111 | else if (is_imx8mms() || is_imx8mmsl()) |
| 1112 | disable_cpu_nodes(blob, 3); |
| 1113 | |
| 1114 | #elif defined(CONFIG_IMX8MN) |
| 1115 | if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl()) |
| 1116 | disable_gpu_nodes(blob); |
Ye Li | ee337ce | 2021-03-19 15:57:09 +0800 | [diff] [blame] | 1117 | #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE |
| 1118 | else { |
| 1119 | int ldm_gpu = low_drive_gpu_freq(blob); |
| 1120 | |
| 1121 | if (ldm_gpu < 0) |
| 1122 | printf("Update GPU node assigned-clock-rates failed\n"); |
| 1123 | else |
| 1124 | printf("Update GPU node assigned-clock-rates ok\n"); |
| 1125 | } |
| 1126 | #endif |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1127 | |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 1128 | if (is_imx8mnd() || is_imx8mndl() || is_imx8mnud()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1129 | disable_cpu_nodes(blob, 2); |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 1130 | else if (is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1131 | disable_cpu_nodes(blob, 3); |
| 1132 | |
| 1133 | #elif defined(CONFIG_IMX8MP) |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1134 | if (is_imx8mpl()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1135 | disable_vpu_nodes(blob); |
| 1136 | |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1137 | if (is_imx8mpl() || is_imx8mp6()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1138 | disable_npu_nodes(blob); |
| 1139 | |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1140 | if (is_imx8mpl()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1141 | disable_isp_nodes(blob); |
| 1142 | |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1143 | if (is_imx8mpl() || is_imx8mp6()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1144 | disable_dsp_nodes(blob); |
| 1145 | |
| 1146 | if (is_imx8mpd()) |
| 1147 | disable_cpu_nodes(blob, 2); |
| 1148 | #endif |
| 1149 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
| 1152 | #endif |
| 1153 | |
Marek Vasut | 64dc4de | 2020-04-29 15:04:21 +0200 | [diff] [blame] | 1154 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 1155 | void reset_cpu(void) |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1156 | { |
Claudius Heine | e73f394 | 2020-04-29 15:04:23 +0200 | [diff] [blame] | 1157 | struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1158 | |
Ye Li | 54a915a | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 1159 | /* Clear WDA to trigger WDOG_B immediately */ |
| 1160 | writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr); |
Peng Fan | 24290d9 | 2019-08-27 06:25:41 +0000 | [diff] [blame] | 1161 | |
Ye Li | 54a915a | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 1162 | while (1) { |
| 1163 | /* |
Harald Seiler | ec0c447 | 2020-04-29 15:04:22 +0200 | [diff] [blame] | 1164 | * spin for .5 seconds before reset |
Ye Li | 54a915a | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 1165 | */ |
| 1166 | } |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1167 | } |
Peng Fan | 24290d9 | 2019-08-27 06:25:41 +0000 | [diff] [blame] | 1168 | #endif |
Peng Fan | 5760d8d | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 1169 | |
| 1170 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 1171 | static void acquire_buildinfo(void) |
| 1172 | { |
| 1173 | u64 atf_commit = 0; |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 1174 | struct arm_smccc_res res; |
Peng Fan | 5760d8d | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 1175 | |
| 1176 | /* Get ARM Trusted Firmware commit id */ |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 1177 | arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH, |
Fabio Estevam | 31e410f | 2020-07-17 16:36:54 -0300 | [diff] [blame] | 1178 | 0, 0, 0, 0, 0, 0, &res); |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 1179 | atf_commit = res.a0; |
Peng Fan | 5760d8d | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 1180 | if (atf_commit == 0xffffffff) { |
| 1181 | debug("ATF does not support build info\n"); |
| 1182 | atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */ |
| 1183 | } |
| 1184 | |
| 1185 | printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit); |
| 1186 | } |
| 1187 | |
| 1188 | int arch_misc_init(void) |
| 1189 | { |
| 1190 | acquire_buildinfo(); |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
| 1194 | #endif |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 1195 | |
| 1196 | void imx_tmu_arch_init(void *reg_base) |
| 1197 | { |
Ye Li | a00f2f0 | 2020-05-03 22:19:53 +0800 | [diff] [blame] | 1198 | if (is_imx8mm() || is_imx8mn()) { |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 1199 | /* Load TCALIV and TASR from fuses */ |
| 1200 | struct ocotp_regs *ocotp = |
| 1201 | (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 1202 | struct fuse_bank *bank = &ocotp->bank[3]; |
| 1203 | struct fuse_bank3_regs *fuse = |
| 1204 | (struct fuse_bank3_regs *)bank->fuse_regs; |
| 1205 | |
| 1206 | u32 tca_rt, tca_hr, tca_en; |
| 1207 | u32 buf_vref, buf_slope; |
| 1208 | |
| 1209 | tca_rt = fuse->ana0 & 0xFF; |
| 1210 | tca_hr = (fuse->ana0 & 0xFF00) >> 8; |
| 1211 | tca_en = (fuse->ana0 & 0x2000000) >> 25; |
| 1212 | |
| 1213 | buf_vref = (fuse->ana0 & 0x1F00000) >> 20; |
| 1214 | buf_slope = (fuse->ana0 & 0xF0000) >> 16; |
| 1215 | |
| 1216 | writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28); |
| 1217 | writel((tca_en << 31) | (tca_hr << 16) | tca_rt, |
| 1218 | (ulong)reg_base + 0x30); |
| 1219 | } |
Ye Li | 41a2025 | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 1220 | #ifdef CONFIG_IMX8MP |
| 1221 | /* Load TCALIV0/1/m40 and TRIM from fuses */ |
| 1222 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 1223 | struct fuse_bank *bank = &ocotp->bank[38]; |
| 1224 | struct fuse_bank38_regs *fuse = |
| 1225 | (struct fuse_bank38_regs *)bank->fuse_regs; |
| 1226 | struct fuse_bank *bank2 = &ocotp->bank[39]; |
| 1227 | struct fuse_bank39_regs *fuse2 = |
| 1228 | (struct fuse_bank39_regs *)bank2->fuse_regs; |
| 1229 | u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr; |
| 1230 | u32 reg; |
| 1231 | u32 tca40[2], tca25[2], tca105[2]; |
| 1232 | |
| 1233 | /* For blank sample */ |
| 1234 | if (!fuse->ana_trim2 && !fuse->ana_trim3 && |
| 1235 | !fuse->ana_trim4 && !fuse2->ana_trim5) { |
| 1236 | /* Use a default 25C binary codes */ |
| 1237 | tca25[0] = 1596; |
Ye Li | d756ca0 | 2020-05-03 22:19:55 +0800 | [diff] [blame] | 1238 | tca25[1] = 1596; |
Ye Li | 41a2025 | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 1239 | writel(tca25[0], (ulong)reg_base + 0x30); |
Ye Li | d756ca0 | 2020-05-03 22:19:55 +0800 | [diff] [blame] | 1240 | writel(tca25[1], (ulong)reg_base + 0x34); |
Ye Li | 41a2025 | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 1241 | return; |
| 1242 | } |
| 1243 | |
| 1244 | buf_vref = (fuse->ana_trim2 & 0xc0) >> 6; |
| 1245 | buf_slope = (fuse->ana_trim2 & 0xF00) >> 8; |
| 1246 | bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12; |
| 1247 | bgr = (fuse->ana_trim2 & 0xF0000) >> 16; |
| 1248 | vlsb = (fuse->ana_trim2 & 0xF00000) >> 20; |
| 1249 | writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28); |
| 1250 | |
| 1251 | reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7); |
| 1252 | writel(reg, (ulong)reg_base + 0x3c); |
| 1253 | |
| 1254 | tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16; |
| 1255 | tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28; |
| 1256 | tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4); |
| 1257 | tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8; |
| 1258 | tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20; |
| 1259 | tca25[1] = fuse2->ana_trim5 & 0xFFF; |
| 1260 | tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12; |
| 1261 | |
| 1262 | /* use 25c for 1p calibration */ |
| 1263 | writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30); |
| 1264 | writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34); |
| 1265 | writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38); |
| 1266 | #endif |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 1267 | } |
Peng Fan | a35215d | 2020-07-09 13:39:26 +0800 | [diff] [blame] | 1268 | |
| 1269 | #if defined(CONFIG_SPL_BUILD) |
| 1270 | #if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN) |
| 1271 | bool serror_need_skip = true; |
| 1272 | |
| 1273 | void do_error(struct pt_regs *pt_regs, unsigned int esr) |
| 1274 | { |
| 1275 | /* |
| 1276 | * If stack is still in ROM reserved OCRAM not switch to SPL, |
| 1277 | * it is the ROM SError |
| 1278 | */ |
| 1279 | ulong sp; |
| 1280 | |
| 1281 | asm volatile("mov %0, sp" : "=r"(sp) : ); |
| 1282 | |
| 1283 | if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) { |
| 1284 | /* Check for ERR050342, imx8mq HDCP enabled parts */ |
| 1285 | if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) { |
| 1286 | serror_need_skip = false; |
| 1287 | return; /* Do nothing skip the SError in ROM */ |
| 1288 | } |
| 1289 | |
| 1290 | /* Check for ERR050350, field return mode for imx8mq, mm and mn */ |
| 1291 | if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) { |
| 1292 | serror_need_skip = false; |
| 1293 | return; /* Do nothing skip the SError in ROM */ |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | efi_restore_gd(); |
| 1298 | printf("\"Error\" handler, esr 0x%08x\n", esr); |
| 1299 | show_regs(pt_regs); |
| 1300 | panic("Resetting CPU ...\n"); |
| 1301 | } |
| 1302 | #endif |
| 1303 | #endif |
Ye Li | 0513f36 | 2019-07-15 01:16:46 -0700 | [diff] [blame] | 1304 | |
| 1305 | #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP) |
| 1306 | enum env_location env_get_location(enum env_operation op, int prio) |
| 1307 | { |
| 1308 | enum boot_device dev = get_boot_device(); |
| 1309 | enum env_location env_loc = ENVL_UNKNOWN; |
| 1310 | |
| 1311 | if (prio) |
| 1312 | return env_loc; |
| 1313 | |
| 1314 | switch (dev) { |
| 1315 | #ifdef CONFIG_ENV_IS_IN_SPI_FLASH |
| 1316 | case QSPI_BOOT: |
| 1317 | env_loc = ENVL_SPI_FLASH; |
| 1318 | break; |
| 1319 | #endif |
| 1320 | #ifdef CONFIG_ENV_IS_IN_NAND |
| 1321 | case NAND_BOOT: |
| 1322 | env_loc = ENVL_NAND; |
| 1323 | break; |
| 1324 | #endif |
| 1325 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 1326 | case SD1_BOOT: |
| 1327 | case SD2_BOOT: |
| 1328 | case SD3_BOOT: |
| 1329 | case MMC1_BOOT: |
| 1330 | case MMC2_BOOT: |
| 1331 | case MMC3_BOOT: |
| 1332 | env_loc = ENVL_MMC; |
| 1333 | break; |
| 1334 | #endif |
| 1335 | default: |
| 1336 | #if defined(CONFIG_ENV_IS_NOWHERE) |
| 1337 | env_loc = ENVL_NOWHERE; |
| 1338 | #endif |
| 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | return env_loc; |
| 1343 | } |
| 1344 | |
| 1345 | #ifndef ENV_IS_EMBEDDED |
| 1346 | long long env_get_offset(long long defautl_offset) |
| 1347 | { |
| 1348 | enum boot_device dev = get_boot_device(); |
| 1349 | |
| 1350 | switch (dev) { |
| 1351 | case NAND_BOOT: |
| 1352 | return (60 << 20); /* 60MB offset for NAND */ |
| 1353 | default: |
| 1354 | break; |
| 1355 | } |
| 1356 | |
| 1357 | return defautl_offset; |
| 1358 | } |
| 1359 | #endif |
| 1360 | #endif |