blob: c103bc3ad10a8b12721a9ec0e5af2f47781eed90 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fanfcdbde72018-01-10 13:20:37 +08002/*
Ye Li70487ff2020-05-03 22:19:52 +08003 * Copyright 2017-2019 NXP
Peng Fanfcdbde72018-01-10 13:20:37 +08004 *
5 * Peng Fan <peng.fan@nxp.com>
Peng Fanfcdbde72018-01-10 13:20:37 +08006 */
7
8#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07009#include <cpu_func.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Peng Fanfcdbde72018-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 Fan2f3c9202020-07-09 13:39:26 +080019#include <asm/ptrace.h>
Peng Fanfcdbde72018-01-10 13:20:37 +080020#include <asm/armv8/mmu.h>
Peng Fane663c702019-08-27 06:25:58 +000021#include <dm/uclass.h>
Peng Fan2f3c9202020-07-09 13:39:26 +080022#include <efi_loader.h>
Peng Fanfcdbde72018-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 Fana2f143e2020-05-11 15:14:04 +080027#include <linux/arm-smccc.h>
Simon Glasscd93d622020-05-10 11:40:13 -060028#include <linux/bitops.h>
Peng Fanfcdbde72018-01-10 13:20:37 +080029
30DECLARE_GLOBAL_DATA_PTR;
31
Stefano Babicd714a752019-09-20 08:47:53 +020032#if defined(CONFIG_IMX_HAB)
Peng Fanfcdbde72018-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 Fana07c7182019-12-27 10:19:42 +080066 if (is_imx8mm() || is_imx8mn() || is_imx8mp())
Peng Fandbb2b7e2019-08-27 06:25:30 +000067 setbits_le32(&gpr->gpr[10], BIT(1));
Ye Lib3cf0a82019-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 Fanfcdbde72018-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 Bissoncb158852018-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 Fanfcdbde72018-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 Fan59efa6b2019-08-27 06:25:27 +0000131 .size = PHYS_SDRAM_SIZE,
Peng Fanfcdbde72018-01-10 13:20:37 +0800132 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
133 PTE_BLOCK_OUTER_SHARE
Peng Fan59efa6b2019-08-27 06:25:27 +0000134#ifdef PHYS_SDRAM_2_SIZE
Peng Fanfcdbde72018-01-10 13:20:37 +0800135 }, {
136 /* DRAM2 */
137 .virt = 0x100000000UL,
138 .phys = 0x100000000UL,
Peng Fan59efa6b2019-08-27 06:25:27 +0000139 .size = PHYS_SDRAM_2_SIZE,
Peng Fanfcdbde72018-01-10 13:20:37 +0800140 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
141 PTE_BLOCK_OUTER_SHARE
Peng Fan59efa6b2019-08-27 06:25:27 +0000142#endif
Peng Fanfcdbde72018-01-10 13:20:37 +0800143 }, {
144 /* List terminator */
145 0,
146 }
147};
148
149struct mm_region *mem_map = imx8m_mem_map;
150
Peng Fan59efa6b2019-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 Fan78db9a52019-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 Fancb1a1de2020-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 Fan78db9a52019-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 Fanc9154032020-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 }
Ye Lid1eee7e2020-04-20 20:12:54 -0700214 } else if (type == MXC_CPU_IMX8MP) {
215 u32 value0 = readl(&fuse->tester3);
216 u32 flag = 0;
217
218 if ((value0 & 0xc0000) == 0x80000)
219 return MXC_CPU_IMX8MPD;
220
221 /* vpu disabled */
222 if ((value0 & 0x43000000) == 0x43000000)
223 flag = 1;
224
225 /* npu disabled*/
226 if ((value & 0x8) == 0x8)
227 flag |= (1 << 1);
228
229 /* isp disabled */
230 if ((value & 0x3) == 0x3)
231 flag |= (1 << 2);
232
233 switch (flag) {
234 case 7:
235 return MXC_CPU_IMX8MPL;
236 case 6:
237 return MXC_CPU_IMX8MP5;
238 case 2:
239 return MXC_CPU_IMX8MP6;
240 case 1:
241 return MXC_CPU_IMX8MP7;
242 default:
243 break;
244 }
245
Peng Fan78db9a52019-08-27 06:25:17 +0000246 }
247
248 return type;
249}
250
Peng Fanfcdbde72018-01-10 13:20:37 +0800251u32 get_cpu_rev(void)
252{
253 struct anamix_pll *ana_pll = (struct anamix_pll *)ANATOP_BASE_ADDR;
254 u32 reg = readl(&ana_pll->digprog);
255 u32 type = (reg >> 16) & 0xff;
Peng Fan78db9a52019-08-27 06:25:17 +0000256 u32 major_low = (reg >> 8) & 0xff;
Peng Fanfcdbde72018-01-10 13:20:37 +0800257 u32 rom_version;
258
259 reg &= 0xff;
260
Peng Fan625b03d2019-12-27 10:14:02 +0800261 /* iMX8MP */
262 if (major_low == 0x43) {
Ye Lid1eee7e2020-04-20 20:12:54 -0700263 type = get_cpu_variant_type(MXC_CPU_IMX8MP);
Peng Fan625b03d2019-12-27 10:14:02 +0800264 } else if (major_low == 0x42) {
265 /* iMX8MN */
Peng Fanc9154032020-02-05 17:39:27 +0800266 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
Peng Fan24341312019-06-27 17:23:49 +0800267 } else if (major_low == 0x41) {
Peng Fan78db9a52019-08-27 06:25:17 +0000268 type = get_cpu_variant_type(MXC_CPU_IMX8MM);
269 } else {
270 if (reg == CHIP_REV_1_0) {
271 /*
Peng Fan9e094452019-10-16 10:24:17 +0000272 * For B0 chip, the DIGPROG is not updated,
273 * it is still TO1.0. we have to check ROM
274 * version or OCOTP_READ_FUSE_DATA.
275 * 0xff0055aa is magic number for B1.
Peng Fan78db9a52019-08-27 06:25:17 +0000276 */
Peng Fan9e094452019-10-16 10:24:17 +0000277 if (readl((void __iomem *)(OCOTP_BASE_ADDR + 0x40)) == 0xff0055aa) {
278 reg = CHIP_REV_2_1;
279 } else {
280 rom_version =
281 readl((void __iomem *)ROM_VERSION_A0);
282 if (rom_version != CHIP_REV_1_0) {
283 rom_version = readl((void __iomem *)ROM_VERSION_B0);
Patrick Wildt6a4b07e2019-11-19 09:42:06 +0100284 rom_version &= 0xff;
Peng Fan9e094452019-10-16 10:24:17 +0000285 if (rom_version == CHIP_REV_2_0)
286 reg = CHIP_REV_2_0;
287 }
Peng Fan78db9a52019-08-27 06:25:17 +0000288 }
Peng Fanfcdbde72018-01-10 13:20:37 +0800289 }
Peng Fancb1a1de2020-02-05 17:34:54 +0800290
291 type = get_cpu_variant_type(type);
Peng Fanfcdbde72018-01-10 13:20:37 +0800292 }
293
294 return (type << 12) | reg;
295}
296
297static void imx_set_wdog_powerdown(bool enable)
298{
299 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
300 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
301 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
302
303 /* Write to the PDE (Power Down Enable) bit */
304 writew(enable, &wdog1->wmcr);
305 writew(enable, &wdog2->wmcr);
306 writew(enable, &wdog3->wmcr);
307}
308
Peng Fane663c702019-08-27 06:25:58 +0000309int arch_cpu_init_dm(void)
310{
311 struct udevice *dev;
312 int ret;
313
Peng Fancd7c8062019-10-16 03:01:51 +0000314 if (CONFIG_IS_ENABLED(CLK)) {
315 ret = uclass_get_device_by_name(UCLASS_CLK,
316 "clock-controller@30380000",
317 &dev);
318 if (ret < 0) {
319 printf("Failed to find clock node. Check device tree\n");
320 return ret;
321 }
Peng Fane663c702019-08-27 06:25:58 +0000322 }
323
324 return 0;
325}
326
Peng Fanfcdbde72018-01-10 13:20:37 +0800327int arch_cpu_init(void)
328{
Peng Fan702339b2019-04-17 09:41:16 +0000329 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
Peng Fanfcdbde72018-01-10 13:20:37 +0800330 /*
Peng Fan0528ba02019-08-27 06:25:37 +0000331 * ROM might disable clock for SCTR,
332 * enable the clock before timer_init.
333 */
334 if (IS_ENABLED(CONFIG_SPL_BUILD))
335 clock_enable(CCGR_SCTR, 1);
336 /*
Peng Fanfcdbde72018-01-10 13:20:37 +0800337 * Init timer at very early state, because sscg pll setting
338 * will use it
339 */
340 timer_init();
341
342 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
343 clock_init();
344 imx_set_wdog_powerdown(false);
345 }
346
Peng Fan702339b2019-04-17 09:41:16 +0000347 if (is_imx8mq()) {
348 clock_enable(CCGR_OCOTP, 1);
349 if (readl(&ocotp->ctrl) & 0x200)
350 writel(0x200, &ocotp->ctrl_clr);
351 }
352
Peng Fanfcdbde72018-01-10 13:20:37 +0800353 return 0;
354}
355
Peng Fanb1821372019-09-16 03:09:36 +0000356#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
357struct rom_api *g_rom_api = (struct rom_api *)0x980;
358
359enum boot_device get_boot_device(void)
360{
361 volatile gd_t *pgd = gd;
362 int ret;
363 u32 boot;
364 u16 boot_type;
365 u8 boot_instance;
366 enum boot_device boot_dev = SD1_BOOT;
367
368 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
369 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
370 gd = pgd;
371
372 if (ret != ROM_API_OKAY) {
373 puts("ROMAPI: failure at query_boot_info\n");
374 return -1;
375 }
376
377 boot_type = boot >> 16;
378 boot_instance = (boot >> 8) & 0xff;
379
380 switch (boot_type) {
381 case BT_DEV_TYPE_SD:
382 boot_dev = boot_instance + SD1_BOOT;
383 break;
384 case BT_DEV_TYPE_MMC:
385 boot_dev = boot_instance + MMC1_BOOT;
386 break;
387 case BT_DEV_TYPE_NAND:
388 boot_dev = NAND_BOOT;
389 break;
390 case BT_DEV_TYPE_FLEXSPINOR:
391 boot_dev = QSPI_BOOT;
392 break;
393 case BT_DEV_TYPE_USB:
394 boot_dev = USB_BOOT;
395 break;
396 default:
397 break;
398 }
399
400 return boot_dev;
401}
402#endif
403
Peng Fanfcdbde72018-01-10 13:20:37 +0800404bool is_usb_boot(void)
405{
406 return get_boot_device() == USB_BOOT;
407}
408
409#ifdef CONFIG_OF_SYSTEM_SETUP
410int ft_system_setup(void *blob, bd_t *bd)
411{
412 int i = 0;
413 int rc;
414 int nodeoff;
415
416 /* Disable the CPU idle for A0 chip since the HW does not support it */
417 if (is_soc_rev(CHIP_REV_1_0)) {
418 static const char * const nodes_path[] = {
419 "/cpus/cpu@0",
420 "/cpus/cpu@1",
421 "/cpus/cpu@2",
422 "/cpus/cpu@3",
423 };
424
425 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
426 nodeoff = fdt_path_offset(blob, nodes_path[i]);
427 if (nodeoff < 0)
428 continue; /* Not found, skip it */
429
Marek Vasutdabaabd2020-04-24 21:37:33 +0200430 debug("Found %s node\n", nodes_path[i]);
Peng Fanfcdbde72018-01-10 13:20:37 +0800431
432 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
Marek Vasutdabaabd2020-04-24 21:37:33 +0200433 if (rc == -FDT_ERR_NOTFOUND)
434 continue;
Peng Fanfcdbde72018-01-10 13:20:37 +0800435 if (rc) {
436 printf("Unable to update property %s:%s, err=%s\n",
437 nodes_path[i], "status", fdt_strerror(rc));
438 return rc;
439 }
440
Marek Vasutdabaabd2020-04-24 21:37:33 +0200441 debug("Remove %s:%s\n", nodes_path[i],
Peng Fanfcdbde72018-01-10 13:20:37 +0800442 "cpu-idle-states");
443 }
444 }
445
446 return 0;
447}
448#endif
449
Marek Vasutefa1a622020-04-29 15:04:21 +0200450#if !CONFIG_IS_ENABLED(SYSRESET)
Peng Fanfcdbde72018-01-10 13:20:37 +0800451void reset_cpu(ulong addr)
452{
Claudius Heinec5635a02020-04-29 15:04:23 +0200453 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
Peng Fanfcdbde72018-01-10 13:20:37 +0800454
Ye Li72479742019-12-09 00:47:18 -0800455 /* Clear WDA to trigger WDOG_B immediately */
456 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
Peng Fand2041722019-08-27 06:25:41 +0000457
Ye Li72479742019-12-09 00:47:18 -0800458 while (1) {
459 /*
Harald Seiler568af922020-04-29 15:04:22 +0200460 * spin for .5 seconds before reset
Ye Li72479742019-12-09 00:47:18 -0800461 */
462 }
Peng Fanfcdbde72018-01-10 13:20:37 +0800463}
Peng Fand2041722019-08-27 06:25:41 +0000464#endif
Peng Fana07bcec2020-04-22 10:51:13 +0800465
466#if defined(CONFIG_ARCH_MISC_INIT)
467static void acquire_buildinfo(void)
468{
469 u64 atf_commit = 0;
Peng Fana2f143e2020-05-11 15:14:04 +0800470 struct arm_smccc_res res;
Peng Fana07bcec2020-04-22 10:51:13 +0800471
472 /* Get ARM Trusted Firmware commit id */
Peng Fana2f143e2020-05-11 15:14:04 +0800473 arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH,
474 0, 0 , 0, 0, 0, 0, &res);
475 atf_commit = res.a0;
Peng Fana07bcec2020-04-22 10:51:13 +0800476 if (atf_commit == 0xffffffff) {
477 debug("ATF does not support build info\n");
478 atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */
479 }
480
481 printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit);
482}
483
484int arch_misc_init(void)
485{
486 acquire_buildinfo();
487
488 return 0;
489}
490#endif
Ye Li70487ff2020-05-03 22:19:52 +0800491
492void imx_tmu_arch_init(void *reg_base)
493{
Ye Li94c693d2020-05-03 22:19:53 +0800494 if (is_imx8mm() || is_imx8mn()) {
Ye Li70487ff2020-05-03 22:19:52 +0800495 /* Load TCALIV and TASR from fuses */
496 struct ocotp_regs *ocotp =
497 (struct ocotp_regs *)OCOTP_BASE_ADDR;
498 struct fuse_bank *bank = &ocotp->bank[3];
499 struct fuse_bank3_regs *fuse =
500 (struct fuse_bank3_regs *)bank->fuse_regs;
501
502 u32 tca_rt, tca_hr, tca_en;
503 u32 buf_vref, buf_slope;
504
505 tca_rt = fuse->ana0 & 0xFF;
506 tca_hr = (fuse->ana0 & 0xFF00) >> 8;
507 tca_en = (fuse->ana0 & 0x2000000) >> 25;
508
509 buf_vref = (fuse->ana0 & 0x1F00000) >> 20;
510 buf_slope = (fuse->ana0 & 0xF0000) >> 16;
511
512 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
513 writel((tca_en << 31) | (tca_hr << 16) | tca_rt,
514 (ulong)reg_base + 0x30);
515 }
Ye Liebb9aab2020-05-03 22:19:54 +0800516#ifdef CONFIG_IMX8MP
517 /* Load TCALIV0/1/m40 and TRIM from fuses */
518 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
519 struct fuse_bank *bank = &ocotp->bank[38];
520 struct fuse_bank38_regs *fuse =
521 (struct fuse_bank38_regs *)bank->fuse_regs;
522 struct fuse_bank *bank2 = &ocotp->bank[39];
523 struct fuse_bank39_regs *fuse2 =
524 (struct fuse_bank39_regs *)bank2->fuse_regs;
525 u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr;
526 u32 reg;
527 u32 tca40[2], tca25[2], tca105[2];
528
529 /* For blank sample */
530 if (!fuse->ana_trim2 && !fuse->ana_trim3 &&
531 !fuse->ana_trim4 && !fuse2->ana_trim5) {
532 /* Use a default 25C binary codes */
533 tca25[0] = 1596;
Ye Li3462b552020-05-03 22:19:55 +0800534 tca25[1] = 1596;
Ye Liebb9aab2020-05-03 22:19:54 +0800535 writel(tca25[0], (ulong)reg_base + 0x30);
Ye Li3462b552020-05-03 22:19:55 +0800536 writel(tca25[1], (ulong)reg_base + 0x34);
Ye Liebb9aab2020-05-03 22:19:54 +0800537 return;
538 }
539
540 buf_vref = (fuse->ana_trim2 & 0xc0) >> 6;
541 buf_slope = (fuse->ana_trim2 & 0xF00) >> 8;
542 bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12;
543 bgr = (fuse->ana_trim2 & 0xF0000) >> 16;
544 vlsb = (fuse->ana_trim2 & 0xF00000) >> 20;
545 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
546
547 reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7);
548 writel(reg, (ulong)reg_base + 0x3c);
549
550 tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16;
551 tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28;
552 tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4);
553 tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8;
554 tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20;
555 tca25[1] = fuse2->ana_trim5 & 0xFFF;
556 tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12;
557
558 /* use 25c for 1p calibration */
559 writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30);
560 writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34);
561 writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38);
562#endif
Ye Li70487ff2020-05-03 22:19:52 +0800563}
Peng Fan2f3c9202020-07-09 13:39:26 +0800564
565#if defined(CONFIG_SPL_BUILD)
566#if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
567bool serror_need_skip = true;
568
569void do_error(struct pt_regs *pt_regs, unsigned int esr)
570{
571 /*
572 * If stack is still in ROM reserved OCRAM not switch to SPL,
573 * it is the ROM SError
574 */
575 ulong sp;
576
577 asm volatile("mov %0, sp" : "=r"(sp) : );
578
579 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
580 /* Check for ERR050342, imx8mq HDCP enabled parts */
581 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
582 serror_need_skip = false;
583 return; /* Do nothing skip the SError in ROM */
584 }
585
586 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
587 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
588 serror_need_skip = false;
589 return; /* Do nothing skip the SError in ROM */
590 }
591 }
592
593 efi_restore_gd();
594 printf("\"Error\" handler, esr 0x%08x\n", esr);
595 show_regs(pt_regs);
596 panic("Resetting CPU ...\n");
597}
598#endif
599#endif