blob: f74a343ed8abb769833b24b7808589b021ac27b7 [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 }
Ye Lid2d754f2020-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 Fan1caffdf2019-08-27 06:25:17 +0000246 }
247
248 return type;
249}
250
Peng Faneae4de22018-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 Fan1caffdf2019-08-27 06:25:17 +0000256 u32 major_low = (reg >> 8) & 0xff;
Peng Faneae4de22018-01-10 13:20:37 +0800257 u32 rom_version;
258
259 reg &= 0xff;
260
Peng Fan69cec072019-12-27 10:14:02 +0800261 /* iMX8MP */
262 if (major_low == 0x43) {
Ye Lid2d754f2020-04-20 20:12:54 -0700263 type = get_cpu_variant_type(MXC_CPU_IMX8MP);
Peng Fan69cec072019-12-27 10:14:02 +0800264 } else if (major_low == 0x42) {
265 /* iMX8MN */
Peng Fan1a07d912020-02-05 17:39:27 +0800266 type = get_cpu_variant_type(MXC_CPU_IMX8MN);
Peng Fan5d2f2062019-06-27 17:23:49 +0800267 } else if (major_low == 0x41) {
Peng Fan1caffdf2019-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 Fanc23fbdd2019-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 Fan1caffdf2019-08-27 06:25:17 +0000276 */
Peng Fanc23fbdd2019-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 Wildtd4a78b92019-11-19 09:42:06 +0100284 rom_version &= 0xff;
Peng Fanc23fbdd2019-10-16 10:24:17 +0000285 if (rom_version == CHIP_REV_2_0)
286 reg = CHIP_REV_2_0;
287 }
Peng Fan1caffdf2019-08-27 06:25:17 +0000288 }
Peng Faneae4de22018-01-10 13:20:37 +0800289 }
Peng Fan67815082020-02-05 17:34:54 +0800290
291 type = get_cpu_variant_type(type);
Peng Faneae4de22018-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 Fanc98e0322019-08-27 06:25:58 +0000309int arch_cpu_init_dm(void)
310{
311 struct udevice *dev;
312 int ret;
313
Peng Fan3c073342019-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 Fanc98e0322019-08-27 06:25:58 +0000322 }
323
324 return 0;
325}
326
Peng Faneae4de22018-01-10 13:20:37 +0800327int arch_cpu_init(void)
328{
Peng Fanc0b30d72019-04-17 09:41:16 +0000329 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
Peng Faneae4de22018-01-10 13:20:37 +0800330 /*
Peng Fand0ca2892019-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 Faneae4de22018-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);
Peng Fan9cf2aa32020-07-09 13:52:41 +0800345
346 if (is_imx8md() || is_imx8mmd() || is_imx8mmdl() || is_imx8mms() ||
347 is_imx8mmsl() || is_imx8mnd() || is_imx8mndl() || is_imx8mns() ||
348 is_imx8mnsl() || is_imx8mpd()) {
349 /* Power down cpu core 1, 2 and 3 for iMX8M Dual core or Single core */
350 struct pgc_reg *pgc_core1 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x840);
351 struct pgc_reg *pgc_core2 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x880);
352 struct pgc_reg *pgc_core3 = (struct pgc_reg *)(GPC_BASE_ADDR + 0x8C0);
353 struct gpc_reg *gpc = (struct gpc_reg *)GPC_BASE_ADDR;
354
355 writel(0x1, &pgc_core2->pgcr);
356 writel(0x1, &pgc_core3->pgcr);
357 if (is_imx8mms() || is_imx8mmsl() || is_imx8mns() || is_imx8mnsl()) {
358 writel(0x1, &pgc_core1->pgcr);
359 writel(0xE, &gpc->cpu_pgc_dn_trg);
360 } else {
361 writel(0xC, &gpc->cpu_pgc_dn_trg);
362 }
363 }
Peng Faneae4de22018-01-10 13:20:37 +0800364 }
365
Peng Fanc0b30d72019-04-17 09:41:16 +0000366 if (is_imx8mq()) {
367 clock_enable(CCGR_OCOTP, 1);
368 if (readl(&ocotp->ctrl) & 0x200)
369 writel(0x200, &ocotp->ctrl_clr);
370 }
371
Peng Faneae4de22018-01-10 13:20:37 +0800372 return 0;
373}
374
Peng Fanc9823b02019-09-16 03:09:36 +0000375#if defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
376struct rom_api *g_rom_api = (struct rom_api *)0x980;
377
378enum boot_device get_boot_device(void)
379{
380 volatile gd_t *pgd = gd;
381 int ret;
382 u32 boot;
383 u16 boot_type;
384 u8 boot_instance;
385 enum boot_device boot_dev = SD1_BOOT;
386
387 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
388 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
389 gd = pgd;
390
391 if (ret != ROM_API_OKAY) {
392 puts("ROMAPI: failure at query_boot_info\n");
393 return -1;
394 }
395
396 boot_type = boot >> 16;
397 boot_instance = (boot >> 8) & 0xff;
398
399 switch (boot_type) {
400 case BT_DEV_TYPE_SD:
401 boot_dev = boot_instance + SD1_BOOT;
402 break;
403 case BT_DEV_TYPE_MMC:
404 boot_dev = boot_instance + MMC1_BOOT;
405 break;
406 case BT_DEV_TYPE_NAND:
407 boot_dev = NAND_BOOT;
408 break;
409 case BT_DEV_TYPE_FLEXSPINOR:
410 boot_dev = QSPI_BOOT;
411 break;
412 case BT_DEV_TYPE_USB:
413 boot_dev = USB_BOOT;
414 break;
415 default:
416 break;
417 }
418
419 return boot_dev;
420}
421#endif
422
Peng Faneae4de22018-01-10 13:20:37 +0800423bool is_usb_boot(void)
424{
425 return get_boot_device() == USB_BOOT;
426}
427
428#ifdef CONFIG_OF_SYSTEM_SETUP
429int ft_system_setup(void *blob, bd_t *bd)
430{
431 int i = 0;
432 int rc;
433 int nodeoff;
434
435 /* Disable the CPU idle for A0 chip since the HW does not support it */
436 if (is_soc_rev(CHIP_REV_1_0)) {
437 static const char * const nodes_path[] = {
438 "/cpus/cpu@0",
439 "/cpus/cpu@1",
440 "/cpus/cpu@2",
441 "/cpus/cpu@3",
442 };
443
444 for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
445 nodeoff = fdt_path_offset(blob, nodes_path[i]);
446 if (nodeoff < 0)
447 continue; /* Not found, skip it */
448
Marek Vasute2e7a772020-04-24 21:37:33 +0200449 debug("Found %s node\n", nodes_path[i]);
Peng Faneae4de22018-01-10 13:20:37 +0800450
451 rc = fdt_delprop(blob, nodeoff, "cpu-idle-states");
Marek Vasute2e7a772020-04-24 21:37:33 +0200452 if (rc == -FDT_ERR_NOTFOUND)
453 continue;
Peng Faneae4de22018-01-10 13:20:37 +0800454 if (rc) {
455 printf("Unable to update property %s:%s, err=%s\n",
456 nodes_path[i], "status", fdt_strerror(rc));
457 return rc;
458 }
459
Marek Vasute2e7a772020-04-24 21:37:33 +0200460 debug("Remove %s:%s\n", nodes_path[i],
Peng Faneae4de22018-01-10 13:20:37 +0800461 "cpu-idle-states");
462 }
463 }
464
465 return 0;
466}
467#endif
468
Marek Vasut64dc4de2020-04-29 15:04:21 +0200469#if !CONFIG_IS_ENABLED(SYSRESET)
Peng Faneae4de22018-01-10 13:20:37 +0800470void reset_cpu(ulong addr)
471{
Claudius Heinee73f3942020-04-29 15:04:23 +0200472 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
Peng Faneae4de22018-01-10 13:20:37 +0800473
Ye Li54a915a2019-12-09 00:47:18 -0800474 /* Clear WDA to trigger WDOG_B immediately */
475 writew((SET_WCR_WT(1) | WCR_WDT | WCR_WDE | WCR_SRS), &wdog->wcr);
Peng Fan24290d92019-08-27 06:25:41 +0000476
Ye Li54a915a2019-12-09 00:47:18 -0800477 while (1) {
478 /*
Harald Seilerec0c4472020-04-29 15:04:22 +0200479 * spin for .5 seconds before reset
Ye Li54a915a2019-12-09 00:47:18 -0800480 */
481 }
Peng Faneae4de22018-01-10 13:20:37 +0800482}
Peng Fan24290d92019-08-27 06:25:41 +0000483#endif
Peng Fan5760d8d2020-04-22 10:51:13 +0800484
485#if defined(CONFIG_ARCH_MISC_INIT)
486static void acquire_buildinfo(void)
487{
488 u64 atf_commit = 0;
Peng Fan45d843a2020-05-11 15:14:04 +0800489 struct arm_smccc_res res;
Peng Fan5760d8d2020-04-22 10:51:13 +0800490
491 /* Get ARM Trusted Firmware commit id */
Peng Fan45d843a2020-05-11 15:14:04 +0800492 arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH,
493 0, 0 , 0, 0, 0, 0, &res);
494 atf_commit = res.a0;
Peng Fan5760d8d2020-04-22 10:51:13 +0800495 if (atf_commit == 0xffffffff) {
496 debug("ATF does not support build info\n");
497 atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */
498 }
499
500 printf("\n BuildInfo:\n - ATF %s\n\n", (char *)&atf_commit);
501}
502
503int arch_misc_init(void)
504{
505 acquire_buildinfo();
506
507 return 0;
508}
509#endif
Ye Li325cd012020-05-03 22:19:52 +0800510
511void imx_tmu_arch_init(void *reg_base)
512{
Ye Lia00f2f02020-05-03 22:19:53 +0800513 if (is_imx8mm() || is_imx8mn()) {
Ye Li325cd012020-05-03 22:19:52 +0800514 /* Load TCALIV and TASR from fuses */
515 struct ocotp_regs *ocotp =
516 (struct ocotp_regs *)OCOTP_BASE_ADDR;
517 struct fuse_bank *bank = &ocotp->bank[3];
518 struct fuse_bank3_regs *fuse =
519 (struct fuse_bank3_regs *)bank->fuse_regs;
520
521 u32 tca_rt, tca_hr, tca_en;
522 u32 buf_vref, buf_slope;
523
524 tca_rt = fuse->ana0 & 0xFF;
525 tca_hr = (fuse->ana0 & 0xFF00) >> 8;
526 tca_en = (fuse->ana0 & 0x2000000) >> 25;
527
528 buf_vref = (fuse->ana0 & 0x1F00000) >> 20;
529 buf_slope = (fuse->ana0 & 0xF0000) >> 16;
530
531 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
532 writel((tca_en << 31) | (tca_hr << 16) | tca_rt,
533 (ulong)reg_base + 0x30);
534 }
Ye Li41a20252020-05-03 22:19:54 +0800535#ifdef CONFIG_IMX8MP
536 /* Load TCALIV0/1/m40 and TRIM from fuses */
537 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
538 struct fuse_bank *bank = &ocotp->bank[38];
539 struct fuse_bank38_regs *fuse =
540 (struct fuse_bank38_regs *)bank->fuse_regs;
541 struct fuse_bank *bank2 = &ocotp->bank[39];
542 struct fuse_bank39_regs *fuse2 =
543 (struct fuse_bank39_regs *)bank2->fuse_regs;
544 u32 buf_vref, buf_slope, bjt_cur, vlsb, bgr;
545 u32 reg;
546 u32 tca40[2], tca25[2], tca105[2];
547
548 /* For blank sample */
549 if (!fuse->ana_trim2 && !fuse->ana_trim3 &&
550 !fuse->ana_trim4 && !fuse2->ana_trim5) {
551 /* Use a default 25C binary codes */
552 tca25[0] = 1596;
Ye Lid756ca02020-05-03 22:19:55 +0800553 tca25[1] = 1596;
Ye Li41a20252020-05-03 22:19:54 +0800554 writel(tca25[0], (ulong)reg_base + 0x30);
Ye Lid756ca02020-05-03 22:19:55 +0800555 writel(tca25[1], (ulong)reg_base + 0x34);
Ye Li41a20252020-05-03 22:19:54 +0800556 return;
557 }
558
559 buf_vref = (fuse->ana_trim2 & 0xc0) >> 6;
560 buf_slope = (fuse->ana_trim2 & 0xF00) >> 8;
561 bjt_cur = (fuse->ana_trim2 & 0xF000) >> 12;
562 bgr = (fuse->ana_trim2 & 0xF0000) >> 16;
563 vlsb = (fuse->ana_trim2 & 0xF00000) >> 20;
564 writel(buf_vref | (buf_slope << 16), (ulong)reg_base + 0x28);
565
566 reg = (bgr << 28) | (bjt_cur << 20) | (vlsb << 12) | (1 << 7);
567 writel(reg, (ulong)reg_base + 0x3c);
568
569 tca40[0] = (fuse->ana_trim3 & 0xFFF0000) >> 16;
570 tca25[0] = (fuse->ana_trim3 & 0xF0000000) >> 28;
571 tca25[0] |= ((fuse->ana_trim4 & 0xFF) << 4);
572 tca105[0] = (fuse->ana_trim4 & 0xFFF00) >> 8;
573 tca40[1] = (fuse->ana_trim4 & 0xFFF00000) >> 20;
574 tca25[1] = fuse2->ana_trim5 & 0xFFF;
575 tca105[1] = (fuse2->ana_trim5 & 0xFFF000) >> 12;
576
577 /* use 25c for 1p calibration */
578 writel(tca25[0] | (tca105[0] << 16), (ulong)reg_base + 0x30);
579 writel(tca25[1] | (tca105[1] << 16), (ulong)reg_base + 0x34);
580 writel(tca40[0] | (tca40[1] << 16), (ulong)reg_base + 0x38);
581#endif
Ye Li325cd012020-05-03 22:19:52 +0800582}
Peng Fana35215d2020-07-09 13:39:26 +0800583
584#if defined(CONFIG_SPL_BUILD)
585#if defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN)
586bool serror_need_skip = true;
587
588void do_error(struct pt_regs *pt_regs, unsigned int esr)
589{
590 /*
591 * If stack is still in ROM reserved OCRAM not switch to SPL,
592 * it is the ROM SError
593 */
594 ulong sp;
595
596 asm volatile("mov %0, sp" : "=r"(sp) : );
597
598 if (serror_need_skip && sp < 0x910000 && sp >= 0x900000) {
599 /* Check for ERR050342, imx8mq HDCP enabled parts */
600 if (is_imx8mq() && !(readl(OCOTP_BASE_ADDR + 0x450) & 0x08000000)) {
601 serror_need_skip = false;
602 return; /* Do nothing skip the SError in ROM */
603 }
604
605 /* Check for ERR050350, field return mode for imx8mq, mm and mn */
606 if (readl(OCOTP_BASE_ADDR + 0x630) & 0x1) {
607 serror_need_skip = false;
608 return; /* Do nothing skip the SError in ROM */
609 }
610 }
611
612 efi_restore_gd();
613 printf("\"Error\" handler, esr 0x%08x\n", esr);
614 show_regs(pt_regs);
615 panic("Resetting CPU ...\n");
616}
617#endif
618#endif