blob: 711d8c290661eb97eaa5c5f16f2fbeed1129401a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huanf0ce7d62014-09-05 13:52:44 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Biwen Lid15aa9f2019-12-31 15:33:44 +08004 * Copyright 2019 NXP
Wang Huanf0ce7d62014-09-05 13:52:44 +08005 */
6
7#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07008#include <clock_legacy.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080010#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080013#include <asm/io.h>
14#include <asm/arch/immap_ls102xa.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/fsl_serdes.h>
Yao Yuane0f8f542015-12-05 14:59:10 +080017#include <asm/arch/ls102xa_soc.h>
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +080018#include <asm/arch/ls102xa_devdis.h>
Yao Yuanfec6aa02014-11-26 14:54:33 +080019#include <hwconfig.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080020#include <mmc.h>
Mingkai Hu5b0df8a2015-10-26 19:47:41 +080021#include <fsl_csu.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080022#include <fsl_ifc.h>
Ruchika Gupta901ae762014-10-15 11:39:06 +053023#include <fsl_sec.h>
Alison Wang9da51782014-12-03 15:00:47 +080024#include <spl.h>
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +080025#include <fsl_devdis.h>
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053026#include <fsl_validate.h>
Shengzhou Liu15875a52016-11-21 11:36:48 +080027#include <fsl_ddr.h>
Stephen Carlsonf1790922021-06-22 16:38:21 -070028#include "../common/i2c_mux.h"
tang yuantian57296e72014-12-17 12:58:05 +080029#include "../common/sleep.h"
Wang Huanf0ce7d62014-09-05 13:52:44 +080030#include "../common/qixis.h"
31#include "ls1021aqds_qixis.h"
Zhao Qiang9fc2f302014-09-26 16:25:32 +080032#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080033#include <fsl_qe.h>
Zhao Qiang9fc2f302014-09-26 16:25:32 +080034#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080035
Yao Yuanfec6aa02014-11-26 14:54:33 +080036#define PIN_MUX_SEL_CAN 0x03
37#define PIN_MUX_SEL_IIC2 0xa0
38#define PIN_MUX_SEL_RGMII 0x00
39#define PIN_MUX_SEL_SAI 0x0c
40#define PIN_MUX_SEL_SDHC 0x00
41
42#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0x0f) | value)
43#define SET_EC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
Wang Huanf0ce7d62014-09-05 13:52:44 +080044enum {
Yao Yuanfec6aa02014-11-26 14:54:33 +080045 MUX_TYPE_CAN,
46 MUX_TYPE_IIC2,
47 MUX_TYPE_RGMII,
48 MUX_TYPE_SAI,
49 MUX_TYPE_SDHC,
Wang Huanf0ce7d62014-09-05 13:52:44 +080050 MUX_TYPE_SD_PCI4,
51 MUX_TYPE_SD_PC_SA_SG_SG,
52 MUX_TYPE_SD_PC_SA_PC_SG,
53 MUX_TYPE_SD_PC_SG_SG,
54};
55
Alison Wang29d75432014-12-09 17:38:23 +080056enum {
57 GE0_CLK125,
58 GE2_CLK125,
59 GE1_CLK125,
60};
61
Wang Huanf0ce7d62014-09-05 13:52:44 +080062int checkboard(void)
63{
Alison Wang34de5e42016-02-02 15:16:23 +080064#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanf0ce7d62014-09-05 13:52:44 +080065 char buf[64];
Alison Wang2145a372014-12-09 17:38:02 +080066#endif
Alison Wang9da51782014-12-03 15:00:47 +080067#if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
Wang Huanf0ce7d62014-09-05 13:52:44 +080068 u8 sw;
Alison Wang9da51782014-12-03 15:00:47 +080069#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080070
71 puts("Board: LS1021AQDS\n");
72
Alison Wang9da51782014-12-03 15:00:47 +080073#ifdef CONFIG_SD_BOOT
74 puts("SD\n");
75#elif CONFIG_QSPI_BOOT
76 puts("QSPI\n");
77#else
Wang Huanf0ce7d62014-09-05 13:52:44 +080078 sw = QIXIS_READ(brdcfg[0]);
79 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
80
81 if (sw < 0x8)
82 printf("vBank: %d\n", sw);
83 else if (sw == 0x8)
84 puts("PromJet\n");
85 else if (sw == 0x9)
86 puts("NAND\n");
87 else if (sw == 0x15)
88 printf("IFCCard\n");
89 else
90 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Alison Wang9da51782014-12-03 15:00:47 +080091#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080092
Alison Wang34de5e42016-02-02 15:16:23 +080093#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanf0ce7d62014-09-05 13:52:44 +080094 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
95 QIXIS_READ(id), QIXIS_READ(arch));
96
97 printf("FPGA: v%d (%s), build %d\n",
98 (int)QIXIS_READ(scver), qixis_read_tag(buf),
99 (int)qixis_read_minor());
Alison Wang2145a372014-12-09 17:38:02 +0800100#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800101
102 return 0;
103}
104
105unsigned long get_board_sys_clk(void)
106{
107 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
108
109 switch (sysclk_conf & 0x0f) {
110 case QIXIS_SYSCLK_64:
111 return 64000000;
112 case QIXIS_SYSCLK_83:
113 return 83333333;
114 case QIXIS_SYSCLK_100:
115 return 100000000;
116 case QIXIS_SYSCLK_125:
117 return 125000000;
118 case QIXIS_SYSCLK_133:
119 return 133333333;
120 case QIXIS_SYSCLK_150:
121 return 150000000;
122 case QIXIS_SYSCLK_160:
123 return 160000000;
124 case QIXIS_SYSCLK_166:
125 return 166666666;
126 }
127 return 66666666;
128}
129
130unsigned long get_board_ddr_clk(void)
131{
132 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
133
134 switch ((ddrclk_conf & 0x30) >> 4) {
135 case QIXIS_DDRCLK_100:
136 return 100000000;
137 case QIXIS_DDRCLK_125:
138 return 125000000;
139 case QIXIS_DDRCLK_133:
140 return 133333333;
141 }
142 return 66666666;
143}
144
145int dram_init(void)
146{
Chenhui Zhao50966942014-11-06 10:51:59 +0800147 /*
148 * When resuming from deep sleep, the I2C channel may not be
149 * in the default channel. So, switch to the default channel
150 * before accessing DDR SPD.
Biwen Lid15aa9f2019-12-31 15:33:44 +0800151 *
152 * PCA9547(0x77) mount on I2C1 bus
Chenhui Zhao50966942014-11-06 10:51:59 +0800153 */
Biwen Lid15aa9f2019-12-31 15:33:44 +0800154 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600155 return fsl_initdram();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800156}
157
Wang Huanf0ce7d62014-09-05 13:52:44 +0800158int board_early_init_f(void)
159{
160 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800161
162#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300163 /* clear BD & FR bits for BE BD's and frame data */
164 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800165#endif
166
167#ifdef CONFIG_FSL_IFC
168 init_early_memctl_regs();
169#endif
170
Yao Yuane0f8f542015-12-05 14:59:10 +0800171 arch_soc_init();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800172
tang yuantian57296e72014-12-17 12:58:05 +0800173#if defined(CONFIG_DEEP_SLEEP)
174 if (is_warm_boot())
175 fsl_dp_disable_console();
176#endif
177
Wang Huanf0ce7d62014-09-05 13:52:44 +0800178 return 0;
179}
Alison Wang9da51782014-12-03 15:00:47 +0800180
181#ifdef CONFIG_SPL_BUILD
182void board_init_f(ulong dummy)
183{
Alison Wangab98bb52014-12-09 17:38:14 +0800184#ifdef CONFIG_NAND_BOOT
185 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
186 u32 porsr1, pinctl;
187
188 /*
189 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
190 * NAND boot because IFC signals > IFC_AD7 are not enabled.
191 * This workaround changes RCW source to make all signals enabled.
192 */
193 porsr1 = in_be32(&gur->porsr1);
194 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
195 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
196 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
197 pinctl);
198#endif
199
Alison Wang9da51782014-12-03 15:00:47 +0800200 /* Clear the BSS */
201 memset(__bss_start, 0, __bss_end - __bss_start);
202
203#ifdef CONFIG_FSL_IFC
204 init_early_memctl_regs();
205#endif
206
207 get_clocks();
208
tang yuantian57296e72014-12-17 12:58:05 +0800209#if defined(CONFIG_DEEP_SLEEP)
210 if (is_warm_boot())
211 fsl_dp_disable_console();
212#endif
213
Alison Wang9da51782014-12-03 15:00:47 +0800214 preloader_console_init();
215
Simon Glassbccfc2e2021-07-10 21:14:36 -0600216#ifdef CONFIG_SPL_I2C
Alison Wang9da51782014-12-03 15:00:47 +0800217 i2c_init_all();
218#endif
Alison Wang6027eb42015-03-12 11:31:44 +0800219
Alison Wang28253032018-10-16 16:19:22 +0800220 timer_init();
Alison Wang9da51782014-12-03 15:00:47 +0800221 dram_init();
222
Alison Wang5dec9d72015-07-09 10:50:07 +0800223 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800224#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
225 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800226#endif
227
Alison Wang9da51782014-12-03 15:00:47 +0800228 board_init_r(NULL, 0);
229}
230#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800231
Alison Wang29d75432014-12-09 17:38:23 +0800232void config_etseccm_source(int etsec_gtx_125_mux)
233{
234 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
235
236 switch (etsec_gtx_125_mux) {
237 case GE0_CLK125:
238 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
239 debug("etseccm set to GE0_CLK125\n");
240 break;
241
242 case GE2_CLK125:
243 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
244 debug("etseccm set to GE2_CLK125\n");
245 break;
246
247 case GE1_CLK125:
248 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
249 debug("etseccm set to GE1_CLK125\n");
250 break;
251
252 default:
253 printf("Error! trying to set etseccm to invalid value\n");
254 break;
255 }
256}
257
Wang Huanf0ce7d62014-09-05 13:52:44 +0800258int config_board_mux(int ctrl_type)
259{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800260 u8 reg12, reg14;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800261
262 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800263 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800264
265 switch (ctrl_type) {
Yao Yuanfec6aa02014-11-26 14:54:33 +0800266 case MUX_TYPE_CAN:
Alison Wang29d75432014-12-09 17:38:23 +0800267 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800268 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
269 break;
270 case MUX_TYPE_IIC2:
271 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
272 break;
273 case MUX_TYPE_RGMII:
274 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
275 break;
276 case MUX_TYPE_SAI:
Alison Wang29d75432014-12-09 17:38:23 +0800277 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800278 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
279 break;
280 case MUX_TYPE_SDHC:
281 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
282 break;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800283 case MUX_TYPE_SD_PCI4:
284 reg12 = 0x38;
285 break;
286 case MUX_TYPE_SD_PC_SA_SG_SG:
287 reg12 = 0x01;
288 break;
289 case MUX_TYPE_SD_PC_SA_PC_SG:
290 reg12 = 0x01;
291 break;
292 case MUX_TYPE_SD_PC_SG_SG:
293 reg12 = 0x21;
294 break;
295 default:
296 printf("Wrong mux interface type\n");
297 return -1;
298 }
299
300 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800301 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800302
303 return 0;
304}
305
306int config_serdes_mux(void)
307{
308 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
309 u32 cfg;
310
311 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
312 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
313
314 switch (cfg) {
315 case 0x0:
316 config_board_mux(MUX_TYPE_SD_PCI4);
317 break;
318 case 0x30:
319 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
320 break;
321 case 0x60:
322 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
323 break;
324 case 0x70:
325 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
326 break;
327 default:
328 printf("SRDS1 prtcl:0x%x\n", cfg);
329 break;
330 }
331
332 return 0;
333}
334
tang yuantian9f51db22015-10-16 16:06:05 +0800335#ifdef CONFIG_BOARD_LATE_INIT
336int board_late_init(void)
337{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530338#ifdef CONFIG_CHAIN_OF_TRUST
339 fsl_setenv_chain_of_trust();
340#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800341
342 return 0;
343}
344#endif
345
Ruchika Gupta901ae762014-10-15 11:39:06 +0530346int misc_init_r(void)
347{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800348 int conflict_flag;
349
350 /* some signals can not enable simultaneous*/
351 conflict_flag = 0;
352 if (hwconfig("sdhc"))
353 conflict_flag++;
354 if (hwconfig("iic2"))
355 conflict_flag++;
356 if (conflict_flag > 1) {
357 printf("WARNING: pin conflict !\n");
358 return 0;
359 }
360
361 conflict_flag = 0;
362 if (hwconfig("rgmii"))
363 conflict_flag++;
364 if (hwconfig("can"))
365 conflict_flag++;
366 if (hwconfig("sai"))
367 conflict_flag++;
368 if (conflict_flag > 1) {
369 printf("WARNING: pin conflict !\n");
370 return 0;
371 }
372
373 if (hwconfig("can"))
374 config_board_mux(MUX_TYPE_CAN);
375 else if (hwconfig("rgmii"))
376 config_board_mux(MUX_TYPE_RGMII);
377 else if (hwconfig("sai"))
378 config_board_mux(MUX_TYPE_SAI);
379
380 if (hwconfig("iic2"))
381 config_board_mux(MUX_TYPE_IIC2);
382 else if (hwconfig("sdhc"))
383 config_board_mux(MUX_TYPE_SDHC);
384
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800385#ifdef CONFIG_FSL_DEVICE_DISABLE
386 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
387#endif
Ruchika Gupta901ae762014-10-15 11:39:06 +0530388#ifdef CONFIG_FSL_CAAM
389 return sec_init();
390#endif
Yao Yuanfec6aa02014-11-26 14:54:33 +0800391 return 0;
Ruchika Gupta901ae762014-10-15 11:39:06 +0530392}
Ruchika Gupta901ae762014-10-15 11:39:06 +0530393
Wang Huanf0ce7d62014-09-05 13:52:44 +0800394int board_init(void)
395{
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800396#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
397 erratum_a010315();
398#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +0800399#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
400 erratum_a009942_check_cpo();
401#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800402
Biwen Lid15aa9f2019-12-31 15:33:44 +0800403 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800404
405#ifndef CONFIG_SYS_FSL_NO_SERDES
406 fsl_serdes_init();
407 config_serdes_mux();
408#endif
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800409
Alison Wang69364922016-02-05 12:48:17 +0800410 ls102xa_smmu_stream_id_init();
Xiubo Li03d40aa2014-11-21 17:40:59 +0800411
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800412#ifdef CONFIG_U_QE
413 u_qe_init();
414#endif
415
Wang Huanf0ce7d62014-09-05 13:52:44 +0800416 return 0;
417}
tang yuantian57296e72014-12-17 12:58:05 +0800418
419#if defined(CONFIG_DEEP_SLEEP)
420void board_sleep_prepare(void)
421{
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800422#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
423 enable_layerscape_ns_access();
tang yuantian57296e72014-12-17 12:58:05 +0800424#endif
425}
426#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800427
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900428int ft_board_setup(void *blob, struct bd_info *bd)
Wang Huanf0ce7d62014-09-05 13:52:44 +0800429{
430 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600431
Minghuan Lian0c535242015-03-12 10:58:48 +0800432#ifdef CONFIG_PCI
433 ft_pci_setup(blob, bd);
Minghuan Liana4d6b612014-10-31 13:43:44 +0800434#endif
435
Simon Glass2aec3cc2014-10-23 18:58:47 -0600436 return 0;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800437}
438
439u8 flash_read8(void *addr)
440{
441 return __raw_readb(addr + 1);
442}
443
444void flash_write16(u16 val, void *addr)
445{
446 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
447
448 __raw_writew(shftval, addr);
449}
450
451u16 flash_read16(void *addr)
452{
453 u16 val = __raw_readw(addr);
454
455 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
456}