blob: a3b9f6baa45fe51c65bda576997702bb27443c4a [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
Ashish Kumarb25faa22017-08-31 16:12:53 +053027#include <fsl_immap.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070028
29DECLARE_GLOBAL_DATA_PTR;
Scott Woodae1df322015-03-20 19:28:13 -070030
York Suncbe8e1c2016-04-04 11:41:26 -070031bool soc_has_dp_ddr(void)
32{
33 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
34 u32 svr = gur_in32(&gur->svr);
35
Priyanka Jain4a6f1732016-11-17 12:29:55 +053036 /* 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))
York Suncbe8e1c2016-04-04 11:41:26 -070040 return true;
41
42 return false;
43}
44
45bool soc_has_aiop(void)
46{
47 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
48 u32 svr = gur_in32(&gur->svr);
49
50 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053051 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070052 return true;
53
54 return false;
55}
56
Shengzhou Liua3117ee2016-11-11 18:11:05 +080057#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +080058/*
59 * This erratum requires setting a value to eddrtqcr1 to
60 * optimal the DDR performance.
61 */
62static void erratum_a008336(void)
63{
Shengzhou Liua3117ee2016-11-11 18:11:05 +080064#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +080065 u32 *eddrtqcr1;
66
Yao Yuanfae88052015-12-05 14:59:14 +080067#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
68 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080069 if (fsl_ddr_get_version(0) == 0x50200)
70 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080071#endif
72#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
73 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080074 if (fsl_ddr_get_version(0) == 0x50200)
75 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080076#endif
77#endif
78}
79
80/*
81 * This erratum requires a register write before being Memory
82 * controller 3 being enabled.
83 */
84static void erratum_a008514(void)
85{
Shengzhou Liua3117ee2016-11-11 18:11:05 +080086#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +080087 u32 *eddrtqcr1;
88
Yao Yuanfae88052015-12-05 14:59:14 +080089#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
90 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
91 out_le32(eddrtqcr1, 0x63b20002);
92#endif
93#endif
94}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053095#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
96#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
97
98static unsigned long get_internval_val_mhz(void)
99{
Simon Glass64b723f2017-08-03 12:22:12 -0600100 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530101 /*
102 * interval is the number of platform cycles(MHz) between
103 * wake up events generated by EPU.
104 */
105 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
106
107 if (interval)
108 interval_mhz = simple_strtoul(interval, NULL, 10);
109
110 return interval_mhz;
111}
112
113void erratum_a009635(void)
114{
115 u32 val;
116 unsigned long interval_mhz = get_internval_val_mhz();
117
118 if (!interval_mhz)
119 return;
120
121 val = in_le32(DCSR_CGACRE5);
122 writel(val | 0x00000200, DCSR_CGACRE5);
123
124 val = in_le32(EPU_EPCMPR5);
125 writel(interval_mhz, EPU_EPCMPR5);
126 val = in_le32(EPU_EPCCR5);
127 writel(val | 0x82820000, EPU_EPCCR5);
128 val = in_le32(EPU_EPSMCR5);
129 writel(val | 0x002f0000, EPU_EPSMCR5);
130 val = in_le32(EPU_EPECR5);
131 writel(val | 0x20000000, EPU_EPECR5);
132 val = in_le32(EPU_EPGCR);
133 writel(val | 0x80000000, EPU_EPGCR);
134}
135#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
136
Scott Wood8e728cd2015-03-24 13:25:02 -0700137static void erratum_rcw_src(void)
138{
Santan Kumar99136482017-05-05 15:42:28 +0530139#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700140 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
141 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
142 u32 val;
143
144 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
145 val &= ~DCFG_PORSR1_RCW_SRC;
146 val |= DCFG_PORSR1_RCW_SRC_NOR;
147 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
148#endif
149}
150
York Sun0404a392015-03-23 10:41:35 -0700151#define I2C_DEBUG_REG 0x6
152#define I2C_GLITCH_EN 0x8
153/*
154 * This erratum requires setting glitch_en bit to enable
155 * digital glitch filter to improve clock stability.
156 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530157#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700158static void erratum_a009203(void)
159{
160 u8 __iomem *ptr;
161#ifdef CONFIG_SYS_I2C
162#ifdef I2C1_BASE_ADDR
163 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
164
165 writeb(I2C_GLITCH_EN, ptr);
166#endif
167#ifdef I2C2_BASE_ADDR
168 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
169
170 writeb(I2C_GLITCH_EN, ptr);
171#endif
172#ifdef I2C3_BASE_ADDR
173 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
174
175 writeb(I2C_GLITCH_EN, ptr);
176#endif
177#ifdef I2C4_BASE_ADDR
178 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
179
180 writeb(I2C_GLITCH_EN, ptr);
181#endif
182#endif
183}
Ashish kumar3b52a232017-02-23 16:03:57 +0530184#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800185
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530186void bypass_smmu(void)
187{
188 u32 val;
189 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
190 out_le32(SMMU_SCR0, val);
191 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
192 out_le32(SMMU_NSCR0, val);
193}
Scott Woodf64c98c2015-03-20 19:28:12 -0700194void fsl_lsch3_early_init_f(void)
195{
Scott Wood8e728cd2015-03-24 13:25:02 -0700196 erratum_rcw_src();
Scott Woodf64c98c2015-03-20 19:28:12 -0700197 init_early_memctl_regs(); /* tighten IFC timing */
Ashish kumar3b52a232017-02-23 16:03:57 +0530198#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700199 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530200#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800201 erratum_a008514();
202 erratum_a008336();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530203#ifdef CONFIG_CHAIN_OF_TRUST
204 /* In case of Secure Boot, the IBR configures the SMMU
205 * to allow only Secure transactions.
206 * SMMU must be reset in bypass mode.
207 * Set the ClientPD bit and Clear the USFCFG Bit
208 */
209 if (fsl_check_boot_mode_secure() == 1)
210 bypass_smmu();
211#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700212}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800213
Tang Yuantian57894be2015-12-09 15:32:18 +0800214#ifdef CONFIG_SCSI_AHCI_PLAT
215int sata_init(void)
216{
217 struct ccsr_ahci __iomem *ccsr_ahci;
218
219 ccsr_ahci = (void *)CONFIG_SYS_SATA2;
220 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
221 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800222 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800223
224 ccsr_ahci = (void *)CONFIG_SYS_SATA1;
225 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
226 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800227 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800228
229 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
Simon Glass48228732017-06-14 21:28:41 -0600230 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800231
232 return 0;
233}
234#endif
235
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530236#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800237#ifdef CONFIG_SCSI_AHCI_PLAT
238int sata_init(void)
239{
240 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
241
Shaohui Xieed81e2b2016-09-07 17:56:12 +0800242 /* Disable SATA ECC */
243 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
Tang Yuantian57894be2015-12-09 15:32:18 +0800244 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800245 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantian2945ae02016-08-08 15:07:20 +0800246 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800247
248 ahci_init((void __iomem *)CONFIG_SYS_SATA);
Simon Glass48228732017-06-14 21:28:41 -0600249 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800250
251 return 0;
252}
253#endif
254
Mingkai Hu8beb0752015-12-07 16:58:54 +0800255static void erratum_a009929(void)
256{
257#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
258 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
259 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
260 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
261
262 rstrqmr1 |= 0x00000400;
263 gur_out32(&gur->rstrqmr1, rstrqmr1);
264 writel(0x01000000, dcsr_cop_ccp);
265#endif
266}
267
Mingkai Hu172081c2016-02-02 11:28:03 +0800268/*
269 * This erratum requires setting a value to eddrtqcr1 to optimal
270 * the DDR performance. The eddrtqcr1 register is in SCFG space
271 * of LS1043A and the offset is 0x157_020c.
272 */
273#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
274 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
275#error A009660 and A008514 can not be both enabled.
276#endif
277
278static void erratum_a009660(void)
279{
280#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
281 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
282 out_be32(eddrtqcr1, 0x63b20042);
283#endif
284}
285
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800286static void erratum_a008850_early(void)
287{
288#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
289 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530290 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
291 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800292 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
293
York Sune6b871e2017-05-15 08:51:59 -0700294 /* Skip if running at lower exception level */
295 if (current_el() < 3)
296 return;
297
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800298 /* disables propagation of barrier transactions to DDRC from CCI400 */
299 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
300
301 /* disable the re-ordering in DDRC */
302 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
303#endif
304}
305
306void erratum_a008850_post(void)
307{
308#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
309 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530310 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
311 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800312 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
313 u32 tmp;
314
York Sune6b871e2017-05-15 08:51:59 -0700315 /* Skip if running at lower exception level */
316 if (current_el() < 3)
317 return;
318
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800319 /* enable propagation of barrier transactions to DDRC from CCI400 */
320 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
321
322 /* enable the re-ordering in DDRC */
323 tmp = ddr_in32(&ddr->eor);
324 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
325 ddr_out32(&ddr->eor, tmp);
326#endif
327}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800328
329#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
330void erratum_a010315(void)
331{
332 int i;
333
334 for (i = PCIE1; i <= PCIE4; i++)
335 if (!is_serdes_configured(i)) {
336 debug("PCIe%d: disabled all R/W permission!\n", i);
337 set_pcie_ns_access(i, 0);
338 }
339}
340#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800341
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800342static void erratum_a010539(void)
343{
344#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
345 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
346 u32 porsr1;
347
348 porsr1 = in_be32(&gur->porsr1);
349 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
350 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
351 porsr1);
352#endif
353}
354
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800355/* Get VDD in the unit mV from voltage ID */
356int get_core_volt_from_fuse(void)
357{
358 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
359 int vdd;
360 u32 fusesr;
361 u8 vid;
362
363 fusesr = in_be32(&gur->dcfg_fusesr);
364 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
365 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
366 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
367 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
368 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
369 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
370 }
371 debug("%s: VID = 0x%x\n", __func__, vid);
372 switch (vid) {
373 case 0x00: /* VID isn't supported */
374 vdd = -EINVAL;
375 debug("%s: The VID feature is not supported\n", __func__);
376 break;
377 case 0x08: /* 0.9V silicon */
378 vdd = 900;
379 break;
380 case 0x10: /* 1.0V silicon */
381 vdd = 1000;
382 break;
383 default: /* Other core voltage */
384 vdd = -EINVAL;
385 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
386 break;
387 }
388 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
389
390 return vdd;
391}
392
393__weak int board_switch_core_volt(u32 vdd)
394{
395 return 0;
396}
397
398static int setup_core_volt(u32 vdd)
399{
400 return board_setup_core_volt(vdd);
401}
402
403#ifdef CONFIG_SYS_FSL_DDR
404static void ddr_enable_0v9_volt(bool en)
405{
406 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
407 u32 tmp;
408
409 tmp = ddr_in32(&ddr->ddr_cdr1);
410
411 if (en)
412 tmp |= DDR_CDR1_V0PT9_EN;
413 else
414 tmp &= ~DDR_CDR1_V0PT9_EN;
415
416 ddr_out32(&ddr->ddr_cdr1, tmp);
417}
418#endif
419
420int setup_chip_volt(void)
421{
422 int vdd;
423
424 vdd = get_core_volt_from_fuse();
425 /* Nothing to do for silicons doesn't support VID */
426 if (vdd < 0)
427 return vdd;
428
429 if (setup_core_volt(vdd))
430 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
431#ifdef CONFIG_SYS_HAS_SERDES
432 if (setup_serdes_volt(vdd))
433 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
434#endif
435
436#ifdef CONFIG_SYS_FSL_DDR
437 if (vdd == 900)
438 ddr_enable_0v9_volt(true);
439#endif
440
441 return 0;
442}
443
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800444void fsl_lsch2_early_init_f(void)
445{
Ashish Kumar11234062017-08-11 11:09:14 +0530446 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
447 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530448 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800449
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800450#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
451 enable_layerscape_ns_access();
452#endif
453
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800454#ifdef CONFIG_FSL_IFC
455 init_early_memctl_regs(); /* tighten IFC timing */
456#endif
457
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800458#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800459 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
460#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530461 /* Make SEC reads and writes snoopable */
462 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800463 SCFG_SNPCNFGCR_SECWRSNP |
464 SCFG_SNPCNFGCR_SATARDSNP |
465 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530466
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800467 /*
468 * Enable snoop requests and DVM message requests for
469 * Slave insterface S4 (A53 core cluster)
470 */
York Sune6b871e2017-05-15 08:51:59 -0700471 if (current_el() == 3) {
472 out_le32(&cci->slave[4].snoop_ctrl,
473 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
474 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800475
476 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800477 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800478 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800479 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800480 erratum_a010539();
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800481}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800482#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700483
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800484#ifdef CONFIG_QSPI_AHB_INIT
485/* Enable 4bytes address support and fast read */
486int qspi_ahb_init(void)
487{
488 u32 *qspi_lut, lut_key, *qspi_key;
489
490 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
491 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
492
493 lut_key = in_be32(qspi_key);
494
495 if (lut_key == 0x5af05af0) {
496 /* That means the register is BE */
497 out_be32(qspi_key, 0x5af05af0);
498 /* Unlock the lut table */
499 out_be32(qspi_key + 1, 0x00000002);
500 out_be32(qspi_lut, 0x0820040c);
501 out_be32(qspi_lut + 1, 0x1c080c08);
502 out_be32(qspi_lut + 2, 0x00002400);
503 /* Lock the lut table */
504 out_be32(qspi_key, 0x5af05af0);
505 out_be32(qspi_key + 1, 0x00000001);
506 } else {
507 /* That means the register is LE */
508 out_le32(qspi_key, 0x5af05af0);
509 /* Unlock the lut table */
510 out_le32(qspi_key + 1, 0x00000002);
511 out_le32(qspi_lut, 0x0820040c);
512 out_le32(qspi_lut + 1, 0x1c080c08);
513 out_le32(qspi_lut + 2, 0x00002400);
514 /* Lock the lut table */
515 out_le32(qspi_key, 0x5af05af0);
516 out_le32(qspi_key + 1, 0x00000001);
517 }
518
519 return 0;
520}
521#endif
522
Mingkai Hu0e58b512015-10-26 19:47:50 +0800523#ifdef CONFIG_BOARD_LATE_INIT
524int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700525{
Tang Yuantian57894be2015-12-09 15:32:18 +0800526#ifdef CONFIG_SCSI_AHCI_PLAT
527 sata_init();
528#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530529#ifdef CONFIG_CHAIN_OF_TRUST
530 fsl_setenv_chain_of_trust();
531#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800532#ifdef CONFIG_QSPI_AHB_INIT
533 qspi_ahb_init();
534#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800535
Mingkai Hu0e58b512015-10-26 19:47:50 +0800536 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700537}
538#endif