blob: 578f8d12de65d58cf6906a32fb13feaf2b505a66 [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>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080012#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080013#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070014#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070015#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053016#include <asm/arch-fsl-layerscape/config.h>
Ran Wang4e7cdcf2018-08-10 15:00:00 +080017#include <asm/arch-fsl-layerscape/ns_access.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030018#include <asm/arch-fsl-layerscape/fsl_icid.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080019#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080020#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080021#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053022#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080023#include <fsl_ddr_sdram.h>
24#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053025#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053026#ifdef CONFIG_CHAIN_OF_TRUST
27#include <fsl_validate.h>
28#endif
Ashish Kumarb25faa22017-08-31 16:12:53 +053029#include <fsl_immap.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000030#ifdef CONFIG_TFABOOT
Simon Glass9d1f6192019-08-02 09:44:25 -060031#include <env_internal.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000032DECLARE_GLOBAL_DATA_PTR;
33#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070034
York Suncbe8e1c2016-04-04 11:41:26 -070035bool soc_has_dp_ddr(void)
36{
37 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
38 u32 svr = gur_in32(&gur->svr);
39
Priyanka Jain4a6f1732016-11-17 12:29:55 +053040 /* LS2085A, LS2088A, LS2048A has DP_DDR */
41 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
42 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
43 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070044 return true;
45
46 return false;
47}
48
49bool soc_has_aiop(void)
50{
51 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
52 u32 svr = gur_in32(&gur->svr);
53
54 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053055 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070056 return true;
57
58 return false;
59}
60
Ran Wangb358b7b2017-09-04 18:46:48 +080061static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
62{
63 scfg_clrsetbits32(scfg + offset / 4,
64 0xF << 6,
65 SCFG_USB_TXVREFTUNE << 6);
66}
67
68static void erratum_a009008(void)
69{
70#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
71 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080072
Ran Wang02dc77b2017-11-13 16:14:48 +080073#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
74 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080075 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080076#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080077 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
78 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080079#endif
Ran Wangb358b7b2017-09-04 18:46:48 +080080#elif defined(CONFIG_ARCH_LS2080A)
81 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
82#endif
83#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
84}
85
Ran Wang9e8fabc2017-09-04 18:46:49 +080086static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
87{
88 scfg_clrbits32(scfg + offset / 4,
89 SCFG_USB_SQRXTUNE_MASK << 23);
90}
91
92static void erratum_a009798(void)
93{
94#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
95 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
96
Ran Wang02dc77b2017-11-13 16:14:48 +080097#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
98 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080099 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800100#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800101 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
102 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800103#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800104#elif defined(CONFIG_ARCH_LS2080A)
105 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
106#endif
107#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
108}
109
Ran Wang02dc77b2017-11-13 16:14:48 +0800110#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
111 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800112static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
113{
114 scfg_clrsetbits32(scfg + offset / 4,
115 0x7F << 9,
116 SCFG_USB_PCSTXSWINGFULL << 9);
117}
118#endif
119
120static void erratum_a008997(void)
121{
122#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800123#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
124 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800125 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
126
127 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800128#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800129 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
130 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
131#endif
Ran Wange118acb2019-05-14 17:34:56 +0800132#elif defined(CONFIG_ARCH_LS1028A)
133 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
134 0x7F << 11,
135 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800136#endif
Ran Wange64f7472017-09-04 18:46:50 +0800137#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
138}
139
Ran Wang02dc77b2017-11-13 16:14:48 +0800140#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
141 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800142
143#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
144 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
145 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
146 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
147 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
148
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800149#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
Ran Wangd0270dc2019-11-26 11:40:40 +0800150 defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A)
Ran Wang3ba69482017-09-04 18:46:51 +0800151
152#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
153 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
154 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
155 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
156 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
157
158#endif
159
160static void erratum_a009007(void)
161{
Ran Wang02dc77b2017-11-13 16:14:48 +0800162#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
163 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800164 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
165
166 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800167#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800168 usb_phy = (void __iomem *)SCFG_USB_PHY2;
169 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
170
171 usb_phy = (void __iomem *)SCFG_USB_PHY3;
172 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800173#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800174#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
175 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800176 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
177
178 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
179 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
180#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
181}
182
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800183#if defined(CONFIG_FSL_LSCH3)
Ran Wangd0270dc2019-11-26 11:40:40 +0800184static void erratum_a050106(void)
185{
186#if defined(CONFIG_ARCH_LX2160A)
187 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
188
189 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
190 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
191#endif
192}
Yao Yuanfae88052015-12-05 14:59:14 +0800193/*
194 * This erratum requires setting a value to eddrtqcr1 to
195 * optimal the DDR performance.
196 */
197static void erratum_a008336(void)
198{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800199#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800200 u32 *eddrtqcr1;
201
Yao Yuanfae88052015-12-05 14:59:14 +0800202#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
203 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800204 if (fsl_ddr_get_version(0) == 0x50200)
205 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800206#endif
207#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
208 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800209 if (fsl_ddr_get_version(0) == 0x50200)
210 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800211#endif
212#endif
213}
214
215/*
216 * This erratum requires a register write before being Memory
217 * controller 3 being enabled.
218 */
219static void erratum_a008514(void)
220{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800221#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800222 u32 *eddrtqcr1;
223
Yao Yuanfae88052015-12-05 14:59:14 +0800224#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
225 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
226 out_le32(eddrtqcr1, 0x63b20002);
227#endif
228#endif
229}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530230#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
231#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
232
233static unsigned long get_internval_val_mhz(void)
234{
Simon Glass64b723f2017-08-03 12:22:12 -0600235 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530236 /*
237 * interval is the number of platform cycles(MHz) between
238 * wake up events generated by EPU.
239 */
240 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
241
242 if (interval)
243 interval_mhz = simple_strtoul(interval, NULL, 10);
244
245 return interval_mhz;
246}
247
248void erratum_a009635(void)
249{
250 u32 val;
251 unsigned long interval_mhz = get_internval_val_mhz();
252
253 if (!interval_mhz)
254 return;
255
256 val = in_le32(DCSR_CGACRE5);
257 writel(val | 0x00000200, DCSR_CGACRE5);
258
259 val = in_le32(EPU_EPCMPR5);
260 writel(interval_mhz, EPU_EPCMPR5);
261 val = in_le32(EPU_EPCCR5);
262 writel(val | 0x82820000, EPU_EPCCR5);
263 val = in_le32(EPU_EPSMCR5);
264 writel(val | 0x002f0000, EPU_EPSMCR5);
265 val = in_le32(EPU_EPECR5);
266 writel(val | 0x20000000, EPU_EPECR5);
267 val = in_le32(EPU_EPGCR);
268 writel(val | 0x80000000, EPU_EPGCR);
269}
270#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
271
Scott Wood8e728cd2015-03-24 13:25:02 -0700272static void erratum_rcw_src(void)
273{
Santan Kumar99136482017-05-05 15:42:28 +0530274#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700275 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
276 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
277 u32 val;
278
279 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
280 val &= ~DCFG_PORSR1_RCW_SRC;
281 val |= DCFG_PORSR1_RCW_SRC_NOR;
282 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
283#endif
284}
285
York Sun0404a392015-03-23 10:41:35 -0700286#define I2C_DEBUG_REG 0x6
287#define I2C_GLITCH_EN 0x8
288/*
289 * This erratum requires setting glitch_en bit to enable
290 * digital glitch filter to improve clock stability.
291 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530292#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700293static void erratum_a009203(void)
294{
York Sun0404a392015-03-23 10:41:35 -0700295#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530296 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700297#ifdef I2C1_BASE_ADDR
298 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
299
300 writeb(I2C_GLITCH_EN, ptr);
301#endif
302#ifdef I2C2_BASE_ADDR
303 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
304
305 writeb(I2C_GLITCH_EN, ptr);
306#endif
307#ifdef I2C3_BASE_ADDR
308 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
309
310 writeb(I2C_GLITCH_EN, ptr);
311#endif
312#ifdef I2C4_BASE_ADDR
313 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
314
315 writeb(I2C_GLITCH_EN, ptr);
316#endif
317#endif
318}
Ashish kumar3b52a232017-02-23 16:03:57 +0530319#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800320
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530321void bypass_smmu(void)
322{
323 u32 val;
324 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
325 out_le32(SMMU_SCR0, val);
326 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
327 out_le32(SMMU_NSCR0, val);
328}
Scott Woodf64c98c2015-03-20 19:28:12 -0700329void fsl_lsch3_early_init_f(void)
330{
Scott Wood8e728cd2015-03-24 13:25:02 -0700331 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530332#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700333 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530334#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530335#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700336 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530337#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800338 erratum_a008514();
339 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800340 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800341 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800342 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800343 erratum_a009007();
Ran Wangd0270dc2019-11-26 11:40:40 +0800344 erratum_a050106();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530345#ifdef CONFIG_CHAIN_OF_TRUST
346 /* In case of Secure Boot, the IBR configures the SMMU
347 * to allow only Secure transactions.
348 * SMMU must be reset in bypass mode.
349 * Set the ClientPD bit and Clear the USFCFG Bit
350 */
351 if (fsl_check_boot_mode_secure() == 1)
352 bypass_smmu();
353#endif
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300354
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000355#if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000356 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300357 set_icids();
358#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700359}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800360
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530361/* Get VDD in the unit mV from voltage ID */
362int get_core_volt_from_fuse(void)
363{
364 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
365 int vdd;
366 u32 fusesr;
367 u8 vid;
368
369 /* get the voltage ID from fuse status register */
370 fusesr = in_le32(&gur->dcfg_fusesr);
371 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
372 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
373 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
374 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
375 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
376 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
377 }
378 debug("%s: VID = 0x%x\n", __func__, vid);
379 switch (vid) {
380 case 0x00: /* VID isn't supported */
381 vdd = -EINVAL;
382 debug("%s: The VID feature is not supported\n", __func__);
383 break;
384 case 0x08: /* 0.9V silicon */
385 vdd = 900;
386 break;
387 case 0x10: /* 1.0V silicon */
388 vdd = 1000;
389 break;
390 default: /* Other core voltage */
391 vdd = -EINVAL;
392 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
393 break;
394 }
395 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
396
397 return vdd;
398}
399
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530400#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800401
Mingkai Hu8beb0752015-12-07 16:58:54 +0800402static void erratum_a009929(void)
403{
404#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
405 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
406 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
407 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
408
409 rstrqmr1 |= 0x00000400;
410 gur_out32(&gur->rstrqmr1, rstrqmr1);
411 writel(0x01000000, dcsr_cop_ccp);
412#endif
413}
414
Mingkai Hu172081c2016-02-02 11:28:03 +0800415/*
416 * This erratum requires setting a value to eddrtqcr1 to optimal
417 * the DDR performance. The eddrtqcr1 register is in SCFG space
418 * of LS1043A and the offset is 0x157_020c.
419 */
420#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
421 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
422#error A009660 and A008514 can not be both enabled.
423#endif
424
425static void erratum_a009660(void)
426{
427#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
428 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
429 out_be32(eddrtqcr1, 0x63b20042);
430#endif
431}
432
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800433static void erratum_a008850_early(void)
434{
435#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
436 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530437 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
438 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800439 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
440
York Sune6b871e2017-05-15 08:51:59 -0700441 /* Skip if running at lower exception level */
442 if (current_el() < 3)
443 return;
444
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800445 /* disables propagation of barrier transactions to DDRC from CCI400 */
446 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
447
448 /* disable the re-ordering in DDRC */
449 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
450#endif
451}
452
453void erratum_a008850_post(void)
454{
455#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
456 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530457 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
458 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800459 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
460 u32 tmp;
461
York Sune6b871e2017-05-15 08:51:59 -0700462 /* Skip if running at lower exception level */
463 if (current_el() < 3)
464 return;
465
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800466 /* enable propagation of barrier transactions to DDRC from CCI400 */
467 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
468
469 /* enable the re-ordering in DDRC */
470 tmp = ddr_in32(&ddr->eor);
471 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
472 ddr_out32(&ddr->eor, tmp);
473#endif
474}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800475
476#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
477void erratum_a010315(void)
478{
479 int i;
480
481 for (i = PCIE1; i <= PCIE4; i++)
482 if (!is_serdes_configured(i)) {
483 debug("PCIe%d: disabled all R/W permission!\n", i);
484 set_pcie_ns_access(i, 0);
485 }
486}
487#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800488
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800489static void erratum_a010539(void)
490{
491#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
492 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
493 u32 porsr1;
494
495 porsr1 = in_be32(&gur->porsr1);
496 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
497 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
498 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800499 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800500#endif
501}
502
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800503/* Get VDD in the unit mV from voltage ID */
504int get_core_volt_from_fuse(void)
505{
506 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
507 int vdd;
508 u32 fusesr;
509 u8 vid;
510
511 fusesr = in_be32(&gur->dcfg_fusesr);
512 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
513 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
514 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
515 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
516 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
517 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
518 }
519 debug("%s: VID = 0x%x\n", __func__, vid);
520 switch (vid) {
521 case 0x00: /* VID isn't supported */
522 vdd = -EINVAL;
523 debug("%s: The VID feature is not supported\n", __func__);
524 break;
525 case 0x08: /* 0.9V silicon */
526 vdd = 900;
527 break;
528 case 0x10: /* 1.0V silicon */
529 vdd = 1000;
530 break;
531 default: /* Other core voltage */
532 vdd = -EINVAL;
533 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
534 break;
535 }
536 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
537
538 return vdd;
539}
540
541__weak int board_switch_core_volt(u32 vdd)
542{
543 return 0;
544}
545
546static int setup_core_volt(u32 vdd)
547{
548 return board_setup_core_volt(vdd);
549}
550
551#ifdef CONFIG_SYS_FSL_DDR
552static void ddr_enable_0v9_volt(bool en)
553{
554 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
555 u32 tmp;
556
557 tmp = ddr_in32(&ddr->ddr_cdr1);
558
559 if (en)
560 tmp |= DDR_CDR1_V0PT9_EN;
561 else
562 tmp &= ~DDR_CDR1_V0PT9_EN;
563
564 ddr_out32(&ddr->ddr_cdr1, tmp);
565}
566#endif
567
568int setup_chip_volt(void)
569{
570 int vdd;
571
572 vdd = get_core_volt_from_fuse();
573 /* Nothing to do for silicons doesn't support VID */
574 if (vdd < 0)
575 return vdd;
576
577 if (setup_core_volt(vdd))
578 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
579#ifdef CONFIG_SYS_HAS_SERDES
580 if (setup_serdes_volt(vdd))
581 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
582#endif
583
584#ifdef CONFIG_SYS_FSL_DDR
585 if (vdd == 900)
586 ddr_enable_0v9_volt(true);
587#endif
588
589 return 0;
590}
591
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530592#ifdef CONFIG_FSL_PFE
593void init_pfe_scfg_dcfg_regs(void)
594{
595 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
596 u32 ecccr2;
597
598 out_be32(&scfg->pfeasbcr,
599 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
600 out_be32(&scfg->pfebsbcr,
601 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
602
603 /* CCI-400 QoS settings for PFE */
604 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
605 | SCFG_WR_QOS1_PFE2_QOS));
606 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
607 | SCFG_RD_QOS1_PFE2_QOS));
608
609 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
610 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
611 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
612}
613#endif
614
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800615void fsl_lsch2_early_init_f(void)
616{
Ashish Kumar11234062017-08-11 11:09:14 +0530617 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
618 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530619 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000620#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
621 enum boot_src src;
622#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800623
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800624#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
625 enable_layerscape_ns_access();
626#endif
627
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800628#ifdef CONFIG_FSL_IFC
629 init_early_memctl_regs(); /* tighten IFC timing */
630#endif
631
Pankit Garg41bde722019-05-29 12:12:36 +0000632#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
633 src = get_boot_src();
634 if (src != BOOT_SOURCE_QSPI_NOR)
635 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
636#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800637#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800638 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
639#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000640#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530641 /* Make SEC reads and writes snoopable */
Ran Wangc75026e2019-09-20 17:34:29 +0800642#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
643 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
644 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
645 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
646 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
647 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
648 SCFG_SNPCNFGCR_SATAWRSNP);
649#else
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530650 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800651 SCFG_SNPCNFGCR_SECWRSNP |
652 SCFG_SNPCNFGCR_SATARDSNP |
653 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800654#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530655
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800656 /*
657 * Enable snoop requests and DVM message requests for
658 * Slave insterface S4 (A53 core cluster)
659 */
York Sune6b871e2017-05-15 08:51:59 -0700660 if (current_el() == 3) {
661 out_le32(&cci->slave[4].snoop_ctrl,
662 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
663 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800664
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800665 /*
666 * Program Central Security Unit (CSU) to grant access
667 * permission for USB 2.0 controller
668 */
669#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
670 if (current_el() == 3)
671 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
672#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800673 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800674 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800675 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800676 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800677 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800678 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800679 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800680 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800681 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300682
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300683#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300684 set_icids();
685#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800686}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800687#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700688
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530689#ifdef CONFIG_FSPI_AHB_EN_4BYTE
690int fspi_ahb_init(void)
691{
692 /* Enable 4bytes address support and fast read */
693 u32 *fspi_lut, lut_key, *fspi_key;
694
695 fspi_key = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUTKEY_BASE_ADDR;
696 fspi_lut = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUT_BASE_ADDR;
697
698 lut_key = in_be32(fspi_key);
699
700 if (lut_key == SYS_NXP_FSPI_LUTKEY) {
701 /* That means the register is BE */
702 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
703 /* Unlock the lut table */
704 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
705 /* Create READ LUT */
706 out_be32(fspi_lut, 0x0820040c);
707 out_be32(fspi_lut + 1, 0x24003008);
708 out_be32(fspi_lut + 2, 0x00000000);
709 /* Lock the lut table */
710 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
711 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
712 } else {
713 /* That means the register is LE */
714 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
715 /* Unlock the lut table */
716 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
717 /* Create READ LUT */
718 out_le32(fspi_lut, 0x0820040c);
719 out_le32(fspi_lut + 1, 0x24003008);
720 out_le32(fspi_lut + 2, 0x00000000);
721 /* Lock the lut table */
722 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
723 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
724 }
725
726 return 0;
727}
728#endif
729
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800730#ifdef CONFIG_QSPI_AHB_INIT
731/* Enable 4bytes address support and fast read */
732int qspi_ahb_init(void)
733{
734 u32 *qspi_lut, lut_key, *qspi_key;
735
736 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
737 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
738
739 lut_key = in_be32(qspi_key);
740
741 if (lut_key == 0x5af05af0) {
742 /* That means the register is BE */
743 out_be32(qspi_key, 0x5af05af0);
744 /* Unlock the lut table */
745 out_be32(qspi_key + 1, 0x00000002);
746 out_be32(qspi_lut, 0x0820040c);
747 out_be32(qspi_lut + 1, 0x1c080c08);
748 out_be32(qspi_lut + 2, 0x00002400);
749 /* Lock the lut table */
750 out_be32(qspi_key, 0x5af05af0);
751 out_be32(qspi_key + 1, 0x00000001);
752 } else {
753 /* That means the register is LE */
754 out_le32(qspi_key, 0x5af05af0);
755 /* Unlock the lut table */
756 out_le32(qspi_key + 1, 0x00000002);
757 out_le32(qspi_lut, 0x0820040c);
758 out_le32(qspi_lut + 1, 0x1c080c08);
759 out_le32(qspi_lut + 2, 0x00002400);
760 /* Lock the lut table */
761 out_le32(qspi_key, 0x5af05af0);
762 out_le32(qspi_key + 1, 0x00000001);
763 }
764
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000765 return 0;
766}
767#endif
768
769#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000770#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000771
772int fsl_setenv_bootcmd(void)
773{
774 int ret;
775 enum boot_src src = get_boot_src();
776 char bootcmd_str[MAX_BOOTCMD_SIZE];
777
778 switch (src) {
779#ifdef IFC_NOR_BOOTCOMMAND
780 case BOOT_SOURCE_IFC_NOR:
781 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
782 break;
783#endif
784#ifdef QSPI_NOR_BOOTCOMMAND
785 case BOOT_SOURCE_QSPI_NOR:
786 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
787 break;
788#endif
789#ifdef XSPI_NOR_BOOTCOMMAND
790 case BOOT_SOURCE_XSPI_NOR:
791 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
792 break;
793#endif
794#ifdef IFC_NAND_BOOTCOMMAND
795 case BOOT_SOURCE_IFC_NAND:
796 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
797 break;
798#endif
799#ifdef QSPI_NAND_BOOTCOMMAND
800 case BOOT_SOURCE_QSPI_NAND:
801 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
802 break;
803#endif
804#ifdef XSPI_NAND_BOOTCOMMAND
805 case BOOT_SOURCE_XSPI_NAND:
806 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
807 break;
808#endif
809#ifdef SD_BOOTCOMMAND
810 case BOOT_SOURCE_SD_MMC:
811 sprintf(bootcmd_str, SD_BOOTCOMMAND);
812 break;
813#endif
814#ifdef SD2_BOOTCOMMAND
815 case BOOT_SOURCE_SD_MMC2:
816 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
817 break;
818#endif
819 default:
820#ifdef QSPI_NOR_BOOTCOMMAND
821 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
822#endif
823 break;
824 }
825
826 ret = env_set("bootcmd", bootcmd_str);
827 if (ret) {
828 printf("Failed to set bootcmd: ret = %d\n", ret);
829 return ret;
830 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800831 return 0;
832}
Pankit Garg82fcc462018-11-05 18:02:31 +0000833
834int fsl_setenv_mcinitcmd(void)
835{
836 int ret = 0;
837 enum boot_src src = get_boot_src();
838
839 switch (src) {
840#ifdef IFC_MC_INIT_CMD
841 case BOOT_SOURCE_IFC_NAND:
842 case BOOT_SOURCE_IFC_NOR:
843 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
844 break;
845#endif
846#ifdef QSPI_MC_INIT_CMD
847 case BOOT_SOURCE_QSPI_NAND:
848 case BOOT_SOURCE_QSPI_NOR:
849 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
850 break;
851#endif
852#ifdef XSPI_MC_INIT_CMD
853 case BOOT_SOURCE_XSPI_NAND:
854 case BOOT_SOURCE_XSPI_NOR:
855 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
856 break;
857#endif
858#ifdef SD_MC_INIT_CMD
859 case BOOT_SOURCE_SD_MMC:
860 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
861 break;
862#endif
863#ifdef SD2_MC_INIT_CMD
864 case BOOT_SOURCE_SD_MMC2:
865 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
866 break;
867#endif
868 default:
869#ifdef QSPI_MC_INIT_CMD
870 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
871#endif
872 break;
873 }
874
875 if (ret) {
876 printf("Failed to set mcinitcmd: ret = %d\n", ret);
877 return ret;
878 }
879 return 0;
880}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800881#endif
882
Mingkai Hu0e58b512015-10-26 19:47:50 +0800883#ifdef CONFIG_BOARD_LATE_INIT
Michael Wallefc667ea2019-10-21 22:37:45 +0200884__weak int fsl_board_late_init(void)
885{
886 return 0;
887}
888
Mingkai Hu0e58b512015-10-26 19:47:50 +0800889int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700890{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530891#ifdef CONFIG_CHAIN_OF_TRUST
892 fsl_setenv_chain_of_trust();
893#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000894#ifdef CONFIG_TFABOOT
895 /*
896 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000897 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000898 */
Tom Rini5cd7ece2019-11-18 20:02:10 -0500899#ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
Pankit Gargd6bd6782019-05-30 12:04:15 +0000900 if (gd->env_addr == (ulong)&default_environment[0]) {
901#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000902 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000903#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000904 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000905 fsl_setenv_mcinitcmd();
906 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000907
908 /*
909 * If the boot mode is secure, default environment is not present then
910 * setenv command needs to be run by default
911 */
912#ifdef CONFIG_CHAIN_OF_TRUST
913 if ((fsl_check_boot_mode_secure() == 1)) {
914 fsl_setenv_bootcmd();
915 fsl_setenv_mcinitcmd();
916 }
917#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000918#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800919#ifdef CONFIG_QSPI_AHB_INIT
920 qspi_ahb_init();
921#endif
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530922#ifdef CONFIG_FSPI_AHB_EN_4BYTE
923 fspi_ahb_init();
924#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800925
Michael Wallefc667ea2019-10-21 22:37:45 +0200926 return fsl_board_late_init();
Scott Wood8e728cd2015-03-24 13:25:02 -0700927}
928#endif