Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 2 | /* |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 3 | * Copyright 2017-2019 NXP |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 4 | * |
| 5 | * Peng Fan <peng.fan@nxp.com> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 12 | #include <asm/arch/imx-regs.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/mach-imx/hab.h> |
| 18 | #include <asm/mach-imx/boot_mode.h> |
| 19 | #include <asm/mach-imx/syscounter.h> |
Peng Fan | a35215d | 2020-07-09 13:39:26 +0800 | [diff] [blame] | 20 | #include <asm/ptrace.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 21 | #include <asm/armv8/mmu.h> |
Peng Fan | c98e032 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 22 | #include <dm/uclass.h> |
Peng Fan | a35215d | 2020-07-09 13:39:26 +0800 | [diff] [blame] | 23 | #include <efi_loader.h> |
Ye Li | 0513f36 | 2019-07-15 01:16:46 -0700 | [diff] [blame] | 24 | #include <env.h> |
| 25 | #include <env_internal.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 26 | #include <errno.h> |
| 27 | #include <fdt_support.h> |
| 28 | #include <fsl_wdog.h> |
| 29 | #include <imx_sip.h> |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 30 | #include <linux/arm-smccc.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 31 | #include <linux/bitops.h> |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 35 | #if defined(CONFIG_IMX_HAB) |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 36 | struct imx_sec_config_fuse_t const imx_sec_config_fuse = { |
| 37 | .bank = 1, |
| 38 | .word = 3, |
| 39 | }; |
| 40 | #endif |
| 41 | |
| 42 | int timer_init(void) |
| 43 | { |
| 44 | #ifdef CONFIG_SPL_BUILD |
| 45 | struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR; |
| 46 | unsigned long freq = readl(&sctr->cntfid0); |
| 47 | |
| 48 | /* Update with accurate clock frequency */ |
| 49 | asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory"); |
| 50 | |
| 51 | clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1, |
| 52 | SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG); |
| 53 | #endif |
| 54 | |
| 55 | gd->arch.tbl = 0; |
| 56 | gd->arch.tbu = 0; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | void enable_tzc380(void) |
| 62 | { |
| 63 | struct iomuxc_gpr_base_regs *gpr = |
| 64 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 65 | |
| 66 | /* Enable TZASC and lock setting */ |
| 67 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN); |
| 68 | setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK); |
Peng Fan | c0e47fc | 2019-12-27 10:19:42 +0800 | [diff] [blame] | 69 | if (is_imx8mm() || is_imx8mn() || is_imx8mp()) |
Peng Fan | 99047fc | 2019-08-27 06:25:30 +0000 | [diff] [blame] | 70 | setbits_le32(&gpr->gpr[10], BIT(1)); |
Ye Li | 4c97c46 | 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 | eae4de2 | 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 | 5c72a45 | 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 | eae4de2 | 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 | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 134 | .size = PHYS_SDRAM_SIZE, |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 135 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 136 | PTE_BLOCK_OUTER_SHARE |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 137 | #ifdef PHYS_SDRAM_2_SIZE |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 138 | }, { |
| 139 | /* DRAM2 */ |
| 140 | .virt = 0x100000000UL, |
| 141 | .phys = 0x100000000UL, |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 142 | .size = PHYS_SDRAM_2_SIZE, |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 143 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 144 | PTE_BLOCK_OUTER_SHARE |
Peng Fan | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 145 | #endif |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 146 | }, { |
Peng Fan | fa35c3d | 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 | eae4de2 | 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 | e48aac0 | 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 | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 168 | void enable_caches(void) |
| 169 | { |
Peng Fan | fa35c3d | 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 | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 181 | int entry = imx8m_find_dram_entry_in_mem_map(); |
Peng Fan | fa35c3d | 2020-07-09 15:26:06 +0800 | [diff] [blame] | 182 | u64 attrs = imx8m_mem_map[entry].attrs; |
| 183 | |
Marek Vasut | e48aac0 | 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 | fa35c3d | 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 | b749b5e | 2019-08-27 06:25:27 +0000 | [diff] [blame] | 197 | |
| 198 | icache_enable(); |
| 199 | dcache_enable(); |
| 200 | } |
| 201 | |
Peng Fan | fa35c3d | 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 | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 213 | unsigned int entry = imx8m_find_dram_entry_in_mem_map(); |
Peng Fan | fa35c3d | 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 | 32927bc | 2020-09-25 08:08:35 -0700 | [diff] [blame] | 227 | /* also update the SDRAM size in the mem_map used externally */ |
Marek Vasut | e48aac0 | 2021-02-27 14:59:00 +0100 | [diff] [blame] | 228 | imx8m_mem_map[entry].size = sdram_size; |
Tim Harvey | 32927bc | 2020-09-25 08:08:35 -0700 | [diff] [blame] | 229 | |
Peng Fan | fa35c3d | 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 | 1caffdf | 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 | 6781508 | 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 | 1caffdf | 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 | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 324 | } else if (type == MXC_CPU_IMX8MN) { |
| 325 | switch (value & 0x3) { |
| 326 | case 2: |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 327 | if (value & 0x1000000) { |
| 328 | if (value & 0x10000000) /* MIPI DSI */ |
| 329 | return MXC_CPU_IMX8MNUD; |
| 330 | else |
| 331 | return MXC_CPU_IMX8MNDL; |
| 332 | } else { |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 333 | return MXC_CPU_IMX8MND; |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 334 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 335 | case 3: |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 336 | if (value & 0x1000000) { |
| 337 | if (value & 0x10000000) /* MIPI DSI */ |
| 338 | return MXC_CPU_IMX8MNUS; |
| 339 | else |
| 340 | return MXC_CPU_IMX8MNSL; |
| 341 | } else { |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 342 | return MXC_CPU_IMX8MNS; |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 343 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 344 | default: |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 345 | if (value & 0x1000000) { |
| 346 | if (value & 0x10000000) /* MIPI DSI */ |
| 347 | return MXC_CPU_IMX8MNUQ; |
| 348 | else |
| 349 | return MXC_CPU_IMX8MNL; |
| 350 | } |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 351 | break; |
| 352 | } |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 353 | } else if (type == MXC_CPU_IMX8MP) { |
| 354 | u32 value0 = readl(&fuse->tester3); |
| 355 | u32 flag = 0; |
| 356 | |
| 357 | if ((value0 & 0xc0000) == 0x80000) |
| 358 | return MXC_CPU_IMX8MPD; |
| 359 | |
| 360 | /* vpu disabled */ |
| 361 | if ((value0 & 0x43000000) == 0x43000000) |
| 362 | flag = 1; |
| 363 | |
| 364 | /* npu disabled*/ |
| 365 | if ((value & 0x8) == 0x8) |
| 366 | flag |= (1 << 1); |
| 367 | |
| 368 | /* isp disabled */ |
| 369 | if ((value & 0x3) == 0x3) |
| 370 | flag |= (1 << 2); |
| 371 | |
| 372 | switch (flag) { |
| 373 | case 7: |
| 374 | return MXC_CPU_IMX8MPL; |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 375 | case 2: |
| 376 | return MXC_CPU_IMX8MP6; |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 377 | default: |
| 378 | break; |
| 379 | } |
| 380 | |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | return type; |
| 384 | } |
| 385 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 386 | u32 get_cpu_rev(void) |
| 387 | { |
| 388 | struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR; |
| 389 | u32 reg = readl(&ana_pll->digprog); |
| 390 | u32 type = (reg >> 16) & 0xff; |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 391 | u32 major_low = (reg >> 8) & 0xff; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 392 | u32 rom_version; |
| 393 | |
| 394 | reg &= 0xff; |
| 395 | |
Peng Fan | 69cec07 | 2019-12-27 10:14:02 +0800 | [diff] [blame] | 396 | /* iMX8MP */ |
| 397 | if (major_low == 0x43) { |
Ye Li | d2d754f | 2020-04-20 20:12:54 -0700 | [diff] [blame] | 398 | type = get_cpu_variant_type(MXC_CPU_IMX8MP); |
Peng Fan | 69cec07 | 2019-12-27 10:14:02 +0800 | [diff] [blame] | 399 | } else if (major_low == 0x42) { |
| 400 | /* iMX8MN */ |
Peng Fan | 1a07d91 | 2020-02-05 17:39:27 +0800 | [diff] [blame] | 401 | type = get_cpu_variant_type(MXC_CPU_IMX8MN); |
Peng Fan | 5d2f206 | 2019-06-27 17:23:49 +0800 | [diff] [blame] | 402 | } else if (major_low == 0x41) { |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 403 | type = get_cpu_variant_type(MXC_CPU_IMX8MM); |
| 404 | } else { |
| 405 | if (reg == CHIP_REV_1_0) { |
| 406 | /* |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 407 | * For B0 chip, the DIGPROG is not updated, |
| 408 | * it is still TO1.0. we have to check ROM |
| 409 | * version or OCOTP_READ_FUSE_DATA. |
| 410 | * 0xff0055aa is magic number for B1. |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 411 | */ |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 412 | if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) { |
Ye Li | c963ed1 | 2021-03-19 15:57:16 +0800 | [diff] [blame^] | 413 | /* |
| 414 | * B2 uses same DIGPROG and OCOTP_READ_FUSE_DATA value with B1, |
| 415 | * so have to check ROM to distinguish them |
| 416 | */ |
| 417 | rom_version = readl((void __iomem *)ROM_VERSION_B0); |
| 418 | rom_version &= 0xff; |
| 419 | if (rom_version == CHIP_REV_2_2) |
| 420 | reg = CHIP_REV_2_2; |
| 421 | else |
| 422 | reg = CHIP_REV_2_1; |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 423 | } else { |
| 424 | rom_version = |
| 425 | readl((void __iomem *)ROM_VERSION_A0); |
| 426 | if (rom_version != CHIP_REV_1_0) { |
| 427 | rom_version = readl((void __iomem *)ROM_VERSION_B0); |
Patrick Wildt | d4a78b9 | 2019-11-19 09:42:06 +0100 | [diff] [blame] | 428 | rom_version &= 0xff; |
Peng Fan | c23fbdd | 2019-10-16 10:24:17 +0000 | [diff] [blame] | 429 | if (rom_version == CHIP_REV_2_0) |
| 430 | reg = CHIP_REV_2_0; |
| 431 | } |
Peng Fan | 1caffdf | 2019-08-27 06:25:17 +0000 | [diff] [blame] | 432 | } |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 433 | } |
Peng Fan | 6781508 | 2020-02-05 17:34:54 +0800 | [diff] [blame] | 434 | |
| 435 | type = get_cpu_variant_type(type); |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | return (type << 12) | reg; |
| 439 | } |
| 440 | |
| 441 | static void imx_set_wdog_powerdown(bool enable) |
| 442 | { |
| 443 | struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 444 | struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR; |
| 445 | struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR; |
| 446 | |
| 447 | /* Write to the PDE (Power Down Enable) bit */ |
| 448 | writew(enable, &wdog1->wmcr); |
| 449 | writew(enable, &wdog2->wmcr); |
| 450 | writew(enable, &wdog3->wmcr); |
| 451 | } |
| 452 | |
Peng Fan | c98e032 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 453 | int arch_cpu_init_dm(void) |
| 454 | { |
| 455 | struct udevice *dev; |
| 456 | int ret; |
| 457 | |
Peng Fan | 3c07334 | 2019-10-16 03:01:51 +0000 | [diff] [blame] | 458 | if (CONFIG_IS_ENABLED(CLK)) { |
| 459 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 460 | "clock-controller@30380000", |
| 461 | &dev); |
| 462 | if (ret < 0) { |
| 463 | printf("Failed to find clock node. Check device tree\n"); |
| 464 | return ret; |
| 465 | } |
Peng Fan | c98e032 | 2019-08-27 06:25:58 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 471 | int arch_cpu_init(void) |
| 472 | { |
Peng Fan | c0b30d7 | 2019-04-17 09:41:16 +0000 | [diff] [blame] | 473 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 474 | /* |
Peng Fan | d0ca289 | 2019-08-27 06:25:37 +0000 | [diff] [blame] | 475 | * ROM might disable clock for SCTR, |
| 476 | * enable the clock before timer_init. |
| 477 | */ |
| 478 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 479 | clock_enable(CCGR_SCTR, 1); |
| 480 | /* |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 481 | * Init timer at very early state, because sscg pll setting |
| 482 | * will use it |
| 483 | */ |
| 484 | timer_init(); |
| 485 | |
| 486 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 487 | clock_init(); |
| 488 | imx_set_wdog_powerdown(false); |
Peng Fan | 9cf2aa3 | 2020-07-09 13:52:41 +0800 | [diff] [blame] | 489 | |
| 490 | if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() || |
| 491 | is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() || |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 492 | is_imx8mnsl() || is_imx8mpd() || is_imx8mnud() || is_imx8mnus()) { |
Peng Fan | 9cf2aa3 | 2020-07-09 13:52:41 +0800 | [diff] [blame] | 493 | /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */ |
| 494 | struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840); |
| 495 | struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880); |
| 496 | struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0); |
| 497 | struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR; |
| 498 | |
| 499 | writel(0x1, &pgc_core2->pgcr); |
| 500 | writel(0x1, &pgc_core3->pgcr); |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 501 | if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) { |
Peng Fan | 9cf2aa3 | 2020-07-09 13:52:41 +0800 | [diff] [blame] | 502 | writel(0x1, &pgc_core1->pgcr); |
| 503 | writel(0xE, &gpc->cpu_pgc_dn_trg); |
| 504 | } else { |
| 505 | writel(0xC, &gpc->cpu_pgc_dn_trg); |
| 506 | } |
| 507 | } |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 508 | } |
| 509 | |
Peng Fan | c0b30d7 | 2019-04-17 09:41:16 +0000 | [diff] [blame] | 510 | if (is_imx8mq()) { |
| 511 | clock_enable(CCGR_OCOTP, 1); |
| 512 | if (readl(&ocotp->ctrl) & 0x200) |
| 513 | writel(0x200, &ocotp->ctrl_clr); |
| 514 | } |
| 515 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
Peng Fan | c9823b0 | 2019-09-16 03:09:36 +0000 | [diff] [blame] | 519 | #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP) |
| 520 | struct rom_api *g_rom_api = (struct rom_api *)0x980; |
| 521 | |
| 522 | enum boot_device get_boot_device(void) |
| 523 | { |
| 524 | volatile gd_t *pgd = gd; |
| 525 | int ret; |
| 526 | u32 boot; |
| 527 | u16 boot_type; |
| 528 | u8 boot_instance; |
| 529 | enum boot_device boot_dev = SD1_BOOT; |
| 530 | |
| 531 | ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, |
| 532 | ((uintptr_t)&boot) ^ QUERY_BT_DEV); |
| 533 | gd = pgd; |
| 534 | |
| 535 | if (ret != ROM_API_OKAY) { |
| 536 | puts("ROMAPI: failure at query_boot_info\n"); |
| 537 | return -1; |
| 538 | } |
| 539 | |
| 540 | boot_type = boot >> 16; |
| 541 | boot_instance = (boot >> 8) & 0xff; |
| 542 | |
| 543 | switch (boot_type) { |
| 544 | case BT_DEV_TYPE_SD: |
| 545 | boot_dev = boot_instance + SD1_BOOT; |
| 546 | break; |
| 547 | case BT_DEV_TYPE_MMC: |
| 548 | boot_dev = boot_instance + MMC1_BOOT; |
| 549 | break; |
| 550 | case BT_DEV_TYPE_NAND: |
| 551 | boot_dev = NAND_BOOT; |
| 552 | break; |
| 553 | case BT_DEV_TYPE_FLEXSPINOR: |
| 554 | boot_dev = QSPI_BOOT; |
| 555 | break; |
| 556 | case BT_DEV_TYPE_USB: |
| 557 | boot_dev = USB_BOOT; |
| 558 | break; |
| 559 | default: |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | return boot_dev; |
| 564 | } |
| 565 | #endif |
| 566 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 567 | bool is_usb_boot(void) |
| 568 | { |
| 569 | return get_boot_device() == USB_BOOT; |
| 570 | } |
| 571 | |
| 572 | #ifdef CONFIG_OF_SYSTEM_SETUP |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 573 | bool check_fdt_new_path(void *blob) |
| 574 | { |
| 575 | const char *soc_path = "/soc@0"; |
| 576 | int nodeoff; |
| 577 | |
| 578 | nodeoff = fdt_path_offset(blob, soc_path); |
| 579 | if (nodeoff < 0) |
| 580 | return false; |
| 581 | |
| 582 | return true; |
| 583 | } |
| 584 | |
| 585 | static int disable_fdt_nodes(void *blob, const char *const nodes_path[], int size_array) |
| 586 | { |
| 587 | int i = 0; |
| 588 | int rc; |
| 589 | int nodeoff; |
| 590 | const char *status = "disabled"; |
| 591 | |
| 592 | for (i = 0; i < size_array; i++) { |
| 593 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 594 | if (nodeoff < 0) |
| 595 | continue; /* Not found, skip it */ |
| 596 | |
| 597 | printf("Found %s node\n", nodes_path[i]); |
| 598 | |
| 599 | add_status: |
| 600 | rc = fdt_setprop(blob, nodeoff, "status", status, strlen(status) + 1); |
| 601 | if (rc) { |
| 602 | if (rc == -FDT_ERR_NOSPACE) { |
| 603 | rc = fdt_increase_size(blob, 512); |
| 604 | if (!rc) |
| 605 | goto add_status; |
| 606 | } |
| 607 | printf("Unable to update property %s:%s, err=%s\n", |
| 608 | nodes_path[i], "status", fdt_strerror(rc)); |
| 609 | } else { |
| 610 | printf("Modify %s:%s disabled\n", |
| 611 | nodes_path[i], "status"); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | #ifdef CONFIG_IMX8MQ |
| 619 | bool check_dcss_fused(void) |
| 620 | { |
| 621 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 622 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 623 | struct fuse_bank1_regs *fuse = |
| 624 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 625 | u32 value = readl(&fuse->tester4); |
| 626 | |
| 627 | if (value & 0x4000000) |
| 628 | return true; |
| 629 | |
| 630 | return false; |
| 631 | } |
| 632 | |
| 633 | static int disable_mipi_dsi_nodes(void *blob) |
| 634 | { |
| 635 | static const char * const nodes_path[] = { |
| 636 | "/mipi_dsi@30A00000", |
| 637 | "/mipi_dsi_bridge@30A00000", |
| 638 | "/dsi_phy@30A00300", |
| 639 | "/soc@0/bus@30800000/mipi_dsi@30a00000", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 640 | "/soc@0/bus@30800000/dphy@30a00300", |
| 641 | "/soc@0/bus@30800000/mipi-dsi@30a00000", |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path)); |
| 645 | } |
| 646 | |
| 647 | static int disable_dcss_nodes(void *blob) |
| 648 | { |
| 649 | static const char * const nodes_path[] = { |
| 650 | "/dcss@0x32e00000", |
| 651 | "/dcss@32e00000", |
| 652 | "/hdmi@32c00000", |
| 653 | "/hdmi_cec@32c33800", |
| 654 | "/hdmi_drm@32c00000", |
| 655 | "/display-subsystem", |
| 656 | "/sound-hdmi", |
| 657 | "/sound-hdmi-arc", |
| 658 | "/soc@0/bus@32c00000/display-controller@32e00000", |
| 659 | "/soc@0/bus@32c00000/hdmi@32c00000", |
| 660 | }; |
| 661 | |
| 662 | return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path)); |
| 663 | } |
| 664 | |
| 665 | static int check_mipi_dsi_nodes(void *blob) |
| 666 | { |
| 667 | static const char * const lcdif_path[] = { |
| 668 | "/lcdif@30320000", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 669 | "/soc@0/bus@30000000/lcdif@30320000", |
| 670 | "/soc@0/bus@30000000/lcd-controller@30320000" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 671 | }; |
| 672 | static const char * const mipi_dsi_path[] = { |
| 673 | "/mipi_dsi@30A00000", |
| 674 | "/soc@0/bus@30800000/mipi_dsi@30a00000" |
| 675 | }; |
| 676 | static const char * const lcdif_ep_path[] = { |
| 677 | "/lcdif@30320000/port@0/mipi-dsi-endpoint", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 678 | "/soc@0/bus@30000000/lcdif@30320000/port@0/endpoint", |
| 679 | "/soc@0/bus@30000000/lcd-controller@30320000/port@0/endpoint" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 680 | }; |
| 681 | static const char * const mipi_dsi_ep_path[] = { |
| 682 | "/mipi_dsi@30A00000/port@1/endpoint", |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 683 | "/soc@0/bus@30800000/mipi_dsi@30a00000/ports/port@0/endpoint", |
| 684 | "/soc@0/bus@30800000/mipi-dsi@30a00000/ports/port@0/endpoint@0" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 685 | }; |
| 686 | |
| 687 | int lookup_node; |
| 688 | int nodeoff; |
| 689 | bool new_path = check_fdt_new_path(blob); |
| 690 | int i = new_path ? 1 : 0; |
| 691 | |
| 692 | nodeoff = fdt_path_offset(blob, lcdif_path[i]); |
| 693 | if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) { |
| 694 | /* |
| 695 | * If can't find lcdif node or lcdif node is disabled, |
| 696 | * then disable all mipi dsi, since they only can input |
| 697 | * from DCSS |
| 698 | */ |
| 699 | return disable_mipi_dsi_nodes(blob); |
| 700 | } |
| 701 | |
| 702 | nodeoff = fdt_path_offset(blob, mipi_dsi_path[i]); |
| 703 | if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) |
| 704 | return 0; |
| 705 | |
| 706 | nodeoff = fdt_path_offset(blob, lcdif_ep_path[i]); |
| 707 | if (nodeoff < 0) { |
| 708 | /* |
| 709 | * If can't find lcdif endpoint, then disable all mipi dsi, |
| 710 | * since they only can input from DCSS |
| 711 | */ |
| 712 | return disable_mipi_dsi_nodes(blob); |
| 713 | } |
| 714 | |
| 715 | lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint"); |
| 716 | nodeoff = fdt_path_offset(blob, mipi_dsi_ep_path[i]); |
| 717 | |
| 718 | if (nodeoff > 0 && nodeoff == lookup_node) |
| 719 | return 0; |
| 720 | |
| 721 | return disable_mipi_dsi_nodes(blob); |
| 722 | } |
| 723 | #endif |
| 724 | |
| 725 | int disable_vpu_nodes(void *blob) |
| 726 | { |
| 727 | static const char * const nodes_path_8mq[] = { |
| 728 | "/vpu@38300000", |
| 729 | "/soc@0/vpu@38300000" |
| 730 | }; |
| 731 | |
| 732 | static const char * const nodes_path_8mm[] = { |
| 733 | "/vpu_g1@38300000", |
| 734 | "/vpu_g2@38310000", |
| 735 | "/vpu_h1@38320000" |
| 736 | }; |
| 737 | |
| 738 | static const char * const nodes_path_8mp[] = { |
| 739 | "/vpu_g1@38300000", |
| 740 | "/vpu_g2@38310000", |
| 741 | "/vpu_vc8000e@38320000" |
| 742 | }; |
| 743 | |
| 744 | if (is_imx8mq()) |
| 745 | return disable_fdt_nodes(blob, nodes_path_8mq, ARRAY_SIZE(nodes_path_8mq)); |
| 746 | else if (is_imx8mm()) |
| 747 | return disable_fdt_nodes(blob, nodes_path_8mm, ARRAY_SIZE(nodes_path_8mm)); |
| 748 | else if (is_imx8mp()) |
| 749 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 750 | else |
| 751 | return -EPERM; |
| 752 | } |
| 753 | |
Ye Li | ee337ce | 2021-03-19 15:57:09 +0800 | [diff] [blame] | 754 | #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE |
| 755 | static int low_drive_gpu_freq(void *blob) |
| 756 | { |
| 757 | static const char *nodes_path_8mn[] = { |
| 758 | "/gpu@38000000", |
| 759 | "/soc@0/gpu@38000000" |
| 760 | }; |
| 761 | |
| 762 | int nodeoff, cnt, i; |
| 763 | u32 assignedclks[7]; |
| 764 | |
| 765 | nodeoff = fdt_path_offset(blob, nodes_path_8mn[0]); |
| 766 | if (nodeoff < 0) |
| 767 | return nodeoff; |
| 768 | |
| 769 | cnt = fdtdec_get_int_array_count(blob, nodeoff, "assigned-clock-rates", assignedclks, 7); |
| 770 | if (cnt < 0) |
| 771 | return cnt; |
| 772 | |
| 773 | if (cnt != 7) |
| 774 | printf("Warning: %s, assigned-clock-rates count %d\n", nodes_path_8mn[0], cnt); |
| 775 | |
| 776 | assignedclks[cnt - 1] = 200000000; |
| 777 | assignedclks[cnt - 2] = 200000000; |
| 778 | |
| 779 | for (i = 0; i < cnt; i++) { |
| 780 | debug("<%u>, ", assignedclks[i]); |
| 781 | assignedclks[i] = cpu_to_fdt32(assignedclks[i]); |
| 782 | } |
| 783 | debug("\n"); |
| 784 | |
| 785 | return fdt_setprop(blob, nodeoff, "assigned-clock-rates", &assignedclks, sizeof(assignedclks)); |
| 786 | } |
| 787 | #endif |
| 788 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 789 | int disable_gpu_nodes(void *blob) |
| 790 | { |
| 791 | static const char * const nodes_path_8mn[] = { |
Peng Fan | 7d4195c | 2021-03-19 15:57:13 +0800 | [diff] [blame] | 792 | "/gpu@38000000", |
| 793 | "/soc@/gpu@38000000" |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 794 | }; |
| 795 | |
| 796 | return disable_fdt_nodes(blob, nodes_path_8mn, ARRAY_SIZE(nodes_path_8mn)); |
| 797 | } |
| 798 | |
| 799 | int disable_npu_nodes(void *blob) |
| 800 | { |
| 801 | static const char * const nodes_path_8mp[] = { |
| 802 | "/vipsi@38500000" |
| 803 | }; |
| 804 | |
| 805 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 806 | } |
| 807 | |
| 808 | int disable_isp_nodes(void *blob) |
| 809 | { |
| 810 | static const char * const nodes_path_8mp[] = { |
| 811 | "/soc@0/bus@32c00000/camera/isp@32e10000", |
| 812 | "/soc@0/bus@32c00000/camera/isp@32e20000" |
| 813 | }; |
| 814 | |
| 815 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 816 | } |
| 817 | |
| 818 | int disable_dsp_nodes(void *blob) |
| 819 | { |
| 820 | static const char * const nodes_path_8mp[] = { |
| 821 | "/dsp@3b6e8000" |
| 822 | }; |
| 823 | |
| 824 | return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); |
| 825 | } |
| 826 | |
Ye Li | 26517af | 2021-03-19 15:57:12 +0800 | [diff] [blame] | 827 | static void disable_thermal_cpu_nodes(void *blob, u32 disabled_cores) |
| 828 | { |
| 829 | static const char * const thermal_path[] = { |
| 830 | "/thermal-zones/cpu-thermal/cooling-maps/map0" |
| 831 | }; |
| 832 | |
| 833 | int nodeoff, cnt, i, ret, j; |
| 834 | u32 cooling_dev[12]; |
| 835 | |
| 836 | for (i = 0; i < ARRAY_SIZE(thermal_path); i++) { |
| 837 | nodeoff = fdt_path_offset(blob, thermal_path[i]); |
| 838 | if (nodeoff < 0) |
| 839 | continue; /* Not found, skip it */ |
| 840 | |
| 841 | cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", cooling_dev, 12); |
| 842 | if (cnt < 0) |
| 843 | continue; |
| 844 | |
| 845 | if (cnt != 12) |
| 846 | printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt); |
| 847 | |
| 848 | for (j = 0; j < cnt; j++) |
| 849 | cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]); |
| 850 | |
| 851 | ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev, |
| 852 | sizeof(u32) * (12 - disabled_cores * 3)); |
| 853 | if (ret < 0) { |
| 854 | printf("Warning: %s, cooling-device setprop failed %d\n", |
| 855 | thermal_path[i], ret); |
| 856 | continue; |
| 857 | } |
| 858 | |
| 859 | printf("Update node %s, cooling-device prop\n", thermal_path[i]); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | static void disable_pmu_cpu_nodes(void *blob, u32 disabled_cores) |
| 864 | { |
| 865 | static const char * const pmu_path[] = { |
| 866 | "/pmu" |
| 867 | }; |
| 868 | |
| 869 | int nodeoff, cnt, i, ret, j; |
| 870 | u32 irq_affinity[4]; |
| 871 | |
| 872 | for (i = 0; i < ARRAY_SIZE(pmu_path); i++) { |
| 873 | nodeoff = fdt_path_offset(blob, pmu_path[i]); |
| 874 | if (nodeoff < 0) |
| 875 | continue; /* Not found, skip it */ |
| 876 | |
| 877 | cnt = fdtdec_get_int_array_count(blob, nodeoff, "interrupt-affinity", |
| 878 | irq_affinity, 4); |
| 879 | if (cnt < 0) |
| 880 | continue; |
| 881 | |
| 882 | if (cnt != 4) |
| 883 | printf("Warning: %s, interrupt-affinity count %d\n", pmu_path[i], cnt); |
| 884 | |
| 885 | for (j = 0; j < cnt; j++) |
| 886 | irq_affinity[j] = cpu_to_fdt32(irq_affinity[j]); |
| 887 | |
| 888 | ret = fdt_setprop(blob, nodeoff, "interrupt-affinity", &irq_affinity, |
| 889 | sizeof(u32) * (4 - disabled_cores)); |
| 890 | if (ret < 0) { |
| 891 | printf("Warning: %s, interrupt-affinity setprop failed %d\n", |
| 892 | pmu_path[i], ret); |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | printf("Update node %s, interrupt-affinity prop\n", pmu_path[i]); |
| 897 | } |
| 898 | } |
| 899 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 900 | static int disable_cpu_nodes(void *blob, u32 disabled_cores) |
| 901 | { |
| 902 | static const char * const nodes_path[] = { |
| 903 | "/cpus/cpu@1", |
| 904 | "/cpus/cpu@2", |
| 905 | "/cpus/cpu@3", |
| 906 | }; |
| 907 | u32 i = 0; |
| 908 | int rc; |
| 909 | int nodeoff; |
| 910 | |
| 911 | if (disabled_cores > 3) |
| 912 | return -EINVAL; |
| 913 | |
| 914 | i = 3 - disabled_cores; |
| 915 | |
| 916 | for (; i < 3; i++) { |
| 917 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 918 | if (nodeoff < 0) |
| 919 | continue; /* Not found, skip it */ |
| 920 | |
| 921 | debug("Found %s node\n", nodes_path[i]); |
| 922 | |
| 923 | rc = fdt_del_node(blob, nodeoff); |
| 924 | if (rc < 0) { |
| 925 | printf("Unable to delete node %s, err=%s\n", |
| 926 | nodes_path[i], fdt_strerror(rc)); |
| 927 | } else { |
| 928 | printf("Delete node %s\n", nodes_path[i]); |
| 929 | } |
| 930 | } |
| 931 | |
Ye Li | 26517af | 2021-03-19 15:57:12 +0800 | [diff] [blame] | 932 | disable_thermal_cpu_nodes(blob, disabled_cores); |
| 933 | disable_pmu_cpu_nodes(blob, disabled_cores); |
| 934 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 938 | int ft_system_setup(void *blob, struct bd_info *bd) |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 939 | { |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 940 | #ifdef CONFIG_IMX8MQ |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 941 | int i = 0; |
| 942 | int rc; |
| 943 | int nodeoff; |
| 944 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 945 | if (get_boot_device() == USB_BOOT) { |
| 946 | disable_dcss_nodes(blob); |
| 947 | |
| 948 | bool new_path = check_fdt_new_path(blob); |
| 949 | int v = new_path ? 1 : 0; |
| 950 | static const char * const usb_dwc3_path[] = { |
| 951 | "/usb@38100000/dwc3", |
| 952 | "/soc@0/usb@38100000" |
| 953 | }; |
| 954 | |
| 955 | nodeoff = fdt_path_offset(blob, usb_dwc3_path[v]); |
| 956 | if (nodeoff >= 0) { |
| 957 | const char *speed = "high-speed"; |
| 958 | |
| 959 | printf("Found %s node\n", usb_dwc3_path[v]); |
| 960 | |
| 961 | usb_modify_speed: |
| 962 | |
| 963 | rc = fdt_setprop(blob, nodeoff, "maximum-speed", speed, strlen(speed) + 1); |
| 964 | if (rc) { |
| 965 | if (rc == -FDT_ERR_NOSPACE) { |
| 966 | rc = fdt_increase_size(blob, 512); |
| 967 | if (!rc) |
| 968 | goto usb_modify_speed; |
| 969 | } |
| 970 | printf("Unable to set property %s:%s, err=%s\n", |
| 971 | usb_dwc3_path[v], "maximum-speed", fdt_strerror(rc)); |
| 972 | } else { |
| 973 | printf("Modify %s:%s = %s\n", |
| 974 | usb_dwc3_path[v], "maximum-speed", speed); |
| 975 | } |
| 976 | } else { |
| 977 | printf("Can't found %s node\n", usb_dwc3_path[v]); |
| 978 | } |
| 979 | } |
| 980 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 981 | /* Disable the CPU idle for A0 chip since the HW does not support it */ |
| 982 | if (is_soc_rev(CHIP_REV_1_0)) { |
| 983 | static const char * const nodes_path[] = { |
| 984 | "/cpus/cpu@0", |
| 985 | "/cpus/cpu@1", |
| 986 | "/cpus/cpu@2", |
| 987 | "/cpus/cpu@3", |
| 988 | }; |
| 989 | |
| 990 | for (i = 0; i < ARRAY_SIZE(nodes_path); i++) { |
| 991 | nodeoff = fdt_path_offset(blob, nodes_path[i]); |
| 992 | if (nodeoff < 0) |
| 993 | continue; /* Not found, skip it */ |
| 994 | |
Marek Vasut | e2e7a77 | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 995 | debug("Found %s node\n", nodes_path[i]); |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 996 | |
| 997 | rc = fdt_delprop(blob, nodeoff, "cpu-idle-states"); |
Marek Vasut | e2e7a77 | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 998 | if (rc == -FDT_ERR_NOTFOUND) |
| 999 | continue; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1000 | if (rc) { |
| 1001 | printf("Unable to update property %s:%s, err=%s\n", |
| 1002 | nodes_path[i], "status", fdt_strerror(rc)); |
| 1003 | return rc; |
| 1004 | } |
| 1005 | |
Marek Vasut | e2e7a77 | 2020-04-24 21:37:33 +0200 | [diff] [blame] | 1006 | debug("Remove %s:%s\n", nodes_path[i], |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1007 | "cpu-idle-states"); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1011 | if (is_imx8mql()) { |
| 1012 | disable_vpu_nodes(blob); |
| 1013 | if (check_dcss_fused()) { |
| 1014 | printf("DCSS is fused\n"); |
| 1015 | disable_dcss_nodes(blob); |
| 1016 | check_mipi_dsi_nodes(blob); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if (is_imx8md()) |
| 1021 | disable_cpu_nodes(blob, 2); |
| 1022 | |
| 1023 | #elif defined(CONFIG_IMX8MM) |
| 1024 | if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl()) |
| 1025 | disable_vpu_nodes(blob); |
| 1026 | |
| 1027 | if (is_imx8mmd() || is_imx8mmdl()) |
| 1028 | disable_cpu_nodes(blob, 2); |
| 1029 | else if (is_imx8mms() || is_imx8mmsl()) |
| 1030 | disable_cpu_nodes(blob, 3); |
| 1031 | |
| 1032 | #elif defined(CONFIG_IMX8MN) |
| 1033 | if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl()) |
| 1034 | disable_gpu_nodes(blob); |
Ye Li | ee337ce | 2021-03-19 15:57:09 +0800 | [diff] [blame] | 1035 | #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE |
| 1036 | else { |
| 1037 | int ldm_gpu = low_drive_gpu_freq(blob); |
| 1038 | |
| 1039 | if (ldm_gpu < 0) |
| 1040 | printf("Update GPU node assigned-clock-rates failed\n"); |
| 1041 | else |
| 1042 | printf("Update GPU node assigned-clock-rates ok\n"); |
| 1043 | } |
| 1044 | #endif |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1045 | |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 1046 | if (is_imx8mnd() || is_imx8mndl() || is_imx8mnud()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1047 | disable_cpu_nodes(blob, 2); |
Ye Li | 715180e | 2021-03-19 15:57:11 +0800 | [diff] [blame] | 1048 | else if (is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1049 | disable_cpu_nodes(blob, 3); |
| 1050 | |
| 1051 | #elif defined(CONFIG_IMX8MP) |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1052 | if (is_imx8mpl()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1053 | disable_vpu_nodes(blob); |
| 1054 | |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1055 | if (is_imx8mpl() || is_imx8mp6()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1056 | disable_npu_nodes(blob); |
| 1057 | |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1058 | if (is_imx8mpl()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1059 | disable_isp_nodes(blob); |
| 1060 | |
Peng Fan | 8a472a2 | 2020-09-16 15:17:22 +0800 | [diff] [blame] | 1061 | if (is_imx8mpl() || is_imx8mp6()) |
Peng Fan | 435dc12 | 2020-07-09 14:06:49 +0800 | [diff] [blame] | 1062 | disable_dsp_nodes(blob); |
| 1063 | |
| 1064 | if (is_imx8mpd()) |
| 1065 | disable_cpu_nodes(blob, 2); |
| 1066 | #endif |
| 1067 | |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1068 | return 0; |
| 1069 | } |
| 1070 | #endif |
| 1071 | |
Marek Vasut | 64dc4de | 2020-04-29 15:04:21 +0200 | [diff] [blame] | 1072 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 1073 | void reset_cpu(void) |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1074 | { |
Claudius Heine | e73f394 | 2020-04-29 15:04:23 +0200 | [diff] [blame] | 1075 | struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR; |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1076 | |
Ye Li | 54a915a | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 1077 | /* Clear WDA to trigger WDOG_B immediately */ |
| 1078 | 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] | 1079 | |
Ye Li | 54a915a | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 1080 | while (1) { |
| 1081 | /* |
Harald Seiler | ec0c447 | 2020-04-29 15:04:22 +0200 | [diff] [blame] | 1082 | * spin for .5 seconds before reset |
Ye Li | 54a915a | 2019-12-09 00:47:18 -0800 | [diff] [blame] | 1083 | */ |
| 1084 | } |
Peng Fan | eae4de2 | 2018-01-10 13:20:37 +0800 | [diff] [blame] | 1085 | } |
Peng Fan | 24290d9 | 2019-08-27 06:25:41 +0000 | [diff] [blame] | 1086 | #endif |
Peng Fan | 5760d8d | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 1087 | |
| 1088 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 1089 | static void acquire_buildinfo(void) |
| 1090 | { |
| 1091 | u64 atf_commit = 0; |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 1092 | struct arm_smccc_res res; |
Peng Fan | 5760d8d | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 1093 | |
| 1094 | /* Get ARM Trusted Firmware commit id */ |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 1095 | arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH, |
Fabio Estevam | 31e410f | 2020-07-17 16:36:54 -0300 | [diff] [blame] | 1096 | 0, 0, 0, 0, 0, 0, &res); |
Peng Fan | 45d843a | 2020-05-11 15:14:04 +0800 | [diff] [blame] | 1097 | atf_commit = res.a0; |
Peng Fan | 5760d8d | 2020-04-22 10:51:13 +0800 | [diff] [blame] | 1098 | if (atf_commit == 0xffffffff) { |
| 1099 | debug("ATF does not support build info\n"); |
| 1100 | atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */ |
| 1101 | } |
| 1102 | |
| 1103 | printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit); |
| 1104 | } |
| 1105 | |
| 1106 | int arch_misc_init(void) |
| 1107 | { |
| 1108 | acquire_buildinfo(); |
| 1109 | |
| 1110 | return 0; |
| 1111 | } |
| 1112 | #endif |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 1113 | |
| 1114 | void imx_tmu_arch_init(void *reg_base) |
| 1115 | { |
Ye Li | a00f2f0 | 2020-05-03 22:19:53 +0800 | [diff] [blame] | 1116 | if (is_imx8mm() || is_imx8mn()) { |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 1117 | /* Load TCALIV and TASR from fuses */ |
| 1118 | struct ocotp_regs *ocotp = |
| 1119 | (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 1120 | struct fuse_bank *bank = &ocotp->bank[3]; |
| 1121 | struct fuse_bank3_regs *fuse = |
| 1122 | (struct fuse_bank3_regs *)bank->fuse_regs; |
| 1123 | |
| 1124 | u32 tca_rt, tca_hr, tca_en; |
| 1125 | u32 buf_vref, buf_slope; |
| 1126 | |
| 1127 | tca_rt = fuse->ana0 & 0xFF; |
| 1128 | tca_hr = (fuse->ana0 & 0xFF00) >> 8; |
| 1129 | tca_en = (fuse->ana0 & 0x2000000) >> 25; |
| 1130 | |
| 1131 | buf_vref = (fuse->ana0 & 0x1F00000) >> 20; |
| 1132 | buf_slope = (fuse->ana0 & 0xF0000) >> 16; |
| 1133 | |
| 1134 | writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28); |
| 1135 | writel((tca_en << 31) | (tca_hr << 16) | tca_rt, |
| 1136 | (ulong)reg_base + 0x30); |
| 1137 | } |
Ye Li | 41a2025 | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 1138 | #ifdef CONFIG_IMX8MP |
| 1139 | /* Load TCALIV0/1/m40 and TRIM from fuses */ |
| 1140 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 1141 | struct fuse_bank *bank = &ocotp->bank[38]; |
| 1142 | struct fuse_bank38_regs *fuse = |
| 1143 | (struct fuse_bank38_regs *)bank->fuse_regs; |
| 1144 | struct fuse_bank *bank2 = &ocotp->bank[39]; |
| 1145 | struct fuse_bank39_regs *fuse2 = |
| 1146 | (struct fuse_bank39_regs *)bank2->fuse_regs; |
| 1147 | u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr; |
| 1148 | u32 reg; |
| 1149 | u32 tca40[2], tca25[2], tca105[2]; |
| 1150 | |
| 1151 | /* For blank sample */ |
| 1152 | if (!fuse->ana_trim2 && !fuse->ana_trim3 && |
| 1153 | !fuse->ana_trim4 && !fuse2->ana_trim5) { |
| 1154 | /* Use a default 25C binary codes */ |
| 1155 | tca25[0] = 1596; |
Ye Li | d756ca0 | 2020-05-03 22:19:55 +0800 | [diff] [blame] | 1156 | tca25[1] = 1596; |
Ye Li | 41a2025 | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 1157 | writel(tca25[0], (ulong)reg_base + 0x30); |
Ye Li | d756ca0 | 2020-05-03 22:19:55 +0800 | [diff] [blame] | 1158 | writel(tca25[1], (ulong)reg_base + 0x34); |
Ye Li | 41a2025 | 2020-05-03 22:19:54 +0800 | [diff] [blame] | 1159 | return; |
| 1160 | } |
| 1161 | |
| 1162 | buf_vref = (fuse->ana_trim2 & 0xc0) >> 6; |
| 1163 | buf_slope = (fuse->ana_trim2 & 0xF00) >> 8; |
| 1164 | bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12; |
| 1165 | bgr = (fuse->ana_trim2 & 0xF0000) >> 16; |
| 1166 | vlsb = (fuse->ana_trim2 & 0xF00000) >> 20; |
| 1167 | writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28); |
| 1168 | |
| 1169 | reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7); |
| 1170 | writel(reg, (ulong)reg_base + 0x3c); |
| 1171 | |
| 1172 | tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16; |
| 1173 | tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28; |
| 1174 | tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4); |
| 1175 | tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8; |
| 1176 | tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20; |
| 1177 | tca25[1] = fuse2->ana_trim5 & 0xFFF; |
| 1178 | tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12; |
| 1179 | |
| 1180 | /* use 25c for 1p calibration */ |
| 1181 | writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30); |
| 1182 | writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34); |
| 1183 | writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38); |
| 1184 | #endif |
Ye Li | 325cd01 | 2020-05-03 22:19:52 +0800 | [diff] [blame] | 1185 | } |
Peng Fan | a35215d | 2020-07-09 13:39:26 +0800 | [diff] [blame] | 1186 | |
| 1187 | #if defined(CONFIG_SPL_BUILD) |
| 1188 | #if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN) |
| 1189 | bool serror_need_skip = true; |
| 1190 | |
| 1191 | void do_error(struct pt_regs *pt_regs, unsigned int esr) |
| 1192 | { |
| 1193 | /* |
| 1194 | * If stack is still in ROM reserved OCRAM not switch to SPL, |
| 1195 | * it is the ROM SError |
| 1196 | */ |
| 1197 | ulong sp; |
| 1198 | |
| 1199 | asm volatile("mov %0, sp" : "=r"(sp) : ); |
| 1200 | |
| 1201 | if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) { |
| 1202 | /* Check for ERR050342, imx8mq HDCP enabled parts */ |
| 1203 | if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) { |
| 1204 | serror_need_skip = false; |
| 1205 | return; /* Do nothing skip the SError in ROM */ |
| 1206 | } |
| 1207 | |
| 1208 | /* Check for ERR050350, field return mode for imx8mq, mm and mn */ |
| 1209 | if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) { |
| 1210 | serror_need_skip = false; |
| 1211 | return; /* Do nothing skip the SError in ROM */ |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | efi_restore_gd(); |
| 1216 | printf("\"Error\" handler, esr 0x%08x\n", esr); |
| 1217 | show_regs(pt_regs); |
| 1218 | panic("Resetting CPU ...\n"); |
| 1219 | } |
| 1220 | #endif |
| 1221 | #endif |
Ye Li | 0513f36 | 2019-07-15 01:16:46 -0700 | [diff] [blame] | 1222 | |
| 1223 | #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP) |
| 1224 | enum env_location env_get_location(enum env_operation op, int prio) |
| 1225 | { |
| 1226 | enum boot_device dev = get_boot_device(); |
| 1227 | enum env_location env_loc = ENVL_UNKNOWN; |
| 1228 | |
| 1229 | if (prio) |
| 1230 | return env_loc; |
| 1231 | |
| 1232 | switch (dev) { |
| 1233 | #ifdef CONFIG_ENV_IS_IN_SPI_FLASH |
| 1234 | case QSPI_BOOT: |
| 1235 | env_loc = ENVL_SPI_FLASH; |
| 1236 | break; |
| 1237 | #endif |
| 1238 | #ifdef CONFIG_ENV_IS_IN_NAND |
| 1239 | case NAND_BOOT: |
| 1240 | env_loc = ENVL_NAND; |
| 1241 | break; |
| 1242 | #endif |
| 1243 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 1244 | case SD1_BOOT: |
| 1245 | case SD2_BOOT: |
| 1246 | case SD3_BOOT: |
| 1247 | case MMC1_BOOT: |
| 1248 | case MMC2_BOOT: |
| 1249 | case MMC3_BOOT: |
| 1250 | env_loc = ENVL_MMC; |
| 1251 | break; |
| 1252 | #endif |
| 1253 | default: |
| 1254 | #if defined(CONFIG_ENV_IS_NOWHERE) |
| 1255 | env_loc = ENVL_NOWHERE; |
| 1256 | #endif |
| 1257 | break; |
| 1258 | } |
| 1259 | |
| 1260 | return env_loc; |
| 1261 | } |
| 1262 | |
| 1263 | #ifndef ENV_IS_EMBEDDED |
| 1264 | long long env_get_offset(long long defautl_offset) |
| 1265 | { |
| 1266 | enum boot_device dev = get_boot_device(); |
| 1267 | |
| 1268 | switch (dev) { |
| 1269 | case NAND_BOOT: |
| 1270 | return (60 << 20); /* 60MB offset for NAND */ |
| 1271 | default: |
| 1272 | break; |
| 1273 | } |
| 1274 | |
| 1275 | return defautl_offset; |
| 1276 | } |
| 1277 | #endif |
| 1278 | #endif |