1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017-2019, 2021 NXP
5 * Peng Fan <peng.fan@nxp.com>
13 #include <asm/arch/imx-regs.h>
14 #include <asm/global_data.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/mach-imx/hab.h>
19 #include <asm/mach-imx/boot_mode.h>
20 #include <asm/mach-imx/syscounter.h>
21 #include <asm/ptrace.h>
22 #include <asm/armv8/mmu.h>
23 #include <dm/uclass.h>
24 #include <dm/device.h>
25 #include <efi_loader.h>
27 #include <env_internal.h>
29 #include <fdt_support.h>
32 #include <linux/bitops.h>
34 DECLARE_GLOBAL_DATA_PTR;
36 #if defined(CONFIG_IMX_HAB)
37 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
45 #ifdef CONFIG_SPL_BUILD
46 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
47 unsigned long freq = readl(&sctr->cntfid0);
49 /* Update with accurate clock frequency */
50 asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
52 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
53 SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
62 void enable_tzc380(void)
64 struct iomuxc_gpr_base_regs *gpr =
65 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
67 /* Enable TZASC and lock setting */
68 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN);
69 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK);
72 * According to TRM, TZASC_ID_SWAP_BYPASS should be set in
73 * order to avoid AXI Bus errors when GPU is in use
75 setbits_le32(&gpr->gpr[10], GPR_TZASC_ID_SWAP_BYPASS);
78 * imx8mn and imx8mp implements the lock bit for
79 * TZASC_ID_SWAP_BYPASS, enable it to lock settings
81 setbits_le32(&gpr->gpr[10], GPR_TZASC_ID_SWAP_BYPASS_LOCK);
84 * set Region 0 attribute to allow secure and non-secure
85 * read/write permission. Found some masters like usb dwc3
86 * controllers can't work with secure memory.
88 writel(0xf0000000, TZASC_BASE_ADDR + 0x108);
91 void set_wdog_reset(struct wdog_regs *wdog)
94 * Output WDOG_B signal to reset external pmic or POR_B decided by
95 * the board design. Without external reset, the peripherals/DDR/
96 * PMIC are not reset, that may cause system working abnormal.
97 * WDZST bit is write-once only bit. Align this bit in kernel,
98 * otherwise kernel code will have no chance to set this bit.
100 setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK);
103 #ifdef CONFIG_ARMV8_PSCI
104 #define PTE_MAP_NS PTE_BLOCK_NS
109 static struct mm_region imx8m_mem_map[] = {
115 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
116 PTE_BLOCK_OUTER_SHARE
122 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
123 PTE_BLOCK_NON_SHARE |
124 PTE_BLOCK_PXN | PTE_BLOCK_UXN
130 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
131 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
137 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
138 PTE_BLOCK_NON_SHARE |
139 PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_MAP_NS
145 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
146 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
151 .size = 0x3f500000UL,
152 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
153 PTE_BLOCK_NON_SHARE |
154 PTE_BLOCK_PXN | PTE_BLOCK_UXN
157 .virt = 0x40000000UL,
158 .phys = 0x40000000UL,
159 .size = PHYS_SDRAM_SIZE,
160 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
161 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
162 #ifdef PHYS_SDRAM_2_SIZE
165 .virt = 0x100000000UL,
166 .phys = 0x100000000UL,
167 .size = PHYS_SDRAM_2_SIZE,
168 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
169 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
172 /* empty entrie to split table entry 5 if needed when TEEs are used */
175 /* List terminator */
180 struct mm_region *mem_map = imx8m_mem_map;
182 static unsigned int imx8m_find_dram_entry_in_mem_map(void)
186 for (i = 0; i < ARRAY_SIZE(imx8m_mem_map); i++)
187 if (imx8m_mem_map[i].phys == CFG_SYS_SDRAM_BASE)
190 hang(); /* Entry not found, this must never happen. */
193 void enable_caches(void)
195 /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch
196 * If OPTEE does not run, still update the MMU table according to dram banks structure
197 * to set correct dram size from board_phys_sdram_size
201 * please make sure that entry initial value matches
202 * imx8m_mem_map for DRAM1
204 int entry = imx8m_find_dram_entry_in_mem_map();
205 u64 attrs = imx8m_mem_map[entry].attrs;
207 while (i < CONFIG_NR_DRAM_BANKS &&
208 entry < ARRAY_SIZE(imx8m_mem_map)) {
209 if (gd->bd->bi_dram[i].start == 0)
211 imx8m_mem_map[entry].phys = gd->bd->bi_dram[i].start;
212 imx8m_mem_map[entry].virt = gd->bd->bi_dram[i].start;
213 imx8m_mem_map[entry].size = gd->bd->bi_dram[i].size;
214 imx8m_mem_map[entry].attrs = attrs;
215 debug("Added memory mapping (%d): %llx %llx\n", entry,
216 imx8m_mem_map[entry].phys, imx8m_mem_map[entry].size);
224 __weak int board_phys_sdram_size(phys_size_t *size)
229 *size = PHYS_SDRAM_SIZE;
231 #ifdef PHYS_SDRAM_2_SIZE
232 *size += PHYS_SDRAM_2_SIZE;
239 phys_size_t sdram_size;
242 ret = board_phys_sdram_size(&sdram_size);
246 /* rom_pointer[1] contains the size of TEE occupies */
247 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && !IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1])
248 gd->ram_size = sdram_size - rom_pointer[1];
250 gd->ram_size = sdram_size;
255 int dram_init_banksize(void)
259 phys_size_t sdram_size;
260 phys_size_t sdram_b1_size, sdram_b2_size;
262 ret = board_phys_sdram_size(&sdram_size);
266 /* Bank 1 can't cross over 4GB space */
267 if (sdram_size > 0xc0000000) {
268 sdram_b1_size = 0xc0000000;
269 sdram_b2_size = sdram_size - 0xc0000000;
271 sdram_b1_size = sdram_size;
275 gd->bd->bi_dram[bank].start = PHYS_SDRAM;
276 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && !IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1]) {
277 phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
278 phys_size_t optee_size = (size_t)rom_pointer[1];
280 gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start;
281 if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_b1_size)) {
282 if (++bank >= CONFIG_NR_DRAM_BANKS) {
283 puts("CONFIG_NR_DRAM_BANKS is not enough\n");
287 gd->bd->bi_dram[bank].start = optee_start + optee_size;
288 gd->bd->bi_dram[bank].size = PHYS_SDRAM +
289 sdram_b1_size - gd->bd->bi_dram[bank].start;
292 gd->bd->bi_dram[bank].size = sdram_b1_size;
296 if (++bank >= CONFIG_NR_DRAM_BANKS) {
297 puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n");
300 gd->bd->bi_dram[bank].start = 0x100000000UL;
301 gd->bd->bi_dram[bank].size = sdram_b2_size;
307 phys_size_t get_effective_memsize(void)
310 phys_size_t sdram_size;
311 phys_size_t sdram_b1_size;
312 ret = board_phys_sdram_size(&sdram_size);
314 /* Bank 1 can't cross over 4GB space */
315 if (sdram_size > 0xc0000000) {
316 sdram_b1_size = 0xc0000000;
318 sdram_b1_size = sdram_size;
321 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && !IS_ENABLED(CONFIG_SPL_BUILD) &&
323 /* We will relocate u-boot to Top of dram1. Tee position has two cases:
324 * 1. At the top of dram1, Then return the size removed optee size.
325 * 2. In the middle of dram1, return the size of dram1.
327 if ((rom_pointer[0] + rom_pointer[1]) == (PHYS_SDRAM + sdram_b1_size))
328 return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM);
331 return sdram_b1_size;
333 return PHYS_SDRAM_SIZE;
337 phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
342 * Some IPs have their accessible address space restricted by
343 * the interconnect. Let's make sure U-Boot only ever uses the
344 * space below the 4G address boundary (which is 3GiB big),
345 * even when the effective available memory is bigger.
347 top_addr = clamp_val((u64)PHYS_SDRAM + gd->ram_size, 0, 0xffffffff);
350 * rom_pointer[0] stores the TEE memory start address.
351 * rom_pointer[1] stores the size TEE uses.
352 * We need to reserve the memory region for TEE.
354 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[0] &&
355 rom_pointer[1] && top_addr > rom_pointer[0])
356 top_addr = rom_pointer[0];
361 static u32 get_cpu_variant_type(u32 type)
363 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
364 struct fuse_bank *bank = &ocotp->bank[1];
365 struct fuse_bank1_regs *fuse =
366 (struct fuse_bank1_regs *)bank->fuse_regs;
368 u32 value = readl(&fuse->tester4);
370 if (type == MXC_CPU_IMX8MQ) {
371 if ((value & 0x3) == 0x2)
372 return MXC_CPU_IMX8MD;
373 else if (value & 0x200000)
374 return MXC_CPU_IMX8MQL;
376 } else if (type == MXC_CPU_IMX8MM) {
377 switch (value & 0x3) {
379 if (value & 0x1c0000)
380 return MXC_CPU_IMX8MMDL;
382 return MXC_CPU_IMX8MMD;
384 if (value & 0x1c0000)
385 return MXC_CPU_IMX8MMSL;
387 return MXC_CPU_IMX8MMS;
389 if (value & 0x1c0000)
390 return MXC_CPU_IMX8MML;
393 } else if (type == MXC_CPU_IMX8MN) {
394 switch (value & 0x3) {
396 if (value & 0x1000000) {
397 if (value & 0x10000000) /* MIPI DSI */
398 return MXC_CPU_IMX8MNUD;
400 return MXC_CPU_IMX8MNDL;
402 return MXC_CPU_IMX8MND;
405 if (value & 0x1000000) {
406 if (value & 0x10000000) /* MIPI DSI */
407 return MXC_CPU_IMX8MNUS;
409 return MXC_CPU_IMX8MNSL;
411 return MXC_CPU_IMX8MNS;
414 if (value & 0x1000000) {
415 if (value & 0x10000000) /* MIPI DSI */
416 return MXC_CPU_IMX8MNUQ;
418 return MXC_CPU_IMX8MNL;
422 } else if (type == MXC_CPU_IMX8MP) {
423 u32 value0 = readl(&fuse->tester3);
426 if ((value0 & 0xc0000) == 0x80000)
427 return MXC_CPU_IMX8MPD;
430 if ((value0 & 0x43000000) == 0x43000000)
434 if ((value & 0x8) == 0x8)
438 if ((value & 0x3) == 0x3)
442 if ((value & 0xc0) == 0xc0)
446 if ((value & 0x180000) == 0x180000)
449 /* mipi dsi disabled */
450 if ((value & 0x60000) == 0x60000)
455 return MXC_CPU_IMX8MPUL;
457 return MXC_CPU_IMX8MPL;
459 return MXC_CPU_IMX8MP6;
469 u32 get_cpu_rev(void)
471 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
472 u32 reg = readl(&ana_pll->digprog);
473 u32 type = (reg >> 16) & 0xff;
474 u32 major_low = (reg >> 8) & 0xff;
480 if (major_low == 0x43) {
481 type = get_cpu_variant_type(MXC_CPU_IMX8MP);
482 } else if (major_low == 0x42) {
484 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
485 } else if (major_low == 0x41) {
486 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
488 if (reg == CHIP_REV_1_0) {
490 * For B0 chip, the DIGPROG is not updated,
491 * it is still TO1.0. we have to check ROM
492 * version or OCOTP_READ_FUSE_DATA.
493 * 0xff0055aa is magic number for B1.
495 if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) {
497 * B2 uses same DIGPROG and OCOTP_READ_FUSE_DATA value with B1,
498 * so have to check ROM to distinguish them
500 rom_version = readl((void __iomem *)ROM_VERSION_B0);
502 if (rom_version == CHIP_REV_2_2)
508 readl((void __iomem *)ROM_VERSION_A0);
509 if (rom_version != CHIP_REV_1_0) {
510 rom_version = readl((void __iomem *)ROM_VERSION_B0);
512 if (rom_version == CHIP_REV_2_0)
518 type = get_cpu_variant_type(type);
521 return (type << 12) | reg;
524 static void imx_set_wdog_powerdown(bool enable)
526 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
527 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
528 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
530 /* Write to the PDE (Power Down Enable) bit */
531 writew(enable, &wdog1->wmcr);
532 writew(enable, &wdog2->wmcr);
533 writew(enable, &wdog3->wmcr);
536 static int imx8m_check_clock(void *ctx, struct event *event)
541 if (CONFIG_IS_ENABLED(CLK)) {
542 ret = uclass_get_device_by_name(UCLASS_CLK,
543 "clock-controller@30380000",
546 printf("Failed to find clock node. Check device tree\n");
553 EVENT_SPY(EVT_DM_POST_INIT_F, imx8m_check_clock);
555 static void imx8m_setup_snvs(void)
557 /* Enable SNVS clock */
558 clock_enable(CCGR_SNVS, 1);
559 /* Initialize glitch detect */
560 writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
561 /* Clear interrupt status */
562 writel(0xffffffff, SNVS_BASE_ADDR + SNVS_LPSR);
565 static void imx8m_setup_csu_tzasc(void)
567 const uintptr_t tzasc_base[4] = {
568 0x301f0000, 0x301f0000, 0x301f0000, 0x301f0000
572 if (!IS_ENABLED(CONFIG_ARMV8_PSCI))
576 for (i = 0; i < 64; i++)
577 writel(0x00ff00ff, (void *)CSU_BASE_ADDR + (4 * i));
580 for (j = 0; j < 4; j++) {
581 writel(0x77777777, (void *)(tzasc_base[j]));
582 writel(0x77777777, (void *)(tzasc_base[j]) + 0x4);
583 for (i = 0; i <= 0x10; i += 4)
584 writel(0, (void *)(tzasc_base[j]) + 0x40 + i);
588 int arch_cpu_init(void)
590 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
592 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
597 * ROM might disable clock for SCTR,
598 * enable the clock before timer_init.
600 if (IS_ENABLED(CONFIG_SPL_BUILD))
601 clock_enable(CCGR_SCTR, 1);
603 * Init timer at very early state, because sscg pll setting
608 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
610 imx_set_wdog_powerdown(false);
612 if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() ||
613 is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() ||
614 is_imx8mnsl() || is_imx8mpd() || is_imx8mnud() || is_imx8mnus()) {
615 /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */
616 struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840);
617 struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880);
618 struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0);
619 struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR;
621 writel(0x1, &pgc_core2->pgcr);
622 writel(0x1, &pgc_core3->pgcr);
623 if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) {
624 writel(0x1, &pgc_core1->pgcr);
625 writel(0xE, &gpc->cpu_pgc_dn_trg);
627 writel(0xC, &gpc->cpu_pgc_dn_trg);
633 clock_enable(CCGR_OCOTP, 1);
634 if (readl(&ocotp->ctrl) & 0x200)
635 writel(0x200, &ocotp->ctrl_clr);
640 imx8m_setup_csu_tzasc();
645 #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
646 struct rom_api *g_rom_api = (struct rom_api *)0x980;
649 #if defined(CONFIG_IMX8M)
651 int spl_mmc_emmc_boot_partition(struct mmc *mmc)
653 u32 *rom_log_addr = (u32 *)0x9e0;
658 part = default_spl_mmc_emmc_boot_partition(mmc);
660 /* If the ROM event log pointer is not valid. */
661 if (*rom_log_addr < 0x900000 || *rom_log_addr >= 0xb00000 ||
665 /* Parse the ROM event ID version 2 log */
666 rom_log = (u32 *)(uintptr_t)(*rom_log_addr);
667 for (i = 0; i < 128; i++) {
668 event_id = rom_log[i] >> 24;
670 case 0x00: /* End of list */
672 /* Log entries with 1 parameter, skip 1 */
673 case 0x80: /* Start to perform the device initialization */
674 case 0x81: /* The boot device initialization completes */
675 case 0x82: /* Starts to execute boot device driver pre-config */
676 case 0x8f: /* The boot device initialization fails */
677 case 0x90: /* Start to read data from boot device */
678 case 0x91: /* Reading data from boot device completes */
679 case 0x9f: /* Reading data from boot device fails */
682 /* Log entries with 2 parameters, skip 2 */
683 case 0xa0: /* Image authentication result */
684 case 0xc0: /* Jump to the boot image soon */
687 /* Boot from the secondary boot image */
690 * Swap the eMMC boot partitions in case there was a
691 * fallback event (i.e. primary image was corrupted
692 * and that corruption was recognized by the BootROM),
693 * so the SPL loads the rest of the U-Boot from the
694 * correct eMMC boot partition, since the BootROM
695 * leaves the boot partition set to the corrupted one.
711 bool is_usb_boot(void)
713 return get_boot_device() == USB_BOOT;
716 #ifdef CONFIG_OF_SYSTEM_SETUP
717 bool check_fdt_new_path(void *blob)
719 const char *soc_path = "/soc@0";
722 nodeoff = fdt_path_offset(blob, soc_path);
729 static int disable_fdt_nodes(void *blob, const char *const nodes_path[], int size_array)
734 const char *status = "disabled";
736 for (i = 0; i < size_array; i++) {
737 nodeoff = fdt_path_offset(blob, nodes_path[i]);
739 continue; /* Not found, skip it */
741 debug("Found %s node\n", nodes_path[i]);
744 rc = fdt_setprop(blob, nodeoff, "status", status, strlen(status) + 1);
746 if (rc == -FDT_ERR_NOSPACE) {
747 rc = fdt_increase_size(blob, 512);
751 printf("Unable to update property %s:%s, err=%s\n",
752 nodes_path[i], "status", fdt_strerror(rc));
754 printf("Modify %s:%s disabled\n",
755 nodes_path[i], "status");
763 bool check_dcss_fused(void)
765 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
766 struct fuse_bank *bank = &ocotp->bank[1];
767 struct fuse_bank1_regs *fuse =
768 (struct fuse_bank1_regs *)bank->fuse_regs;
769 u32 value = readl(&fuse->tester4);
771 if (value & 0x4000000)
777 static int disable_mipi_dsi_nodes(void *blob)
779 static const char * const nodes_path[] = {
780 "/mipi_dsi@30A00000",
781 "/mipi_dsi_bridge@30A00000",
783 "/soc@0/bus@30800000/mipi_dsi@30a00000",
784 "/soc@0/bus@30800000/dphy@30a00300",
785 "/soc@0/bus@30800000/mipi-dsi@30a00000",
788 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
791 static int disable_dcss_nodes(void *blob)
793 static const char * const nodes_path[] = {
797 "/hdmi_cec@32c33800",
798 "/hdmi_drm@32c00000",
799 "/display-subsystem",
802 "/soc@0/bus@32c00000/display-controller@32e00000",
803 "/soc@0/bus@32c00000/hdmi@32c00000",
806 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
809 static int check_mipi_dsi_nodes(void *blob)
811 static const char * const lcdif_path[] = {
813 "/soc@0/bus@30000000/lcdif@30320000",
814 "/soc@0/bus@30000000/lcd-controller@30320000"
816 static const char * const mipi_dsi_path[] = {
817 "/mipi_dsi@30A00000",
818 "/soc@0/bus@30800000/mipi_dsi@30a00000"
820 static const char * const lcdif_ep_path[] = {
821 "/lcdif@30320000/port@0/mipi-dsi-endpoint",
822 "/soc@0/bus@30000000/lcdif@30320000/port@0/endpoint",
823 "/soc@0/bus@30000000/lcd-controller@30320000/port@0/endpoint"
825 static const char * const mipi_dsi_ep_path[] = {
826 "/mipi_dsi@30A00000/port@1/endpoint",
827 "/soc@0/bus@30800000/mipi_dsi@30a00000/ports/port@0/endpoint",
828 "/soc@0/bus@30800000/mipi-dsi@30a00000/ports/port@0/endpoint@0"
833 bool new_path = check_fdt_new_path(blob);
834 int i = new_path ? 1 : 0;
836 nodeoff = fdt_path_offset(blob, lcdif_path[i]);
837 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) {
839 * If can't find lcdif node or lcdif node is disabled,
840 * then disable all mipi dsi, since they only can input
843 return disable_mipi_dsi_nodes(blob);
846 nodeoff = fdt_path_offset(blob, mipi_dsi_path[i]);
847 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff))
850 nodeoff = fdt_path_offset(blob, lcdif_ep_path[i]);
853 * If can't find lcdif endpoint, then disable all mipi dsi,
854 * since they only can input from DCSS
856 return disable_mipi_dsi_nodes(blob);
859 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
860 nodeoff = fdt_path_offset(blob, mipi_dsi_ep_path[i]);
862 if (nodeoff > 0 && nodeoff == lookup_node)
865 return disable_mipi_dsi_nodes(blob);
869 int disable_vpu_nodes(void *blob)
871 static const char * const nodes_path_8mq[] = {
873 "/soc@0/vpu@38300000"
876 static const char * const nodes_path_8mm[] = {
882 static const char * const nodes_path_8mp[] = {
885 "/vpu_vc8000e@38320000"
889 return disable_fdt_nodes(blob, nodes_path_8mq, ARRAY_SIZE(nodes_path_8mq));
890 else if (is_imx8mm())
891 return disable_fdt_nodes(blob, nodes_path_8mm, ARRAY_SIZE(nodes_path_8mm));
892 else if (is_imx8mp())
893 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
898 #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
899 static int low_drive_gpu_freq(void *blob)
901 static const char *nodes_path_8mn[] = {
903 "/soc@0/gpu@38000000"
909 nodeoff = fdt_path_offset(blob, nodes_path_8mn[0]);
913 cnt = fdtdec_get_int_array_count(blob, nodeoff, "assigned-clock-rates", assignedclks, 7);
918 printf("Warning: %s, assigned-clock-rates count %d\n", nodes_path_8mn[0], cnt);
922 assignedclks[cnt - 1] = 200000000;
923 assignedclks[cnt - 2] = 200000000;
925 for (i = 0; i < cnt; i++) {
926 debug("<%u>, ", assignedclks[i]);
927 assignedclks[i] = cpu_to_fdt32(assignedclks[i]);
931 return fdt_setprop(blob, nodeoff, "assigned-clock-rates", &assignedclks, sizeof(assignedclks));
935 static bool check_remote_endpoint(void *blob, const char *ep1, const char *ep2)
940 nodeoff = fdt_path_offset(blob, ep1);
942 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
943 nodeoff = fdt_path_offset(blob, ep2);
945 if (nodeoff > 0 && nodeoff == lookup_node)
952 int disable_dsi_lcdif_nodes(void *blob)
956 static const char * const dsi_path_8mp[] = {
957 "/soc@0/bus@32c00000/mipi_dsi@32e60000"
960 static const char * const lcdif_path_8mp[] = {
961 "/soc@0/bus@32c00000/lcd-controller@32e80000"
964 static const char * const lcdif_ep_path_8mp[] = {
965 "/soc@0/bus@32c00000/lcd-controller@32e80000/port@0/endpoint"
967 static const char * const dsi_ep_path_8mp[] = {
968 "/soc@0/bus@32c00000/mipi_dsi@32e60000/port@0/endpoint"
971 ret = disable_fdt_nodes(blob, dsi_path_8mp, ARRAY_SIZE(dsi_path_8mp));
975 if (check_remote_endpoint(blob, dsi_ep_path_8mp[0], lcdif_ep_path_8mp[0])) {
976 /* Disable lcdif node */
977 return disable_fdt_nodes(blob, lcdif_path_8mp, ARRAY_SIZE(lcdif_path_8mp));
983 int disable_lvds_lcdif_nodes(void *blob)
987 static const char * const ldb_path_8mp[] = {
988 "/soc@0/bus@32c00000/ldb@32ec005c",
989 "/soc@0/bus@32c00000/phy@32ec0128"
992 static const char * const lcdif_path_8mp[] = {
993 "/soc@0/bus@32c00000/lcd-controller@32e90000"
996 static const char * const lcdif_ep_path_8mp[] = {
997 "/soc@0/bus@32c00000/lcd-controller@32e90000/port@0/endpoint@0",
998 "/soc@0/bus@32c00000/lcd-controller@32e90000/port@0/endpoint@1"
1000 static const char * const ldb_ep_path_8mp[] = {
1001 "/soc@0/bus@32c00000/ldb@32ec005c/lvds-channel@0/port@0/endpoint",
1002 "/soc@0/bus@32c00000/ldb@32ec005c/lvds-channel@1/port@0/endpoint"
1005 ret = disable_fdt_nodes(blob, ldb_path_8mp, ARRAY_SIZE(ldb_path_8mp));
1009 for (i = 0; i < ARRAY_SIZE(ldb_ep_path_8mp); i++) {
1010 if (check_remote_endpoint(blob, ldb_ep_path_8mp[i], lcdif_ep_path_8mp[i])) {
1011 /* Disable lcdif node */
1012 return disable_fdt_nodes(blob, lcdif_path_8mp, ARRAY_SIZE(lcdif_path_8mp));
1019 int disable_gpu_nodes(void *blob)
1021 static const char * const nodes_path_8mn[] = {
1023 "/soc@/gpu@38000000"
1026 static const char * const nodes_path_8mp[] = {
1032 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1034 return disable_fdt_nodes(blob, nodes_path_8mn, ARRAY_SIZE(nodes_path_8mn));
1037 int disable_npu_nodes(void *blob)
1039 static const char * const nodes_path_8mp[] = {
1043 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1046 int disable_isp_nodes(void *blob)
1048 static const char * const nodes_path_8mp[] = {
1049 "/soc@0/bus@32c00000/camera/isp@32e10000",
1050 "/soc@0/bus@32c00000/camera/isp@32e20000"
1053 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1056 int disable_dsp_nodes(void *blob)
1058 static const char * const nodes_path_8mp[] = {
1062 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1065 static void disable_thermal_cpu_nodes(void *blob, u32 disabled_cores)
1067 static const char * const thermal_path[] = {
1068 "/thermal-zones/cpu-thermal/cooling-maps/map0"
1071 int nodeoff, cnt, i, ret, j;
1072 u32 cooling_dev[12];
1074 for (i = 0; i < ARRAY_SIZE(thermal_path); i++) {
1075 nodeoff = fdt_path_offset(blob, thermal_path[i]);
1077 continue; /* Not found, skip it */
1079 cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", cooling_dev, 12);
1084 printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt);
1086 for (j = 0; j < cnt; j++)
1087 cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]);
1089 ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev,
1090 sizeof(u32) * (12 - disabled_cores * 3));
1092 printf("Warning: %s, cooling-device setprop failed %d\n",
1093 thermal_path[i], ret);
1097 printf("Update node %s, cooling-device prop\n", thermal_path[i]);
1101 static void disable_pmu_cpu_nodes(void *blob, u32 disabled_cores)
1103 static const char * const pmu_path[] = {
1107 int nodeoff, cnt, i, ret, j;
1108 u32 irq_affinity[4];
1110 for (i = 0; i < ARRAY_SIZE(pmu_path); i++) {
1111 nodeoff = fdt_path_offset(blob, pmu_path[i]);
1113 continue; /* Not found, skip it */
1115 cnt = fdtdec_get_int_array_count(blob, nodeoff, "interrupt-affinity",
1121 printf("Warning: %s, interrupt-affinity count %d\n", pmu_path[i], cnt);
1123 for (j = 0; j < cnt; j++)
1124 irq_affinity[j] = cpu_to_fdt32(irq_affinity[j]);
1126 ret = fdt_setprop(blob, nodeoff, "interrupt-affinity", &irq_affinity,
1127 sizeof(u32) * (4 - disabled_cores));
1129 printf("Warning: %s, interrupt-affinity setprop failed %d\n",
1134 printf("Update node %s, interrupt-affinity prop\n", pmu_path[i]);
1138 static int disable_cpu_nodes(void *blob, u32 disabled_cores)
1140 static const char * const nodes_path[] = {
1149 if (disabled_cores > 3)
1152 i = 3 - disabled_cores;
1154 for (; i < 3; i++) {
1155 nodeoff = fdt_path_offset(blob, nodes_path[i]);
1157 continue; /* Not found, skip it */
1159 debug("Found %s node\n", nodes_path[i]);
1161 rc = fdt_del_node(blob, nodeoff);
1163 printf("Unable to delete node %s, err=%s\n",
1164 nodes_path[i], fdt_strerror(rc));
1166 printf("Delete node %s\n", nodes_path[i]);
1170 disable_thermal_cpu_nodes(blob, disabled_cores);
1171 disable_pmu_cpu_nodes(blob, disabled_cores);
1176 static int cleanup_nodes_for_efi(void *blob)
1178 static const char * const path[][2] = {
1179 { "/soc@0/bus@32c00000/usb@32e40000", "extcon" },
1180 { "/soc@0/bus@32c00000/usb@32e50000", "extcon" },
1181 { "/soc@0/bus@30800000/ethernet@30be0000", "phy-reset-gpios" },
1182 { "/soc@0/bus@30800000/ethernet@30bf0000", "phy-reset-gpios" }
1186 for (i = 0; i < ARRAY_SIZE(path); i++) {
1187 nodeoff = fdt_path_offset(blob, path[i][0]);
1189 continue; /* Not found, skip it */
1190 debug("Found %s node\n", path[i][0]);
1192 rc = fdt_delprop(blob, nodeoff, path[i][1]);
1193 if (rc == -FDT_ERR_NOTFOUND)
1196 printf("Unable to update property %s:%s, err=%s\n",
1197 path[i][0], path[i][1], fdt_strerror(rc));
1201 printf("Remove %s:%s\n", path[i][0], path[i][1]);
1207 static int fixup_thermal_trips(void *blob, const char *name)
1212 node = fdt_path_offset(blob, "/thermal-zones");
1216 node = fdt_subnode_offset(blob, node, name);
1220 node = fdt_subnode_offset(blob, node, "trips");
1224 get_cpu_temp_grade(&minc, &maxc);
1226 fdt_for_each_subnode(trip, blob, node) {
1230 type = fdt_getprop(blob, trip, "type", NULL);
1235 if (!strcmp(type, "critical"))
1237 else if (!strcmp(type, "passive"))
1238 temp = 1000 * (maxc - 10);
1240 ret = fdt_setprop_u32(blob, trip, "temperature", temp);
1249 int ft_system_setup(void *blob, struct bd_info *bd)
1251 #ifdef CONFIG_IMX8MQ
1256 if (get_boot_device() == USB_BOOT) {
1257 disable_dcss_nodes(blob);
1259 bool new_path = check_fdt_new_path(blob);
1260 int v = new_path ? 1 : 0;
1261 static const char * const usb_dwc3_path[] = {
1262 "/usb@38100000/dwc3",
1263 "/soc@0/usb@38100000"
1266 nodeoff = fdt_path_offset(blob, usb_dwc3_path[v]);
1268 const char *speed = "high-speed";
1270 debug("Found %s node\n", usb_dwc3_path[v]);
1274 rc = fdt_setprop(blob, nodeoff, "maximum-speed", speed, strlen(speed) + 1);
1276 if (rc == -FDT_ERR_NOSPACE) {
1277 rc = fdt_increase_size(blob, 512);
1279 goto usb_modify_speed;
1281 printf("Unable to set property %s:%s, err=%s\n",
1282 usb_dwc3_path[v], "maximum-speed", fdt_strerror(rc));
1284 printf("Modify %s:%s = %s\n",
1285 usb_dwc3_path[v], "maximum-speed", speed);
1288 printf("Can't found %s node\n", usb_dwc3_path[v]);
1292 /* Disable the CPU idle for A0 chip since the HW does not support it */
1293 if (is_soc_rev(CHIP_REV_1_0)) {
1294 static const char * const nodes_path[] = {
1301 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
1302 nodeoff = fdt_path_offset(blob, nodes_path[i]);
1304 continue; /* Not found, skip it */
1306 debug("Found %s node\n", nodes_path[i]);
1308 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
1309 if (rc == -FDT_ERR_NOTFOUND)
1312 printf("Unable to update property %s:%s, err=%s\n",
1313 nodes_path[i], "status", fdt_strerror(rc));
1317 debug("Remove %s:%s\n", nodes_path[i],
1323 disable_vpu_nodes(blob);
1324 if (check_dcss_fused()) {
1325 printf("DCSS is fused\n");
1326 disable_dcss_nodes(blob);
1327 check_mipi_dsi_nodes(blob);
1332 disable_cpu_nodes(blob, 2);
1334 #elif defined(CONFIG_IMX8MM)
1335 if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl())
1336 disable_vpu_nodes(blob);
1338 if (is_imx8mmd() || is_imx8mmdl())
1339 disable_cpu_nodes(blob, 2);
1340 else if (is_imx8mms() || is_imx8mmsl())
1341 disable_cpu_nodes(blob, 3);
1343 #elif defined(CONFIG_IMX8MN)
1344 if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl())
1345 disable_gpu_nodes(blob);
1346 #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
1348 int ldm_gpu = low_drive_gpu_freq(blob);
1351 printf("Update GPU node assigned-clock-rates failed\n");
1353 printf("Update GPU node assigned-clock-rates ok\n");
1357 if (is_imx8mnd() || is_imx8mndl() || is_imx8mnud())
1358 disable_cpu_nodes(blob, 2);
1359 else if (is_imx8mns() || is_imx8mnsl() || is_imx8mnus())
1360 disable_cpu_nodes(blob, 3);
1362 #elif defined(CONFIG_IMX8MP)
1363 if (is_imx8mpul()) {
1365 disable_gpu_nodes(blob);
1368 disable_dsi_lcdif_nodes(blob);
1371 disable_lvds_lcdif_nodes(blob);
1374 if (is_imx8mpul() || is_imx8mpl())
1375 disable_vpu_nodes(blob);
1377 if (is_imx8mpul() || is_imx8mpl() || is_imx8mp6())
1378 disable_npu_nodes(blob);
1380 if (is_imx8mpul() || is_imx8mpl())
1381 disable_isp_nodes(blob);
1383 if (is_imx8mpul() || is_imx8mpl() || is_imx8mp6())
1384 disable_dsp_nodes(blob);
1387 disable_cpu_nodes(blob, 2);
1390 cleanup_nodes_for_efi(blob);
1392 if (fixup_thermal_trips(blob, "cpu-thermal"))
1393 printf("Failed to update cpu-thermal trip(s)");
1394 if (IS_ENABLED(CONFIG_IMX8MP) &&
1395 fixup_thermal_trips(blob, "soc-thermal"))
1396 printf("Failed to update soc-thermal trip(s)");
1402 #if !CONFIG_IS_ENABLED(SYSRESET)
1403 void reset_cpu(void)
1405 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
1407 /* Clear WDA to trigger WDOG_B immediately */
1408 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
1412 * spin for .5 seconds before reset
1418 #if defined(CONFIG_ARCH_MISC_INIT)
1419 int arch_misc_init(void)
1421 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
1422 struct udevice *dev;
1425 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
1427 printf("Failed to initialize caam_jr: %d\n", ret);
1434 #if defined(CONFIG_SPL_BUILD)
1435 #if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
1436 bool serror_need_skip = true;
1438 void do_error(struct pt_regs *pt_regs)
1441 * If stack is still in ROM reserved OCRAM not switch to SPL,
1442 * it is the ROM SError
1446 asm volatile("mov %0, sp" : "=r"(sp) : );
1448 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
1449 /* Check for ERR050342, imx8mq HDCP enabled parts */
1450 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
1451 serror_need_skip = false;
1452 return; /* Do nothing skip the SError in ROM */
1455 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
1456 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
1457 serror_need_skip = false;
1458 return; /* Do nothing skip the SError in ROM */
1463 printf("\"Error\" handler, esr 0x%08lx\n", pt_regs->esr);
1465 panic("Resetting CPU ...\n");
1470 #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
1471 enum env_location arch_env_get_location(enum env_operation op, int prio)
1473 enum boot_device dev = get_boot_device();
1476 return ENVL_UNKNOWN;
1480 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
1481 return ENVL_SPI_FLASH;
1482 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
1484 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
1486 if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
1487 return ENVL_NOWHERE;
1488 return ENVL_UNKNOWN;
1491 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
1492 return ENVL_SPI_FLASH;
1493 return ENVL_NOWHERE;
1495 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
1497 return ENVL_NOWHERE;
1504 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
1506 else if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
1508 else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
1510 return ENVL_NOWHERE;
1512 return ENVL_NOWHERE;
1518 #ifdef CONFIG_IMX_BOOTAUX
1519 const struct rproc_att hostmap[] = {
1520 /* aux core , host core, size */
1521 { 0x00000000, 0x007e0000, 0x00020000 },
1523 { 0x00180000, 0x00180000, 0x00008000 },
1525 { 0x00900000, 0x00900000, 0x00020000 },
1527 { 0x00920000, 0x00920000, 0x00020000 },
1528 /* QSPI Code - alias */
1529 { 0x08000000, 0x08000000, 0x08000000 },
1530 /* DDR (Code) - alias */
1531 { 0x10000000, 0x80000000, 0x0FFE0000 },
1533 { 0x1FFE0000, 0x007E0000, 0x00040000 },
1535 { 0x20180000, 0x00180000, 0x00008000 },
1537 { 0x20200000, 0x00900000, 0x00040000 },
1539 { 0x40000000, 0x40000000, 0x80000000 },
1543 const struct rproc_att *imx_bootaux_get_hostmap(void)