blob: c0e100d21c24167f00939ce00388261a4ed3be8f [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
Ran Wang13a84a52021-06-16 17:53:19 +05304 * Copyright 2019-2021 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>
Hou Zhiqiang031bb872020-04-28 10:19:32 +08009#include <cpu_func.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Ashish Kumar11234062017-08-11 11:09:14 +053011#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -070012#include <fsl_ifc.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Hou Zhiqiang031bb872020-04-28 10:19:32 +080014#include <linux/sizes.h>
Simon Glass0f2af882020-05-10 11:40:05 -060015#include <log.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080016#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080017#include <asm/arch/soc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060018#include <asm/cache.h>
Scott Woodae1df322015-03-20 19:28:13 -070019#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070020#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053021#include <asm/arch-fsl-layerscape/config.h>
Ran Wang4e7cdcf2018-08-10 15:00:00 +080022#include <asm/arch-fsl-layerscape/ns_access.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030023#include <asm/arch-fsl-layerscape/fsl_icid.h>
Hou Zhiqiang031bb872020-04-28 10:19:32 +080024#include <asm/gic-v3.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080025#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080026#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080027#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053028#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080029#include <fsl_ddr_sdram.h>
30#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053031#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053032#ifdef CONFIG_CHAIN_OF_TRUST
33#include <fsl_validate.h>
34#endif
Ashish Kumarb25faa22017-08-31 16:12:53 +053035#include <fsl_immap.h>
Ran Wangba7cd0f2020-08-05 15:07:27 +080036#include <dm.h>
Tom Rinifb6abdd2020-10-15 21:44:15 -040037#include <dm/device_compat.h>
Ran Wangba7cd0f2020-08-05 15:07:27 +080038#include <linux/err.h>
Alban Bedel0b8932f2020-11-17 16:20:04 +010039#ifdef CONFIG_GIC_V3_ITS
Pankit Gargbdbf84f2018-11-05 18:01:52 +000040DECLARE_GLOBAL_DATA_PTR;
41#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070042
Hou Zhiqiang031bb872020-04-28 10:19:32 +080043#ifdef CONFIG_GIC_V3_ITS
Hou Zhiqiang031bb872020-04-28 10:19:32 +080044int ls_gic_rd_tables_init(void *blob)
45{
Tom Rini4e87d9d2021-10-27 18:54:53 +020046 int ret;
Hou Zhiqiang031bb872020-04-28 10:19:32 +080047
Rayagonda Kokatanur158c16e2020-07-26 22:37:33 +053048 ret = gic_lpi_tables_init();
Hou Zhiqiang031bb872020-04-28 10:19:32 +080049 if (ret)
50 debug("%s: failed to init gic-lpi-tables\n", __func__);
51
52 return ret;
53}
54#endif
55
York Suncbe8e1c2016-04-04 11:41:26 -070056bool soc_has_dp_ddr(void)
57{
58 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
59 u32 svr = gur_in32(&gur->svr);
60
Priyanka Jain4a6f1732016-11-17 12:29:55 +053061 /* LS2085A, LS2088A, LS2048A has DP_DDR */
62 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
63 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
64 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070065 return true;
66
67 return false;
68}
69
70bool soc_has_aiop(void)
71{
72 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
73 u32 svr = gur_in32(&gur->svr);
74
75 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053076 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070077 return true;
78
79 return false;
80}
81
Ran Wangb358b7b2017-09-04 18:46:48 +080082static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
83{
84 scfg_clrsetbits32(scfg + offset / 4,
85 0xF << 6,
86 SCFG_USB_TXVREFTUNE << 6);
87}
88
89static void erratum_a009008(void)
90{
91#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
92 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080093
Ran Wang02dc77b2017-11-13 16:14:48 +080094#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
95 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080096 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080097#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080098 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
99 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800100#endif
Ran Wangb358b7b2017-09-04 18:46:48 +0800101#elif defined(CONFIG_ARCH_LS2080A)
102 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
103#endif
104#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
105}
106
Ran Wang9e8fabc2017-09-04 18:46:49 +0800107static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
108{
109 scfg_clrbits32(scfg + offset / 4,
110 SCFG_USB_SQRXTUNE_MASK << 23);
111}
112
113static void erratum_a009798(void)
114{
115#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
116 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
117
Ran Wang02dc77b2017-11-13 16:14:48 +0800118#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
119 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800120 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800121#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800122 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
123 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800124#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800125#elif defined(CONFIG_ARCH_LS2080A)
126 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
127#endif
128#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
129}
130
Ran Wang02dc77b2017-11-13 16:14:48 +0800131#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
132 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800133static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
134{
135 scfg_clrsetbits32(scfg + offset / 4,
136 0x7F << 9,
137 SCFG_USB_PCSTXSWINGFULL << 9);
138}
139#endif
140
141static void erratum_a008997(void)
142{
143#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800144#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
145 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800146 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
147
148 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800149#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800150 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
151 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
152#endif
Ran Wange118acb2019-05-14 17:34:56 +0800153#elif defined(CONFIG_ARCH_LS1028A)
154 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
155 0x7F << 11,
156 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800157#endif
Ran Wange64f7472017-09-04 18:46:50 +0800158#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
159}
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
164#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
165 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
166 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
167 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
168 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
169
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800170#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530171 defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A) || \
172 defined(CONFIG_ARCH_LX2162A)
Ran Wang3ba69482017-09-04 18:46:51 +0800173
174#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
175 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
176 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
177 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
178 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
179
180#endif
181
182static void erratum_a009007(void)
183{
Ran Wang02dc77b2017-11-13 16:14:48 +0800184#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
185 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800186 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
187
188 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800189#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800190 usb_phy = (void __iomem *)SCFG_USB_PHY2;
191 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
192
193 usb_phy = (void __iomem *)SCFG_USB_PHY3;
194 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800195#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800196#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
197 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800198 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
199
200 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
201 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
202#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
203}
204
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800205#if defined(CONFIG_FSL_LSCH3)
Ran Wang13a84a52021-06-16 17:53:19 +0530206static void erratum_a050204(void)
Ran Wangd0270dc2019-11-26 11:40:40 +0800207{
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530208#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Ran Wangd0270dc2019-11-26 11:40:40 +0800209 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
210
211 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
212 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
213#endif
214}
Yao Yuanfae88052015-12-05 14:59:14 +0800215/*
216 * This erratum requires setting a value to eddrtqcr1 to
217 * optimal the DDR performance.
218 */
219static void erratum_a008336(void)
220{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800221#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800222 u32 *eddrtqcr1;
223
Yao Yuanfae88052015-12-05 14:59:14 +0800224#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
225 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800226 if (fsl_ddr_get_version(0) == 0x50200)
227 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800228#endif
229#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
230 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800231 if (fsl_ddr_get_version(0) == 0x50200)
232 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800233#endif
234#endif
235}
236
237/*
238 * This erratum requires a register write before being Memory
239 * controller 3 being enabled.
240 */
241static void erratum_a008514(void)
242{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800243#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800244 u32 *eddrtqcr1;
245
Yao Yuanfae88052015-12-05 14:59:14 +0800246#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
247 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
248 out_le32(eddrtqcr1, 0x63b20002);
249#endif
250#endif
251}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530252#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
253#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
254
255static unsigned long get_internval_val_mhz(void)
256{
Simon Glass64b723f2017-08-03 12:22:12 -0600257 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530258 /*
259 * interval is the number of platform cycles(MHz) between
260 * wake up events generated by EPU.
261 */
262 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
263
264 if (interval)
Simon Glassff9b9032021-07-24 09:03:30 -0600265 interval_mhz = dectoul(interval, NULL);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530266
267 return interval_mhz;
268}
269
270void erratum_a009635(void)
271{
272 u32 val;
273 unsigned long interval_mhz = get_internval_val_mhz();
274
275 if (!interval_mhz)
276 return;
277
278 val = in_le32(DCSR_CGACRE5);
279 writel(val | 0x00000200, DCSR_CGACRE5);
280
281 val = in_le32(EPU_EPCMPR5);
282 writel(interval_mhz, EPU_EPCMPR5);
283 val = in_le32(EPU_EPCCR5);
284 writel(val | 0x82820000, EPU_EPCCR5);
285 val = in_le32(EPU_EPSMCR5);
286 writel(val | 0x002f0000, EPU_EPSMCR5);
287 val = in_le32(EPU_EPECR5);
288 writel(val | 0x20000000, EPU_EPECR5);
289 val = in_le32(EPU_EPGCR);
290 writel(val | 0x80000000, EPU_EPGCR);
291}
292#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
293
Scott Wood8e728cd2015-03-24 13:25:02 -0700294static void erratum_rcw_src(void)
295{
Santan Kumar99136482017-05-05 15:42:28 +0530296#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700297 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
298 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
299 u32 val;
300
301 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
302 val &= ~DCFG_PORSR1_RCW_SRC;
303 val |= DCFG_PORSR1_RCW_SRC_NOR;
304 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
305#endif
306}
307
York Sun0404a392015-03-23 10:41:35 -0700308#define I2C_DEBUG_REG 0x6
309#define I2C_GLITCH_EN 0x8
310/*
311 * This erratum requires setting glitch_en bit to enable
312 * digital glitch filter to improve clock stability.
313 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530314#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700315static void erratum_a009203(void)
316{
Tom Rini52b2e262021-08-18 23:12:24 -0400317#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
Sriram Dashafa125b2017-09-04 15:45:02 +0530318 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700319#ifdef I2C1_BASE_ADDR
320 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
321
322 writeb(I2C_GLITCH_EN, ptr);
323#endif
324#ifdef I2C2_BASE_ADDR
325 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
326
327 writeb(I2C_GLITCH_EN, ptr);
328#endif
329#ifdef I2C3_BASE_ADDR
330 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
331
332 writeb(I2C_GLITCH_EN, ptr);
333#endif
334#ifdef I2C4_BASE_ADDR
335 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
336
337 writeb(I2C_GLITCH_EN, ptr);
338#endif
339#endif
340}
Ashish kumar3b52a232017-02-23 16:03:57 +0530341#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800342
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530343void bypass_smmu(void)
344{
345 u32 val;
346 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
347 out_le32(SMMU_SCR0, val);
348 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
349 out_le32(SMMU_NSCR0, val);
350}
Scott Woodf64c98c2015-03-20 19:28:12 -0700351void fsl_lsch3_early_init_f(void)
352{
Scott Wood8e728cd2015-03-24 13:25:02 -0700353 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530354#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700355 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530356#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530357#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700358 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530359#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800360 erratum_a008514();
361 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800362 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800363 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800364 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800365 erratum_a009007();
Ran Wang13a84a52021-06-16 17:53:19 +0530366 erratum_a050204();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530367#ifdef CONFIG_CHAIN_OF_TRUST
368 /* In case of Secure Boot, the IBR configures the SMMU
369 * to allow only Secure transactions.
370 * SMMU must be reset in bypass mode.
371 * Set the ClientPD bit and Clear the USFCFG Bit
372 */
373 if (fsl_check_boot_mode_secure() == 1)
374 bypass_smmu();
375#endif
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300376
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000377#if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530378 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A) || \
379 defined(CONFIG_ARCH_LX2162A)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300380 set_icids();
381#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700382}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800383
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530384/* Get VDD in the unit mV from voltage ID */
385int get_core_volt_from_fuse(void)
386{
387 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
388 int vdd;
389 u32 fusesr;
390 u8 vid;
391
392 /* get the voltage ID from fuse status register */
393 fusesr = in_le32(&gur->dcfg_fusesr);
394 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
395 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
396 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
397 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
398 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
399 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
400 }
401 debug("%s: VID = 0x%x\n", __func__, vid);
402 switch (vid) {
403 case 0x00: /* VID isn't supported */
404 vdd = -EINVAL;
405 debug("%s: The VID feature is not supported\n", __func__);
406 break;
407 case 0x08: /* 0.9V silicon */
408 vdd = 900;
409 break;
410 case 0x10: /* 1.0V silicon */
411 vdd = 1000;
412 break;
413 default: /* Other core voltage */
414 vdd = -EINVAL;
415 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
416 break;
417 }
418 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
419
420 return vdd;
421}
422
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530423#elif defined(CONFIG_FSL_LSCH2)
Mingkai Hu172081c2016-02-02 11:28:03 +0800424/*
425 * This erratum requires setting a value to eddrtqcr1 to optimal
426 * the DDR performance. The eddrtqcr1 register is in SCFG space
427 * of LS1043A and the offset is 0x157_020c.
428 */
429#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
430 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
431#error A009660 and A008514 can not be both enabled.
432#endif
433
434static void erratum_a009660(void)
435{
436#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
437 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
438 out_be32(eddrtqcr1, 0x63b20042);
439#endif
440}
441
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800442static void erratum_a008850_early(void)
443{
444#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
445 /* part 1 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
York Sune6b871e2017-05-15 08:51:59 -0700450 /* Skip if running at lower exception level */
451 if (current_el() < 3)
452 return;
453
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800454 /* disables propagation of barrier transactions to DDRC from CCI400 */
455 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
456
457 /* disable the re-ordering in DDRC */
458 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
459#endif
460}
461
462void erratum_a008850_post(void)
463{
464#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
465 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530466 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
467 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800468 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
469 u32 tmp;
470
York Sune6b871e2017-05-15 08:51:59 -0700471 /* Skip if running at lower exception level */
472 if (current_el() < 3)
473 return;
474
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800475 /* enable propagation of barrier transactions to DDRC from CCI400 */
476 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
477
478 /* enable the re-ordering in DDRC */
479 tmp = ddr_in32(&ddr->eor);
480 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
481 ddr_out32(&ddr->eor, tmp);
482#endif
483}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800484
485#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
486void erratum_a010315(void)
487{
488 int i;
489
490 for (i = PCIE1; i <= PCIE4; i++)
491 if (!is_serdes_configured(i)) {
492 debug("PCIe%d: disabled all R/W permission!\n", i);
493 set_pcie_ns_access(i, 0);
494 }
495}
496#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800497
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800498static void erratum_a010539(void)
499{
500#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
501 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
502 u32 porsr1;
503
504 porsr1 = in_be32(&gur->porsr1);
505 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
506 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
507 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800508 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800509#endif
510}
511
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800512/* Get VDD in the unit mV from voltage ID */
513int get_core_volt_from_fuse(void)
514{
515 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
516 int vdd;
517 u32 fusesr;
518 u8 vid;
519
520 fusesr = in_be32(&gur->dcfg_fusesr);
521 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
522 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
523 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
524 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
525 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
526 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
527 }
528 debug("%s: VID = 0x%x\n", __func__, vid);
529 switch (vid) {
530 case 0x00: /* VID isn't supported */
531 vdd = -EINVAL;
532 debug("%s: The VID feature is not supported\n", __func__);
533 break;
534 case 0x08: /* 0.9V silicon */
535 vdd = 900;
536 break;
537 case 0x10: /* 1.0V silicon */
538 vdd = 1000;
539 break;
540 default: /* Other core voltage */
541 vdd = -EINVAL;
542 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
543 break;
544 }
545 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
546
547 return vdd;
548}
549
550__weak int board_switch_core_volt(u32 vdd)
551{
552 return 0;
553}
554
555static int setup_core_volt(u32 vdd)
556{
557 return board_setup_core_volt(vdd);
558}
559
560#ifdef CONFIG_SYS_FSL_DDR
561static void ddr_enable_0v9_volt(bool en)
562{
563 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
564 u32 tmp;
565
566 tmp = ddr_in32(&ddr->ddr_cdr1);
567
568 if (en)
569 tmp |= DDR_CDR1_V0PT9_EN;
570 else
571 tmp &= ~DDR_CDR1_V0PT9_EN;
572
573 ddr_out32(&ddr->ddr_cdr1, tmp);
574}
575#endif
576
577int setup_chip_volt(void)
578{
579 int vdd;
580
581 vdd = get_core_volt_from_fuse();
582 /* Nothing to do for silicons doesn't support VID */
583 if (vdd < 0)
584 return vdd;
585
586 if (setup_core_volt(vdd))
587 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
588#ifdef CONFIG_SYS_HAS_SERDES
589 if (setup_serdes_volt(vdd))
590 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
591#endif
592
593#ifdef CONFIG_SYS_FSL_DDR
594 if (vdd == 900)
595 ddr_enable_0v9_volt(true);
596#endif
597
598 return 0;
599}
600
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530601#ifdef CONFIG_FSL_PFE
602void init_pfe_scfg_dcfg_regs(void)
603{
604 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
605 u32 ecccr2;
606
607 out_be32(&scfg->pfeasbcr,
608 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
609 out_be32(&scfg->pfebsbcr,
610 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
611
612 /* CCI-400 QoS settings for PFE */
613 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
614 | SCFG_WR_QOS1_PFE2_QOS));
615 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
616 | SCFG_RD_QOS1_PFE2_QOS));
617
618 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
619 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
620 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
621}
622#endif
623
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800624void fsl_lsch2_early_init_f(void)
625{
Ashish Kumar11234062017-08-11 11:09:14 +0530626 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
627 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530628 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000629#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
630 enum boot_src src;
631#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800632
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800633#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
634 enable_layerscape_ns_access();
635#endif
636
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800637#ifdef CONFIG_FSL_IFC
638 init_early_memctl_regs(); /* tighten IFC timing */
639#endif
640
Pankit Garg41bde722019-05-29 12:12:36 +0000641#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
642 src = get_boot_src();
643 if (src != BOOT_SOURCE_QSPI_NOR)
644 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
645#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800646#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800647 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
648#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000649#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530650 /* Make SEC reads and writes snoopable */
Ran Wangc75026e2019-09-20 17:34:29 +0800651#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
652 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
653 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
654 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
655 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
656 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
657 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wanga7576692019-12-26 18:11:17 +0800658#elif defined(CONFIG_ARCH_LS1012A)
659 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
660 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
661 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
662 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800663#else
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530664 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800665 SCFG_SNPCNFGCR_SECWRSNP |
666 SCFG_SNPCNFGCR_SATARDSNP |
667 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800668#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530669
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800670 /*
671 * Enable snoop requests and DVM message requests for
672 * Slave insterface S4 (A53 core cluster)
673 */
York Sune6b871e2017-05-15 08:51:59 -0700674 if (current_el() == 3) {
675 out_le32(&cci->slave[4].snoop_ctrl,
676 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
677 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800678
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800679 /*
680 * Program Central Security Unit (CSU) to grant access
681 * permission for USB 2.0 controller
682 */
683#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
684 if (current_el() == 3)
685 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
686#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800687 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800688 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu172081c2016-02-02 11:28:03 +0800689 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800690 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800691 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800692 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800693 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800694 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300695
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300696#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300697 set_icids();
698#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800699}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800700#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700701
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530702#ifdef CONFIG_FSPI_AHB_EN_4BYTE
703int fspi_ahb_init(void)
704{
705 /* Enable 4bytes address support and fast read */
706 u32 *fspi_lut, lut_key, *fspi_key;
707
708 fspi_key = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUTKEY_BASE_ADDR;
709 fspi_lut = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUT_BASE_ADDR;
710
711 lut_key = in_be32(fspi_key);
712
713 if (lut_key == SYS_NXP_FSPI_LUTKEY) {
714 /* That means the register is BE */
715 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
716 /* Unlock the lut table */
717 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
718 /* Create READ LUT */
719 out_be32(fspi_lut, 0x0820040c);
720 out_be32(fspi_lut + 1, 0x24003008);
721 out_be32(fspi_lut + 2, 0x00000000);
722 /* Lock the lut table */
723 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
724 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
725 } else {
726 /* That means the register is LE */
727 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
728 /* Unlock the lut table */
729 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
730 /* Create READ LUT */
731 out_le32(fspi_lut, 0x0820040c);
732 out_le32(fspi_lut + 1, 0x24003008);
733 out_le32(fspi_lut + 2, 0x00000000);
734 /* Lock the lut table */
735 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
736 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
737 }
738
739 return 0;
740}
741#endif
742
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800743#ifdef CONFIG_QSPI_AHB_INIT
744/* Enable 4bytes address support and fast read */
745int qspi_ahb_init(void)
746{
747 u32 *qspi_lut, lut_key, *qspi_key;
748
749 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
750 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
751
752 lut_key = in_be32(qspi_key);
753
754 if (lut_key == 0x5af05af0) {
755 /* That means the register is BE */
756 out_be32(qspi_key, 0x5af05af0);
757 /* Unlock the lut table */
758 out_be32(qspi_key + 1, 0x00000002);
759 out_be32(qspi_lut, 0x0820040c);
760 out_be32(qspi_lut + 1, 0x1c080c08);
761 out_be32(qspi_lut + 2, 0x00002400);
762 /* Lock the lut table */
763 out_be32(qspi_key, 0x5af05af0);
764 out_be32(qspi_key + 1, 0x00000001);
765 } else {
766 /* That means the register is LE */
767 out_le32(qspi_key, 0x5af05af0);
768 /* Unlock the lut table */
769 out_le32(qspi_key + 1, 0x00000002);
770 out_le32(qspi_lut, 0x0820040c);
771 out_le32(qspi_lut + 1, 0x1c080c08);
772 out_le32(qspi_lut + 2, 0x00002400);
773 /* Lock the lut table */
774 out_le32(qspi_key, 0x5af05af0);
775 out_le32(qspi_key + 1, 0x00000001);
776 }
777
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000778 return 0;
779}
780#endif
781
782#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000783#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000784
785int fsl_setenv_bootcmd(void)
786{
787 int ret;
788 enum boot_src src = get_boot_src();
789 char bootcmd_str[MAX_BOOTCMD_SIZE];
790
791 switch (src) {
792#ifdef IFC_NOR_BOOTCOMMAND
793 case BOOT_SOURCE_IFC_NOR:
794 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
795 break;
796#endif
797#ifdef QSPI_NOR_BOOTCOMMAND
798 case BOOT_SOURCE_QSPI_NOR:
799 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
800 break;
801#endif
802#ifdef XSPI_NOR_BOOTCOMMAND
803 case BOOT_SOURCE_XSPI_NOR:
804 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
805 break;
806#endif
807#ifdef IFC_NAND_BOOTCOMMAND
808 case BOOT_SOURCE_IFC_NAND:
809 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
810 break;
811#endif
812#ifdef QSPI_NAND_BOOTCOMMAND
813 case BOOT_SOURCE_QSPI_NAND:
814 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
815 break;
816#endif
817#ifdef XSPI_NAND_BOOTCOMMAND
818 case BOOT_SOURCE_XSPI_NAND:
819 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
820 break;
821#endif
822#ifdef SD_BOOTCOMMAND
823 case BOOT_SOURCE_SD_MMC:
824 sprintf(bootcmd_str, SD_BOOTCOMMAND);
825 break;
826#endif
827#ifdef SD2_BOOTCOMMAND
828 case BOOT_SOURCE_SD_MMC2:
829 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
830 break;
831#endif
832 default:
833#ifdef QSPI_NOR_BOOTCOMMAND
834 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
835#endif
836 break;
837 }
838
839 ret = env_set("bootcmd", bootcmd_str);
840 if (ret) {
841 printf("Failed to set bootcmd: ret = %d\n", ret);
842 return ret;
843 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800844 return 0;
845}
Pankit Garg82fcc462018-11-05 18:02:31 +0000846
847int fsl_setenv_mcinitcmd(void)
848{
849 int ret = 0;
850 enum boot_src src = get_boot_src();
851
852 switch (src) {
853#ifdef IFC_MC_INIT_CMD
854 case BOOT_SOURCE_IFC_NAND:
855 case BOOT_SOURCE_IFC_NOR:
856 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
857 break;
858#endif
859#ifdef QSPI_MC_INIT_CMD
860 case BOOT_SOURCE_QSPI_NAND:
861 case BOOT_SOURCE_QSPI_NOR:
862 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
863 break;
864#endif
865#ifdef XSPI_MC_INIT_CMD
866 case BOOT_SOURCE_XSPI_NAND:
867 case BOOT_SOURCE_XSPI_NOR:
868 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
869 break;
870#endif
871#ifdef SD_MC_INIT_CMD
872 case BOOT_SOURCE_SD_MMC:
873 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
874 break;
875#endif
876#ifdef SD2_MC_INIT_CMD
877 case BOOT_SOURCE_SD_MMC2:
878 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
879 break;
880#endif
881 default:
882#ifdef QSPI_MC_INIT_CMD
883 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
884#endif
885 break;
886 }
887
888 if (ret) {
889 printf("Failed to set mcinitcmd: ret = %d\n", ret);
890 return ret;
891 }
892 return 0;
893}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800894#endif
895
Mingkai Hu0e58b512015-10-26 19:47:50 +0800896#ifdef CONFIG_BOARD_LATE_INIT
Michael Wallefc667ea2019-10-21 22:37:45 +0200897__weak int fsl_board_late_init(void)
898{
899 return 0;
900}
901
Ran Wangba7cd0f2020-08-05 15:07:27 +0800902#define DWC3_GSBUSCFG0 0xc100
903#define DWC3_GSBUSCFG0_CACHETYPE_SHIFT 16
904#define DWC3_GSBUSCFG0_CACHETYPE(n) (((n) & 0xffff) \
905 << DWC3_GSBUSCFG0_CACHETYPE_SHIFT)
906
907void enable_dwc3_snooping(void)
908{
909 int ret;
910 u32 val;
911 struct udevice *bus;
912 struct uclass *uc;
913 fdt_addr_t dwc3_base;
914
915 ret = uclass_get(UCLASS_USB, &uc);
916 if (ret)
917 return;
918
919 uclass_foreach_dev(bus, uc) {
920 if (!strcmp(bus->driver->of_match->compatible, "fsl,layerscape-dwc3")) {
921 dwc3_base = devfdt_get_addr(bus);
922 if (dwc3_base == FDT_ADDR_T_NONE) {
923 dev_err(bus, "dwc3 regs missing\n");
924 continue;
925 }
926 val = in_le32(dwc3_base + DWC3_GSBUSCFG0);
927 val &= ~DWC3_GSBUSCFG0_CACHETYPE(~0);
928 val |= DWC3_GSBUSCFG0_CACHETYPE(0x2222);
929 writel(val, dwc3_base + DWC3_GSBUSCFG0);
930 }
931 }
932}
933
Mingkai Hu0e58b512015-10-26 19:47:50 +0800934int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700935{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530936#ifdef CONFIG_CHAIN_OF_TRUST
937 fsl_setenv_chain_of_trust();
938#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000939#ifdef CONFIG_TFABOOT
940 /*
Wasim Khan5f745142021-08-02 10:34:52 +0200941 * Set bootcmd and mcinitcmd if "fsl_bootcmd_mcinitcmd_set" does
942 * not exists in env
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000943 */
Wasim Khan5f745142021-08-02 10:34:52 +0200944 if (env_get_yesno("fsl_bootcmd_mcinitcmd_set") <= 0) {
945 // Set bootcmd and mcinitcmd as per boot source
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000946 fsl_setenv_bootcmd();
947 fsl_setenv_mcinitcmd();
Wasim Khan5f745142021-08-02 10:34:52 +0200948 env_set("fsl_bootcmd_mcinitcmd_set", "y");
949 }
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000950#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800951#ifdef CONFIG_QSPI_AHB_INIT
952 qspi_ahb_init();
953#endif
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530954#ifdef CONFIG_FSPI_AHB_EN_4BYTE
955 fspi_ahb_init();
956#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800957
Ran Wangba7cd0f2020-08-05 15:07:27 +0800958 if (IS_ENABLED(CONFIG_DM))
959 enable_dwc3_snooping();
960
Michael Wallefc667ea2019-10-21 22:37:45 +0200961 return fsl_board_late_init();
Scott Wood8e728cd2015-03-24 13:25:02 -0700962}
963#endif