blob: 2f306c509ab0bb9593db522ddbbb309d44eccb8f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Scott Woodf64c98c2015-03-20 19:28:12 -07002/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08003 * Copyright 2014-2015 Freescale Semiconductor
Scott Woodf64c98c2015-03-20 19:28:12 -07004 */
5
6#include <common.h>
Ashish Kumar11234062017-08-11 11:09:14 +05307#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -07008#include <fsl_ifc.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +08009#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080010#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070011#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070012#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053013#include <asm/arch-fsl-layerscape/config.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030014#include <asm/arch-fsl-layerscape/fsl_icid.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080015#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080016#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080017#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053018#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080019#include <fsl_ddr_sdram.h>
20#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053021#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053022#ifdef CONFIG_CHAIN_OF_TRUST
23#include <fsl_validate.h>
24#endif
Ashish Kumarb25faa22017-08-31 16:12:53 +053025#include <fsl_immap.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070026
York Suncbe8e1c2016-04-04 11:41:26 -070027bool soc_has_dp_ddr(void)
28{
29 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
30 u32 svr = gur_in32(&gur->svr);
31
Priyanka Jain4a6f1732016-11-17 12:29:55 +053032 /* LS2085A, LS2088A, LS2048A has DP_DDR */
33 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
34 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
35 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070036 return true;
37
38 return false;
39}
40
41bool soc_has_aiop(void)
42{
43 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
44 u32 svr = gur_in32(&gur->svr);
45
46 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053047 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070048 return true;
49
50 return false;
51}
52
Ran Wangb358b7b2017-09-04 18:46:48 +080053static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
54{
55 scfg_clrsetbits32(scfg + offset / 4,
56 0xF << 6,
57 SCFG_USB_TXVREFTUNE << 6);
58}
59
60static void erratum_a009008(void)
61{
62#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
63 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080064
Ran Wang02dc77b2017-11-13 16:14:48 +080065#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
66 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080067 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080068#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080069 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
70 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080071#endif
Ran Wangb358b7b2017-09-04 18:46:48 +080072#elif defined(CONFIG_ARCH_LS2080A)
73 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
74#endif
75#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
76}
77
Ran Wang9e8fabc2017-09-04 18:46:49 +080078static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
79{
80 scfg_clrbits32(scfg + offset / 4,
81 SCFG_USB_SQRXTUNE_MASK << 23);
82}
83
84static void erratum_a009798(void)
85{
86#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
87 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
88
Ran Wang02dc77b2017-11-13 16:14:48 +080089#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
90 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080091 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080092#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080093 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
94 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080095#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +080096#elif defined(CONFIG_ARCH_LS2080A)
97 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
98#endif
99#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
100}
101
Ran Wang02dc77b2017-11-13 16:14:48 +0800102#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
103 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800104static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
105{
106 scfg_clrsetbits32(scfg + offset / 4,
107 0x7F << 9,
108 SCFG_USB_PCSTXSWINGFULL << 9);
109}
110#endif
111
112static void erratum_a008997(void)
113{
114#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800115#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
116 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800117 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
118
119 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800120#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800121 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
122 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
123#endif
Ran Wang02dc77b2017-11-13 16:14:48 +0800124#endif
Ran Wange64f7472017-09-04 18:46:50 +0800125#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
126}
127
Ran Wang02dc77b2017-11-13 16:14:48 +0800128#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
129 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800130
131#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
132 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
133 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
134 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
135 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
136
Ran Wangef277072017-09-22 15:21:34 +0800137#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
Ran Wang3ba69482017-09-04 18:46:51 +0800138
139#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
140 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
141 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
142 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
143 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
144
145#endif
146
147static void erratum_a009007(void)
148{
Ran Wang02dc77b2017-11-13 16:14:48 +0800149#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
150 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800151 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
152
153 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800154#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800155 usb_phy = (void __iomem *)SCFG_USB_PHY2;
156 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
157
158 usb_phy = (void __iomem *)SCFG_USB_PHY3;
159 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800160#endif
Ran Wangef277072017-09-22 15:21:34 +0800161#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
Ran Wang3ba69482017-09-04 18:46:51 +0800162 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
163
164 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
165 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
166#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
167}
168
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800169#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +0800170/*
171 * This erratum requires setting a value to eddrtqcr1 to
172 * optimal the DDR performance.
173 */
174static void erratum_a008336(void)
175{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800176#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800177 u32 *eddrtqcr1;
178
Yao Yuanfae88052015-12-05 14:59:14 +0800179#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
180 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800181 if (fsl_ddr_get_version(0) == 0x50200)
182 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800183#endif
184#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
185 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800186 if (fsl_ddr_get_version(0) == 0x50200)
187 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800188#endif
189#endif
190}
191
192/*
193 * This erratum requires a register write before being Memory
194 * controller 3 being enabled.
195 */
196static void erratum_a008514(void)
197{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800198#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800199 u32 *eddrtqcr1;
200
Yao Yuanfae88052015-12-05 14:59:14 +0800201#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
202 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
203 out_le32(eddrtqcr1, 0x63b20002);
204#endif
205#endif
206}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530207#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
208#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
209
210static unsigned long get_internval_val_mhz(void)
211{
Simon Glass64b723f2017-08-03 12:22:12 -0600212 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530213 /*
214 * interval is the number of platform cycles(MHz) between
215 * wake up events generated by EPU.
216 */
217 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
218
219 if (interval)
220 interval_mhz = simple_strtoul(interval, NULL, 10);
221
222 return interval_mhz;
223}
224
225void erratum_a009635(void)
226{
227 u32 val;
228 unsigned long interval_mhz = get_internval_val_mhz();
229
230 if (!interval_mhz)
231 return;
232
233 val = in_le32(DCSR_CGACRE5);
234 writel(val | 0x00000200, DCSR_CGACRE5);
235
236 val = in_le32(EPU_EPCMPR5);
237 writel(interval_mhz, EPU_EPCMPR5);
238 val = in_le32(EPU_EPCCR5);
239 writel(val | 0x82820000, EPU_EPCCR5);
240 val = in_le32(EPU_EPSMCR5);
241 writel(val | 0x002f0000, EPU_EPSMCR5);
242 val = in_le32(EPU_EPECR5);
243 writel(val | 0x20000000, EPU_EPECR5);
244 val = in_le32(EPU_EPGCR);
245 writel(val | 0x80000000, EPU_EPGCR);
246}
247#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
248
Scott Wood8e728cd2015-03-24 13:25:02 -0700249static void erratum_rcw_src(void)
250{
Santan Kumar99136482017-05-05 15:42:28 +0530251#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700252 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
253 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
254 u32 val;
255
256 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
257 val &= ~DCFG_PORSR1_RCW_SRC;
258 val |= DCFG_PORSR1_RCW_SRC_NOR;
259 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
260#endif
261}
262
York Sun0404a392015-03-23 10:41:35 -0700263#define I2C_DEBUG_REG 0x6
264#define I2C_GLITCH_EN 0x8
265/*
266 * This erratum requires setting glitch_en bit to enable
267 * digital glitch filter to improve clock stability.
268 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530269#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700270static void erratum_a009203(void)
271{
York Sun0404a392015-03-23 10:41:35 -0700272#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530273 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700274#ifdef I2C1_BASE_ADDR
275 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
276
277 writeb(I2C_GLITCH_EN, ptr);
278#endif
279#ifdef I2C2_BASE_ADDR
280 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
281
282 writeb(I2C_GLITCH_EN, ptr);
283#endif
284#ifdef I2C3_BASE_ADDR
285 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
286
287 writeb(I2C_GLITCH_EN, ptr);
288#endif
289#ifdef I2C4_BASE_ADDR
290 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
291
292 writeb(I2C_GLITCH_EN, ptr);
293#endif
294#endif
295}
Ashish kumar3b52a232017-02-23 16:03:57 +0530296#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800297
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530298void bypass_smmu(void)
299{
300 u32 val;
301 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
302 out_le32(SMMU_SCR0, val);
303 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
304 out_le32(SMMU_NSCR0, val);
305}
Scott Woodf64c98c2015-03-20 19:28:12 -0700306void fsl_lsch3_early_init_f(void)
307{
Scott Wood8e728cd2015-03-24 13:25:02 -0700308 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530309#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700310 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530311#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530312#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700313 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530314#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800315 erratum_a008514();
316 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800317 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800318 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800319 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800320 erratum_a009007();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530321#ifdef CONFIG_CHAIN_OF_TRUST
322 /* In case of Secure Boot, the IBR configures the SMMU
323 * to allow only Secure transactions.
324 * SMMU must be reset in bypass mode.
325 * Set the ClientPD bit and Clear the USFCFG Bit
326 */
327 if (fsl_check_boot_mode_secure() == 1)
328 bypass_smmu();
329#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700330}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800331
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530332/* Get VDD in the unit mV from voltage ID */
333int get_core_volt_from_fuse(void)
334{
335 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
336 int vdd;
337 u32 fusesr;
338 u8 vid;
339
340 /* get the voltage ID from fuse status register */
341 fusesr = in_le32(&gur->dcfg_fusesr);
342 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
343 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
344 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
345 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
346 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
347 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
348 }
349 debug("%s: VID = 0x%x\n", __func__, vid);
350 switch (vid) {
351 case 0x00: /* VID isn't supported */
352 vdd = -EINVAL;
353 debug("%s: The VID feature is not supported\n", __func__);
354 break;
355 case 0x08: /* 0.9V silicon */
356 vdd = 900;
357 break;
358 case 0x10: /* 1.0V silicon */
359 vdd = 1000;
360 break;
361 default: /* Other core voltage */
362 vdd = -EINVAL;
363 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
364 break;
365 }
366 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
367
368 return vdd;
369}
370
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530371#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800372
Mingkai Hu8beb0752015-12-07 16:58:54 +0800373static void erratum_a009929(void)
374{
375#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
376 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
377 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
378 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
379
380 rstrqmr1 |= 0x00000400;
381 gur_out32(&gur->rstrqmr1, rstrqmr1);
382 writel(0x01000000, dcsr_cop_ccp);
383#endif
384}
385
Mingkai Hu172081c2016-02-02 11:28:03 +0800386/*
387 * This erratum requires setting a value to eddrtqcr1 to optimal
388 * the DDR performance. The eddrtqcr1 register is in SCFG space
389 * of LS1043A and the offset is 0x157_020c.
390 */
391#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
392 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
393#error A009660 and A008514 can not be both enabled.
394#endif
395
396static void erratum_a009660(void)
397{
398#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
399 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
400 out_be32(eddrtqcr1, 0x63b20042);
401#endif
402}
403
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800404static void erratum_a008850_early(void)
405{
406#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
407 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530408 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
409 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800410 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
411
York Sune6b871e2017-05-15 08:51:59 -0700412 /* Skip if running at lower exception level */
413 if (current_el() < 3)
414 return;
415
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800416 /* disables propagation of barrier transactions to DDRC from CCI400 */
417 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
418
419 /* disable the re-ordering in DDRC */
420 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
421#endif
422}
423
424void erratum_a008850_post(void)
425{
426#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
427 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530428 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
429 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800430 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
431 u32 tmp;
432
York Sune6b871e2017-05-15 08:51:59 -0700433 /* Skip if running at lower exception level */
434 if (current_el() < 3)
435 return;
436
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800437 /* enable propagation of barrier transactions to DDRC from CCI400 */
438 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
439
440 /* enable the re-ordering in DDRC */
441 tmp = ddr_in32(&ddr->eor);
442 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
443 ddr_out32(&ddr->eor, tmp);
444#endif
445}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800446
447#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
448void erratum_a010315(void)
449{
450 int i;
451
452 for (i = PCIE1; i <= PCIE4; i++)
453 if (!is_serdes_configured(i)) {
454 debug("PCIe%d: disabled all R/W permission!\n", i);
455 set_pcie_ns_access(i, 0);
456 }
457}
458#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800459
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800460static void erratum_a010539(void)
461{
462#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
463 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
464 u32 porsr1;
465
466 porsr1 = in_be32(&gur->porsr1);
467 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
468 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
469 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800470 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800471#endif
472}
473
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800474/* Get VDD in the unit mV from voltage ID */
475int get_core_volt_from_fuse(void)
476{
477 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
478 int vdd;
479 u32 fusesr;
480 u8 vid;
481
482 fusesr = in_be32(&gur->dcfg_fusesr);
483 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
484 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
485 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
486 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
487 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
488 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
489 }
490 debug("%s: VID = 0x%x\n", __func__, vid);
491 switch (vid) {
492 case 0x00: /* VID isn't supported */
493 vdd = -EINVAL;
494 debug("%s: The VID feature is not supported\n", __func__);
495 break;
496 case 0x08: /* 0.9V silicon */
497 vdd = 900;
498 break;
499 case 0x10: /* 1.0V silicon */
500 vdd = 1000;
501 break;
502 default: /* Other core voltage */
503 vdd = -EINVAL;
504 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
505 break;
506 }
507 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
508
509 return vdd;
510}
511
512__weak int board_switch_core_volt(u32 vdd)
513{
514 return 0;
515}
516
517static int setup_core_volt(u32 vdd)
518{
519 return board_setup_core_volt(vdd);
520}
521
522#ifdef CONFIG_SYS_FSL_DDR
523static void ddr_enable_0v9_volt(bool en)
524{
525 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
526 u32 tmp;
527
528 tmp = ddr_in32(&ddr->ddr_cdr1);
529
530 if (en)
531 tmp |= DDR_CDR1_V0PT9_EN;
532 else
533 tmp &= ~DDR_CDR1_V0PT9_EN;
534
535 ddr_out32(&ddr->ddr_cdr1, tmp);
536}
537#endif
538
539int setup_chip_volt(void)
540{
541 int vdd;
542
543 vdd = get_core_volt_from_fuse();
544 /* Nothing to do for silicons doesn't support VID */
545 if (vdd < 0)
546 return vdd;
547
548 if (setup_core_volt(vdd))
549 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
550#ifdef CONFIG_SYS_HAS_SERDES
551 if (setup_serdes_volt(vdd))
552 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
553#endif
554
555#ifdef CONFIG_SYS_FSL_DDR
556 if (vdd == 900)
557 ddr_enable_0v9_volt(true);
558#endif
559
560 return 0;
561}
562
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530563#ifdef CONFIG_FSL_PFE
564void init_pfe_scfg_dcfg_regs(void)
565{
566 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
567 u32 ecccr2;
568
569 out_be32(&scfg->pfeasbcr,
570 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
571 out_be32(&scfg->pfebsbcr,
572 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
573
574 /* CCI-400 QoS settings for PFE */
575 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
576 | SCFG_WR_QOS1_PFE2_QOS));
577 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
578 | SCFG_RD_QOS1_PFE2_QOS));
579
580 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
581 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
582 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
583}
584#endif
585
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800586void fsl_lsch2_early_init_f(void)
587{
Ashish Kumar11234062017-08-11 11:09:14 +0530588 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
589 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530590 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800591
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800592#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
593 enable_layerscape_ns_access();
594#endif
595
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800596#ifdef CONFIG_FSL_IFC
597 init_early_memctl_regs(); /* tighten IFC timing */
598#endif
599
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800600#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800601 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
602#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530603 /* Make SEC reads and writes snoopable */
604 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800605 SCFG_SNPCNFGCR_SECWRSNP |
606 SCFG_SNPCNFGCR_SATARDSNP |
607 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530608
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800609 /*
610 * Enable snoop requests and DVM message requests for
611 * Slave insterface S4 (A53 core cluster)
612 */
York Sune6b871e2017-05-15 08:51:59 -0700613 if (current_el() == 3) {
614 out_le32(&cci->slave[4].snoop_ctrl,
615 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
616 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800617
618 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800619 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800620 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800621 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800622 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800623 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800624 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800625 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800626 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300627
628#ifdef CONFIG_ARCH_LS1046A
629 set_icids();
630#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800631}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800632#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700633
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800634#ifdef CONFIG_QSPI_AHB_INIT
635/* Enable 4bytes address support and fast read */
636int qspi_ahb_init(void)
637{
638 u32 *qspi_lut, lut_key, *qspi_key;
639
640 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
641 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
642
643 lut_key = in_be32(qspi_key);
644
645 if (lut_key == 0x5af05af0) {
646 /* That means the register is BE */
647 out_be32(qspi_key, 0x5af05af0);
648 /* Unlock the lut table */
649 out_be32(qspi_key + 1, 0x00000002);
650 out_be32(qspi_lut, 0x0820040c);
651 out_be32(qspi_lut + 1, 0x1c080c08);
652 out_be32(qspi_lut + 2, 0x00002400);
653 /* Lock the lut table */
654 out_be32(qspi_key, 0x5af05af0);
655 out_be32(qspi_key + 1, 0x00000001);
656 } else {
657 /* That means the register is LE */
658 out_le32(qspi_key, 0x5af05af0);
659 /* Unlock the lut table */
660 out_le32(qspi_key + 1, 0x00000002);
661 out_le32(qspi_lut, 0x0820040c);
662 out_le32(qspi_lut + 1, 0x1c080c08);
663 out_le32(qspi_lut + 2, 0x00002400);
664 /* Lock the lut table */
665 out_le32(qspi_key, 0x5af05af0);
666 out_le32(qspi_key + 1, 0x00000001);
667 }
668
669 return 0;
670}
671#endif
672
Mingkai Hu0e58b512015-10-26 19:47:50 +0800673#ifdef CONFIG_BOARD_LATE_INIT
674int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700675{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530676#ifdef CONFIG_CHAIN_OF_TRUST
677 fsl_setenv_chain_of_trust();
678#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800679#ifdef CONFIG_QSPI_AHB_INIT
680 qspi_ahb_init();
681#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800682
Mingkai Hu0e58b512015-10-26 19:47:50 +0800683 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700684}
685#endif