blob: cad9200dd1eef9f515f44d2811723e52a8c58f5c [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
Marek Vasut003969b2022-12-22 01:46:40 +0100103#ifdef CONFIG_ARMV8_PSCI
104#define PTE_MAP_NS PTE_BLOCK_NS
105#else
106#define PTE_MAP_NS 0
107#endif
108
Peng Faneae4de22018-01-10 13:20:37 +0800109static struct mm_region imx8m_mem_map[] = {
110 {
111 /* ROM */
112 .virt = 0x0UL,
113 .phys = 0x0UL,
114 .size = 0x100000UL,
115 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
116 PTE_BLOCK_OUTER_SHARE
117 }, {
Gary Bisson5c72a452018-11-14 17:55:28 +0100118 /* CAAM */
119 .virt = 0x100000UL,
120 .phys = 0x100000UL,
121 .size = 0x8000UL,
122 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
123 PTE_BLOCK_NON_SHARE |
124 PTE_BLOCK_PXN | PTE_BLOCK_UXN
125 }, {
Marek Vasutb1738e02021-02-25 21:52:26 +0100126 /* OCRAM_S */
127 .virt = 0x180000UL,
128 .phys = 0x180000UL,
129 .size = 0x8000UL,
130 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
Marek Vasut003969b2022-12-22 01:46:40 +0100131 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
Marek Vasutb1738e02021-02-25 21:52:26 +0100132 }, {
Gary Bisson5c72a452018-11-14 17:55:28 +0100133 /* TCM */
134 .virt = 0x7C0000UL,
135 .phys = 0x7C0000UL,
136 .size = 0x80000UL,
137 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
138 PTE_BLOCK_NON_SHARE |
Marek Vasut003969b2022-12-22 01:46:40 +0100139 PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_MAP_NS
Gary Bisson5c72a452018-11-14 17:55:28 +0100140 }, {
Peng Faneae4de22018-01-10 13:20:37 +0800141 /* OCRAM */
142 .virt = 0x900000UL,
143 .phys = 0x900000UL,
144 .size = 0x200000UL,
145 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
Marek Vasut003969b2022-12-22 01:46:40 +0100146 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
Peng Faneae4de22018-01-10 13:20:37 +0800147 }, {
148 /* AIPS */
149 .virt = 0xB00000UL,
150 .phys = 0xB00000UL,
151 .size = 0x3f500000UL,
152 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
153 PTE_BLOCK_NON_SHARE |
154 PTE_BLOCK_PXN | PTE_BLOCK_UXN
155 }, {
156 /* DRAM1 */
157 .virt = 0x40000000UL,
158 .phys = 0x40000000UL,
Peng Fanb749b5e2019-08-27 06:25:27 +0000159 .size = PHYS_SDRAM_SIZE,
Peng Faneae4de22018-01-10 13:20:37 +0800160 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
Marek Vasut003969b2022-12-22 01:46:40 +0100161 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
Peng Fanb749b5e2019-08-27 06:25:27 +0000162#ifdef PHYS_SDRAM_2_SIZE
Peng Faneae4de22018-01-10 13:20:37 +0800163 }, {
164 /* DRAM2 */
165 .virt = 0x100000000UL,
166 .phys = 0x100000000UL,
Peng Fanb749b5e2019-08-27 06:25:27 +0000167 .size = PHYS_SDRAM_2_SIZE,
Peng Faneae4de22018-01-10 13:20:37 +0800168 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
Marek Vasut003969b2022-12-22 01:46:40 +0100169 PTE_BLOCK_OUTER_SHARE | PTE_MAP_NS
Peng Fanb749b5e2019-08-27 06:25:27 +0000170#endif
Peng Faneae4de22018-01-10 13:20:37 +0800171 }, {
Peng Fanfa35c3d2020-07-09 15:26:06 +0800172 /* empty entrie to split table entry 5 if needed when TEEs are used */
173 0,
174 }, {
Peng Faneae4de22018-01-10 13:20:37 +0800175 /* List terminator */
176 0,
177 }
178};
179
180struct mm_region *mem_map = imx8m_mem_map;
181
Marek Vasute48aac02021-02-27 14:59:00 +0100182static unsigned int imx8m_find_dram_entry_in_mem_map(void)
183{
184 int i;
185
186 for (i = 0; i < ARRAY_SIZE(imx8m_mem_map); i++)
Tom Rinibb4dd962022-11-16 13:10:37 -0500187 if (imx8m_mem_map[i].phys == CFG_SYS_SDRAM_BASE)
Marek Vasute48aac02021-02-27 14:59:00 +0100188 return i;
189
190 hang(); /* Entry not found, this must never happen. */
191}
192
Peng Fanb749b5e2019-08-27 06:25:27 +0000193void enable_caches(void)
194{
Ye Li453bfcb2022-04-07 15:55:56 +0800195 /* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch
196 * If OPTEE does not run, still update the MMU table according to dram banks structure
197 * to set correct dram size from board_phys_sdram_size
198 */
199 int i = 0;
200 /*
201 * please make sure that entry initial value matches
202 * imx8m_mem_map for DRAM1
203 */
204 int entry = imx8m_find_dram_entry_in_mem_map();
205 u64 attrs = imx8m_mem_map[entry].attrs;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800206
Ye Li453bfcb2022-04-07 15:55:56 +0800207 while (i < CONFIG_NR_DRAM_BANKS &&
208 entry < ARRAY_SIZE(imx8m_mem_map)) {
209 if (gd->bd->bi_dram[i].start == 0)
210 break;
211 imx8m_mem_map[entry].phys = gd->bd->bi_dram[i].start;
212 imx8m_mem_map[entry].virt = gd->bd->bi_dram[i].start;
213 imx8m_mem_map[entry].size = gd->bd->bi_dram[i].size;
214 imx8m_mem_map[entry].attrs = attrs;
215 debug("Added memory mapping (%d): %llx %llx\n", entry,
216 imx8m_mem_map[entry].phys, imx8m_mem_map[entry].size);
217 i++; entry++;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800218 }
Peng Fanb749b5e2019-08-27 06:25:27 +0000219
220 icache_enable();
221 dcache_enable();
222}
223
Peng Fanfa35c3d2020-07-09 15:26:06 +0800224__weak int board_phys_sdram_size(phys_size_t *size)
225{
226 if (!size)
227 return -EINVAL;
228
229 *size = PHYS_SDRAM_SIZE;
Ye Li453bfcb2022-04-07 15:55:56 +0800230
231#ifdef PHYS_SDRAM_2_SIZE
232 *size += PHYS_SDRAM_2_SIZE;
233#endif
Peng Fanfa35c3d2020-07-09 15:26:06 +0800234 return 0;
235}
236
237int dram_init(void)
238{
239 phys_size_t sdram_size;
240 int ret;
241
242 ret = board_phys_sdram_size(&sdram_size);
243 if (ret)
244 return ret;
245
246 /* rom_pointer[1] contains the size of TEE occupies */
Marek Vasut9ca966e2022-12-22 01:46:38 +0100247 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[1])
Peng Fanfa35c3d2020-07-09 15:26:06 +0800248 gd->ram_size = sdram_size - rom_pointer[1];
249 else
250 gd->ram_size = sdram_size;
251
Peng Fanfa35c3d2020-07-09 15:26:06 +0800252 return 0;
253}
254
255int dram_init_banksize(void)
256{
257 int bank = 0;
258 int ret;
259 phys_size_t sdram_size;
Ye Li453bfcb2022-04-07 15:55:56 +0800260 phys_size_t sdram_b1_size, sdram_b2_size;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800261
262 ret = board_phys_sdram_size(&sdram_size);
263 if (ret)
264 return ret;
265
Ye Li453bfcb2022-04-07 15:55:56 +0800266 /* Bank 1 can't cross over 4GB space */
267 if (sdram_size > 0xc0000000) {
268 sdram_b1_size = 0xc0000000;
269 sdram_b2_size = sdram_size - 0xc0000000;
270 } else {
271 sdram_b1_size = sdram_size;
272 sdram_b2_size = 0;
273 }
274
Peng Fanfa35c3d2020-07-09 15:26:06 +0800275 gd->bd->bi_dram[bank].start = PHYS_SDRAM;
Marek Vasut9ca966e2022-12-22 01:46:38 +0100276 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[1]) {
Peng Fanfa35c3d2020-07-09 15:26:06 +0800277 phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
278 phys_size_t optee_size = (size_t)rom_pointer[1];
279
280 gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start;
Ye Li453bfcb2022-04-07 15:55:56 +0800281 if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_b1_size)) {
Peng Fanfa35c3d2020-07-09 15:26:06 +0800282 if (++bank >= CONFIG_NR_DRAM_BANKS) {
283 puts("CONFIG_NR_DRAM_BANKS is not enough\n");
284 return -1;
285 }
286
287 gd->bd->bi_dram[bank].start = optee_start + optee_size;
288 gd->bd->bi_dram[bank].size = PHYS_SDRAM +
Ye Li453bfcb2022-04-07 15:55:56 +0800289 sdram_b1_size - gd->bd->bi_dram[bank].start;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800290 }
291 } else {
Ye Li453bfcb2022-04-07 15:55:56 +0800292 gd->bd->bi_dram[bank].size = sdram_b1_size;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800293 }
294
Ye Li453bfcb2022-04-07 15:55:56 +0800295 if (sdram_b2_size) {
296 if (++bank >= CONFIG_NR_DRAM_BANKS) {
297 puts("CONFIG_NR_DRAM_BANKS is not enough for SDRAM_2\n");
298 return -1;
299 }
300 gd->bd->bi_dram[bank].start = 0x100000000UL;
301 gd->bd->bi_dram[bank].size = sdram_b2_size;
Peng Fanfa35c3d2020-07-09 15:26:06 +0800302 }
Peng Fanfa35c3d2020-07-09 15:26:06 +0800303
304 return 0;
305}
306
307phys_size_t get_effective_memsize(void)
308{
Ye Li453bfcb2022-04-07 15:55:56 +0800309 int ret;
310 phys_size_t sdram_size;
311 phys_size_t sdram_b1_size;
312 ret = board_phys_sdram_size(&sdram_size);
313 if (!ret) {
314 /* Bank 1 can't cross over 4GB space */
315 if (sdram_size > 0xc0000000) {
316 sdram_b1_size = 0xc0000000;
317 } else {
318 sdram_b1_size = sdram_size;
319 }
Peng Fanfa35c3d2020-07-09 15:26:06 +0800320
Marek Vasut9ca966e2022-12-22 01:46:38 +0100321 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[1]) {
Ye Li453bfcb2022-04-07 15:55:56 +0800322 /* We will relocate u-boot to Top of dram1. Tee position has two cases:
323 * 1. At the top of dram1, Then return the size removed optee size.
324 * 2. In the middle of dram1, return the size of dram1.
325 */
326 if ((rom_pointer[0] + rom_pointer[1]) == (PHYS_SDRAM + sdram_b1_size))
327 return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM);
328 }
329
330 return sdram_b1_size;
331 } else {
332 return PHYS_SDRAM_SIZE;
333 }
Peng Fanfa35c3d2020-07-09 15:26:06 +0800334}
335
Pali Rohár4f4f5832022-09-09 17:32:40 +0200336phys_size_t board_get_usable_ram_top(phys_size_t total_size)
Frieder Schrempf159879e2021-06-07 14:36:44 +0200337{
Marek Vasutdcbbf782022-04-14 15:51:46 +0200338 ulong top_addr;
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800339
Frieder Schrempf159879e2021-06-07 14:36:44 +0200340 /*
341 * Some IPs have their accessible address space restricted by
342 * the interconnect. Let's make sure U-Boot only ever uses the
343 * space below the 4G address boundary (which is 3GiB big),
344 * even when the effective available memory is bigger.
345 */
Marek Vasutdcbbf782022-04-14 15:51:46 +0200346 top_addr = clamp_val((u64)PHYS_SDRAM + gd->ram_size, 0, 0xffffffff);
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800347
348 /*
349 * rom_pointer[0] stores the TEE memory start address.
350 * rom_pointer[1] stores the size TEE uses.
351 * We need to reserve the memory region for TEE.
352 */
Marek Vasut9ca966e2022-12-22 01:46:38 +0100353 if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[0] &&
354 rom_pointer[1] && top_addr > rom_pointer[0])
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800355 top_addr = rom_pointer[0];
Frieder Schrempf159879e2021-06-07 14:36:44 +0200356
Ying-Chun Liu (PaulLiu)ed55caf2021-08-23 10:43:06 +0800357 return top_addr;
Frieder Schrempf159879e2021-06-07 14:36:44 +0200358}
359
Peng Fan1caffdf2019-08-27 06:25:17 +0000360static u32 get_cpu_variant_type(u32 type)
361{
362 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
363 struct fuse_bank *bank = &ocotp->bank[1];
364 struct fuse_bank1_regs *fuse =
365 (struct fuse_bank1_regs *)bank->fuse_regs;
366
367 u32 value = readl(&fuse->tester4);
368
Peng Fan67815082020-02-05 17:34:54 +0800369 if (type == MXC_CPU_IMX8MQ) {
370 if ((value & 0x3) == 0x2)
371 return MXC_CPU_IMX8MD;
372 else if (value & 0x200000)
373 return MXC_CPU_IMX8MQL;
374
375 } else if (type == MXC_CPU_IMX8MM) {
Peng Fan1caffdf2019-08-27 06:25:17 +0000376 switch (value & 0x3) {
377 case 2:
378 if (value & 0x1c0000)
379 return MXC_CPU_IMX8MMDL;
380 else
381 return MXC_CPU_IMX8MMD;
382 case 3:
383 if (value & 0x1c0000)
384 return MXC_CPU_IMX8MMSL;
385 else
386 return MXC_CPU_IMX8MMS;
387 default:
388 if (value & 0x1c0000)
389 return MXC_CPU_IMX8MML;
390 break;
391 }
Peng Fan1a07d912020-02-05 17:39:27 +0800392 } else if (type == MXC_CPU_IMX8MN) {
393 switch (value & 0x3) {
394 case 2:
Ye Li715180e2021-03-19 15:57:11 +0800395 if (value & 0x1000000) {
396 if (value & 0x10000000) /* MIPI DSI */
397 return MXC_CPU_IMX8MNUD;
398 else
399 return MXC_CPU_IMX8MNDL;
400 } else {
Peng Fan1a07d912020-02-05 17:39:27 +0800401 return MXC_CPU_IMX8MND;
Ye Li715180e2021-03-19 15:57:11 +0800402 }
Peng Fan1a07d912020-02-05 17:39:27 +0800403 case 3:
Ye Li715180e2021-03-19 15:57:11 +0800404 if (value & 0x1000000) {
405 if (value & 0x10000000) /* MIPI DSI */
406 return MXC_CPU_IMX8MNUS;
407 else
408 return MXC_CPU_IMX8MNSL;
409 } else {
Peng Fan1a07d912020-02-05 17:39:27 +0800410 return MXC_CPU_IMX8MNS;
Ye Li715180e2021-03-19 15:57:11 +0800411 }
Peng Fan1a07d912020-02-05 17:39:27 +0800412 default:
Ye Li715180e2021-03-19 15:57:11 +0800413 if (value & 0x1000000) {
414 if (value & 0x10000000) /* MIPI DSI */
415 return MXC_CPU_IMX8MNUQ;
416 else
417 return MXC_CPU_IMX8MNL;
418 }
Peng Fan1a07d912020-02-05 17:39:27 +0800419 break;
420 }
Ye Lid2d754f2020-04-20 20:12:54 -0700421 } else if (type == MXC_CPU_IMX8MP) {
422 u32 value0 = readl(&fuse->tester3);
423 u32 flag = 0;
424
425 if ((value0 & 0xc0000) == 0x80000)
426 return MXC_CPU_IMX8MPD;
427
428 /* vpu disabled */
429 if ((value0 & 0x43000000) == 0x43000000)
430 flag = 1;
431
432 /* npu disabled*/
433 if ((value & 0x8) == 0x8)
Peng Fan0386e7f2022-04-07 15:55:52 +0800434 flag |= BIT(1);
Ye Lid2d754f2020-04-20 20:12:54 -0700435
436 /* isp disabled */
437 if ((value & 0x3) == 0x3)
Peng Fan0386e7f2022-04-07 15:55:52 +0800438 flag |= BIT(2);
439
440 /* gpu disabled */
441 if ((value & 0xc0) == 0xc0)
442 flag |= BIT(3);
443
444 /* lvds disabled */
445 if ((value & 0x180000) == 0x180000)
446 flag |= BIT(4);
447
448 /* mipi dsi disabled */
449 if ((value & 0x60000) == 0x60000)
450 flag |= BIT(5);
Ye Lid2d754f2020-04-20 20:12:54 -0700451
452 switch (flag) {
Peng Fan0386e7f2022-04-07 15:55:52 +0800453 case 0x3f:
454 return MXC_CPU_IMX8MPUL;
Ye Lid2d754f2020-04-20 20:12:54 -0700455 case 7:
456 return MXC_CPU_IMX8MPL;
Ye Lid2d754f2020-04-20 20:12:54 -0700457 case 2:
458 return MXC_CPU_IMX8MP6;
Ye Lid2d754f2020-04-20 20:12:54 -0700459 default:
460 break;
461 }
462
Peng Fan1caffdf2019-08-27 06:25:17 +0000463 }
464
465 return type;
466}
467
Peng Faneae4de22018-01-10 13:20:37 +0800468u32 get_cpu_rev(void)
469{
470 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
471 u32 reg = readl(&ana_pll->digprog);
472 u32 type = (reg >> 16) & 0xff;
Peng Fan1caffdf2019-08-27 06:25:17 +0000473 u32 major_low = (reg >> 8) & 0xff;
Peng Faneae4de22018-01-10 13:20:37 +0800474 u32 rom_version;
475
476 reg &= 0xff;
477
Peng Fan69cec072019-12-27 10:14:02 +0800478 /* iMX8MP */
479 if (major_low == 0x43) {
Ye Lid2d754f2020-04-20 20:12:54 -0700480 type = get_cpu_variant_type(MXC_CPU_IMX8MP);
Peng Fan69cec072019-12-27 10:14:02 +0800481 } else if (major_low == 0x42) {
482 /* iMX8MN */
Peng Fan1a07d912020-02-05 17:39:27 +0800483 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
Peng Fan5d2f2062019-06-27 17:23:49 +0800484 } else if (major_low == 0x41) {
Peng Fan1caffdf2019-08-27 06:25:17 +0000485 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
486 } else {
487 if (reg == CHIP_REV_1_0) {
488 /*
Peng Fanc23fbdd2019-10-16 10:24:17 +0000489 * For B0 chip, the DIGPROG is not updated,
490 * it is still TO1.0. we have to check ROM
491 * version or OCOTP_READ_FUSE_DATA.
492 * 0xff0055aa is magic number for B1.
Peng Fan1caffdf2019-08-27 06:25:17 +0000493 */
Peng Fanc23fbdd2019-10-16 10:24:17 +0000494 if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) {
Ye Lic963ed12021-03-19 15:57:16 +0800495 /*
496 * B2 uses same DIGPROG and OCOTP_READ_FUSE_DATA value with B1,
497 * so have to check ROM to distinguish them
498 */
499 rom_version = readl((void __iomem *)ROM_VERSION_B0);
500 rom_version &= 0xff;
501 if (rom_version == CHIP_REV_2_2)
502 reg = CHIP_REV_2_2;
503 else
504 reg = CHIP_REV_2_1;
Peng Fanc23fbdd2019-10-16 10:24:17 +0000505 } else {
506 rom_version =
507 readl((void __iomem *)ROM_VERSION_A0);
508 if (rom_version != CHIP_REV_1_0) {
509 rom_version = readl((void __iomem *)ROM_VERSION_B0);
Patrick Wildtd4a78b92019-11-19 09:42:06 +0100510 rom_version &= 0xff;
Peng Fanc23fbdd2019-10-16 10:24:17 +0000511 if (rom_version == CHIP_REV_2_0)
512 reg = CHIP_REV_2_0;
513 }
Peng Fan1caffdf2019-08-27 06:25:17 +0000514 }
Peng Faneae4de22018-01-10 13:20:37 +0800515 }
Peng Fan67815082020-02-05 17:34:54 +0800516
517 type = get_cpu_variant_type(type);
Peng Faneae4de22018-01-10 13:20:37 +0800518 }
519
520 return (type << 12) | reg;
521}
522
523static void imx_set_wdog_powerdown(bool enable)
524{
525 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
526 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
527 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
528
529 /* Write to the PDE (Power Down Enable) bit */
530 writew(enable, &wdog1->wmcr);
531 writew(enable, &wdog2->wmcr);
532 writew(enable, &wdog3->wmcr);
533}
534
Simon Glassfc557362022-03-04 08:43:05 -0700535static int imx8m_check_clock(void *ctx, struct event *event)
Peng Fanc98e0322019-08-27 06:25:58 +0000536{
537 struct udevice *dev;
538 int ret;
539
Peng Fan3c073342019-10-16 03:01:51 +0000540 if (CONFIG_IS_ENABLED(CLK)) {
541 ret = uclass_get_device_by_name(UCLASS_CLK,
542 "clock-controller@30380000",
543 &dev);
544 if (ret < 0) {
545 printf("Failed to find clock node. Check device tree\n");
546 return ret;
547 }
Peng Fanc98e0322019-08-27 06:25:58 +0000548 }
549
550 return 0;
551}
Simon Glassfc557362022-03-04 08:43:05 -0700552EVENT_SPY(EVT_DM_POST_INIT, imx8m_check_clock);
Peng Fanc98e0322019-08-27 06:25:58 +0000553
Marek Vasutf7b184e2022-09-19 21:37:07 +0200554static void imx8m_setup_snvs(void)
555{
556 /* Enable SNVS clock */
557 clock_enable(CCGR_SNVS, 1);
558 /* Initialize glitch detect */
559 writel(SNVS_LPPGDR_INIT, SNVS_BASE_ADDR + SNVS_LPLVDR);
560 /* Clear interrupt status */
561 writel(0xffffffff, SNVS_BASE_ADDR + SNVS_LPSR);
562}
563
Peng Faneae4de22018-01-10 13:20:37 +0800564int arch_cpu_init(void)
565{
Peng Fanc0b30d72019-04-17 09:41:16 +0000566 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
Marek Vasut3ea500a2022-04-13 00:41:52 +0200567
568#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
569 icache_enable();
570#endif
571
Peng Faneae4de22018-01-10 13:20:37 +0800572 /*
Peng Fand0ca2892019-08-27 06:25:37 +0000573 * ROM might disable clock for SCTR,
574 * enable the clock before timer_init.
575 */
576 if (IS_ENABLED(CONFIG_SPL_BUILD))
577 clock_enable(CCGR_SCTR, 1);
578 /*
Peng Faneae4de22018-01-10 13:20:37 +0800579 * Init timer at very early state, because sscg pll setting
580 * will use it
581 */
582 timer_init();
583
584 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
585 clock_init();
586 imx_set_wdog_powerdown(false);
Peng Fan9cf2aa32020-07-09 13:52:41 +0800587
588 if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() ||
589 is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() ||
Ye Li715180e2021-03-19 15:57:11 +0800590 is_imx8mnsl() || is_imx8mpd() || is_imx8mnud() || is_imx8mnus()) {
Peng Fan9cf2aa32020-07-09 13:52:41 +0800591 /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */
592 struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840);
593 struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880);
594 struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0);
595 struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR;
596
597 writel(0x1, &pgc_core2->pgcr);
598 writel(0x1, &pgc_core3->pgcr);
Ye Li715180e2021-03-19 15:57:11 +0800599 if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) {
Peng Fan9cf2aa32020-07-09 13:52:41 +0800600 writel(0x1, &pgc_core1->pgcr);
601 writel(0xE, &gpc->cpu_pgc_dn_trg);
602 } else {
603 writel(0xC, &gpc->cpu_pgc_dn_trg);
604 }
605 }
Peng Faneae4de22018-01-10 13:20:37 +0800606 }
607
Peng Fanc0b30d72019-04-17 09:41:16 +0000608 if (is_imx8mq()) {
609 clock_enable(CCGR_OCOTP, 1);
610 if (readl(&ocotp->ctrl) & 0x200)
611 writel(0x200, &ocotp->ctrl_clr);
612 }
613
Marek Vasutf7b184e2022-09-19 21:37:07 +0200614 imx8m_setup_snvs();
615
Peng Faneae4de22018-01-10 13:20:37 +0800616 return 0;
617}
618
Peng Fanc9823b02019-09-16 03:09:36 +0000619#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
620struct rom_api *g_rom_api = (struct rom_api *)0x980;
Peng Fanc9823b02019-09-16 03:09:36 +0000621#endif
622
Marek Vasut520ded02021-07-03 04:55:33 +0200623#if defined(CONFIG_IMX8M)
624#include <spl.h>
625int spl_mmc_emmc_boot_partition(struct mmc *mmc)
626{
627 u32 *rom_log_addr = (u32 *)0x9e0;
628 u32 *rom_log;
629 u8 event_id;
630 int i, part;
631
632 part = default_spl_mmc_emmc_boot_partition(mmc);
633
634 /* If the ROM event log pointer is not valid. */
635 if (*rom_log_addr < 0x900000 || *rom_log_addr >= 0xb00000 ||
636 *rom_log_addr & 0x3)
637 return part;
638
639 /* Parse the ROM event ID version 2 log */
640 rom_log = (u32 *)(uintptr_t)(*rom_log_addr);
641 for (i = 0; i < 128; i++) {
642 event_id = rom_log[i] >> 24;
643 switch (event_id) {
644 case 0x00: /* End of list */
645 return part;
646 /* Log entries with 1 parameter, skip 1 */
647 case 0x80: /* Start to perform the device initialization */
648 case 0x81: /* The boot device initialization completes */
649 case 0x8f: /* The boot device initialization fails */
650 case 0x90: /* Start to read data from boot device */
651 case 0x91: /* Reading data from boot device completes */
652 case 0x9f: /* Reading data from boot device fails */
653 i += 1;
654 continue;
655 /* Log entries with 2 parameters, skip 2 */
656 case 0xa0: /* Image authentication result */
657 case 0xc0: /* Jump to the boot image soon */
658 i += 2;
659 continue;
660 /* Boot from the secondary boot image */
661 case 0x51:
662 /*
663 * Swap the eMMC boot partitions in case there was a
664 * fallback event (i.e. primary image was corrupted
665 * and that corruption was recognized by the BootROM),
666 * so the SPL loads the rest of the U-Boot from the
667 * correct eMMC boot partition, since the BootROM
668 * leaves the boot partition set to the corrupted one.
669 */
670 if (part == 1)
671 part = 2;
672 else if (part == 2)
673 part = 1;
674 continue;
675 default:
676 continue;
677 }
678 }
679
680 return part;
681}
682#endif
683
Peng Faneae4de22018-01-10 13:20:37 +0800684bool is_usb_boot(void)
685{
686 return get_boot_device() == USB_BOOT;
687}
688
689#ifdef CONFIG_OF_SYSTEM_SETUP
Peng Fan435dc122020-07-09 14:06:49 +0800690bool check_fdt_new_path(void *blob)
691{
692 const char *soc_path = "/soc@0";
693 int nodeoff;
694
695 nodeoff = fdt_path_offset(blob, soc_path);
696 if (nodeoff < 0)
697 return false;
698
699 return true;
700}
701
702static int disable_fdt_nodes(void *blob, const char *const nodes_path[], int size_array)
703{
704 int i = 0;
705 int rc;
706 int nodeoff;
707 const char *status = "disabled";
708
709 for (i = 0; i < size_array; i++) {
710 nodeoff = fdt_path_offset(blob, nodes_path[i]);
711 if (nodeoff < 0)
712 continue; /* Not found, skip it */
713
714 printf("Found %s node\n", nodes_path[i]);
715
716add_status:
717 rc = fdt_setprop(blob, nodeoff, "status", status, strlen(status) + 1);
718 if (rc) {
719 if (rc == -FDT_ERR_NOSPACE) {
720 rc = fdt_increase_size(blob, 512);
721 if (!rc)
722 goto add_status;
723 }
724 printf("Unable to update property %s:%s, err=%s\n",
725 nodes_path[i], "status", fdt_strerror(rc));
726 } else {
727 printf("Modify %s:%s disabled\n",
728 nodes_path[i], "status");
729 }
730 }
731
732 return 0;
733}
734
735#ifdef CONFIG_IMX8MQ
736bool check_dcss_fused(void)
737{
738 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
739 struct fuse_bank *bank = &ocotp->bank[1];
740 struct fuse_bank1_regs *fuse =
741 (struct fuse_bank1_regs *)bank->fuse_regs;
742 u32 value = readl(&fuse->tester4);
743
744 if (value & 0x4000000)
745 return true;
746
747 return false;
748}
749
750static int disable_mipi_dsi_nodes(void *blob)
751{
752 static const char * const nodes_path[] = {
753 "/mipi_dsi@30A00000",
754 "/mipi_dsi_bridge@30A00000",
755 "/dsi_phy@30A00300",
756 "/soc@0/bus@30800000/mipi_dsi@30a00000",
Peng Fan7d4195c2021-03-19 15:57:13 +0800757 "/soc@0/bus@30800000/dphy@30a00300",
758 "/soc@0/bus@30800000/mipi-dsi@30a00000",
Peng Fan435dc122020-07-09 14:06:49 +0800759 };
760
761 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
762}
763
764static int disable_dcss_nodes(void *blob)
765{
766 static const char * const nodes_path[] = {
767 "/dcss@0x32e00000",
768 "/dcss@32e00000",
769 "/hdmi@32c00000",
770 "/hdmi_cec@32c33800",
771 "/hdmi_drm@32c00000",
772 "/display-subsystem",
773 "/sound-hdmi",
774 "/sound-hdmi-arc",
775 "/soc@0/bus@32c00000/display-controller@32e00000",
776 "/soc@0/bus@32c00000/hdmi@32c00000",
777 };
778
779 return disable_fdt_nodes(blob, nodes_path, ARRAY_SIZE(nodes_path));
780}
781
782static int check_mipi_dsi_nodes(void *blob)
783{
784 static const char * const lcdif_path[] = {
785 "/lcdif@30320000",
Peng Fan7d4195c2021-03-19 15:57:13 +0800786 "/soc@0/bus@30000000/lcdif@30320000",
787 "/soc@0/bus@30000000/lcd-controller@30320000"
Peng Fan435dc122020-07-09 14:06:49 +0800788 };
789 static const char * const mipi_dsi_path[] = {
790 "/mipi_dsi@30A00000",
791 "/soc@0/bus@30800000/mipi_dsi@30a00000"
792 };
793 static const char * const lcdif_ep_path[] = {
794 "/lcdif@30320000/port@0/mipi-dsi-endpoint",
Peng Fan7d4195c2021-03-19 15:57:13 +0800795 "/soc@0/bus@30000000/lcdif@30320000/port@0/endpoint",
796 "/soc@0/bus@30000000/lcd-controller@30320000/port@0/endpoint"
Peng Fan435dc122020-07-09 14:06:49 +0800797 };
798 static const char * const mipi_dsi_ep_path[] = {
799 "/mipi_dsi@30A00000/port@1/endpoint",
Peng Fan7d4195c2021-03-19 15:57:13 +0800800 "/soc@0/bus@30800000/mipi_dsi@30a00000/ports/port@0/endpoint",
801 "/soc@0/bus@30800000/mipi-dsi@30a00000/ports/port@0/endpoint@0"
Peng Fan435dc122020-07-09 14:06:49 +0800802 };
803
804 int lookup_node;
805 int nodeoff;
806 bool new_path = check_fdt_new_path(blob);
807 int i = new_path ? 1 : 0;
808
809 nodeoff = fdt_path_offset(blob, lcdif_path[i]);
810 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff)) {
811 /*
812 * If can't find lcdif node or lcdif node is disabled,
813 * then disable all mipi dsi, since they only can input
814 * from DCSS
815 */
816 return disable_mipi_dsi_nodes(blob);
817 }
818
819 nodeoff = fdt_path_offset(blob, mipi_dsi_path[i]);
820 if (nodeoff < 0 || !fdtdec_get_is_enabled(blob, nodeoff))
821 return 0;
822
823 nodeoff = fdt_path_offset(blob, lcdif_ep_path[i]);
824 if (nodeoff < 0) {
825 /*
826 * If can't find lcdif endpoint, then disable all mipi dsi,
827 * since they only can input from DCSS
828 */
829 return disable_mipi_dsi_nodes(blob);
830 }
831
832 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
833 nodeoff = fdt_path_offset(blob, mipi_dsi_ep_path[i]);
834
835 if (nodeoff > 0 && nodeoff == lookup_node)
836 return 0;
837
838 return disable_mipi_dsi_nodes(blob);
839}
840#endif
841
842int disable_vpu_nodes(void *blob)
843{
844 static const char * const nodes_path_8mq[] = {
845 "/vpu@38300000",
846 "/soc@0/vpu@38300000"
847 };
848
849 static const char * const nodes_path_8mm[] = {
850 "/vpu_g1@38300000",
851 "/vpu_g2@38310000",
852 "/vpu_h1@38320000"
853 };
854
855 static const char * const nodes_path_8mp[] = {
856 "/vpu_g1@38300000",
857 "/vpu_g2@38310000",
858 "/vpu_vc8000e@38320000"
859 };
860
861 if (is_imx8mq())
862 return disable_fdt_nodes(blob, nodes_path_8mq, ARRAY_SIZE(nodes_path_8mq));
863 else if (is_imx8mm())
864 return disable_fdt_nodes(blob, nodes_path_8mm, ARRAY_SIZE(nodes_path_8mm));
865 else if (is_imx8mp())
866 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
867 else
868 return -EPERM;
869}
870
Ye Liee337ce2021-03-19 15:57:09 +0800871#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
872static int low_drive_gpu_freq(void *blob)
873{
874 static const char *nodes_path_8mn[] = {
875 "/gpu@38000000",
876 "/soc@0/gpu@38000000"
877 };
878
879 int nodeoff, cnt, i;
880 u32 assignedclks[7];
881
882 nodeoff = fdt_path_offset(blob, nodes_path_8mn[0]);
883 if (nodeoff < 0)
884 return nodeoff;
885
886 cnt = fdtdec_get_int_array_count(blob, nodeoff, "assigned-clock-rates", assignedclks, 7);
887 if (cnt < 0)
888 return cnt;
889
890 if (cnt != 7)
891 printf("Warning: %s, assigned-clock-rates count %d\n", nodes_path_8mn[0], cnt);
892
893 assignedclks[cnt - 1] = 200000000;
894 assignedclks[cnt - 2] = 200000000;
895
896 for (i = 0; i < cnt; i++) {
897 debug("<%u>, ", assignedclks[i]);
898 assignedclks[i] = cpu_to_fdt32(assignedclks[i]);
899 }
900 debug("\n");
901
902 return fdt_setprop(blob, nodeoff, "assigned-clock-rates", &assignedclks, sizeof(assignedclks));
903}
904#endif
905
Peng Fanf5f9b8e2022-04-07 15:55:53 +0800906static bool check_remote_endpoint(void *blob, const char *ep1, const char *ep2)
907{
908 int lookup_node;
909 int nodeoff;
910
911 nodeoff = fdt_path_offset(blob, ep1);
912 if (nodeoff) {
913 lookup_node = fdtdec_lookup_phandle(blob, nodeoff, "remote-endpoint");
914 nodeoff = fdt_path_offset(blob, ep2);
915
916 if (nodeoff > 0 && nodeoff == lookup_node)
917 return true;
918 }
919
920 return false;
921}
922
923int disable_dsi_lcdif_nodes(void *blob)
924{
925 int ret;
926
927 static const char * const dsi_path_8mp[] = {
928 "/soc@0/bus@32c00000/mipi_dsi@32e60000"
929 };
930
931 static const char * const lcdif_path_8mp[] = {
932 "/soc@0/bus@32c00000/lcd-controller@32e80000"
933 };
934
935 static const char * const lcdif_ep_path_8mp[] = {
936 "/soc@0/bus@32c00000/lcd-controller@32e80000/port@0/endpoint"
937 };
938 static const char * const dsi_ep_path_8mp[] = {
939 "/soc@0/bus@32c00000/mipi_dsi@32e60000/port@0/endpoint"
940 };
941
942 ret = disable_fdt_nodes(blob, dsi_path_8mp, ARRAY_SIZE(dsi_path_8mp));
943 if (ret)
944 return ret;
945
946 if (check_remote_endpoint(blob, dsi_ep_path_8mp[0], lcdif_ep_path_8mp[0])) {
947 /* Disable lcdif node */
948 return disable_fdt_nodes(blob, lcdif_path_8mp, ARRAY_SIZE(lcdif_path_8mp));
949 }
950
951 return 0;
952}
953
954int disable_lvds_lcdif_nodes(void *blob)
955{
956 int ret, i;
957
958 static const char * const ldb_path_8mp[] = {
959 "/soc@0/bus@32c00000/ldb@32ec005c",
960 "/soc@0/bus@32c00000/phy@32ec0128"
961 };
962
963 static const char * const lcdif_path_8mp[] = {
964 "/soc@0/bus@32c00000/lcd-controller@32e90000"
965 };
966
967 static const char * const lcdif_ep_path_8mp[] = {
968 "/soc@0/bus@32c00000/lcd-controller@32e90000/port@0/endpoint@0",
969 "/soc@0/bus@32c00000/lcd-controller@32e90000/port@0/endpoint@1"
970 };
971 static const char * const ldb_ep_path_8mp[] = {
972 "/soc@0/bus@32c00000/ldb@32ec005c/lvds-channel@0/port@0/endpoint",
973 "/soc@0/bus@32c00000/ldb@32ec005c/lvds-channel@1/port@0/endpoint"
974 };
975
976 ret = disable_fdt_nodes(blob, ldb_path_8mp, ARRAY_SIZE(ldb_path_8mp));
977 if (ret)
978 return ret;
979
980 for (i = 0; i < ARRAY_SIZE(ldb_ep_path_8mp); i++) {
981 if (check_remote_endpoint(blob, ldb_ep_path_8mp[i], lcdif_ep_path_8mp[i])) {
982 /* Disable lcdif node */
983 return disable_fdt_nodes(blob, lcdif_path_8mp, ARRAY_SIZE(lcdif_path_8mp));
984 }
985 }
986
987 return 0;
988}
989
Peng Fan435dc122020-07-09 14:06:49 +0800990int disable_gpu_nodes(void *blob)
991{
992 static const char * const nodes_path_8mn[] = {
Peng Fan7d4195c2021-03-19 15:57:13 +0800993 "/gpu@38000000",
994 "/soc@/gpu@38000000"
Peng Fan435dc122020-07-09 14:06:49 +0800995 };
996
Peng Fanf5f9b8e2022-04-07 15:55:53 +0800997 static const char * const nodes_path_8mp[] = {
998 "/gpu3d@38000000",
999 "/gpu2d@38008000"
1000 };
1001
1002 if (is_imx8mp())
1003 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1004 else
1005 return disable_fdt_nodes(blob, nodes_path_8mn, ARRAY_SIZE(nodes_path_8mn));
Peng Fan435dc122020-07-09 14:06:49 +08001006}
1007
1008int disable_npu_nodes(void *blob)
1009{
1010 static const char * const nodes_path_8mp[] = {
1011 "/vipsi@38500000"
1012 };
1013
1014 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1015}
1016
1017int disable_isp_nodes(void *blob)
1018{
1019 static const char * const nodes_path_8mp[] = {
1020 "/soc@0/bus@32c00000/camera/isp@32e10000",
1021 "/soc@0/bus@32c00000/camera/isp@32e20000"
1022 };
1023
1024 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1025}
1026
1027int disable_dsp_nodes(void *blob)
1028{
1029 static const char * const nodes_path_8mp[] = {
1030 "/dsp@3b6e8000"
1031 };
1032
1033 return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp));
1034}
1035
Ye Li26517af2021-03-19 15:57:12 +08001036static void disable_thermal_cpu_nodes(void *blob, u32 disabled_cores)
1037{
1038 static const char * const thermal_path[] = {
1039 "/thermal-zones/cpu-thermal/cooling-maps/map0"
1040 };
1041
1042 int nodeoff, cnt, i, ret, j;
1043 u32 cooling_dev[12];
1044
1045 for (i = 0; i < ARRAY_SIZE(thermal_path); i++) {
1046 nodeoff = fdt_path_offset(blob, thermal_path[i]);
1047 if (nodeoff < 0)
1048 continue; /* Not found, skip it */
1049
1050 cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", cooling_dev, 12);
1051 if (cnt < 0)
1052 continue;
1053
1054 if (cnt != 12)
1055 printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt);
1056
1057 for (j = 0; j < cnt; j++)
1058 cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]);
1059
1060 ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev,
1061 sizeof(u32) * (12 - disabled_cores * 3));
1062 if (ret < 0) {
1063 printf("Warning: %s, cooling-device setprop failed %d\n",
1064 thermal_path[i], ret);
1065 continue;
1066 }
1067
1068 printf("Update node %s, cooling-device prop\n", thermal_path[i]);
1069 }
1070}
1071
1072static void disable_pmu_cpu_nodes(void *blob, u32 disabled_cores)
1073{
1074 static const char * const pmu_path[] = {
1075 "/pmu"
1076 };
1077
1078 int nodeoff, cnt, i, ret, j;
1079 u32 irq_affinity[4];
1080
1081 for (i = 0; i < ARRAY_SIZE(pmu_path); i++) {
1082 nodeoff = fdt_path_offset(blob, pmu_path[i]);
1083 if (nodeoff < 0)
1084 continue; /* Not found, skip it */
1085
1086 cnt = fdtdec_get_int_array_count(blob, nodeoff, "interrupt-affinity",
1087 irq_affinity, 4);
1088 if (cnt < 0)
1089 continue;
1090
1091 if (cnt != 4)
1092 printf("Warning: %s, interrupt-affinity count %d\n", pmu_path[i], cnt);
1093
1094 for (j = 0; j < cnt; j++)
1095 irq_affinity[j] = cpu_to_fdt32(irq_affinity[j]);
1096
1097 ret = fdt_setprop(blob, nodeoff, "interrupt-affinity", &irq_affinity,
1098 sizeof(u32) * (4 - disabled_cores));
1099 if (ret < 0) {
1100 printf("Warning: %s, interrupt-affinity setprop failed %d\n",
1101 pmu_path[i], ret);
1102 continue;
1103 }
1104
1105 printf("Update node %s, interrupt-affinity prop\n", pmu_path[i]);
1106 }
1107}
1108
Peng Fan435dc122020-07-09 14:06:49 +08001109static int disable_cpu_nodes(void *blob, u32 disabled_cores)
1110{
1111 static const char * const nodes_path[] = {
1112 "/cpus/cpu@1",
1113 "/cpus/cpu@2",
1114 "/cpus/cpu@3",
1115 };
1116 u32 i = 0;
1117 int rc;
1118 int nodeoff;
1119
1120 if (disabled_cores > 3)
1121 return -EINVAL;
1122
1123 i = 3 - disabled_cores;
1124
1125 for (; i < 3; i++) {
1126 nodeoff = fdt_path_offset(blob, nodes_path[i]);
1127 if (nodeoff < 0)
1128 continue; /* Not found, skip it */
1129
1130 debug("Found %s node\n", nodes_path[i]);
1131
1132 rc = fdt_del_node(blob, nodeoff);
1133 if (rc < 0) {
1134 printf("Unable to delete node %s, err=%s\n",
1135 nodes_path[i], fdt_strerror(rc));
1136 } else {
1137 printf("Delete node %s\n", nodes_path[i]);
1138 }
1139 }
1140
Ye Li26517af2021-03-19 15:57:12 +08001141 disable_thermal_cpu_nodes(blob, disabled_cores);
1142 disable_pmu_cpu_nodes(blob, disabled_cores);
1143
Peng Fan435dc122020-07-09 14:06:49 +08001144 return 0;
1145}
1146
Peng Fana08bc872022-04-07 15:55:54 +08001147static int cleanup_nodes_for_efi(void *blob)
1148{
Peng Fan1585b202022-04-07 15:55:55 +08001149 static const char * const path[][2] = {
1150 { "/soc@0/bus@32c00000/usb@32e40000", "extcon" },
1151 { "/soc@0/bus@32c00000/usb@32e50000", "extcon" },
1152 { "/soc@0/bus@30800000/ethernet@30be0000", "phy-reset-gpios" },
1153 { "/soc@0/bus@30800000/ethernet@30bf0000", "phy-reset-gpios" }
1154 };
Peng Fana08bc872022-04-07 15:55:54 +08001155 int nodeoff, i, rc;
1156
Peng Fan1585b202022-04-07 15:55:55 +08001157 for (i = 0; i < ARRAY_SIZE(path); i++) {
1158 nodeoff = fdt_path_offset(blob, path[i][0]);
Peng Fana08bc872022-04-07 15:55:54 +08001159 if (nodeoff < 0)
1160 continue; /* Not found, skip it */
Peng Fan1585b202022-04-07 15:55:55 +08001161 debug("Found %s node\n", path[i][0]);
Peng Fana08bc872022-04-07 15:55:54 +08001162
Peng Fan1585b202022-04-07 15:55:55 +08001163 rc = fdt_delprop(blob, nodeoff, path[i][1]);
Peng Fana08bc872022-04-07 15:55:54 +08001164 if (rc == -FDT_ERR_NOTFOUND)
1165 continue;
1166 if (rc) {
1167 printf("Unable to update property %s:%s, err=%s\n",
Peng Fan1585b202022-04-07 15:55:55 +08001168 path[i][0], path[i][1], fdt_strerror(rc));
Peng Fana08bc872022-04-07 15:55:54 +08001169 return rc;
1170 }
1171
Peng Fan1585b202022-04-07 15:55:55 +08001172 printf("Remove %s:%s\n", path[i][0], path[i][1]);
Peng Fana08bc872022-04-07 15:55:54 +08001173 }
1174
1175 return 0;
1176}
Peng Fana08bc872022-04-07 15:55:54 +08001177
Andrejs Cainikovs2f3491c2022-05-27 15:20:42 +02001178static int fixup_thermal_trips(void *blob, const char *name)
1179{
1180 int minc, maxc;
1181 int node, trip;
1182
1183 node = fdt_path_offset(blob, "/thermal-zones");
1184 if (node < 0)
1185 return node;
1186
1187 node = fdt_subnode_offset(blob, node, name);
1188 if (node < 0)
1189 return node;
1190
1191 node = fdt_subnode_offset(blob, node, "trips");
1192 if (node < 0)
1193 return node;
1194
1195 get_cpu_temp_grade(&minc, &maxc);
1196
1197 fdt_for_each_subnode(trip, blob, node) {
1198 const char *type;
1199 int temp, ret;
1200
1201 type = fdt_getprop(blob, trip, "type", NULL);
1202 if (!type)
1203 continue;
1204
1205 temp = 0;
1206 if (!strcmp(type, "critical"))
1207 temp = 1000 * maxc;
1208 else if (!strcmp(type, "passive"))
1209 temp = 1000 * (maxc - 10);
1210 if (temp) {
1211 ret = fdt_setprop_u32(blob, trip, "temperature", temp);
1212 if (ret)
1213 return ret;
1214 }
1215 }
1216
1217 return 0;
1218}
1219
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001220int ft_system_setup(void *blob, struct bd_info *bd)
Peng Faneae4de22018-01-10 13:20:37 +08001221{
Peng Fan435dc122020-07-09 14:06:49 +08001222#ifdef CONFIG_IMX8MQ
Peng Faneae4de22018-01-10 13:20:37 +08001223 int i = 0;
1224 int rc;
1225 int nodeoff;
1226
Peng Fan435dc122020-07-09 14:06:49 +08001227 if (get_boot_device() == USB_BOOT) {
1228 disable_dcss_nodes(blob);
1229
1230 bool new_path = check_fdt_new_path(blob);
1231 int v = new_path ? 1 : 0;
1232 static const char * const usb_dwc3_path[] = {
1233 "/usb@38100000/dwc3",
1234 "/soc@0/usb@38100000"
1235 };
1236
1237 nodeoff = fdt_path_offset(blob, usb_dwc3_path[v]);
1238 if (nodeoff >= 0) {
1239 const char *speed = "high-speed";
1240
1241 printf("Found %s node\n", usb_dwc3_path[v]);
1242
1243usb_modify_speed:
1244
1245 rc = fdt_setprop(blob, nodeoff, "maximum-speed", speed, strlen(speed) + 1);
1246 if (rc) {
1247 if (rc == -FDT_ERR_NOSPACE) {
1248 rc = fdt_increase_size(blob, 512);
1249 if (!rc)
1250 goto usb_modify_speed;
1251 }
1252 printf("Unable to set property %s:%s, err=%s\n",
1253 usb_dwc3_path[v], "maximum-speed", fdt_strerror(rc));
1254 } else {
1255 printf("Modify %s:%s = %s\n",
1256 usb_dwc3_path[v], "maximum-speed", speed);
1257 }
1258 } else {
1259 printf("Can't found %s node\n", usb_dwc3_path[v]);
1260 }
1261 }
1262
Peng Faneae4de22018-01-10 13:20:37 +08001263 /* Disable the CPU idle for A0 chip since the HW does not support it */
1264 if (is_soc_rev(CHIP_REV_1_0)) {
1265 static const char * const nodes_path[] = {
1266 "/cpus/cpu@0",
1267 "/cpus/cpu@1",
1268 "/cpus/cpu@2",
1269 "/cpus/cpu@3",
1270 };
1271
1272 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
1273 nodeoff = fdt_path_offset(blob, nodes_path[i]);
1274 if (nodeoff < 0)
1275 continue; /* Not found, skip it */
1276
Marek Vasute2e7a772020-04-24 21:37:33 +02001277 debug("Found %s node\n", nodes_path[i]);
Peng Faneae4de22018-01-10 13:20:37 +08001278
1279 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
Marek Vasute2e7a772020-04-24 21:37:33 +02001280 if (rc == -FDT_ERR_NOTFOUND)
1281 continue;
Peng Faneae4de22018-01-10 13:20:37 +08001282 if (rc) {
1283 printf("Unable to update property %s:%s, err=%s\n",
1284 nodes_path[i], "status", fdt_strerror(rc));
1285 return rc;
1286 }
1287
Marek Vasute2e7a772020-04-24 21:37:33 +02001288 debug("Remove %s:%s\n", nodes_path[i],
Peng Faneae4de22018-01-10 13:20:37 +08001289 "cpu-idle-states");
1290 }
1291 }
1292
Peng Fan435dc122020-07-09 14:06:49 +08001293 if (is_imx8mql()) {
1294 disable_vpu_nodes(blob);
1295 if (check_dcss_fused()) {
1296 printf("DCSS is fused\n");
1297 disable_dcss_nodes(blob);
1298 check_mipi_dsi_nodes(blob);
1299 }
1300 }
1301
1302 if (is_imx8md())
1303 disable_cpu_nodes(blob, 2);
1304
1305#elif defined(CONFIG_IMX8MM)
1306 if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl())
1307 disable_vpu_nodes(blob);
1308
1309 if (is_imx8mmd() || is_imx8mmdl())
1310 disable_cpu_nodes(blob, 2);
1311 else if (is_imx8mms() || is_imx8mmsl())
1312 disable_cpu_nodes(blob, 3);
1313
1314#elif defined(CONFIG_IMX8MN)
1315 if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl())
1316 disable_gpu_nodes(blob);
Ye Liee337ce2021-03-19 15:57:09 +08001317#ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE
1318 else {
1319 int ldm_gpu = low_drive_gpu_freq(blob);
1320
1321 if (ldm_gpu < 0)
1322 printf("Update GPU node assigned-clock-rates failed\n");
1323 else
1324 printf("Update GPU node assigned-clock-rates ok\n");
1325 }
1326#endif
Peng Fan435dc122020-07-09 14:06:49 +08001327
Ye Li715180e2021-03-19 15:57:11 +08001328 if (is_imx8mnd() || is_imx8mndl() || is_imx8mnud())
Peng Fan435dc122020-07-09 14:06:49 +08001329 disable_cpu_nodes(blob, 2);
Ye Li715180e2021-03-19 15:57:11 +08001330 else if (is_imx8mns() || is_imx8mnsl() || is_imx8mnus())
Peng Fan435dc122020-07-09 14:06:49 +08001331 disable_cpu_nodes(blob, 3);
1332
1333#elif defined(CONFIG_IMX8MP)
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001334 if (is_imx8mpul()) {
1335 /* Disable GPU */
1336 disable_gpu_nodes(blob);
1337
1338 /* Disable DSI */
1339 disable_dsi_lcdif_nodes(blob);
1340
1341 /* Disable LVDS */
1342 disable_lvds_lcdif_nodes(blob);
1343 }
1344
1345 if (is_imx8mpul() || is_imx8mpl())
Peng Fan435dc122020-07-09 14:06:49 +08001346 disable_vpu_nodes(blob);
1347
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001348 if (is_imx8mpul() || is_imx8mpl() || is_imx8mp6())
Peng Fan435dc122020-07-09 14:06:49 +08001349 disable_npu_nodes(blob);
1350
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001351 if (is_imx8mpul() || is_imx8mpl())
Peng Fan435dc122020-07-09 14:06:49 +08001352 disable_isp_nodes(blob);
1353
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001354 if (is_imx8mpul() || is_imx8mpl() || is_imx8mp6())
Peng Fan435dc122020-07-09 14:06:49 +08001355 disable_dsp_nodes(blob);
1356
1357 if (is_imx8mpd())
1358 disable_cpu_nodes(blob, 2);
1359#endif
1360
Peng Fan1585b202022-04-07 15:55:55 +08001361 cleanup_nodes_for_efi(blob);
Andrejs Cainikovs2f3491c2022-05-27 15:20:42 +02001362
1363 if (fixup_thermal_trips(blob, "cpu-thermal"))
1364 printf("Failed to update cpu-thermal trip(s)");
1365 if (IS_ENABLED(CONFIG_IMX8MP) &&
1366 fixup_thermal_trips(blob, "soc-thermal"))
1367 printf("Failed to update soc-thermal trip(s)");
1368
Peng Faneae4de22018-01-10 13:20:37 +08001369 return 0;
1370}
1371#endif
1372
Peng Fanf5f9b8e2022-04-07 15:55:53 +08001373#ifdef CONFIG_OF_BOARD_FIXUP
1374#ifndef CONFIG_SPL_BUILD
1375int board_fix_fdt(void *fdt)
1376{
1377 if (is_imx8mpul()) {
1378 int i = 0;
1379 int nodeoff, ret;
1380 const char *status = "disabled";
1381 static const char * const dsi_nodes[] = {
1382 "/soc@0/bus@32c00000/mipi_dsi@32e60000",
1383 "/soc@0/bus@32c00000/lcd-controller@32e80000",
1384 "/dsi-host"
1385 };
1386
1387 for (i = 0; i < ARRAY_SIZE(dsi_nodes); i++) {
1388 nodeoff = fdt_path_offset(fdt, dsi_nodes[i]);
1389 if (nodeoff > 0) {
1390set_status:
1391 ret = fdt_setprop(fdt, nodeoff, "status", status,
1392 strlen(status) + 1);
1393 if (ret == -FDT_ERR_NOSPACE) {
1394 ret = fdt_increase_size(fdt, 512);
1395 if (!ret)
1396 goto set_status;
1397 }
1398 }
1399 }
1400 }
1401
1402 return 0;
1403}
1404#endif
1405#endif
1406
Marek Vasut64dc4de2020-04-29 15:04:21 +02001407#if !CONFIG_IS_ENABLED(SYSRESET)
Harald Seiler6f14d5f2020-12-15 16:47:52 +01001408void reset_cpu(void)
Peng Faneae4de22018-01-10 13:20:37 +08001409{
Claudius Heinee73f3942020-04-29 15:04:23 +02001410 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
Peng Faneae4de22018-01-10 13:20:37 +08001411
Ye Li54a915a2019-12-09 00:47:18 -08001412 /* Clear WDA to trigger WDOG_B immediately */
1413 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
Peng Fan24290d92019-08-27 06:25:41 +00001414
Ye Li54a915a2019-12-09 00:47:18 -08001415 while (1) {
1416 /*
Harald Seilerec0c4472020-04-29 15:04:22 +02001417 * spin for .5 seconds before reset
Ye Li54a915a2019-12-09 00:47:18 -08001418 */
1419 }
Peng Faneae4de22018-01-10 13:20:37 +08001420}
Peng Fan24290d92019-08-27 06:25:41 +00001421#endif
Peng Fan5760d8d2020-04-22 10:51:13 +08001422
1423#if defined(CONFIG_ARCH_MISC_INIT)
Peng Fan5760d8d2020-04-22 10:51:13 +08001424int arch_misc_init(void)
1425{
Gaurav Jain81113a02022-03-24 11:50:27 +05301426 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
1427 struct udevice *dev;
1428 int ret;
1429
1430 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
1431 if (ret)
Ye Liec346892022-05-11 13:56:20 +05301432 printf("Failed to initialize caam_jr: %d\n", ret);
Gaurav Jain81113a02022-03-24 11:50:27 +05301433 }
Peng Fan5760d8d2020-04-22 10:51:13 +08001434
1435 return 0;
1436}
1437#endif
Ye Li325cd012020-05-03 22:19:52 +08001438
1439void imx_tmu_arch_init(void *reg_base)
1440{
Ye Lia00f2f02020-05-03 22:19:53 +08001441 if (is_imx8mm() || is_imx8mn()) {
Ye Li325cd012020-05-03 22:19:52 +08001442 /* Load TCALIV and TASR from fuses */
1443 struct ocotp_regs *ocotp =
1444 (struct ocotp_regs *)OCOTP_BASE_ADDR;
1445 struct fuse_bank *bank = &ocotp->bank[3];
1446 struct fuse_bank3_regs *fuse =
1447 (struct fuse_bank3_regs *)bank->fuse_regs;
1448
1449 u32 tca_rt, tca_hr, tca_en;
1450 u32 buf_vref, buf_slope;
1451
1452 tca_rt = fuse->ana0 & 0xFF;
1453 tca_hr = (fuse->ana0 & 0xFF00) >> 8;
1454 tca_en = (fuse->ana0 & 0x2000000) >> 25;
1455
1456 buf_vref = (fuse->ana0 & 0x1F00000) >> 20;
1457 buf_slope = (fuse->ana0 & 0xF0000) >> 16;
1458
1459 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
1460 writel((tca_en << 31) | (tca_hr << 16) | tca_rt,
1461 (ulong)reg_base + 0x30);
1462 }
Ye Li41a20252020-05-03 22:19:54 +08001463#ifdef CONFIG_IMX8MP
1464 /* Load TCALIV0/1/m40 and TRIM from fuses */
1465 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
1466 struct fuse_bank *bank = &ocotp->bank[38];
1467 struct fuse_bank38_regs *fuse =
1468 (struct fuse_bank38_regs *)bank->fuse_regs;
1469 struct fuse_bank *bank2 = &ocotp->bank[39];
1470 struct fuse_bank39_regs *fuse2 =
1471 (struct fuse_bank39_regs *)bank2->fuse_regs;
1472 u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr;
1473 u32 reg;
1474 u32 tca40[2], tca25[2], tca105[2];
1475
1476 /* For blank sample */
1477 if (!fuse->ana_trim2 && !fuse->ana_trim3 &&
1478 !fuse->ana_trim4 && !fuse2->ana_trim5) {
1479 /* Use a default 25C binary codes */
1480 tca25[0] = 1596;
Ye Lid756ca02020-05-03 22:19:55 +08001481 tca25[1] = 1596;
Ye Li41a20252020-05-03 22:19:54 +08001482 writel(tca25[0], (ulong)reg_base + 0x30);
Ye Lid756ca02020-05-03 22:19:55 +08001483 writel(tca25[1], (ulong)reg_base + 0x34);
Ye Li41a20252020-05-03 22:19:54 +08001484 return;
1485 }
1486
1487 buf_vref = (fuse->ana_trim2 & 0xc0) >> 6;
1488 buf_slope = (fuse->ana_trim2 & 0xF00) >> 8;
1489 bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12;
1490 bgr = (fuse->ana_trim2 & 0xF0000) >> 16;
1491 vlsb = (fuse->ana_trim2 & 0xF00000) >> 20;
1492 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
1493
1494 reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7);
1495 writel(reg, (ulong)reg_base + 0x3c);
1496
1497 tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16;
1498 tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28;
1499 tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4);
1500 tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8;
1501 tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20;
1502 tca25[1] = fuse2->ana_trim5 & 0xFFF;
1503 tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12;
1504
1505 /* use 25c for 1p calibration */
1506 writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30);
1507 writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34);
1508 writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38);
1509#endif
Ye Li325cd012020-05-03 22:19:52 +08001510}
Peng Fana35215d2020-07-09 13:39:26 +08001511
1512#if defined(CONFIG_SPL_BUILD)
1513#if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
1514bool serror_need_skip = true;
1515
Sean Anderson2d755492022-03-22 17:17:35 -04001516void do_error(struct pt_regs *pt_regs)
Peng Fana35215d2020-07-09 13:39:26 +08001517{
1518 /*
1519 * If stack is still in ROM reserved OCRAM not switch to SPL,
1520 * it is the ROM SError
1521 */
1522 ulong sp;
1523
1524 asm volatile("mov %0, sp" : "=r"(sp) : );
1525
1526 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
1527 /* Check for ERR050342, imx8mq HDCP enabled parts */
1528 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
1529 serror_need_skip = false;
1530 return; /* Do nothing skip the SError in ROM */
1531 }
1532
1533 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
1534 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
1535 serror_need_skip = false;
1536 return; /* Do nothing skip the SError in ROM */
1537 }
1538 }
1539
1540 efi_restore_gd();
Sean Anderson2d755492022-03-22 17:17:35 -04001541 printf("\"Error\" handler, esr 0x%08lx\n", pt_regs->esr);
Peng Fana35215d2020-07-09 13:39:26 +08001542 show_regs(pt_regs);
1543 panic("Resetting CPU ...\n");
1544}
1545#endif
1546#endif
Ye Li0513f362019-07-15 01:16:46 -07001547
1548#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
Marek Vasut765b5802022-04-06 02:21:34 +02001549enum env_location arch_env_get_location(enum env_operation op, int prio)
Ye Li0513f362019-07-15 01:16:46 -07001550{
1551 enum boot_device dev = get_boot_device();
Ye Li0513f362019-07-15 01:16:46 -07001552
1553 if (prio)
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001554 return ENVL_UNKNOWN;
Ye Li0513f362019-07-15 01:16:46 -07001555
1556 switch (dev) {
Fabio Estevam9be6daf2022-04-21 15:05:23 -03001557 case USB_BOOT:
1558 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
1559 return ENVL_SPI_FLASH;
1560 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
1561 return ENVL_NAND;
1562 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
1563 return ENVL_MMC;
1564 if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
1565 return ENVL_NOWHERE;
1566 return ENVL_UNKNOWN;
Ye Li0513f362019-07-15 01:16:46 -07001567 case QSPI_BOOT:
Marek Vasut31b3bc42022-03-25 18:59:28 +01001568 case SPI_NOR_BOOT:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001569 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
1570 return ENVL_SPI_FLASH;
1571 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001572 case NAND_BOOT:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001573 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
1574 return ENVL_NAND;
1575 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001576 case SD1_BOOT:
1577 case SD2_BOOT:
1578 case SD3_BOOT:
1579 case MMC1_BOOT:
1580 case MMC2_BOOT:
1581 case MMC3_BOOT:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001582 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
1583 return ENVL_MMC;
1584 else if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
1585 return ENVL_EXT4;
1586 else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
1587 return ENVL_FAT;
1588 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001589 default:
Ricardo Salveti1daf63f2021-10-20 16:16:26 -03001590 return ENVL_NOWHERE;
Ye Li0513f362019-07-15 01:16:46 -07001591 }
Ye Li0513f362019-07-15 01:16:46 -07001592}
1593
Ye Li0513f362019-07-15 01:16:46 -07001594#endif
Peng Fanf19e0e52022-04-29 16:03:14 +08001595
1596#ifdef CONFIG_IMX_BOOTAUX
1597const struct rproc_att hostmap[] = {
1598 /* aux core , host core, size */
1599 { 0x00000000, 0x007e0000, 0x00020000 },
1600 /* OCRAM_S */
1601 { 0x00180000, 0x00180000, 0x00008000 },
1602 /* OCRAM */
1603 { 0x00900000, 0x00900000, 0x00020000 },
1604 /* OCRAM */
1605 { 0x00920000, 0x00920000, 0x00020000 },
1606 /* QSPI Code - alias */
1607 { 0x08000000, 0x08000000, 0x08000000 },
1608 /* DDR (Code) - alias */
1609 { 0x10000000, 0x80000000, 0x0FFE0000 },
1610 /* TCML */
1611 { 0x1FFE0000, 0x007E0000, 0x00040000 },
1612 /* OCRAM_S */
1613 { 0x20180000, 0x00180000, 0x00008000 },
1614 /* OCRAM */
1615 { 0x20200000, 0x00900000, 0x00040000 },
1616 /* DDR (Data) */
1617 { 0x40000000, 0x40000000, 0x80000000 },
1618 { /* sentinel */ }
1619};
Marek Vasutddc59352022-12-13 05:46:07 +01001620
1621const struct rproc_att *imx_bootaux_get_hostmap(void)
1622{
1623 return hostmap;
1624}
Peng Fanf19e0e52022-04-29 16:03:14 +08001625#endif