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