blob: 9a632b9cc6a0c579d7f91bdfa9e60d326477b219 [file] [log] [blame]
Peng Fan331d40d2021-08-07 16:00:31 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 NXP
4 */
5
Peng Fan77c3b9c2021-08-07 16:00:33 +08006#include <asm/io.h>
7#include <asm/arch/clock.h>
8#include <asm/arch/imx-regs.h>
Peng Fan331d40d2021-08-07 16:00:31 +08009#include <asm/arch/sys_proto.h>
Peng Fan9ef89ea2021-08-07 16:00:35 +080010#include <asm/armv8/mmu.h>
Peng Fan77c3b9c2021-08-07 16:00:33 +080011#include <asm/mach-imx/boot_mode.h>
Ye Li619412a2021-08-07 16:01:01 +080012#include <asm/global_data.h>
Ye Li610083e2021-08-07 16:00:48 +080013#include <efi_loader.h>
Simon Glass7fe32b32022-03-04 08:43:05 -070014#include <event.h>
Ye Li610083e2021-08-07 16:00:48 +080015#include <spl.h>
Peng Fan3912d4b2021-08-07 16:00:59 +080016#include <asm/arch/rdc.h>
Ye Liba472a22021-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 Lia7990a82021-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 Li961ac782021-10-29 09:46:15 +080027#include <fuse.h>
Alice Guo6293b732021-10-29 09:46:32 +080028#include <thermal.h>
Ye Li5579d662022-04-06 14:30:08 +080029#include <linux/iopoll.h>
Peng Fan331d40d2021-08-07 16:00:31 +080030
Peng Fan9ef89ea2021-08-07 16:00:35 +080031DECLARE_GLOBAL_DATA_PTR;
32
Ye Li6f3858d2021-08-07 16:00:39 +080033struct rom_api *g_rom_api = (struct rom_api *)0x1980;
34
Ye Li619412a2021-08-07 16:01:01 +080035enum boot_device get_boot_device(void)
36{
37 volatile gd_t *pgd = gd;
38 int ret;
39 u32 boot;
40 u16 boot_type;
41 u8 boot_instance;
42 enum boot_device boot_dev = SD1_BOOT;
43
44 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
45 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
46 set_gd(pgd);
47
48 if (ret != ROM_API_OKAY) {
49 puts("ROMAPI: failure at query_boot_info\n");
50 return -1;
51 }
52
53 boot_type = boot >> 16;
54 boot_instance = (boot >> 8) & 0xff;
55
56 switch (boot_type) {
57 case BT_DEV_TYPE_SD:
58 boot_dev = boot_instance + SD1_BOOT;
59 break;
60 case BT_DEV_TYPE_MMC:
61 boot_dev = boot_instance + MMC1_BOOT;
62 break;
63 case BT_DEV_TYPE_NAND:
64 boot_dev = NAND_BOOT;
65 break;
66 case BT_DEV_TYPE_FLEXSPINOR:
67 boot_dev = QSPI_BOOT;
68 break;
69 case BT_DEV_TYPE_USB:
70 boot_dev = USB_BOOT;
71 break;
72 default:
73 break;
74 }
75
76 return boot_dev;
77}
78
79bool is_usb_boot(void)
80{
81 return get_boot_device() == USB_BOOT;
82}
83
84#ifdef CONFIG_ENV_IS_IN_MMC
85__weak int board_mmc_get_env_dev(int devno)
86{
87 return devno;
88}
89
90int mmc_get_env_dev(void)
91{
92 volatile gd_t *pgd = gd;
93 int ret;
94 u32 boot;
95 u16 boot_type;
96 u8 boot_instance;
97
98 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
99 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
100 set_gd(pgd);
101
102 if (ret != ROM_API_OKAY) {
103 puts("ROMAPI: failure at query_boot_info\n");
104 return CONFIG_SYS_MMC_ENV_DEV;
105 }
106
107 boot_type = boot >> 16;
108 boot_instance = (boot >> 8) & 0xff;
109
110 /* If not boot from sd/mmc, use default value */
111 if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC)
112 return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV);
113
114 return board_mmc_get_env_dev(boot_instance);
115}
116#endif
117
Peng Fan331d40d2021-08-07 16:00:31 +0800118u32 get_cpu_rev(void)
119{
120 return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0;
121}
Peng Fan77c3b9c2021-08-07 16:00:33 +0800122
123enum bt_mode get_boot_mode(void)
124{
125 u32 bt0_cfg = 0;
126
Ye Li27b6a452021-08-07 16:01:07 +0800127 bt0_cfg = readl(SIM_SEC_BASE_ADDR + 0x24);
Peng Fan77c3b9c2021-08-07 16:00:33 +0800128 bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK);
129
130 if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) {
131 /* No low power boot */
132 if (bt0_cfg & BT0CFG_DUALBOOT_MASK)
133 return DUAL_BOOT;
134 else
135 return SINGLE_BOOT;
136 }
137
138 return LOW_POWER_BOOT;
139}
140
Ye Li5579d662022-04-06 14:30:08 +0800141bool m33_image_booted(void)
142{
143 u32 gp6;
144
145 /* DGO_GP6 */
146 gp6 = readl(SIM_SEC_BASE_ADDR + 0x28);
147 if (gp6 & BIT(5))
148 return true;
149
150 return false;
151}
152
153int m33_image_handshake(ulong timeout_ms)
154{
155 u32 fsr;
156 int ret;
157 ulong timeout_us = timeout_ms * 1000;
158
159 /* enable MU0_MUB clock before access the register of MU0_MUB */
160 pcc_clock_enable(3, MU0_B_PCC3_SLOT, true);
161
162 /* Notify m33 that it's ready to do init srtm(enable mu receive interrupt and so on) */
163 setbits_le32(MU0_B_BASE_ADDR + 0x100, BIT(0)); /* set FCR F0 flag of MU0_MUB */
164
165 /*
166 * Wait m33 to set FCR F0 flag of MU0_MUA
167 * Clear FCR F0 flag of MU0_MUB after m33 has set FCR F0 flag of MU0_MUA
168 */
169 ret = readl_poll_sleep_timeout(MU0_B_BASE_ADDR + 0x104, fsr, fsr & BIT(0), 10, timeout_us);
170 if (!ret)
171 clrbits_le32(MU0_B_BASE_ADDR + 0x100, BIT(0));
172
173 return ret;
174}
175
Peng Fanc17f5932021-08-07 16:00:34 +0800176#define CMC_SRS_TAMPER BIT(31)
177#define CMC_SRS_SECURITY BIT(30)
178#define CMC_SRS_TZWDG BIT(29)
179#define CMC_SRS_JTAG_RST BIT(28)
180#define CMC_SRS_CORE1 BIT(16)
181#define CMC_SRS_LOCKUP BIT(15)
182#define CMC_SRS_SW BIT(14)
183#define CMC_SRS_WDG BIT(13)
184#define CMC_SRS_PIN_RESET BIT(8)
185#define CMC_SRS_WARM BIT(4)
186#define CMC_SRS_HVD BIT(3)
187#define CMC_SRS_LVD BIT(2)
188#define CMC_SRS_POR BIT(1)
189#define CMC_SRS_WUP BIT(0)
190
Peng Fanc17f5932021-08-07 16:00:34 +0800191static char *get_reset_cause(char *ret)
192{
193 u32 cause1, cause = 0, srs = 0;
Peng Fan9ef89ea2021-08-07 16:00:35 +0800194 void __iomem *reg_ssrs = (void __iomem *)(CMC1_BASE_ADDR + 0x88);
195 void __iomem *reg_srs = (void __iomem *)(CMC1_BASE_ADDR + 0x80);
Peng Fanc17f5932021-08-07 16:00:34 +0800196
197 if (!ret)
198 return "null";
199
200 srs = readl(reg_srs);
201 cause1 = readl(reg_ssrs);
202
Peng Fan8a588972021-08-07 16:01:06 +0800203 cause = srs & (CMC_SRS_POR | CMC_SRS_WUP | CMC_SRS_WARM);
Peng Fanc17f5932021-08-07 16:00:34 +0800204
205 switch (cause) {
206 case CMC_SRS_POR:
207 sprintf(ret, "%s", "POR");
208 break;
209 case CMC_SRS_WUP:
210 sprintf(ret, "%s", "WUP");
211 break;
212 case CMC_SRS_WARM:
Peng Fan8a588972021-08-07 16:01:06 +0800213 cause = srs & (CMC_SRS_WDG | CMC_SRS_SW |
Peng Fanc17f5932021-08-07 16:00:34 +0800214 CMC_SRS_JTAG_RST);
215 switch (cause) {
216 case CMC_SRS_WDG:
217 sprintf(ret, "%s", "WARM-WDG");
218 break;
219 case CMC_SRS_SW:
220 sprintf(ret, "%s", "WARM-SW");
221 break;
222 case CMC_SRS_JTAG_RST:
223 sprintf(ret, "%s", "WARM-JTAG");
224 break;
225 default:
226 sprintf(ret, "%s", "WARM-UNKN");
227 break;
228 }
229 break;
230 default:
Peng Fan8a588972021-08-07 16:01:06 +0800231 sprintf(ret, "%s-%X", "UNKN", srs);
Peng Fanc17f5932021-08-07 16:00:34 +0800232 break;
233 }
234
235 debug("[%X] SRS[%X] %X - ", cause1, srs, srs ^ cause1);
236 return ret;
237}
238
Peng Fan77c3b9c2021-08-07 16:00:33 +0800239#if defined(CONFIG_DISPLAY_CPUINFO)
240const char *get_imx_type(u32 imxtype)
241{
242 return "8ULP";
243}
244
245int print_cpuinfo(void)
246{
247 u32 cpurev;
248 char cause[18];
249
250 cpurev = get_cpu_rev();
251
Ye Li112b4ca2021-10-29 09:46:24 +0800252 printf("CPU: i.MX%s rev%d.%d at %d MHz\n",
Peng Fan77c3b9c2021-08-07 16:00:33 +0800253 get_imx_type((cpurev & 0xFF000) >> 12),
254 (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0,
255 mxc_get_clock(MXC_ARM_CLK) / 1000000);
256
Alice Guo6293b732021-10-29 09:46:32 +0800257#if defined(CONFIG_IMX_PMC_TEMPERATURE)
258 struct udevice *udev;
259 int ret, temp;
260
261 ret = uclass_get_device(UCLASS_THERMAL, 0, &udev);
262 if (!ret) {
263 ret = thermal_get_temp(udev, &temp);
264 if (!ret)
265 printf("CPU current temperature: %d\n", temp);
266 else
267 debug(" - failed to get CPU current temperature\n");
268 } else {
269 debug(" - failed to get CPU current temperature\n");
270 }
271#endif
272
Peng Fanc17f5932021-08-07 16:00:34 +0800273 printf("Reset cause: %s\n", get_reset_cause(cause));
274
Peng Fan77c3b9c2021-08-07 16:00:33 +0800275 printf("Boot mode: ");
276 switch (get_boot_mode()) {
277 case LOW_POWER_BOOT:
278 printf("Low power boot\n");
279 break;
280 case DUAL_BOOT:
281 printf("Dual boot\n");
282 break;
283 case SINGLE_BOOT:
284 default:
285 printf("Single boot\n");
286 break;
287 }
288
289 return 0;
290}
291#endif
Peng Fan9ef89ea2021-08-07 16:00:35 +0800292
Peng Fan3a01f722021-08-07 16:00:49 +0800293#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
294#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
295#define REFRESH_WORD0 0xA602 /* 1st refresh word */
296#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
297
298static void disable_wdog(void __iomem *wdog_base)
299{
300 u32 val_cs = readl(wdog_base + 0x00);
301
302 if (!(val_cs & 0x80))
303 return;
304
305 dmb();
306 __raw_writel(REFRESH_WORD0, (wdog_base + 0x04)); /* Refresh the CNT */
307 __raw_writel(REFRESH_WORD1, (wdog_base + 0x04));
308 dmb();
309
310 if (!(val_cs & 800)) {
311 dmb();
312 __raw_writel(UNLOCK_WORD0, (wdog_base + 0x04));
313 __raw_writel(UNLOCK_WORD1, (wdog_base + 0x04));
314 dmb();
315
316 while (!(readl(wdog_base + 0x00) & 0x800))
317 ;
318 }
319 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
320 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
321 writel(0x120, (wdog_base + 0x00)); /* Disable it and set update */
322
323 while (!(readl(wdog_base + 0x00) & 0x400))
324 ;
325}
326
Peng Fan9ef89ea2021-08-07 16:00:35 +0800327void init_wdog(void)
328{
Peng Fan3a01f722021-08-07 16:00:49 +0800329 disable_wdog((void __iomem *)WDG3_RBASE);
Peng Fan9ef89ea2021-08-07 16:00:35 +0800330}
331
332static struct mm_region imx8ulp_arm64_mem_map[] = {
333 {
334 /* ROM */
335 .virt = 0x0,
336 .phys = 0x0,
337 .size = 0x40000UL,
338 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
339 PTE_BLOCK_OUTER_SHARE
340 },
341 {
342 /* FLEXSPI0 */
343 .virt = 0x04000000,
344 .phys = 0x04000000,
345 .size = 0x08000000UL,
346 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
347 PTE_BLOCK_NON_SHARE |
348 PTE_BLOCK_PXN | PTE_BLOCK_UXN
349 },
350 {
351 /* SSRAM (align with 2M) */
352 .virt = 0x1FE00000UL,
353 .phys = 0x1FE00000UL,
354 .size = 0x400000UL,
355 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
356 PTE_BLOCK_OUTER_SHARE |
357 PTE_BLOCK_PXN | PTE_BLOCK_UXN
358 }, {
359 /* SRAM1 (align with 2M) */
360 .virt = 0x21000000UL,
361 .phys = 0x21000000UL,
362 .size = 0x200000UL,
363 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
364 PTE_BLOCK_OUTER_SHARE |
365 PTE_BLOCK_PXN | PTE_BLOCK_UXN
366 }, {
367 /* SRAM0 (align with 2M) */
368 .virt = 0x22000000UL,
369 .phys = 0x22000000UL,
370 .size = 0x200000UL,
371 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
372 PTE_BLOCK_OUTER_SHARE |
373 PTE_BLOCK_PXN | PTE_BLOCK_UXN
374 }, {
375 /* Peripherals */
376 .virt = 0x27000000UL,
377 .phys = 0x27000000UL,
378 .size = 0x3000000UL,
379 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
380 PTE_BLOCK_NON_SHARE |
381 PTE_BLOCK_PXN | PTE_BLOCK_UXN
382 }, {
383 /* Peripherals */
384 .virt = 0x2D000000UL,
385 .phys = 0x2D000000UL,
386 .size = 0x1600000UL,
387 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
388 PTE_BLOCK_NON_SHARE |
389 PTE_BLOCK_PXN | PTE_BLOCK_UXN
390 }, {
391 /* FLEXSPI1-2 */
392 .virt = 0x40000000UL,
393 .phys = 0x40000000UL,
394 .size = 0x40000000UL,
395 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
396 PTE_BLOCK_NON_SHARE |
397 PTE_BLOCK_PXN | PTE_BLOCK_UXN
398 }, {
399 /* DRAM1 */
400 .virt = 0x80000000UL,
401 .phys = 0x80000000UL,
402 .size = PHYS_SDRAM_SIZE,
403 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
404 PTE_BLOCK_OUTER_SHARE
405 }, {
406 /*
407 * empty entrie to split table entry 5
408 * if needed when TEEs are used
409 */
410 0,
411 }, {
412 /* List terminator */
413 0,
414 }
415};
416
417struct mm_region *mem_map = imx8ulp_arm64_mem_map;
418
419/* simplify the page table size to enhance boot speed */
420#define MAX_PTE_ENTRIES 512
421#define MAX_MEM_MAP_REGIONS 16
422u64 get_page_table_size(void)
423{
424 u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
425 u64 size = 0;
426
427 /*
428 * For each memory region, the max table size:
429 * 2 level 3 tables + 2 level 2 tables + 1 level 1 table
430 */
431 size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt;
432
433 /*
434 * We need to duplicate our page table once to have an emergency pt to
435 * resort to when splitting page tables later on
436 */
437 size *= 2;
438
439 /*
440 * We may need to split page tables later on if dcache settings change,
441 * so reserve up to 4 (random pick) page tables for that.
442 */
443 size += one_pt * 4;
444
445 return size;
446}
447
448void enable_caches(void)
449{
450 /* TODO: add TEE memmap region */
451
452 icache_enable();
453 dcache_enable();
454}
455
456int dram_init(void)
457{
458 gd->ram_size = PHYS_SDRAM_SIZE;
459
460 return 0;
461}
462
Tom Rinib9d66a02021-08-30 09:16:29 -0400463#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Peng Fan9ef89ea2021-08-07 16:00:35 +0800464void get_board_serial(struct tag_serialnr *serialnr)
465{
Ye Lia7990a82021-08-07 16:01:00 +0800466 u32 uid[4];
467 u32 res;
468 int ret;
469
470 ret = ahab_read_common_fuse(1, uid, 4, &res);
471 if (ret)
472 printf("ahab read fuse failed %d, 0x%x\n", ret, res);
473 else
474 printf("UID 0x%x,0x%x,0x%x,0x%x\n", uid[0], uid[1], uid[2], uid[3]);
475
476 serialnr->low = uid[0];
477 serialnr->high = uid[3];
Peng Fan9ef89ea2021-08-07 16:00:35 +0800478}
479#endif
480
Ye Liaadd6ca2021-08-07 16:00:50 +0800481static void set_core0_reset_vector(u32 entry)
Peng Fan9ef89ea2021-08-07 16:00:35 +0800482{
Ye Li610083e2021-08-07 16:00:48 +0800483 /* Update SIM1 DGO8 for reset vector base */
Ye Liaadd6ca2021-08-07 16:00:50 +0800484 writel(entry, SIM1_BASE_ADDR + 0x5c);
Ye Li610083e2021-08-07 16:00:48 +0800485
486 /* set update bit */
487 setbits_le32(SIM1_BASE_ADDR + 0x8, 0x1 << 24);
488
489 /* polling the ack */
490 while ((readl(SIM1_BASE_ADDR + 0x8) & (0x1 << 26)) == 0)
491 ;
492
493 /* clear the update */
494 clrbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 24));
495
496 /* clear the ack by set 1 */
497 setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26));
Ye Liaadd6ca2021-08-07 16:00:50 +0800498}
499
Peng Fan3912d4b2021-08-07 16:00:59 +0800500static int trdc_set_access(void)
Peng Fana443ec22021-08-07 16:00:58 +0800501{
502 /*
Peng Fan3912d4b2021-08-07 16:00:59 +0800503 * TRDC mgr + 4 MBC + 2 MRC.
504 * S400 should already configure when release RDC
505 * A35 only map non-secure region for pbridge0 and 1, set sec_access to false
Peng Fana443ec22021-08-07 16:00:58 +0800506 */
Peng Fan3912d4b2021-08-07 16:00:59 +0800507 trdc_mbc_set_access(2, 7, 0, 49, false);
508 trdc_mbc_set_access(2, 7, 0, 50, false);
509 trdc_mbc_set_access(2, 7, 0, 51, false);
510 trdc_mbc_set_access(2, 7, 0, 52, false);
511 trdc_mbc_set_access(2, 7, 0, 53, false);
512 trdc_mbc_set_access(2, 7, 0, 54, false);
Peng Fana443ec22021-08-07 16:00:58 +0800513
Peng Fan3912d4b2021-08-07 16:00:59 +0800514 /* CGC0: PBridge0 slot 47 */
515 trdc_mbc_set_access(2, 7, 0, 47, false);
Peng Fana443ec22021-08-07 16:00:58 +0800516
Peng Fan3912d4b2021-08-07 16:00:59 +0800517 /* Iomuxc0: : PBridge1 slot 33 */
518 trdc_mbc_set_access(2, 7, 1, 33, false);
Peng Fana443ec22021-08-07 16:00:58 +0800519
Ye Li608ed202021-10-29 09:46:20 +0800520 /* flexspi0 */
521 trdc_mrc_region_set_access(0, 7, 0x04000000, 0x0c000000, false);
Ye Li9dde3902021-10-29 09:46:21 +0800522
523 /* tpm0: PBridge1 slot 21 */
524 trdc_mbc_set_access(2, 7, 1, 21, false);
525 /* lpi2c0: PBridge1 slot 24 */
526 trdc_mbc_set_access(2, 7, 1, 24, false);
Peng Fana443ec22021-08-07 16:00:58 +0800527 return 0;
528}
529
Ye Lid563d292021-10-29 09:46:16 +0800530void lpav_configure(void)
531{
532 /* LPAV to APD */
533 setbits_le32(SIM_SEC_BASE_ADDR + 0x44, BIT(7));
534
Peng Fan99de1682021-10-29 09:46:17 +0800535 /* PXP/GPU 2D/3D/DCNANO/MIPI_DSI/EPDC/HIFI4 to APD */
536 setbits_le32(SIM_SEC_BASE_ADDR + 0x4c, 0x7F);
Ye Lid563d292021-10-29 09:46:16 +0800537
538 /* LPAV slave/dma2 ch allocation and request allocation to APD */
539 writel(0x1f, SIM_SEC_BASE_ADDR + 0x50);
540 writel(0xffffffff, SIM_SEC_BASE_ADDR + 0x54);
541 writel(0x003fffff, SIM_SEC_BASE_ADDR + 0x58);
Ye Libd8b6732021-10-29 09:46:23 +0800542}
Ye Li16062f92021-10-29 09:46:22 +0800543
Ye Li9c7fbeb2021-10-29 09:46:25 +0800544void load_lposc_fuse(void)
545{
546 int ret;
547 u32 val = 0, val2 = 0, reg;
548
549 ret = fuse_read(25, 0, &val);
550 if (ret)
551 return; /* failed */
552
553 ret = fuse_read(25, 1, &val2);
554 if (ret)
555 return; /* failed */
556
557 /* LPOSCCTRL */
558 reg = readl(0x2802f304);
559 reg &= ~0xff;
560 reg |= (val & 0xff);
561 writel(reg, 0x2802f304);
562}
563
Ye Libd8b6732021-10-29 09:46:23 +0800564void set_lpav_qos(void)
565{
Ye Li16062f92021-10-29 09:46:22 +0800566 /* Set read QoS of dcnano on LPAV NIC */
567 writel(0xf, 0x2e447100);
Ye Lid563d292021-10-29 09:46:16 +0800568}
569
Ye Liaadd6ca2021-08-07 16:00:50 +0800570int arch_cpu_init(void)
571{
572 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
Ye Li961ac782021-10-29 09:46:15 +0800573 u32 val = 0;
574 int ret;
575 bool rdc_en = true; /* Default assume DBD_EN is set */
576
Ye Liba472a22021-08-07 16:00:55 +0800577 /* Disable wdog */
578 init_wdog();
579
Ye Li961ac782021-10-29 09:46:15 +0800580 /* Read DBD_EN fuse */
581 ret = fuse_read(8, 1, &val);
582 if (!ret)
583 rdc_en = !!(val & 0x4000);
584
Peng Fana443ec22021-08-07 16:00:58 +0800585 if (get_boot_mode() == SINGLE_BOOT) {
Ye Li961ac782021-10-29 09:46:15 +0800586 if (rdc_en)
587 release_rdc(RDC_TRDC);
588
Peng Fana443ec22021-08-07 16:00:58 +0800589 trdc_set_access();
Ye Lid563d292021-10-29 09:46:16 +0800590
591 lpav_configure();
Peng Fana443ec22021-08-07 16:00:58 +0800592 }
Peng Fan3df56492021-08-07 16:00:57 +0800593
Ye Li961ac782021-10-29 09:46:15 +0800594 /* Release xrdc, then allow A35 to write SRAM2 */
595 if (rdc_en)
596 release_rdc(RDC_XRDC);
597
Ye Liba472a22021-08-07 16:00:55 +0800598 xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00);
599
Ye Liaadd6ca2021-08-07 16:00:50 +0800600 clock_init();
601 } else {
602 /* reconfigure core0 reset vector to ROM */
603 set_core0_reset_vector(0x1000);
604 }
605
606 return 0;
607}
608
Simon Glass7fe32b32022-03-04 08:43:05 -0700609static int imx8ulp_check_mu(void *ctx, struct event *event)
Ye Lia7990a82021-08-07 16:01:00 +0800610{
611 struct udevice *devp;
612 int node, ret;
613
614 node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8ulp-mu");
615
616 ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp);
617 if (ret) {
618 printf("could not get S400 mu %d\n", ret);
619 return ret;
620 }
621
622 return 0;
623}
Simon Glass7fe32b32022-03-04 08:43:05 -0700624EVENT_SPY(EVT_DM_POST_INIT, imx8ulp_check_mu);
Ye Lia7990a82021-08-07 16:01:00 +0800625
Ye Liaadd6ca2021-08-07 16:00:50 +0800626#if defined(CONFIG_SPL_BUILD)
627__weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
628{
629 debug("image entry point: 0x%lx\n", spl_image->entry_point);
630
631 set_core0_reset_vector((u32)spl_image->entry_point);
Ye Li610083e2021-08-07 16:00:48 +0800632
633 /* Enable the 512KB cache */
634 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 4));
635
636 /* reset core */
637 setbits_le32(SIM1_BASE_ADDR + 0x30, (0x1 << 16));
638
639 while (1)
640 ;
641}
642#endif
Peng Fan525a28c2021-08-07 16:01:03 +0800643
644void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
645{
Ye Li484b3062021-10-29 09:46:28 +0800646 u32 val[2] = {};
647 int ret;
648
649 ret = fuse_read(5, 3, &val[0]);
650 if (ret)
651 goto err;
652
653 ret = fuse_read(5, 4, &val[1]);
654 if (ret)
655 goto err;
656
657 mac[0] = val[0];
658 mac[1] = val[0] >> 8;
659 mac[2] = val[0] >> 16;
660 mac[3] = val[0] >> 24;
661 mac[4] = val[1];
662 mac[5] = val[1] >> 8;
663
664 debug("%s: MAC%d: %02x.%02x.%02x.%02x.%02x.%02x\n",
665 __func__, dev_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
666 return;
667err:
Peng Fan525a28c2021-08-07 16:01:03 +0800668 memset(mac, 0, 6);
Ye Li484b3062021-10-29 09:46:28 +0800669 printf("%s: fuse read err: %d\n", __func__, ret);
Peng Fan525a28c2021-08-07 16:01:03 +0800670}
Ye Lie8b68042021-08-07 16:01:08 +0800671
672int (*card_emmc_is_boot_part_en)(void) = (void *)0x67cc;
673u32 spl_arch_boot_image_offset(u32 image_offset, u32 rom_bt_dev)
674{
675 /* Hard code for eMMC image_offset on 8ULP ROM, need fix by ROM, temp workaround */
676 if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_MMC && card_emmc_is_boot_part_en())
677 image_offset = 0;
678
679 return image_offset;
680}