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