1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014-2015 Freescale Semiconductor
12 #include <asm/arch/fsl_serdes.h>
13 #include <asm/arch/soc.h>
15 #include <asm/global_data.h>
16 #include <asm/arch-fsl-layerscape/config.h>
17 #include <asm/arch-fsl-layerscape/ns_access.h>
18 #include <asm/arch-fsl-layerscape/fsl_icid.h>
19 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
22 #ifdef CONFIG_SYS_FSL_DDR
23 #include <fsl_ddr_sdram.h>
26 #ifdef CONFIG_CHAIN_OF_TRUST
27 #include <fsl_validate.h>
29 #include <fsl_immap.h>
31 #include <env_internal.h>
32 DECLARE_GLOBAL_DATA_PTR;
35 bool soc_has_dp_ddr(void)
37 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
38 u32 svr = gur_in32(&gur->svr);
40 /* LS2085A, LS2088A, LS2048A has DP_DDR */
41 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
42 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
43 (SVR_SOC_VER(svr) == SVR_LS2048A))
49 bool soc_has_aiop(void)
51 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
52 u32 svr = gur_in32(&gur->svr);
54 /* LS2085A has AIOP */
55 if (SVR_SOC_VER(svr) == SVR_LS2085A)
61 static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
63 scfg_clrsetbits32(scfg + offset / 4,
65 SCFG_USB_TXVREFTUNE << 6);
68 static void erratum_a009008(void)
70 #ifdef CONFIG_SYS_FSL_ERRATUM_A009008
71 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
73 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
74 defined(CONFIG_ARCH_LS1012A)
75 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
76 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
77 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
78 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
80 #elif defined(CONFIG_ARCH_LS2080A)
81 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
83 #endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
86 static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
88 scfg_clrbits32(scfg + offset / 4,
89 SCFG_USB_SQRXTUNE_MASK << 23);
92 static void erratum_a009798(void)
94 #ifdef CONFIG_SYS_FSL_ERRATUM_A009798
95 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
97 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
98 defined(CONFIG_ARCH_LS1012A)
99 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
100 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
101 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
102 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
104 #elif defined(CONFIG_ARCH_LS2080A)
105 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
107 #endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
110 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
111 defined(CONFIG_ARCH_LS1012A)
112 static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
114 scfg_clrsetbits32(scfg + offset / 4,
116 SCFG_USB_PCSTXSWINGFULL << 9);
120 static void erratum_a008997(void)
122 #ifdef CONFIG_SYS_FSL_ERRATUM_A008997
123 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
124 defined(CONFIG_ARCH_LS1012A)
125 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
127 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
128 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
129 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
130 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
132 #elif defined(CONFIG_ARCH_LS1028A)
133 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
135 DCSR_USB_PCSTXSWINGFULL << 11);
137 #endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
140 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
141 defined(CONFIG_ARCH_LS1012A)
143 #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
144 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
145 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
146 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
147 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
149 #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
150 defined(CONFIG_ARCH_LS1028A)
152 #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
153 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
154 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
155 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
156 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
160 static void erratum_a009007(void)
162 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
163 defined(CONFIG_ARCH_LS1012A)
164 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
166 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
167 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
168 usb_phy = (void __iomem *)SCFG_USB_PHY2;
169 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
171 usb_phy = (void __iomem *)SCFG_USB_PHY3;
172 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
174 #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
175 defined(CONFIG_ARCH_LS1028A)
176 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
178 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
179 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
180 #endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
183 #if defined(CONFIG_FSL_LSCH3)
185 * This erratum requires setting a value to eddrtqcr1 to
186 * optimal the DDR performance.
188 static void erratum_a008336(void)
190 #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
193 #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
194 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
195 if (fsl_ddr_get_version(0) == 0x50200)
196 out_le32(eddrtqcr1, 0x63b30002);
198 #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
199 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
200 if (fsl_ddr_get_version(0) == 0x50200)
201 out_le32(eddrtqcr1, 0x63b30002);
207 * This erratum requires a register write before being Memory
208 * controller 3 being enabled.
210 static void erratum_a008514(void)
212 #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
215 #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
216 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
217 out_le32(eddrtqcr1, 0x63b20002);
221 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
222 #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
224 static unsigned long get_internval_val_mhz(void)
226 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
228 * interval is the number of platform cycles(MHz) between
229 * wake up events generated by EPU.
231 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
234 interval_mhz = simple_strtoul(interval, NULL, 10);
239 void erratum_a009635(void)
242 unsigned long interval_mhz = get_internval_val_mhz();
247 val = in_le32(DCSR_CGACRE5);
248 writel(val | 0x00000200, DCSR_CGACRE5);
250 val = in_le32(EPU_EPCMPR5);
251 writel(interval_mhz, EPU_EPCMPR5);
252 val = in_le32(EPU_EPCCR5);
253 writel(val | 0x82820000, EPU_EPCCR5);
254 val = in_le32(EPU_EPSMCR5);
255 writel(val | 0x002f0000, EPU_EPSMCR5);
256 val = in_le32(EPU_EPECR5);
257 writel(val | 0x20000000, EPU_EPECR5);
258 val = in_le32(EPU_EPGCR);
259 writel(val | 0x80000000, EPU_EPGCR);
261 #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
263 static void erratum_rcw_src(void)
265 #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
266 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
267 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
270 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
271 val &= ~DCFG_PORSR1_RCW_SRC;
272 val |= DCFG_PORSR1_RCW_SRC_NOR;
273 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
277 #define I2C_DEBUG_REG 0x6
278 #define I2C_GLITCH_EN 0x8
280 * This erratum requires setting glitch_en bit to enable
281 * digital glitch filter to improve clock stability.
283 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
284 static void erratum_a009203(void)
286 #ifdef CONFIG_SYS_I2C
288 #ifdef I2C1_BASE_ADDR
289 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
291 writeb(I2C_GLITCH_EN, ptr);
293 #ifdef I2C2_BASE_ADDR
294 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
296 writeb(I2C_GLITCH_EN, ptr);
298 #ifdef I2C3_BASE_ADDR
299 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
301 writeb(I2C_GLITCH_EN, ptr);
303 #ifdef I2C4_BASE_ADDR
304 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
306 writeb(I2C_GLITCH_EN, ptr);
312 void bypass_smmu(void)
315 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
316 out_le32(SMMU_SCR0, val);
317 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
318 out_le32(SMMU_NSCR0, val);
320 void fsl_lsch3_early_init_f(void)
323 #ifdef CONFIG_FSL_IFC
324 init_early_memctl_regs(); /* tighten IFC timing */
326 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
335 #ifdef CONFIG_CHAIN_OF_TRUST
336 /* In case of Secure Boot, the IBR configures the SMMU
337 * to allow only Secure transactions.
338 * SMMU must be reset in bypass mode.
339 * Set the ClientPD bit and Clear the USFCFG Bit
341 if (fsl_check_boot_mode_secure() == 1)
345 #if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
346 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A)
351 /* Get VDD in the unit mV from voltage ID */
352 int get_core_volt_from_fuse(void)
354 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
359 /* get the voltage ID from fuse status register */
360 fusesr = in_le32(&gur->dcfg_fusesr);
361 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
362 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
363 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
364 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
365 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
366 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
368 debug("%s: VID = 0x%x\n", __func__, vid);
370 case 0x00: /* VID isn't supported */
372 debug("%s: The VID feature is not supported\n", __func__);
374 case 0x08: /* 0.9V silicon */
377 case 0x10: /* 1.0V silicon */
380 default: /* Other core voltage */
382 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
385 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
390 #elif defined(CONFIG_FSL_LSCH2)
392 static void erratum_a009929(void)
394 #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
395 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
396 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
397 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
399 rstrqmr1 |= 0x00000400;
400 gur_out32(&gur->rstrqmr1, rstrqmr1);
401 writel(0x01000000, dcsr_cop_ccp);
406 * This erratum requires setting a value to eddrtqcr1 to optimal
407 * the DDR performance. The eddrtqcr1 register is in SCFG space
408 * of LS1043A and the offset is 0x157_020c.
410 #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
411 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
412 #error A009660 and A008514 can not be both enabled.
415 static void erratum_a009660(void)
417 #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
418 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
419 out_be32(eddrtqcr1, 0x63b20042);
423 static void erratum_a008850_early(void)
425 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
427 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
428 CONFIG_SYS_CCI400_OFFSET);
429 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
431 /* Skip if running at lower exception level */
432 if (current_el() < 3)
435 /* disables propagation of barrier transactions to DDRC from CCI400 */
436 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
438 /* disable the re-ordering in DDRC */
439 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
443 void erratum_a008850_post(void)
445 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
447 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
448 CONFIG_SYS_CCI400_OFFSET);
449 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
452 /* Skip if running at lower exception level */
453 if (current_el() < 3)
456 /* enable propagation of barrier transactions to DDRC from CCI400 */
457 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
459 /* enable the re-ordering in DDRC */
460 tmp = ddr_in32(&ddr->eor);
461 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
462 ddr_out32(&ddr->eor, tmp);
466 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
467 void erratum_a010315(void)
471 for (i = PCIE1; i <= PCIE4; i++)
472 if (!is_serdes_configured(i)) {
473 debug("PCIe%d: disabled all R/W permission!\n", i);
474 set_pcie_ns_access(i, 0);
479 static void erratum_a010539(void)
481 #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
482 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
485 porsr1 = in_be32(&gur->porsr1);
486 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
487 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
489 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
493 /* Get VDD in the unit mV from voltage ID */
494 int get_core_volt_from_fuse(void)
496 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
501 fusesr = in_be32(&gur->dcfg_fusesr);
502 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
503 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
504 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
505 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
506 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
507 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
509 debug("%s: VID = 0x%x\n", __func__, vid);
511 case 0x00: /* VID isn't supported */
513 debug("%s: The VID feature is not supported\n", __func__);
515 case 0x08: /* 0.9V silicon */
518 case 0x10: /* 1.0V silicon */
521 default: /* Other core voltage */
523 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
526 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
531 __weak int board_switch_core_volt(u32 vdd)
536 static int setup_core_volt(u32 vdd)
538 return board_setup_core_volt(vdd);
541 #ifdef CONFIG_SYS_FSL_DDR
542 static void ddr_enable_0v9_volt(bool en)
544 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
547 tmp = ddr_in32(&ddr->ddr_cdr1);
550 tmp |= DDR_CDR1_V0PT9_EN;
552 tmp &= ~DDR_CDR1_V0PT9_EN;
554 ddr_out32(&ddr->ddr_cdr1, tmp);
558 int setup_chip_volt(void)
562 vdd = get_core_volt_from_fuse();
563 /* Nothing to do for silicons doesn't support VID */
567 if (setup_core_volt(vdd))
568 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
569 #ifdef CONFIG_SYS_HAS_SERDES
570 if (setup_serdes_volt(vdd))
571 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
574 #ifdef CONFIG_SYS_FSL_DDR
576 ddr_enable_0v9_volt(true);
582 #ifdef CONFIG_FSL_PFE
583 void init_pfe_scfg_dcfg_regs(void)
585 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
588 out_be32(&scfg->pfeasbcr,
589 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
590 out_be32(&scfg->pfebsbcr,
591 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
593 /* CCI-400 QoS settings for PFE */
594 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
595 | SCFG_WR_QOS1_PFE2_QOS));
596 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
597 | SCFG_RD_QOS1_PFE2_QOS));
599 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
600 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
601 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
605 void fsl_lsch2_early_init_f(void)
607 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
608 CONFIG_SYS_CCI400_OFFSET);
609 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
610 #if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
614 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
615 enable_layerscape_ns_access();
618 #ifdef CONFIG_FSL_IFC
619 init_early_memctl_regs(); /* tighten IFC timing */
622 #if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
623 src = get_boot_src();
624 if (src != BOOT_SOURCE_QSPI_NOR)
625 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
627 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
628 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
631 /* Make SEC reads and writes snoopable */
632 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
633 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
634 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
635 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
636 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
637 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
638 SCFG_SNPCNFGCR_SATAWRSNP);
640 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
641 SCFG_SNPCNFGCR_SECWRSNP |
642 SCFG_SNPCNFGCR_SATARDSNP |
643 SCFG_SNPCNFGCR_SATAWRSNP);
647 * Enable snoop requests and DVM message requests for
648 * Slave insterface S4 (A53 core cluster)
650 if (current_el() == 3) {
651 out_le32(&cci->slave[4].snoop_ctrl,
652 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
656 * Program Central Security Unit (CSU) to grant access
657 * permission for USB 2.0 controller
659 #if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
660 if (current_el() == 3)
661 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
664 erratum_a008850_early(); /* part 1 of 2 */
673 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
679 #ifdef CONFIG_QSPI_AHB_INIT
680 /* Enable 4bytes address support and fast read */
681 int qspi_ahb_init(void)
683 u32 *qspi_lut, lut_key, *qspi_key;
685 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
686 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
688 lut_key = in_be32(qspi_key);
690 if (lut_key == 0x5af05af0) {
691 /* That means the register is BE */
692 out_be32(qspi_key, 0x5af05af0);
693 /* Unlock the lut table */
694 out_be32(qspi_key + 1, 0x00000002);
695 out_be32(qspi_lut, 0x0820040c);
696 out_be32(qspi_lut + 1, 0x1c080c08);
697 out_be32(qspi_lut + 2, 0x00002400);
698 /* Lock the lut table */
699 out_be32(qspi_key, 0x5af05af0);
700 out_be32(qspi_key + 1, 0x00000001);
702 /* That means the register is LE */
703 out_le32(qspi_key, 0x5af05af0);
704 /* Unlock the lut table */
705 out_le32(qspi_key + 1, 0x00000002);
706 out_le32(qspi_lut, 0x0820040c);
707 out_le32(qspi_lut + 1, 0x1c080c08);
708 out_le32(qspi_lut + 2, 0x00002400);
709 /* Lock the lut table */
710 out_le32(qspi_key, 0x5af05af0);
711 out_le32(qspi_key + 1, 0x00000001);
718 #ifdef CONFIG_TFABOOT
719 #define MAX_BOOTCMD_SIZE 512
721 int fsl_setenv_bootcmd(void)
724 enum boot_src src = get_boot_src();
725 char bootcmd_str[MAX_BOOTCMD_SIZE];
728 #ifdef IFC_NOR_BOOTCOMMAND
729 case BOOT_SOURCE_IFC_NOR:
730 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
733 #ifdef QSPI_NOR_BOOTCOMMAND
734 case BOOT_SOURCE_QSPI_NOR:
735 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
738 #ifdef XSPI_NOR_BOOTCOMMAND
739 case BOOT_SOURCE_XSPI_NOR:
740 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
743 #ifdef IFC_NAND_BOOTCOMMAND
744 case BOOT_SOURCE_IFC_NAND:
745 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
748 #ifdef QSPI_NAND_BOOTCOMMAND
749 case BOOT_SOURCE_QSPI_NAND:
750 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
753 #ifdef XSPI_NAND_BOOTCOMMAND
754 case BOOT_SOURCE_XSPI_NAND:
755 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
758 #ifdef SD_BOOTCOMMAND
759 case BOOT_SOURCE_SD_MMC:
760 sprintf(bootcmd_str, SD_BOOTCOMMAND);
763 #ifdef SD2_BOOTCOMMAND
764 case BOOT_SOURCE_SD_MMC2:
765 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
769 #ifdef QSPI_NOR_BOOTCOMMAND
770 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
775 ret = env_set("bootcmd", bootcmd_str);
777 printf("Failed to set bootcmd: ret = %d\n", ret);
783 int fsl_setenv_mcinitcmd(void)
786 enum boot_src src = get_boot_src();
789 #ifdef IFC_MC_INIT_CMD
790 case BOOT_SOURCE_IFC_NAND:
791 case BOOT_SOURCE_IFC_NOR:
792 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
795 #ifdef QSPI_MC_INIT_CMD
796 case BOOT_SOURCE_QSPI_NAND:
797 case BOOT_SOURCE_QSPI_NOR:
798 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
801 #ifdef XSPI_MC_INIT_CMD
802 case BOOT_SOURCE_XSPI_NAND:
803 case BOOT_SOURCE_XSPI_NOR:
804 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
807 #ifdef SD_MC_INIT_CMD
808 case BOOT_SOURCE_SD_MMC:
809 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
812 #ifdef SD2_MC_INIT_CMD
813 case BOOT_SOURCE_SD_MMC2:
814 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
818 #ifdef QSPI_MC_INIT_CMD
819 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
825 printf("Failed to set mcinitcmd: ret = %d\n", ret);
832 #ifdef CONFIG_BOARD_LATE_INIT
833 __weak int fsl_board_late_init(void)
838 int board_late_init(void)
840 #ifdef CONFIG_CHAIN_OF_TRUST
841 fsl_setenv_chain_of_trust();
843 #ifdef CONFIG_TFABOOT
845 * check if gd->env_addr is default_environment; then setenv bootcmd
848 #ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
849 if (gd->env_addr == (ulong)&default_environment[0]) {
851 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
853 fsl_setenv_bootcmd();
854 fsl_setenv_mcinitcmd();
858 * If the boot mode is secure, default environment is not present then
859 * setenv command needs to be run by default
861 #ifdef CONFIG_CHAIN_OF_TRUST
862 if ((fsl_check_boot_mode_secure() == 1)) {
863 fsl_setenv_bootcmd();
864 fsl_setenv_mcinitcmd();
868 #ifdef CONFIG_QSPI_AHB_INIT
872 return fsl_board_late_init();