2 * Copyright 2014-2015 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/soc.h>
13 #include <asm/global_data.h>
14 #include <asm/arch-fsl-layerscape/config.h>
15 #ifdef CONFIG_SYS_FSL_DDR
16 #include <fsl_ddr_sdram.h>
19 #ifdef CONFIG_CHAIN_OF_TRUST
20 #include <fsl_validate.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 bool soc_has_dp_ddr(void)
27 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
28 u32 svr = gur_in32(&gur->svr);
30 /* LS2085A has DP_DDR */
31 if (SVR_SOC_VER(svr) == SVR_LS2085A)
37 bool soc_has_aiop(void)
39 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
40 u32 svr = gur_in32(&gur->svr);
42 /* LS2085A has AIOP */
43 if (SVR_SOC_VER(svr) == SVR_LS2085A)
51 * This erratum requires setting a value to eddrtqcr1 to
52 * optimal the DDR performance.
54 static void erratum_a008336(void)
58 #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
59 #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
60 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
61 if (fsl_ddr_get_version(0) == 0x50200)
62 out_le32(eddrtqcr1, 0x63b30002);
64 #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
65 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
66 if (fsl_ddr_get_version(0) == 0x50200)
67 out_le32(eddrtqcr1, 0x63b30002);
73 * This erratum requires a register write before being Memory
74 * controller 3 being enabled.
76 static void erratum_a008514(void)
80 #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
81 #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
82 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
83 out_le32(eddrtqcr1, 0x63b20002);
87 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
88 #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
90 static unsigned long get_internval_val_mhz(void)
92 char *interval = getenv(PLATFORM_CYCLE_ENV_VAR);
94 * interval is the number of platform cycles(MHz) between
95 * wake up events generated by EPU.
97 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
100 interval_mhz = simple_strtoul(interval, NULL, 10);
105 void erratum_a009635(void)
108 unsigned long interval_mhz = get_internval_val_mhz();
113 val = in_le32(DCSR_CGACRE5);
114 writel(val | 0x00000200, DCSR_CGACRE5);
116 val = in_le32(EPU_EPCMPR5);
117 writel(interval_mhz, EPU_EPCMPR5);
118 val = in_le32(EPU_EPCCR5);
119 writel(val | 0x82820000, EPU_EPCCR5);
120 val = in_le32(EPU_EPSMCR5);
121 writel(val | 0x002f0000, EPU_EPSMCR5);
122 val = in_le32(EPU_EPECR5);
123 writel(val | 0x20000000, EPU_EPECR5);
124 val = in_le32(EPU_EPGCR);
125 writel(val | 0x80000000, EPU_EPGCR);
127 #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
129 static void erratum_rcw_src(void)
131 #if defined(CONFIG_SPL)
132 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
133 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
136 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
137 val &= ~DCFG_PORSR1_RCW_SRC;
138 val |= DCFG_PORSR1_RCW_SRC_NOR;
139 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
143 #define I2C_DEBUG_REG 0x6
144 #define I2C_GLITCH_EN 0x8
146 * This erratum requires setting glitch_en bit to enable
147 * digital glitch filter to improve clock stability.
149 static void erratum_a009203(void)
152 #ifdef CONFIG_SYS_I2C
153 #ifdef I2C1_BASE_ADDR
154 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
156 writeb(I2C_GLITCH_EN, ptr);
158 #ifdef I2C2_BASE_ADDR
159 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
161 writeb(I2C_GLITCH_EN, ptr);
163 #ifdef I2C3_BASE_ADDR
164 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
166 writeb(I2C_GLITCH_EN, ptr);
168 #ifdef I2C4_BASE_ADDR
169 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
171 writeb(I2C_GLITCH_EN, ptr);
175 void bypass_smmu(void)
178 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
179 out_le32(SMMU_SCR0, val);
180 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
181 out_le32(SMMU_NSCR0, val);
183 void fsl_lsch3_early_init_f(void)
186 init_early_memctl_regs(); /* tighten IFC timing */
190 #ifdef CONFIG_CHAIN_OF_TRUST
191 /* In case of Secure Boot, the IBR configures the SMMU
192 * to allow only Secure transactions.
193 * SMMU must be reset in bypass mode.
194 * Set the ClientPD bit and Clear the USFCFG Bit
196 if (fsl_check_boot_mode_secure() == 1)
201 #ifdef CONFIG_SCSI_AHCI_PLAT
204 struct ccsr_ahci __iomem *ccsr_ahci;
206 ccsr_ahci = (void *)CONFIG_SYS_SATA2;
207 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
208 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
210 ccsr_ahci = (void *)CONFIG_SYS_SATA1;
211 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
212 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
214 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
221 #elif defined(CONFIG_FSL_LSCH2)
222 #ifdef CONFIG_SCSI_AHCI_PLAT
225 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
227 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
228 out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY_2_CFG);
229 out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY_3_CFG);
230 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
232 ahci_init((void __iomem *)CONFIG_SYS_SATA);
239 static void erratum_a009929(void)
241 #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
242 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
243 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
244 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
246 rstrqmr1 |= 0x00000400;
247 gur_out32(&gur->rstrqmr1, rstrqmr1);
248 writel(0x01000000, dcsr_cop_ccp);
253 * This erratum requires setting a value to eddrtqcr1 to optimal
254 * the DDR performance. The eddrtqcr1 register is in SCFG space
255 * of LS1043A and the offset is 0x157_020c.
257 #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
258 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
259 #error A009660 and A008514 can not be both enabled.
262 static void erratum_a009660(void)
264 #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
265 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
266 out_be32(eddrtqcr1, 0x63b20042);
270 static void erratum_a008850_early(void)
272 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
274 struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
275 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
277 /* disables propagation of barrier transactions to DDRC from CCI400 */
278 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
280 /* disable the re-ordering in DDRC */
281 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
285 void erratum_a008850_post(void)
287 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
289 struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
290 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
293 /* enable propagation of barrier transactions to DDRC from CCI400 */
294 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
296 /* enable the re-ordering in DDRC */
297 tmp = ddr_in32(&ddr->eor);
298 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
299 ddr_out32(&ddr->eor, tmp);
303 void fsl_lsch2_early_init_f(void)
305 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
306 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
308 #ifdef CONFIG_FSL_IFC
309 init_early_memctl_regs(); /* tighten IFC timing */
312 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
313 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
315 /* Make SEC reads and writes snoopable */
316 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
317 SCFG_SNPCNFGCR_SECWRSNP);
320 * Enable snoop requests and DVM message requests for
321 * Slave insterface S4 (A53 core cluster)
323 out_le32(&cci->slave[4].snoop_ctrl,
324 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
327 erratum_a008850_early(); /* part 1 of 2 */
333 #ifdef CONFIG_BOARD_LATE_INIT
334 int board_late_init(void)
336 #ifdef CONFIG_SCSI_AHCI_PLAT
339 #ifdef CONFIG_CHAIN_OF_TRUST
340 fsl_setenv_chain_of_trust();