blob: 9caf08e86cf2d4a918c75a00b62349fdbd5f594c [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/*
Ye Li325cd012020-05-03 22:19:52 +08003 * Copyright 2017-2019 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 Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Peng Faneae4de22018-01-10 13:20:37 +080012#include <asm/arch/imx-regs.h>
13#include <asm/io.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/mach-imx/hab.h>
17#include <asm/mach-imx/boot_mode.h>
18#include <asm/mach-imx/syscounter.h>
Peng Fana35215d2020-07-09 13:39:26 +080019#include <asm/ptrace.h>
Peng Faneae4de22018-01-10 13:20:37 +080020#include <asm/armv8/mmu.h>
Peng Fanc98e0322019-08-27 06:25:58 +000021#include <dm/uclass.h>
Peng Fana35215d2020-07-09 13:39:26 +080022#include <efi_loader.h>
Peng Faneae4de22018-01-10 13:20:37 +080023#include <errno.h>
24#include <fdt_support.h>
25#include <fsl_wdog.h>
26#include <imx_sip.h>
Peng Fan45d843a2020-05-11 15:14:04 +080027#include <linux/arm-smccc.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060028#include <linux/bitops.h>
Peng Faneae4de22018-01-10 13:20:37 +080029
30DECLARE_GLOBAL_DATA_PTR;
31
Stefano Babicf8b509b2019-09-20 08:47:53 +020032#if defined(CONFIG_IMX_HAB)
Peng Faneae4de22018-01-10 13:20:37 +080033struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
34 .bank = 1,
35 .word = 3,
36};
37#endif
38
39int timer_init(void)
40{
41#ifdef CONFIG_SPL_BUILD
42 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
43 unsigned long freq = readl(&sctr->cntfid0);
44
45 /* Update with accurate clock frequency */
46 asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
47
48 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
49 SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
50#endif
51
52 gd->arch.tbl = 0;
53 gd->arch.tbu = 0;
54
55 return 0;
56}
57
58void enable_tzc380(void)
59{
60 struct iomuxc_gpr_base_regs *gpr =
61 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
62
63 /* Enable TZASC and lock setting */
64 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN);
65 setbits_le32(&gpr->gpr[10], GPR_TZASC_EN_LOCK);
Peng Fanc0e47fc2019-12-27 10:19:42 +080066 if (is_imx8mm() || is_imx8mn() || is_imx8mp())
Peng Fan99047fc2019-08-27 06:25:30 +000067 setbits_le32(&gpr->gpr[10], BIT(1));
Ye Li4c97c462019-08-27 06:25:34 +000068 /*
69 * set Region 0 attribute to allow secure and non-secure
70 * read/write permission. Found some masters like usb dwc3
71 * controllers can't work with secure memory.
72 */
73 writel(0xf0000000, TZASC_BASE_ADDR + 0x108);
Peng Faneae4de22018-01-10 13:20:37 +080074}
75
76void set_wdog_reset(struct wdog_regs *wdog)
77{
78 /*
79 * Output WDOG_B signal to reset external pmic or POR_B decided by
80 * the board design. Without external reset, the peripherals/DDR/
81 * PMIC are not reset, that may cause system working abnormal.
82 * WDZST bit is write-once only bit. Align this bit in kernel,
83 * otherwise kernel code will have no chance to set this bit.
84 */
85 setbits_le16(&wdog->wcr, WDOG_WDT_MASK | WDOG_WDZST_MASK);
86}
87
88static struct mm_region imx8m_mem_map[] = {
89 {
90 /* ROM */
91 .virt = 0x0UL,
92 .phys = 0x0UL,
93 .size = 0x100000UL,
94 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
95 PTE_BLOCK_OUTER_SHARE
96 }, {
Gary Bisson5c72a452018-11-14 17:55:28 +010097 /* CAAM */
98 .virt = 0x100000UL,
99 .phys = 0x100000UL,
100 .size = 0x8000UL,
101 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
102 PTE_BLOCK_NON_SHARE |
103 PTE_BLOCK_PXN | PTE_BLOCK_UXN
104 }, {
105 /* TCM */
106 .virt = 0x7C0000UL,
107 .phys = 0x7C0000UL,
108 .size = 0x80000UL,
109 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
110 PTE_BLOCK_NON_SHARE |
111 PTE_BLOCK_PXN | PTE_BLOCK_UXN
112 }, {
Peng Faneae4de22018-01-10 13:20:37 +0800113 /* OCRAM */
114 .virt = 0x900000UL,
115 .phys = 0x900000UL,
116 .size = 0x200000UL,
117 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
118 PTE_BLOCK_OUTER_SHARE
119 }, {
120 /* AIPS */
121 .virt = 0xB00000UL,
122 .phys = 0xB00000UL,
123 .size = 0x3f500000UL,
124 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
125 PTE_BLOCK_NON_SHARE |
126 PTE_BLOCK_PXN | PTE_BLOCK_UXN
127 }, {
128 /* DRAM1 */
129 .virt = 0x40000000UL,
130 .phys = 0x40000000UL,
Peng Fanb749b5e2019-08-27 06:25:27 +0000131 .size = PHYS_SDRAM_SIZE,
Peng Faneae4de22018-01-10 13:20:37 +0800132 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
133 PTE_BLOCK_OUTER_SHARE
Peng Fanb749b5e2019-08-27 06:25:27 +0000134#ifdef PHYS_SDRAM_2_SIZE
Peng Faneae4de22018-01-10 13:20:37 +0800135 }, {
136 /* DRAM2 */
137 .virt = 0x100000000UL,
138 .phys = 0x100000000UL,
Peng Fanb749b5e2019-08-27 06:25:27 +0000139 .size = PHYS_SDRAM_2_SIZE,
Peng Faneae4de22018-01-10 13:20:37 +0800140 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
141 PTE_BLOCK_OUTER_SHARE
Peng Fanb749b5e2019-08-27 06:25:27 +0000142#endif
Peng Faneae4de22018-01-10 13:20:37 +0800143 }, {
144 /* List terminator */
145 0,
146 }
147};
148
149struct mm_region *mem_map = imx8m_mem_map;
150
Peng Fanb749b5e2019-08-27 06:25:27 +0000151void enable_caches(void)
152{
153 /*
154 * If OPTEE runs, remove OPTEE memory from MMU table to
155 * avoid speculative prefetch. OPTEE runs at the top of
156 * the first memory bank
157 */
158 if (rom_pointer[1])
159 imx8m_mem_map[5].size -= rom_pointer[1];
160
161 icache_enable();
162 dcache_enable();
163}
164
Peng Fan1caffdf2019-08-27 06:25:17 +0000165static u32 get_cpu_variant_type(u32 type)
166{
167 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
168 struct fuse_bank *bank = &ocotp->bank[1];
169 struct fuse_bank1_regs *fuse =
170 (struct fuse_bank1_regs *)bank->fuse_regs;
171
172 u32 value = readl(&fuse->tester4);
173
Peng Fan67815082020-02-05 17:34:54 +0800174 if (type == MXC_CPU_IMX8MQ) {
175 if ((value & 0x3) == 0x2)
176 return MXC_CPU_IMX8MD;
177 else if (value & 0x200000)
178 return MXC_CPU_IMX8MQL;
179
180 } else if (type == MXC_CPU_IMX8MM) {
Peng Fan1caffdf2019-08-27 06:25:17 +0000181 switch (value & 0x3) {
182 case 2:
183 if (value & 0x1c0000)
184 return MXC_CPU_IMX8MMDL;
185 else
186 return MXC_CPU_IMX8MMD;
187 case 3:
188 if (value & 0x1c0000)
189 return MXC_CPU_IMX8MMSL;
190 else
191 return MXC_CPU_IMX8MMS;
192 default:
193 if (value & 0x1c0000)
194 return MXC_CPU_IMX8MML;
195 break;
196 }
Peng Fan1a07d912020-02-05 17:39:27 +0800197 } else if (type == MXC_CPU_IMX8MN) {
198 switch (value & 0x3) {
199 case 2:
200 if (value & 0x1000000)
201 return MXC_CPU_IMX8MNDL;
202 else
203 return MXC_CPU_IMX8MND;
204 case 3:
205 if (value & 0x1000000)
206 return MXC_CPU_IMX8MNSL;
207 else
208 return MXC_CPU_IMX8MNS;
209 default:
210 if (value & 0x1000000)
211 return MXC_CPU_IMX8MNL;
212 break;
213 }
Peng Fan1caffdf2019-08-27 06:25:17 +0000214 }
215
216 return type;
217}
218
Peng Faneae4de22018-01-10 13:20:37 +0800219u32 get_cpu_rev(void)
220{
221 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
222 u32 reg = readl(&ana_pll->digprog);
223 u32 type = (reg >> 16) & 0xff;
Peng Fan1caffdf2019-08-27 06:25:17 +0000224 u32 major_low = (reg >> 8) & 0xff;
Peng Faneae4de22018-01-10 13:20:37 +0800225 u32 rom_version;
226
227 reg &= 0xff;
228
Peng Fan69cec072019-12-27 10:14:02 +0800229 /* iMX8MP */
230 if (major_low == 0x43) {
231 return (MXC_CPU_IMX8MP << 12) | reg;
232 } else if (major_low == 0x42) {
233 /* iMX8MN */
Peng Fan1a07d912020-02-05 17:39:27 +0800234 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
Peng Fan5d2f2062019-06-27 17:23:49 +0800235 } else if (major_low == 0x41) {
Peng Fan1caffdf2019-08-27 06:25:17 +0000236 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
237 } else {
238 if (reg == CHIP_REV_1_0) {
239 /*
Peng Fanc23fbdd2019-10-16 10:24:17 +0000240 * For B0 chip, the DIGPROG is not updated,
241 * it is still TO1.0. we have to check ROM
242 * version or OCOTP_READ_FUSE_DATA.
243 * 0xff0055aa is magic number for B1.
Peng Fan1caffdf2019-08-27 06:25:17 +0000244 */
Peng Fanc23fbdd2019-10-16 10:24:17 +0000245 if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) {
246 reg = CHIP_REV_2_1;
247 } else {
248 rom_version =
249 readl((void __iomem *)ROM_VERSION_A0);
250 if (rom_version != CHIP_REV_1_0) {
251 rom_version = readl((void __iomem *)ROM_VERSION_B0);
Patrick Wildtd4a78b92019-11-19 09:42:06 +0100252 rom_version &= 0xff;
Peng Fanc23fbdd2019-10-16 10:24:17 +0000253 if (rom_version == CHIP_REV_2_0)
254 reg = CHIP_REV_2_0;
255 }
Peng Fan1caffdf2019-08-27 06:25:17 +0000256 }
Peng Faneae4de22018-01-10 13:20:37 +0800257 }
Peng Fan67815082020-02-05 17:34:54 +0800258
259 type = get_cpu_variant_type(type);
Peng Faneae4de22018-01-10 13:20:37 +0800260 }
261
262 return (type << 12) | reg;
263}
264
265static void imx_set_wdog_powerdown(bool enable)
266{
267 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
268 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
269 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
270
271 /* Write to the PDE (Power Down Enable) bit */
272 writew(enable, &wdog1->wmcr);
273 writew(enable, &wdog2->wmcr);
274 writew(enable, &wdog3->wmcr);
275}
276
Peng Fanc98e0322019-08-27 06:25:58 +0000277int arch_cpu_init_dm(void)
278{
279 struct udevice *dev;
280 int ret;
281
Peng Fan3c073342019-10-16 03:01:51 +0000282 if (CONFIG_IS_ENABLED(CLK)) {
283 ret = uclass_get_device_by_name(UCLASS_CLK,
284 "clock-controller@30380000",
285 &dev);
286 if (ret < 0) {
287 printf("Failed to find clock node. Check device tree\n");
288 return ret;
289 }
Peng Fanc98e0322019-08-27 06:25:58 +0000290 }
291
292 return 0;
293}
294
Peng Faneae4de22018-01-10 13:20:37 +0800295int arch_cpu_init(void)
296{
Peng Fanc0b30d72019-04-17 09:41:16 +0000297 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
Peng Faneae4de22018-01-10 13:20:37 +0800298 /*
Peng Fand0ca2892019-08-27 06:25:37 +0000299 * ROM might disable clock for SCTR,
300 * enable the clock before timer_init.
301 */
302 if (IS_ENABLED(CONFIG_SPL_BUILD))
303 clock_enable(CCGR_SCTR, 1);
304 /*
Peng Faneae4de22018-01-10 13:20:37 +0800305 * Init timer at very early state, because sscg pll setting
306 * will use it
307 */
308 timer_init();
309
310 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
311 clock_init();
312 imx_set_wdog_powerdown(false);
313 }
314
Peng Fanc0b30d72019-04-17 09:41:16 +0000315 if (is_imx8mq()) {
316 clock_enable(CCGR_OCOTP, 1);
317 if (readl(&ocotp->ctrl) & 0x200)
318 writel(0x200, &ocotp->ctrl_clr);
319 }
320
Peng Faneae4de22018-01-10 13:20:37 +0800321 return 0;
322}
323
Peng Fanc9823b02019-09-16 03:09:36 +0000324#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
325struct rom_api *g_rom_api = (struct rom_api *)0x980;
326
327enum boot_device get_boot_device(void)
328{
329 volatile gd_t *pgd = gd;
330 int ret;
331 u32 boot;
332 u16 boot_type;
333 u8 boot_instance;
334 enum boot_device boot_dev = SD1_BOOT;
335
336 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
337 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
338 gd = pgd;
339
340 if (ret != ROM_API_OKAY) {
341 puts("ROMAPI: failure at query_boot_info\n");
342 return -1;
343 }
344
345 boot_type = boot >> 16;
346 boot_instance = (boot >> 8) & 0xff;
347
348 switch (boot_type) {
349 case BT_DEV_TYPE_SD:
350 boot_dev = boot_instance + SD1_BOOT;
351 break;
352 case BT_DEV_TYPE_MMC:
353 boot_dev = boot_instance + MMC1_BOOT;
354 break;
355 case BT_DEV_TYPE_NAND:
356 boot_dev = NAND_BOOT;
357 break;
358 case BT_DEV_TYPE_FLEXSPINOR:
359 boot_dev = QSPI_BOOT;
360 break;
361 case BT_DEV_TYPE_USB:
362 boot_dev = USB_BOOT;
363 break;
364 default:
365 break;
366 }
367
368 return boot_dev;
369}
370#endif
371
Peng Faneae4de22018-01-10 13:20:37 +0800372bool is_usb_boot(void)
373{
374 return get_boot_device() == USB_BOOT;
375}
376
377#ifdef CONFIG_OF_SYSTEM_SETUP
378int ft_system_setup(void *blob, bd_t *bd)
379{
380 int i = 0;
381 int rc;
382 int nodeoff;
383
384 /* Disable the CPU idle for A0 chip since the HW does not support it */
385 if (is_soc_rev(CHIP_REV_1_0)) {
386 static const char * const nodes_path[] = {
387 "/cpus/cpu@0",
388 "/cpus/cpu@1",
389 "/cpus/cpu@2",
390 "/cpus/cpu@3",
391 };
392
393 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
394 nodeoff = fdt_path_offset(blob, nodes_path[i]);
395 if (nodeoff < 0)
396 continue; /* Not found, skip it */
397
Marek Vasute2e7a772020-04-24 21:37:33 +0200398 debug("Found %s node\n", nodes_path[i]);
Peng Faneae4de22018-01-10 13:20:37 +0800399
400 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
Marek Vasute2e7a772020-04-24 21:37:33 +0200401 if (rc == -FDT_ERR_NOTFOUND)
402 continue;
Peng Faneae4de22018-01-10 13:20:37 +0800403 if (rc) {
404 printf("Unable to update property %s:%s, err=%s\n",
405 nodes_path[i], "status", fdt_strerror(rc));
406 return rc;
407 }
408
Marek Vasute2e7a772020-04-24 21:37:33 +0200409 debug("Remove %s:%s\n", nodes_path[i],
Peng Faneae4de22018-01-10 13:20:37 +0800410 "cpu-idle-states");
411 }
412 }
413
414 return 0;
415}
416#endif
417
Marek Vasut64dc4de2020-04-29 15:04:21 +0200418#if !CONFIG_IS_ENABLED(SYSRESET)
Peng Faneae4de22018-01-10 13:20:37 +0800419void reset_cpu(ulong addr)
420{
Claudius Heinee73f3942020-04-29 15:04:23 +0200421 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
Peng Faneae4de22018-01-10 13:20:37 +0800422
Ye Li54a915a2019-12-09 00:47:18 -0800423 /* Clear WDA to trigger WDOG_B immediately */
424 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
Peng Fan24290d92019-08-27 06:25:41 +0000425
Ye Li54a915a2019-12-09 00:47:18 -0800426 while (1) {
427 /*
Harald Seilerec0c4472020-04-29 15:04:22 +0200428 * spin for .5 seconds before reset
Ye Li54a915a2019-12-09 00:47:18 -0800429 */
430 }
Peng Faneae4de22018-01-10 13:20:37 +0800431}
Peng Fan24290d92019-08-27 06:25:41 +0000432#endif
Peng Fan5760d8d2020-04-22 10:51:13 +0800433
434#if defined(CONFIG_ARCH_MISC_INIT)
435static void acquire_buildinfo(void)
436{
437 u64 atf_commit = 0;
Peng Fan45d843a2020-05-11 15:14:04 +0800438 struct arm_smccc_res res;
Peng Fan5760d8d2020-04-22 10:51:13 +0800439
440 /* Get ARM Trusted Firmware commit id */
Peng Fan45d843a2020-05-11 15:14:04 +0800441 arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH,
442 0, 0 , 0, 0, 0, 0, &res);
443 atf_commit = res.a0;
Peng Fan5760d8d2020-04-22 10:51:13 +0800444 if (atf_commit == 0xffffffff) {
445 debug("ATF does not support build info\n");
446 atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */
447 }
448
449 printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit);
450}
451
452int arch_misc_init(void)
453{
454 acquire_buildinfo();
455
456 return 0;
457}
458#endif
Ye Li325cd012020-05-03 22:19:52 +0800459
460void imx_tmu_arch_init(void *reg_base)
461{
Ye Lia00f2f02020-05-03 22:19:53 +0800462 if (is_imx8mm() || is_imx8mn()) {
Ye Li325cd012020-05-03 22:19:52 +0800463 /* Load TCALIV and TASR from fuses */
464 struct ocotp_regs *ocotp =
465 (struct ocotp_regs *)OCOTP_BASE_ADDR;
466 struct fuse_bank *bank = &ocotp->bank[3];
467 struct fuse_bank3_regs *fuse =
468 (struct fuse_bank3_regs *)bank->fuse_regs;
469
470 u32 tca_rt, tca_hr, tca_en;
471 u32 buf_vref, buf_slope;
472
473 tca_rt = fuse->ana0 & 0xFF;
474 tca_hr = (fuse->ana0 & 0xFF00) >> 8;
475 tca_en = (fuse->ana0 & 0x2000000) >> 25;
476
477 buf_vref = (fuse->ana0 & 0x1F00000) >> 20;
478 buf_slope = (fuse->ana0 & 0xF0000) >> 16;
479
480 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
481 writel((tca_en << 31) | (tca_hr << 16) | tca_rt,
482 (ulong)reg_base + 0x30);
483 }
Ye Li41a20252020-05-03 22:19:54 +0800484#ifdef CONFIG_IMX8MP
485 /* Load TCALIV0/1/m40 and TRIM from fuses */
486 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
487 struct fuse_bank *bank = &ocotp->bank[38];
488 struct fuse_bank38_regs *fuse =
489 (struct fuse_bank38_regs *)bank->fuse_regs;
490 struct fuse_bank *bank2 = &ocotp->bank[39];
491 struct fuse_bank39_regs *fuse2 =
492 (struct fuse_bank39_regs *)bank2->fuse_regs;
493 u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr;
494 u32 reg;
495 u32 tca40[2], tca25[2], tca105[2];
496
497 /* For blank sample */
498 if (!fuse->ana_trim2 && !fuse->ana_trim3 &&
499 !fuse->ana_trim4 && !fuse2->ana_trim5) {
500 /* Use a default 25C binary codes */
501 tca25[0] = 1596;
Ye Lid756ca02020-05-03 22:19:55 +0800502 tca25[1] = 1596;
Ye Li41a20252020-05-03 22:19:54 +0800503 writel(tca25[0], (ulong)reg_base + 0x30);
Ye Lid756ca02020-05-03 22:19:55 +0800504 writel(tca25[1], (ulong)reg_base + 0x34);
Ye Li41a20252020-05-03 22:19:54 +0800505 return;
506 }
507
508 buf_vref = (fuse->ana_trim2 & 0xc0) >> 6;
509 buf_slope = (fuse->ana_trim2 & 0xF00) >> 8;
510 bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12;
511 bgr = (fuse->ana_trim2 & 0xF0000) >> 16;
512 vlsb = (fuse->ana_trim2 & 0xF00000) >> 20;
513 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
514
515 reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7);
516 writel(reg, (ulong)reg_base + 0x3c);
517
518 tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16;
519 tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28;
520 tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4);
521 tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8;
522 tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20;
523 tca25[1] = fuse2->ana_trim5 & 0xFFF;
524 tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12;
525
526 /* use 25c for 1p calibration */
527 writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30);
528 writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34);
529 writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38);
530#endif
Ye Li325cd012020-05-03 22:19:52 +0800531}
Peng Fana35215d2020-07-09 13:39:26 +0800532
533#if defined(CONFIG_SPL_BUILD)
534#if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
535bool serror_need_skip = true;
536
537void do_error(struct pt_regs *pt_regs, unsigned int esr)
538{
539 /*
540 * If stack is still in ROM reserved OCRAM not switch to SPL,
541 * it is the ROM SError
542 */
543 ulong sp;
544
545 asm volatile("mov %0, sp" : "=r"(sp) : );
546
547 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
548 /* Check for ERR050342, imx8mq HDCP enabled parts */
549 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
550 serror_need_skip = false;
551 return; /* Do nothing skip the SError in ROM */
552 }
553
554 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
555 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
556 serror_need_skip = false;
557 return; /* Do nothing skip the SError in ROM */
558 }
559 }
560
561 efi_restore_gd();
562 printf("\"Error\" handler, esr 0x%08x\n", esr);
563 show_regs(pt_regs);
564 panic("Resetting CPU ...\n");
565}
566#endif
567#endif