blob: 7414215208cba49e8271fbb8d9db5de0b447c319 [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>
Ashish Kumar11234062017-08-11 11:09:14 +05308#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -07009#include <fsl_ifc.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080010#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080011#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070012#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070013#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053014#include <asm/arch-fsl-layerscape/config.h>
Ran Wang4e7cdcf2018-08-10 15:00:00 +080015#include <asm/arch-fsl-layerscape/ns_access.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030016#include <asm/arch-fsl-layerscape/fsl_icid.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>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000028#ifdef CONFIG_TFABOOT
29#include <environment.h>
30DECLARE_GLOBAL_DATA_PTR;
31#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070032
York Suncbe8e1c2016-04-04 11:41:26 -070033bool soc_has_dp_ddr(void)
34{
35 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
36 u32 svr = gur_in32(&gur->svr);
37
Priyanka Jain4a6f1732016-11-17 12:29:55 +053038 /* LS2085A, LS2088A, LS2048A has DP_DDR */
39 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
40 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
41 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070042 return true;
43
44 return false;
45}
46
47bool soc_has_aiop(void)
48{
49 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
50 u32 svr = gur_in32(&gur->svr);
51
52 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053053 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070054 return true;
55
56 return false;
57}
58
Ran Wangb358b7b2017-09-04 18:46:48 +080059static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
60{
61 scfg_clrsetbits32(scfg + offset / 4,
62 0xF << 6,
63 SCFG_USB_TXVREFTUNE << 6);
64}
65
66static void erratum_a009008(void)
67{
68#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
69 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080070
Ran Wang02dc77b2017-11-13 16:14:48 +080071#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
72 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080073 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080074#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080075 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
76 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080077#endif
Ran Wangb358b7b2017-09-04 18:46:48 +080078#elif defined(CONFIG_ARCH_LS2080A)
79 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
80#endif
81#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
82}
83
Ran Wang9e8fabc2017-09-04 18:46:49 +080084static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
85{
86 scfg_clrbits32(scfg + offset / 4,
87 SCFG_USB_SQRXTUNE_MASK << 23);
88}
89
90static void erratum_a009798(void)
91{
92#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
93 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
94
Ran Wang02dc77b2017-11-13 16:14:48 +080095#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
96 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080097 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080098#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080099 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
100 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800101#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800102#elif defined(CONFIG_ARCH_LS2080A)
103 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
104#endif
105#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
106}
107
Ran Wang02dc77b2017-11-13 16:14:48 +0800108#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
109 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800110static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
111{
112 scfg_clrsetbits32(scfg + offset / 4,
113 0x7F << 9,
114 SCFG_USB_PCSTXSWINGFULL << 9);
115}
116#endif
117
118static void erratum_a008997(void)
119{
120#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800121#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
122 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800123 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
124
125 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800126#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800127 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
128 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
129#endif
Ran Wange118acb2019-05-14 17:34:56 +0800130#elif defined(CONFIG_ARCH_LS1028A)
131 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
132 0x7F << 11,
133 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800134#endif
Ran Wange64f7472017-09-04 18:46:50 +0800135#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
136}
137
Ran Wang02dc77b2017-11-13 16:14:48 +0800138#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
139 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800140
141#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
142 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
143 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
144 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
145 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
146
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800147#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
148 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800149
150#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
151 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
152 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
153 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
154 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
155
156#endif
157
158static void erratum_a009007(void)
159{
Ran Wang02dc77b2017-11-13 16:14:48 +0800160#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
161 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800162 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
163
164 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800165#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800166 usb_phy = (void __iomem *)SCFG_USB_PHY2;
167 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
168
169 usb_phy = (void __iomem *)SCFG_USB_PHY3;
170 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800171#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800172#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
173 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800174 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
175
176 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
177 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
178#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
179}
180
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800181#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +0800182/*
183 * This erratum requires setting a value to eddrtqcr1 to
184 * optimal the DDR performance.
185 */
186static void erratum_a008336(void)
187{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800188#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800189 u32 *eddrtqcr1;
190
Yao Yuanfae88052015-12-05 14:59:14 +0800191#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
192 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800193 if (fsl_ddr_get_version(0) == 0x50200)
194 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800195#endif
196#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
197 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800198 if (fsl_ddr_get_version(0) == 0x50200)
199 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800200#endif
201#endif
202}
203
204/*
205 * This erratum requires a register write before being Memory
206 * controller 3 being enabled.
207 */
208static void erratum_a008514(void)
209{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800210#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800211 u32 *eddrtqcr1;
212
Yao Yuanfae88052015-12-05 14:59:14 +0800213#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
214 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
215 out_le32(eddrtqcr1, 0x63b20002);
216#endif
217#endif
218}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530219#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
220#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
221
222static unsigned long get_internval_val_mhz(void)
223{
Simon Glass64b723f2017-08-03 12:22:12 -0600224 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530225 /*
226 * interval is the number of platform cycles(MHz) between
227 * wake up events generated by EPU.
228 */
229 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
230
231 if (interval)
232 interval_mhz = simple_strtoul(interval, NULL, 10);
233
234 return interval_mhz;
235}
236
237void erratum_a009635(void)
238{
239 u32 val;
240 unsigned long interval_mhz = get_internval_val_mhz();
241
242 if (!interval_mhz)
243 return;
244
245 val = in_le32(DCSR_CGACRE5);
246 writel(val | 0x00000200, DCSR_CGACRE5);
247
248 val = in_le32(EPU_EPCMPR5);
249 writel(interval_mhz, EPU_EPCMPR5);
250 val = in_le32(EPU_EPCCR5);
251 writel(val | 0x82820000, EPU_EPCCR5);
252 val = in_le32(EPU_EPSMCR5);
253 writel(val | 0x002f0000, EPU_EPSMCR5);
254 val = in_le32(EPU_EPECR5);
255 writel(val | 0x20000000, EPU_EPECR5);
256 val = in_le32(EPU_EPGCR);
257 writel(val | 0x80000000, EPU_EPGCR);
258}
259#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
260
Scott Wood8e728cd2015-03-24 13:25:02 -0700261static void erratum_rcw_src(void)
262{
Santan Kumar99136482017-05-05 15:42:28 +0530263#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700264 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
265 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
266 u32 val;
267
268 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
269 val &= ~DCFG_PORSR1_RCW_SRC;
270 val |= DCFG_PORSR1_RCW_SRC_NOR;
271 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
272#endif
273}
274
York Sun0404a392015-03-23 10:41:35 -0700275#define I2C_DEBUG_REG 0x6
276#define I2C_GLITCH_EN 0x8
277/*
278 * This erratum requires setting glitch_en bit to enable
279 * digital glitch filter to improve clock stability.
280 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530281#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700282static void erratum_a009203(void)
283{
York Sun0404a392015-03-23 10:41:35 -0700284#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530285 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700286#ifdef I2C1_BASE_ADDR
287 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
288
289 writeb(I2C_GLITCH_EN, ptr);
290#endif
291#ifdef I2C2_BASE_ADDR
292 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
293
294 writeb(I2C_GLITCH_EN, ptr);
295#endif
296#ifdef I2C3_BASE_ADDR
297 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
298
299 writeb(I2C_GLITCH_EN, ptr);
300#endif
301#ifdef I2C4_BASE_ADDR
302 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
303
304 writeb(I2C_GLITCH_EN, ptr);
305#endif
306#endif
307}
Ashish kumar3b52a232017-02-23 16:03:57 +0530308#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800309
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530310void bypass_smmu(void)
311{
312 u32 val;
313 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
314 out_le32(SMMU_SCR0, val);
315 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
316 out_le32(SMMU_NSCR0, val);
317}
Scott Woodf64c98c2015-03-20 19:28:12 -0700318void fsl_lsch3_early_init_f(void)
319{
Scott Wood8e728cd2015-03-24 13:25:02 -0700320 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530321#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700322 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530323#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530324#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700325 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530326#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800327 erratum_a008514();
328 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800329 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800330 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800331 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800332 erratum_a009007();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530333#ifdef CONFIG_CHAIN_OF_TRUST
334 /* In case of Secure Boot, the IBR configures the SMMU
335 * to allow only Secure transactions.
336 * SMMU must be reset in bypass mode.
337 * Set the ClientPD bit and Clear the USFCFG Bit
338 */
339 if (fsl_check_boot_mode_secure() == 1)
340 bypass_smmu();
341#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700342}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800343
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530344/* Get VDD in the unit mV from voltage ID */
345int get_core_volt_from_fuse(void)
346{
347 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
348 int vdd;
349 u32 fusesr;
350 u8 vid;
351
352 /* get the voltage ID from fuse status register */
353 fusesr = in_le32(&gur->dcfg_fusesr);
354 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
355 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
356 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
357 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
358 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
359 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
360 }
361 debug("%s: VID = 0x%x\n", __func__, vid);
362 switch (vid) {
363 case 0x00: /* VID isn't supported */
364 vdd = -EINVAL;
365 debug("%s: The VID feature is not supported\n", __func__);
366 break;
367 case 0x08: /* 0.9V silicon */
368 vdd = 900;
369 break;
370 case 0x10: /* 1.0V silicon */
371 vdd = 1000;
372 break;
373 default: /* Other core voltage */
374 vdd = -EINVAL;
375 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
376 break;
377 }
378 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
379
380 return vdd;
381}
382
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530383#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800384
Mingkai Hu8beb0752015-12-07 16:58:54 +0800385static void erratum_a009929(void)
386{
387#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
388 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
389 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
390 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
391
392 rstrqmr1 |= 0x00000400;
393 gur_out32(&gur->rstrqmr1, rstrqmr1);
394 writel(0x01000000, dcsr_cop_ccp);
395#endif
396}
397
Mingkai Hu172081c2016-02-02 11:28:03 +0800398/*
399 * This erratum requires setting a value to eddrtqcr1 to optimal
400 * the DDR performance. The eddrtqcr1 register is in SCFG space
401 * of LS1043A and the offset is 0x157_020c.
402 */
403#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
404 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
405#error A009660 and A008514 can not be both enabled.
406#endif
407
408static void erratum_a009660(void)
409{
410#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
411 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
412 out_be32(eddrtqcr1, 0x63b20042);
413#endif
414}
415
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800416static void erratum_a008850_early(void)
417{
418#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
419 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530420 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
421 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800422 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
423
York Sune6b871e2017-05-15 08:51:59 -0700424 /* Skip if running at lower exception level */
425 if (current_el() < 3)
426 return;
427
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800428 /* disables propagation of barrier transactions to DDRC from CCI400 */
429 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
430
431 /* disable the re-ordering in DDRC */
432 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
433#endif
434}
435
436void erratum_a008850_post(void)
437{
438#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
439 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530440 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
441 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800442 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
443 u32 tmp;
444
York Sune6b871e2017-05-15 08:51:59 -0700445 /* Skip if running at lower exception level */
446 if (current_el() < 3)
447 return;
448
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800449 /* enable propagation of barrier transactions to DDRC from CCI400 */
450 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
451
452 /* enable the re-ordering in DDRC */
453 tmp = ddr_in32(&ddr->eor);
454 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
455 ddr_out32(&ddr->eor, tmp);
456#endif
457}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800458
459#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
460void erratum_a010315(void)
461{
462 int i;
463
464 for (i = PCIE1; i <= PCIE4; i++)
465 if (!is_serdes_configured(i)) {
466 debug("PCIe%d: disabled all R/W permission!\n", i);
467 set_pcie_ns_access(i, 0);
468 }
469}
470#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800471
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800472static void erratum_a010539(void)
473{
474#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
475 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
476 u32 porsr1;
477
478 porsr1 = in_be32(&gur->porsr1);
479 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
480 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
481 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800482 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800483#endif
484}
485
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800486/* Get VDD in the unit mV from voltage ID */
487int get_core_volt_from_fuse(void)
488{
489 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
490 int vdd;
491 u32 fusesr;
492 u8 vid;
493
494 fusesr = in_be32(&gur->dcfg_fusesr);
495 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
496 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
497 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
498 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
499 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
500 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
501 }
502 debug("%s: VID = 0x%x\n", __func__, vid);
503 switch (vid) {
504 case 0x00: /* VID isn't supported */
505 vdd = -EINVAL;
506 debug("%s: The VID feature is not supported\n", __func__);
507 break;
508 case 0x08: /* 0.9V silicon */
509 vdd = 900;
510 break;
511 case 0x10: /* 1.0V silicon */
512 vdd = 1000;
513 break;
514 default: /* Other core voltage */
515 vdd = -EINVAL;
516 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
517 break;
518 }
519 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
520
521 return vdd;
522}
523
524__weak int board_switch_core_volt(u32 vdd)
525{
526 return 0;
527}
528
529static int setup_core_volt(u32 vdd)
530{
531 return board_setup_core_volt(vdd);
532}
533
534#ifdef CONFIG_SYS_FSL_DDR
535static void ddr_enable_0v9_volt(bool en)
536{
537 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
538 u32 tmp;
539
540 tmp = ddr_in32(&ddr->ddr_cdr1);
541
542 if (en)
543 tmp |= DDR_CDR1_V0PT9_EN;
544 else
545 tmp &= ~DDR_CDR1_V0PT9_EN;
546
547 ddr_out32(&ddr->ddr_cdr1, tmp);
548}
549#endif
550
551int setup_chip_volt(void)
552{
553 int vdd;
554
555 vdd = get_core_volt_from_fuse();
556 /* Nothing to do for silicons doesn't support VID */
557 if (vdd < 0)
558 return vdd;
559
560 if (setup_core_volt(vdd))
561 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
562#ifdef CONFIG_SYS_HAS_SERDES
563 if (setup_serdes_volt(vdd))
564 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
565#endif
566
567#ifdef CONFIG_SYS_FSL_DDR
568 if (vdd == 900)
569 ddr_enable_0v9_volt(true);
570#endif
571
572 return 0;
573}
574
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530575#ifdef CONFIG_FSL_PFE
576void init_pfe_scfg_dcfg_regs(void)
577{
578 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
579 u32 ecccr2;
580
581 out_be32(&scfg->pfeasbcr,
582 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
583 out_be32(&scfg->pfebsbcr,
584 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
585
586 /* CCI-400 QoS settings for PFE */
587 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
588 | SCFG_WR_QOS1_PFE2_QOS));
589 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
590 | SCFG_RD_QOS1_PFE2_QOS));
591
592 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
593 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
594 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
595}
596#endif
597
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800598void fsl_lsch2_early_init_f(void)
599{
Ashish Kumar11234062017-08-11 11:09:14 +0530600 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
601 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530602 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000603#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
604 enum boot_src src;
605#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800606
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800607#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
608 enable_layerscape_ns_access();
609#endif
610
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800611#ifdef CONFIG_FSL_IFC
612 init_early_memctl_regs(); /* tighten IFC timing */
613#endif
614
Pankit Garg41bde722019-05-29 12:12:36 +0000615#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
616 src = get_boot_src();
617 if (src != BOOT_SOURCE_QSPI_NOR)
618 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
619#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800620#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800621 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
622#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000623#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530624 /* Make SEC reads and writes snoopable */
625 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800626 SCFG_SNPCNFGCR_SECWRSNP |
627 SCFG_SNPCNFGCR_SATARDSNP |
628 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530629
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800630 /*
631 * Enable snoop requests and DVM message requests for
632 * Slave insterface S4 (A53 core cluster)
633 */
York Sune6b871e2017-05-15 08:51:59 -0700634 if (current_el() == 3) {
635 out_le32(&cci->slave[4].snoop_ctrl,
636 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
637 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800638
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800639 /*
640 * Program Central Security Unit (CSU) to grant access
641 * permission for USB 2.0 controller
642 */
643#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
644 if (current_el() == 3)
645 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
646#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800647 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800648 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800649 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800650 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800651 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800652 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800653 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800654 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800655 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300656
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300657#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300658 set_icids();
659#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800660}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800661#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700662
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800663#ifdef CONFIG_QSPI_AHB_INIT
664/* Enable 4bytes address support and fast read */
665int qspi_ahb_init(void)
666{
667 u32 *qspi_lut, lut_key, *qspi_key;
668
669 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
670 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
671
672 lut_key = in_be32(qspi_key);
673
674 if (lut_key == 0x5af05af0) {
675 /* That means the register is BE */
676 out_be32(qspi_key, 0x5af05af0);
677 /* Unlock the lut table */
678 out_be32(qspi_key + 1, 0x00000002);
679 out_be32(qspi_lut, 0x0820040c);
680 out_be32(qspi_lut + 1, 0x1c080c08);
681 out_be32(qspi_lut + 2, 0x00002400);
682 /* Lock the lut table */
683 out_be32(qspi_key, 0x5af05af0);
684 out_be32(qspi_key + 1, 0x00000001);
685 } else {
686 /* That means the register is LE */
687 out_le32(qspi_key, 0x5af05af0);
688 /* Unlock the lut table */
689 out_le32(qspi_key + 1, 0x00000002);
690 out_le32(qspi_lut, 0x0820040c);
691 out_le32(qspi_lut + 1, 0x1c080c08);
692 out_le32(qspi_lut + 2, 0x00002400);
693 /* Lock the lut table */
694 out_le32(qspi_key, 0x5af05af0);
695 out_le32(qspi_key + 1, 0x00000001);
696 }
697
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000698 return 0;
699}
700#endif
701
702#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000703#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000704
705int fsl_setenv_bootcmd(void)
706{
707 int ret;
708 enum boot_src src = get_boot_src();
709 char bootcmd_str[MAX_BOOTCMD_SIZE];
710
711 switch (src) {
712#ifdef IFC_NOR_BOOTCOMMAND
713 case BOOT_SOURCE_IFC_NOR:
714 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
715 break;
716#endif
717#ifdef QSPI_NOR_BOOTCOMMAND
718 case BOOT_SOURCE_QSPI_NOR:
719 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
720 break;
721#endif
722#ifdef XSPI_NOR_BOOTCOMMAND
723 case BOOT_SOURCE_XSPI_NOR:
724 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
725 break;
726#endif
727#ifdef IFC_NAND_BOOTCOMMAND
728 case BOOT_SOURCE_IFC_NAND:
729 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
730 break;
731#endif
732#ifdef QSPI_NAND_BOOTCOMMAND
733 case BOOT_SOURCE_QSPI_NAND:
734 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
735 break;
736#endif
737#ifdef XSPI_NAND_BOOTCOMMAND
738 case BOOT_SOURCE_XSPI_NAND:
739 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
740 break;
741#endif
742#ifdef SD_BOOTCOMMAND
743 case BOOT_SOURCE_SD_MMC:
744 sprintf(bootcmd_str, SD_BOOTCOMMAND);
745 break;
746#endif
747#ifdef SD2_BOOTCOMMAND
748 case BOOT_SOURCE_SD_MMC2:
749 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
750 break;
751#endif
752 default:
753#ifdef QSPI_NOR_BOOTCOMMAND
754 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
755#endif
756 break;
757 }
758
759 ret = env_set("bootcmd", bootcmd_str);
760 if (ret) {
761 printf("Failed to set bootcmd: ret = %d\n", ret);
762 return ret;
763 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800764 return 0;
765}
Pankit Garg82fcc462018-11-05 18:02:31 +0000766
767int fsl_setenv_mcinitcmd(void)
768{
769 int ret = 0;
770 enum boot_src src = get_boot_src();
771
772 switch (src) {
773#ifdef IFC_MC_INIT_CMD
774 case BOOT_SOURCE_IFC_NAND:
775 case BOOT_SOURCE_IFC_NOR:
776 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
777 break;
778#endif
779#ifdef QSPI_MC_INIT_CMD
780 case BOOT_SOURCE_QSPI_NAND:
781 case BOOT_SOURCE_QSPI_NOR:
782 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
783 break;
784#endif
785#ifdef XSPI_MC_INIT_CMD
786 case BOOT_SOURCE_XSPI_NAND:
787 case BOOT_SOURCE_XSPI_NOR:
788 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
789 break;
790#endif
791#ifdef SD_MC_INIT_CMD
792 case BOOT_SOURCE_SD_MMC:
793 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
794 break;
795#endif
796#ifdef SD2_MC_INIT_CMD
797 case BOOT_SOURCE_SD_MMC2:
798 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
799 break;
800#endif
801 default:
802#ifdef QSPI_MC_INIT_CMD
803 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
804#endif
805 break;
806 }
807
808 if (ret) {
809 printf("Failed to set mcinitcmd: ret = %d\n", ret);
810 return ret;
811 }
812 return 0;
813}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800814#endif
815
Mingkai Hu0e58b512015-10-26 19:47:50 +0800816#ifdef CONFIG_BOARD_LATE_INIT
817int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700818{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530819#ifdef CONFIG_CHAIN_OF_TRUST
820 fsl_setenv_chain_of_trust();
821#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000822#ifdef CONFIG_TFABOOT
823 /*
824 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000825 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000826 */
Pankit Gargd6bd6782019-05-30 12:04:15 +0000827#if !defined(CONFIG_ENV_ADDR) || defined(ENV_IS_EMBEDDED)
828 if (gd->env_addr == (ulong)&default_environment[0]) {
829#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000830 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000831#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000832 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000833 fsl_setenv_mcinitcmd();
834 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000835
836 /*
837 * If the boot mode is secure, default environment is not present then
838 * setenv command needs to be run by default
839 */
840#ifdef CONFIG_CHAIN_OF_TRUST
841 if ((fsl_check_boot_mode_secure() == 1)) {
842 fsl_setenv_bootcmd();
843 fsl_setenv_mcinitcmd();
844 }
845#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000846#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800847#ifdef CONFIG_QSPI_AHB_INIT
848 qspi_ahb_init();
849#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800850
Mingkai Hu0e58b512015-10-26 19:47:50 +0800851 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700852}
853#endif