blob: f0df88c565ab0abd1d16d8787d2cc095a2f22a30 [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
Simon Glass9d1f6192019-08-02 09:44:25 -060030#include <env_internal.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000031DECLARE_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
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300343
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000344#if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000345 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300346 set_icids();
347#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700348}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800349
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530350/* Get VDD in the unit mV from voltage ID */
351int get_core_volt_from_fuse(void)
352{
353 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
354 int vdd;
355 u32 fusesr;
356 u8 vid;
357
358 /* get the voltage ID from fuse status register */
359 fusesr = in_le32(&gur->dcfg_fusesr);
360 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
361 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
362 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
363 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
364 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
365 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
366 }
367 debug("%s: VID = 0x%x\n", __func__, vid);
368 switch (vid) {
369 case 0x00: /* VID isn't supported */
370 vdd = -EINVAL;
371 debug("%s: The VID feature is not supported\n", __func__);
372 break;
373 case 0x08: /* 0.9V silicon */
374 vdd = 900;
375 break;
376 case 0x10: /* 1.0V silicon */
377 vdd = 1000;
378 break;
379 default: /* Other core voltage */
380 vdd = -EINVAL;
381 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
382 break;
383 }
384 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
385
386 return vdd;
387}
388
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530389#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800390
Mingkai Hu8beb0752015-12-07 16:58:54 +0800391static void erratum_a009929(void)
392{
393#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
394 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
395 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
396 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
397
398 rstrqmr1 |= 0x00000400;
399 gur_out32(&gur->rstrqmr1, rstrqmr1);
400 writel(0x01000000, dcsr_cop_ccp);
401#endif
402}
403
Mingkai Hu172081c2016-02-02 11:28:03 +0800404/*
405 * This erratum requires setting a value to eddrtqcr1 to optimal
406 * the DDR performance. The eddrtqcr1 register is in SCFG space
407 * of LS1043A and the offset is 0x157_020c.
408 */
409#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
410 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
411#error A009660 and A008514 can not be both enabled.
412#endif
413
414static void erratum_a009660(void)
415{
416#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
417 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
418 out_be32(eddrtqcr1, 0x63b20042);
419#endif
420}
421
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800422static void erratum_a008850_early(void)
423{
424#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
425 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530426 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
427 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800428 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
429
York Sune6b871e2017-05-15 08:51:59 -0700430 /* Skip if running at lower exception level */
431 if (current_el() < 3)
432 return;
433
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800434 /* disables propagation of barrier transactions to DDRC from CCI400 */
435 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
436
437 /* disable the re-ordering in DDRC */
438 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
439#endif
440}
441
442void erratum_a008850_post(void)
443{
444#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
445 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530446 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
447 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800448 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
449 u32 tmp;
450
York Sune6b871e2017-05-15 08:51:59 -0700451 /* Skip if running at lower exception level */
452 if (current_el() < 3)
453 return;
454
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800455 /* enable propagation of barrier transactions to DDRC from CCI400 */
456 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
457
458 /* enable the re-ordering in DDRC */
459 tmp = ddr_in32(&ddr->eor);
460 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
461 ddr_out32(&ddr->eor, tmp);
462#endif
463}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800464
465#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
466void erratum_a010315(void)
467{
468 int i;
469
470 for (i = PCIE1; i <= PCIE4; i++)
471 if (!is_serdes_configured(i)) {
472 debug("PCIe%d: disabled all R/W permission!\n", i);
473 set_pcie_ns_access(i, 0);
474 }
475}
476#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800477
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800478static void erratum_a010539(void)
479{
480#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
481 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
482 u32 porsr1;
483
484 porsr1 = in_be32(&gur->porsr1);
485 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
486 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
487 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800488 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800489#endif
490}
491
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800492/* Get VDD in the unit mV from voltage ID */
493int get_core_volt_from_fuse(void)
494{
495 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
496 int vdd;
497 u32 fusesr;
498 u8 vid;
499
500 fusesr = in_be32(&gur->dcfg_fusesr);
501 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
502 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
503 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
504 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
505 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
506 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
507 }
508 debug("%s: VID = 0x%x\n", __func__, vid);
509 switch (vid) {
510 case 0x00: /* VID isn't supported */
511 vdd = -EINVAL;
512 debug("%s: The VID feature is not supported\n", __func__);
513 break;
514 case 0x08: /* 0.9V silicon */
515 vdd = 900;
516 break;
517 case 0x10: /* 1.0V silicon */
518 vdd = 1000;
519 break;
520 default: /* Other core voltage */
521 vdd = -EINVAL;
522 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
523 break;
524 }
525 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
526
527 return vdd;
528}
529
530__weak int board_switch_core_volt(u32 vdd)
531{
532 return 0;
533}
534
535static int setup_core_volt(u32 vdd)
536{
537 return board_setup_core_volt(vdd);
538}
539
540#ifdef CONFIG_SYS_FSL_DDR
541static void ddr_enable_0v9_volt(bool en)
542{
543 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
544 u32 tmp;
545
546 tmp = ddr_in32(&ddr->ddr_cdr1);
547
548 if (en)
549 tmp |= DDR_CDR1_V0PT9_EN;
550 else
551 tmp &= ~DDR_CDR1_V0PT9_EN;
552
553 ddr_out32(&ddr->ddr_cdr1, tmp);
554}
555#endif
556
557int setup_chip_volt(void)
558{
559 int vdd;
560
561 vdd = get_core_volt_from_fuse();
562 /* Nothing to do for silicons doesn't support VID */
563 if (vdd < 0)
564 return vdd;
565
566 if (setup_core_volt(vdd))
567 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
568#ifdef CONFIG_SYS_HAS_SERDES
569 if (setup_serdes_volt(vdd))
570 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
571#endif
572
573#ifdef CONFIG_SYS_FSL_DDR
574 if (vdd == 900)
575 ddr_enable_0v9_volt(true);
576#endif
577
578 return 0;
579}
580
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530581#ifdef CONFIG_FSL_PFE
582void init_pfe_scfg_dcfg_regs(void)
583{
584 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
585 u32 ecccr2;
586
587 out_be32(&scfg->pfeasbcr,
588 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
589 out_be32(&scfg->pfebsbcr,
590 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
591
592 /* CCI-400 QoS settings for PFE */
593 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
594 | SCFG_WR_QOS1_PFE2_QOS));
595 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
596 | SCFG_RD_QOS1_PFE2_QOS));
597
598 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
599 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
600 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
601}
602#endif
603
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800604void fsl_lsch2_early_init_f(void)
605{
Ashish Kumar11234062017-08-11 11:09:14 +0530606 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
607 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530608 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000609#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
610 enum boot_src src;
611#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800612
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800613#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
614 enable_layerscape_ns_access();
615#endif
616
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800617#ifdef CONFIG_FSL_IFC
618 init_early_memctl_regs(); /* tighten IFC timing */
619#endif
620
Pankit Garg41bde722019-05-29 12:12:36 +0000621#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
622 src = get_boot_src();
623 if (src != BOOT_SOURCE_QSPI_NOR)
624 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
625#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800626#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800627 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
628#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000629#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530630 /* Make SEC reads and writes snoopable */
Ran Wangc75026e2019-09-20 17:34:29 +0800631#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
632 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
633 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
634 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
635 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
636 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
637 SCFG_SNPCNFGCR_SATAWRSNP);
638#else
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530639 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800640 SCFG_SNPCNFGCR_SECWRSNP |
641 SCFG_SNPCNFGCR_SATARDSNP |
642 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800643#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530644
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800645 /*
646 * Enable snoop requests and DVM message requests for
647 * Slave insterface S4 (A53 core cluster)
648 */
York Sune6b871e2017-05-15 08:51:59 -0700649 if (current_el() == 3) {
650 out_le32(&cci->slave[4].snoop_ctrl,
651 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
652 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800653
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800654 /*
655 * Program Central Security Unit (CSU) to grant access
656 * permission for USB 2.0 controller
657 */
658#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
659 if (current_el() == 3)
660 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
661#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800662 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800663 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800664 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800665 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800666 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800667 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800668 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800669 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800670 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300671
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300672#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300673 set_icids();
674#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800675}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800676#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700677
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800678#ifdef CONFIG_QSPI_AHB_INIT
679/* Enable 4bytes address support and fast read */
680int qspi_ahb_init(void)
681{
682 u32 *qspi_lut, lut_key, *qspi_key;
683
684 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
685 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
686
687 lut_key = in_be32(qspi_key);
688
689 if (lut_key == 0x5af05af0) {
690 /* That means the register is BE */
691 out_be32(qspi_key, 0x5af05af0);
692 /* Unlock the lut table */
693 out_be32(qspi_key + 1, 0x00000002);
694 out_be32(qspi_lut, 0x0820040c);
695 out_be32(qspi_lut + 1, 0x1c080c08);
696 out_be32(qspi_lut + 2, 0x00002400);
697 /* Lock the lut table */
698 out_be32(qspi_key, 0x5af05af0);
699 out_be32(qspi_key + 1, 0x00000001);
700 } else {
701 /* That means the register is LE */
702 out_le32(qspi_key, 0x5af05af0);
703 /* Unlock the lut table */
704 out_le32(qspi_key + 1, 0x00000002);
705 out_le32(qspi_lut, 0x0820040c);
706 out_le32(qspi_lut + 1, 0x1c080c08);
707 out_le32(qspi_lut + 2, 0x00002400);
708 /* Lock the lut table */
709 out_le32(qspi_key, 0x5af05af0);
710 out_le32(qspi_key + 1, 0x00000001);
711 }
712
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000713 return 0;
714}
715#endif
716
717#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000718#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000719
720int fsl_setenv_bootcmd(void)
721{
722 int ret;
723 enum boot_src src = get_boot_src();
724 char bootcmd_str[MAX_BOOTCMD_SIZE];
725
726 switch (src) {
727#ifdef IFC_NOR_BOOTCOMMAND
728 case BOOT_SOURCE_IFC_NOR:
729 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
730 break;
731#endif
732#ifdef QSPI_NOR_BOOTCOMMAND
733 case BOOT_SOURCE_QSPI_NOR:
734 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
735 break;
736#endif
737#ifdef XSPI_NOR_BOOTCOMMAND
738 case BOOT_SOURCE_XSPI_NOR:
739 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
740 break;
741#endif
742#ifdef IFC_NAND_BOOTCOMMAND
743 case BOOT_SOURCE_IFC_NAND:
744 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
745 break;
746#endif
747#ifdef QSPI_NAND_BOOTCOMMAND
748 case BOOT_SOURCE_QSPI_NAND:
749 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
750 break;
751#endif
752#ifdef XSPI_NAND_BOOTCOMMAND
753 case BOOT_SOURCE_XSPI_NAND:
754 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
755 break;
756#endif
757#ifdef SD_BOOTCOMMAND
758 case BOOT_SOURCE_SD_MMC:
759 sprintf(bootcmd_str, SD_BOOTCOMMAND);
760 break;
761#endif
762#ifdef SD2_BOOTCOMMAND
763 case BOOT_SOURCE_SD_MMC2:
764 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
765 break;
766#endif
767 default:
768#ifdef QSPI_NOR_BOOTCOMMAND
769 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
770#endif
771 break;
772 }
773
774 ret = env_set("bootcmd", bootcmd_str);
775 if (ret) {
776 printf("Failed to set bootcmd: ret = %d\n", ret);
777 return ret;
778 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800779 return 0;
780}
Pankit Garg82fcc462018-11-05 18:02:31 +0000781
782int fsl_setenv_mcinitcmd(void)
783{
784 int ret = 0;
785 enum boot_src src = get_boot_src();
786
787 switch (src) {
788#ifdef IFC_MC_INIT_CMD
789 case BOOT_SOURCE_IFC_NAND:
790 case BOOT_SOURCE_IFC_NOR:
791 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
792 break;
793#endif
794#ifdef QSPI_MC_INIT_CMD
795 case BOOT_SOURCE_QSPI_NAND:
796 case BOOT_SOURCE_QSPI_NOR:
797 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
798 break;
799#endif
800#ifdef XSPI_MC_INIT_CMD
801 case BOOT_SOURCE_XSPI_NAND:
802 case BOOT_SOURCE_XSPI_NOR:
803 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
804 break;
805#endif
806#ifdef SD_MC_INIT_CMD
807 case BOOT_SOURCE_SD_MMC:
808 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
809 break;
810#endif
811#ifdef SD2_MC_INIT_CMD
812 case BOOT_SOURCE_SD_MMC2:
813 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
814 break;
815#endif
816 default:
817#ifdef QSPI_MC_INIT_CMD
818 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
819#endif
820 break;
821 }
822
823 if (ret) {
824 printf("Failed to set mcinitcmd: ret = %d\n", ret);
825 return ret;
826 }
827 return 0;
828}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800829#endif
830
Mingkai Hu0e58b512015-10-26 19:47:50 +0800831#ifdef CONFIG_BOARD_LATE_INIT
Michael Wallefc667ea2019-10-21 22:37:45 +0200832__weak int fsl_board_late_init(void)
833{
834 return 0;
835}
836
Mingkai Hu0e58b512015-10-26 19:47:50 +0800837int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700838{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530839#ifdef CONFIG_CHAIN_OF_TRUST
840 fsl_setenv_chain_of_trust();
841#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000842#ifdef CONFIG_TFABOOT
843 /*
844 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000845 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000846 */
Pankit Gargd6bd6782019-05-30 12:04:15 +0000847#if !defined(CONFIG_ENV_ADDR) || defined(ENV_IS_EMBEDDED)
848 if (gd->env_addr == (ulong)&default_environment[0]) {
849#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000850 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000851#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000852 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000853 fsl_setenv_mcinitcmd();
854 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000855
856 /*
857 * If the boot mode is secure, default environment is not present then
858 * setenv command needs to be run by default
859 */
860#ifdef CONFIG_CHAIN_OF_TRUST
861 if ((fsl_check_boot_mode_secure() == 1)) {
862 fsl_setenv_bootcmd();
863 fsl_setenv_mcinitcmd();
864 }
865#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000866#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800867#ifdef CONFIG_QSPI_AHB_INIT
868 qspi_ahb_init();
869#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800870
Michael Wallefc667ea2019-10-21 22:37:45 +0200871 return fsl_board_late_init();
Scott Wood8e728cd2015-03-24 13:25:02 -0700872}
873#endif