blob: fbbd27d9d71eb156dbe846201bdcb7b0212302e2 [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
Tom Rinif7246c22021-08-21 13:50:17 -0400130#ifdef CONFIG_DYNAMIC_DDR_CLK_FREQ
Wang Huanf0ce7d62014-09-05 13:52:44 +0800131unsigned long get_board_ddr_clk(void)
132{
133 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
134
135 switch ((ddrclk_conf & 0x30) >> 4) {
136 case QIXIS_DDRCLK_100:
137 return 100000000;
138 case QIXIS_DDRCLK_125:
139 return 125000000;
140 case QIXIS_DDRCLK_133:
141 return 133333333;
142 }
143 return 66666666;
144}
Tom Rinif7246c22021-08-21 13:50:17 -0400145#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800146
147int dram_init(void)
148{
Chenhui Zhao50966942014-11-06 10:51:59 +0800149 /*
150 * When resuming from deep sleep, the I2C channel may not be
151 * in the default channel. So, switch to the default channel
152 * before accessing DDR SPD.
Biwen Lid15aa9f2019-12-31 15:33:44 +0800153 *
154 * PCA9547(0x77) mount on I2C1 bus
Chenhui Zhao50966942014-11-06 10:51:59 +0800155 */
Biwen Lid15aa9f2019-12-31 15:33:44 +0800156 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600157 return fsl_initdram();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800158}
159
Wang Huanf0ce7d62014-09-05 13:52:44 +0800160int board_early_init_f(void)
161{
162 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800163
164#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300165 /* clear BD & FR bits for BE BD's and frame data */
166 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800167#endif
168
169#ifdef CONFIG_FSL_IFC
170 init_early_memctl_regs();
171#endif
172
Yao Yuane0f8f542015-12-05 14:59:10 +0800173 arch_soc_init();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800174
tang yuantian57296e72014-12-17 12:58:05 +0800175#if defined(CONFIG_DEEP_SLEEP)
176 if (is_warm_boot())
177 fsl_dp_disable_console();
178#endif
179
Wang Huanf0ce7d62014-09-05 13:52:44 +0800180 return 0;
181}
Alison Wang9da51782014-12-03 15:00:47 +0800182
183#ifdef CONFIG_SPL_BUILD
184void board_init_f(ulong dummy)
185{
Alison Wangab98bb52014-12-09 17:38:14 +0800186#ifdef CONFIG_NAND_BOOT
187 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
188 u32 porsr1, pinctl;
189
190 /*
191 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
192 * NAND boot because IFC signals > IFC_AD7 are not enabled.
193 * This workaround changes RCW source to make all signals enabled.
194 */
195 porsr1 = in_be32(&gur->porsr1);
196 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
197 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
198 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
199 pinctl);
200#endif
201
Alison Wang9da51782014-12-03 15:00:47 +0800202 /* Clear the BSS */
203 memset(__bss_start, 0, __bss_end - __bss_start);
204
205#ifdef CONFIG_FSL_IFC
206 init_early_memctl_regs();
207#endif
208
209 get_clocks();
210
tang yuantian57296e72014-12-17 12:58:05 +0800211#if defined(CONFIG_DEEP_SLEEP)
212 if (is_warm_boot())
213 fsl_dp_disable_console();
214#endif
215
Alison Wang9da51782014-12-03 15:00:47 +0800216 preloader_console_init();
217
Simon Glassbccfc2e2021-07-10 21:14:36 -0600218#ifdef CONFIG_SPL_I2C
Alison Wang9da51782014-12-03 15:00:47 +0800219 i2c_init_all();
220#endif
Alison Wang6027eb42015-03-12 11:31:44 +0800221
Alison Wang28253032018-10-16 16:19:22 +0800222 timer_init();
Alison Wang9da51782014-12-03 15:00:47 +0800223 dram_init();
224
Alison Wang5dec9d72015-07-09 10:50:07 +0800225 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800226#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
227 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800228#endif
229
Alison Wang9da51782014-12-03 15:00:47 +0800230 board_init_r(NULL, 0);
231}
232#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800233
Alison Wang29d75432014-12-09 17:38:23 +0800234void config_etseccm_source(int etsec_gtx_125_mux)
235{
236 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
237
238 switch (etsec_gtx_125_mux) {
239 case GE0_CLK125:
240 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
241 debug("etseccm set to GE0_CLK125\n");
242 break;
243
244 case GE2_CLK125:
245 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
246 debug("etseccm set to GE2_CLK125\n");
247 break;
248
249 case GE1_CLK125:
250 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
251 debug("etseccm set to GE1_CLK125\n");
252 break;
253
254 default:
255 printf("Error! trying to set etseccm to invalid value\n");
256 break;
257 }
258}
259
Wang Huanf0ce7d62014-09-05 13:52:44 +0800260int config_board_mux(int ctrl_type)
261{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800262 u8 reg12, reg14;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800263
264 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800265 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800266
267 switch (ctrl_type) {
Yao Yuanfec6aa02014-11-26 14:54:33 +0800268 case MUX_TYPE_CAN:
Alison Wang29d75432014-12-09 17:38:23 +0800269 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800270 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
271 break;
272 case MUX_TYPE_IIC2:
273 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
274 break;
275 case MUX_TYPE_RGMII:
276 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
277 break;
278 case MUX_TYPE_SAI:
Alison Wang29d75432014-12-09 17:38:23 +0800279 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800280 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
281 break;
282 case MUX_TYPE_SDHC:
283 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
284 break;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800285 case MUX_TYPE_SD_PCI4:
286 reg12 = 0x38;
287 break;
288 case MUX_TYPE_SD_PC_SA_SG_SG:
289 reg12 = 0x01;
290 break;
291 case MUX_TYPE_SD_PC_SA_PC_SG:
292 reg12 = 0x01;
293 break;
294 case MUX_TYPE_SD_PC_SG_SG:
295 reg12 = 0x21;
296 break;
297 default:
298 printf("Wrong mux interface type\n");
299 return -1;
300 }
301
302 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800303 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800304
305 return 0;
306}
307
308int config_serdes_mux(void)
309{
310 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
311 u32 cfg;
312
313 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
314 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
315
316 switch (cfg) {
317 case 0x0:
318 config_board_mux(MUX_TYPE_SD_PCI4);
319 break;
320 case 0x30:
321 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
322 break;
323 case 0x60:
324 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
325 break;
326 case 0x70:
327 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
328 break;
329 default:
330 printf("SRDS1 prtcl:0x%x\n", cfg);
331 break;
332 }
333
334 return 0;
335}
336
tang yuantian9f51db22015-10-16 16:06:05 +0800337#ifdef CONFIG_BOARD_LATE_INIT
338int board_late_init(void)
339{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530340#ifdef CONFIG_CHAIN_OF_TRUST
341 fsl_setenv_chain_of_trust();
342#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800343
344 return 0;
345}
346#endif
347
Ruchika Gupta901ae762014-10-15 11:39:06 +0530348int misc_init_r(void)
349{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800350 int conflict_flag;
351
352 /* some signals can not enable simultaneous*/
353 conflict_flag = 0;
354 if (hwconfig("sdhc"))
355 conflict_flag++;
356 if (hwconfig("iic2"))
357 conflict_flag++;
358 if (conflict_flag > 1) {
359 printf("WARNING: pin conflict !\n");
360 return 0;
361 }
362
363 conflict_flag = 0;
364 if (hwconfig("rgmii"))
365 conflict_flag++;
366 if (hwconfig("can"))
367 conflict_flag++;
368 if (hwconfig("sai"))
369 conflict_flag++;
370 if (conflict_flag > 1) {
371 printf("WARNING: pin conflict !\n");
372 return 0;
373 }
374
375 if (hwconfig("can"))
376 config_board_mux(MUX_TYPE_CAN);
377 else if (hwconfig("rgmii"))
378 config_board_mux(MUX_TYPE_RGMII);
379 else if (hwconfig("sai"))
380 config_board_mux(MUX_TYPE_SAI);
381
382 if (hwconfig("iic2"))
383 config_board_mux(MUX_TYPE_IIC2);
384 else if (hwconfig("sdhc"))
385 config_board_mux(MUX_TYPE_SDHC);
386
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800387#ifdef CONFIG_FSL_DEVICE_DISABLE
388 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
389#endif
Ruchika Gupta901ae762014-10-15 11:39:06 +0530390#ifdef CONFIG_FSL_CAAM
391 return sec_init();
392#endif
Yao Yuanfec6aa02014-11-26 14:54:33 +0800393 return 0;
Ruchika Gupta901ae762014-10-15 11:39:06 +0530394}
Ruchika Gupta901ae762014-10-15 11:39:06 +0530395
Wang Huanf0ce7d62014-09-05 13:52:44 +0800396int board_init(void)
397{
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800398#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
399 erratum_a010315();
400#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +0800401#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
402 erratum_a009942_check_cpo();
403#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800404
Biwen Lid15aa9f2019-12-31 15:33:44 +0800405 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800406
407#ifndef CONFIG_SYS_FSL_NO_SERDES
408 fsl_serdes_init();
409 config_serdes_mux();
410#endif
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800411
Alison Wang69364922016-02-05 12:48:17 +0800412 ls102xa_smmu_stream_id_init();
Xiubo Li03d40aa2014-11-21 17:40:59 +0800413
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800414#ifdef CONFIG_U_QE
415 u_qe_init();
416#endif
417
Wang Huanf0ce7d62014-09-05 13:52:44 +0800418 return 0;
419}
tang yuantian57296e72014-12-17 12:58:05 +0800420
421#if defined(CONFIG_DEEP_SLEEP)
422void board_sleep_prepare(void)
423{
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800424#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
425 enable_layerscape_ns_access();
tang yuantian57296e72014-12-17 12:58:05 +0800426#endif
427}
428#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800429
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900430int ft_board_setup(void *blob, struct bd_info *bd)
Wang Huanf0ce7d62014-09-05 13:52:44 +0800431{
432 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600433
Minghuan Lian0c535242015-03-12 10:58:48 +0800434#ifdef CONFIG_PCI
435 ft_pci_setup(blob, bd);
Minghuan Liana4d6b612014-10-31 13:43:44 +0800436#endif
437
Simon Glass2aec3cc2014-10-23 18:58:47 -0600438 return 0;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800439}
440
441u8 flash_read8(void *addr)
442{
443 return __raw_readb(addr + 1);
444}
445
446void flash_write16(u16 val, void *addr)
447{
448 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
449
450 __raw_writew(shftval, addr);
451}
452
453u16 flash_read16(void *addr)
454{
455 u16 val = __raw_readw(addr);
456
457 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
458}