blob: 339ff0c4c708e6047da60d718f54e341a24b3402 [file] [log] [blame]
Scott Woodf64c98c2015-03-20 19:28:12 -07001/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08002 * Copyright 2014-2015 Freescale Semiconductor
Scott Woodf64c98c2015-03-20 19:28:12 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Ashish Kumar11234062017-08-11 11:09:14 +05308#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -07009#include <fsl_ifc.h>
Tang Yuantian57894be2015-12-09 15:32:18 +080010#include <ahci.h>
11#include <scsi.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080012#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080013#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070014#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070015#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053016#include <asm/arch-fsl-layerscape/config.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080017#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080018#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080019#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053020#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080021#include <fsl_ddr_sdram.h>
22#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053023#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053024#ifdef CONFIG_CHAIN_OF_TRUST
25#include <fsl_validate.h>
26#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070027
28DECLARE_GLOBAL_DATA_PTR;
Scott Woodae1df322015-03-20 19:28:13 -070029
York Suncbe8e1c2016-04-04 11:41:26 -070030bool soc_has_dp_ddr(void)
31{
32 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
33 u32 svr = gur_in32(&gur->svr);
34
Priyanka Jain4a6f1732016-11-17 12:29:55 +053035 /* 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))
York Suncbe8e1c2016-04-04 11:41:26 -070039 return true;
40
41 return false;
42}
43
44bool soc_has_aiop(void)
45{
46 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
47 u32 svr = gur_in32(&gur->svr);
48
49 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053050 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070051 return true;
52
53 return false;
54}
55
Shengzhou Liua3117ee2016-11-11 18:11:05 +080056#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +080057/*
58 * This erratum requires setting a value to eddrtqcr1 to
59 * optimal the DDR performance.
60 */
61static void erratum_a008336(void)
62{
Shengzhou Liua3117ee2016-11-11 18:11:05 +080063#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +080064 u32 *eddrtqcr1;
65
Yao Yuanfae88052015-12-05 14:59:14 +080066#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
67 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080068 if (fsl_ddr_get_version(0) == 0x50200)
69 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080070#endif
71#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
72 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080073 if (fsl_ddr_get_version(0) == 0x50200)
74 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080075#endif
76#endif
77}
78
79/*
80 * This erratum requires a register write before being Memory
81 * controller 3 being enabled.
82 */
83static void erratum_a008514(void)
84{
Shengzhou Liua3117ee2016-11-11 18:11:05 +080085#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +080086 u32 *eddrtqcr1;
87
Yao Yuanfae88052015-12-05 14:59:14 +080088#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
89 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
90 out_le32(eddrtqcr1, 0x63b20002);
91#endif
92#endif
93}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053094#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
95#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
96
97static unsigned long get_internval_val_mhz(void)
98{
Simon Glass64b723f2017-08-03 12:22:12 -060099 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530100 /*
101 * interval is the number of platform cycles(MHz) between
102 * wake up events generated by EPU.
103 */
104 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
105
106 if (interval)
107 interval_mhz = simple_strtoul(interval, NULL, 10);
108
109 return interval_mhz;
110}
111
112void erratum_a009635(void)
113{
114 u32 val;
115 unsigned long interval_mhz = get_internval_val_mhz();
116
117 if (!interval_mhz)
118 return;
119
120 val = in_le32(DCSR_CGACRE5);
121 writel(val | 0x00000200, DCSR_CGACRE5);
122
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);
133}
134#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
135
Scott Wood8e728cd2015-03-24 13:25:02 -0700136static void erratum_rcw_src(void)
137{
Santan Kumar99136482017-05-05 15:42:28 +0530138#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700139 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
140 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
141 u32 val;
142
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);
147#endif
148}
149
York Sun0404a392015-03-23 10:41:35 -0700150#define I2C_DEBUG_REG 0x6
151#define I2C_GLITCH_EN 0x8
152/*
153 * This erratum requires setting glitch_en bit to enable
154 * digital glitch filter to improve clock stability.
155 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530156#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700157static void erratum_a009203(void)
158{
159 u8 __iomem *ptr;
160#ifdef CONFIG_SYS_I2C
161#ifdef I2C1_BASE_ADDR
162 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
163
164 writeb(I2C_GLITCH_EN, ptr);
165#endif
166#ifdef I2C2_BASE_ADDR
167 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
168
169 writeb(I2C_GLITCH_EN, ptr);
170#endif
171#ifdef I2C3_BASE_ADDR
172 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
173
174 writeb(I2C_GLITCH_EN, ptr);
175#endif
176#ifdef I2C4_BASE_ADDR
177 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
178
179 writeb(I2C_GLITCH_EN, ptr);
180#endif
181#endif
182}
Ashish kumar3b52a232017-02-23 16:03:57 +0530183#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800184
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530185void bypass_smmu(void)
186{
187 u32 val;
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);
192}
Scott Woodf64c98c2015-03-20 19:28:12 -0700193void fsl_lsch3_early_init_f(void)
194{
Scott Wood8e728cd2015-03-24 13:25:02 -0700195 erratum_rcw_src();
Scott Woodf64c98c2015-03-20 19:28:12 -0700196 init_early_memctl_regs(); /* tighten IFC timing */
Ashish kumar3b52a232017-02-23 16:03:57 +0530197#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700198 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530199#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800200 erratum_a008514();
201 erratum_a008336();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530202#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
207 */
208 if (fsl_check_boot_mode_secure() == 1)
209 bypass_smmu();
210#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700211}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800212
Tang Yuantian57894be2015-12-09 15:32:18 +0800213#ifdef CONFIG_SCSI_AHCI_PLAT
214int sata_init(void)
215{
216 struct ccsr_ahci __iomem *ccsr_ahci;
217
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);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800221 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800222
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);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800226 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800227
228 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
Simon Glass48228732017-06-14 21:28:41 -0600229 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800230
231 return 0;
232}
233#endif
234
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530235#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800236#ifdef CONFIG_SCSI_AHCI_PLAT
237int sata_init(void)
238{
239 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
240
Shaohui Xieed81e2b2016-09-07 17:56:12 +0800241 /* Disable SATA ECC */
242 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
Tang Yuantian57894be2015-12-09 15:32:18 +0800243 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800244 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantian2945ae02016-08-08 15:07:20 +0800245 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800246
247 ahci_init((void __iomem *)CONFIG_SYS_SATA);
Simon Glass48228732017-06-14 21:28:41 -0600248 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800249
250 return 0;
251}
252#endif
253
Mingkai Hu8beb0752015-12-07 16:58:54 +0800254static void erratum_a009929(void)
255{
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);
260
261 rstrqmr1 |= 0x00000400;
262 gur_out32(&gur->rstrqmr1, rstrqmr1);
263 writel(0x01000000, dcsr_cop_ccp);
264#endif
265}
266
Mingkai Hu172081c2016-02-02 11:28:03 +0800267/*
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.
271 */
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.
275#endif
276
277static void erratum_a009660(void)
278{
279#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
280 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
281 out_be32(eddrtqcr1, 0x63b20042);
282#endif
283}
284
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800285static void erratum_a008850_early(void)
286{
287#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
288 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530289 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
290 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800291 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
292
York Sune6b871e2017-05-15 08:51:59 -0700293 /* Skip if running at lower exception level */
294 if (current_el() < 3)
295 return;
296
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800297 /* disables propagation of barrier transactions to DDRC from CCI400 */
298 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
299
300 /* disable the re-ordering in DDRC */
301 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
302#endif
303}
304
305void erratum_a008850_post(void)
306{
307#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
308 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530309 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
310 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800311 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
312 u32 tmp;
313
York Sune6b871e2017-05-15 08:51:59 -0700314 /* Skip if running at lower exception level */
315 if (current_el() < 3)
316 return;
317
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800318 /* enable propagation of barrier transactions to DDRC from CCI400 */
319 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
320
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);
325#endif
326}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800327
328#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
329void erratum_a010315(void)
330{
331 int i;
332
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);
337 }
338}
339#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800340
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800341static void erratum_a010539(void)
342{
343#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
344 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
345 u32 porsr1;
346
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),
350 porsr1);
351#endif
352}
353
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800354/* Get VDD in the unit mV from voltage ID */
355int get_core_volt_from_fuse(void)
356{
357 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
358 int vdd;
359 u32 fusesr;
360 u8 vid;
361
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;
369 }
370 debug("%s: VID = 0x%x\n", __func__, vid);
371 switch (vid) {
372 case 0x00: /* VID isn't supported */
373 vdd = -EINVAL;
374 debug("%s: The VID feature is not supported\n", __func__);
375 break;
376 case 0x08: /* 0.9V silicon */
377 vdd = 900;
378 break;
379 case 0x10: /* 1.0V silicon */
380 vdd = 1000;
381 break;
382 default: /* Other core voltage */
383 vdd = -EINVAL;
384 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
385 break;
386 }
387 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
388
389 return vdd;
390}
391
392__weak int board_switch_core_volt(u32 vdd)
393{
394 return 0;
395}
396
397static int setup_core_volt(u32 vdd)
398{
399 return board_setup_core_volt(vdd);
400}
401
402#ifdef CONFIG_SYS_FSL_DDR
403static void ddr_enable_0v9_volt(bool en)
404{
405 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
406 u32 tmp;
407
408 tmp = ddr_in32(&ddr->ddr_cdr1);
409
410 if (en)
411 tmp |= DDR_CDR1_V0PT9_EN;
412 else
413 tmp &= ~DDR_CDR1_V0PT9_EN;
414
415 ddr_out32(&ddr->ddr_cdr1, tmp);
416}
417#endif
418
419int setup_chip_volt(void)
420{
421 int vdd;
422
423 vdd = get_core_volt_from_fuse();
424 /* Nothing to do for silicons doesn't support VID */
425 if (vdd < 0)
426 return vdd;
427
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);
433#endif
434
435#ifdef CONFIG_SYS_FSL_DDR
436 if (vdd == 900)
437 ddr_enable_0v9_volt(true);
438#endif
439
440 return 0;
441}
442
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800443void fsl_lsch2_early_init_f(void)
444{
Ashish Kumar11234062017-08-11 11:09:14 +0530445 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
446 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530447 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800448
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800449#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
450 enable_layerscape_ns_access();
451#endif
452
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800453#ifdef CONFIG_FSL_IFC
454 init_early_memctl_regs(); /* tighten IFC timing */
455#endif
456
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800457#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800458 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
459#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530460 /* Make SEC reads and writes snoopable */
461 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800462 SCFG_SNPCNFGCR_SECWRSNP |
463 SCFG_SNPCNFGCR_SATARDSNP |
464 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530465
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800466 /*
467 * Enable snoop requests and DVM message requests for
468 * Slave insterface S4 (A53 core cluster)
469 */
York Sune6b871e2017-05-15 08:51:59 -0700470 if (current_el() == 3) {
471 out_le32(&cci->slave[4].snoop_ctrl,
472 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
473 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800474
475 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800476 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800477 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800478 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800479 erratum_a010539();
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800480}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800481#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700482
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800483#ifdef CONFIG_QSPI_AHB_INIT
484/* Enable 4bytes address support and fast read */
485int qspi_ahb_init(void)
486{
487 u32 *qspi_lut, lut_key, *qspi_key;
488
489 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
490 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
491
492 lut_key = in_be32(qspi_key);
493
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);
505 } else {
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);
516 }
517
518 return 0;
519}
520#endif
521
Mingkai Hu0e58b512015-10-26 19:47:50 +0800522#ifdef CONFIG_BOARD_LATE_INIT
523int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700524{
Tang Yuantian57894be2015-12-09 15:32:18 +0800525#ifdef CONFIG_SCSI_AHCI_PLAT
526 sata_init();
527#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530528#ifdef CONFIG_CHAIN_OF_TRUST
529 fsl_setenv_chain_of_trust();
530#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800531#ifdef CONFIG_QSPI_AHB_INIT
532 qspi_ahb_init();
533#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800534
Mingkai Hu0e58b512015-10-26 19:47:50 +0800535 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700536}
537#endif