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>
28 DECLARE_GLOBAL_DATA_PTR;
30 bool soc_has_dp_ddr(void)
32 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
33 u32 svr = gur_in32(&gur->svr);
35 /* LS2085A, LS2088A, LS2048A has DP_DDR */
36 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
37 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
38 (SVR_SOC_VER(svr) == SVR_LS2048A))
44 bool soc_has_aiop(void)
46 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
47 u32 svr = gur_in32(&gur->svr);
49 /* LS2085A has AIOP */
50 if (SVR_SOC_VER(svr) == SVR_LS2085A)
56 #if defined(CONFIG_FSL_LSCH3)
58 * This erratum requires setting a value to eddrtqcr1 to
59 * optimal the DDR performance.
61 static void erratum_a008336(void)
63 #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
66 #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
67 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
68 if (fsl_ddr_get_version(0) == 0x50200)
69 out_le32(eddrtqcr1, 0x63b30002);
71 #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
72 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
73 if (fsl_ddr_get_version(0) == 0x50200)
74 out_le32(eddrtqcr1, 0x63b30002);
80 * This erratum requires a register write before being Memory
81 * controller 3 being enabled.
83 static void erratum_a008514(void)
85 #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
88 #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
89 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
90 out_le32(eddrtqcr1, 0x63b20002);
94 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
95 #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
97 static unsigned long get_internval_val_mhz(void)
99 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
101 * interval is the number of platform cycles(MHz) between
102 * wake up events generated by EPU.
104 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
107 interval_mhz = simple_strtoul(interval, NULL, 10);
112 void erratum_a009635(void)
115 unsigned long interval_mhz = get_internval_val_mhz();
120 val = in_le32(DCSR_CGACRE5);
121 writel(val | 0x00000200, DCSR_CGACRE5);
123 val = in_le32(EPU_EPCMPR5);
124 writel(interval_mhz, EPU_EPCMPR5);
125 val = in_le32(EPU_EPCCR5);
126 writel(val | 0x82820000, EPU_EPCCR5);
127 val = in_le32(EPU_EPSMCR5);
128 writel(val | 0x002f0000, EPU_EPSMCR5);
129 val = in_le32(EPU_EPECR5);
130 writel(val | 0x20000000, EPU_EPECR5);
131 val = in_le32(EPU_EPGCR);
132 writel(val | 0x80000000, EPU_EPGCR);
134 #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
136 static void erratum_rcw_src(void)
138 #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
139 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
140 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
143 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
144 val &= ~DCFG_PORSR1_RCW_SRC;
145 val |= DCFG_PORSR1_RCW_SRC_NOR;
146 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
150 #define I2C_DEBUG_REG 0x6
151 #define I2C_GLITCH_EN 0x8
153 * This erratum requires setting glitch_en bit to enable
154 * digital glitch filter to improve clock stability.
156 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
157 static void erratum_a009203(void)
160 #ifdef CONFIG_SYS_I2C
161 #ifdef I2C1_BASE_ADDR
162 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
164 writeb(I2C_GLITCH_EN, ptr);
166 #ifdef I2C2_BASE_ADDR
167 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
169 writeb(I2C_GLITCH_EN, ptr);
171 #ifdef I2C3_BASE_ADDR
172 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
174 writeb(I2C_GLITCH_EN, ptr);
176 #ifdef I2C4_BASE_ADDR
177 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
179 writeb(I2C_GLITCH_EN, ptr);
185 void bypass_smmu(void)
188 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
189 out_le32(SMMU_SCR0, val);
190 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
191 out_le32(SMMU_NSCR0, val);
193 void fsl_lsch3_early_init_f(void)
196 init_early_memctl_regs(); /* tighten IFC timing */
197 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
202 #ifdef CONFIG_CHAIN_OF_TRUST
203 /* In case of Secure Boot, the IBR configures the SMMU
204 * to allow only Secure transactions.
205 * SMMU must be reset in bypass mode.
206 * Set the ClientPD bit and Clear the USFCFG Bit
208 if (fsl_check_boot_mode_secure() == 1)
213 #ifdef CONFIG_SCSI_AHCI_PLAT
216 struct ccsr_ahci __iomem *ccsr_ahci;
218 ccsr_ahci = (void *)CONFIG_SYS_SATA2;
219 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
220 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
221 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
223 ccsr_ahci = (void *)CONFIG_SYS_SATA1;
224 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
225 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
226 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
228 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
235 #elif defined(CONFIG_FSL_LSCH2)
236 #ifdef CONFIG_SCSI_AHCI_PLAT
239 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
241 /* Disable SATA ECC */
242 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
243 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
244 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
245 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
247 ahci_init((void __iomem *)CONFIG_SYS_SATA);
254 static void erratum_a009929(void)
256 #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
257 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
258 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
259 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
261 rstrqmr1 |= 0x00000400;
262 gur_out32(&gur->rstrqmr1, rstrqmr1);
263 writel(0x01000000, dcsr_cop_ccp);
268 * This erratum requires setting a value to eddrtqcr1 to optimal
269 * the DDR performance. The eddrtqcr1 register is in SCFG space
270 * of LS1043A and the offset is 0x157_020c.
272 #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
273 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
274 #error A009660 and A008514 can not be both enabled.
277 static void erratum_a009660(void)
279 #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
280 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
281 out_be32(eddrtqcr1, 0x63b20042);
285 static void erratum_a008850_early(void)
287 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
289 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
290 CONFIG_SYS_CCI400_OFFSET);
291 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
293 /* Skip if running at lower exception level */
294 if (current_el() < 3)
297 /* disables propagation of barrier transactions to DDRC from CCI400 */
298 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
300 /* disable the re-ordering in DDRC */
301 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
305 void erratum_a008850_post(void)
307 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
309 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
310 CONFIG_SYS_CCI400_OFFSET);
311 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
314 /* Skip if running at lower exception level */
315 if (current_el() < 3)
318 /* enable propagation of barrier transactions to DDRC from CCI400 */
319 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
321 /* enable the re-ordering in DDRC */
322 tmp = ddr_in32(&ddr->eor);
323 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
324 ddr_out32(&ddr->eor, tmp);
328 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
329 void erratum_a010315(void)
333 for (i = PCIE1; i <= PCIE4; i++)
334 if (!is_serdes_configured(i)) {
335 debug("PCIe%d: disabled all R/W permission!\n", i);
336 set_pcie_ns_access(i, 0);
341 static void erratum_a010539(void)
343 #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
344 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
347 porsr1 = in_be32(&gur->porsr1);
348 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
349 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
354 /* Get VDD in the unit mV from voltage ID */
355 int get_core_volt_from_fuse(void)
357 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
362 fusesr = in_be32(&gur->dcfg_fusesr);
363 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
364 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
365 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
366 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
367 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
368 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
370 debug("%s: VID = 0x%x\n", __func__, vid);
372 case 0x00: /* VID isn't supported */
374 debug("%s: The VID feature is not supported\n", __func__);
376 case 0x08: /* 0.9V silicon */
379 case 0x10: /* 1.0V silicon */
382 default: /* Other core voltage */
384 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
387 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
392 __weak int board_switch_core_volt(u32 vdd)
397 static int setup_core_volt(u32 vdd)
399 return board_setup_core_volt(vdd);
402 #ifdef CONFIG_SYS_FSL_DDR
403 static void ddr_enable_0v9_volt(bool en)
405 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
408 tmp = ddr_in32(&ddr->ddr_cdr1);
411 tmp |= DDR_CDR1_V0PT9_EN;
413 tmp &= ~DDR_CDR1_V0PT9_EN;
415 ddr_out32(&ddr->ddr_cdr1, tmp);
419 int setup_chip_volt(void)
423 vdd = get_core_volt_from_fuse();
424 /* Nothing to do for silicons doesn't support VID */
428 if (setup_core_volt(vdd))
429 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
430 #ifdef CONFIG_SYS_HAS_SERDES
431 if (setup_serdes_volt(vdd))
432 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
435 #ifdef CONFIG_SYS_FSL_DDR
437 ddr_enable_0v9_volt(true);
443 void fsl_lsch2_early_init_f(void)
445 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
446 CONFIG_SYS_CCI400_OFFSET);
447 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
449 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
450 enable_layerscape_ns_access();
453 #ifdef CONFIG_FSL_IFC
454 init_early_memctl_regs(); /* tighten IFC timing */
457 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
458 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
460 /* Make SEC reads and writes snoopable */
461 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
462 SCFG_SNPCNFGCR_SECWRSNP |
463 SCFG_SNPCNFGCR_SATARDSNP |
464 SCFG_SNPCNFGCR_SATAWRSNP);
467 * Enable snoop requests and DVM message requests for
468 * Slave insterface S4 (A53 core cluster)
470 if (current_el() == 3) {
471 out_le32(&cci->slave[4].snoop_ctrl,
472 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
476 erratum_a008850_early(); /* part 1 of 2 */
483 #ifdef CONFIG_QSPI_AHB_INIT
484 /* Enable 4bytes address support and fast read */
485 int qspi_ahb_init(void)
487 u32 *qspi_lut, lut_key, *qspi_key;
489 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
490 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
492 lut_key = in_be32(qspi_key);
494 if (lut_key == 0x5af05af0) {
495 /* That means the register is BE */
496 out_be32(qspi_key, 0x5af05af0);
497 /* Unlock the lut table */
498 out_be32(qspi_key + 1, 0x00000002);
499 out_be32(qspi_lut, 0x0820040c);
500 out_be32(qspi_lut + 1, 0x1c080c08);
501 out_be32(qspi_lut + 2, 0x00002400);
502 /* Lock the lut table */
503 out_be32(qspi_key, 0x5af05af0);
504 out_be32(qspi_key + 1, 0x00000001);
506 /* That means the register is LE */
507 out_le32(qspi_key, 0x5af05af0);
508 /* Unlock the lut table */
509 out_le32(qspi_key + 1, 0x00000002);
510 out_le32(qspi_lut, 0x0820040c);
511 out_le32(qspi_lut + 1, 0x1c080c08);
512 out_le32(qspi_lut + 2, 0x00002400);
513 /* Lock the lut table */
514 out_le32(qspi_key, 0x5af05af0);
515 out_le32(qspi_key + 1, 0x00000001);
522 #ifdef CONFIG_BOARD_LATE_INIT
523 int board_late_init(void)
525 #ifdef CONFIG_SCSI_AHCI_PLAT
528 #ifdef CONFIG_CHAIN_OF_TRUST
529 fsl_setenv_chain_of_trust();
531 #ifdef CONFIG_QSPI_AHB_INIT