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