blob: 00c705f74eb2f397903f0443fb650b85705cc35d [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
Pankit Gargd6bd6782019-05-30 12:04:15 +00004 * Copyright 2019 NXP
Scott Woodf64c98c2015-03-20 19:28:12 -07005 */
6
7#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06008#include <env.h>
Ashish Kumar11234062017-08-11 11:09:14 +05309#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -070010#include <fsl_ifc.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080011#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080012#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070013#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070014#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053015#include <asm/arch-fsl-layerscape/config.h>
Ran Wang4e7cdcf2018-08-10 15:00:00 +080016#include <asm/arch-fsl-layerscape/ns_access.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030017#include <asm/arch-fsl-layerscape/fsl_icid.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080018#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080019#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080020#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053021#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080022#include <fsl_ddr_sdram.h>
23#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053024#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053025#ifdef CONFIG_CHAIN_OF_TRUST
26#include <fsl_validate.h>
27#endif
Ashish Kumarb25faa22017-08-31 16:12:53 +053028#include <fsl_immap.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000029#ifdef CONFIG_TFABOOT
30#include <environment.h>
31DECLARE_GLOBAL_DATA_PTR;
32#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070033
York Suncbe8e1c2016-04-04 11:41:26 -070034bool soc_has_dp_ddr(void)
35{
36 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
37 u32 svr = gur_in32(&gur->svr);
38
Priyanka Jain4a6f1732016-11-17 12:29:55 +053039 /* LS2085A, LS2088A, LS2048A has DP_DDR */
40 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
41 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
42 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070043 return true;
44
45 return false;
46}
47
48bool soc_has_aiop(void)
49{
50 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
51 u32 svr = gur_in32(&gur->svr);
52
53 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053054 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070055 return true;
56
57 return false;
58}
59
Ran Wangb358b7b2017-09-04 18:46:48 +080060static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
61{
62 scfg_clrsetbits32(scfg + offset / 4,
63 0xF << 6,
64 SCFG_USB_TXVREFTUNE << 6);
65}
66
67static void erratum_a009008(void)
68{
69#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
70 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080071
Ran Wang02dc77b2017-11-13 16:14:48 +080072#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
73 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080074 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080075#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080076 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
77 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080078#endif
Ran Wangb358b7b2017-09-04 18:46:48 +080079#elif defined(CONFIG_ARCH_LS2080A)
80 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
81#endif
82#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
83}
84
Ran Wang9e8fabc2017-09-04 18:46:49 +080085static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
86{
87 scfg_clrbits32(scfg + offset / 4,
88 SCFG_USB_SQRXTUNE_MASK << 23);
89}
90
91static void erratum_a009798(void)
92{
93#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
94 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
95
Ran Wang02dc77b2017-11-13 16:14:48 +080096#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
97 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080098 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080099#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800100 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
101 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800102#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800103#elif defined(CONFIG_ARCH_LS2080A)
104 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
105#endif
106#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
107}
108
Ran Wang02dc77b2017-11-13 16:14:48 +0800109#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
110 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800111static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
112{
113 scfg_clrsetbits32(scfg + offset / 4,
114 0x7F << 9,
115 SCFG_USB_PCSTXSWINGFULL << 9);
116}
117#endif
118
119static void erratum_a008997(void)
120{
121#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800122#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
123 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800124 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
125
126 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800127#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800128 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
129 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
130#endif
Ran Wange118acb2019-05-14 17:34:56 +0800131#elif defined(CONFIG_ARCH_LS1028A)
132 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
133 0x7F << 11,
134 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800135#endif
Ran Wange64f7472017-09-04 18:46:50 +0800136#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
137}
138
Ran Wang02dc77b2017-11-13 16:14:48 +0800139#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
140 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800141
142#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
143 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
144 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
145 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
146 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
147
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800148#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
149 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800150
151#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
152 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
153 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
154 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
155 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
156
157#endif
158
159static void erratum_a009007(void)
160{
Ran Wang02dc77b2017-11-13 16:14:48 +0800161#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
162 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800163 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
164
165 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800166#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800167 usb_phy = (void __iomem *)SCFG_USB_PHY2;
168 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
169
170 usb_phy = (void __iomem *)SCFG_USB_PHY3;
171 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800172#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800173#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
174 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800175 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
176
177 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
178 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
179#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
180}
181
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800182#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +0800183/*
184 * This erratum requires setting a value to eddrtqcr1 to
185 * optimal the DDR performance.
186 */
187static void erratum_a008336(void)
188{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800189#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800190 u32 *eddrtqcr1;
191
Yao Yuanfae88052015-12-05 14:59:14 +0800192#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
193 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800194 if (fsl_ddr_get_version(0) == 0x50200)
195 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800196#endif
197#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
198 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800199 if (fsl_ddr_get_version(0) == 0x50200)
200 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800201#endif
202#endif
203}
204
205/*
206 * This erratum requires a register write before being Memory
207 * controller 3 being enabled.
208 */
209static void erratum_a008514(void)
210{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800211#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800212 u32 *eddrtqcr1;
213
Yao Yuanfae88052015-12-05 14:59:14 +0800214#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
215 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
216 out_le32(eddrtqcr1, 0x63b20002);
217#endif
218#endif
219}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530220#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
221#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
222
223static unsigned long get_internval_val_mhz(void)
224{
Simon Glass64b723f2017-08-03 12:22:12 -0600225 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530226 /*
227 * interval is the number of platform cycles(MHz) between
228 * wake up events generated by EPU.
229 */
230 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
231
232 if (interval)
233 interval_mhz = simple_strtoul(interval, NULL, 10);
234
235 return interval_mhz;
236}
237
238void erratum_a009635(void)
239{
240 u32 val;
241 unsigned long interval_mhz = get_internval_val_mhz();
242
243 if (!interval_mhz)
244 return;
245
246 val = in_le32(DCSR_CGACRE5);
247 writel(val | 0x00000200, DCSR_CGACRE5);
248
249 val = in_le32(EPU_EPCMPR5);
250 writel(interval_mhz, EPU_EPCMPR5);
251 val = in_le32(EPU_EPCCR5);
252 writel(val | 0x82820000, EPU_EPCCR5);
253 val = in_le32(EPU_EPSMCR5);
254 writel(val | 0x002f0000, EPU_EPSMCR5);
255 val = in_le32(EPU_EPECR5);
256 writel(val | 0x20000000, EPU_EPECR5);
257 val = in_le32(EPU_EPGCR);
258 writel(val | 0x80000000, EPU_EPGCR);
259}
260#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
261
Scott Wood8e728cd2015-03-24 13:25:02 -0700262static void erratum_rcw_src(void)
263{
Santan Kumar99136482017-05-05 15:42:28 +0530264#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700265 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
266 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
267 u32 val;
268
269 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
270 val &= ~DCFG_PORSR1_RCW_SRC;
271 val |= DCFG_PORSR1_RCW_SRC_NOR;
272 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
273#endif
274}
275
York Sun0404a392015-03-23 10:41:35 -0700276#define I2C_DEBUG_REG 0x6
277#define I2C_GLITCH_EN 0x8
278/*
279 * This erratum requires setting glitch_en bit to enable
280 * digital glitch filter to improve clock stability.
281 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530282#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700283static void erratum_a009203(void)
284{
York Sun0404a392015-03-23 10:41:35 -0700285#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530286 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700287#ifdef I2C1_BASE_ADDR
288 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
289
290 writeb(I2C_GLITCH_EN, ptr);
291#endif
292#ifdef I2C2_BASE_ADDR
293 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
294
295 writeb(I2C_GLITCH_EN, ptr);
296#endif
297#ifdef I2C3_BASE_ADDR
298 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
299
300 writeb(I2C_GLITCH_EN, ptr);
301#endif
302#ifdef I2C4_BASE_ADDR
303 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
304
305 writeb(I2C_GLITCH_EN, ptr);
306#endif
307#endif
308}
Ashish kumar3b52a232017-02-23 16:03:57 +0530309#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800310
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530311void bypass_smmu(void)
312{
313 u32 val;
314 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
315 out_le32(SMMU_SCR0, val);
316 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
317 out_le32(SMMU_NSCR0, val);
318}
Scott Woodf64c98c2015-03-20 19:28:12 -0700319void fsl_lsch3_early_init_f(void)
320{
Scott Wood8e728cd2015-03-24 13:25:02 -0700321 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530322#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700323 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530324#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530325#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700326 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530327#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800328 erratum_a008514();
329 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800330 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800331 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800332 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800333 erratum_a009007();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530334#ifdef CONFIG_CHAIN_OF_TRUST
335 /* In case of Secure Boot, the IBR configures the SMMU
336 * to allow only Secure transactions.
337 * SMMU must be reset in bypass mode.
338 * Set the ClientPD bit and Clear the USFCFG Bit
339 */
340 if (fsl_check_boot_mode_secure() == 1)
341 bypass_smmu();
342#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700343}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800344
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530345/* Get VDD in the unit mV from voltage ID */
346int get_core_volt_from_fuse(void)
347{
348 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
349 int vdd;
350 u32 fusesr;
351 u8 vid;
352
353 /* get the voltage ID from fuse status register */
354 fusesr = in_le32(&gur->dcfg_fusesr);
355 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
356 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
357 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
358 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
359 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
360 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
361 }
362 debug("%s: VID = 0x%x\n", __func__, vid);
363 switch (vid) {
364 case 0x00: /* VID isn't supported */
365 vdd = -EINVAL;
366 debug("%s: The VID feature is not supported\n", __func__);
367 break;
368 case 0x08: /* 0.9V silicon */
369 vdd = 900;
370 break;
371 case 0x10: /* 1.0V silicon */
372 vdd = 1000;
373 break;
374 default: /* Other core voltage */
375 vdd = -EINVAL;
376 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
377 break;
378 }
379 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
380
381 return vdd;
382}
383
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530384#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800385
Mingkai Hu8beb0752015-12-07 16:58:54 +0800386static void erratum_a009929(void)
387{
388#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
389 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
390 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
391 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
392
393 rstrqmr1 |= 0x00000400;
394 gur_out32(&gur->rstrqmr1, rstrqmr1);
395 writel(0x01000000, dcsr_cop_ccp);
396#endif
397}
398
Mingkai Hu172081c2016-02-02 11:28:03 +0800399/*
400 * This erratum requires setting a value to eddrtqcr1 to optimal
401 * the DDR performance. The eddrtqcr1 register is in SCFG space
402 * of LS1043A and the offset is 0x157_020c.
403 */
404#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
405 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
406#error A009660 and A008514 can not be both enabled.
407#endif
408
409static void erratum_a009660(void)
410{
411#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
412 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
413 out_be32(eddrtqcr1, 0x63b20042);
414#endif
415}
416
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800417static void erratum_a008850_early(void)
418{
419#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
420 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530421 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
422 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800423 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
424
York Sune6b871e2017-05-15 08:51:59 -0700425 /* Skip if running at lower exception level */
426 if (current_el() < 3)
427 return;
428
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800429 /* disables propagation of barrier transactions to DDRC from CCI400 */
430 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
431
432 /* disable the re-ordering in DDRC */
433 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
434#endif
435}
436
437void erratum_a008850_post(void)
438{
439#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
440 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530441 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
442 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800443 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
444 u32 tmp;
445
York Sune6b871e2017-05-15 08:51:59 -0700446 /* Skip if running at lower exception level */
447 if (current_el() < 3)
448 return;
449
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800450 /* enable propagation of barrier transactions to DDRC from CCI400 */
451 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
452
453 /* enable the re-ordering in DDRC */
454 tmp = ddr_in32(&ddr->eor);
455 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
456 ddr_out32(&ddr->eor, tmp);
457#endif
458}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800459
460#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
461void erratum_a010315(void)
462{
463 int i;
464
465 for (i = PCIE1; i <= PCIE4; i++)
466 if (!is_serdes_configured(i)) {
467 debug("PCIe%d: disabled all R/W permission!\n", i);
468 set_pcie_ns_access(i, 0);
469 }
470}
471#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800472
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800473static void erratum_a010539(void)
474{
475#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
476 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
477 u32 porsr1;
478
479 porsr1 = in_be32(&gur->porsr1);
480 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
481 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
482 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800483 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800484#endif
485}
486
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800487/* Get VDD in the unit mV from voltage ID */
488int get_core_volt_from_fuse(void)
489{
490 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
491 int vdd;
492 u32 fusesr;
493 u8 vid;
494
495 fusesr = in_be32(&gur->dcfg_fusesr);
496 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
497 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
498 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
499 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
500 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
501 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
502 }
503 debug("%s: VID = 0x%x\n", __func__, vid);
504 switch (vid) {
505 case 0x00: /* VID isn't supported */
506 vdd = -EINVAL;
507 debug("%s: The VID feature is not supported\n", __func__);
508 break;
509 case 0x08: /* 0.9V silicon */
510 vdd = 900;
511 break;
512 case 0x10: /* 1.0V silicon */
513 vdd = 1000;
514 break;
515 default: /* Other core voltage */
516 vdd = -EINVAL;
517 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
518 break;
519 }
520 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
521
522 return vdd;
523}
524
525__weak int board_switch_core_volt(u32 vdd)
526{
527 return 0;
528}
529
530static int setup_core_volt(u32 vdd)
531{
532 return board_setup_core_volt(vdd);
533}
534
535#ifdef CONFIG_SYS_FSL_DDR
536static void ddr_enable_0v9_volt(bool en)
537{
538 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
539 u32 tmp;
540
541 tmp = ddr_in32(&ddr->ddr_cdr1);
542
543 if (en)
544 tmp |= DDR_CDR1_V0PT9_EN;
545 else
546 tmp &= ~DDR_CDR1_V0PT9_EN;
547
548 ddr_out32(&ddr->ddr_cdr1, tmp);
549}
550#endif
551
552int setup_chip_volt(void)
553{
554 int vdd;
555
556 vdd = get_core_volt_from_fuse();
557 /* Nothing to do for silicons doesn't support VID */
558 if (vdd < 0)
559 return vdd;
560
561 if (setup_core_volt(vdd))
562 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
563#ifdef CONFIG_SYS_HAS_SERDES
564 if (setup_serdes_volt(vdd))
565 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
566#endif
567
568#ifdef CONFIG_SYS_FSL_DDR
569 if (vdd == 900)
570 ddr_enable_0v9_volt(true);
571#endif
572
573 return 0;
574}
575
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530576#ifdef CONFIG_FSL_PFE
577void init_pfe_scfg_dcfg_regs(void)
578{
579 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
580 u32 ecccr2;
581
582 out_be32(&scfg->pfeasbcr,
583 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
584 out_be32(&scfg->pfebsbcr,
585 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
586
587 /* CCI-400 QoS settings for PFE */
588 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
589 | SCFG_WR_QOS1_PFE2_QOS));
590 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
591 | SCFG_RD_QOS1_PFE2_QOS));
592
593 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
594 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
595 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
596}
597#endif
598
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800599void fsl_lsch2_early_init_f(void)
600{
Ashish Kumar11234062017-08-11 11:09:14 +0530601 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
602 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530603 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000604#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
605 enum boot_src src;
606#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800607
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800608#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
609 enable_layerscape_ns_access();
610#endif
611
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800612#ifdef CONFIG_FSL_IFC
613 init_early_memctl_regs(); /* tighten IFC timing */
614#endif
615
Pankit Garg41bde722019-05-29 12:12:36 +0000616#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
617 src = get_boot_src();
618 if (src != BOOT_SOURCE_QSPI_NOR)
619 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
620#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800621#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800622 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
623#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000624#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530625 /* Make SEC reads and writes snoopable */
626 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800627 SCFG_SNPCNFGCR_SECWRSNP |
628 SCFG_SNPCNFGCR_SATARDSNP |
629 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530630
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800631 /*
632 * Enable snoop requests and DVM message requests for
633 * Slave insterface S4 (A53 core cluster)
634 */
York Sune6b871e2017-05-15 08:51:59 -0700635 if (current_el() == 3) {
636 out_le32(&cci->slave[4].snoop_ctrl,
637 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
638 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800639
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800640 /*
641 * Program Central Security Unit (CSU) to grant access
642 * permission for USB 2.0 controller
643 */
644#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
645 if (current_el() == 3)
646 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
647#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800648 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800649 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800650 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800651 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800652 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800653 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800654 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800655 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800656 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300657
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300658#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300659 set_icids();
660#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800661}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800662#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700663
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800664#ifdef CONFIG_QSPI_AHB_INIT
665/* Enable 4bytes address support and fast read */
666int qspi_ahb_init(void)
667{
668 u32 *qspi_lut, lut_key, *qspi_key;
669
670 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
671 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
672
673 lut_key = in_be32(qspi_key);
674
675 if (lut_key == 0x5af05af0) {
676 /* That means the register is BE */
677 out_be32(qspi_key, 0x5af05af0);
678 /* Unlock the lut table */
679 out_be32(qspi_key + 1, 0x00000002);
680 out_be32(qspi_lut, 0x0820040c);
681 out_be32(qspi_lut + 1, 0x1c080c08);
682 out_be32(qspi_lut + 2, 0x00002400);
683 /* Lock the lut table */
684 out_be32(qspi_key, 0x5af05af0);
685 out_be32(qspi_key + 1, 0x00000001);
686 } else {
687 /* That means the register is LE */
688 out_le32(qspi_key, 0x5af05af0);
689 /* Unlock the lut table */
690 out_le32(qspi_key + 1, 0x00000002);
691 out_le32(qspi_lut, 0x0820040c);
692 out_le32(qspi_lut + 1, 0x1c080c08);
693 out_le32(qspi_lut + 2, 0x00002400);
694 /* Lock the lut table */
695 out_le32(qspi_key, 0x5af05af0);
696 out_le32(qspi_key + 1, 0x00000001);
697 }
698
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000699 return 0;
700}
701#endif
702
703#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000704#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000705
706int fsl_setenv_bootcmd(void)
707{
708 int ret;
709 enum boot_src src = get_boot_src();
710 char bootcmd_str[MAX_BOOTCMD_SIZE];
711
712 switch (src) {
713#ifdef IFC_NOR_BOOTCOMMAND
714 case BOOT_SOURCE_IFC_NOR:
715 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
716 break;
717#endif
718#ifdef QSPI_NOR_BOOTCOMMAND
719 case BOOT_SOURCE_QSPI_NOR:
720 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
721 break;
722#endif
723#ifdef XSPI_NOR_BOOTCOMMAND
724 case BOOT_SOURCE_XSPI_NOR:
725 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
726 break;
727#endif
728#ifdef IFC_NAND_BOOTCOMMAND
729 case BOOT_SOURCE_IFC_NAND:
730 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
731 break;
732#endif
733#ifdef QSPI_NAND_BOOTCOMMAND
734 case BOOT_SOURCE_QSPI_NAND:
735 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
736 break;
737#endif
738#ifdef XSPI_NAND_BOOTCOMMAND
739 case BOOT_SOURCE_XSPI_NAND:
740 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
741 break;
742#endif
743#ifdef SD_BOOTCOMMAND
744 case BOOT_SOURCE_SD_MMC:
745 sprintf(bootcmd_str, SD_BOOTCOMMAND);
746 break;
747#endif
748#ifdef SD2_BOOTCOMMAND
749 case BOOT_SOURCE_SD_MMC2:
750 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
751 break;
752#endif
753 default:
754#ifdef QSPI_NOR_BOOTCOMMAND
755 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
756#endif
757 break;
758 }
759
760 ret = env_set("bootcmd", bootcmd_str);
761 if (ret) {
762 printf("Failed to set bootcmd: ret = %d\n", ret);
763 return ret;
764 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800765 return 0;
766}
Pankit Garg82fcc462018-11-05 18:02:31 +0000767
768int fsl_setenv_mcinitcmd(void)
769{
770 int ret = 0;
771 enum boot_src src = get_boot_src();
772
773 switch (src) {
774#ifdef IFC_MC_INIT_CMD
775 case BOOT_SOURCE_IFC_NAND:
776 case BOOT_SOURCE_IFC_NOR:
777 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
778 break;
779#endif
780#ifdef QSPI_MC_INIT_CMD
781 case BOOT_SOURCE_QSPI_NAND:
782 case BOOT_SOURCE_QSPI_NOR:
783 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
784 break;
785#endif
786#ifdef XSPI_MC_INIT_CMD
787 case BOOT_SOURCE_XSPI_NAND:
788 case BOOT_SOURCE_XSPI_NOR:
789 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
790 break;
791#endif
792#ifdef SD_MC_INIT_CMD
793 case BOOT_SOURCE_SD_MMC:
794 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
795 break;
796#endif
797#ifdef SD2_MC_INIT_CMD
798 case BOOT_SOURCE_SD_MMC2:
799 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
800 break;
801#endif
802 default:
803#ifdef QSPI_MC_INIT_CMD
804 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
805#endif
806 break;
807 }
808
809 if (ret) {
810 printf("Failed to set mcinitcmd: ret = %d\n", ret);
811 return ret;
812 }
813 return 0;
814}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800815#endif
816
Mingkai Hu0e58b512015-10-26 19:47:50 +0800817#ifdef CONFIG_BOARD_LATE_INIT
818int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700819{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530820#ifdef CONFIG_CHAIN_OF_TRUST
821 fsl_setenv_chain_of_trust();
822#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000823#ifdef CONFIG_TFABOOT
824 /*
825 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000826 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000827 */
Pankit Gargd6bd6782019-05-30 12:04:15 +0000828#if !defined(CONFIG_ENV_ADDR) || defined(ENV_IS_EMBEDDED)
829 if (gd->env_addr == (ulong)&default_environment[0]) {
830#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000831 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000832#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000833 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000834 fsl_setenv_mcinitcmd();
835 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000836
837 /*
838 * If the boot mode is secure, default environment is not present then
839 * setenv command needs to be run by default
840 */
841#ifdef CONFIG_CHAIN_OF_TRUST
842 if ((fsl_check_boot_mode_secure() == 1)) {
843 fsl_setenv_bootcmd();
844 fsl_setenv_mcinitcmd();
845 }
846#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000847#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800848#ifdef CONFIG_QSPI_AHB_INIT
849 qspi_ahb_init();
850#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800851
Mingkai Hu0e58b512015-10-26 19:47:50 +0800852 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700853}
854#endif