2 * Copyright 2014-2015 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
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 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
20 #ifdef CONFIG_SYS_FSL_DDR
21 #include <fsl_ddr_sdram.h>
24 #ifdef CONFIG_CHAIN_OF_TRUST
25 #include <fsl_validate.h>
27 #include <fsl_immap.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 bool soc_has_dp_ddr(void)
33 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
34 u32 svr = gur_in32(&gur->svr);
36 /* LS2085A, LS2088A, LS2048A has DP_DDR */
37 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
38 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
39 (SVR_SOC_VER(svr) == SVR_LS2048A))
45 bool soc_has_aiop(void)
47 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
48 u32 svr = gur_in32(&gur->svr);
50 /* LS2085A has AIOP */
51 if (SVR_SOC_VER(svr) == SVR_LS2085A)
57 static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
59 scfg_clrsetbits32(scfg + offset / 4,
61 SCFG_USB_TXVREFTUNE << 6);
64 static void erratum_a009008(void)
66 #ifdef CONFIG_SYS_FSL_ERRATUM_A009008
67 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
68 #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
69 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
70 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
71 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
72 #elif defined(CONFIG_ARCH_LS2080A)
73 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
75 #endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
78 #if defined(CONFIG_FSL_LSCH3)
80 * This erratum requires setting a value to eddrtqcr1 to
81 * optimal the DDR performance.
83 static void erratum_a008336(void)
85 #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
88 #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
89 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
90 if (fsl_ddr_get_version(0) == 0x50200)
91 out_le32(eddrtqcr1, 0x63b30002);
93 #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
94 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
95 if (fsl_ddr_get_version(0) == 0x50200)
96 out_le32(eddrtqcr1, 0x63b30002);
102 * This erratum requires a register write before being Memory
103 * controller 3 being enabled.
105 static void erratum_a008514(void)
107 #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
110 #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
111 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
112 out_le32(eddrtqcr1, 0x63b20002);
116 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
117 #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
119 static unsigned long get_internval_val_mhz(void)
121 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
123 * interval is the number of platform cycles(MHz) between
124 * wake up events generated by EPU.
126 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
129 interval_mhz = simple_strtoul(interval, NULL, 10);
134 void erratum_a009635(void)
137 unsigned long interval_mhz = get_internval_val_mhz();
142 val = in_le32(DCSR_CGACRE5);
143 writel(val | 0x00000200, DCSR_CGACRE5);
145 val = in_le32(EPU_EPCMPR5);
146 writel(interval_mhz, EPU_EPCMPR5);
147 val = in_le32(EPU_EPCCR5);
148 writel(val | 0x82820000, EPU_EPCCR5);
149 val = in_le32(EPU_EPSMCR5);
150 writel(val | 0x002f0000, EPU_EPSMCR5);
151 val = in_le32(EPU_EPECR5);
152 writel(val | 0x20000000, EPU_EPECR5);
153 val = in_le32(EPU_EPGCR);
154 writel(val | 0x80000000, EPU_EPGCR);
156 #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
158 static void erratum_rcw_src(void)
160 #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
161 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
162 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
165 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
166 val &= ~DCFG_PORSR1_RCW_SRC;
167 val |= DCFG_PORSR1_RCW_SRC_NOR;
168 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
172 #define I2C_DEBUG_REG 0x6
173 #define I2C_GLITCH_EN 0x8
175 * This erratum requires setting glitch_en bit to enable
176 * digital glitch filter to improve clock stability.
178 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
179 static void erratum_a009203(void)
182 #ifdef CONFIG_SYS_I2C
183 #ifdef I2C1_BASE_ADDR
184 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
186 writeb(I2C_GLITCH_EN, ptr);
188 #ifdef I2C2_BASE_ADDR
189 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
191 writeb(I2C_GLITCH_EN, ptr);
193 #ifdef I2C3_BASE_ADDR
194 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
196 writeb(I2C_GLITCH_EN, ptr);
198 #ifdef I2C4_BASE_ADDR
199 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
201 writeb(I2C_GLITCH_EN, ptr);
207 void bypass_smmu(void)
210 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
211 out_le32(SMMU_SCR0, val);
212 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
213 out_le32(SMMU_NSCR0, val);
215 void fsl_lsch3_early_init_f(void)
218 init_early_memctl_regs(); /* tighten IFC timing */
219 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
225 #ifdef CONFIG_CHAIN_OF_TRUST
226 /* In case of Secure Boot, the IBR configures the SMMU
227 * to allow only Secure transactions.
228 * SMMU must be reset in bypass mode.
229 * Set the ClientPD bit and Clear the USFCFG Bit
231 if (fsl_check_boot_mode_secure() == 1)
236 #ifdef CONFIG_SCSI_AHCI_PLAT
239 struct ccsr_ahci __iomem *ccsr_ahci;
241 ccsr_ahci = (void *)CONFIG_SYS_SATA2;
242 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
243 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
244 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
246 ccsr_ahci = (void *)CONFIG_SYS_SATA1;
247 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
248 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
249 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
251 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
258 #elif defined(CONFIG_FSL_LSCH2)
259 #ifdef CONFIG_SCSI_AHCI_PLAT
262 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
264 /* Disable SATA ECC */
265 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
266 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
267 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
268 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
270 ahci_init((void __iomem *)CONFIG_SYS_SATA);
277 static void erratum_a009929(void)
279 #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
280 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
281 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
282 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
284 rstrqmr1 |= 0x00000400;
285 gur_out32(&gur->rstrqmr1, rstrqmr1);
286 writel(0x01000000, dcsr_cop_ccp);
291 * This erratum requires setting a value to eddrtqcr1 to optimal
292 * the DDR performance. The eddrtqcr1 register is in SCFG space
293 * of LS1043A and the offset is 0x157_020c.
295 #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
296 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
297 #error A009660 and A008514 can not be both enabled.
300 static void erratum_a009660(void)
302 #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
303 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
304 out_be32(eddrtqcr1, 0x63b20042);
308 static void erratum_a008850_early(void)
310 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
312 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
313 CONFIG_SYS_CCI400_OFFSET);
314 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
316 /* Skip if running at lower exception level */
317 if (current_el() < 3)
320 /* disables propagation of barrier transactions to DDRC from CCI400 */
321 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
323 /* disable the re-ordering in DDRC */
324 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
328 void erratum_a008850_post(void)
330 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
332 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
333 CONFIG_SYS_CCI400_OFFSET);
334 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
337 /* Skip if running at lower exception level */
338 if (current_el() < 3)
341 /* enable propagation of barrier transactions to DDRC from CCI400 */
342 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
344 /* enable the re-ordering in DDRC */
345 tmp = ddr_in32(&ddr->eor);
346 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
347 ddr_out32(&ddr->eor, tmp);
351 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
352 void erratum_a010315(void)
356 for (i = PCIE1; i <= PCIE4; i++)
357 if (!is_serdes_configured(i)) {
358 debug("PCIe%d: disabled all R/W permission!\n", i);
359 set_pcie_ns_access(i, 0);
364 static void erratum_a010539(void)
366 #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
367 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
370 porsr1 = in_be32(&gur->porsr1);
371 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
372 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
377 /* Get VDD in the unit mV from voltage ID */
378 int get_core_volt_from_fuse(void)
380 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
385 fusesr = in_be32(&gur->dcfg_fusesr);
386 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
387 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
388 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
389 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
390 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
391 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
393 debug("%s: VID = 0x%x\n", __func__, vid);
395 case 0x00: /* VID isn't supported */
397 debug("%s: The VID feature is not supported\n", __func__);
399 case 0x08: /* 0.9V silicon */
402 case 0x10: /* 1.0V silicon */
405 default: /* Other core voltage */
407 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
410 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
415 __weak int board_switch_core_volt(u32 vdd)
420 static int setup_core_volt(u32 vdd)
422 return board_setup_core_volt(vdd);
425 #ifdef CONFIG_SYS_FSL_DDR
426 static void ddr_enable_0v9_volt(bool en)
428 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
431 tmp = ddr_in32(&ddr->ddr_cdr1);
434 tmp |= DDR_CDR1_V0PT9_EN;
436 tmp &= ~DDR_CDR1_V0PT9_EN;
438 ddr_out32(&ddr->ddr_cdr1, tmp);
442 int setup_chip_volt(void)
446 vdd = get_core_volt_from_fuse();
447 /* Nothing to do for silicons doesn't support VID */
451 if (setup_core_volt(vdd))
452 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
453 #ifdef CONFIG_SYS_HAS_SERDES
454 if (setup_serdes_volt(vdd))
455 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
458 #ifdef CONFIG_SYS_FSL_DDR
460 ddr_enable_0v9_volt(true);
466 void fsl_lsch2_early_init_f(void)
468 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
469 CONFIG_SYS_CCI400_OFFSET);
470 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
472 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
473 enable_layerscape_ns_access();
476 #ifdef CONFIG_FSL_IFC
477 init_early_memctl_regs(); /* tighten IFC timing */
480 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
481 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
483 /* Make SEC reads and writes snoopable */
484 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
485 SCFG_SNPCNFGCR_SECWRSNP |
486 SCFG_SNPCNFGCR_SATARDSNP |
487 SCFG_SNPCNFGCR_SATAWRSNP);
490 * Enable snoop requests and DVM message requests for
491 * Slave insterface S4 (A53 core cluster)
493 if (current_el() == 3) {
494 out_le32(&cci->slave[4].snoop_ctrl,
495 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
499 erratum_a008850_early(); /* part 1 of 2 */
507 #ifdef CONFIG_QSPI_AHB_INIT
508 /* Enable 4bytes address support and fast read */
509 int qspi_ahb_init(void)
511 u32 *qspi_lut, lut_key, *qspi_key;
513 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
514 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
516 lut_key = in_be32(qspi_key);
518 if (lut_key == 0x5af05af0) {
519 /* That means the register is BE */
520 out_be32(qspi_key, 0x5af05af0);
521 /* Unlock the lut table */
522 out_be32(qspi_key + 1, 0x00000002);
523 out_be32(qspi_lut, 0x0820040c);
524 out_be32(qspi_lut + 1, 0x1c080c08);
525 out_be32(qspi_lut + 2, 0x00002400);
526 /* Lock the lut table */
527 out_be32(qspi_key, 0x5af05af0);
528 out_be32(qspi_key + 1, 0x00000001);
530 /* That means the register is LE */
531 out_le32(qspi_key, 0x5af05af0);
532 /* Unlock the lut table */
533 out_le32(qspi_key + 1, 0x00000002);
534 out_le32(qspi_lut, 0x0820040c);
535 out_le32(qspi_lut + 1, 0x1c080c08);
536 out_le32(qspi_lut + 2, 0x00002400);
537 /* Lock the lut table */
538 out_le32(qspi_key, 0x5af05af0);
539 out_le32(qspi_key + 1, 0x00000001);
546 #ifdef CONFIG_BOARD_LATE_INIT
547 int board_late_init(void)
549 #ifdef CONFIG_SCSI_AHCI_PLAT
552 #ifdef CONFIG_CHAIN_OF_TRUST
553 fsl_setenv_chain_of_trust();
555 #ifdef CONFIG_QSPI_AHB_INIT