blob: 0647622cde5936c0d3505f89e78d3efe0f9c250c [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
Tom Riniaea2a992021-12-14 13:36:39 -0500105#ifdef CONFIG_DYNAMIC_SYS_CLK_FREQ
Wang Huanf0ce7d62014-09-05 13:52:44 +0800106unsigned long get_board_sys_clk(void)
107{
108 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
109
110 switch (sysclk_conf & 0x0f) {
111 case QIXIS_SYSCLK_64:
112 return 64000000;
113 case QIXIS_SYSCLK_83:
114 return 83333333;
115 case QIXIS_SYSCLK_100:
116 return 100000000;
117 case QIXIS_SYSCLK_125:
118 return 125000000;
119 case QIXIS_SYSCLK_133:
120 return 133333333;
121 case QIXIS_SYSCLK_150:
122 return 150000000;
123 case QIXIS_SYSCLK_160:
124 return 160000000;
125 case QIXIS_SYSCLK_166:
126 return 166666666;
127 }
128 return 66666666;
129}
Tom Riniaea2a992021-12-14 13:36:39 -0500130#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800131
Tom Rinif7246c22021-08-21 13:50:17 -0400132#ifdef CONFIG_DYNAMIC_DDR_CLK_FREQ
Wang Huanf0ce7d62014-09-05 13:52:44 +0800133unsigned long get_board_ddr_clk(void)
134{
135 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
136
137 switch ((ddrclk_conf & 0x30) >> 4) {
138 case QIXIS_DDRCLK_100:
139 return 100000000;
140 case QIXIS_DDRCLK_125:
141 return 125000000;
142 case QIXIS_DDRCLK_133:
143 return 133333333;
144 }
145 return 66666666;
146}
Tom Rinif7246c22021-08-21 13:50:17 -0400147#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800148
149int dram_init(void)
150{
Chenhui Zhao50966942014-11-06 10:51:59 +0800151 /*
152 * When resuming from deep sleep, the I2C channel may not be
153 * in the default channel. So, switch to the default channel
154 * before accessing DDR SPD.
Biwen Lid15aa9f2019-12-31 15:33:44 +0800155 *
156 * PCA9547(0x77) mount on I2C1 bus
Chenhui Zhao50966942014-11-06 10:51:59 +0800157 */
Biwen Lid15aa9f2019-12-31 15:33:44 +0800158 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600159 return fsl_initdram();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800160}
161
Wang Huanf0ce7d62014-09-05 13:52:44 +0800162int board_early_init_f(void)
163{
164 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800165
166#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300167 /* clear BD & FR bits for BE BD's and frame data */
168 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800169#endif
170
171#ifdef CONFIG_FSL_IFC
172 init_early_memctl_regs();
173#endif
174
Yao Yuane0f8f542015-12-05 14:59:10 +0800175 arch_soc_init();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800176
tang yuantian57296e72014-12-17 12:58:05 +0800177#if defined(CONFIG_DEEP_SLEEP)
178 if (is_warm_boot())
179 fsl_dp_disable_console();
180#endif
181
Wang Huanf0ce7d62014-09-05 13:52:44 +0800182 return 0;
183}
Alison Wang9da51782014-12-03 15:00:47 +0800184
185#ifdef CONFIG_SPL_BUILD
186void board_init_f(ulong dummy)
187{
Alison Wangab98bb52014-12-09 17:38:14 +0800188#ifdef CONFIG_NAND_BOOT
189 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
190 u32 porsr1, pinctl;
191
192 /*
193 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
194 * NAND boot because IFC signals > IFC_AD7 are not enabled.
195 * This workaround changes RCW source to make all signals enabled.
196 */
197 porsr1 = in_be32(&gur->porsr1);
198 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
199 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
200 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
201 pinctl);
202#endif
203
Alison Wang9da51782014-12-03 15:00:47 +0800204 /* Clear the BSS */
205 memset(__bss_start, 0, __bss_end - __bss_start);
206
207#ifdef CONFIG_FSL_IFC
208 init_early_memctl_regs();
209#endif
210
211 get_clocks();
212
tang yuantian57296e72014-12-17 12:58:05 +0800213#if defined(CONFIG_DEEP_SLEEP)
214 if (is_warm_boot())
215 fsl_dp_disable_console();
216#endif
217
Alison Wang9da51782014-12-03 15:00:47 +0800218 preloader_console_init();
219
Simon Glassbccfc2e2021-07-10 21:14:36 -0600220#ifdef CONFIG_SPL_I2C
Alison Wang9da51782014-12-03 15:00:47 +0800221 i2c_init_all();
222#endif
Alison Wang6027eb42015-03-12 11:31:44 +0800223
Alison Wang28253032018-10-16 16:19:22 +0800224 timer_init();
Alison Wang9da51782014-12-03 15:00:47 +0800225 dram_init();
226
Alison Wang5dec9d72015-07-09 10:50:07 +0800227 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800228#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
229 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800230#endif
231
Alison Wang9da51782014-12-03 15:00:47 +0800232 board_init_r(NULL, 0);
233}
234#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800235
Alison Wang29d75432014-12-09 17:38:23 +0800236void config_etseccm_source(int etsec_gtx_125_mux)
237{
238 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
239
240 switch (etsec_gtx_125_mux) {
241 case GE0_CLK125:
242 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
243 debug("etseccm set to GE0_CLK125\n");
244 break;
245
246 case GE2_CLK125:
247 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
248 debug("etseccm set to GE2_CLK125\n");
249 break;
250
251 case GE1_CLK125:
252 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
253 debug("etseccm set to GE1_CLK125\n");
254 break;
255
256 default:
257 printf("Error! trying to set etseccm to invalid value\n");
258 break;
259 }
260}
261
Wang Huanf0ce7d62014-09-05 13:52:44 +0800262int config_board_mux(int ctrl_type)
263{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800264 u8 reg12, reg14;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800265
266 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800267 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800268
269 switch (ctrl_type) {
Yao Yuanfec6aa02014-11-26 14:54:33 +0800270 case MUX_TYPE_CAN:
Alison Wang29d75432014-12-09 17:38:23 +0800271 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800272 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
273 break;
274 case MUX_TYPE_IIC2:
275 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
276 break;
277 case MUX_TYPE_RGMII:
278 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
279 break;
280 case MUX_TYPE_SAI:
Alison Wang29d75432014-12-09 17:38:23 +0800281 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800282 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
283 break;
284 case MUX_TYPE_SDHC:
285 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
286 break;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800287 case MUX_TYPE_SD_PCI4:
288 reg12 = 0x38;
289 break;
290 case MUX_TYPE_SD_PC_SA_SG_SG:
291 reg12 = 0x01;
292 break;
293 case MUX_TYPE_SD_PC_SA_PC_SG:
294 reg12 = 0x01;
295 break;
296 case MUX_TYPE_SD_PC_SG_SG:
297 reg12 = 0x21;
298 break;
299 default:
300 printf("Wrong mux interface type\n");
301 return -1;
302 }
303
304 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800305 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800306
307 return 0;
308}
309
310int config_serdes_mux(void)
311{
312 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
313 u32 cfg;
314
315 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
316 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
317
318 switch (cfg) {
319 case 0x0:
320 config_board_mux(MUX_TYPE_SD_PCI4);
321 break;
322 case 0x30:
323 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
324 break;
325 case 0x60:
326 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
327 break;
328 case 0x70:
329 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
330 break;
331 default:
332 printf("SRDS1 prtcl:0x%x\n", cfg);
333 break;
334 }
335
336 return 0;
337}
338
tang yuantian9f51db22015-10-16 16:06:05 +0800339#ifdef CONFIG_BOARD_LATE_INIT
340int board_late_init(void)
341{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530342#ifdef CONFIG_CHAIN_OF_TRUST
343 fsl_setenv_chain_of_trust();
344#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800345
346 return 0;
347}
348#endif
349
Ruchika Gupta901ae762014-10-15 11:39:06 +0530350int misc_init_r(void)
351{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800352 int conflict_flag;
353
354 /* some signals can not enable simultaneous*/
355 conflict_flag = 0;
356 if (hwconfig("sdhc"))
357 conflict_flag++;
358 if (hwconfig("iic2"))
359 conflict_flag++;
360 if (conflict_flag > 1) {
361 printf("WARNING: pin conflict !\n");
362 return 0;
363 }
364
365 conflict_flag = 0;
366 if (hwconfig("rgmii"))
367 conflict_flag++;
368 if (hwconfig("can"))
369 conflict_flag++;
370 if (hwconfig("sai"))
371 conflict_flag++;
372 if (conflict_flag > 1) {
373 printf("WARNING: pin conflict !\n");
374 return 0;
375 }
376
377 if (hwconfig("can"))
378 config_board_mux(MUX_TYPE_CAN);
379 else if (hwconfig("rgmii"))
380 config_board_mux(MUX_TYPE_RGMII);
381 else if (hwconfig("sai"))
382 config_board_mux(MUX_TYPE_SAI);
383
384 if (hwconfig("iic2"))
385 config_board_mux(MUX_TYPE_IIC2);
386 else if (hwconfig("sdhc"))
387 config_board_mux(MUX_TYPE_SDHC);
388
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800389#ifdef CONFIG_FSL_DEVICE_DISABLE
390 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
391#endif
Ruchika Gupta901ae762014-10-15 11:39:06 +0530392#ifdef CONFIG_FSL_CAAM
393 return sec_init();
394#endif
Yao Yuanfec6aa02014-11-26 14:54:33 +0800395 return 0;
Ruchika Gupta901ae762014-10-15 11:39:06 +0530396}
Ruchika Gupta901ae762014-10-15 11:39:06 +0530397
Wang Huanf0ce7d62014-09-05 13:52:44 +0800398int board_init(void)
399{
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800400#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
401 erratum_a010315();
402#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +0800403#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
404 erratum_a009942_check_cpo();
405#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800406
Biwen Lid15aa9f2019-12-31 15:33:44 +0800407 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800408
409#ifndef CONFIG_SYS_FSL_NO_SERDES
410 fsl_serdes_init();
411 config_serdes_mux();
412#endif
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800413
Alison Wang69364922016-02-05 12:48:17 +0800414 ls102xa_smmu_stream_id_init();
Xiubo Li03d40aa2014-11-21 17:40:59 +0800415
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800416#ifdef CONFIG_U_QE
417 u_qe_init();
418#endif
419
Wang Huanf0ce7d62014-09-05 13:52:44 +0800420 return 0;
421}
tang yuantian57296e72014-12-17 12:58:05 +0800422
423#if defined(CONFIG_DEEP_SLEEP)
424void board_sleep_prepare(void)
425{
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800426#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
427 enable_layerscape_ns_access();
tang yuantian57296e72014-12-17 12:58:05 +0800428#endif
429}
430#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800431
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900432int ft_board_setup(void *blob, struct bd_info *bd)
Wang Huanf0ce7d62014-09-05 13:52:44 +0800433{
434 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600435
Minghuan Lian0c535242015-03-12 10:58:48 +0800436#ifdef CONFIG_PCI
437 ft_pci_setup(blob, bd);
Minghuan Liana4d6b612014-10-31 13:43:44 +0800438#endif
439
Simon Glass2aec3cc2014-10-23 18:58:47 -0600440 return 0;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800441}
442
443u8 flash_read8(void *addr)
444{
445 return __raw_readb(addr + 1);
446}
447
448void flash_write16(u16 val, void *addr)
449{
450 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
451
452 __raw_writew(shftval, addr);
453}
454
455u16 flash_read16(void *addr)
456{
457 u16 val = __raw_readw(addr);
458
459 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
460}