blob: ad209bde334c4c9692ea48b30ee5a4ab48cefab7 [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
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +05304 * Copyright 2019-2020 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>
Pankit Gargbdbf84f2018-11-05 18:01:52 +000036#ifdef CONFIG_TFABOOT
Simon Glass9d1f6192019-08-02 09:44:25 -060037#include <env_internal.h>
Hou Zhiqiang031bb872020-04-28 10:19:32 +080038#endif
Ran Wangba7cd0f2020-08-05 15:07:27 +080039#include <dm.h>
Tom Rinifb6abdd2020-10-15 21:44:15 -040040#include <dm/device_compat.h>
Ran Wangba7cd0f2020-08-05 15:07:27 +080041#include <linux/err.h>
Hou Zhiqiang031bb872020-04-28 10:19:32 +080042#if defined(CONFIG_TFABOOT) || defined(CONFIG_GIC_V3_ITS)
Pankit Gargbdbf84f2018-11-05 18:01:52 +000043DECLARE_GLOBAL_DATA_PTR;
44#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070045
Hou Zhiqiang031bb872020-04-28 10:19:32 +080046#ifdef CONFIG_GIC_V3_ITS
Hou Zhiqiang031bb872020-04-28 10:19:32 +080047int ls_gic_rd_tables_init(void *blob)
48{
Hou Zhiqiang14fa6b72020-08-06 14:38:19 +080049 struct fdt_memory lpi_base;
50 fdt_addr_t addr;
51 fdt_size_t size;
52 int offset, ret;
53
54 offset = fdt_path_offset(gd->fdt_blob, "/syscon@0x80000000");
55 addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, offset, "reg",
56 0, &size, false);
57
58 lpi_base.start = addr;
59 lpi_base.end = addr + size - 1;
Tom Rini38ae92e2020-10-05 13:05:46 -040060 ret = fdtdec_add_reserved_memory(blob, "lpi_rd_table", &lpi_base, NULL, false);
Hou Zhiqiang14fa6b72020-08-06 14:38:19 +080061 if (ret) {
62 debug("%s: failed to add reserved memory\n", __func__);
63 return ret;
64 }
Hou Zhiqiang031bb872020-04-28 10:19:32 +080065
Rayagonda Kokatanur158c16e2020-07-26 22:37:33 +053066 ret = gic_lpi_tables_init();
Hou Zhiqiang031bb872020-04-28 10:19:32 +080067 if (ret)
68 debug("%s: failed to init gic-lpi-tables\n", __func__);
69
70 return ret;
71}
72#endif
73
York Suncbe8e1c2016-04-04 11:41:26 -070074bool soc_has_dp_ddr(void)
75{
76 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
77 u32 svr = gur_in32(&gur->svr);
78
Priyanka Jain4a6f1732016-11-17 12:29:55 +053079 /* LS2085A, LS2088A, LS2048A has DP_DDR */
80 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
81 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
82 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070083 return true;
84
85 return false;
86}
87
88bool soc_has_aiop(void)
89{
90 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
91 u32 svr = gur_in32(&gur->svr);
92
93 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053094 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070095 return true;
96
97 return false;
98}
99
Ran Wangb358b7b2017-09-04 18:46:48 +0800100static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
101{
102 scfg_clrsetbits32(scfg + offset / 4,
103 0xF << 6,
104 SCFG_USB_TXVREFTUNE << 6);
105}
106
107static void erratum_a009008(void)
108{
109#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
110 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +0800111
Ran Wang02dc77b2017-11-13 16:14:48 +0800112#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
113 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +0800114 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800115#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +0800116 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
117 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800118#endif
Ran Wangb358b7b2017-09-04 18:46:48 +0800119#elif defined(CONFIG_ARCH_LS2080A)
120 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
121#endif
122#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
123}
124
Ran Wang9e8fabc2017-09-04 18:46:49 +0800125static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
126{
127 scfg_clrbits32(scfg + offset / 4,
128 SCFG_USB_SQRXTUNE_MASK << 23);
129}
130
131static void erratum_a009798(void)
132{
133#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
134 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
135
Ran Wang02dc77b2017-11-13 16:14:48 +0800136#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
137 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800138 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800139#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800140 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
141 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800142#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800143#elif defined(CONFIG_ARCH_LS2080A)
144 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
145#endif
146#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
147}
148
Ran Wang02dc77b2017-11-13 16:14:48 +0800149#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
150 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800151static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
152{
153 scfg_clrsetbits32(scfg + offset / 4,
154 0x7F << 9,
155 SCFG_USB_PCSTXSWINGFULL << 9);
156}
157#endif
158
159static void erratum_a008997(void)
160{
161#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800162#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
163 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800164 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
165
166 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800167#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800168 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
169 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
170#endif
Ran Wange118acb2019-05-14 17:34:56 +0800171#elif defined(CONFIG_ARCH_LS1028A)
172 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
173 0x7F << 11,
174 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800175#endif
Ran Wange64f7472017-09-04 18:46:50 +0800176#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
177}
178
Ran Wang02dc77b2017-11-13 16:14:48 +0800179#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
180 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800181
182#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
183 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
184 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
185 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
186 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
187
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800188#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530189 defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A) || \
190 defined(CONFIG_ARCH_LX2162A)
Ran Wang3ba69482017-09-04 18:46:51 +0800191
192#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
193 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
194 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
195 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
196 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
197
198#endif
199
200static void erratum_a009007(void)
201{
Ran Wang02dc77b2017-11-13 16:14:48 +0800202#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
203 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800204 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
205
206 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800207#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800208 usb_phy = (void __iomem *)SCFG_USB_PHY2;
209 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
210
211 usb_phy = (void __iomem *)SCFG_USB_PHY3;
212 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800213#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800214#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
215 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800216 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
217
218 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
219 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
220#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
221}
222
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800223#if defined(CONFIG_FSL_LSCH3)
Ran Wangd0270dc2019-11-26 11:40:40 +0800224static void erratum_a050106(void)
225{
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530226#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Ran Wangd0270dc2019-11-26 11:40:40 +0800227 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
228
229 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
230 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
231#endif
232}
Yao Yuanfae88052015-12-05 14:59:14 +0800233/*
234 * This erratum requires setting a value to eddrtqcr1 to
235 * optimal the DDR performance.
236 */
237static void erratum_a008336(void)
238{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800239#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800240 u32 *eddrtqcr1;
241
Yao Yuanfae88052015-12-05 14:59:14 +0800242#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
243 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800244 if (fsl_ddr_get_version(0) == 0x50200)
245 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800246#endif
247#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
248 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800249 if (fsl_ddr_get_version(0) == 0x50200)
250 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800251#endif
252#endif
253}
254
255/*
256 * This erratum requires a register write before being Memory
257 * controller 3 being enabled.
258 */
259static void erratum_a008514(void)
260{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800261#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800262 u32 *eddrtqcr1;
263
Yao Yuanfae88052015-12-05 14:59:14 +0800264#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
265 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
266 out_le32(eddrtqcr1, 0x63b20002);
267#endif
268#endif
269}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530270#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
271#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
272
273static unsigned long get_internval_val_mhz(void)
274{
Simon Glass64b723f2017-08-03 12:22:12 -0600275 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530276 /*
277 * interval is the number of platform cycles(MHz) between
278 * wake up events generated by EPU.
279 */
280 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
281
282 if (interval)
283 interval_mhz = simple_strtoul(interval, NULL, 10);
284
285 return interval_mhz;
286}
287
288void erratum_a009635(void)
289{
290 u32 val;
291 unsigned long interval_mhz = get_internval_val_mhz();
292
293 if (!interval_mhz)
294 return;
295
296 val = in_le32(DCSR_CGACRE5);
297 writel(val | 0x00000200, DCSR_CGACRE5);
298
299 val = in_le32(EPU_EPCMPR5);
300 writel(interval_mhz, EPU_EPCMPR5);
301 val = in_le32(EPU_EPCCR5);
302 writel(val | 0x82820000, EPU_EPCCR5);
303 val = in_le32(EPU_EPSMCR5);
304 writel(val | 0x002f0000, EPU_EPSMCR5);
305 val = in_le32(EPU_EPECR5);
306 writel(val | 0x20000000, EPU_EPECR5);
307 val = in_le32(EPU_EPGCR);
308 writel(val | 0x80000000, EPU_EPGCR);
309}
310#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
311
Scott Wood8e728cd2015-03-24 13:25:02 -0700312static void erratum_rcw_src(void)
313{
Santan Kumar99136482017-05-05 15:42:28 +0530314#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700315 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
316 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
317 u32 val;
318
319 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
320 val &= ~DCFG_PORSR1_RCW_SRC;
321 val |= DCFG_PORSR1_RCW_SRC_NOR;
322 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
323#endif
324}
325
York Sun0404a392015-03-23 10:41:35 -0700326#define I2C_DEBUG_REG 0x6
327#define I2C_GLITCH_EN 0x8
328/*
329 * This erratum requires setting glitch_en bit to enable
330 * digital glitch filter to improve clock stability.
331 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530332#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700333static void erratum_a009203(void)
334{
York Sun0404a392015-03-23 10:41:35 -0700335#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530336 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700337#ifdef I2C1_BASE_ADDR
338 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
339
340 writeb(I2C_GLITCH_EN, ptr);
341#endif
342#ifdef I2C2_BASE_ADDR
343 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
344
345 writeb(I2C_GLITCH_EN, ptr);
346#endif
347#ifdef I2C3_BASE_ADDR
348 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
349
350 writeb(I2C_GLITCH_EN, ptr);
351#endif
352#ifdef I2C4_BASE_ADDR
353 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
354
355 writeb(I2C_GLITCH_EN, ptr);
356#endif
357#endif
358}
Ashish kumar3b52a232017-02-23 16:03:57 +0530359#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800360
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530361void bypass_smmu(void)
362{
363 u32 val;
364 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
365 out_le32(SMMU_SCR0, val);
366 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
367 out_le32(SMMU_NSCR0, val);
368}
Scott Woodf64c98c2015-03-20 19:28:12 -0700369void fsl_lsch3_early_init_f(void)
370{
Scott Wood8e728cd2015-03-24 13:25:02 -0700371 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530372#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700373 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530374#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530375#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700376 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530377#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800378 erratum_a008514();
379 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800380 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800381 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800382 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800383 erratum_a009007();
Ran Wangd0270dc2019-11-26 11:40:40 +0800384 erratum_a050106();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530385#ifdef CONFIG_CHAIN_OF_TRUST
386 /* In case of Secure Boot, the IBR configures the SMMU
387 * to allow only Secure transactions.
388 * SMMU must be reset in bypass mode.
389 * Set the ClientPD bit and Clear the USFCFG Bit
390 */
391 if (fsl_check_boot_mode_secure() == 1)
392 bypass_smmu();
393#endif
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300394
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000395#if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530396 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A) || \
397 defined(CONFIG_ARCH_LX2162A)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300398 set_icids();
399#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700400}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800401
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530402/* Get VDD in the unit mV from voltage ID */
403int get_core_volt_from_fuse(void)
404{
405 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
406 int vdd;
407 u32 fusesr;
408 u8 vid;
409
410 /* get the voltage ID from fuse status register */
411 fusesr = in_le32(&gur->dcfg_fusesr);
412 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
413 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
414 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
415 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
416 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
417 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
418 }
419 debug("%s: VID = 0x%x\n", __func__, vid);
420 switch (vid) {
421 case 0x00: /* VID isn't supported */
422 vdd = -EINVAL;
423 debug("%s: The VID feature is not supported\n", __func__);
424 break;
425 case 0x08: /* 0.9V silicon */
426 vdd = 900;
427 break;
428 case 0x10: /* 1.0V silicon */
429 vdd = 1000;
430 break;
431 default: /* Other core voltage */
432 vdd = -EINVAL;
433 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
434 break;
435 }
436 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
437
438 return vdd;
439}
440
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530441#elif defined(CONFIG_FSL_LSCH2)
Mingkai Hu172081c2016-02-02 11:28:03 +0800442/*
443 * This erratum requires setting a value to eddrtqcr1 to optimal
444 * the DDR performance. The eddrtqcr1 register is in SCFG space
445 * of LS1043A and the offset is 0x157_020c.
446 */
447#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
448 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
449#error A009660 and A008514 can not be both enabled.
450#endif
451
452static void erratum_a009660(void)
453{
454#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
455 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
456 out_be32(eddrtqcr1, 0x63b20042);
457#endif
458}
459
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800460static void erratum_a008850_early(void)
461{
462#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
463 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530464 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
465 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800466 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
467
York Sune6b871e2017-05-15 08:51:59 -0700468 /* Skip if running at lower exception level */
469 if (current_el() < 3)
470 return;
471
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800472 /* disables propagation of barrier transactions to DDRC from CCI400 */
473 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
474
475 /* disable the re-ordering in DDRC */
476 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
477#endif
478}
479
480void erratum_a008850_post(void)
481{
482#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
483 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530484 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
485 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800486 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
487 u32 tmp;
488
York Sune6b871e2017-05-15 08:51:59 -0700489 /* Skip if running at lower exception level */
490 if (current_el() < 3)
491 return;
492
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800493 /* enable propagation of barrier transactions to DDRC from CCI400 */
494 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
495
496 /* enable the re-ordering in DDRC */
497 tmp = ddr_in32(&ddr->eor);
498 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
499 ddr_out32(&ddr->eor, tmp);
500#endif
501}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800502
503#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
504void erratum_a010315(void)
505{
506 int i;
507
508 for (i = PCIE1; i <= PCIE4; i++)
509 if (!is_serdes_configured(i)) {
510 debug("PCIe%d: disabled all R/W permission!\n", i);
511 set_pcie_ns_access(i, 0);
512 }
513}
514#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800515
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800516static void erratum_a010539(void)
517{
518#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
519 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
520 u32 porsr1;
521
522 porsr1 = in_be32(&gur->porsr1);
523 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
524 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
525 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800526 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800527#endif
528}
529
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800530/* Get VDD in the unit mV from voltage ID */
531int get_core_volt_from_fuse(void)
532{
533 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
534 int vdd;
535 u32 fusesr;
536 u8 vid;
537
538 fusesr = in_be32(&gur->dcfg_fusesr);
539 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
540 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
541 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
542 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
543 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
544 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
545 }
546 debug("%s: VID = 0x%x\n", __func__, vid);
547 switch (vid) {
548 case 0x00: /* VID isn't supported */
549 vdd = -EINVAL;
550 debug("%s: The VID feature is not supported\n", __func__);
551 break;
552 case 0x08: /* 0.9V silicon */
553 vdd = 900;
554 break;
555 case 0x10: /* 1.0V silicon */
556 vdd = 1000;
557 break;
558 default: /* Other core voltage */
559 vdd = -EINVAL;
560 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
561 break;
562 }
563 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
564
565 return vdd;
566}
567
568__weak int board_switch_core_volt(u32 vdd)
569{
570 return 0;
571}
572
573static int setup_core_volt(u32 vdd)
574{
575 return board_setup_core_volt(vdd);
576}
577
578#ifdef CONFIG_SYS_FSL_DDR
579static void ddr_enable_0v9_volt(bool en)
580{
581 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
582 u32 tmp;
583
584 tmp = ddr_in32(&ddr->ddr_cdr1);
585
586 if (en)
587 tmp |= DDR_CDR1_V0PT9_EN;
588 else
589 tmp &= ~DDR_CDR1_V0PT9_EN;
590
591 ddr_out32(&ddr->ddr_cdr1, tmp);
592}
593#endif
594
595int setup_chip_volt(void)
596{
597 int vdd;
598
599 vdd = get_core_volt_from_fuse();
600 /* Nothing to do for silicons doesn't support VID */
601 if (vdd < 0)
602 return vdd;
603
604 if (setup_core_volt(vdd))
605 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
606#ifdef CONFIG_SYS_HAS_SERDES
607 if (setup_serdes_volt(vdd))
608 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
609#endif
610
611#ifdef CONFIG_SYS_FSL_DDR
612 if (vdd == 900)
613 ddr_enable_0v9_volt(true);
614#endif
615
616 return 0;
617}
618
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530619#ifdef CONFIG_FSL_PFE
620void init_pfe_scfg_dcfg_regs(void)
621{
622 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
623 u32 ecccr2;
624
625 out_be32(&scfg->pfeasbcr,
626 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
627 out_be32(&scfg->pfebsbcr,
628 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
629
630 /* CCI-400 QoS settings for PFE */
631 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
632 | SCFG_WR_QOS1_PFE2_QOS));
633 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
634 | SCFG_RD_QOS1_PFE2_QOS));
635
636 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
637 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
638 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
639}
640#endif
641
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800642void fsl_lsch2_early_init_f(void)
643{
Ashish Kumar11234062017-08-11 11:09:14 +0530644 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
645 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530646 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000647#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
648 enum boot_src src;
649#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800650
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800651#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
652 enable_layerscape_ns_access();
653#endif
654
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800655#ifdef CONFIG_FSL_IFC
656 init_early_memctl_regs(); /* tighten IFC timing */
657#endif
658
Pankit Garg41bde722019-05-29 12:12:36 +0000659#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
660 src = get_boot_src();
661 if (src != BOOT_SOURCE_QSPI_NOR)
662 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
663#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800664#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800665 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
666#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000667#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530668 /* Make SEC reads and writes snoopable */
Ran Wangc75026e2019-09-20 17:34:29 +0800669#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
670 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
671 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
672 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
673 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
674 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
675 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wanga7576692019-12-26 18:11:17 +0800676#elif defined(CONFIG_ARCH_LS1012A)
677 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
678 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
679 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
680 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800681#else
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530682 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800683 SCFG_SNPCNFGCR_SECWRSNP |
684 SCFG_SNPCNFGCR_SATARDSNP |
685 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800686#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530687
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800688 /*
689 * Enable snoop requests and DVM message requests for
690 * Slave insterface S4 (A53 core cluster)
691 */
York Sune6b871e2017-05-15 08:51:59 -0700692 if (current_el() == 3) {
693 out_le32(&cci->slave[4].snoop_ctrl,
694 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
695 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800696
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800697 /*
698 * Program Central Security Unit (CSU) to grant access
699 * permission for USB 2.0 controller
700 */
701#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
702 if (current_el() == 3)
703 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
704#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800705 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800706 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu172081c2016-02-02 11:28:03 +0800707 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800708 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800709 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800710 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800711 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800712 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300713
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300714#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300715 set_icids();
716#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800717}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800718#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700719
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530720#ifdef CONFIG_FSPI_AHB_EN_4BYTE
721int fspi_ahb_init(void)
722{
723 /* Enable 4bytes address support and fast read */
724 u32 *fspi_lut, lut_key, *fspi_key;
725
726 fspi_key = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUTKEY_BASE_ADDR;
727 fspi_lut = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUT_BASE_ADDR;
728
729 lut_key = in_be32(fspi_key);
730
731 if (lut_key == SYS_NXP_FSPI_LUTKEY) {
732 /* That means the register is BE */
733 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
734 /* Unlock the lut table */
735 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
736 /* Create READ LUT */
737 out_be32(fspi_lut, 0x0820040c);
738 out_be32(fspi_lut + 1, 0x24003008);
739 out_be32(fspi_lut + 2, 0x00000000);
740 /* Lock the lut table */
741 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
742 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
743 } else {
744 /* That means the register is LE */
745 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
746 /* Unlock the lut table */
747 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
748 /* Create READ LUT */
749 out_le32(fspi_lut, 0x0820040c);
750 out_le32(fspi_lut + 1, 0x24003008);
751 out_le32(fspi_lut + 2, 0x00000000);
752 /* Lock the lut table */
753 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
754 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
755 }
756
757 return 0;
758}
759#endif
760
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800761#ifdef CONFIG_QSPI_AHB_INIT
762/* Enable 4bytes address support and fast read */
763int qspi_ahb_init(void)
764{
765 u32 *qspi_lut, lut_key, *qspi_key;
766
767 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
768 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
769
770 lut_key = in_be32(qspi_key);
771
772 if (lut_key == 0x5af05af0) {
773 /* That means the register is BE */
774 out_be32(qspi_key, 0x5af05af0);
775 /* Unlock the lut table */
776 out_be32(qspi_key + 1, 0x00000002);
777 out_be32(qspi_lut, 0x0820040c);
778 out_be32(qspi_lut + 1, 0x1c080c08);
779 out_be32(qspi_lut + 2, 0x00002400);
780 /* Lock the lut table */
781 out_be32(qspi_key, 0x5af05af0);
782 out_be32(qspi_key + 1, 0x00000001);
783 } else {
784 /* That means the register is LE */
785 out_le32(qspi_key, 0x5af05af0);
786 /* Unlock the lut table */
787 out_le32(qspi_key + 1, 0x00000002);
788 out_le32(qspi_lut, 0x0820040c);
789 out_le32(qspi_lut + 1, 0x1c080c08);
790 out_le32(qspi_lut + 2, 0x00002400);
791 /* Lock the lut table */
792 out_le32(qspi_key, 0x5af05af0);
793 out_le32(qspi_key + 1, 0x00000001);
794 }
795
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000796 return 0;
797}
798#endif
799
800#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000801#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000802
803int fsl_setenv_bootcmd(void)
804{
805 int ret;
806 enum boot_src src = get_boot_src();
807 char bootcmd_str[MAX_BOOTCMD_SIZE];
808
809 switch (src) {
810#ifdef IFC_NOR_BOOTCOMMAND
811 case BOOT_SOURCE_IFC_NOR:
812 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
813 break;
814#endif
815#ifdef QSPI_NOR_BOOTCOMMAND
816 case BOOT_SOURCE_QSPI_NOR:
817 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
818 break;
819#endif
820#ifdef XSPI_NOR_BOOTCOMMAND
821 case BOOT_SOURCE_XSPI_NOR:
822 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
823 break;
824#endif
825#ifdef IFC_NAND_BOOTCOMMAND
826 case BOOT_SOURCE_IFC_NAND:
827 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
828 break;
829#endif
830#ifdef QSPI_NAND_BOOTCOMMAND
831 case BOOT_SOURCE_QSPI_NAND:
832 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
833 break;
834#endif
835#ifdef XSPI_NAND_BOOTCOMMAND
836 case BOOT_SOURCE_XSPI_NAND:
837 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
838 break;
839#endif
840#ifdef SD_BOOTCOMMAND
841 case BOOT_SOURCE_SD_MMC:
842 sprintf(bootcmd_str, SD_BOOTCOMMAND);
843 break;
844#endif
845#ifdef SD2_BOOTCOMMAND
846 case BOOT_SOURCE_SD_MMC2:
847 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
848 break;
849#endif
850 default:
851#ifdef QSPI_NOR_BOOTCOMMAND
852 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
853#endif
854 break;
855 }
856
857 ret = env_set("bootcmd", bootcmd_str);
858 if (ret) {
859 printf("Failed to set bootcmd: ret = %d\n", ret);
860 return ret;
861 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800862 return 0;
863}
Pankit Garg82fcc462018-11-05 18:02:31 +0000864
865int fsl_setenv_mcinitcmd(void)
866{
867 int ret = 0;
868 enum boot_src src = get_boot_src();
869
870 switch (src) {
871#ifdef IFC_MC_INIT_CMD
872 case BOOT_SOURCE_IFC_NAND:
873 case BOOT_SOURCE_IFC_NOR:
874 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
875 break;
876#endif
877#ifdef QSPI_MC_INIT_CMD
878 case BOOT_SOURCE_QSPI_NAND:
879 case BOOT_SOURCE_QSPI_NOR:
880 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
881 break;
882#endif
883#ifdef XSPI_MC_INIT_CMD
884 case BOOT_SOURCE_XSPI_NAND:
885 case BOOT_SOURCE_XSPI_NOR:
886 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
887 break;
888#endif
889#ifdef SD_MC_INIT_CMD
890 case BOOT_SOURCE_SD_MMC:
891 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
892 break;
893#endif
894#ifdef SD2_MC_INIT_CMD
895 case BOOT_SOURCE_SD_MMC2:
896 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
897 break;
898#endif
899 default:
900#ifdef QSPI_MC_INIT_CMD
901 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
902#endif
903 break;
904 }
905
906 if (ret) {
907 printf("Failed to set mcinitcmd: ret = %d\n", ret);
908 return ret;
909 }
910 return 0;
911}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800912#endif
913
Mingkai Hu0e58b512015-10-26 19:47:50 +0800914#ifdef CONFIG_BOARD_LATE_INIT
Michael Wallefc667ea2019-10-21 22:37:45 +0200915__weak int fsl_board_late_init(void)
916{
917 return 0;
918}
919
Ran Wangba7cd0f2020-08-05 15:07:27 +0800920#define DWC3_GSBUSCFG0 0xc100
921#define DWC3_GSBUSCFG0_CACHETYPE_SHIFT 16
922#define DWC3_GSBUSCFG0_CACHETYPE(n) (((n) & 0xffff) \
923 << DWC3_GSBUSCFG0_CACHETYPE_SHIFT)
924
925void enable_dwc3_snooping(void)
926{
927 int ret;
928 u32 val;
929 struct udevice *bus;
930 struct uclass *uc;
931 fdt_addr_t dwc3_base;
932
933 ret = uclass_get(UCLASS_USB, &uc);
934 if (ret)
935 return;
936
937 uclass_foreach_dev(bus, uc) {
938 if (!strcmp(bus->driver->of_match->compatible, "fsl,layerscape-dwc3")) {
939 dwc3_base = devfdt_get_addr(bus);
940 if (dwc3_base == FDT_ADDR_T_NONE) {
941 dev_err(bus, "dwc3 regs missing\n");
942 continue;
943 }
944 val = in_le32(dwc3_base + DWC3_GSBUSCFG0);
945 val &= ~DWC3_GSBUSCFG0_CACHETYPE(~0);
946 val |= DWC3_GSBUSCFG0_CACHETYPE(0x2222);
947 writel(val, dwc3_base + DWC3_GSBUSCFG0);
948 }
949 }
950}
951
Mingkai Hu0e58b512015-10-26 19:47:50 +0800952int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700953{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530954#ifdef CONFIG_CHAIN_OF_TRUST
955 fsl_setenv_chain_of_trust();
956#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000957#ifdef CONFIG_TFABOOT
958 /*
959 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000960 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000961 */
Tom Rini5cd7ece2019-11-18 20:02:10 -0500962#ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
Pankit Gargd6bd6782019-05-30 12:04:15 +0000963 if (gd->env_addr == (ulong)&default_environment[0]) {
964#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000965 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000966#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000967 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000968 fsl_setenv_mcinitcmd();
969 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000970
971 /*
972 * If the boot mode is secure, default environment is not present then
973 * setenv command needs to be run by default
974 */
975#ifdef CONFIG_CHAIN_OF_TRUST
976 if ((fsl_check_boot_mode_secure() == 1)) {
977 fsl_setenv_bootcmd();
978 fsl_setenv_mcinitcmd();
979 }
980#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000981#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800982#ifdef CONFIG_QSPI_AHB_INIT
983 qspi_ahb_init();
984#endif
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530985#ifdef CONFIG_FSPI_AHB_EN_4BYTE
986 fspi_ahb_init();
987#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800988
Ran Wangba7cd0f2020-08-05 15:07:27 +0800989 if (IS_ENABLED(CONFIG_DM))
990 enable_dwc3_snooping();
991
Michael Wallefc667ea2019-10-21 22:37:45 +0200992 return fsl_board_late_init();
Scott Wood8e728cd2015-03-24 13:25:02 -0700993}
994#endif