blob: b9e3a2075acca2261198bd423139c10cdd56bfea [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
Ran Wangb358b7b2017-09-04 18:46:48 +080057static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
58{
59 scfg_clrsetbits32(scfg + offset / 4,
60 0xF << 6,
61 SCFG_USB_TXVREFTUNE << 6);
62}
63
64static void erratum_a009008(void)
65{
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);
74#endif
75#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
76}
77
Shengzhou Liua3117ee2016-11-11 18:11:05 +080078#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +080079/*
80 * This erratum requires setting a value to eddrtqcr1 to
81 * optimal the DDR performance.
82 */
83static void erratum_a008336(void)
84{
Shengzhou Liua3117ee2016-11-11 18:11:05 +080085#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +080086 u32 *eddrtqcr1;
87
Yao Yuanfae88052015-12-05 14:59:14 +080088#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
89 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080090 if (fsl_ddr_get_version(0) == 0x50200)
91 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080092#endif
93#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
94 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080095 if (fsl_ddr_get_version(0) == 0x50200)
96 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080097#endif
98#endif
99}
100
101/*
102 * This erratum requires a register write before being Memory
103 * controller 3 being enabled.
104 */
105static void erratum_a008514(void)
106{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800107#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800108 u32 *eddrtqcr1;
109
Yao Yuanfae88052015-12-05 14:59:14 +0800110#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
111 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
112 out_le32(eddrtqcr1, 0x63b20002);
113#endif
114#endif
115}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530116#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
117#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
118
119static unsigned long get_internval_val_mhz(void)
120{
Simon Glass64b723f2017-08-03 12:22:12 -0600121 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530122 /*
123 * interval is the number of platform cycles(MHz) between
124 * wake up events generated by EPU.
125 */
126 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
127
128 if (interval)
129 interval_mhz = simple_strtoul(interval, NULL, 10);
130
131 return interval_mhz;
132}
133
134void erratum_a009635(void)
135{
136 u32 val;
137 unsigned long interval_mhz = get_internval_val_mhz();
138
139 if (!interval_mhz)
140 return;
141
142 val = in_le32(DCSR_CGACRE5);
143 writel(val | 0x00000200, DCSR_CGACRE5);
144
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);
155}
156#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
157
Scott Wood8e728cd2015-03-24 13:25:02 -0700158static void erratum_rcw_src(void)
159{
Santan Kumar99136482017-05-05 15:42:28 +0530160#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700161 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
162 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
163 u32 val;
164
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);
169#endif
170}
171
York Sun0404a392015-03-23 10:41:35 -0700172#define I2C_DEBUG_REG 0x6
173#define I2C_GLITCH_EN 0x8
174/*
175 * This erratum requires setting glitch_en bit to enable
176 * digital glitch filter to improve clock stability.
177 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530178#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700179static void erratum_a009203(void)
180{
181 u8 __iomem *ptr;
182#ifdef CONFIG_SYS_I2C
183#ifdef I2C1_BASE_ADDR
184 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
185
186 writeb(I2C_GLITCH_EN, ptr);
187#endif
188#ifdef I2C2_BASE_ADDR
189 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
190
191 writeb(I2C_GLITCH_EN, ptr);
192#endif
193#ifdef I2C3_BASE_ADDR
194 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
195
196 writeb(I2C_GLITCH_EN, ptr);
197#endif
198#ifdef I2C4_BASE_ADDR
199 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
200
201 writeb(I2C_GLITCH_EN, ptr);
202#endif
203#endif
204}
Ashish kumar3b52a232017-02-23 16:03:57 +0530205#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800206
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530207void bypass_smmu(void)
208{
209 u32 val;
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);
214}
Scott Woodf64c98c2015-03-20 19:28:12 -0700215void fsl_lsch3_early_init_f(void)
216{
Scott Wood8e728cd2015-03-24 13:25:02 -0700217 erratum_rcw_src();
Scott Woodf64c98c2015-03-20 19:28:12 -0700218 init_early_memctl_regs(); /* tighten IFC timing */
Ashish kumar3b52a232017-02-23 16:03:57 +0530219#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700220 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530221#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800222 erratum_a008514();
223 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800224 erratum_a009008();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530225#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
230 */
231 if (fsl_check_boot_mode_secure() == 1)
232 bypass_smmu();
233#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700234}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800235
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;
240
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);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800244 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800245
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);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800249 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800250
251 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
Simon Glass48228732017-06-14 21:28:41 -0600252 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800253
254 return 0;
255}
256#endif
257
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530258#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800259#ifdef CONFIG_SCSI_AHCI_PLAT
260int sata_init(void)
261{
262 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
263
Shaohui Xieed81e2b2016-09-07 17:56:12 +0800264 /* Disable SATA ECC */
265 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
Tang Yuantian57894be2015-12-09 15:32:18 +0800266 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800267 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantian2945ae02016-08-08 15:07:20 +0800268 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800269
270 ahci_init((void __iomem *)CONFIG_SYS_SATA);
Simon Glass48228732017-06-14 21:28:41 -0600271 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800272
273 return 0;
274}
275#endif
276
Mingkai Hu8beb0752015-12-07 16:58:54 +0800277static void erratum_a009929(void)
278{
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);
283
284 rstrqmr1 |= 0x00000400;
285 gur_out32(&gur->rstrqmr1, rstrqmr1);
286 writel(0x01000000, dcsr_cop_ccp);
287#endif
288}
289
Mingkai Hu172081c2016-02-02 11:28:03 +0800290/*
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.
294 */
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.
298#endif
299
300static void erratum_a009660(void)
301{
302#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
303 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
304 out_be32(eddrtqcr1, 0x63b20042);
305#endif
306}
307
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800308static void erratum_a008850_early(void)
309{
310#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
311 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530312 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
313 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800314 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
315
York Sune6b871e2017-05-15 08:51:59 -0700316 /* Skip if running at lower exception level */
317 if (current_el() < 3)
318 return;
319
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800320 /* disables propagation of barrier transactions to DDRC from CCI400 */
321 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
322
323 /* disable the re-ordering in DDRC */
324 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
325#endif
326}
327
328void erratum_a008850_post(void)
329{
330#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
331 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530332 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
333 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800334 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
335 u32 tmp;
336
York Sune6b871e2017-05-15 08:51:59 -0700337 /* Skip if running at lower exception level */
338 if (current_el() < 3)
339 return;
340
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800341 /* enable propagation of barrier transactions to DDRC from CCI400 */
342 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
343
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);
348#endif
349}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800350
351#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
352void erratum_a010315(void)
353{
354 int i;
355
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);
360 }
361}
362#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800363
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800364static void erratum_a010539(void)
365{
366#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
367 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
368 u32 porsr1;
369
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),
373 porsr1);
374#endif
375}
376
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800377/* Get VDD in the unit mV from voltage ID */
378int get_core_volt_from_fuse(void)
379{
380 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
381 int vdd;
382 u32 fusesr;
383 u8 vid;
384
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;
392 }
393 debug("%s: VID = 0x%x\n", __func__, vid);
394 switch (vid) {
395 case 0x00: /* VID isn't supported */
396 vdd = -EINVAL;
397 debug("%s: The VID feature is not supported\n", __func__);
398 break;
399 case 0x08: /* 0.9V silicon */
400 vdd = 900;
401 break;
402 case 0x10: /* 1.0V silicon */
403 vdd = 1000;
404 break;
405 default: /* Other core voltage */
406 vdd = -EINVAL;
407 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
408 break;
409 }
410 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
411
412 return vdd;
413}
414
415__weak int board_switch_core_volt(u32 vdd)
416{
417 return 0;
418}
419
420static int setup_core_volt(u32 vdd)
421{
422 return board_setup_core_volt(vdd);
423}
424
425#ifdef CONFIG_SYS_FSL_DDR
426static void ddr_enable_0v9_volt(bool en)
427{
428 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
429 u32 tmp;
430
431 tmp = ddr_in32(&ddr->ddr_cdr1);
432
433 if (en)
434 tmp |= DDR_CDR1_V0PT9_EN;
435 else
436 tmp &= ~DDR_CDR1_V0PT9_EN;
437
438 ddr_out32(&ddr->ddr_cdr1, tmp);
439}
440#endif
441
442int setup_chip_volt(void)
443{
444 int vdd;
445
446 vdd = get_core_volt_from_fuse();
447 /* Nothing to do for silicons doesn't support VID */
448 if (vdd < 0)
449 return vdd;
450
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);
456#endif
457
458#ifdef CONFIG_SYS_FSL_DDR
459 if (vdd == 900)
460 ddr_enable_0v9_volt(true);
461#endif
462
463 return 0;
464}
465
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800466void fsl_lsch2_early_init_f(void)
467{
Ashish Kumar11234062017-08-11 11:09:14 +0530468 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
469 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530470 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800471
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800472#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
473 enable_layerscape_ns_access();
474#endif
475
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800476#ifdef CONFIG_FSL_IFC
477 init_early_memctl_regs(); /* tighten IFC timing */
478#endif
479
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800480#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800481 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
482#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530483 /* Make SEC reads and writes snoopable */
484 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800485 SCFG_SNPCNFGCR_SECWRSNP |
486 SCFG_SNPCNFGCR_SATARDSNP |
487 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530488
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800489 /*
490 * Enable snoop requests and DVM message requests for
491 * Slave insterface S4 (A53 core cluster)
492 */
York Sune6b871e2017-05-15 08:51:59 -0700493 if (current_el() == 3) {
494 out_le32(&cci->slave[4].snoop_ctrl,
495 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
496 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800497
498 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800499 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800500 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800501 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800502 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800503 erratum_a009008();
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800504}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800505#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700506
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800507#ifdef CONFIG_QSPI_AHB_INIT
508/* Enable 4bytes address support and fast read */
509int qspi_ahb_init(void)
510{
511 u32 *qspi_lut, lut_key, *qspi_key;
512
513 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
514 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
515
516 lut_key = in_be32(qspi_key);
517
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);
529 } else {
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);
540 }
541
542 return 0;
543}
544#endif
545
Mingkai Hu0e58b512015-10-26 19:47:50 +0800546#ifdef CONFIG_BOARD_LATE_INIT
547int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700548{
Tang Yuantian57894be2015-12-09 15:32:18 +0800549#ifdef CONFIG_SCSI_AHCI_PLAT
550 sata_init();
551#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530552#ifdef CONFIG_CHAIN_OF_TRUST
553 fsl_setenv_chain_of_trust();
554#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800555#ifdef CONFIG_QSPI_AHB_INIT
556 qspi_ahb_init();
557#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800558
Mingkai Hu0e58b512015-10-26 19:47:50 +0800559 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700560}
561#endif