blob: e6d417ed48b218f54d4707087b195f045262f4c7 [file] [log] [blame]
Peng Fan5c2218a2021-08-07 16:00:31 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 NXP
4 */
5
Peng Fan72530162021-08-07 16:00:33 +08006#include <asm/io.h>
7#include <asm/arch/clock.h>
8#include <asm/arch/imx-regs.h>
Peng Fan5c2218a2021-08-07 16:00:31 +08009#include <asm/arch/sys_proto.h>
Peng Fanb15705a2021-08-07 16:00:35 +080010#include <asm/armv8/mmu.h>
Peng Fan72530162021-08-07 16:00:33 +080011#include <asm/mach-imx/boot_mode.h>
Ye Li88044c72021-08-07 16:01:01 +080012#include <asm/global_data.h>
Ye Li6dd43022021-08-07 16:00:48 +080013#include <efi_loader.h>
Simon Glassfc557362022-03-04 08:43:05 -070014#include <event.h>
Ye Li6dd43022021-08-07 16:00:48 +080015#include <spl.h>
Peng Fan9c87e462021-08-07 16:00:59 +080016#include <asm/arch/rdc.h>
Ye Li853cc9d2021-08-07 16:00:55 +080017#include <asm/arch/s400_api.h>
18#include <asm/arch/mu_hal.h>
19#include <cpu_func.h>
20#include <asm/setup.h>
Ye Li7bea5b02021-08-07 16:01:00 +080021#include <dm.h>
22#include <dm/device-internal.h>
23#include <dm/lists.h>
24#include <dm/uclass.h>
25#include <dm/device.h>
26#include <dm/uclass-internal.h>
Ye Li72012622021-10-29 09:46:15 +080027#include <fuse.h>
Alice Guof2c4a392021-10-29 09:46:32 +080028#include <thermal.h>
Peng Fan5c2218a2021-08-07 16:00:31 +080029
Peng Fanb15705a2021-08-07 16:00:35 +080030DECLARE_GLOBAL_DATA_PTR;
31
Ye Li7a71c612021-08-07 16:00:39 +080032struct rom_api *g_rom_api = (struct rom_api *)0x1980;
33
Ye Li88044c72021-08-07 16:01:01 +080034enum boot_device get_boot_device(void)
35{
36 volatile gd_t *pgd = gd;
37 int ret;
38 u32 boot;
39 u16 boot_type;
40 u8 boot_instance;
41 enum boot_device boot_dev = SD1_BOOT;
42
43 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
44 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
45 set_gd(pgd);
46
47 if (ret != ROM_API_OKAY) {
48 puts("ROMAPI: failure at query_boot_info\n");
49 return -1;
50 }
51
52 boot_type = boot >> 16;
53 boot_instance = (boot >> 8) & 0xff;
54
55 switch (boot_type) {
56 case BT_DEV_TYPE_SD:
57 boot_dev = boot_instance + SD1_BOOT;
58 break;
59 case BT_DEV_TYPE_MMC:
60 boot_dev = boot_instance + MMC1_BOOT;
61 break;
62 case BT_DEV_TYPE_NAND:
63 boot_dev = NAND_BOOT;
64 break;
65 case BT_DEV_TYPE_FLEXSPINOR:
66 boot_dev = QSPI_BOOT;
67 break;
68 case BT_DEV_TYPE_USB:
69 boot_dev = USB_BOOT;
70 break;
71 default:
72 break;
73 }
74
75 return boot_dev;
76}
77
78bool is_usb_boot(void)
79{
80 return get_boot_device() == USB_BOOT;
81}
82
83#ifdef CONFIG_ENV_IS_IN_MMC
84__weak int board_mmc_get_env_dev(int devno)
85{
86 return devno;
87}
88
89int mmc_get_env_dev(void)
90{
91 volatile gd_t *pgd = gd;
92 int ret;
93 u32 boot;
94 u16 boot_type;
95 u8 boot_instance;
96
97 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
98 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
99 set_gd(pgd);
100
101 if (ret != ROM_API_OKAY) {
102 puts("ROMAPI: failure at query_boot_info\n");
103 return CONFIG_SYS_MMC_ENV_DEV;
104 }
105
106 boot_type = boot >> 16;
107 boot_instance = (boot >> 8) & 0xff;
108
109 /* If not boot from sd/mmc, use default value */
110 if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC)
111 return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV);
112
113 return board_mmc_get_env_dev(boot_instance);
114}
115#endif
116
Peng Fan5c2218a2021-08-07 16:00:31 +0800117u32 get_cpu_rev(void)
118{
119 return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0;
120}
Peng Fan72530162021-08-07 16:00:33 +0800121
122enum bt_mode get_boot_mode(void)
123{
124 u32 bt0_cfg = 0;
125
Ye Li0e358052021-08-07 16:01:07 +0800126 bt0_cfg = readl(SIM_SEC_BASE_ADDR + 0x24);
Peng Fan72530162021-08-07 16:00:33 +0800127 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
128
129 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
130 /* No low power boot */
131 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
132 return DUAL_BOOT;
133 else
134 return SINGLE_BOOT;
135 }
136
137 return LOW_POWER_BOOT;
138}
139
Peng Fanaf4f3b32021-08-07 16:00:34 +0800140#define CMC_SRS_TAMPER BIT(31)
141#define CMC_SRS_SECURITY BIT(30)
142#define CMC_SRS_TZWDG BIT(29)
143#define CMC_SRS_JTAG_RST BIT(28)
144#define CMC_SRS_CORE1 BIT(16)
145#define CMC_SRS_LOCKUP BIT(15)
146#define CMC_SRS_SW BIT(14)
147#define CMC_SRS_WDG BIT(13)
148#define CMC_SRS_PIN_RESET BIT(8)
149#define CMC_SRS_WARM BIT(4)
150#define CMC_SRS_HVD BIT(3)
151#define CMC_SRS_LVD BIT(2)
152#define CMC_SRS_POR BIT(1)
153#define CMC_SRS_WUP BIT(0)
154
Peng Fanaf4f3b32021-08-07 16:00:34 +0800155static char *get_reset_cause(char *ret)
156{
157 u32 cause1, cause = 0, srs = 0;
Peng Fanb15705a2021-08-07 16:00:35 +0800158 void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88);
159 void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80);
Peng Fanaf4f3b32021-08-07 16:00:34 +0800160
161 if (!ret)
162 return "null";
163
164 srs = readl(reg_srs);
165 cause1 = readl(reg_ssrs);
166
Peng Fan0d720e22021-08-07 16:01:06 +0800167 cause = srs & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
Peng Fanaf4f3b32021-08-07 16:00:34 +0800168
169 switch (cause) {
170 case CMC_SRS_POR:
171 sprintf(ret, "%s", "POR");
172 break;
173 case CMC_SRS_WUP:
174 sprintf(ret, "%s", "WUP");
175 break;
176 case CMC_SRS_WARM:
Peng Fan0d720e22021-08-07 16:01:06 +0800177 cause = srs & (CMC_SRS_WDG | CMC_SRS_SW |
Peng Fanaf4f3b32021-08-07 16:00:34 +0800178 CMC_SRS_JTAG_RST);
179 switch (cause) {
180 case CMC_SRS_WDG:
181 sprintf(ret, "%s", "WARM-WDG");
182 break;
183 case CMC_SRS_SW:
184 sprintf(ret, "%s", "WARM-SW");
185 break;
186 case CMC_SRS_JTAG_RST:
187 sprintf(ret, "%s", "WARM-JTAG");
188 break;
189 default:
190 sprintf(ret, "%s", "WARM-UNKN");
191 break;
192 }
193 break;
194 default:
Peng Fan0d720e22021-08-07 16:01:06 +0800195 sprintf(ret, "%s-%X", "UNKN", srs);
Peng Fanaf4f3b32021-08-07 16:00:34 +0800196 break;
197 }
198
199 debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1);
200 return ret;
201}
202
Peng Fan72530162021-08-07 16:00:33 +0800203#if defined(CONFIG_DISPLAY_CPUINFO)
204const char *get_imx_type(u32 imxtype)
205{
206 return "8ULP";
207}
208
209int print_cpuinfo(void)
210{
211 u32 cpurev;
212 char cause[18];
213
214 cpurev = get_cpu_rev();
215
Ye Lif012ceb2021-10-29 09:46:24 +0800216 printf("CPU: i.MX%s rev%d.%d at %d MHz\n",
Peng Fan72530162021-08-07 16:00:33 +0800217 get_imx_type((cpurev & 0xFF000) >> 12),
218 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
219 mxc_get_clock(MXC_ARM_CLK) / 1000000);
220
Alice Guof2c4a392021-10-29 09:46:32 +0800221#if defined(CONFIG_IMX_PMC_TEMPERATURE)
222 struct udevice *udev;
223 int ret, temp;
224
225 ret = uclass_get_device(UCLASS_THERMAL, 0, &udev);
226 if (!ret) {
227 ret = thermal_get_temp(udev, &temp);
228 if (!ret)
229 printf("CPU current temperature: %d\n", temp);
230 else
231 debug(" - failed to get CPU current temperature\n");
232 } else {
233 debug(" - failed to get CPU current temperature\n");
234 }
235#endif
236
Peng Fanaf4f3b32021-08-07 16:00:34 +0800237 printf("Reset cause: %s\n", get_reset_cause(cause));
238
Peng Fan72530162021-08-07 16:00:33 +0800239 printf("Boot mode: ");
240 switch (get_boot_mode()) {
241 case LOW_POWER_BOOT:
242 printf("Low power boot\n");
243 break;
244 case DUAL_BOOT:
245 printf("Dual boot\n");
246 break;
247 case SINGLE_BOOT:
248 default:
249 printf("Single boot\n");
250 break;
251 }
252
253 return 0;
254}
255#endif
Peng Fanb15705a2021-08-07 16:00:35 +0800256
Peng Fanc84bc102021-08-07 16:00:49 +0800257#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
258#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
259#define REFRESH_WORD0 0xA602 /* 1st refresh word */
260#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
261
262static void disable_wdog(void __iomem *wdog_base)
263{
264 u32 val_cs = readl(wdog_base + 0x00);
265
266 if (!(val_cs & 0x80))
267 return;
268
269 dmb();
270 __raw_writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
271 __raw_writel(REFRESH_WORD1, (wdog_base + 0x04));
272 dmb();
273
274 if (!(val_cs & 800)) {
275 dmb();
276 __raw_writel(UNLOCK_WORD0, (wdog_base + 0x04));
277 __raw_writel(UNLOCK_WORD1, (wdog_base + 0x04));
278 dmb();
279
280 while (!(readl(wdog_base + 0x00) & 0x800))
281 ;
282 }
283 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
284 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
285 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
286
287 while (!(readl(wdog_base + 0x00) & 0x400))
288 ;
289}
290
Peng Fanb15705a2021-08-07 16:00:35 +0800291void init_wdog(void)
292{
Peng Fanc84bc102021-08-07 16:00:49 +0800293 disable_wdog((void __iomem *)WDG3_RBASE);
Peng Fanb15705a2021-08-07 16:00:35 +0800294}
295
296static struct mm_region imx8ulp_arm64_mem_map[] = {
297 {
298 /* ROM */
299 .virt = 0x0,
300 .phys = 0x0,
301 .size = 0x40000UL,
302 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
303 PTE_BLOCK_OUTER_SHARE
304 },
305 {
306 /* FLEXSPI0 */
307 .virt = 0x04000000,
308 .phys = 0x04000000,
309 .size = 0x08000000UL,
310 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
311 PTE_BLOCK_NON_SHARE |
312 PTE_BLOCK_PXN | PTE_BLOCK_UXN
313 },
314 {
315 /* SSRAM (align with 2M) */
316 .virt = 0x1FE00000UL,
317 .phys = 0x1FE00000UL,
318 .size = 0x400000UL,
319 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
320 PTE_BLOCK_OUTER_SHARE |
321 PTE_BLOCK_PXN | PTE_BLOCK_UXN
322 }, {
323 /* SRAM1 (align with 2M) */
324 .virt = 0x21000000UL,
325 .phys = 0x21000000UL,
326 .size = 0x200000UL,
327 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
328 PTE_BLOCK_OUTER_SHARE |
329 PTE_BLOCK_PXN | PTE_BLOCK_UXN
330 }, {
331 /* SRAM0 (align with 2M) */
332 .virt = 0x22000000UL,
333 .phys = 0x22000000UL,
334 .size = 0x200000UL,
335 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
336 PTE_BLOCK_OUTER_SHARE |
337 PTE_BLOCK_PXN | PTE_BLOCK_UXN
338 }, {
339 /* Peripherals */
340 .virt = 0x27000000UL,
341 .phys = 0x27000000UL,
342 .size = 0x3000000UL,
343 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
344 PTE_BLOCK_NON_SHARE |
345 PTE_BLOCK_PXN | PTE_BLOCK_UXN
346 }, {
347 /* Peripherals */
348 .virt = 0x2D000000UL,
349 .phys = 0x2D000000UL,
350 .size = 0x1600000UL,
351 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
352 PTE_BLOCK_NON_SHARE |
353 PTE_BLOCK_PXN | PTE_BLOCK_UXN
354 }, {
355 /* FLEXSPI1-2 */
356 .virt = 0x40000000UL,
357 .phys = 0x40000000UL,
358 .size = 0x40000000UL,
359 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
360 PTE_BLOCK_NON_SHARE |
361 PTE_BLOCK_PXN | PTE_BLOCK_UXN
362 }, {
363 /* DRAM1 */
364 .virt = 0x80000000UL,
365 .phys = 0x80000000UL,
366 .size = PHYS_SDRAM_SIZE,
367 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
368 PTE_BLOCK_OUTER_SHARE
369 }, {
370 /*
371 * empty entrie to split table entry 5
372 * if needed when TEEs are used
373 */
374 0,
375 }, {
376 /* List terminator */
377 0,
378 }
379};
380
381struct mm_region *mem_map = imx8ulp_arm64_mem_map;
382
383/* simplify the page table size to enhance boot speed */
384#define MAX_PTE_ENTRIES 512
385#define MAX_MEM_MAP_REGIONS 16
386u64 get_page_table_size(void)
387{
388 u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
389 u64 size = 0;
390
391 /*
392 * For each memory region, the max table size:
393 * 2 level 3 tables + 2 level 2 tables + 1 level 1 table
394 */
395 size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt;
396
397 /*
398 * We need to duplicate our page table once to have an emergency pt to
399 * resort to when splitting page tables later on
400 */
401 size *= 2;
402
403 /*
404 * We may need to split page tables later on if dcache settings change,
405 * so reserve up to 4 (random pick) page tables for that.
406 */
407 size += one_pt * 4;
408
409 return size;
410}
411
412void enable_caches(void)
413{
414 /* TODO: add TEE memmap region */
415
416 icache_enable();
417 dcache_enable();
418}
419
420int dram_init(void)
421{
422 gd->ram_size = PHYS_SDRAM_SIZE;
423
424 return 0;
425}
426
Tom Riniae21e7f2021-08-30 09:16:29 -0400427#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Peng Fanb15705a2021-08-07 16:00:35 +0800428void get_board_serial(struct tag_serialnr *serialnr)
429{
Ye Li7bea5b02021-08-07 16:01:00 +0800430 u32 uid[4];
431 u32 res;
432 int ret;
433
434 ret = ahab_read_common_fuse(1, uid, 4, &res);
435 if (ret)
436 printf("ahab read fuse failed %d, 0x%x\n", ret, res);
437 else
438 printf("UID 0x%x,0x%x,0x%x,0x%x\n", uid[0], uid[1], uid[2], uid[3]);
439
440 serialnr->low = uid[0];
441 serialnr->high = uid[3];
Peng Fanb15705a2021-08-07 16:00:35 +0800442}
443#endif
444
Ye Li6ee435eb2021-08-07 16:00:50 +0800445static void set_core0_reset_vector(u32 entry)
Peng Fanb15705a2021-08-07 16:00:35 +0800446{
Ye Li6dd43022021-08-07 16:00:48 +0800447 /* Update SIM1 DGO8 for reset vector base */
Ye Li6ee435eb2021-08-07 16:00:50 +0800448 writel(entry, SIM1_BASE_ADDR + 0x5c);
Ye Li6dd43022021-08-07 16:00:48 +0800449
450 /* set update bit */
451 setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24);
452
453 /* polling the ack */
454 while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0)
455 ;
456
457 /* clear the update */
458 clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24));
459
460 /* clear the ack by set 1 */
461 setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26));
Ye Li6ee435eb2021-08-07 16:00:50 +0800462}
463
Peng Fan9c87e462021-08-07 16:00:59 +0800464static int trdc_set_access(void)
Peng Fanb5c41b12021-08-07 16:00:58 +0800465{
466 /*
Peng Fan9c87e462021-08-07 16:00:59 +0800467 * TRDC mgr + 4 MBC + 2 MRC.
468 * S400 should already configure when release RDC
469 * A35 only map non-secure region for pbridge0 and 1, set sec_access to false
Peng Fanb5c41b12021-08-07 16:00:58 +0800470 */
Peng Fan9c87e462021-08-07 16:00:59 +0800471 trdc_mbc_set_access(2, 7, 0, 49, false);
472 trdc_mbc_set_access(2, 7, 0, 50, false);
473 trdc_mbc_set_access(2, 7, 0, 51, false);
474 trdc_mbc_set_access(2, 7, 0, 52, false);
475 trdc_mbc_set_access(2, 7, 0, 53, false);
476 trdc_mbc_set_access(2, 7, 0, 54, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800477
Peng Fan9c87e462021-08-07 16:00:59 +0800478 /* CGC0: PBridge0 slot 47 */
479 trdc_mbc_set_access(2, 7, 0, 47, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800480
Peng Fan9c87e462021-08-07 16:00:59 +0800481 /* Iomuxc0: : PBridge1 slot 33 */
482 trdc_mbc_set_access(2, 7, 1, 33, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800483
Ye Lid325d372021-10-29 09:46:20 +0800484 /* flexspi0 */
485 trdc_mrc_region_set_access(0, 7, 0x04000000, 0x0c000000, false);
Ye Li27666ca2021-10-29 09:46:21 +0800486
487 /* tpm0: PBridge1 slot 21 */
488 trdc_mbc_set_access(2, 7, 1, 21, false);
489 /* lpi2c0: PBridge1 slot 24 */
490 trdc_mbc_set_access(2, 7, 1, 24, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800491 return 0;
492}
493
Ye Li43819eb2021-10-29 09:46:16 +0800494void lpav_configure(void)
495{
496 /* LPAV to APD */
497 setbits_le32(SIM_SEC_BASE_ADDR + 0x44, BIT(7));
498
Peng Fanfa609b42021-10-29 09:46:17 +0800499 /* PXP/GPU 2D/3D/DCNANO/MIPI_DSI/EPDC/HIFI4 to APD */
500 setbits_le32(SIM_SEC_BASE_ADDR + 0x4c, 0x7F);
Ye Li43819eb2021-10-29 09:46:16 +0800501
502 /* LPAV slave/dma2 ch allocation and request allocation to APD */
503 writel(0x1f, SIM_SEC_BASE_ADDR + 0x50);
504 writel(0xffffffff, SIM_SEC_BASE_ADDR + 0x54);
505 writel(0x003fffff, SIM_SEC_BASE_ADDR + 0x58);
Ye Li715cfa02021-10-29 09:46:23 +0800506}
Ye Lia0311552021-10-29 09:46:22 +0800507
Ye Li133f8b82021-10-29 09:46:25 +0800508void load_lposc_fuse(void)
509{
510 int ret;
511 u32 val = 0, val2 = 0, reg;
512
513 ret = fuse_read(25, 0, &val);
514 if (ret)
515 return; /* failed */
516
517 ret = fuse_read(25, 1, &val2);
518 if (ret)
519 return; /* failed */
520
521 /* LPOSCCTRL */
522 reg = readl(0x2802f304);
523 reg &= ~0xff;
524 reg |= (val & 0xff);
525 writel(reg, 0x2802f304);
526}
527
Ye Li715cfa02021-10-29 09:46:23 +0800528void set_lpav_qos(void)
529{
Ye Lia0311552021-10-29 09:46:22 +0800530 /* Set read QoS of dcnano on LPAV NIC */
531 writel(0xf, 0x2e447100);
Ye Li43819eb2021-10-29 09:46:16 +0800532}
533
Ye Li6ee435eb2021-08-07 16:00:50 +0800534int arch_cpu_init(void)
535{
536 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
Ye Li72012622021-10-29 09:46:15 +0800537 u32 val = 0;
538 int ret;
539 bool rdc_en = true; /* Default assume DBD_EN is set */
540
Ye Li853cc9d2021-08-07 16:00:55 +0800541 /* Disable wdog */
542 init_wdog();
543
Ye Li72012622021-10-29 09:46:15 +0800544 /* Read DBD_EN fuse */
545 ret = fuse_read(8, 1, &val);
546 if (!ret)
547 rdc_en = !!(val & 0x4000);
548
Peng Fanb5c41b12021-08-07 16:00:58 +0800549 if (get_boot_mode() == SINGLE_BOOT) {
Ye Li72012622021-10-29 09:46:15 +0800550 if (rdc_en)
551 release_rdc(RDC_TRDC);
552
Peng Fanb5c41b12021-08-07 16:00:58 +0800553 trdc_set_access();
Ye Li43819eb2021-10-29 09:46:16 +0800554
555 lpav_configure();
Peng Fanb5c41b12021-08-07 16:00:58 +0800556 }
Peng Fanfa55b212021-08-07 16:00:57 +0800557
Ye Li72012622021-10-29 09:46:15 +0800558 /* Release xrdc, then allow A35 to write SRAM2 */
559 if (rdc_en)
560 release_rdc(RDC_XRDC);
561
Ye Li853cc9d2021-08-07 16:00:55 +0800562 xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00);
563
Ye Li6ee435eb2021-08-07 16:00:50 +0800564 clock_init();
565 } else {
566 /* reconfigure core0 reset vector to ROM */
567 set_core0_reset_vector(0x1000);
568 }
569
570 return 0;
571}
572
Simon Glassfc557362022-03-04 08:43:05 -0700573static int imx8ulp_check_mu(void *ctx, struct event *event)
Ye Li7bea5b02021-08-07 16:01:00 +0800574{
575 struct udevice *devp;
576 int node, ret;
577
578 node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8ulp-mu");
579
580 ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp);
581 if (ret) {
582 printf("could not get S400 mu %d\n", ret);
583 return ret;
584 }
585
586 return 0;
587}
Simon Glassfc557362022-03-04 08:43:05 -0700588EVENT_SPY(EVT_DM_POST_INIT, imx8ulp_check_mu);
Ye Li7bea5b02021-08-07 16:01:00 +0800589
Ye Li6ee435eb2021-08-07 16:00:50 +0800590#if defined(CONFIG_SPL_BUILD)
591__weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
592{
593 debug("image entry point: 0x%lx\n", spl_image->entry_point);
594
595 set_core0_reset_vector((u32)spl_image->entry_point);
Ye Li6dd43022021-08-07 16:00:48 +0800596
597 /* Enable the 512KB cache */
598 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4));
599
600 /* reset core */
601 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16));
602
603 while (1)
604 ;
605}
606#endif
Peng Fanfa6ae052021-08-07 16:01:03 +0800607
608void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
609{
Ye Li992b0ae2021-10-29 09:46:28 +0800610 u32 val[2] = {};
611 int ret;
612
613 ret = fuse_read(5, 3, &val[0]);
614 if (ret)
615 goto err;
616
617 ret = fuse_read(5, 4, &val[1]);
618 if (ret)
619 goto err;
620
621 mac[0] = val[0];
622 mac[1] = val[0] >> 8;
623 mac[2] = val[0] >> 16;
624 mac[3] = val[0] >> 24;
625 mac[4] = val[1];
626 mac[5] = val[1] >> 8;
627
628 debug("%s: MAC%d: %02x.%02x.%02x.%02x.%02x.%02x\n",
629 __func__, dev_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
630 return;
631err:
Peng Fanfa6ae052021-08-07 16:01:03 +0800632 memset(mac, 0, 6);
Ye Li992b0ae2021-10-29 09:46:28 +0800633 printf("%s: fuse read err: %d\n", __func__, ret);
Peng Fanfa6ae052021-08-07 16:01:03 +0800634}
Ye Li479fd4a2021-08-07 16:01:08 +0800635
636int (*card_emmc_is_boot_part_en)(void) = (void *)0x67cc;
637u32 spl_arch_boot_image_offset(u32 image_offset, u32 rom_bt_dev)
638{
639 /* Hard code for eMMC image_offset on 8ULP ROM, need fix by ROM, temp workaround */
640 if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_MMC && card_emmc_is_boot_part_en())
641 image_offset = 0;
642
643 return image_offset;
644}