1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014-2015 Freescale Semiconductor
8 #include <clock_legacy.h>
11 #include <fsl_immap.h>
14 #include <linux/sizes.h>
16 #include <asm/arch/fsl_serdes.h>
17 #include <asm/arch/soc.h>
18 #include <asm/cache.h>
20 #include <asm/global_data.h>
21 #include <asm/arch-fsl-layerscape/config.h>
22 #include <asm/arch-fsl-layerscape/ns_access.h>
23 #include <asm/arch-fsl-layerscape/fsl_icid.h>
24 #include <asm/gic-v3.h>
25 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
28 #ifdef CONFIG_SYS_FSL_DDR
29 #include <fsl_ddr_sdram.h>
32 #ifdef CONFIG_CHAIN_OF_TRUST
33 #include <fsl_validate.h>
35 #include <fsl_immap.h>
37 #include <env_internal.h>
40 #include <dm/device_compat.h>
41 #include <linux/err.h>
42 #if defined(CONFIG_TFABOOT) || defined(CONFIG_GIC_V3_ITS)
43 DECLARE_GLOBAL_DATA_PTR;
46 #ifdef CONFIG_GIC_V3_ITS
47 int ls_gic_rd_tables_init(void *blob)
49 struct fdt_memory lpi_base;
54 offset = fdt_path_offset(gd->fdt_blob, "/syscon@0x80000000");
55 addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, offset, "reg",
58 lpi_base.start = addr;
59 lpi_base.end = addr + size - 1;
60 ret = fdtdec_add_reserved_memory(blob, "lpi_rd_table", &lpi_base, NULL, false);
62 debug("%s: failed to add reserved memory\n", __func__);
66 ret = gic_lpi_tables_init();
68 debug("%s: failed to init gic-lpi-tables\n", __func__);
74 bool soc_has_dp_ddr(void)
76 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
77 u32 svr = gur_in32(&gur->svr);
79 /* LS2085A, LS2088A, LS2048A has DP_DDR */
80 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
81 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
82 (SVR_SOC_VER(svr) == SVR_LS2048A))
88 bool soc_has_aiop(void)
90 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
91 u32 svr = gur_in32(&gur->svr);
93 /* LS2085A has AIOP */
94 if (SVR_SOC_VER(svr) == SVR_LS2085A)
100 static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
102 scfg_clrsetbits32(scfg + offset / 4,
104 SCFG_USB_TXVREFTUNE << 6);
107 static void erratum_a009008(void)
109 #ifdef CONFIG_SYS_FSL_ERRATUM_A009008
110 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
112 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
113 defined(CONFIG_ARCH_LS1012A)
114 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
115 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
116 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
117 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
119 #elif defined(CONFIG_ARCH_LS2080A)
120 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
122 #endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
125 static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
127 scfg_clrbits32(scfg + offset / 4,
128 SCFG_USB_SQRXTUNE_MASK << 23);
131 static void erratum_a009798(void)
133 #ifdef CONFIG_SYS_FSL_ERRATUM_A009798
134 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
136 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
137 defined(CONFIG_ARCH_LS1012A)
138 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
139 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
140 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
141 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
143 #elif defined(CONFIG_ARCH_LS2080A)
144 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
146 #endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
149 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
150 defined(CONFIG_ARCH_LS1012A)
151 static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
153 scfg_clrsetbits32(scfg + offset / 4,
155 SCFG_USB_PCSTXSWINGFULL << 9);
159 static void erratum_a008997(void)
161 #ifdef CONFIG_SYS_FSL_ERRATUM_A008997
162 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
163 defined(CONFIG_ARCH_LS1012A)
164 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
166 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
167 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
168 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
169 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
171 #elif defined(CONFIG_ARCH_LS1028A)
172 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
174 DCSR_USB_PCSTXSWINGFULL << 11);
176 #endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
179 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
180 defined(CONFIG_ARCH_LS1012A)
182 #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
183 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
184 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
185 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
186 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
188 #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
189 defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A)
191 #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
192 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
193 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
194 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
195 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
199 static void erratum_a009007(void)
201 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
202 defined(CONFIG_ARCH_LS1012A)
203 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
205 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
206 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
207 usb_phy = (void __iomem *)SCFG_USB_PHY2;
208 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
210 usb_phy = (void __iomem *)SCFG_USB_PHY3;
211 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
213 #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
214 defined(CONFIG_ARCH_LS1028A)
215 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
217 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
218 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
219 #endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
222 #if defined(CONFIG_FSL_LSCH3)
223 static void erratum_a050106(void)
225 #if defined(CONFIG_ARCH_LX2160A)
226 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
228 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
229 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
233 * This erratum requires setting a value to eddrtqcr1 to
234 * optimal the DDR performance.
236 static void erratum_a008336(void)
238 #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
241 #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
242 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
243 if (fsl_ddr_get_version(0) == 0x50200)
244 out_le32(eddrtqcr1, 0x63b30002);
246 #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
247 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
248 if (fsl_ddr_get_version(0) == 0x50200)
249 out_le32(eddrtqcr1, 0x63b30002);
255 * This erratum requires a register write before being Memory
256 * controller 3 being enabled.
258 static void erratum_a008514(void)
260 #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
263 #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
264 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
265 out_le32(eddrtqcr1, 0x63b20002);
269 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
270 #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
272 static unsigned long get_internval_val_mhz(void)
274 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
276 * interval is the number of platform cycles(MHz) between
277 * wake up events generated by EPU.
279 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
282 interval_mhz = simple_strtoul(interval, NULL, 10);
287 void erratum_a009635(void)
290 unsigned long interval_mhz = get_internval_val_mhz();
295 val = in_le32(DCSR_CGACRE5);
296 writel(val | 0x00000200, DCSR_CGACRE5);
298 val = in_le32(EPU_EPCMPR5);
299 writel(interval_mhz, EPU_EPCMPR5);
300 val = in_le32(EPU_EPCCR5);
301 writel(val | 0x82820000, EPU_EPCCR5);
302 val = in_le32(EPU_EPSMCR5);
303 writel(val | 0x002f0000, EPU_EPSMCR5);
304 val = in_le32(EPU_EPECR5);
305 writel(val | 0x20000000, EPU_EPECR5);
306 val = in_le32(EPU_EPGCR);
307 writel(val | 0x80000000, EPU_EPGCR);
309 #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
311 static void erratum_rcw_src(void)
313 #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
314 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
315 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
318 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
319 val &= ~DCFG_PORSR1_RCW_SRC;
320 val |= DCFG_PORSR1_RCW_SRC_NOR;
321 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
325 #define I2C_DEBUG_REG 0x6
326 #define I2C_GLITCH_EN 0x8
328 * This erratum requires setting glitch_en bit to enable
329 * digital glitch filter to improve clock stability.
331 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
332 static void erratum_a009203(void)
334 #ifdef CONFIG_SYS_I2C
336 #ifdef I2C1_BASE_ADDR
337 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
339 writeb(I2C_GLITCH_EN, ptr);
341 #ifdef I2C2_BASE_ADDR
342 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
344 writeb(I2C_GLITCH_EN, ptr);
346 #ifdef I2C3_BASE_ADDR
347 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
349 writeb(I2C_GLITCH_EN, ptr);
351 #ifdef I2C4_BASE_ADDR
352 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
354 writeb(I2C_GLITCH_EN, ptr);
360 void bypass_smmu(void)
363 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
364 out_le32(SMMU_SCR0, val);
365 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
366 out_le32(SMMU_NSCR0, val);
368 void fsl_lsch3_early_init_f(void)
371 #ifdef CONFIG_FSL_IFC
372 init_early_memctl_regs(); /* tighten IFC timing */
374 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
384 #ifdef CONFIG_CHAIN_OF_TRUST
385 /* In case of Secure Boot, the IBR configures the SMMU
386 * to allow only Secure transactions.
387 * SMMU must be reset in bypass mode.
388 * Set the ClientPD bit and Clear the USFCFG Bit
390 if (fsl_check_boot_mode_secure() == 1)
394 #if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
395 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A)
400 /* Get VDD in the unit mV from voltage ID */
401 int get_core_volt_from_fuse(void)
403 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
408 /* get the voltage ID from fuse status register */
409 fusesr = in_le32(&gur->dcfg_fusesr);
410 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
411 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
412 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
413 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
414 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
415 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
417 debug("%s: VID = 0x%x\n", __func__, vid);
419 case 0x00: /* VID isn't supported */
421 debug("%s: The VID feature is not supported\n", __func__);
423 case 0x08: /* 0.9V silicon */
426 case 0x10: /* 1.0V silicon */
429 default: /* Other core voltage */
431 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
434 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
439 #elif defined(CONFIG_FSL_LSCH2)
441 * This erratum requires setting a value to eddrtqcr1 to optimal
442 * the DDR performance. The eddrtqcr1 register is in SCFG space
443 * of LS1043A and the offset is 0x157_020c.
445 #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
446 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
447 #error A009660 and A008514 can not be both enabled.
450 static void erratum_a009660(void)
452 #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
453 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
454 out_be32(eddrtqcr1, 0x63b20042);
458 static void erratum_a008850_early(void)
460 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
462 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
463 CONFIG_SYS_CCI400_OFFSET);
464 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
466 /* Skip if running at lower exception level */
467 if (current_el() < 3)
470 /* disables propagation of barrier transactions to DDRC from CCI400 */
471 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
473 /* disable the re-ordering in DDRC */
474 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
478 void erratum_a008850_post(void)
480 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
482 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
483 CONFIG_SYS_CCI400_OFFSET);
484 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
487 /* Skip if running at lower exception level */
488 if (current_el() < 3)
491 /* enable propagation of barrier transactions to DDRC from CCI400 */
492 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
494 /* enable the re-ordering in DDRC */
495 tmp = ddr_in32(&ddr->eor);
496 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
497 ddr_out32(&ddr->eor, tmp);
501 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
502 void erratum_a010315(void)
506 for (i = PCIE1; i <= PCIE4; i++)
507 if (!is_serdes_configured(i)) {
508 debug("PCIe%d: disabled all R/W permission!\n", i);
509 set_pcie_ns_access(i, 0);
514 static void erratum_a010539(void)
516 #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
517 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
520 porsr1 = in_be32(&gur->porsr1);
521 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
522 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
524 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
528 /* Get VDD in the unit mV from voltage ID */
529 int get_core_volt_from_fuse(void)
531 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
536 fusesr = in_be32(&gur->dcfg_fusesr);
537 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
538 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
539 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
540 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
541 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
542 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
544 debug("%s: VID = 0x%x\n", __func__, vid);
546 case 0x00: /* VID isn't supported */
548 debug("%s: The VID feature is not supported\n", __func__);
550 case 0x08: /* 0.9V silicon */
553 case 0x10: /* 1.0V silicon */
556 default: /* Other core voltage */
558 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
561 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
566 __weak int board_switch_core_volt(u32 vdd)
571 static int setup_core_volt(u32 vdd)
573 return board_setup_core_volt(vdd);
576 #ifdef CONFIG_SYS_FSL_DDR
577 static void ddr_enable_0v9_volt(bool en)
579 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
582 tmp = ddr_in32(&ddr->ddr_cdr1);
585 tmp |= DDR_CDR1_V0PT9_EN;
587 tmp &= ~DDR_CDR1_V0PT9_EN;
589 ddr_out32(&ddr->ddr_cdr1, tmp);
593 int setup_chip_volt(void)
597 vdd = get_core_volt_from_fuse();
598 /* Nothing to do for silicons doesn't support VID */
602 if (setup_core_volt(vdd))
603 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
604 #ifdef CONFIG_SYS_HAS_SERDES
605 if (setup_serdes_volt(vdd))
606 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
609 #ifdef CONFIG_SYS_FSL_DDR
611 ddr_enable_0v9_volt(true);
617 #ifdef CONFIG_FSL_PFE
618 void init_pfe_scfg_dcfg_regs(void)
620 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
623 out_be32(&scfg->pfeasbcr,
624 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
625 out_be32(&scfg->pfebsbcr,
626 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
628 /* CCI-400 QoS settings for PFE */
629 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
630 | SCFG_WR_QOS1_PFE2_QOS));
631 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
632 | SCFG_RD_QOS1_PFE2_QOS));
634 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
635 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
636 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
640 void fsl_lsch2_early_init_f(void)
642 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
643 CONFIG_SYS_CCI400_OFFSET);
644 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
645 #if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
649 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
650 enable_layerscape_ns_access();
653 #ifdef CONFIG_FSL_IFC
654 init_early_memctl_regs(); /* tighten IFC timing */
657 #if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
658 src = get_boot_src();
659 if (src != BOOT_SOURCE_QSPI_NOR)
660 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
662 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
663 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
666 /* Make SEC reads and writes snoopable */
667 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
668 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
669 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
670 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
671 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
672 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
673 SCFG_SNPCNFGCR_SATAWRSNP);
674 #elif defined(CONFIG_ARCH_LS1012A)
675 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
676 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
677 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
678 SCFG_SNPCNFGCR_SATAWRSNP);
680 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
681 SCFG_SNPCNFGCR_SECWRSNP |
682 SCFG_SNPCNFGCR_SATARDSNP |
683 SCFG_SNPCNFGCR_SATAWRSNP);
687 * Enable snoop requests and DVM message requests for
688 * Slave insterface S4 (A53 core cluster)
690 if (current_el() == 3) {
691 out_le32(&cci->slave[4].snoop_ctrl,
692 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
696 * Program Central Security Unit (CSU) to grant access
697 * permission for USB 2.0 controller
699 #if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
700 if (current_el() == 3)
701 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
704 erratum_a008850_early(); /* part 1 of 2 */
712 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
718 #ifdef CONFIG_FSPI_AHB_EN_4BYTE
719 int fspi_ahb_init(void)
721 /* Enable 4bytes address support and fast read */
722 u32 *fspi_lut, lut_key, *fspi_key;
724 fspi_key = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUTKEY_BASE_ADDR;
725 fspi_lut = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUT_BASE_ADDR;
727 lut_key = in_be32(fspi_key);
729 if (lut_key == SYS_NXP_FSPI_LUTKEY) {
730 /* That means the register is BE */
731 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
732 /* Unlock the lut table */
733 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
734 /* Create READ LUT */
735 out_be32(fspi_lut, 0x0820040c);
736 out_be32(fspi_lut + 1, 0x24003008);
737 out_be32(fspi_lut + 2, 0x00000000);
738 /* Lock the lut table */
739 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
740 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
742 /* That means the register is LE */
743 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
744 /* Unlock the lut table */
745 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
746 /* Create READ LUT */
747 out_le32(fspi_lut, 0x0820040c);
748 out_le32(fspi_lut + 1, 0x24003008);
749 out_le32(fspi_lut + 2, 0x00000000);
750 /* Lock the lut table */
751 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
752 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
759 #ifdef CONFIG_QSPI_AHB_INIT
760 /* Enable 4bytes address support and fast read */
761 int qspi_ahb_init(void)
763 u32 *qspi_lut, lut_key, *qspi_key;
765 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
766 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
768 lut_key = in_be32(qspi_key);
770 if (lut_key == 0x5af05af0) {
771 /* That means the register is BE */
772 out_be32(qspi_key, 0x5af05af0);
773 /* Unlock the lut table */
774 out_be32(qspi_key + 1, 0x00000002);
775 out_be32(qspi_lut, 0x0820040c);
776 out_be32(qspi_lut + 1, 0x1c080c08);
777 out_be32(qspi_lut + 2, 0x00002400);
778 /* Lock the lut table */
779 out_be32(qspi_key, 0x5af05af0);
780 out_be32(qspi_key + 1, 0x00000001);
782 /* That means the register is LE */
783 out_le32(qspi_key, 0x5af05af0);
784 /* Unlock the lut table */
785 out_le32(qspi_key + 1, 0x00000002);
786 out_le32(qspi_lut, 0x0820040c);
787 out_le32(qspi_lut + 1, 0x1c080c08);
788 out_le32(qspi_lut + 2, 0x00002400);
789 /* Lock the lut table */
790 out_le32(qspi_key, 0x5af05af0);
791 out_le32(qspi_key + 1, 0x00000001);
798 #ifdef CONFIG_TFABOOT
799 #define MAX_BOOTCMD_SIZE 512
801 int fsl_setenv_bootcmd(void)
804 enum boot_src src = get_boot_src();
805 char bootcmd_str[MAX_BOOTCMD_SIZE];
808 #ifdef IFC_NOR_BOOTCOMMAND
809 case BOOT_SOURCE_IFC_NOR:
810 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
813 #ifdef QSPI_NOR_BOOTCOMMAND
814 case BOOT_SOURCE_QSPI_NOR:
815 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
818 #ifdef XSPI_NOR_BOOTCOMMAND
819 case BOOT_SOURCE_XSPI_NOR:
820 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
823 #ifdef IFC_NAND_BOOTCOMMAND
824 case BOOT_SOURCE_IFC_NAND:
825 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
828 #ifdef QSPI_NAND_BOOTCOMMAND
829 case BOOT_SOURCE_QSPI_NAND:
830 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
833 #ifdef XSPI_NAND_BOOTCOMMAND
834 case BOOT_SOURCE_XSPI_NAND:
835 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
838 #ifdef SD_BOOTCOMMAND
839 case BOOT_SOURCE_SD_MMC:
840 sprintf(bootcmd_str, SD_BOOTCOMMAND);
843 #ifdef SD2_BOOTCOMMAND
844 case BOOT_SOURCE_SD_MMC2:
845 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
849 #ifdef QSPI_NOR_BOOTCOMMAND
850 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
855 ret = env_set("bootcmd", bootcmd_str);
857 printf("Failed to set bootcmd: ret = %d\n", ret);
863 int fsl_setenv_mcinitcmd(void)
866 enum boot_src src = get_boot_src();
869 #ifdef IFC_MC_INIT_CMD
870 case BOOT_SOURCE_IFC_NAND:
871 case BOOT_SOURCE_IFC_NOR:
872 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
875 #ifdef QSPI_MC_INIT_CMD
876 case BOOT_SOURCE_QSPI_NAND:
877 case BOOT_SOURCE_QSPI_NOR:
878 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
881 #ifdef XSPI_MC_INIT_CMD
882 case BOOT_SOURCE_XSPI_NAND:
883 case BOOT_SOURCE_XSPI_NOR:
884 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
887 #ifdef SD_MC_INIT_CMD
888 case BOOT_SOURCE_SD_MMC:
889 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
892 #ifdef SD2_MC_INIT_CMD
893 case BOOT_SOURCE_SD_MMC2:
894 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
898 #ifdef QSPI_MC_INIT_CMD
899 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
905 printf("Failed to set mcinitcmd: ret = %d\n", ret);
912 #ifdef CONFIG_BOARD_LATE_INIT
913 __weak int fsl_board_late_init(void)
918 #define DWC3_GSBUSCFG0 0xc100
919 #define DWC3_GSBUSCFG0_CACHETYPE_SHIFT 16
920 #define DWC3_GSBUSCFG0_CACHETYPE(n) (((n) & 0xffff) \
921 << DWC3_GSBUSCFG0_CACHETYPE_SHIFT)
923 void enable_dwc3_snooping(void)
929 fdt_addr_t dwc3_base;
931 ret = uclass_get(UCLASS_USB, &uc);
935 uclass_foreach_dev(bus, uc) {
936 if (!strcmp(bus->driver->of_match->compatible, "fsl,layerscape-dwc3")) {
937 dwc3_base = devfdt_get_addr(bus);
938 if (dwc3_base == FDT_ADDR_T_NONE) {
939 dev_err(bus, "dwc3 regs missing\n");
942 val = in_le32(dwc3_base + DWC3_GSBUSCFG0);
943 val &= ~DWC3_GSBUSCFG0_CACHETYPE(~0);
944 val |= DWC3_GSBUSCFG0_CACHETYPE(0x2222);
945 writel(val, dwc3_base + DWC3_GSBUSCFG0);
950 int board_late_init(void)
952 #ifdef CONFIG_CHAIN_OF_TRUST
953 fsl_setenv_chain_of_trust();
955 #ifdef CONFIG_TFABOOT
957 * check if gd->env_addr is default_environment; then setenv bootcmd
960 #ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
961 if (gd->env_addr == (ulong)&default_environment[0]) {
963 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
965 fsl_setenv_bootcmd();
966 fsl_setenv_mcinitcmd();
970 * If the boot mode is secure, default environment is not present then
971 * setenv command needs to be run by default
973 #ifdef CONFIG_CHAIN_OF_TRUST
974 if ((fsl_check_boot_mode_secure() == 1)) {
975 fsl_setenv_bootcmd();
976 fsl_setenv_mcinitcmd();
980 #ifdef CONFIG_QSPI_AHB_INIT
983 #ifdef CONFIG_FSPI_AHB_EN_4BYTE
987 if (IS_ENABLED(CONFIG_DM))
988 enable_dwc3_snooping();
990 return fsl_board_late_init();