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