blob: 8050406613d7db73389ca3d291ed4b4013632c93 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Faneae4de22018-01-10 13:20:37 +08002/*
Gaurav Jain81113a02022-03-24 11:50:27 +05303 * Copyright 2017-2019, 2021 NXP
Peng Faneae4de22018-01-10 13:20:37 +08004 *
5 * Peng Fan <peng.fan@nxp.com>
Peng Faneae4de22018-01-10 13:20:37 +08006 */
7
8#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Simon Glassfc557362022-03-04 08:43:05 -070010#include <event.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Peng Faneae4de22018-01-10 13:20:37 +080013#include <asm/arch/imx-regs.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Peng Faneae4de22018-01-10 13:20:37 +080015#include <asm/io.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/sys_proto.h>
18#include <asm/mach-imx/hab.h>
19#include <asm/mach-imx/boot_mode.h>
20#include <asm/mach-imx/syscounter.h>
Peng Fana35215d2020-07-09 13:39:26 +080021#include <asm/ptrace.h>
Peng Faneae4de22018-01-10 13:20:37 +080022#include <asm/armv8/mmu.h>
Peng Fanc98e0322019-08-27 06:25:58 +000023#include <dm/uclass.h>
Gaurav Jain81113a02022-03-24 11:50:27 +053024#include <dm/device.h>
Peng Fana35215d2020-07-09 13:39:26 +080025#include <efi_loader.h>
Ye Li0513f362019-07-15 01:16:46 -070026#include <env.h>
27#include <env_internal.h>
Peng Faneae4de22018-01-10 13:20:37 +080028#include <errno.h>
29#include <fdt_support.h>
30#include <fsl_wdog.h>
31#include <imx_sip.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060032#include <linux/bitops.h>
Peng Faneae4de22018-01-10 13:20:37 +080033
34DECLARE_GLOBAL_DATA_PTR;
35
Stefano Babicf8b509b2019-09-20 08:47:53 +020036#if defined(CONFIG_IMX_HAB)
Peng Faneae4de22018-01-10 13:20:37 +080037struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
38 .bank = 1,
39 .word = 3,
40};
41#endif
42
43int timer_init(void)
44{
45#ifdef CONFIG_SPL_BUILD
46 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
47 unsigned long freq = readl(&sctr->cntfid0);
48
49 /* Update with accurate clock frequency */
50 asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
51
52 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
53 SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
54#endif
55
56 gd->arch.tbl = 0;
57 gd->arch.tbu = 0;
58
59 return 0;
60}
61
62void enable_tzc380(void)
63{
64 struct iomuxc_gpr_base_regs *gpr =
65 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
66
67 /* Enable TZASC and lock setting */
68 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN);
69 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK);
Andrey Zhizhikin7c2d23a2022-01-24 21:48:09 +010070
71 /*
72 * According to TRM, TZASC_ID_SWAP_BYPASS should be set in
73 * order to avoid AXI Bus errors when GPU is in use
74 */
Peng Fanda7a16c2022-04-29 16:18:49 +080075 setbits_le32(&gpr->gpr[10], GPR_TZASC_ID_SWAP_BYPASS);
Andrey Zhizhikin7c2d23a2022-01-24 21:48:09 +010076
77 /*
78 * imx8mn and imx8mp implements the lock bit for
79 * TZASC_ID_SWAP_BYPASS, enable it to lock settings
80 */
Peng Fanda7a16c2022-04-29 16:18:49 +080081 setbits_le32(&gpr->gpr[10], GPR_TZASC_ID_SWAP_BYPASS_LOCK);
Andrey Zhizhikin7c2d23a2022-01-24 21:48:09 +010082
Ye Li4c97c462019-08-27 06:25:34 +000083 /*
84 * set Region 0 attribute to allow secure and non-secure
85 * read/write permission. Found some masters like usb dwc3
86 * controllers can't work with secure memory.
87 */
88 writel(0xf0000000, TZASC_BASE_ADDR + 0x108);
Peng Faneae4de22018-01-10 13:20:37 +080089}
90
91void set_wdog_reset(struct wdog_regs *wdog)
92{
93 /*
94 * Output WDOG_B signal to reset external pmic or POR_B decided by
95 * the board design. Without external reset, the peripherals/DDR/
96 * PMIC are not reset, that may cause system working abnormal.
97 * WDZST bit is write-once only bit. Align this bit in kernel,
98 * otherwise kernel code will have no chance to set this bit.
99 */
100 setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK);
101}
102
103static struct mm_region imx8m_mem_map[] = {
104 {
105 /* ROM */
106 .virt = 0x0UL,
107 .phys = 0x0UL,
108 .size = 0x100000UL,
109 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
110 PTE_BLOCK_OUTER_SHARE
111 }, {
Gary Bisson5c72a452018-11-14 17:55:28 +0100112 /* CAAM */
113 .virt = 0x100000UL,
114 .phys = 0x100000UL,
115 .size = 0x8000UL,
116 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
117 PTE_BLOCK_NON_SHARE |
118 PTE_BLOCK_PXN | PTE_BLOCK_UXN
119 }, {
Marek Vasutb1738e02021-02-25 21:52:26 +0100120 /* OCRAM_S */
121 .virt = 0x180000UL,
122 .phys = 0x180000UL,
123 .size = 0x8000UL,
124 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
125 PTE_BLOCK_OUTER_SHARE
126 }, {
Gary Bisson5c72a452018-11-14 17:55:28 +0100127 /* TCM */
128 .virt = 0x7C0000UL,
129 .phys = 0x7C0000UL,
130 .size = 0x80000UL,
131 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
132 PTE_BLOCK_NON_SHARE |
133 PTE_BLOCK_PXN | PTE_BLOCK_UXN
134 }, {
Peng Faneae4de22018-01-10 13:20:37 +0800135 /* OCRAM */
136 .virt = 0x900000UL,
137 .phys = 0x900000UL,
138 .size = 0x200000UL,
139 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
140 PTE_BLOCK_OUTER_SHARE
141 }, {
142 /* AIPS */
143 .virt = 0xB00000UL,
144 .phys = 0xB00000UL,
145 .size = 0x3f500000UL,
146 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
147 PTE_BLOCK_NON_SHARE |
148 PTE_BLOCK_PXN | PTE_BLOCK_UXN
149 }, {
150 /* DRAM1 */
151 .virt = 0x40000000UL,
152 .phys = 0x40000000UL,
Peng Fanb749b5e2019-08-27 06:25:27 +0000153 .size = PHYS_SDRAM_SIZE,
Peng Faneae4de22018-01-10 13:20:37 +0800154 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
155 PTE_BLOCK_OUTER_SHARE
Peng Fanb749b5e2019-08-27 06:25:27 +0000156#ifdef PHYS_SDRAM_2_SIZE
Peng Faneae4de22018-01-10 13:20:37 +0800157 }, {
158 /* DRAM2 */
159 .virt = 0x100000000UL,
160 .phys = 0x100000000UL,
Peng Fanb749b5e2019-08-27 06:25:27 +0000161 .size = PHYS_SDRAM_2_SIZE,
Peng Faneae4de22018-01-10 13:20:37 +0800162 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
163 PTE_BLOCK_OUTER_SHARE
Peng Fanb749b5e2019-08-27 06:25:27 +0000164#endif
Peng Faneae4de22018-01-10 13:20:37 +0800165 }, {
Peng Fanfa35c3d2020-07-09 15:26:06 +0800166 /* empty entrie to split table entry 5 if needed when TEEs are used */
167 0,
168 }, {
Peng Faneae4de22018-01-10 13:20:37 +0800169 /* List terminator */
170 0,
171 }
172};
173
174struct mm_region *mem_map = imx8m_mem_map;
175
Marek Vasute48aac02021-02-27 14:59:00 +0100176static unsigned int imx8m_find_dram_entry_in_mem_map(void)
177{
178 int i;
179
180 for (i = 0; i < ARRAY_SIZE(imx8m_mem_map); i++)
Tom Rinibb4dd962022-11-16 13:10:37 -0500181 if (imx8m_mem_map[i].phys == CFG_SYS_SDRAM_BASE)
Marek Vasute48aac02021-02-27 14:59:00 +0100182 return i;
183
184 hang(); /* Entry not found, this must never happen. */
185}
186
Peng Fanb749b5e2019-08-27 06:25:27 +0000187void enable_caches(void)
188{
Ye Li453bfcb2022-04-07 15:55:56 +0800189 /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch
190 * If OPTEE does not run, still update the MMU table according to dram banks structure
191 * to set correct dram size from board_phys_sdram_size
192 */
193 int i = 0;
194 /*
195 * please make sure that entry initial value matches
196 * imx8m_mem_map for DRAM1
197 */
198 int entry = imx8m_find_dram_entry_in_mem_map();
199 u64 attrs = imx8m_mem_map[entry].attrs;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800200
Ye Li453bfcb2022-04-07 15:55:56 +0800201 while (i < CONFIG_NR_DRAM_BANKS &&
202 entry < ARRAY_SIZE(imx8m_mem_map)) {
203 if (gd->bd->bi_dram[i].start == 0)
204 break;
205 imx8m_mem_map[entry].phys = gd->bd->bi_dram[i].start;
206 imx8m_mem_map[entry].virt = gd->bd->bi_dram[i].start;
207 imx8m_mem_map[entry].size = gd->bd->bi_dram[i].size;
208 imx8m_mem_map[entry].attrs = attrs;
209 debug("Added memory mapping (%d): %llx %llx\n", entry,
210 imx8m_mem_map[entry].phys, imx8m_mem_map[entry].size);
211 i++; entry++;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800212 }
Peng Fanb749b5e2019-08-27 06:25:27 +0000213
214 icache_enable();
215 dcache_enable();
216}
217
Peng Fanfa35c3d2020-07-09 15:26:06 +0800218__weak int board_phys_sdram_size(phys_size_t *size)
219{
220 if (!size)
221 return -EINVAL;
222
223 *size = PHYS_SDRAM_SIZE;
Ye Li453bfcb2022-04-07 15:55:56 +0800224
225#ifdef PHYS_SDRAM_2_SIZE
226 *size += PHYS_SDRAM_2_SIZE;
227#endif
Peng Fanfa35c3d2020-07-09 15:26:06 +0800228 return 0;
229}
230
231int dram_init(void)
232{
233 phys_size_t sdram_size;
234 int ret;
235
236 ret = board_phys_sdram_size(&sdram_size);
237 if (ret)
238 return ret;
239
240 /* rom_pointer[1] contains the size of TEE occupies */
241 if (rom_pointer[1])
242 gd->ram_size = sdram_size - rom_pointer[1];
243 else
244 gd->ram_size = sdram_size;
245
Peng Fanfa35c3d2020-07-09 15:26:06 +0800246 return 0;
247}
248
249int dram_init_banksize(void)
250{
251 int bank = 0;
252 int ret;
253 phys_size_t sdram_size;
Ye Li453bfcb2022-04-07 15:55:56 +0800254 phys_size_t sdram_b1_size, sdram_b2_size;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800255
256 ret = board_phys_sdram_size(&sdram_size);
257 if (ret)
258 return ret;
259
Ye Li453bfcb2022-04-07 15:55:56 +0800260 /* Bank 1 can't cross over 4GB space */
261 if (sdram_size > 0xc0000000) {
262 sdram_b1_size = 0xc0000000;
263 sdram_b2_size = sdram_size - 0xc0000000;
264 } else {
265 sdram_b1_size = sdram_size;
266 sdram_b2_size = 0;
267 }
268
Peng Fanfa35c3d2020-07-09 15:26:06 +0800269 gd->bd->bi_dram[bank].start = PHYS_SDRAM;
270 if (rom_pointer[1]) {
271 phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
272 phys_size_t optee_size = (size_t)rom_pointer[1];
273
274 gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start;
Ye Li453bfcb2022-04-07 15:55:56 +0800275 if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_b1_size)) {
Peng Fanfa35c3d2020-07-09 15:26:06 +0800276 if (++bank >= CONFIG_NR_DRAM_BANKS) {
277 puts("CONFIG_NR_DRAM_BANKS is not enough\n");
278 return -1;
279 }
280
281 gd->bd->bi_dram[bank].start = optee_start + optee_size;
282 gd->bd->bi_dram[bank].size = PHYS_SDRAM +
Ye Li453bfcb2022-04-07 15:55:56 +0800283 sdram_b1_size - gd->bd->bi_dram[bank].start;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800284 }
285 } else {
Ye Li453bfcb2022-04-07 15:55:56 +0800286 gd->bd->bi_dram[bank].size = sdram_b1_size;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800287 }
288
Ye Li453bfcb2022-04-07 15:55:56 +0800289 if (sdram_b2_size) {
290 if (++bank >= CONFIG_NR_DRAM_BANKS) {
291 puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n");
292 return -1;
293 }
294 gd->bd->bi_dram[bank].start = 0x100000000UL;
295 gd->bd->bi_dram[bank].size = sdram_b2_size;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800296 }
Peng Fanfa35c3d2020-07-09 15:26:06 +0800297
298 return 0;
299}
300
301phys_size_t get_effective_memsize(void)
302{
Ye Li453bfcb2022-04-07 15:55:56 +0800303 int ret;
304 phys_size_t sdram_size;
305 phys_size_t sdram_b1_size;
306 ret = board_phys_sdram_size(&sdram_size);
307 if (!ret) {
308 /* Bank 1 can't cross over 4GB space */
309 if (sdram_size > 0xc0000000) {
310 sdram_b1_size = 0xc0000000;
311 } else {
312 sdram_b1_size = sdram_size;
313 }
Peng Fanfa35c3d2020-07-09 15:26:06 +0800314
Ye Li453bfcb2022-04-07 15:55:56 +0800315 if (rom_pointer[1]) {
316 /* We will relocate u-boot to Top of dram1. Tee position has two cases:
317 * 1. At the top of dram1, Then return the size removed optee size.
318 * 2. In the middle of dram1, return the size of dram1.
319 */
320 if ((rom_pointer[0] + rom_pointer[1]) == (PHYS_SDRAM + sdram_b1_size))
321 return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM);
322 }
323
324 return sdram_b1_size;
325 } else {
326 return PHYS_SDRAM_SIZE;
327 }
Peng Fanfa35c3d2020-07-09 15:26:06 +0800328}
329
Pali Rohár4f4f5832022-09-09 17:32:40 +0200330phys_size_t board_get_usable_ram_top(phys_size_t total_size)
Frieder Schrempf159879e2021-06-07 14:36:44 +0200331{
Marek Vasutdcbbf782022-04-14 15:51:46 +0200332 ulong top_addr;
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800333
Frieder Schrempf159879e2021-06-07 14:36:44 +0200334 /*
335 * Some IPs have their accessible address space restricted by
336 * the interconnect. Let's make sure U-Boot only ever uses the
337 * space below the 4G address boundary (which is 3GiB big),
338 * even when the effective available memory is bigger.
339 */
Marek Vasutdcbbf782022-04-14 15:51:46 +0200340 top_addr = clamp_val((u64)PHYS_SDRAM + gd->ram_size, 0, 0xffffffff);
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800341
342 /*
343 * rom_pointer[0] stores the TEE memory start address.
344 * rom_pointer[1] stores the size TEE uses.
345 * We need to reserve the memory region for TEE.
346 */
347 if (rom_pointer[0] && rom_pointer[1] && top_addr > rom_pointer[0])
348 top_addr = rom_pointer[0];
Frieder Schrempf159879e2021-06-07 14:36:44 +0200349
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800350 return top_addr;
Frieder Schrempf159879e2021-06-07 14:36:44 +0200351}
352
Peng Fan1caffdf2019-08-27 06:25:17 +0000353static u32 get_cpu_variant_type(u32 type)
354{
355 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
356 struct fuse_bank *bank = &ocotp->bank[1];
357 struct fuse_bank1_regs *fuse =
358 (struct fuse_bank1_regs *)bank->fuse_regs;
359
360 u32 value = readl(&fuse->tester4);
361
Peng Fan67815082020-02-05 17:34:54 +0800362 if (type == MXC_CPU_IMX8MQ) {
363 if ((value & 0x3) == 0x2)
364 return MXC_CPU_IMX8MD;
365 else if (value & 0x200000)
366 return MXC_CPU_IMX8MQL;
367
368 } else if (type == MXC_CPU_IMX8MM) {
Peng Fan1caffdf2019-08-27 06:25:17 +0000369 switch (value & 0x3) {
370 case 2:
371 if (value & 0x1c0000)
372 return MXC_CPU_IMX8MMDL;
373 else
374 return MXC_CPU_IMX8MMD;
375 case 3:
376 if (value & 0x1c0000)
377 return MXC_CPU_IMX8MMSL;
378 else
379 return MXC_CPU_IMX8MMS;
380 default:
381 if (value & 0x1c0000)
382 return MXC_CPU_IMX8MML;
383 break;
384 }
Peng Fan1a07d912020-02-05 17:39:27 +0800385 } else if (type == MXC_CPU_IMX8MN) {
386 switch (value & 0x3) {
387 case 2:
Ye Li715180e2021-03-19 15:57:11 +0800388 if (value & 0x1000000) {
389 if (value & 0x10000000) /* MIPI DSI */
390 return MXC_CPU_IMX8MNUD;
391 else
392 return MXC_CPU_IMX8MNDL;
393 } else {
Peng Fan1a07d912020-02-05 17:39:27 +0800394 return MXC_CPU_IMX8MND;
Ye Li715180e2021-03-19 15:57:11 +0800395 }
Peng Fan1a07d912020-02-05 17:39:27 +0800396 case 3:
Ye Li715180e2021-03-19 15:57:11 +0800397 if (value & 0x1000000) {
398 if (value & 0x10000000) /* MIPI DSI */
399 return MXC_CPU_IMX8MNUS;
400 else
401 return MXC_CPU_IMX8MNSL;
402 } else {
Peng Fan1a07d912020-02-05 17:39:27 +0800403 return MXC_CPU_IMX8MNS;
Ye Li715180e2021-03-19 15:57:11 +0800404 }
Peng Fan1a07d912020-02-05 17:39:27 +0800405 default:
Ye Li715180e2021-03-19 15:57:11 +0800406 if (value & 0x1000000) {
407 if (value & 0x10000000) /* MIPI DSI */
408 return MXC_CPU_IMX8MNUQ;
409 else
410 return MXC_CPU_IMX8MNL;
411 }
Peng Fan1a07d912020-02-05 17:39:27 +0800412 break;
413 }
Ye Lid2d754f2020-04-20 20:12:54 -0700414 } else if (type == MXC_CPU_IMX8MP) {
415 u32 value0 = readl(&fuse->tester3);
416 u32 flag = 0;
417
418 if ((value0 & 0xc0000) == 0x80000)
419 return MXC_CPU_IMX8MPD;
420
421 /* vpu disabled */
422 if ((value0 & 0x43000000) == 0x43000000)
423 flag = 1;
424
425 /* npu disabled*/
426 if ((value & 0x8) == 0x8)
Peng Fan0386e7f2022-04-07 15:55:52 +0800427 flag |= BIT(1);
Ye Lid2d754f2020-04-20 20:12:54 -0700428
429 /* isp disabled */
430 if ((value & 0x3) == 0x3)
Peng Fan0386e7f2022-04-07 15:55:52 +0800431 flag |= BIT(2);
432
433 /* gpu disabled */
434 if ((value & 0xc0) == 0xc0)
435 flag |= BIT(3);
436
437 /* lvds disabled */
438 if ((value & 0x180000) == 0x180000)
439 flag |= BIT(4);
440
441 /* mipi dsi disabled */
442 if ((value & 0x60000) == 0x60000)
443 flag |= BIT(5);
Ye Lid2d754f2020-04-20 20:12:54 -0700444
445 switch (flag) {
Peng Fan0386e7f2022-04-07 15:55:52 +0800446 case 0x3f:
447 return MXC_CPU_IMX8MPUL;
Ye Lid2d754f2020-04-20 20:12:54 -0700448 case 7:
449 return MXC_CPU_IMX8MPL;
Ye Lid2d754f2020-04-20 20:12:54 -0700450 case 2:
451 return MXC_CPU_IMX8MP6;
Ye Lid2d754f2020-04-20 20:12:54 -0700452 default:
453 break;
454 }
455
Peng Fan1caffdf2019-08-27 06:25:17 +0000456 }
457
458 return type;
459}
460
Peng Faneae4de22018-01-10 13:20:37 +0800461u32 get_cpu_rev(void)
462{
463 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
464 u32 reg = readl(&ana_pll->digprog);
465 u32 type = (reg >> 16) & 0xff;
Peng Fan1caffdf2019-08-27 06:25:17 +0000466 u32 major_low = (reg >> 8) & 0xff;
Peng Faneae4de22018-01-10 13:20:37 +0800467 u32 rom_version;
468
469 reg &= 0xff;
470
Peng Fan69cec072019-12-27 10:14:02 +0800471 /* iMX8MP */
472 if (major_low == 0x43) {
Ye Lid2d754f2020-04-20 20:12:54 -0700473 type = get_cpu_variant_type(MXC_CPU_IMX8MP);
Peng Fan69cec072019-12-27 10:14:02 +0800474 } else if (major_low == 0x42) {
475 /* iMX8MN */
Peng Fan1a07d912020-02-05 17:39:27 +0800476 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
Peng Fan5d2f2062019-06-27 17:23:49 +0800477 } else if (major_low == 0x41) {
Peng Fan1caffdf2019-08-27 06:25:17 +0000478 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
479 } else {
480 if (reg == CHIP_REV_1_0) {
481 /*
Peng Fanc23fbdd2019-10-16 10:24:17 +0000482 * For B0 chip, the DIGPROG is not updated,
483 * it is still TO1.0. we have to check ROM
484 * version or OCOTP_READ_FUSE_DATA.
485 * 0xff0055aa is magic number for B1.
Peng Fan1caffdf2019-08-27 06:25:17 +0000486 */
Peng Fanc23fbdd2019-10-16 10:24:17 +0000487 if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) {
Ye Lic963ed12021-03-19 15:57:16 +0800488 /*
489 * B2 uses same DIGPROG and OCOTP_READ_FUSE_DATA value with B1,
490 * so have to check ROM to distinguish them
491 */
492 rom_version = readl((void __iomem *)ROM_VERSION_B0);
493 rom_version &= 0xff;
494 if (rom_version == CHIP_REV_2_2)
495 reg = CHIP_REV_2_2;
496 else
497 reg = CHIP_REV_2_1;
Peng Fanc23fbdd2019-10-16 10:24:17 +0000498 } else {
499 rom_version =
500 readl((void __iomem *)ROM_VERSION_A0);
501 if (rom_version != CHIP_REV_1_0) {
502 rom_version = readl((void __iomem *)ROM_VERSION_B0);
Patrick Wildtd4a78b92019-11-19 09:42:06 +0100503 rom_version &= 0xff;
Peng Fanc23fbdd2019-10-16 10:24:17 +0000504 if (rom_version == CHIP_REV_2_0)
505 reg = CHIP_REV_2_0;
506 }
Peng Fan1caffdf2019-08-27 06:25:17 +0000507 }
Peng Faneae4de22018-01-10 13:20:37 +0800508 }
Peng Fan67815082020-02-05 17:34:54 +0800509
510 type = get_cpu_variant_type(type);
Peng Faneae4de22018-01-10 13:20:37 +0800511 }
512
513 return (type << 12) | reg;
514}
515
516static void imx_set_wdog_powerdown(bool enable)
517{
518 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
519 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
520 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
521
522 /* Write to the PDE (Power Down Enable) bit */
523 writew(enable, &wdog1->wmcr);
524 writew(enable, &wdog2->wmcr);
525 writew(enable, &wdog3->wmcr);
526}
527
Simon Glassfc557362022-03-04 08:43:05 -0700528static int imx8m_check_clock(void *ctx, struct event *event)
Peng Fanc98e0322019-08-27 06:25:58 +0000529{
530 struct udevice *dev;
531 int ret;
532
Peng Fan3c073342019-10-16 03:01:51 +0000533 if (CONFIG_IS_ENABLED(CLK)) {
534 ret = uclass_get_device_by_name(UCLASS_CLK,
535 "clock-controller@30380000",
536 &dev);
537 if (ret < 0) {
538 printf("Failed to find clock node. Check device tree\n");
539 return ret;
540 }
Peng Fanc98e0322019-08-27 06:25:58 +0000541 }
542
543 return 0;
544}
Simon Glassfc557362022-03-04 08:43:05 -0700545EVENT_SPY(EVT_DM_POST_INIT, imx8m_check_clock);
Peng Fanc98e0322019-08-27 06:25:58 +0000546
Marek Vasutf7b184e2022-09-19 21:37:07 +0200547static void imx8m_setup_snvs(void)
548{
549 /* Enable SNVS clock */
550 clock_enable(CCGR_SNVS, 1);
551 /* Initialize glitch detect */
552 writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
553 /* Clear interrupt status */
554 writel(0xffffffff, SNVS_BASE_ADDR + SNVS_LPSR);
555}
556
Peng Faneae4de22018-01-10 13:20:37 +0800557int arch_cpu_init(void)
558{
Peng Fanc0b30d72019-04-17 09:41:16 +0000559 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
Marek Vasut3ea500a2022-04-13 00:41:52 +0200560
561#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
562 icache_enable();
563#endif
564
Peng Faneae4de22018-01-10 13:20:37 +0800565 /*
Peng Fand0ca2892019-08-27 06:25:37 +0000566 * ROM might disable clock for SCTR,
567 * enable the clock before timer_init.
568 */
569 if (IS_ENABLED(CONFIG_SPL_BUILD))
570 clock_enable(CCGR_SCTR, 1);
571 /*
Peng Faneae4de22018-01-10 13:20:37 +0800572 * Init timer at very early state, because sscg pll setting
573 * will use it
574 */
575 timer_init();
576
577 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
578 clock_init();
579 imx_set_wdog_powerdown(false);
Peng Fan9cf2aa32020-07-09 13:52:41 +0800580
581 if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() ||
582 is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() ||
Ye Li715180e2021-03-19 15:57:11 +0800583 is_imx8mnsl() || is_imx8mpd() || is_imx8mnud() || is_imx8mnus()) {
Peng Fan9cf2aa32020-07-09 13:52:41 +0800584 /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */
585 struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840);
586 struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880);
587 struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0);
588 struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR;
589
590 writel(0x1, &pgc_core2->pgcr);
591 writel(0x1, &pgc_core3->pgcr);
Ye Li715180e2021-03-19 15:57:11 +0800592 if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) {
Peng Fan9cf2aa32020-07-09 13:52:41 +0800593 writel(0x1, &pgc_core1->pgcr);
594 writel(0xE, &gpc->cpu_pgc_dn_trg);
595 } else {
596 writel(0xC, &gpc->cpu_pgc_dn_trg);
597 }
598 }
Peng Faneae4de22018-01-10 13:20:37 +0800599 }
600
Peng Fanc0b30d72019-04-17 09:41:16 +0000601 if (is_imx8mq()) {
602 clock_enable(CCGR_OCOTP, 1);
603 if (readl(&ocotp->ctrl) & 0x200)
604 writel(0x200, &ocotp->ctrl_clr);
605 }
606
Marek Vasutf7b184e2022-09-19 21:37:07 +0200607 imx8m_setup_snvs();
608
Peng Faneae4de22018-01-10 13:20:37 +0800609 return 0;
610}
611
Peng Fanc9823b02019-09-16 03:09:36 +0000612#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
613struct rom_api *g_rom_api = (struct rom_api *)0x980;
Peng Fanc9823b02019-09-16 03:09:36 +0000614#endif
615
Marek Vasut520ded02021-07-03 04:55:33 +0200616#if defined(CONFIG_IMX8M)
617#include <spl.h>
618int spl_mmc_emmc_boot_partition(struct mmc *mmc)
619{
620 u32 *rom_log_addr = (u32 *)0x9e0;
621 u32 *rom_log;
622 u8 event_id;
623 int i, part;
624
625 part = default_spl_mmc_emmc_boot_partition(mmc);
626
627 /* If the ROM event log pointer is not valid. */
628 if (*rom_log_addr < 0x900000 || *rom_log_addr >= 0xb00000 ||
629 *rom_log_addr & 0x3)
630 return part;
631
632 /* Parse the ROM event ID version 2 log */
633 rom_log = (u32 *)(uintptr_t)(*rom_log_addr);
634 for (i = 0; i < 128; i++) {
635 event_id = rom_log[i] >> 24;
636 switch (event_id) {
637 case 0x00: /* End of list */
638 return part;
639 /* Log entries with 1 parameter, skip 1 */
640 case 0x80: /* Start to perform the device initialization */
641 case 0x81: /* The boot device initialization completes */
642 case 0x8f: /* The boot device initialization fails */
643 case 0x90: /* Start to read data from boot device */
644 case 0x91: /* Reading data from boot device completes */
645 case 0x9f: /* Reading data from boot device fails */
646 i += 1;
647 continue;
648 /* Log entries with 2 parameters, skip 2 */
649 case 0xa0: /* Image authentication result */
650 case 0xc0: /* Jump to the boot image soon */
651 i += 2;
652 continue;
653 /* Boot from the secondary boot image */
654 case 0x51:
655 /*
656 * Swap the eMMC boot partitions in case there was a
657 * fallback event (i.e. primary image was corrupted
658 * and that corruption was recognized by the BootROM),
659 * so the SPL loads the rest of the U-Boot from the
660 * correct eMMC boot partition, since the BootROM
661 * leaves the boot partition set to the corrupted one.
662 */
663 if (part == 1)
664 part = 2;
665 else if (part == 2)
666 part = 1;
667 continue;
668 default:
669 continue;
670 }
671 }
672
673 return part;
674}
675#endif
676
Peng Faneae4de22018-01-10 13:20:37 +0800677bool is_usb_boot(void)
678{
679 return get_boot_device() == USB_BOOT;
680}
681
682#ifdef CONFIG_OF_SYSTEM_SETUP
Peng Fan435dc122020-07-09 14:06:49 +0800683bool check_fdt_new_path(void *blob)
684{
685 const char *soc_path = "/soc@0";
686 int nodeoff;
687
688 nodeoff = fdt_path_offset(blob, soc_path);
689 if (nodeoff < 0)
690 return false;
691
692 return true;
693}
694
695static int disable_fdt_nodes(void *blob, const char *const nodes_path[], int size_array)
696{
697 int i = 0;
698 int rc;
699 int nodeoff;
700 const char *status = "disabled";
701
702 for (i = 0; i < size_array; i++) {
703 nodeoff = fdt_path_offset(blob, nodes_path[i]);
704 if (nodeoff < 0)
705 continue; /* Not found, skip it */
706
707 printf("Found %s node\n", nodes_path[i]);
708
709add_status:
710 rc = fdt_setprop(blob, nodeoff, "status", status, strlen(status) + 1);
711 if (rc) {
712 if (rc == -FDT_ERR_NOSPACE) {
713 rc = fdt_increase_size(blob, 512);
714 if (!rc)
715 goto add_status;
716 }
717 printf("Unable to update property %s:%s, err=%s\n",
718 nodes_path[i], "status", fdt_strerror(rc));
719 } else {
720 printf("Modify %s:%s disabled\n",
721 nodes_path[i], "status");
722 }
723 }
724
725 return 0;
726}
727
728#ifdef CONFIG_IMX8MQ
729bool check_dcss_fused(void)
730{
731 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
732 struct fuse_bank *bank = &ocotp->bank[1];
733 struct fuse_bank1_regs *fuse =
734 (struct fuse_bank1_regs *)bank->fuse_regs;
735 u32 value = readl(&fuse->tester4);
736
737 if (value & 0x4000000)
738 return true;
739
740 return false;
741}
742
743static int disable_mipi_dsi_nodes(void *blob)
744{
745 static const char * const nodes_path[] = {
746 "/mipi_dsi@30A00000",
747 "/mipi_dsi_bridge@30A00000",
748 "/dsi_phy@30A00300",
749 "/soc@0/bus@30800000/mipi_dsi@30a00000",
Peng Fan7d4195c2021-03-19 15:57:13 +0800750 "/soc@0/bus@30800000/dphy@30a00300",
751 "/soc@0/bus@30800000/mipi-dsi@30a00000",
Peng Fan435dc122020-07-09 14:06:49 +0800752 };
753
754 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
755}
756
757static int disable_dcss_nodes(void *blob)
758{
759 static const char * const nodes_path[] = {
760 "/dcss@0x32e00000",
761 "/dcss@32e00000",
762 "/hdmi@32c00000",
763 "/hdmi_cec@32c33800",
764 "/hdmi_drm@32c00000",
765 "/display-subsystem",
766 "/sound-hdmi",
767 "/sound-hdmi-arc",
768 "/soc@0/bus@32c00000/display-controller@32e00000",
769 "/soc@0/bus@32c00000/hdmi@32c00000",
770 };
771
772 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
773}
774
775static int check_mipi_dsi_nodes(void *blob)
776{
777 static const char * const lcdif_path[] = {
778 "/lcdif@30320000",
Peng Fan7d4195c2021-03-19 15:57:13 +0800779 "/soc@0/bus@30000000/lcdif@30320000",
780 "/soc@0/bus@30000000/lcd-controller@30320000"
Peng Fan435dc122020-07-09 14:06:49 +0800781 };
782 static const char * const mipi_dsi_path[] = {
783 "/mipi_dsi@30A00000",
784 "/soc@0/bus@30800000/mipi_dsi@30a00000"
785 };
786 static const char * const lcdif_ep_path[] = {
787 "/lcdif@30320000/port@0/mipi-dsi-endpoint",
Peng Fan7d4195c2021-03-19 15:57:13 +0800788 "/soc@0/bus@30000000/lcdif@30320000/port@0/endpoint",
789 "/soc@0/bus@30000000/lcd-controller@30320000/port@0/endpoint"
Peng Fan435dc122020-07-09 14:06:49 +0800790 };
791 static const char * const mipi_dsi_ep_path[] = {
792 "/mipi_dsi@30A00000/port@1/endpoint",
Peng Fan7d4195c2021-03-19 15:57:13 +0800793 "/soc@0/bus@30800000/mipi_dsi@30a00000/ports/port@0/endpoint",
794 "/soc@0/bus@30800000/mipi-dsi@30a00000/ports/port@0/endpoint@0"
Peng Fan435dc122020-07-09 14:06:49 +0800795 };
796
797 int lookup_node;
798 int nodeoff;
799 bool new_path = check_fdt_new_path(blob);
800 int i = new_path ? 1 : 0;
801
802 nodeoff = fdt_path_offset(blob, lcdif_path[i]);
803 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) {
804 /*
805 * If can't find lcdif node or lcdif node is disabled,
806 * then disable all mipi dsi, since they only can input
807 * from DCSS
808 */
809 return disable_mipi_dsi_nodes(blob);
810 }
811
812 nodeoff = fdt_path_offset(blob, mipi_dsi_path[i]);
813 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff))
814 return 0;
815
816 nodeoff = fdt_path_offset(blob, lcdif_ep_path[i]);
817 if (nodeoff < 0) {
818 /*
819 * If can't find lcdif endpoint, then disable all mipi dsi,
820 * since they only can input from DCSS
821 */
822 return disable_mipi_dsi_nodes(blob);
823 }
824
825 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
826 nodeoff = fdt_path_offset(blob, mipi_dsi_ep_path[i]);
827
828 if (nodeoff > 0 && nodeoff == lookup_node)
829 return 0;
830
831 return disable_mipi_dsi_nodes(blob);
832}
833#endif
834
835int disable_vpu_nodes(void *blob)
836{
837 static const char * const nodes_path_8mq[] = {
838 "/vpu@38300000",
839 "/soc@0/vpu@38300000"
840 };
841
842 static const char * const nodes_path_8mm[] = {
843 "/vpu_g1@38300000",
844 "/vpu_g2@38310000",
845 "/vpu_h1@38320000"
846 };
847
848 static const char * const nodes_path_8mp[] = {
849 "/vpu_g1@38300000",
850 "/vpu_g2@38310000",
851 "/vpu_vc8000e@38320000"
852 };
853
854 if (is_imx8mq())
855 return disable_fdt_nodes(blob, nodes_path_8mq, ARRAY_SIZE(nodes_path_8mq));
856 else if (is_imx8mm())
857 return disable_fdt_nodes(blob, nodes_path_8mm, ARRAY_SIZE(nodes_path_8mm));
858 else if (is_imx8mp())
859 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
860 else
861 return -EPERM;
862}
863
Ye Liee337ce2021-03-19 15:57:09 +0800864#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
865static int low_drive_gpu_freq(void *blob)
866{
867 static const char *nodes_path_8mn[] = {
868 "/gpu@38000000",
869 "/soc@0/gpu@38000000"
870 };
871
872 int nodeoff, cnt, i;
873 u32 assignedclks[7];
874
875 nodeoff = fdt_path_offset(blob, nodes_path_8mn[0]);
876 if (nodeoff < 0)
877 return nodeoff;
878
879 cnt = fdtdec_get_int_array_count(blob, nodeoff, "assigned-clock-rates", assignedclks, 7);
880 if (cnt < 0)
881 return cnt;
882
883 if (cnt != 7)
884 printf("Warning: %s, assigned-clock-rates count %d\n", nodes_path_8mn[0], cnt);
885
886 assignedclks[cnt - 1] = 200000000;
887 assignedclks[cnt - 2] = 200000000;
888
889 for (i = 0; i < cnt; i++) {
890 debug("<%u>, ", assignedclks[i]);
891 assignedclks[i] = cpu_to_fdt32(assignedclks[i]);
892 }
893 debug("\n");
894
895 return fdt_setprop(blob, nodeoff, "assigned-clock-rates", &assignedclks, sizeof(assignedclks));
896}
897#endif
898
Peng Fanf5f9b8e2022-04-07 15:55:53 +0800899static bool check_remote_endpoint(void *blob, const char *ep1, const char *ep2)
900{
901 int lookup_node;
902 int nodeoff;
903
904 nodeoff = fdt_path_offset(blob, ep1);
905 if (nodeoff) {
906 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
907 nodeoff = fdt_path_offset(blob, ep2);
908
909 if (nodeoff > 0 && nodeoff == lookup_node)
910 return true;
911 }
912
913 return false;
914}
915
916int disable_dsi_lcdif_nodes(void *blob)
917{
918 int ret;
919
920 static const char * const dsi_path_8mp[] = {
921 "/soc@0/bus@32c00000/mipi_dsi@32e60000"
922 };
923
924 static const char * const lcdif_path_8mp[] = {
925 "/soc@0/bus@32c00000/lcd-controller@32e80000"
926 };
927
928 static const char * const lcdif_ep_path_8mp[] = {
929 "/soc@0/bus@32c00000/lcd-controller@32e80000/port@0/endpoint"
930 };
931 static const char * const dsi_ep_path_8mp[] = {
932 "/soc@0/bus@32c00000/mipi_dsi@32e60000/port@0/endpoint"
933 };
934
935 ret = disable_fdt_nodes(blob, dsi_path_8mp, ARRAY_SIZE(dsi_path_8mp));
936 if (ret)
937 return ret;
938
939 if (check_remote_endpoint(blob, dsi_ep_path_8mp[0], lcdif_ep_path_8mp[0])) {
940 /* Disable lcdif node */
941 return disable_fdt_nodes(blob, lcdif_path_8mp, ARRAY_SIZE(lcdif_path_8mp));
942 }
943
944 return 0;
945}
946
947int disable_lvds_lcdif_nodes(void *blob)
948{
949 int ret, i;
950
951 static const char * const ldb_path_8mp[] = {
952 "/soc@0/bus@32c00000/ldb@32ec005c",
953 "/soc@0/bus@32c00000/phy@32ec0128"
954 };
955
956 static const char * const lcdif_path_8mp[] = {
957 "/soc@0/bus@32c00000/lcd-controller@32e90000"
958 };
959
960 static const char * const lcdif_ep_path_8mp[] = {
961 "/soc@0/bus@32c00000/lcd-controller@32e90000/port@0/endpoint@0",
962 "/soc@0/bus@32c00000/lcd-controller@32e90000/port@0/endpoint@1"
963 };
964 static const char * const ldb_ep_path_8mp[] = {
965 "/soc@0/bus@32c00000/ldb@32ec005c/lvds-channel@0/port@0/endpoint",
966 "/soc@0/bus@32c00000/ldb@32ec005c/lvds-channel@1/port@0/endpoint"
967 };
968
969 ret = disable_fdt_nodes(blob, ldb_path_8mp, ARRAY_SIZE(ldb_path_8mp));
970 if (ret)
971 return ret;
972
973 for (i = 0; i < ARRAY_SIZE(ldb_ep_path_8mp); i++) {
974 if (check_remote_endpoint(blob, ldb_ep_path_8mp[i], lcdif_ep_path_8mp[i])) {
975 /* Disable lcdif node */
976 return disable_fdt_nodes(blob, lcdif_path_8mp, ARRAY_SIZE(lcdif_path_8mp));
977 }
978 }
979
980 return 0;
981}
982
Peng Fan435dc122020-07-09 14:06:49 +0800983int disable_gpu_nodes(void *blob)
984{
985 static const char * const nodes_path_8mn[] = {
Peng Fan7d4195c2021-03-19 15:57:13 +0800986 "/gpu@38000000",
987 "/soc@/gpu@38000000"
Peng Fan435dc122020-07-09 14:06:49 +0800988 };
989
Peng Fanf5f9b8e2022-04-07 15:55:53 +0800990 static const char * const nodes_path_8mp[] = {
991 "/gpu3d@38000000",
992 "/gpu2d@38008000"
993 };
994
995 if (is_imx8mp())
996 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
997 else
998 return disable_fdt_nodes(blob, nodes_path_8mn, ARRAY_SIZE(nodes_path_8mn));
Peng Fan435dc122020-07-09 14:06:49 +0800999}
1000
1001int disable_npu_nodes(void *blob)
1002{
1003 static const char * const nodes_path_8mp[] = {
1004 "/vipsi@38500000"
1005 };
1006
1007 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1008}
1009
1010int disable_isp_nodes(void *blob)
1011{
1012 static const char * const nodes_path_8mp[] = {
1013 "/soc@0/bus@32c00000/camera/isp@32e10000",
1014 "/soc@0/bus@32c00000/camera/isp@32e20000"
1015 };
1016
1017 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1018}
1019
1020int disable_dsp_nodes(void *blob)
1021{
1022 static const char * const nodes_path_8mp[] = {
1023 "/dsp@3b6e8000"
1024 };
1025
1026 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1027}
1028
Ye Li26517af2021-03-19 15:57:12 +08001029static void disable_thermal_cpu_nodes(void *blob, u32 disabled_cores)
1030{
1031 static const char * const thermal_path[] = {
1032 "/thermal-zones/cpu-thermal/cooling-maps/map0"
1033 };
1034
1035 int nodeoff, cnt, i, ret, j;
1036 u32 cooling_dev[12];
1037
1038 for (i = 0; i < ARRAY_SIZE(thermal_path); i++) {
1039 nodeoff = fdt_path_offset(blob, thermal_path[i]);
1040 if (nodeoff < 0)
1041 continue; /* Not found, skip it */
1042
1043 cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", cooling_dev, 12);
1044 if (cnt < 0)
1045 continue;
1046
1047 if (cnt != 12)
1048 printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt);
1049
1050 for (j = 0; j < cnt; j++)
1051 cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]);
1052
1053 ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev,
1054 sizeof(u32) * (12 - disabled_cores * 3));
1055 if (ret < 0) {
1056 printf("Warning: %s, cooling-device setprop failed %d\n",
1057 thermal_path[i], ret);
1058 continue;
1059 }
1060
1061 printf("Update node %s, cooling-device prop\n", thermal_path[i]);
1062 }
1063}
1064
1065static void disable_pmu_cpu_nodes(void *blob, u32 disabled_cores)
1066{
1067 static const char * const pmu_path[] = {
1068 "/pmu"
1069 };
1070
1071 int nodeoff, cnt, i, ret, j;
1072 u32 irq_affinity[4];
1073
1074 for (i = 0; i < ARRAY_SIZE(pmu_path); i++) {
1075 nodeoff = fdt_path_offset(blob, pmu_path[i]);
1076 if (nodeoff < 0)
1077 continue; /* Not found, skip it */
1078
1079 cnt = fdtdec_get_int_array_count(blob, nodeoff, "interrupt-affinity",
1080 irq_affinity, 4);
1081 if (cnt < 0)
1082 continue;
1083
1084 if (cnt != 4)
1085 printf("Warning: %s, interrupt-affinity count %d\n", pmu_path[i], cnt);
1086
1087 for (j = 0; j < cnt; j++)
1088 irq_affinity[j] = cpu_to_fdt32(irq_affinity[j]);
1089
1090 ret = fdt_setprop(blob, nodeoff, "interrupt-affinity", &irq_affinity,
1091 sizeof(u32) * (4 - disabled_cores));
1092 if (ret < 0) {
1093 printf("Warning: %s, interrupt-affinity setprop failed %d\n",
1094 pmu_path[i], ret);
1095 continue;
1096 }
1097
1098 printf("Update node %s, interrupt-affinity prop\n", pmu_path[i]);
1099 }
1100}
1101
Peng Fan435dc122020-07-09 14:06:49 +08001102static int disable_cpu_nodes(void *blob, u32 disabled_cores)
1103{
1104 static const char * const nodes_path[] = {
1105 "/cpus/cpu@1",
1106 "/cpus/cpu@2",
1107 "/cpus/cpu@3",
1108 };
1109 u32 i = 0;
1110 int rc;
1111 int nodeoff;
1112
1113 if (disabled_cores > 3)
1114 return -EINVAL;
1115
1116 i = 3 - disabled_cores;
1117
1118 for (; i < 3; i++) {
1119 nodeoff = fdt_path_offset(blob, nodes_path[i]);
1120 if (nodeoff < 0)
1121 continue; /* Not found, skip it */
1122
1123 debug("Found %s node\n", nodes_path[i]);
1124
1125 rc = fdt_del_node(blob, nodeoff);
1126 if (rc < 0) {
1127 printf("Unable to delete node %s, err=%s\n",
1128 nodes_path[i], fdt_strerror(rc));
1129 } else {
1130 printf("Delete node %s\n", nodes_path[i]);
1131 }
1132 }
1133
Ye Li26517af2021-03-19 15:57:12 +08001134 disable_thermal_cpu_nodes(blob, disabled_cores);
1135 disable_pmu_cpu_nodes(blob, disabled_cores);
1136
Peng Fan435dc122020-07-09 14:06:49 +08001137 return 0;
1138}
1139
Peng Fana08bc872022-04-07 15:55:54 +08001140static int cleanup_nodes_for_efi(void *blob)
1141{
Peng Fan1585b202022-04-07 15:55:55 +08001142 static const char * const path[][2] = {
1143 { "/soc@0/bus@32c00000/usb@32e40000", "extcon" },
1144 { "/soc@0/bus@32c00000/usb@32e50000", "extcon" },
1145 { "/soc@0/bus@30800000/ethernet@30be0000", "phy-reset-gpios" },
1146 { "/soc@0/bus@30800000/ethernet@30bf0000", "phy-reset-gpios" }
1147 };
Peng Fana08bc872022-04-07 15:55:54 +08001148 int nodeoff, i, rc;
1149
Peng Fan1585b202022-04-07 15:55:55 +08001150 for (i = 0; i < ARRAY_SIZE(path); i++) {
1151 nodeoff = fdt_path_offset(blob, path[i][0]);
Peng Fana08bc872022-04-07 15:55:54 +08001152 if (nodeoff < 0)
1153 continue; /* Not found, skip it */
Peng Fan1585b202022-04-07 15:55:55 +08001154 debug("Found %s node\n", path[i][0]);
Peng Fana08bc872022-04-07 15:55:54 +08001155
Peng Fan1585b202022-04-07 15:55:55 +08001156 rc = fdt_delprop(blob, nodeoff, path[i][1]);
Peng Fana08bc872022-04-07 15:55:54 +08001157 if (rc == -FDT_ERR_NOTFOUND)
1158 continue;
1159 if (rc) {
1160 printf("Unable to update property %s:%s, err=%s\n",
Peng Fan1585b202022-04-07 15:55:55 +08001161 path[i][0], path[i][1], fdt_strerror(rc));
Peng Fana08bc872022-04-07 15:55:54 +08001162 return rc;
1163 }
1164
Peng Fan1585b202022-04-07 15:55:55 +08001165 printf("Remove %s:%s\n", path[i][0], path[i][1]);
Peng Fana08bc872022-04-07 15:55:54 +08001166 }
1167
1168 return 0;
1169}
Peng Fana08bc872022-04-07 15:55:54 +08001170
Andrejs Cainikovs2f3491c2022-05-27 15:20:42 +02001171static int fixup_thermal_trips(void *blob, const char *name)
1172{
1173 int minc, maxc;
1174 int node, trip;
1175
1176 node = fdt_path_offset(blob, "/thermal-zones");
1177 if (node < 0)
1178 return node;
1179
1180 node = fdt_subnode_offset(blob, node, name);
1181 if (node < 0)
1182 return node;
1183
1184 node = fdt_subnode_offset(blob, node, "trips");
1185 if (node < 0)
1186 return node;
1187
1188 get_cpu_temp_grade(&minc, &maxc);
1189
1190 fdt_for_each_subnode(trip, blob, node) {
1191 const char *type;
1192 int temp, ret;
1193
1194 type = fdt_getprop(blob, trip, "type", NULL);
1195 if (!type)
1196 continue;
1197
1198 temp = 0;
1199 if (!strcmp(type, "critical"))
1200 temp = 1000 * maxc;
1201 else if (!strcmp(type, "passive"))
1202 temp = 1000 * (maxc - 10);
1203 if (temp) {
1204 ret = fdt_setprop_u32(blob, trip, "temperature", temp);
1205 if (ret)
1206 return ret;
1207 }
1208 }
1209
1210 return 0;
1211}
1212
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001213int ft_system_setup(void *blob, struct bd_info *bd)
Peng Faneae4de22018-01-10 13:20:37 +08001214{
Peng Fan435dc122020-07-09 14:06:49 +08001215#ifdef CONFIG_IMX8MQ
Peng Faneae4de22018-01-10 13:20:37 +08001216 int i = 0;
1217 int rc;
1218 int nodeoff;
1219
Peng Fan435dc122020-07-09 14:06:49 +08001220 if (get_boot_device() == USB_BOOT) {
1221 disable_dcss_nodes(blob);
1222
1223 bool new_path = check_fdt_new_path(blob);
1224 int v = new_path ? 1 : 0;
1225 static const char * const usb_dwc3_path[] = {
1226 "/usb@38100000/dwc3",
1227 "/soc@0/usb@38100000"
1228 };
1229
1230 nodeoff = fdt_path_offset(blob, usb_dwc3_path[v]);
1231 if (nodeoff >= 0) {
1232 const char *speed = "high-speed";
1233
1234 printf("Found %s node\n", usb_dwc3_path[v]);
1235
1236usb_modify_speed:
1237
1238 rc = fdt_setprop(blob, nodeoff, "maximum-speed", speed, strlen(speed) + 1);
1239 if (rc) {
1240 if (rc == -FDT_ERR_NOSPACE) {
1241 rc = fdt_increase_size(blob, 512);
1242 if (!rc)
1243 goto usb_modify_speed;
1244 }
1245 printf("Unable to set property %s:%s, err=%s\n",
1246 usb_dwc3_path[v], "maximum-speed", fdt_strerror(rc));
1247 } else {
1248 printf("Modify %s:%s = %s\n",
1249 usb_dwc3_path[v], "maximum-speed", speed);
1250 }
1251 } else {
1252 printf("Can't found %s node\n", usb_dwc3_path[v]);
1253 }
1254 }
1255
Peng Faneae4de22018-01-10 13:20:37 +08001256 /* Disable the CPU idle for A0 chip since the HW does not support it */
1257 if (is_soc_rev(CHIP_REV_1_0)) {
1258 static const char * const nodes_path[] = {
1259 "/cpus/cpu@0",
1260 "/cpus/cpu@1",
1261 "/cpus/cpu@2",
1262 "/cpus/cpu@3",
1263 };
1264
1265 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
1266 nodeoff = fdt_path_offset(blob, nodes_path[i]);
1267 if (nodeoff < 0)
1268 continue; /* Not found, skip it */
1269
Marek Vasute2e7a772020-04-24 21:37:33 +02001270 debug("Found %s node\n", nodes_path[i]);
Peng Faneae4de22018-01-10 13:20:37 +08001271
1272 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
Marek Vasute2e7a772020-04-24 21:37:33 +02001273 if (rc == -FDT_ERR_NOTFOUND)
1274 continue;
Peng Faneae4de22018-01-10 13:20:37 +08001275 if (rc) {
1276 printf("Unable to update property %s:%s, err=%s\n",
1277 nodes_path[i], "status", fdt_strerror(rc));
1278 return rc;
1279 }
1280
Marek Vasute2e7a772020-04-24 21:37:33 +02001281 debug("Remove %s:%s\n", nodes_path[i],
Peng Faneae4de22018-01-10 13:20:37 +08001282 "cpu-idle-states");
1283 }
1284 }
1285
Peng Fan435dc122020-07-09 14:06:49 +08001286 if (is_imx8mql()) {
1287 disable_vpu_nodes(blob);
1288 if (check_dcss_fused()) {
1289 printf("DCSS is fused\n");
1290 disable_dcss_nodes(blob);
1291 check_mipi_dsi_nodes(blob);
1292 }
1293 }
1294
1295 if (is_imx8md())
1296 disable_cpu_nodes(blob, 2);
1297
1298#elif defined(CONFIG_IMX8MM)
1299 if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl())
1300 disable_vpu_nodes(blob);
1301
1302 if (is_imx8mmd() || is_imx8mmdl())
1303 disable_cpu_nodes(blob, 2);
1304 else if (is_imx8mms() || is_imx8mmsl())
1305 disable_cpu_nodes(blob, 3);
1306
1307#elif defined(CONFIG_IMX8MN)
1308 if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl())
1309 disable_gpu_nodes(blob);
Ye Liee337ce2021-03-19 15:57:09 +08001310#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
1311 else {
1312 int ldm_gpu = low_drive_gpu_freq(blob);
1313
1314 if (ldm_gpu < 0)
1315 printf("Update GPU node assigned-clock-rates failed\n");
1316 else
1317 printf("Update GPU node assigned-clock-rates ok\n");
1318 }
1319#endif
Peng Fan435dc122020-07-09 14:06:49 +08001320
Ye Li715180e2021-03-19 15:57:11 +08001321 if (is_imx8mnd() || is_imx8mndl() || is_imx8mnud())
Peng Fan435dc122020-07-09 14:06:49 +08001322 disable_cpu_nodes(blob, 2);
Ye Li715180e2021-03-19 15:57:11 +08001323 else if (is_imx8mns() || is_imx8mnsl() || is_imx8mnus())
Peng Fan435dc122020-07-09 14:06:49 +08001324 disable_cpu_nodes(blob, 3);
1325
1326#elif defined(CONFIG_IMX8MP)
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001327 if (is_imx8mpul()) {
1328 /* Disable GPU */
1329 disable_gpu_nodes(blob);
1330
1331 /* Disable DSI */
1332 disable_dsi_lcdif_nodes(blob);
1333
1334 /* Disable LVDS */
1335 disable_lvds_lcdif_nodes(blob);
1336 }
1337
1338 if (is_imx8mpul() || is_imx8mpl())
Peng Fan435dc122020-07-09 14:06:49 +08001339 disable_vpu_nodes(blob);
1340
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001341 if (is_imx8mpul() || is_imx8mpl() || is_imx8mp6())
Peng Fan435dc122020-07-09 14:06:49 +08001342 disable_npu_nodes(blob);
1343
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001344 if (is_imx8mpul() || is_imx8mpl())
Peng Fan435dc122020-07-09 14:06:49 +08001345 disable_isp_nodes(blob);
1346
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001347 if (is_imx8mpul() || is_imx8mpl() || is_imx8mp6())
Peng Fan435dc122020-07-09 14:06:49 +08001348 disable_dsp_nodes(blob);
1349
1350 if (is_imx8mpd())
1351 disable_cpu_nodes(blob, 2);
1352#endif
1353
Peng Fan1585b202022-04-07 15:55:55 +08001354 cleanup_nodes_for_efi(blob);
Andrejs Cainikovs2f3491c2022-05-27 15:20:42 +02001355
1356 if (fixup_thermal_trips(blob, "cpu-thermal"))
1357 printf("Failed to update cpu-thermal trip(s)");
1358 if (IS_ENABLED(CONFIG_IMX8MP) &&
1359 fixup_thermal_trips(blob, "soc-thermal"))
1360 printf("Failed to update soc-thermal trip(s)");
1361
Peng Faneae4de22018-01-10 13:20:37 +08001362 return 0;
1363}
1364#endif
1365
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001366#ifdef CONFIG_OF_BOARD_FIXUP
1367#ifndef CONFIG_SPL_BUILD
1368int board_fix_fdt(void *fdt)
1369{
1370 if (is_imx8mpul()) {
1371 int i = 0;
1372 int nodeoff, ret;
1373 const char *status = "disabled";
1374 static const char * const dsi_nodes[] = {
1375 "/soc@0/bus@32c00000/mipi_dsi@32e60000",
1376 "/soc@0/bus@32c00000/lcd-controller@32e80000",
1377 "/dsi-host"
1378 };
1379
1380 for (i = 0; i < ARRAY_SIZE(dsi_nodes); i++) {
1381 nodeoff = fdt_path_offset(fdt, dsi_nodes[i]);
1382 if (nodeoff > 0) {
1383set_status:
1384 ret = fdt_setprop(fdt, nodeoff, "status", status,
1385 strlen(status) + 1);
1386 if (ret == -FDT_ERR_NOSPACE) {
1387 ret = fdt_increase_size(fdt, 512);
1388 if (!ret)
1389 goto set_status;
1390 }
1391 }
1392 }
1393 }
1394
1395 return 0;
1396}
1397#endif
1398#endif
1399
Marek Vasut64dc4de2020-04-29 15:04:21 +02001400#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler6f14d5f2020-12-15 16:47:52 +01001401void reset_cpu(void)
Peng Faneae4de22018-01-10 13:20:37 +08001402{
Claudius Heinee73f3942020-04-29 15:04:23 +02001403 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
Peng Faneae4de22018-01-10 13:20:37 +08001404
Ye Li54a915a2019-12-09 00:47:18 -08001405 /* Clear WDA to trigger WDOG_B immediately */
1406 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
Peng Fan24290d92019-08-27 06:25:41 +00001407
Ye Li54a915a2019-12-09 00:47:18 -08001408 while (1) {
1409 /*
Harald Seilerec0c4472020-04-29 15:04:22 +02001410 * spin for .5 seconds before reset
Ye Li54a915a2019-12-09 00:47:18 -08001411 */
1412 }
Peng Faneae4de22018-01-10 13:20:37 +08001413}
Peng Fan24290d92019-08-27 06:25:41 +00001414#endif
Peng Fan5760d8d2020-04-22 10:51:13 +08001415
1416#if defined(CONFIG_ARCH_MISC_INIT)
Peng Fan5760d8d2020-04-22 10:51:13 +08001417int arch_misc_init(void)
1418{
Gaurav Jain81113a02022-03-24 11:50:27 +05301419 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
1420 struct udevice *dev;
1421 int ret;
1422
1423 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
1424 if (ret)
Ye Liec346892022-05-11 13:56:20 +05301425 printf("Failed to initialize caam_jr: %d\n", ret);
Gaurav Jain81113a02022-03-24 11:50:27 +05301426 }
Peng Fan5760d8d2020-04-22 10:51:13 +08001427
1428 return 0;
1429}
1430#endif
Ye Li325cd012020-05-03 22:19:52 +08001431
1432void imx_tmu_arch_init(void *reg_base)
1433{
Ye Lia00f2f02020-05-03 22:19:53 +08001434 if (is_imx8mm() || is_imx8mn()) {
Ye Li325cd012020-05-03 22:19:52 +08001435 /* Load TCALIV and TASR from fuses */
1436 struct ocotp_regs *ocotp =
1437 (struct ocotp_regs *)OCOTP_BASE_ADDR;
1438 struct fuse_bank *bank = &ocotp->bank[3];
1439 struct fuse_bank3_regs *fuse =
1440 (struct fuse_bank3_regs *)bank->fuse_regs;
1441
1442 u32 tca_rt, tca_hr, tca_en;
1443 u32 buf_vref, buf_slope;
1444
1445 tca_rt = fuse->ana0 & 0xFF;
1446 tca_hr = (fuse->ana0 & 0xFF00) >> 8;
1447 tca_en = (fuse->ana0 & 0x2000000) >> 25;
1448
1449 buf_vref = (fuse->ana0 & 0x1F00000) >> 20;
1450 buf_slope = (fuse->ana0 & 0xF0000) >> 16;
1451
1452 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
1453 writel((tca_en << 31) | (tca_hr << 16) | tca_rt,
1454 (ulong)reg_base + 0x30);
1455 }
Ye Li41a20252020-05-03 22:19:54 +08001456#ifdef CONFIG_IMX8MP
1457 /* Load TCALIV0/1/m40 and TRIM from fuses */
1458 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
1459 struct fuse_bank *bank = &ocotp->bank[38];
1460 struct fuse_bank38_regs *fuse =
1461 (struct fuse_bank38_regs *)bank->fuse_regs;
1462 struct fuse_bank *bank2 = &ocotp->bank[39];
1463 struct fuse_bank39_regs *fuse2 =
1464 (struct fuse_bank39_regs *)bank2->fuse_regs;
1465 u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr;
1466 u32 reg;
1467 u32 tca40[2], tca25[2], tca105[2];
1468
1469 /* For blank sample */
1470 if (!fuse->ana_trim2 && !fuse->ana_trim3 &&
1471 !fuse->ana_trim4 && !fuse2->ana_trim5) {
1472 /* Use a default 25C binary codes */
1473 tca25[0] = 1596;
Ye Lid756ca02020-05-03 22:19:55 +08001474 tca25[1] = 1596;
Ye Li41a20252020-05-03 22:19:54 +08001475 writel(tca25[0], (ulong)reg_base + 0x30);
Ye Lid756ca02020-05-03 22:19:55 +08001476 writel(tca25[1], (ulong)reg_base + 0x34);
Ye Li41a20252020-05-03 22:19:54 +08001477 return;
1478 }
1479
1480 buf_vref = (fuse->ana_trim2 & 0xc0) >> 6;
1481 buf_slope = (fuse->ana_trim2 & 0xF00) >> 8;
1482 bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12;
1483 bgr = (fuse->ana_trim2 & 0xF0000) >> 16;
1484 vlsb = (fuse->ana_trim2 & 0xF00000) >> 20;
1485 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
1486
1487 reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7);
1488 writel(reg, (ulong)reg_base + 0x3c);
1489
1490 tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16;
1491 tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28;
1492 tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4);
1493 tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8;
1494 tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20;
1495 tca25[1] = fuse2->ana_trim5 & 0xFFF;
1496 tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12;
1497
1498 /* use 25c for 1p calibration */
1499 writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30);
1500 writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34);
1501 writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38);
1502#endif
Ye Li325cd012020-05-03 22:19:52 +08001503}
Peng Fana35215d2020-07-09 13:39:26 +08001504
1505#if defined(CONFIG_SPL_BUILD)
1506#if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
1507bool serror_need_skip = true;
1508
Sean Anderson2d755492022-03-22 17:17:35 -04001509void do_error(struct pt_regs *pt_regs)
Peng Fana35215d2020-07-09 13:39:26 +08001510{
1511 /*
1512 * If stack is still in ROM reserved OCRAM not switch to SPL,
1513 * it is the ROM SError
1514 */
1515 ulong sp;
1516
1517 asm volatile("mov %0, sp" : "=r"(sp) : );
1518
1519 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
1520 /* Check for ERR050342, imx8mq HDCP enabled parts */
1521 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
1522 serror_need_skip = false;
1523 return; /* Do nothing skip the SError in ROM */
1524 }
1525
1526 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
1527 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
1528 serror_need_skip = false;
1529 return; /* Do nothing skip the SError in ROM */
1530 }
1531 }
1532
1533 efi_restore_gd();
Sean Anderson2d755492022-03-22 17:17:35 -04001534 printf("\"Error\" handler, esr 0x%08lx\n", pt_regs->esr);
Peng Fana35215d2020-07-09 13:39:26 +08001535 show_regs(pt_regs);
1536 panic("Resetting CPU ...\n");
1537}
1538#endif
1539#endif
Ye Li0513f362019-07-15 01:16:46 -07001540
1541#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
Marek Vasut765b5802022-04-06 02:21:34 +02001542enum env_location arch_env_get_location(enum env_operation op, int prio)
Ye Li0513f362019-07-15 01:16:46 -07001543{
1544 enum boot_device dev = get_boot_device();
Ye Li0513f362019-07-15 01:16:46 -07001545
1546 if (prio)
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001547 return ENVL_UNKNOWN;
Ye Li0513f362019-07-15 01:16:46 -07001548
1549 switch (dev) {
Fabio Estevam9be6daf2022-04-21 15:05:23 -03001550 case USB_BOOT:
1551 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
1552 return ENVL_SPI_FLASH;
1553 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
1554 return ENVL_NAND;
1555 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
1556 return ENVL_MMC;
1557 if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
1558 return ENVL_NOWHERE;
1559 return ENVL_UNKNOWN;
Ye Li0513f362019-07-15 01:16:46 -07001560 case QSPI_BOOT:
Marek Vasut31b3bc42022-03-25 18:59:28 +01001561 case SPI_NOR_BOOT:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001562 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
1563 return ENVL_SPI_FLASH;
1564 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001565 case NAND_BOOT:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001566 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
1567 return ENVL_NAND;
1568 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001569 case SD1_BOOT:
1570 case SD2_BOOT:
1571 case SD3_BOOT:
1572 case MMC1_BOOT:
1573 case MMC2_BOOT:
1574 case MMC3_BOOT:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001575 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
1576 return ENVL_MMC;
1577 else if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
1578 return ENVL_EXT4;
1579 else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
1580 return ENVL_FAT;
1581 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001582 default:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001583 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001584 }
Ye Li0513f362019-07-15 01:16:46 -07001585}
1586
Ye Li0513f362019-07-15 01:16:46 -07001587#endif
Peng Fanf19e0e52022-04-29 16:03:14 +08001588
1589#ifdef CONFIG_IMX_BOOTAUX
1590const struct rproc_att hostmap[] = {
1591 /* aux core , host core, size */
1592 { 0x00000000, 0x007e0000, 0x00020000 },
1593 /* OCRAM_S */
1594 { 0x00180000, 0x00180000, 0x00008000 },
1595 /* OCRAM */
1596 { 0x00900000, 0x00900000, 0x00020000 },
1597 /* OCRAM */
1598 { 0x00920000, 0x00920000, 0x00020000 },
1599 /* QSPI Code - alias */
1600 { 0x08000000, 0x08000000, 0x08000000 },
1601 /* DDR (Code) - alias */
1602 { 0x10000000, 0x80000000, 0x0FFE0000 },
1603 /* TCML */
1604 { 0x1FFE0000, 0x007E0000, 0x00040000 },
1605 /* OCRAM_S */
1606 { 0x20180000, 0x00180000, 0x00008000 },
1607 /* OCRAM */
1608 { 0x20200000, 0x00900000, 0x00040000 },
1609 /* DDR (Data) */
1610 { 0x40000000, 0x40000000, 0x80000000 },
1611 { /* sentinel */ }
1612};
1613#endif