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