blob: 934b0ef038ce83dc2830d5458c975cc50869668e [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>
14#include <spl.h>
Peng Fan9c87e462021-08-07 16:00:59 +080015#include <asm/arch/rdc.h>
Ye Li853cc9d2021-08-07 16:00:55 +080016#include <asm/arch/s400_api.h>
17#include <asm/arch/mu_hal.h>
18#include <cpu_func.h>
19#include <asm/setup.h>
Ye Li7bea5b02021-08-07 16:01:00 +080020#include <dm.h>
21#include <dm/device-internal.h>
22#include <dm/lists.h>
23#include <dm/uclass.h>
24#include <dm/device.h>
25#include <dm/uclass-internal.h>
Ye Li72012622021-10-29 09:46:15 +080026#include <fuse.h>
Alice Guof2c4a392021-10-29 09:46:32 +080027#include <thermal.h>
Peng Fan5c2218a2021-08-07 16:00:31 +080028
Peng Fanb15705a2021-08-07 16:00:35 +080029DECLARE_GLOBAL_DATA_PTR;
30
Ye Li7a71c612021-08-07 16:00:39 +080031struct rom_api *g_rom_api = (struct rom_api *)0x1980;
32
Ye Li88044c72021-08-07 16:01:01 +080033enum boot_device get_boot_device(void)
34{
35 volatile gd_t *pgd = gd;
36 int ret;
37 u32 boot;
38 u16 boot_type;
39 u8 boot_instance;
40 enum boot_device boot_dev = SD1_BOOT;
41
42 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
43 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
44 set_gd(pgd);
45
46 if (ret != ROM_API_OKAY) {
47 puts("ROMAPI: failure at query_boot_info\n");
48 return -1;
49 }
50
51 boot_type = boot >> 16;
52 boot_instance = (boot >> 8) & 0xff;
53
54 switch (boot_type) {
55 case BT_DEV_TYPE_SD:
56 boot_dev = boot_instance + SD1_BOOT;
57 break;
58 case BT_DEV_TYPE_MMC:
59 boot_dev = boot_instance + MMC1_BOOT;
60 break;
61 case BT_DEV_TYPE_NAND:
62 boot_dev = NAND_BOOT;
63 break;
64 case BT_DEV_TYPE_FLEXSPINOR:
65 boot_dev = QSPI_BOOT;
66 break;
67 case BT_DEV_TYPE_USB:
68 boot_dev = USB_BOOT;
69 break;
70 default:
71 break;
72 }
73
74 return boot_dev;
75}
76
77bool is_usb_boot(void)
78{
79 return get_boot_device() == USB_BOOT;
80}
81
82#ifdef CONFIG_ENV_IS_IN_MMC
83__weak int board_mmc_get_env_dev(int devno)
84{
85 return devno;
86}
87
88int mmc_get_env_dev(void)
89{
90 volatile gd_t *pgd = gd;
91 int ret;
92 u32 boot;
93 u16 boot_type;
94 u8 boot_instance;
95
96 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
97 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
98 set_gd(pgd);
99
100 if (ret != ROM_API_OKAY) {
101 puts("ROMAPI: failure at query_boot_info\n");
102 return CONFIG_SYS_MMC_ENV_DEV;
103 }
104
105 boot_type = boot >> 16;
106 boot_instance = (boot >> 8) & 0xff;
107
108 /* If not boot from sd/mmc, use default value */
109 if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC)
110 return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV);
111
112 return board_mmc_get_env_dev(boot_instance);
113}
114#endif
115
Peng Fan5c2218a2021-08-07 16:00:31 +0800116u32 get_cpu_rev(void)
117{
118 return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0;
119}
Peng Fan72530162021-08-07 16:00:33 +0800120
121enum bt_mode get_boot_mode(void)
122{
123 u32 bt0_cfg = 0;
124
Ye Li0e358052021-08-07 16:01:07 +0800125 bt0_cfg = readl(SIM_SEC_BASE_ADDR + 0x24);
Peng Fan72530162021-08-07 16:00:33 +0800126 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
127
128 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
129 /* No low power boot */
130 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
131 return DUAL_BOOT;
132 else
133 return SINGLE_BOOT;
134 }
135
136 return LOW_POWER_BOOT;
137}
138
Peng Fanaf4f3b32021-08-07 16:00:34 +0800139#define CMC_SRS_TAMPER BIT(31)
140#define CMC_SRS_SECURITY BIT(30)
141#define CMC_SRS_TZWDG BIT(29)
142#define CMC_SRS_JTAG_RST BIT(28)
143#define CMC_SRS_CORE1 BIT(16)
144#define CMC_SRS_LOCKUP BIT(15)
145#define CMC_SRS_SW BIT(14)
146#define CMC_SRS_WDG BIT(13)
147#define CMC_SRS_PIN_RESET BIT(8)
148#define CMC_SRS_WARM BIT(4)
149#define CMC_SRS_HVD BIT(3)
150#define CMC_SRS_LVD BIT(2)
151#define CMC_SRS_POR BIT(1)
152#define CMC_SRS_WUP BIT(0)
153
Peng Fanaf4f3b32021-08-07 16:00:34 +0800154static char *get_reset_cause(char *ret)
155{
156 u32 cause1, cause = 0, srs = 0;
Peng Fanb15705a2021-08-07 16:00:35 +0800157 void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88);
158 void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80);
Peng Fanaf4f3b32021-08-07 16:00:34 +0800159
160 if (!ret)
161 return "null";
162
163 srs = readl(reg_srs);
164 cause1 = readl(reg_ssrs);
165
Peng Fan0d720e22021-08-07 16:01:06 +0800166 cause = srs & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
Peng Fanaf4f3b32021-08-07 16:00:34 +0800167
168 switch (cause) {
169 case CMC_SRS_POR:
170 sprintf(ret, "%s", "POR");
171 break;
172 case CMC_SRS_WUP:
173 sprintf(ret, "%s", "WUP");
174 break;
175 case CMC_SRS_WARM:
Peng Fan0d720e22021-08-07 16:01:06 +0800176 cause = srs & (CMC_SRS_WDG | CMC_SRS_SW |
Peng Fanaf4f3b32021-08-07 16:00:34 +0800177 CMC_SRS_JTAG_RST);
178 switch (cause) {
179 case CMC_SRS_WDG:
180 sprintf(ret, "%s", "WARM-WDG");
181 break;
182 case CMC_SRS_SW:
183 sprintf(ret, "%s", "WARM-SW");
184 break;
185 case CMC_SRS_JTAG_RST:
186 sprintf(ret, "%s", "WARM-JTAG");
187 break;
188 default:
189 sprintf(ret, "%s", "WARM-UNKN");
190 break;
191 }
192 break;
193 default:
Peng Fan0d720e22021-08-07 16:01:06 +0800194 sprintf(ret, "%s-%X", "UNKN", srs);
Peng Fanaf4f3b32021-08-07 16:00:34 +0800195 break;
196 }
197
198 debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1);
199 return ret;
200}
201
Peng Fan72530162021-08-07 16:00:33 +0800202#if defined(CONFIG_DISPLAY_CPUINFO)
203const char *get_imx_type(u32 imxtype)
204{
205 return "8ULP";
206}
207
208int print_cpuinfo(void)
209{
210 u32 cpurev;
211 char cause[18];
212
213 cpurev = get_cpu_rev();
214
Ye Lif012ceb2021-10-29 09:46:24 +0800215 printf("CPU: i.MX%s rev%d.%d at %d MHz\n",
Peng Fan72530162021-08-07 16:00:33 +0800216 get_imx_type((cpurev & 0xFF000) >> 12),
217 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
218 mxc_get_clock(MXC_ARM_CLK) / 1000000);
219
Alice Guof2c4a392021-10-29 09:46:32 +0800220#if defined(CONFIG_IMX_PMC_TEMPERATURE)
221 struct udevice *udev;
222 int ret, temp;
223
224 ret = uclass_get_device(UCLASS_THERMAL, 0, &udev);
225 if (!ret) {
226 ret = thermal_get_temp(udev, &temp);
227 if (!ret)
228 printf("CPU current temperature: %d\n", temp);
229 else
230 debug(" - failed to get CPU current temperature\n");
231 } else {
232 debug(" - failed to get CPU current temperature\n");
233 }
234#endif
235
Peng Fanaf4f3b32021-08-07 16:00:34 +0800236 printf("Reset cause: %s\n", get_reset_cause(cause));
237
Peng Fan72530162021-08-07 16:00:33 +0800238 printf("Boot mode: ");
239 switch (get_boot_mode()) {
240 case LOW_POWER_BOOT:
241 printf("Low power boot\n");
242 break;
243 case DUAL_BOOT:
244 printf("Dual boot\n");
245 break;
246 case SINGLE_BOOT:
247 default:
248 printf("Single boot\n");
249 break;
250 }
251
252 return 0;
253}
254#endif
Peng Fanb15705a2021-08-07 16:00:35 +0800255
Peng Fanc84bc102021-08-07 16:00:49 +0800256#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
257#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
258#define REFRESH_WORD0 0xA602 /* 1st refresh word */
259#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
260
261static void disable_wdog(void __iomem *wdog_base)
262{
263 u32 val_cs = readl(wdog_base + 0x00);
264
265 if (!(val_cs & 0x80))
266 return;
267
268 dmb();
269 __raw_writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
270 __raw_writel(REFRESH_WORD1, (wdog_base + 0x04));
271 dmb();
272
273 if (!(val_cs & 800)) {
274 dmb();
275 __raw_writel(UNLOCK_WORD0, (wdog_base + 0x04));
276 __raw_writel(UNLOCK_WORD1, (wdog_base + 0x04));
277 dmb();
278
279 while (!(readl(wdog_base + 0x00) & 0x800))
280 ;
281 }
282 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
283 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
284 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
285
286 while (!(readl(wdog_base + 0x00) & 0x400))
287 ;
288}
289
Peng Fanb15705a2021-08-07 16:00:35 +0800290void init_wdog(void)
291{
Peng Fanc84bc102021-08-07 16:00:49 +0800292 disable_wdog((void __iomem *)WDG3_RBASE);
Peng Fanb15705a2021-08-07 16:00:35 +0800293}
294
295static struct mm_region imx8ulp_arm64_mem_map[] = {
296 {
297 /* ROM */
298 .virt = 0x0,
299 .phys = 0x0,
300 .size = 0x40000UL,
301 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
302 PTE_BLOCK_OUTER_SHARE
303 },
304 {
305 /* FLEXSPI0 */
306 .virt = 0x04000000,
307 .phys = 0x04000000,
308 .size = 0x08000000UL,
309 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
310 PTE_BLOCK_NON_SHARE |
311 PTE_BLOCK_PXN | PTE_BLOCK_UXN
312 },
313 {
314 /* SSRAM (align with 2M) */
315 .virt = 0x1FE00000UL,
316 .phys = 0x1FE00000UL,
317 .size = 0x400000UL,
318 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
319 PTE_BLOCK_OUTER_SHARE |
320 PTE_BLOCK_PXN | PTE_BLOCK_UXN
321 }, {
322 /* SRAM1 (align with 2M) */
323 .virt = 0x21000000UL,
324 .phys = 0x21000000UL,
325 .size = 0x200000UL,
326 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
327 PTE_BLOCK_OUTER_SHARE |
328 PTE_BLOCK_PXN | PTE_BLOCK_UXN
329 }, {
330 /* SRAM0 (align with 2M) */
331 .virt = 0x22000000UL,
332 .phys = 0x22000000UL,
333 .size = 0x200000UL,
334 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
335 PTE_BLOCK_OUTER_SHARE |
336 PTE_BLOCK_PXN | PTE_BLOCK_UXN
337 }, {
338 /* Peripherals */
339 .virt = 0x27000000UL,
340 .phys = 0x27000000UL,
341 .size = 0x3000000UL,
342 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
343 PTE_BLOCK_NON_SHARE |
344 PTE_BLOCK_PXN | PTE_BLOCK_UXN
345 }, {
346 /* Peripherals */
347 .virt = 0x2D000000UL,
348 .phys = 0x2D000000UL,
349 .size = 0x1600000UL,
350 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
351 PTE_BLOCK_NON_SHARE |
352 PTE_BLOCK_PXN | PTE_BLOCK_UXN
353 }, {
354 /* FLEXSPI1-2 */
355 .virt = 0x40000000UL,
356 .phys = 0x40000000UL,
357 .size = 0x40000000UL,
358 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
359 PTE_BLOCK_NON_SHARE |
360 PTE_BLOCK_PXN | PTE_BLOCK_UXN
361 }, {
362 /* DRAM1 */
363 .virt = 0x80000000UL,
364 .phys = 0x80000000UL,
365 .size = PHYS_SDRAM_SIZE,
366 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
367 PTE_BLOCK_OUTER_SHARE
368 }, {
369 /*
370 * empty entrie to split table entry 5
371 * if needed when TEEs are used
372 */
373 0,
374 }, {
375 /* List terminator */
376 0,
377 }
378};
379
380struct mm_region *mem_map = imx8ulp_arm64_mem_map;
381
382/* simplify the page table size to enhance boot speed */
383#define MAX_PTE_ENTRIES 512
384#define MAX_MEM_MAP_REGIONS 16
385u64 get_page_table_size(void)
386{
387 u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
388 u64 size = 0;
389
390 /*
391 * For each memory region, the max table size:
392 * 2 level 3 tables + 2 level 2 tables + 1 level 1 table
393 */
394 size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt;
395
396 /*
397 * We need to duplicate our page table once to have an emergency pt to
398 * resort to when splitting page tables later on
399 */
400 size *= 2;
401
402 /*
403 * We may need to split page tables later on if dcache settings change,
404 * so reserve up to 4 (random pick) page tables for that.
405 */
406 size += one_pt * 4;
407
408 return size;
409}
410
411void enable_caches(void)
412{
413 /* TODO: add TEE memmap region */
414
415 icache_enable();
416 dcache_enable();
417}
418
419int dram_init(void)
420{
421 gd->ram_size = PHYS_SDRAM_SIZE;
422
423 return 0;
424}
425
Tom Riniae21e7f2021-08-30 09:16:29 -0400426#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Peng Fanb15705a2021-08-07 16:00:35 +0800427void get_board_serial(struct tag_serialnr *serialnr)
428{
Ye Li7bea5b02021-08-07 16:01:00 +0800429 u32 uid[4];
430 u32 res;
431 int ret;
432
433 ret = ahab_read_common_fuse(1, uid, 4, &res);
434 if (ret)
435 printf("ahab read fuse failed %d, 0x%x\n", ret, res);
436 else
437 printf("UID 0x%x,0x%x,0x%x,0x%x\n", uid[0], uid[1], uid[2], uid[3]);
438
439 serialnr->low = uid[0];
440 serialnr->high = uid[3];
Peng Fanb15705a2021-08-07 16:00:35 +0800441}
442#endif
443
Ye Li6ee435eb2021-08-07 16:00:50 +0800444static void set_core0_reset_vector(u32 entry)
Peng Fanb15705a2021-08-07 16:00:35 +0800445{
Ye Li6dd43022021-08-07 16:00:48 +0800446 /* Update SIM1 DGO8 for reset vector base */
Ye Li6ee435eb2021-08-07 16:00:50 +0800447 writel(entry, SIM1_BASE_ADDR + 0x5c);
Ye Li6dd43022021-08-07 16:00:48 +0800448
449 /* set update bit */
450 setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24);
451
452 /* polling the ack */
453 while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0)
454 ;
455
456 /* clear the update */
457 clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24));
458
459 /* clear the ack by set 1 */
460 setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26));
Ye Li6ee435eb2021-08-07 16:00:50 +0800461}
462
Peng Fan9c87e462021-08-07 16:00:59 +0800463static int trdc_set_access(void)
Peng Fanb5c41b12021-08-07 16:00:58 +0800464{
465 /*
Peng Fan9c87e462021-08-07 16:00:59 +0800466 * TRDC mgr + 4 MBC + 2 MRC.
467 * S400 should already configure when release RDC
468 * A35 only map non-secure region for pbridge0 and 1, set sec_access to false
Peng Fanb5c41b12021-08-07 16:00:58 +0800469 */
Peng Fan9c87e462021-08-07 16:00:59 +0800470 trdc_mbc_set_access(2, 7, 0, 49, false);
471 trdc_mbc_set_access(2, 7, 0, 50, false);
472 trdc_mbc_set_access(2, 7, 0, 51, false);
473 trdc_mbc_set_access(2, 7, 0, 52, false);
474 trdc_mbc_set_access(2, 7, 0, 53, false);
475 trdc_mbc_set_access(2, 7, 0, 54, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800476
Peng Fan9c87e462021-08-07 16:00:59 +0800477 /* CGC0: PBridge0 slot 47 */
478 trdc_mbc_set_access(2, 7, 0, 47, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800479
Peng Fan9c87e462021-08-07 16:00:59 +0800480 /* Iomuxc0: : PBridge1 slot 33 */
481 trdc_mbc_set_access(2, 7, 1, 33, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800482
Ye Lid325d372021-10-29 09:46:20 +0800483 /* flexspi0 */
484 trdc_mrc_region_set_access(0, 7, 0x04000000, 0x0c000000, false);
Ye Li27666ca2021-10-29 09:46:21 +0800485
486 /* tpm0: PBridge1 slot 21 */
487 trdc_mbc_set_access(2, 7, 1, 21, false);
488 /* lpi2c0: PBridge1 slot 24 */
489 trdc_mbc_set_access(2, 7, 1, 24, false);
Peng Fanb5c41b12021-08-07 16:00:58 +0800490 return 0;
491}
492
Ye Li43819eb2021-10-29 09:46:16 +0800493void lpav_configure(void)
494{
495 /* LPAV to APD */
496 setbits_le32(SIM_SEC_BASE_ADDR + 0x44, BIT(7));
497
Peng Fanfa609b42021-10-29 09:46:17 +0800498 /* PXP/GPU 2D/3D/DCNANO/MIPI_DSI/EPDC/HIFI4 to APD */
499 setbits_le32(SIM_SEC_BASE_ADDR + 0x4c, 0x7F);
Ye Li43819eb2021-10-29 09:46:16 +0800500
501 /* LPAV slave/dma2 ch allocation and request allocation to APD */
502 writel(0x1f, SIM_SEC_BASE_ADDR + 0x50);
503 writel(0xffffffff, SIM_SEC_BASE_ADDR + 0x54);
504 writel(0x003fffff, SIM_SEC_BASE_ADDR + 0x58);
Ye Li715cfa02021-10-29 09:46:23 +0800505}
Ye Lia0311552021-10-29 09:46:22 +0800506
Ye Li133f8b82021-10-29 09:46:25 +0800507void load_lposc_fuse(void)
508{
509 int ret;
510 u32 val = 0, val2 = 0, reg;
511
512 ret = fuse_read(25, 0, &val);
513 if (ret)
514 return; /* failed */
515
516 ret = fuse_read(25, 1, &val2);
517 if (ret)
518 return; /* failed */
519
520 /* LPOSCCTRL */
521 reg = readl(0x2802f304);
522 reg &= ~0xff;
523 reg |= (val & 0xff);
524 writel(reg, 0x2802f304);
525}
526
Ye Li715cfa02021-10-29 09:46:23 +0800527void set_lpav_qos(void)
528{
Ye Lia0311552021-10-29 09:46:22 +0800529 /* Set read QoS of dcnano on LPAV NIC */
530 writel(0xf, 0x2e447100);
Ye Li43819eb2021-10-29 09:46:16 +0800531}
532
Ye Li6ee435eb2021-08-07 16:00:50 +0800533int arch_cpu_init(void)
534{
535 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
Ye Li72012622021-10-29 09:46:15 +0800536 u32 val = 0;
537 int ret;
538 bool rdc_en = true; /* Default assume DBD_EN is set */
539
Ye Li853cc9d2021-08-07 16:00:55 +0800540 /* Disable wdog */
541 init_wdog();
542
Ye Li72012622021-10-29 09:46:15 +0800543 /* Read DBD_EN fuse */
544 ret = fuse_read(8, 1, &val);
545 if (!ret)
546 rdc_en = !!(val & 0x4000);
547
Peng Fanb5c41b12021-08-07 16:00:58 +0800548 if (get_boot_mode() == SINGLE_BOOT) {
Ye Li72012622021-10-29 09:46:15 +0800549 if (rdc_en)
550 release_rdc(RDC_TRDC);
551
Peng Fanb5c41b12021-08-07 16:00:58 +0800552 trdc_set_access();
Ye Li43819eb2021-10-29 09:46:16 +0800553
554 lpav_configure();
Peng Fanb5c41b12021-08-07 16:00:58 +0800555 }
Peng Fanfa55b212021-08-07 16:00:57 +0800556
Ye Li72012622021-10-29 09:46:15 +0800557 /* Release xrdc, then allow A35 to write SRAM2 */
558 if (rdc_en)
559 release_rdc(RDC_XRDC);
560
Ye Li853cc9d2021-08-07 16:00:55 +0800561 xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00);
562
Ye Li6ee435eb2021-08-07 16:00:50 +0800563 clock_init();
564 } else {
565 /* reconfigure core0 reset vector to ROM */
566 set_core0_reset_vector(0x1000);
567 }
568
569 return 0;
570}
571
Ye Li7bea5b02021-08-07 16:01:00 +0800572int arch_cpu_init_dm(void)
573{
574 struct udevice *devp;
575 int node, ret;
576
577 node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8ulp-mu");
578
579 ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp);
580 if (ret) {
581 printf("could not get S400 mu %d\n", ret);
582 return ret;
583 }
584
585 return 0;
586}
587
Ye Li6ee435eb2021-08-07 16:00:50 +0800588#if defined(CONFIG_SPL_BUILD)
589__weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
590{
591 debug("image entry point: 0x%lx\n", spl_image->entry_point);
592
593 set_core0_reset_vector((u32)spl_image->entry_point);
Ye Li6dd43022021-08-07 16:00:48 +0800594
595 /* Enable the 512KB cache */
596 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4));
597
598 /* reset core */
599 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16));
600
601 while (1)
602 ;
603}
604#endif
Peng Fanfa6ae052021-08-07 16:01:03 +0800605
606void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
607{
Ye Li992b0ae2021-10-29 09:46:28 +0800608 u32 val[2] = {};
609 int ret;
610
611 ret = fuse_read(5, 3, &val[0]);
612 if (ret)
613 goto err;
614
615 ret = fuse_read(5, 4, &val[1]);
616 if (ret)
617 goto err;
618
619 mac[0] = val[0];
620 mac[1] = val[0] >> 8;
621 mac[2] = val[0] >> 16;
622 mac[3] = val[0] >> 24;
623 mac[4] = val[1];
624 mac[5] = val[1] >> 8;
625
626 debug("%s: MAC%d: %02x.%02x.%02x.%02x.%02x.%02x\n",
627 __func__, dev_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
628 return;
629err:
Peng Fanfa6ae052021-08-07 16:01:03 +0800630 memset(mac, 0, 6);
Ye Li992b0ae2021-10-29 09:46:28 +0800631 printf("%s: fuse read err: %d\n", __func__, ret);
Peng Fanfa6ae052021-08-07 16:01:03 +0800632}
Ye Li479fd4a2021-08-07 16:01:08 +0800633
634int (*card_emmc_is_boot_part_en)(void) = (void *)0x67cc;
635u32 spl_arch_boot_image_offset(u32 image_offset, u32 rom_bt_dev)
636{
637 /* Hard code for eMMC image_offset on 8ULP ROM, need fix by ROM, temp workaround */
638 if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_MMC && card_emmc_is_boot_part_en())
639 image_offset = 0;
640
641 return image_offset;
642}