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