blob: ad7ea0593506b74b7d28da657d99cff56a61497f [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>
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
39#if defined(CONFIG_TFABOOT) || defined(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
44#define PENDTABLE_MAX_SZ ALIGN(BIT(ITS_MAX_LPI_NRBITS), SZ_64K)
45#define PROPTABLE_MAX_SZ ALIGN(BIT(ITS_MAX_LPI_NRBITS) / 8, SZ_64K)
46#define GIC_LPI_SIZE ALIGN(cpu_numcores() * PENDTABLE_MAX_SZ + \
47 PROPTABLE_MAX_SZ, SZ_1M)
48static int fdt_add_resv_mem_gic_rd_tables(void *blob, u64 base, size_t size)
49{
50 u32 phandle;
51 int err;
52 struct fdt_memory gic_rd_tables;
53
54 gic_rd_tables.start = base;
55 gic_rd_tables.end = base + size - 1;
56 err = fdtdec_add_reserved_memory(blob, "gic-rd-tables", &gic_rd_tables,
57 &phandle);
58 if (err < 0)
59 debug("%s: failed to add reserved memory: %d\n", __func__, err);
60
61 return err;
62}
63
64int ls_gic_rd_tables_init(void *blob)
65{
66 u64 gic_lpi_base;
67 int ret;
68
69 gic_lpi_base = ALIGN(gd->arch.resv_ram - GIC_LPI_SIZE, SZ_64K);
70 ret = fdt_add_resv_mem_gic_rd_tables(blob, gic_lpi_base, GIC_LPI_SIZE);
71 if (ret)
72 return ret;
73
74 ret = gic_lpi_tables_init(gic_lpi_base, cpu_numcores());
75 if (ret)
76 debug("%s: failed to init gic-lpi-tables\n", __func__);
77
78 return ret;
79}
80#endif
81
York Suncbe8e1c2016-04-04 11:41:26 -070082bool soc_has_dp_ddr(void)
83{
84 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
85 u32 svr = gur_in32(&gur->svr);
86
Priyanka Jain4a6f1732016-11-17 12:29:55 +053087 /* LS2085A, LS2088A, LS2048A has DP_DDR */
88 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
89 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
90 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070091 return true;
92
93 return false;
94}
95
96bool soc_has_aiop(void)
97{
98 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
99 u32 svr = gur_in32(&gur->svr);
100
101 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +0530102 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -0700103 return true;
104
105 return false;
106}
107
Ran Wangb358b7b2017-09-04 18:46:48 +0800108static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
109{
110 scfg_clrsetbits32(scfg + offset / 4,
111 0xF << 6,
112 SCFG_USB_TXVREFTUNE << 6);
113}
114
115static void erratum_a009008(void)
116{
117#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
118 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +0800119
Ran Wang02dc77b2017-11-13 16:14:48 +0800120#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
121 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +0800122 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800123#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +0800124 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
125 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800126#endif
Ran Wangb358b7b2017-09-04 18:46:48 +0800127#elif defined(CONFIG_ARCH_LS2080A)
128 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
129#endif
130#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
131}
132
Ran Wang9e8fabc2017-09-04 18:46:49 +0800133static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
134{
135 scfg_clrbits32(scfg + offset / 4,
136 SCFG_USB_SQRXTUNE_MASK << 23);
137}
138
139static void erratum_a009798(void)
140{
141#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
142 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
143
Ran Wang02dc77b2017-11-13 16:14:48 +0800144#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
145 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800146 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800147#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +0800148 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
149 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +0800150#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800151#elif defined(CONFIG_ARCH_LS2080A)
152 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
153#endif
154#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
155}
156
Ran Wang02dc77b2017-11-13 16:14:48 +0800157#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
158 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800159static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
160{
161 scfg_clrsetbits32(scfg + offset / 4,
162 0x7F << 9,
163 SCFG_USB_PCSTXSWINGFULL << 9);
164}
165#endif
166
167static void erratum_a008997(void)
168{
169#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800170#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
171 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800172 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
173
174 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800175#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800176 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
177 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
178#endif
Ran Wange118acb2019-05-14 17:34:56 +0800179#elif defined(CONFIG_ARCH_LS1028A)
180 clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1,
181 0x7F << 11,
182 DCSR_USB_PCSTXSWINGFULL << 11);
Ran Wang02dc77b2017-11-13 16:14:48 +0800183#endif
Ran Wange64f7472017-09-04 18:46:50 +0800184#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
185}
186
Ran Wang02dc77b2017-11-13 16:14:48 +0800187#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
188 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800189
190#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
191 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
192 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
193 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
194 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
195
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800196#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
Ran Wangd0270dc2019-11-26 11:40:40 +0800197 defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A)
Ran Wang3ba69482017-09-04 18:46:51 +0800198
199#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
200 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
201 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
202 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
203 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
204
205#endif
206
207static void erratum_a009007(void)
208{
Ran Wang02dc77b2017-11-13 16:14:48 +0800209#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
210 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800211 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
212
213 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800214#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800215 usb_phy = (void __iomem *)SCFG_USB_PHY2;
216 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
217
218 usb_phy = (void __iomem *)SCFG_USB_PHY3;
219 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800220#endif
Yinbo Zhu5c3767e2019-05-14 17:34:57 +0800221#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
222 defined(CONFIG_ARCH_LS1028A)
Ran Wang3ba69482017-09-04 18:46:51 +0800223 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
224
225 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
226 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
227#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
228}
229
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800230#if defined(CONFIG_FSL_LSCH3)
Ran Wangd0270dc2019-11-26 11:40:40 +0800231static void erratum_a050106(void)
232{
233#if defined(CONFIG_ARCH_LX2160A)
234 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
235
236 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
237 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
238#endif
239}
Yao Yuanfae88052015-12-05 14:59:14 +0800240/*
241 * This erratum requires setting a value to eddrtqcr1 to
242 * optimal the DDR performance.
243 */
244static void erratum_a008336(void)
245{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800246#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800247 u32 *eddrtqcr1;
248
Yao Yuanfae88052015-12-05 14:59:14 +0800249#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
250 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800251 if (fsl_ddr_get_version(0) == 0x50200)
252 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800253#endif
254#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
255 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800256 if (fsl_ddr_get_version(0) == 0x50200)
257 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800258#endif
259#endif
260}
261
262/*
263 * This erratum requires a register write before being Memory
264 * controller 3 being enabled.
265 */
266static void erratum_a008514(void)
267{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800268#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800269 u32 *eddrtqcr1;
270
Yao Yuanfae88052015-12-05 14:59:14 +0800271#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
272 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
273 out_le32(eddrtqcr1, 0x63b20002);
274#endif
275#endif
276}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530277#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
278#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
279
280static unsigned long get_internval_val_mhz(void)
281{
Simon Glass64b723f2017-08-03 12:22:12 -0600282 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530283 /*
284 * interval is the number of platform cycles(MHz) between
285 * wake up events generated by EPU.
286 */
287 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
288
289 if (interval)
290 interval_mhz = simple_strtoul(interval, NULL, 10);
291
292 return interval_mhz;
293}
294
295void erratum_a009635(void)
296{
297 u32 val;
298 unsigned long interval_mhz = get_internval_val_mhz();
299
300 if (!interval_mhz)
301 return;
302
303 val = in_le32(DCSR_CGACRE5);
304 writel(val | 0x00000200, DCSR_CGACRE5);
305
306 val = in_le32(EPU_EPCMPR5);
307 writel(interval_mhz, EPU_EPCMPR5);
308 val = in_le32(EPU_EPCCR5);
309 writel(val | 0x82820000, EPU_EPCCR5);
310 val = in_le32(EPU_EPSMCR5);
311 writel(val | 0x002f0000, EPU_EPSMCR5);
312 val = in_le32(EPU_EPECR5);
313 writel(val | 0x20000000, EPU_EPECR5);
314 val = in_le32(EPU_EPGCR);
315 writel(val | 0x80000000, EPU_EPGCR);
316}
317#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
318
Scott Wood8e728cd2015-03-24 13:25:02 -0700319static void erratum_rcw_src(void)
320{
Santan Kumar99136482017-05-05 15:42:28 +0530321#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700322 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
323 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
324 u32 val;
325
326 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
327 val &= ~DCFG_PORSR1_RCW_SRC;
328 val |= DCFG_PORSR1_RCW_SRC_NOR;
329 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
330#endif
331}
332
York Sun0404a392015-03-23 10:41:35 -0700333#define I2C_DEBUG_REG 0x6
334#define I2C_GLITCH_EN 0x8
335/*
336 * This erratum requires setting glitch_en bit to enable
337 * digital glitch filter to improve clock stability.
338 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530339#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700340static void erratum_a009203(void)
341{
York Sun0404a392015-03-23 10:41:35 -0700342#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530343 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700344#ifdef I2C1_BASE_ADDR
345 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
346
347 writeb(I2C_GLITCH_EN, ptr);
348#endif
349#ifdef I2C2_BASE_ADDR
350 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
351
352 writeb(I2C_GLITCH_EN, ptr);
353#endif
354#ifdef I2C3_BASE_ADDR
355 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
356
357 writeb(I2C_GLITCH_EN, ptr);
358#endif
359#ifdef I2C4_BASE_ADDR
360 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
361
362 writeb(I2C_GLITCH_EN, ptr);
363#endif
364#endif
365}
Ashish kumar3b52a232017-02-23 16:03:57 +0530366#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800367
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530368void bypass_smmu(void)
369{
370 u32 val;
371 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
372 out_le32(SMMU_SCR0, val);
373 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
374 out_le32(SMMU_NSCR0, val);
375}
Scott Woodf64c98c2015-03-20 19:28:12 -0700376void fsl_lsch3_early_init_f(void)
377{
Scott Wood8e728cd2015-03-24 13:25:02 -0700378 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530379#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700380 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530381#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530382#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700383 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530384#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800385 erratum_a008514();
386 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800387 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800388 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800389 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800390 erratum_a009007();
Ran Wangd0270dc2019-11-26 11:40:40 +0800391 erratum_a050106();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530392#ifdef CONFIG_CHAIN_OF_TRUST
393 /* In case of Secure Boot, the IBR configures the SMMU
394 * to allow only Secure transactions.
395 * SMMU must be reset in bypass mode.
396 * Set the ClientPD bit and Clear the USFCFG Bit
397 */
398 if (fsl_check_boot_mode_secure() == 1)
399 bypass_smmu();
400#endif
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300401
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000402#if defined(CONFIG_ARCH_LS1088A) || defined(CONFIG_ARCH_LS1028A) || \
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000403 defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LX2160A)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300404 set_icids();
405#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700406}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800407
Rajesh Bhagat814e0772018-01-17 16:13:00 +0530408/* Get VDD in the unit mV from voltage ID */
409int get_core_volt_from_fuse(void)
410{
411 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
412 int vdd;
413 u32 fusesr;
414 u8 vid;
415
416 /* get the voltage ID from fuse status register */
417 fusesr = in_le32(&gur->dcfg_fusesr);
418 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
419 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
420 FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
421 if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
422 vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
423 FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
424 }
425 debug("%s: VID = 0x%x\n", __func__, vid);
426 switch (vid) {
427 case 0x00: /* VID isn't supported */
428 vdd = -EINVAL;
429 debug("%s: The VID feature is not supported\n", __func__);
430 break;
431 case 0x08: /* 0.9V silicon */
432 vdd = 900;
433 break;
434 case 0x10: /* 1.0V silicon */
435 vdd = 1000;
436 break;
437 default: /* Other core voltage */
438 vdd = -EINVAL;
439 debug("%s: The VID(%x) isn't supported\n", __func__, vid);
440 break;
441 }
442 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
443
444 return vdd;
445}
446
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530447#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800448
Mingkai Hu8beb0752015-12-07 16:58:54 +0800449static void erratum_a009929(void)
450{
451#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
452 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
453 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
454 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
455
456 rstrqmr1 |= 0x00000400;
457 gur_out32(&gur->rstrqmr1, rstrqmr1);
458 writel(0x01000000, dcsr_cop_ccp);
459#endif
460}
461
Mingkai Hu172081c2016-02-02 11:28:03 +0800462/*
463 * This erratum requires setting a value to eddrtqcr1 to optimal
464 * the DDR performance. The eddrtqcr1 register is in SCFG space
465 * of LS1043A and the offset is 0x157_020c.
466 */
467#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
468 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
469#error A009660 and A008514 can not be both enabled.
470#endif
471
472static void erratum_a009660(void)
473{
474#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
475 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
476 out_be32(eddrtqcr1, 0x63b20042);
477#endif
478}
479
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800480static void erratum_a008850_early(void)
481{
482#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
483 /* part 1 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
York Sune6b871e2017-05-15 08:51:59 -0700488 /* Skip if running at lower exception level */
489 if (current_el() < 3)
490 return;
491
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800492 /* disables propagation of barrier transactions to DDRC from CCI400 */
493 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
494
495 /* disable the re-ordering in DDRC */
496 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
497#endif
498}
499
500void erratum_a008850_post(void)
501{
502#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
503 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530504 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
505 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800506 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
507 u32 tmp;
508
York Sune6b871e2017-05-15 08:51:59 -0700509 /* Skip if running at lower exception level */
510 if (current_el() < 3)
511 return;
512
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800513 /* enable propagation of barrier transactions to DDRC from CCI400 */
514 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
515
516 /* enable the re-ordering in DDRC */
517 tmp = ddr_in32(&ddr->eor);
518 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
519 ddr_out32(&ddr->eor, tmp);
520#endif
521}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800522
523#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
524void erratum_a010315(void)
525{
526 int i;
527
528 for (i = PCIE1; i <= PCIE4; i++)
529 if (!is_serdes_configured(i)) {
530 debug("PCIe%d: disabled all R/W permission!\n", i);
531 set_pcie_ns_access(i, 0);
532 }
533}
534#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800535
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800536static void erratum_a010539(void)
537{
538#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
539 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
540 u32 porsr1;
541
542 porsr1 = in_be32(&gur->porsr1);
543 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
544 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
545 porsr1);
Hou Zhiqiang653793a2018-04-25 14:25:42 +0800546 out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800547#endif
548}
549
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800550/* Get VDD in the unit mV from voltage ID */
551int get_core_volt_from_fuse(void)
552{
553 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
554 int vdd;
555 u32 fusesr;
556 u8 vid;
557
558 fusesr = in_be32(&gur->dcfg_fusesr);
559 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
560 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
561 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
562 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
563 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
564 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
565 }
566 debug("%s: VID = 0x%x\n", __func__, vid);
567 switch (vid) {
568 case 0x00: /* VID isn't supported */
569 vdd = -EINVAL;
570 debug("%s: The VID feature is not supported\n", __func__);
571 break;
572 case 0x08: /* 0.9V silicon */
573 vdd = 900;
574 break;
575 case 0x10: /* 1.0V silicon */
576 vdd = 1000;
577 break;
578 default: /* Other core voltage */
579 vdd = -EINVAL;
580 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
581 break;
582 }
583 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
584
585 return vdd;
586}
587
588__weak int board_switch_core_volt(u32 vdd)
589{
590 return 0;
591}
592
593static int setup_core_volt(u32 vdd)
594{
595 return board_setup_core_volt(vdd);
596}
597
598#ifdef CONFIG_SYS_FSL_DDR
599static void ddr_enable_0v9_volt(bool en)
600{
601 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
602 u32 tmp;
603
604 tmp = ddr_in32(&ddr->ddr_cdr1);
605
606 if (en)
607 tmp |= DDR_CDR1_V0PT9_EN;
608 else
609 tmp &= ~DDR_CDR1_V0PT9_EN;
610
611 ddr_out32(&ddr->ddr_cdr1, tmp);
612}
613#endif
614
615int setup_chip_volt(void)
616{
617 int vdd;
618
619 vdd = get_core_volt_from_fuse();
620 /* Nothing to do for silicons doesn't support VID */
621 if (vdd < 0)
622 return vdd;
623
624 if (setup_core_volt(vdd))
625 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
626#ifdef CONFIG_SYS_HAS_SERDES
627 if (setup_serdes_volt(vdd))
628 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
629#endif
630
631#ifdef CONFIG_SYS_FSL_DDR
632 if (vdd == 900)
633 ddr_enable_0v9_volt(true);
634#endif
635
636 return 0;
637}
638
Calvin Johnson6d6ef012018-03-08 15:30:33 +0530639#ifdef CONFIG_FSL_PFE
640void init_pfe_scfg_dcfg_regs(void)
641{
642 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
643 u32 ecccr2;
644
645 out_be32(&scfg->pfeasbcr,
646 in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
647 out_be32(&scfg->pfebsbcr,
648 in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
649
650 /* CCI-400 QoS settings for PFE */
651 out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
652 | SCFG_WR_QOS1_PFE2_QOS));
653 out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
654 | SCFG_RD_QOS1_PFE2_QOS));
655
656 ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
657 out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
658 ecccr2 | (unsigned int)DISABLE_PFE_ECC);
659}
660#endif
661
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800662void fsl_lsch2_early_init_f(void)
663{
Ashish Kumar11234062017-08-11 11:09:14 +0530664 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
665 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530666 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Pankit Garg41bde722019-05-29 12:12:36 +0000667#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
668 enum boot_src src;
669#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800670
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800671#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
672 enable_layerscape_ns_access();
673#endif
674
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800675#ifdef CONFIG_FSL_IFC
676 init_early_memctl_regs(); /* tighten IFC timing */
677#endif
678
Pankit Garg41bde722019-05-29 12:12:36 +0000679#if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT)
680 src = get_boot_src();
681 if (src != BOOT_SOURCE_QSPI_NOR)
682 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
683#else
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800684#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800685 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
686#endif
Pankit Garg41bde722019-05-29 12:12:36 +0000687#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530688 /* Make SEC reads and writes snoopable */
Ran Wangc75026e2019-09-20 17:34:29 +0800689#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
690 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
691 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
692 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
693 SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
694 SCFG_SNPCNFGCR_USB3WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
695 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wanga7576692019-12-26 18:11:17 +0800696#elif defined(CONFIG_ARCH_LS1012A)
697 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
698 SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
699 SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_SATARDSNP |
700 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800701#else
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530702 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800703 SCFG_SNPCNFGCR_SECWRSNP |
704 SCFG_SNPCNFGCR_SATARDSNP |
705 SCFG_SNPCNFGCR_SATAWRSNP);
Ran Wangc75026e2019-09-20 17:34:29 +0800706#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530707
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800708 /*
709 * Enable snoop requests and DVM message requests for
710 * Slave insterface S4 (A53 core cluster)
711 */
York Sune6b871e2017-05-15 08:51:59 -0700712 if (current_el() == 3) {
713 out_le32(&cci->slave[4].snoop_ctrl,
714 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
715 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800716
Ran Wang4e7cdcf2018-08-10 15:00:00 +0800717 /*
718 * Program Central Security Unit (CSU) to grant access
719 * permission for USB 2.0 controller
720 */
721#if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL)
722 if (current_el() == 3)
723 set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW);
724#endif
Mingkai Hu8beb0752015-12-07 16:58:54 +0800725 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800726 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800727 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800728 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800729 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800730 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800731 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800732 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800733 erratum_a009007();
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300734
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300735#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300736 set_icids();
737#endif
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800738}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800739#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700740
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530741#ifdef CONFIG_FSPI_AHB_EN_4BYTE
742int fspi_ahb_init(void)
743{
744 /* Enable 4bytes address support and fast read */
745 u32 *fspi_lut, lut_key, *fspi_key;
746
747 fspi_key = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUTKEY_BASE_ADDR;
748 fspi_lut = (void *)SYS_NXP_FSPI_ADDR + SYS_NXP_FSPI_LUT_BASE_ADDR;
749
750 lut_key = in_be32(fspi_key);
751
752 if (lut_key == SYS_NXP_FSPI_LUTKEY) {
753 /* That means the register is BE */
754 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
755 /* Unlock the lut table */
756 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
757 /* Create READ LUT */
758 out_be32(fspi_lut, 0x0820040c);
759 out_be32(fspi_lut + 1, 0x24003008);
760 out_be32(fspi_lut + 2, 0x00000000);
761 /* Lock the lut table */
762 out_be32(fspi_key, SYS_NXP_FSPI_LUTKEY);
763 out_be32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
764 } else {
765 /* That means the register is LE */
766 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
767 /* Unlock the lut table */
768 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_UNLOCK);
769 /* Create READ LUT */
770 out_le32(fspi_lut, 0x0820040c);
771 out_le32(fspi_lut + 1, 0x24003008);
772 out_le32(fspi_lut + 2, 0x00000000);
773 /* Lock the lut table */
774 out_le32(fspi_key, SYS_NXP_FSPI_LUTKEY);
775 out_le32(fspi_key + 1, SYS_NXP_FSPI_LUTCR_LOCK);
776 }
777
778 return 0;
779}
780#endif
781
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800782#ifdef CONFIG_QSPI_AHB_INIT
783/* Enable 4bytes address support and fast read */
784int qspi_ahb_init(void)
785{
786 u32 *qspi_lut, lut_key, *qspi_key;
787
788 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
789 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
790
791 lut_key = in_be32(qspi_key);
792
793 if (lut_key == 0x5af05af0) {
794 /* That means the register is BE */
795 out_be32(qspi_key, 0x5af05af0);
796 /* Unlock the lut table */
797 out_be32(qspi_key + 1, 0x00000002);
798 out_be32(qspi_lut, 0x0820040c);
799 out_be32(qspi_lut + 1, 0x1c080c08);
800 out_be32(qspi_lut + 2, 0x00002400);
801 /* Lock the lut table */
802 out_be32(qspi_key, 0x5af05af0);
803 out_be32(qspi_key + 1, 0x00000001);
804 } else {
805 /* That means the register is LE */
806 out_le32(qspi_key, 0x5af05af0);
807 /* Unlock the lut table */
808 out_le32(qspi_key + 1, 0x00000002);
809 out_le32(qspi_lut, 0x0820040c);
810 out_le32(qspi_lut + 1, 0x1c080c08);
811 out_le32(qspi_lut + 2, 0x00002400);
812 /* Lock the lut table */
813 out_le32(qspi_key, 0x5af05af0);
814 out_le32(qspi_key + 1, 0x00000001);
815 }
816
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000817 return 0;
818}
819#endif
820
821#ifdef CONFIG_TFABOOT
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000822#define MAX_BOOTCMD_SIZE 512
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000823
824int fsl_setenv_bootcmd(void)
825{
826 int ret;
827 enum boot_src src = get_boot_src();
828 char bootcmd_str[MAX_BOOTCMD_SIZE];
829
830 switch (src) {
831#ifdef IFC_NOR_BOOTCOMMAND
832 case BOOT_SOURCE_IFC_NOR:
833 sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND);
834 break;
835#endif
836#ifdef QSPI_NOR_BOOTCOMMAND
837 case BOOT_SOURCE_QSPI_NOR:
838 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
839 break;
840#endif
841#ifdef XSPI_NOR_BOOTCOMMAND
842 case BOOT_SOURCE_XSPI_NOR:
843 sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND);
844 break;
845#endif
846#ifdef IFC_NAND_BOOTCOMMAND
847 case BOOT_SOURCE_IFC_NAND:
848 sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND);
849 break;
850#endif
851#ifdef QSPI_NAND_BOOTCOMMAND
852 case BOOT_SOURCE_QSPI_NAND:
853 sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND);
854 break;
855#endif
856#ifdef XSPI_NAND_BOOTCOMMAND
857 case BOOT_SOURCE_XSPI_NAND:
858 sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND);
859 break;
860#endif
861#ifdef SD_BOOTCOMMAND
862 case BOOT_SOURCE_SD_MMC:
863 sprintf(bootcmd_str, SD_BOOTCOMMAND);
864 break;
865#endif
866#ifdef SD2_BOOTCOMMAND
867 case BOOT_SOURCE_SD_MMC2:
868 sprintf(bootcmd_str, SD2_BOOTCOMMAND);
869 break;
870#endif
871 default:
872#ifdef QSPI_NOR_BOOTCOMMAND
873 sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND);
874#endif
875 break;
876 }
877
878 ret = env_set("bootcmd", bootcmd_str);
879 if (ret) {
880 printf("Failed to set bootcmd: ret = %d\n", ret);
881 return ret;
882 }
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800883 return 0;
884}
Pankit Garg82fcc462018-11-05 18:02:31 +0000885
886int fsl_setenv_mcinitcmd(void)
887{
888 int ret = 0;
889 enum boot_src src = get_boot_src();
890
891 switch (src) {
892#ifdef IFC_MC_INIT_CMD
893 case BOOT_SOURCE_IFC_NAND:
894 case BOOT_SOURCE_IFC_NOR:
895 ret = env_set("mcinitcmd", IFC_MC_INIT_CMD);
896 break;
897#endif
898#ifdef QSPI_MC_INIT_CMD
899 case BOOT_SOURCE_QSPI_NAND:
900 case BOOT_SOURCE_QSPI_NOR:
901 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
902 break;
903#endif
904#ifdef XSPI_MC_INIT_CMD
905 case BOOT_SOURCE_XSPI_NAND:
906 case BOOT_SOURCE_XSPI_NOR:
907 ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD);
908 break;
909#endif
910#ifdef SD_MC_INIT_CMD
911 case BOOT_SOURCE_SD_MMC:
912 ret = env_set("mcinitcmd", SD_MC_INIT_CMD);
913 break;
914#endif
915#ifdef SD2_MC_INIT_CMD
916 case BOOT_SOURCE_SD_MMC2:
917 ret = env_set("mcinitcmd", SD2_MC_INIT_CMD);
918 break;
919#endif
920 default:
921#ifdef QSPI_MC_INIT_CMD
922 ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD);
923#endif
924 break;
925 }
926
927 if (ret) {
928 printf("Failed to set mcinitcmd: ret = %d\n", ret);
929 return ret;
930 }
931 return 0;
932}
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800933#endif
934
Mingkai Hu0e58b512015-10-26 19:47:50 +0800935#ifdef CONFIG_BOARD_LATE_INIT
Michael Wallefc667ea2019-10-21 22:37:45 +0200936__weak int fsl_board_late_init(void)
937{
938 return 0;
939}
940
Mingkai Hu0e58b512015-10-26 19:47:50 +0800941int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700942{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530943#ifdef CONFIG_CHAIN_OF_TRUST
944 fsl_setenv_chain_of_trust();
945#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000946#ifdef CONFIG_TFABOOT
947 /*
948 * check if gd->env_addr is default_environment; then setenv bootcmd
Pankit Garg82fcc462018-11-05 18:02:31 +0000949 * and mcinitcmd.
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000950 */
Tom Rini5cd7ece2019-11-18 20:02:10 -0500951#ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
Pankit Gargd6bd6782019-05-30 12:04:15 +0000952 if (gd->env_addr == (ulong)&default_environment[0]) {
953#else
Pankit Garg82fcc462018-11-05 18:02:31 +0000954 if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) {
Pankit Gargd6bd6782019-05-30 12:04:15 +0000955#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000956 fsl_setenv_bootcmd();
Pankit Garg82fcc462018-11-05 18:02:31 +0000957 fsl_setenv_mcinitcmd();
958 }
Rajesh Bhagat5b73c902018-12-27 04:37:49 +0000959
960 /*
961 * If the boot mode is secure, default environment is not present then
962 * setenv command needs to be run by default
963 */
964#ifdef CONFIG_CHAIN_OF_TRUST
965 if ((fsl_check_boot_mode_secure() == 1)) {
966 fsl_setenv_bootcmd();
967 fsl_setenv_mcinitcmd();
968 }
969#endif
Pankit Gargbdbf84f2018-11-05 18:01:52 +0000970#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800971#ifdef CONFIG_QSPI_AHB_INIT
972 qspi_ahb_init();
973#endif
Kuldeep Singh34aafb02019-11-21 17:15:17 +0530974#ifdef CONFIG_FSPI_AHB_EN_4BYTE
975 fspi_ahb_init();
976#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800977
Michael Wallefc667ea2019-10-21 22:37:45 +0200978 return fsl_board_late_init();
Scott Wood8e728cd2015-03-24 13:25:02 -0700979}
980#endif