1 // SPDX-License-Identifier: GPL-2.0+
7 #include <asm/arch/clock.h>
8 #include <asm/arch/imx-regs.h>
9 #include <asm/arch/sys_proto.h>
10 #include <asm/armv8/mmu.h>
11 #include <asm/mach-imx/boot_mode.h>
12 #include <asm/global_data.h>
13 #include <efi_loader.h>
15 #include <asm/arch/rdc.h>
16 #include <asm/arch/s400_api.h>
17 #include <asm/arch/mu_hal.h>
19 #include <asm/setup.h>
21 #include <dm/device-internal.h>
23 #include <dm/uclass.h>
24 #include <dm/device.h>
25 #include <dm/uclass-internal.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 struct rom_api *g_rom_api = (struct rom_api *)0x1980;
32 enum boot_device get_boot_device(void)
34 volatile gd_t *pgd = gd;
39 enum boot_device boot_dev = SD1_BOOT;
41 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
42 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
45 if (ret != ROM_API_OKAY) {
46 puts("ROMAPI: failure at query_boot_info\n");
50 boot_type = boot >> 16;
51 boot_instance = (boot >> 8) & 0xff;
55 boot_dev = boot_instance + SD1_BOOT;
58 boot_dev = boot_instance + MMC1_BOOT;
60 case BT_DEV_TYPE_NAND:
63 case BT_DEV_TYPE_FLEXSPINOR:
76 bool is_usb_boot(void)
78 return get_boot_device() == USB_BOOT;
81 #ifdef CONFIG_ENV_IS_IN_MMC
82 __weak int board_mmc_get_env_dev(int devno)
87 int mmc_get_env_dev(void)
89 volatile gd_t *pgd = gd;
95 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
96 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
99 if (ret != ROM_API_OKAY) {
100 puts("ROMAPI: failure at query_boot_info\n");
101 return CONFIG_SYS_MMC_ENV_DEV;
104 boot_type = boot >> 16;
105 boot_instance = (boot >> 8) & 0xff;
107 /* If not boot from sd/mmc, use default value */
108 if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC)
109 return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV);
111 return board_mmc_get_env_dev(boot_instance);
115 u32 get_cpu_rev(void)
117 return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0;
120 enum bt_mode get_boot_mode(void)
124 bt0_cfg = readl(SIM_SEC_BASE_ADDR + 0x24);
125 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
127 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
128 /* No low power boot */
129 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
135 return LOW_POWER_BOOT;
138 #define CMC_SRS_TAMPER BIT(31)
139 #define CMC_SRS_SECURITY BIT(30)
140 #define CMC_SRS_TZWDG BIT(29)
141 #define CMC_SRS_JTAG_RST BIT(28)
142 #define CMC_SRS_CORE1 BIT(16)
143 #define CMC_SRS_LOCKUP BIT(15)
144 #define CMC_SRS_SW BIT(14)
145 #define CMC_SRS_WDG BIT(13)
146 #define CMC_SRS_PIN_RESET BIT(8)
147 #define CMC_SRS_WARM BIT(4)
148 #define CMC_SRS_HVD BIT(3)
149 #define CMC_SRS_LVD BIT(2)
150 #define CMC_SRS_POR BIT(1)
151 #define CMC_SRS_WUP BIT(0)
153 static char *get_reset_cause(char *ret)
155 u32 cause1, cause = 0, srs = 0;
156 void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88);
157 void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80);
162 srs = readl(reg_srs);
163 cause1 = readl(reg_ssrs);
165 cause = srs & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
169 sprintf(ret, "%s", "POR");
172 sprintf(ret, "%s", "WUP");
175 cause = srs & (CMC_SRS_WDG | CMC_SRS_SW |
179 sprintf(ret, "%s", "WARM-WDG");
182 sprintf(ret, "%s", "WARM-SW");
184 case CMC_SRS_JTAG_RST:
185 sprintf(ret, "%s", "WARM-JTAG");
188 sprintf(ret, "%s", "WARM-UNKN");
193 sprintf(ret, "%s-%X", "UNKN", srs);
197 debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1);
201 #if defined(CONFIG_DISPLAY_CPUINFO)
202 const char *get_imx_type(u32 imxtype)
207 int print_cpuinfo(void)
212 cpurev = get_cpu_rev();
214 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
215 get_imx_type((cpurev & 0xFF000) >> 12),
216 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
217 mxc_get_clock(MXC_ARM_CLK) / 1000000);
219 printf("Reset cause: %s\n", get_reset_cause(cause));
221 printf("Boot mode: ");
222 switch (get_boot_mode()) {
224 printf("Low power boot\n");
227 printf("Dual boot\n");
231 printf("Single boot\n");
239 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
240 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
241 #define REFRESH_WORD0 0xA602 /* 1st refresh word */
242 #define REFRESH_WORD1 0xB480 /* 2nd refresh word */
244 static void disable_wdog(void __iomem *wdog_base)
246 u32 val_cs = readl(wdog_base + 0x00);
248 if (!(val_cs & 0x80))
252 __raw_writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
253 __raw_writel(REFRESH_WORD1, (wdog_base + 0x04));
256 if (!(val_cs & 800)) {
258 __raw_writel(UNLOCK_WORD0, (wdog_base + 0x04));
259 __raw_writel(UNLOCK_WORD1, (wdog_base + 0x04));
262 while (!(readl(wdog_base + 0x00) & 0x800))
265 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
266 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
267 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
269 while (!(readl(wdog_base + 0x00) & 0x400))
275 disable_wdog((void __iomem *)WDG3_RBASE);
278 static struct mm_region imx8ulp_arm64_mem_map[] = {
284 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
285 PTE_BLOCK_OUTER_SHARE
291 .size = 0x08000000UL,
292 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
293 PTE_BLOCK_NON_SHARE |
294 PTE_BLOCK_PXN | PTE_BLOCK_UXN
297 /* SSRAM (align with 2M) */
298 .virt = 0x1FE00000UL,
299 .phys = 0x1FE00000UL,
301 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
302 PTE_BLOCK_OUTER_SHARE |
303 PTE_BLOCK_PXN | PTE_BLOCK_UXN
305 /* SRAM1 (align with 2M) */
306 .virt = 0x21000000UL,
307 .phys = 0x21000000UL,
309 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
310 PTE_BLOCK_OUTER_SHARE |
311 PTE_BLOCK_PXN | PTE_BLOCK_UXN
313 /* SRAM0 (align with 2M) */
314 .virt = 0x22000000UL,
315 .phys = 0x22000000UL,
317 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
318 PTE_BLOCK_OUTER_SHARE |
319 PTE_BLOCK_PXN | PTE_BLOCK_UXN
322 .virt = 0x27000000UL,
323 .phys = 0x27000000UL,
325 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
326 PTE_BLOCK_NON_SHARE |
327 PTE_BLOCK_PXN | PTE_BLOCK_UXN
330 .virt = 0x2D000000UL,
331 .phys = 0x2D000000UL,
333 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
334 PTE_BLOCK_NON_SHARE |
335 PTE_BLOCK_PXN | PTE_BLOCK_UXN
338 .virt = 0x40000000UL,
339 .phys = 0x40000000UL,
340 .size = 0x40000000UL,
341 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
342 PTE_BLOCK_NON_SHARE |
343 PTE_BLOCK_PXN | PTE_BLOCK_UXN
346 .virt = 0x80000000UL,
347 .phys = 0x80000000UL,
348 .size = PHYS_SDRAM_SIZE,
349 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
350 PTE_BLOCK_OUTER_SHARE
353 * empty entrie to split table entry 5
354 * if needed when TEEs are used
358 /* List terminator */
363 struct mm_region *mem_map = imx8ulp_arm64_mem_map;
365 /* simplify the page table size to enhance boot speed */
366 #define MAX_PTE_ENTRIES 512
367 #define MAX_MEM_MAP_REGIONS 16
368 u64 get_page_table_size(void)
370 u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
374 * For each memory region, the max table size:
375 * 2 level 3 tables + 2 level 2 tables + 1 level 1 table
377 size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt;
380 * We need to duplicate our page table once to have an emergency pt to
381 * resort to when splitting page tables later on
386 * We may need to split page tables later on if dcache settings change,
387 * so reserve up to 4 (random pick) page tables for that.
394 void enable_caches(void)
396 /* TODO: add TEE memmap region */
404 gd->ram_size = PHYS_SDRAM_SIZE;
409 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
410 void get_board_serial(struct tag_serialnr *serialnr)
416 ret = ahab_read_common_fuse(1, uid, 4, &res);
418 printf("ahab read fuse failed %d, 0x%x\n", ret, res);
420 printf("UID 0x%x,0x%x,0x%x,0x%x\n", uid[0], uid[1], uid[2], uid[3]);
422 serialnr->low = uid[0];
423 serialnr->high = uid[3];
427 static void set_core0_reset_vector(u32 entry)
429 /* Update SIM1 DGO8 for reset vector base */
430 writel(entry, SIM1_BASE_ADDR + 0x5c);
433 setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24);
435 /* polling the ack */
436 while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0)
439 /* clear the update */
440 clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24));
442 /* clear the ack by set 1 */
443 setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26));
446 static int trdc_set_access(void)
449 * TRDC mgr + 4 MBC + 2 MRC.
450 * S400 should already configure when release RDC
451 * A35 only map non-secure region for pbridge0 and 1, set sec_access to false
453 trdc_mbc_set_access(2, 7, 0, 49, false);
454 trdc_mbc_set_access(2, 7, 0, 50, false);
455 trdc_mbc_set_access(2, 7, 0, 51, false);
456 trdc_mbc_set_access(2, 7, 0, 52, false);
457 trdc_mbc_set_access(2, 7, 0, 53, false);
458 trdc_mbc_set_access(2, 7, 0, 54, false);
460 /* CGC0: PBridge0 slot 47 */
461 trdc_mbc_set_access(2, 7, 0, 47, false);
463 /* Iomuxc0: : PBridge1 slot 33 */
464 trdc_mbc_set_access(2, 7, 1, 33, false);
467 trdc_mrc_region_set_access(0, 7, 0x04000000, 0x0c000000, false);
471 void lpav_configure(void)
474 setbits_le32(SIM_SEC_BASE_ADDR + 0x44, BIT(7));
476 /* PXP/GPU 2D/3D/DCNANO/MIPI_DSI/EPDC/HIFI4 to APD */
477 setbits_le32(SIM_SEC_BASE_ADDR + 0x4c, 0x7F);
479 /* LPAV slave/dma2 ch allocation and request allocation to APD */
480 writel(0x1f, SIM_SEC_BASE_ADDR + 0x50);
481 writel(0xffffffff, SIM_SEC_BASE_ADDR + 0x54);
482 writel(0x003fffff, SIM_SEC_BASE_ADDR + 0x58);
485 int arch_cpu_init(void)
487 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
490 bool rdc_en = true; /* Default assume DBD_EN is set */
495 /* Read DBD_EN fuse */
496 ret = fuse_read(8, 1, &val);
498 rdc_en = !!(val & 0x4000);
500 if (get_boot_mode() == SINGLE_BOOT) {
502 release_rdc(RDC_TRDC);
509 /* Release xrdc, then allow A35 to write SRAM2 */
511 release_rdc(RDC_XRDC);
513 xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00);
517 /* reconfigure core0 reset vector to ROM */
518 set_core0_reset_vector(0x1000);
524 int arch_cpu_init_dm(void)
526 struct udevice *devp;
529 node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8ulp-mu");
531 ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp);
533 printf("could not get S400 mu %d\n", ret);
540 #if defined(CONFIG_SPL_BUILD)
541 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
543 debug("image entry point: 0x%lx\n", spl_image->entry_point);
545 set_core0_reset_vector((u32)spl_image->entry_point);
547 /* Enable the 512KB cache */
548 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4));
551 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16));
558 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
563 int (*card_emmc_is_boot_part_en)(void) = (void *)0x67cc;
564 u32 spl_arch_boot_image_offset(u32 image_offset, u32 rom_bt_dev)
566 /* Hard code for eMMC image_offset on 8ULP ROM, need fix by ROM, temp workaround */
567 if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_MMC && card_emmc_is_boot_part_en())