blob: d0e10cb007be5a2be1ac91dce616470ae77ca7f9 [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 Glass85d65312019-12-28 10:44:58 -07008#include <clock_legacy.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Ashish Kumar11234062017-08-11 11:09:14 +053010#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -070011#include <fsl_ifc.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080013#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080014#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070015#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070016#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053017#include <asm/arch-fsl-layerscape/config.h>
Ran Wang4e7cdcf2018-08-10 15:00:00 +080018#include <asm/arch-fsl-layerscape/ns_access.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030019#include <asm/arch-fsl-layerscape/fsl_icid.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080020#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080021#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080022#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053023#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080024#include <fsl_ddr_sdram.h>
25#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053026#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053027#ifdef CONFIG_CHAIN_OF_TRUST
28#include <fsl_validate.h>
29#endif
Ashish Kumarb25faa22017-08-31 16:12:53 +053030#include <fsl_immap.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000031#ifdef CONFIG_TFABOOT
Simon Glass9d1f6192019-08-02 09:44:25 -060032#include <env_internal.h>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000033DECLARE_GLOBAL_DATA_PTR;
34#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070035
York Suncbe8e1c2016-04-04 11:41:26 -070036bool soc_has_dp_ddr(void)
37{
38 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
39 u32 svr = gur_in32(&gur->svr);
40
Priyanka Jain4a6f1732016-11-17 12:29:55 +053041 /* LS2085A, LS2088A, LS2048A has DP_DDR */
42 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
43 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
44 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070045 return true;
46
47 return false;
48}
49
50bool soc_has_aiop(void)
51{
52 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
53 u32 svr = gur_in32(&gur->svr);
54
55 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053056 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070057 return true;
58
59 return false;
60}
61
Ran Wangb358b7b2017-09-04 18:46:48 +080062static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
63{
64 scfg_clrsetbits32(scfg + offset / 4,
65 0xF << 6,
66 SCFG_USB_TXVREFTUNE << 6);
67}
68
69static void erratum_a009008(void)
70{
71#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
72 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080073
Ran Wang02dc77b2017-11-13 16:14:48 +080074#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
75 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080076 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080077#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080078 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
79 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080080#endif
Ran Wangb358b7b2017-09-04 18:46:48 +080081#elif defined(CONFIG_ARCH_LS2080A)
82 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
83#endif
84#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
85}
86
Ran Wang9e8fabc2017-09-04 18:46:49 +080087static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
88{
89 scfg_clrbits32(scfg + offset / 4,
90 SCFG_USB_SQRXTUNE_MASK << 23);
91}
92
93static void erratum_a009798(void)
94{
95#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
96 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
97
Ran Wang02dc77b2017-11-13 16:14:48 +080098#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
99 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800100 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800101#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800102 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
103 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800104#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800105#elif defined(CONFIG_ARCH_LS2080A)
106 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
107#endif
108#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
109}
110
Ran Wang02dc77b2017-11-13 16:14:48 +0800111#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
112 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800113static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
114{
115 scfg_clrsetbits32(scfg + offset / 4,
116 0x7F << 9,
117 SCFG_USB_PCSTXSWINGFULL << 9);
118}
119#endif
120
121static void erratum_a008997(void)
122{
123#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800124#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
125 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800126 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
127
128 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800129#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800130 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
131 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
132#endif
Ran Wange118acb2019-05-14 17:34:56 +0800133#elif defined(CONFIG_ARCH_LS1028A)
134 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
135 0x7F << 11,
136 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800137#endif
Ran Wange64f7472017-09-04 18:46:50 +0800138#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
139}
140
Ran Wang02dc77b2017-11-13 16:14:48 +0800141#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
142 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800143
144#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
145 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
146 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
147 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
148 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
149
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800150#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
Ran Wangd0270dc2019-11-26 11:40:40 +0800151 defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A)
Ran Wang3ba69482017-09-04 18:46:51 +0800152
153#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
154 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
155 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
156 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
157 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
158
159#endif
160
161static void erratum_a009007(void)
162{
Ran Wang02dc77b2017-11-13 16:14:48 +0800163#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
164 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800165 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
166
167 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800168#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800169 usb_phy = (void __iomem *)SCFG_USB_PHY2;
170 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
171
172 usb_phy = (void __iomem *)SCFG_USB_PHY3;
173 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800174#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800175#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
176 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800177 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
178
179 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
180 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
181#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
182}
183
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800184#if defined(CONFIG_FSL_LSCH3)
Ran Wangd0270dc2019-11-26 11:40:40 +0800185static void erratum_a050106(void)
186{
187#if defined(CONFIG_ARCH_LX2160A)
188 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
189
190 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
191 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
192#endif
193}
Yao Yuanfae88052015-12-05 14:59:14 +0800194/*
195 * This erratum requires setting a value to eddrtqcr1 to
196 * optimal the DDR performance.
197 */
198static void erratum_a008336(void)
199{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800200#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800201 u32 *eddrtqcr1;
202
Yao Yuanfae88052015-12-05 14:59:14 +0800203#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
204 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800205 if (fsl_ddr_get_version(0) == 0x50200)
206 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800207#endif
208#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
209 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800210 if (fsl_ddr_get_version(0) == 0x50200)
211 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800212#endif
213#endif
214}
215
216/*
217 * This erratum requires a register write before being Memory
218 * controller 3 being enabled.
219 */
220static void erratum_a008514(void)
221{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800222#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800223 u32 *eddrtqcr1;
224
Yao Yuanfae88052015-12-05 14:59:14 +0800225#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
226 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
227 out_le32(eddrtqcr1, 0x63b20002);
228#endif
229#endif
230}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530231#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
232#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
233
234static unsigned long get_internval_val_mhz(void)
235{
Simon Glass64b723f2017-08-03 12:22:12 -0600236 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530237 /*
238 * interval is the number of platform cycles(MHz) between
239 * wake up events generated by EPU.
240 */
241 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
242
243 if (interval)
244 interval_mhz = simple_strtoul(interval, NULL, 10);
245
246 return interval_mhz;
247}
248
249void erratum_a009635(void)
250{
251 u32 val;
252 unsigned long interval_mhz = get_internval_val_mhz();
253
254 if (!interval_mhz)
255 return;
256
257 val = in_le32(DCSR_CGACRE5);
258 writel(val | 0x00000200, DCSR_CGACRE5);
259
260 val = in_le32(EPU_EPCMPR5);
261 writel(interval_mhz, EPU_EPCMPR5);
262 val = in_le32(EPU_EPCCR5);
263 writel(val | 0x82820000, EPU_EPCCR5);
264 val = in_le32(EPU_EPSMCR5);
265 writel(val | 0x002f0000, EPU_EPSMCR5);
266 val = in_le32(EPU_EPECR5);
267 writel(val | 0x20000000, EPU_EPECR5);
268 val = in_le32(EPU_EPGCR);
269 writel(val | 0x80000000, EPU_EPGCR);
270}
271#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
272
Scott Wood8e728cd2015-03-24 13:25:02 -0700273static void erratum_rcw_src(void)
274{
Santan Kumar99136482017-05-05 15:42:28 +0530275#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700276 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
277 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
278 u32 val;
279
280 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
281 val &= ~DCFG_PORSR1_RCW_SRC;
282 val |= DCFG_PORSR1_RCW_SRC_NOR;
283 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
284#endif
285}
286
York Sun0404a392015-03-23 10:41:35 -0700287#define I2C_DEBUG_REG 0x6
288#define I2C_GLITCH_EN 0x8
289/*
290 * This erratum requires setting glitch_en bit to enable
291 * digital glitch filter to improve clock stability.
292 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530293#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700294static void erratum_a009203(void)
295{
York Sun0404a392015-03-23 10:41:35 -0700296#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530297 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700298#ifdef I2C1_BASE_ADDR
299 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
300
301 writeb(I2C_GLITCH_EN, ptr);
302#endif
303#ifdef I2C2_BASE_ADDR
304 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
305
306 writeb(I2C_GLITCH_EN, ptr);
307#endif
308#ifdef I2C3_BASE_ADDR
309 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
310
311 writeb(I2C_GLITCH_EN, ptr);
312#endif
313#ifdef I2C4_BASE_ADDR
314 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
315
316 writeb(I2C_GLITCH_EN, ptr);
317#endif
318#endif
319}
Ashish kumar3b52a232017-02-23 16:03:57 +0530320#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800321
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530322void bypass_smmu(void)
323{
324 u32 val;
325 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
326 out_le32(SMMU_SCR0, val);
327 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
328 out_le32(SMMU_NSCR0, val);
329}
Scott Woodf64c98c2015-03-20 19:28:12 -0700330void fsl_lsch3_early_init_f(void)
331{
Scott Wood8e728cd2015-03-24 13:25:02 -0700332 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530333#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700334 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530335#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530336#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700337 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530338#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800339 erratum_a008514();
340 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800341 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800342 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800343 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800344 erratum_a009007();
Ran Wangd0270dc2019-11-26 11:40:40 +0800345 erratum_a050106();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530346#ifdef CONFIG_CHAIN_OF_TRUST
347 /* In case of Secure Boot, the IBR configures the SMMU
348 * to allow only Secure transactions.
349 * SMMU must be reset in bypass mode.
350 * Set the ClientPD bit and Clear the USFCFG Bit
351 */
352 if (fsl_check_boot_mode_secure() == 1)
353 bypass_smmu();
354#endif
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300355
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000356#if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000357 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300358 set_icids();
359#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700360}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800361
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530362/* Get VDD in the unit mV from voltage ID */
363int get_core_volt_from_fuse(void)
364{
365 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
366 int vdd;
367 u32 fusesr;
368 u8 vid;
369
370 /* get the voltage ID from fuse status register */
371 fusesr = in_le32(&gur->dcfg_fusesr);
372 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
373 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
374 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
375 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
376 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
377 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
378 }
379 debug("%s: VID = 0x%x\n", __func__, vid);
380 switch (vid) {
381 case 0x00: /* VID isn't supported */
382 vdd = -EINVAL;
383 debug("%s: The VID feature is not supported\n", __func__);
384 break;
385 case 0x08: /* 0.9V silicon */
386 vdd = 900;
387 break;
388 case 0x10: /* 1.0V silicon */
389 vdd = 1000;
390 break;
391 default: /* Other core voltage */
392 vdd = -EINVAL;
393 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
394 break;
395 }
396 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
397
398 return vdd;
399}
400
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530401#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800402
Mingkai Hu8beb0752015-12-07 16:58:54 +0800403static void erratum_a009929(void)
404{
405#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
406 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
407 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
408 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
409
410 rstrqmr1 |= 0x00000400;
411 gur_out32(&gur->rstrqmr1, rstrqmr1);
412 writel(0x01000000, dcsr_cop_ccp);
413#endif
414}
415
Mingkai Hu172081c2016-02-02 11:28:03 +0800416/*
417 * This erratum requires setting a value to eddrtqcr1 to optimal
418 * the DDR performance. The eddrtqcr1 register is in SCFG space
419 * of LS1043A and the offset is 0x157_020c.
420 */
421#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
422 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
423#error A009660 and A008514 can not be both enabled.
424#endif
425
426static void erratum_a009660(void)
427{
428#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
429 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
430 out_be32(eddrtqcr1, 0x63b20042);
431#endif
432}
433
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800434static void erratum_a008850_early(void)
435{
436#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
437 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530438 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
439 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800440 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
441
York Sune6b871e2017-05-15 08:51:59 -0700442 /* Skip if running at lower exception level */
443 if (current_el() < 3)
444 return;
445
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800446 /* disables propagation of barrier transactions to DDRC from CCI400 */
447 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
448
449 /* disable the re-ordering in DDRC */
450 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
451#endif
452}
453
454void erratum_a008850_post(void)
455{
456#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
457 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530458 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
459 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800460 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
461 u32 tmp;
462
York Sune6b871e2017-05-15 08:51:59 -0700463 /* Skip if running at lower exception level */
464 if (current_el() < 3)
465 return;
466
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800467 /* enable propagation of barrier transactions to DDRC from CCI400 */
468 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
469
470 /* enable the re-ordering in DDRC */
471 tmp = ddr_in32(&ddr->eor);
472 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
473 ddr_out32(&ddr->eor, tmp);
474#endif
475}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800476
477#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
478void erratum_a010315(void)
479{
480 int i;
481
482 for (i = PCIE1; i <= PCIE4; i++)
483 if (!is_serdes_configured(i)) {
484 debug("PCIe%d: disabled all R/W permission!\n", i);
485 set_pcie_ns_access(i, 0);
486 }
487}
488#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800489
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800490static void erratum_a010539(void)
491{
492#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
493 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
494 u32 porsr1;
495
496 porsr1 = in_be32(&gur->porsr1);
497 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
498 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
499 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800500 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800501#endif
502}
503
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800504/* Get VDD in the unit mV from voltage ID */
505int get_core_volt_from_fuse(void)
506{
507 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
508 int vdd;
509 u32 fusesr;
510 u8 vid;
511
512 fusesr = in_be32(&gur->dcfg_fusesr);
513 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
514 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
515 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
516 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
517 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
518 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
519 }
520 debug("%s: VID = 0x%x\n", __func__, vid);
521 switch (vid) {
522 case 0x00: /* VID isn't supported */
523 vdd = -EINVAL;
524 debug("%s: The VID feature is not supported\n", __func__);
525 break;
526 case 0x08: /* 0.9V silicon */
527 vdd = 900;
528 break;
529 case 0x10: /* 1.0V silicon */
530 vdd = 1000;
531 break;
532 default: /* Other core voltage */
533 vdd = -EINVAL;
534 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
535 break;
536 }
537 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
538
539 return vdd;
540}
541
542__weak int board_switch_core_volt(u32 vdd)
543{
544 return 0;
545}
546
547static int setup_core_volt(u32 vdd)
548{
549 return board_setup_core_volt(vdd);
550}
551
552#ifdef CONFIG_SYS_FSL_DDR
553static void ddr_enable_0v9_volt(bool en)
554{
555 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
556 u32 tmp;
557
558 tmp = ddr_in32(&ddr->ddr_cdr1);
559
560 if (en)
561 tmp |= DDR_CDR1_V0PT9_EN;
562 else
563 tmp &= ~DDR_CDR1_V0PT9_EN;
564
565 ddr_out32(&ddr->ddr_cdr1, tmp);
566}
567#endif
568
569int setup_chip_volt(void)
570{
571 int vdd;
572
573 vdd = get_core_volt_from_fuse();
574 /* Nothing to do for silicons doesn't support VID */
575 if (vdd < 0)
576 return vdd;
577
578 if (setup_core_volt(vdd))
579 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
580#ifdef CONFIG_SYS_HAS_SERDES
581 if (setup_serdes_volt(vdd))
582 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
583#endif
584
585#ifdef CONFIG_SYS_FSL_DDR
586 if (vdd == 900)
587 ddr_enable_0v9_volt(true);
588#endif
589
590 return 0;
591}
592
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530593#ifdef CONFIG_FSL_PFE
594void init_pfe_scfg_dcfg_regs(void)
595{
596 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
597 u32 ecccr2;
598
599 out_be32(&scfg->pfeasbcr,
600 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
601 out_be32(&scfg->pfebsbcr,
602 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
603
604 /* CCI-400 QoS settings for PFE */
605 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
606 | SCFG_WR_QOS1_PFE2_QOS));
607 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
608 | SCFG_RD_QOS1_PFE2_QOS));
609
610 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
611 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
612 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
613}
614#endif
615
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800616void fsl_lsch2_early_init_f(void)
617{
Ashish Kumar11234062017-08-11 11:09:14 +0530618 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
619 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530620 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000621#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
622 enum boot_src src;
623#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800624
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800625#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
626 enable_layerscape_ns_access();
627#endif
628
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800629#ifdef CONFIG_FSL_IFC
630 init_early_memctl_regs(); /* tighten IFC timing */
631#endif
632
Pankit Garg41bde722019-05-29 12:12:36 +0000633#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
634 src = get_boot_src();
635 if (src != BOOT_SOURCE_QSPI_NOR)
636 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
637#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800638#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800639 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
640#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000641#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530642 /* Make SEC reads and writes snoopable */
Ran Wangc75026e2019-09-20 17:34:29 +0800643#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
644 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
645 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
646 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
647 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
648 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
649 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wanga7576692019-12-26 18:11:17 +0800650#elif defined(CONFIG_ARCH_LS1012A)
651 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
652 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
653 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
654 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800655#else
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530656 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800657 SCFG_SNPCNFGCR_SECWRSNP |
658 SCFG_SNPCNFGCR_SATARDSNP |
659 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800660#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530661
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800662 /*
663 * Enable snoop requests and DVM message requests for
664 * Slave insterface S4 (A53 core cluster)
665 */
York Sune6b871e2017-05-15 08:51:59 -0700666 if (current_el() == 3) {
667 out_le32(&cci->slave[4].snoop_ctrl,
668 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
669 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800670
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800671 /*
672 * Program Central Security Unit (CSU) to grant access
673 * permission for USB 2.0 controller
674 */
675#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
676 if (current_el() == 3)
677 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
678#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800679 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800680 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800681 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800682 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800683 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800684 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800685 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800686 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800687 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300688
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300689#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300690 set_icids();
691#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800692}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800693#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700694
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530695#ifdef CONFIG_FSPI_AHB_EN_4BYTE
696int fspi_ahb_init(void)
697{
698 /* Enable 4bytes address support and fast read */
699 u32 *fspi_lut, lut_key, *fspi_key;
700
701 fspi_key = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUTKEY_BASE_ADDR;
702 fspi_lut = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUT_BASE_ADDR;
703
704 lut_key = in_be32(fspi_key);
705
706 if (lut_key == SYS_NXP_FSPI_LUTKEY) {
707 /* That means the register is BE */
708 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
709 /* Unlock the lut table */
710 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
711 /* Create READ LUT */
712 out_be32(fspi_lut, 0x0820040c);
713 out_be32(fspi_lut + 1, 0x24003008);
714 out_be32(fspi_lut + 2, 0x00000000);
715 /* Lock the lut table */
716 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
717 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
718 } else {
719 /* That means the register is LE */
720 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
721 /* Unlock the lut table */
722 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
723 /* Create READ LUT */
724 out_le32(fspi_lut, 0x0820040c);
725 out_le32(fspi_lut + 1, 0x24003008);
726 out_le32(fspi_lut + 2, 0x00000000);
727 /* Lock the lut table */
728 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
729 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
730 }
731
732 return 0;
733}
734#endif
735
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800736#ifdef CONFIG_QSPI_AHB_INIT
737/* Enable 4bytes address support and fast read */
738int qspi_ahb_init(void)
739{
740 u32 *qspi_lut, lut_key, *qspi_key;
741
742 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
743 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
744
745 lut_key = in_be32(qspi_key);
746
747 if (lut_key == 0x5af05af0) {
748 /* That means the register is BE */
749 out_be32(qspi_key, 0x5af05af0);
750 /* Unlock the lut table */
751 out_be32(qspi_key + 1, 0x00000002);
752 out_be32(qspi_lut, 0x0820040c);
753 out_be32(qspi_lut + 1, 0x1c080c08);
754 out_be32(qspi_lut + 2, 0x00002400);
755 /* Lock the lut table */
756 out_be32(qspi_key, 0x5af05af0);
757 out_be32(qspi_key + 1, 0x00000001);
758 } else {
759 /* That means the register is LE */
760 out_le32(qspi_key, 0x5af05af0);
761 /* Unlock the lut table */
762 out_le32(qspi_key + 1, 0x00000002);
763 out_le32(qspi_lut, 0x0820040c);
764 out_le32(qspi_lut + 1, 0x1c080c08);
765 out_le32(qspi_lut + 2, 0x00002400);
766 /* Lock the lut table */
767 out_le32(qspi_key, 0x5af05af0);
768 out_le32(qspi_key + 1, 0x00000001);
769 }
770
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000771 return 0;
772}
773#endif
774
775#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000776#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000777
778int fsl_setenv_bootcmd(void)
779{
780 int ret;
781 enum boot_src src = get_boot_src();
782 char bootcmd_str[MAX_BOOTCMD_SIZE];
783
784 switch (src) {
785#ifdef IFC_NOR_BOOTCOMMAND
786 case BOOT_SOURCE_IFC_NOR:
787 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
788 break;
789#endif
790#ifdef QSPI_NOR_BOOTCOMMAND
791 case BOOT_SOURCE_QSPI_NOR:
792 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
793 break;
794#endif
795#ifdef XSPI_NOR_BOOTCOMMAND
796 case BOOT_SOURCE_XSPI_NOR:
797 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
798 break;
799#endif
800#ifdef IFC_NAND_BOOTCOMMAND
801 case BOOT_SOURCE_IFC_NAND:
802 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
803 break;
804#endif
805#ifdef QSPI_NAND_BOOTCOMMAND
806 case BOOT_SOURCE_QSPI_NAND:
807 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
808 break;
809#endif
810#ifdef XSPI_NAND_BOOTCOMMAND
811 case BOOT_SOURCE_XSPI_NAND:
812 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
813 break;
814#endif
815#ifdef SD_BOOTCOMMAND
816 case BOOT_SOURCE_SD_MMC:
817 sprintf(bootcmd_str, SD_BOOTCOMMAND);
818 break;
819#endif
820#ifdef SD2_BOOTCOMMAND
821 case BOOT_SOURCE_SD_MMC2:
822 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
823 break;
824#endif
825 default:
826#ifdef QSPI_NOR_BOOTCOMMAND
827 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
828#endif
829 break;
830 }
831
832 ret = env_set("bootcmd", bootcmd_str);
833 if (ret) {
834 printf("Failed to set bootcmd: ret = %d\n", ret);
835 return ret;
836 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800837 return 0;
838}
Pankit Garg82fcc462018-11-05 18:02:31 +0000839
840int fsl_setenv_mcinitcmd(void)
841{
842 int ret = 0;
843 enum boot_src src = get_boot_src();
844
845 switch (src) {
846#ifdef IFC_MC_INIT_CMD
847 case BOOT_SOURCE_IFC_NAND:
848 case BOOT_SOURCE_IFC_NOR:
849 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
850 break;
851#endif
852#ifdef QSPI_MC_INIT_CMD
853 case BOOT_SOURCE_QSPI_NAND:
854 case BOOT_SOURCE_QSPI_NOR:
855 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
856 break;
857#endif
858#ifdef XSPI_MC_INIT_CMD
859 case BOOT_SOURCE_XSPI_NAND:
860 case BOOT_SOURCE_XSPI_NOR:
861 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
862 break;
863#endif
864#ifdef SD_MC_INIT_CMD
865 case BOOT_SOURCE_SD_MMC:
866 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
867 break;
868#endif
869#ifdef SD2_MC_INIT_CMD
870 case BOOT_SOURCE_SD_MMC2:
871 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
872 break;
873#endif
874 default:
875#ifdef QSPI_MC_INIT_CMD
876 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
877#endif
878 break;
879 }
880
881 if (ret) {
882 printf("Failed to set mcinitcmd: ret = %d\n", ret);
883 return ret;
884 }
885 return 0;
886}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800887#endif
888
Mingkai Hu0e58b512015-10-26 19:47:50 +0800889#ifdef CONFIG_BOARD_LATE_INIT
Michael Wallefc667ea2019-10-21 22:37:45 +0200890__weak int fsl_board_late_init(void)
891{
892 return 0;
893}
894
Mingkai Hu0e58b512015-10-26 19:47:50 +0800895int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700896{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530897#ifdef CONFIG_CHAIN_OF_TRUST
898 fsl_setenv_chain_of_trust();
899#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000900#ifdef CONFIG_TFABOOT
901 /*
902 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000903 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000904 */
Tom Rini5cd7ece2019-11-18 20:02:10 -0500905#ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
Pankit Gargd6bd6782019-05-30 12:04:15 +0000906 if (gd->env_addr == (ulong)&default_environment[0]) {
907#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000908 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000909#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000910 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000911 fsl_setenv_mcinitcmd();
912 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000913
914 /*
915 * If the boot mode is secure, default environment is not present then
916 * setenv command needs to be run by default
917 */
918#ifdef CONFIG_CHAIN_OF_TRUST
919 if ((fsl_check_boot_mode_secure() == 1)) {
920 fsl_setenv_bootcmd();
921 fsl_setenv_mcinitcmd();
922 }
923#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000924#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800925#ifdef CONFIG_QSPI_AHB_INIT
926 qspi_ahb_init();
927#endif
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530928#ifdef CONFIG_FSPI_AHB_EN_4BYTE
929 fspi_ahb_init();
930#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800931
Michael Wallefc667ea2019-10-21 22:37:45 +0200932 return fsl_board_late_init();
Scott Wood8e728cd2015-03-24 13:25:02 -0700933}
934#endif