1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017-2019 NXP
5 * Peng Fan <peng.fan@nxp.com>
12 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/clock.h>
15 #include <asm/arch/sys_proto.h>
16 #include <asm/mach-imx/hab.h>
17 #include <asm/mach-imx/boot_mode.h>
18 #include <asm/mach-imx/syscounter.h>
19 #include <asm/ptrace.h>
20 #include <asm/armv8/mmu.h>
21 #include <dm/uclass.h>
22 #include <efi_loader.h>
24 #include <env_internal.h>
26 #include <fdt_support.h>
29 #include <linux/arm-smccc.h>
30 #include <linux/bitops.h>
32 DECLARE_GLOBAL_DATA_PTR;
34 #if defined(CONFIG_IMX_HAB)
35 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
43 #ifdef CONFIG_SPL_BUILD
44 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
45 unsigned long freq = readl(&sctr->cntfid0);
47 /* Update with accurate clock frequency */
48 asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
50 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
51 SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
60 void enable_tzc380(void)
62 struct iomuxc_gpr_base_regs *gpr =
63 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
65 /* Enable TZASC and lock setting */
66 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN);
67 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK);
68 if (is_imx8mm() || is_imx8mn() || is_imx8mp())
69 setbits_le32(&gpr->gpr[10], BIT(1));
71 * set Region 0 attribute to allow secure and non-secure
72 * read/write permission. Found some masters like usb dwc3
73 * controllers can't work with secure memory.
75 writel(0xf0000000, TZASC_BASE_ADDR + 0x108);
78 void set_wdog_reset(struct wdog_regs *wdog)
81 * Output WDOG_B signal to reset external pmic or POR_B decided by
82 * the board design. Without external reset, the peripherals/DDR/
83 * PMIC are not reset, that may cause system working abnormal.
84 * WDZST bit is write-once only bit. Align this bit in kernel,
85 * otherwise kernel code will have no chance to set this bit.
87 setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK);
90 static struct mm_region imx8m_mem_map[] = {
96 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
103 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
104 PTE_BLOCK_NON_SHARE |
105 PTE_BLOCK_PXN | PTE_BLOCK_UXN
111 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
112 PTE_BLOCK_NON_SHARE |
113 PTE_BLOCK_PXN | PTE_BLOCK_UXN
119 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
120 PTE_BLOCK_OUTER_SHARE
125 .size = 0x3f500000UL,
126 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
127 PTE_BLOCK_NON_SHARE |
128 PTE_BLOCK_PXN | PTE_BLOCK_UXN
131 .virt = 0x40000000UL,
132 .phys = 0x40000000UL,
133 .size = PHYS_SDRAM_SIZE,
134 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
135 PTE_BLOCK_OUTER_SHARE
136 #ifdef PHYS_SDRAM_2_SIZE
139 .virt = 0x100000000UL,
140 .phys = 0x100000000UL,
141 .size = PHYS_SDRAM_2_SIZE,
142 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
143 PTE_BLOCK_OUTER_SHARE
146 /* empty entrie to split table entry 5 if needed when TEEs are used */
149 /* List terminator */
154 struct mm_region *mem_map = imx8m_mem_map;
156 void enable_caches(void)
158 /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch */
159 if (rom_pointer[1]) {
161 * TEE are loaded, So the ddr bank structures
162 * have been modified update mmu table accordingly
166 * please make sure that entry initial value matches
167 * imx8m_mem_map for DRAM1
170 u64 attrs = imx8m_mem_map[entry].attrs;
172 while (i < CONFIG_NR_DRAM_BANKS && entry < 8) {
173 if (gd->bd->bi_dram[i].start == 0)
175 imx8m_mem_map[entry].phys = gd->bd->bi_dram[i].start;
176 imx8m_mem_map[entry].virt = gd->bd->bi_dram[i].start;
177 imx8m_mem_map[entry].size = gd->bd->bi_dram[i].size;
178 imx8m_mem_map[entry].attrs = attrs;
179 debug("Added memory mapping (%d): %llx %llx\n", entry,
180 imx8m_mem_map[entry].phys, imx8m_mem_map[entry].size);
189 __weak int board_phys_sdram_size(phys_size_t *size)
194 *size = PHYS_SDRAM_SIZE;
200 phys_size_t sdram_size;
203 ret = board_phys_sdram_size(&sdram_size);
207 /* rom_pointer[1] contains the size of TEE occupies */
209 gd->ram_size = sdram_size - rom_pointer[1];
211 gd->ram_size = sdram_size;
213 #ifdef PHYS_SDRAM_2_SIZE
214 gd->ram_size += PHYS_SDRAM_2_SIZE;
220 int dram_init_banksize(void)
224 phys_size_t sdram_size;
226 ret = board_phys_sdram_size(&sdram_size);
230 gd->bd->bi_dram[bank].start = PHYS_SDRAM;
231 if (rom_pointer[1]) {
232 phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
233 phys_size_t optee_size = (size_t)rom_pointer[1];
235 gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start;
236 if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_size)) {
237 if (++bank >= CONFIG_NR_DRAM_BANKS) {
238 puts("CONFIG_NR_DRAM_BANKS is not enough\n");
242 gd->bd->bi_dram[bank].start = optee_start + optee_size;
243 gd->bd->bi_dram[bank].size = PHYS_SDRAM +
244 sdram_size - gd->bd->bi_dram[bank].start;
247 gd->bd->bi_dram[bank].size = sdram_size;
250 #ifdef PHYS_SDRAM_2_SIZE
251 if (++bank >= CONFIG_NR_DRAM_BANKS) {
252 puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n");
255 gd->bd->bi_dram[bank].start = PHYS_SDRAM_2;
256 gd->bd->bi_dram[bank].size = PHYS_SDRAM_2_SIZE;
262 phys_size_t get_effective_memsize(void)
264 /* return the first bank as effective memory */
266 return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM);
268 #ifdef PHYS_SDRAM_2_SIZE
269 return gd->ram_size - PHYS_SDRAM_2_SIZE;
275 static u32 get_cpu_variant_type(u32 type)
277 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
278 struct fuse_bank *bank = &ocotp->bank[1];
279 struct fuse_bank1_regs *fuse =
280 (struct fuse_bank1_regs *)bank->fuse_regs;
282 u32 value = readl(&fuse->tester4);
284 if (type == MXC_CPU_IMX8MQ) {
285 if ((value & 0x3) == 0x2)
286 return MXC_CPU_IMX8MD;
287 else if (value & 0x200000)
288 return MXC_CPU_IMX8MQL;
290 } else if (type == MXC_CPU_IMX8MM) {
291 switch (value & 0x3) {
293 if (value & 0x1c0000)
294 return MXC_CPU_IMX8MMDL;
296 return MXC_CPU_IMX8MMD;
298 if (value & 0x1c0000)
299 return MXC_CPU_IMX8MMSL;
301 return MXC_CPU_IMX8MMS;
303 if (value & 0x1c0000)
304 return MXC_CPU_IMX8MML;
307 } else if (type == MXC_CPU_IMX8MN) {
308 switch (value & 0x3) {
310 if (value & 0x1000000)
311 return MXC_CPU_IMX8MNDL;
313 return MXC_CPU_IMX8MND;
315 if (value & 0x1000000)
316 return MXC_CPU_IMX8MNSL;
318 return MXC_CPU_IMX8MNS;
320 if (value & 0x1000000)
321 return MXC_CPU_IMX8MNL;
324 } else if (type == MXC_CPU_IMX8MP) {
325 u32 value0 = readl(&fuse->tester3);
328 if ((value0 & 0xc0000) == 0x80000)
329 return MXC_CPU_IMX8MPD;
332 if ((value0 & 0x43000000) == 0x43000000)
336 if ((value & 0x8) == 0x8)
340 if ((value & 0x3) == 0x3)
345 return MXC_CPU_IMX8MPL;
347 return MXC_CPU_IMX8MP6;
357 u32 get_cpu_rev(void)
359 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
360 u32 reg = readl(&ana_pll->digprog);
361 u32 type = (reg >> 16) & 0xff;
362 u32 major_low = (reg >> 8) & 0xff;
368 if (major_low == 0x43) {
369 type = get_cpu_variant_type(MXC_CPU_IMX8MP);
370 } else if (major_low == 0x42) {
372 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
373 } else if (major_low == 0x41) {
374 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
376 if (reg == CHIP_REV_1_0) {
378 * For B0 chip, the DIGPROG is not updated,
379 * it is still TO1.0. we have to check ROM
380 * version or OCOTP_READ_FUSE_DATA.
381 * 0xff0055aa is magic number for B1.
383 if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) {
387 readl((void __iomem *)ROM_VERSION_A0);
388 if (rom_version != CHIP_REV_1_0) {
389 rom_version = readl((void __iomem *)ROM_VERSION_B0);
391 if (rom_version == CHIP_REV_2_0)
397 type = get_cpu_variant_type(type);
400 return (type << 12) | reg;
403 static void imx_set_wdog_powerdown(bool enable)
405 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
406 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
407 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
409 /* Write to the PDE (Power Down Enable) bit */
410 writew(enable, &wdog1->wmcr);
411 writew(enable, &wdog2->wmcr);
412 writew(enable, &wdog3->wmcr);
415 int arch_cpu_init_dm(void)
420 if (CONFIG_IS_ENABLED(CLK)) {
421 ret = uclass_get_device_by_name(UCLASS_CLK,
422 "clock-controller@30380000",
425 printf("Failed to find clock node. Check device tree\n");
433 int arch_cpu_init(void)
435 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
437 * ROM might disable clock for SCTR,
438 * enable the clock before timer_init.
440 if (IS_ENABLED(CONFIG_SPL_BUILD))
441 clock_enable(CCGR_SCTR, 1);
443 * Init timer at very early state, because sscg pll setting
448 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
450 imx_set_wdog_powerdown(false);
452 if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() ||
453 is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() ||
454 is_imx8mnsl() || is_imx8mpd()) {
455 /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */
456 struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840);
457 struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880);
458 struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0);
459 struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR;
461 writel(0x1, &pgc_core2->pgcr);
462 writel(0x1, &pgc_core3->pgcr);
463 if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl()) {
464 writel(0x1, &pgc_core1->pgcr);
465 writel(0xE, &gpc->cpu_pgc_dn_trg);
467 writel(0xC, &gpc->cpu_pgc_dn_trg);
473 clock_enable(CCGR_OCOTP, 1);
474 if (readl(&ocotp->ctrl) & 0x200)
475 writel(0x200, &ocotp->ctrl_clr);
481 #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
482 struct rom_api *g_rom_api = (struct rom_api *)0x980;
484 enum boot_device get_boot_device(void)
486 volatile gd_t *pgd = gd;
491 enum boot_device boot_dev = SD1_BOOT;
493 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
494 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
497 if (ret != ROM_API_OKAY) {
498 puts("ROMAPI: failure at query_boot_info\n");
502 boot_type = boot >> 16;
503 boot_instance = (boot >> 8) & 0xff;
507 boot_dev = boot_instance + SD1_BOOT;
509 case BT_DEV_TYPE_MMC:
510 boot_dev = boot_instance + MMC1_BOOT;
512 case BT_DEV_TYPE_NAND:
513 boot_dev = NAND_BOOT;
515 case BT_DEV_TYPE_FLEXSPINOR:
516 boot_dev = QSPI_BOOT;
518 case BT_DEV_TYPE_USB:
529 bool is_usb_boot(void)
531 return get_boot_device() == USB_BOOT;
534 #ifdef CONFIG_OF_SYSTEM_SETUP
535 bool check_fdt_new_path(void *blob)
537 const char *soc_path = "/soc@0";
540 nodeoff = fdt_path_offset(blob, soc_path);
547 static int disable_fdt_nodes(void *blob, const char *const nodes_path[], int size_array)
552 const char *status = "disabled";
554 for (i = 0; i < size_array; i++) {
555 nodeoff = fdt_path_offset(blob, nodes_path[i]);
557 continue; /* Not found, skip it */
559 printf("Found %s node\n", nodes_path[i]);
562 rc = fdt_setprop(blob, nodeoff, "status", status, strlen(status) + 1);
564 if (rc == -FDT_ERR_NOSPACE) {
565 rc = fdt_increase_size(blob, 512);
569 printf("Unable to update property %s:%s, err=%s\n",
570 nodes_path[i], "status", fdt_strerror(rc));
572 printf("Modify %s:%s disabled\n",
573 nodes_path[i], "status");
581 bool check_dcss_fused(void)
583 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
584 struct fuse_bank *bank = &ocotp->bank[1];
585 struct fuse_bank1_regs *fuse =
586 (struct fuse_bank1_regs *)bank->fuse_regs;
587 u32 value = readl(&fuse->tester4);
589 if (value & 0x4000000)
595 static int disable_mipi_dsi_nodes(void *blob)
597 static const char * const nodes_path[] = {
598 "/mipi_dsi@30A00000",
599 "/mipi_dsi_bridge@30A00000",
601 "/soc@0/bus@30800000/mipi_dsi@30a00000",
602 "/soc@0/bus@30800000/dphy@30a00300"
605 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
608 static int disable_dcss_nodes(void *blob)
610 static const char * const nodes_path[] = {
614 "/hdmi_cec@32c33800",
615 "/hdmi_drm@32c00000",
616 "/display-subsystem",
619 "/soc@0/bus@32c00000/display-controller@32e00000",
620 "/soc@0/bus@32c00000/hdmi@32c00000",
623 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
626 static int check_mipi_dsi_nodes(void *blob)
628 static const char * const lcdif_path[] = {
630 "/soc@0/bus@30000000/lcdif@30320000"
632 static const char * const mipi_dsi_path[] = {
633 "/mipi_dsi@30A00000",
634 "/soc@0/bus@30800000/mipi_dsi@30a00000"
636 static const char * const lcdif_ep_path[] = {
637 "/lcdif@30320000/port@0/mipi-dsi-endpoint",
638 "/soc@0/bus@30000000/lcdif@30320000/port@0/endpoint"
640 static const char * const mipi_dsi_ep_path[] = {
641 "/mipi_dsi@30A00000/port@1/endpoint",
642 "/soc@0/bus@30800000/mipi_dsi@30a00000/ports/port@0/endpoint"
647 bool new_path = check_fdt_new_path(blob);
648 int i = new_path ? 1 : 0;
650 nodeoff = fdt_path_offset(blob, lcdif_path[i]);
651 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) {
653 * If can't find lcdif node or lcdif node is disabled,
654 * then disable all mipi dsi, since they only can input
657 return disable_mipi_dsi_nodes(blob);
660 nodeoff = fdt_path_offset(blob, mipi_dsi_path[i]);
661 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff))
664 nodeoff = fdt_path_offset(blob, lcdif_ep_path[i]);
667 * If can't find lcdif endpoint, then disable all mipi dsi,
668 * since they only can input from DCSS
670 return disable_mipi_dsi_nodes(blob);
673 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
674 nodeoff = fdt_path_offset(blob, mipi_dsi_ep_path[i]);
676 if (nodeoff > 0 && nodeoff == lookup_node)
679 return disable_mipi_dsi_nodes(blob);
683 int disable_vpu_nodes(void *blob)
685 static const char * const nodes_path_8mq[] = {
687 "/soc@0/vpu@38300000"
690 static const char * const nodes_path_8mm[] = {
696 static const char * const nodes_path_8mp[] = {
699 "/vpu_vc8000e@38320000"
703 return disable_fdt_nodes(blob, nodes_path_8mq, ARRAY_SIZE(nodes_path_8mq));
704 else if (is_imx8mm())
705 return disable_fdt_nodes(blob, nodes_path_8mm, ARRAY_SIZE(nodes_path_8mm));
706 else if (is_imx8mp())
707 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
712 int disable_gpu_nodes(void *blob)
714 static const char * const nodes_path_8mn[] = {
718 return disable_fdt_nodes(blob, nodes_path_8mn, ARRAY_SIZE(nodes_path_8mn));
721 int disable_npu_nodes(void *blob)
723 static const char * const nodes_path_8mp[] = {
727 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
730 int disable_isp_nodes(void *blob)
732 static const char * const nodes_path_8mp[] = {
733 "/soc@0/bus@32c00000/camera/isp@32e10000",
734 "/soc@0/bus@32c00000/camera/isp@32e20000"
737 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
740 int disable_dsp_nodes(void *blob)
742 static const char * const nodes_path_8mp[] = {
746 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
749 static int disable_cpu_nodes(void *blob, u32 disabled_cores)
751 static const char * const nodes_path[] = {
760 if (disabled_cores > 3)
763 i = 3 - disabled_cores;
766 nodeoff = fdt_path_offset(blob, nodes_path[i]);
768 continue; /* Not found, skip it */
770 debug("Found %s node\n", nodes_path[i]);
772 rc = fdt_del_node(blob, nodeoff);
774 printf("Unable to delete node %s, err=%s\n",
775 nodes_path[i], fdt_strerror(rc));
777 printf("Delete node %s\n", nodes_path[i]);
784 int ft_system_setup(void *blob, struct bd_info *bd)
791 if (get_boot_device() == USB_BOOT) {
792 disable_dcss_nodes(blob);
794 bool new_path = check_fdt_new_path(blob);
795 int v = new_path ? 1 : 0;
796 static const char * const usb_dwc3_path[] = {
797 "/usb@38100000/dwc3",
798 "/soc@0/usb@38100000"
801 nodeoff = fdt_path_offset(blob, usb_dwc3_path[v]);
803 const char *speed = "high-speed";
805 printf("Found %s node\n", usb_dwc3_path[v]);
809 rc = fdt_setprop(blob, nodeoff, "maximum-speed", speed, strlen(speed) + 1);
811 if (rc == -FDT_ERR_NOSPACE) {
812 rc = fdt_increase_size(blob, 512);
814 goto usb_modify_speed;
816 printf("Unable to set property %s:%s, err=%s\n",
817 usb_dwc3_path[v], "maximum-speed", fdt_strerror(rc));
819 printf("Modify %s:%s = %s\n",
820 usb_dwc3_path[v], "maximum-speed", speed);
823 printf("Can't found %s node\n", usb_dwc3_path[v]);
827 /* Disable the CPU idle for A0 chip since the HW does not support it */
828 if (is_soc_rev(CHIP_REV_1_0)) {
829 static const char * const nodes_path[] = {
836 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
837 nodeoff = fdt_path_offset(blob, nodes_path[i]);
839 continue; /* Not found, skip it */
841 debug("Found %s node\n", nodes_path[i]);
843 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
844 if (rc == -FDT_ERR_NOTFOUND)
847 printf("Unable to update property %s:%s, err=%s\n",
848 nodes_path[i], "status", fdt_strerror(rc));
852 debug("Remove %s:%s\n", nodes_path[i],
858 disable_vpu_nodes(blob);
859 if (check_dcss_fused()) {
860 printf("DCSS is fused\n");
861 disable_dcss_nodes(blob);
862 check_mipi_dsi_nodes(blob);
867 disable_cpu_nodes(blob, 2);
869 #elif defined(CONFIG_IMX8MM)
870 if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl())
871 disable_vpu_nodes(blob);
873 if (is_imx8mmd() || is_imx8mmdl())
874 disable_cpu_nodes(blob, 2);
875 else if (is_imx8mms() || is_imx8mmsl())
876 disable_cpu_nodes(blob, 3);
878 #elif defined(CONFIG_IMX8MN)
879 if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl())
880 disable_gpu_nodes(blob);
882 if (is_imx8mnd() || is_imx8mndl())
883 disable_cpu_nodes(blob, 2);
884 else if (is_imx8mns() || is_imx8mnsl())
885 disable_cpu_nodes(blob, 3);
887 #elif defined(CONFIG_IMX8MP)
889 disable_vpu_nodes(blob);
891 if (is_imx8mpl() || is_imx8mp6())
892 disable_npu_nodes(blob);
895 disable_isp_nodes(blob);
897 if (is_imx8mpl() || is_imx8mp6())
898 disable_dsp_nodes(blob);
901 disable_cpu_nodes(blob, 2);
908 #if !CONFIG_IS_ENABLED(SYSRESET)
909 void reset_cpu(ulong addr)
911 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
913 /* Clear WDA to trigger WDOG_B immediately */
914 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
918 * spin for .5 seconds before reset
924 #if defined(CONFIG_ARCH_MISC_INIT)
925 static void acquire_buildinfo(void)
928 struct arm_smccc_res res;
930 /* Get ARM Trusted Firmware commit id */
931 arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH,
932 0, 0, 0, 0, 0, 0, &res);
934 if (atf_commit == 0xffffffff) {
935 debug("ATF does not support build info\n");
936 atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */
939 printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit);
942 int arch_misc_init(void)
950 void imx_tmu_arch_init(void *reg_base)
952 if (is_imx8mm() || is_imx8mn()) {
953 /* Load TCALIV and TASR from fuses */
954 struct ocotp_regs *ocotp =
955 (struct ocotp_regs *)OCOTP_BASE_ADDR;
956 struct fuse_bank *bank = &ocotp->bank[3];
957 struct fuse_bank3_regs *fuse =
958 (struct fuse_bank3_regs *)bank->fuse_regs;
960 u32 tca_rt, tca_hr, tca_en;
961 u32 buf_vref, buf_slope;
963 tca_rt = fuse->ana0 & 0xFF;
964 tca_hr = (fuse->ana0 & 0xFF00) >> 8;
965 tca_en = (fuse->ana0 & 0x2000000) >> 25;
967 buf_vref = (fuse->ana0 & 0x1F00000) >> 20;
968 buf_slope = (fuse->ana0 & 0xF0000) >> 16;
970 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
971 writel((tca_en << 31) | (tca_hr << 16) | tca_rt,
972 (ulong)reg_base + 0x30);
975 /* Load TCALIV0/1/m40 and TRIM from fuses */
976 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
977 struct fuse_bank *bank = &ocotp->bank[38];
978 struct fuse_bank38_regs *fuse =
979 (struct fuse_bank38_regs *)bank->fuse_regs;
980 struct fuse_bank *bank2 = &ocotp->bank[39];
981 struct fuse_bank39_regs *fuse2 =
982 (struct fuse_bank39_regs *)bank2->fuse_regs;
983 u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr;
985 u32 tca40[2], tca25[2], tca105[2];
987 /* For blank sample */
988 if (!fuse->ana_trim2 && !fuse->ana_trim3 &&
989 !fuse->ana_trim4 && !fuse2->ana_trim5) {
990 /* Use a default 25C binary codes */
993 writel(tca25[0], (ulong)reg_base + 0x30);
994 writel(tca25[1], (ulong)reg_base + 0x34);
998 buf_vref = (fuse->ana_trim2 & 0xc0) >> 6;
999 buf_slope = (fuse->ana_trim2 & 0xF00) >> 8;
1000 bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12;
1001 bgr = (fuse->ana_trim2 & 0xF0000) >> 16;
1002 vlsb = (fuse->ana_trim2 & 0xF00000) >> 20;
1003 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
1005 reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7);
1006 writel(reg, (ulong)reg_base + 0x3c);
1008 tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16;
1009 tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28;
1010 tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4);
1011 tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8;
1012 tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20;
1013 tca25[1] = fuse2->ana_trim5 & 0xFFF;
1014 tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12;
1016 /* use 25c for 1p calibration */
1017 writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30);
1018 writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34);
1019 writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38);
1023 #if defined(CONFIG_SPL_BUILD)
1024 #if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
1025 bool serror_need_skip = true;
1027 void do_error(struct pt_regs *pt_regs, unsigned int esr)
1030 * If stack is still in ROM reserved OCRAM not switch to SPL,
1031 * it is the ROM SError
1035 asm volatile("mov %0, sp" : "=r"(sp) : );
1037 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
1038 /* Check for ERR050342, imx8mq HDCP enabled parts */
1039 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
1040 serror_need_skip = false;
1041 return; /* Do nothing skip the SError in ROM */
1044 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
1045 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
1046 serror_need_skip = false;
1047 return; /* Do nothing skip the SError in ROM */
1052 printf("\"Error\" handler, esr 0x%08x\n", esr);
1054 panic("Resetting CPU ...\n");
1059 #if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
1060 enum env_location env_get_location(enum env_operation op, int prio)
1062 enum boot_device dev = get_boot_device();
1063 enum env_location env_loc = ENVL_UNKNOWN;
1069 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
1071 env_loc = ENVL_SPI_FLASH;
1074 #ifdef CONFIG_ENV_IS_IN_NAND
1076 env_loc = ENVL_NAND;
1079 #ifdef CONFIG_ENV_IS_IN_MMC
1090 #if defined(CONFIG_ENV_IS_NOWHERE)
1091 env_loc = ENVL_NOWHERE;
1099 #ifndef ENV_IS_EMBEDDED
1100 long long env_get_offset(long long defautl_offset)
1102 enum boot_device dev = get_boot_device();
1106 return (60 << 20); /* 60MB offset for NAND */
1111 return defautl_offset;