blob: 930ef6be3850ba2dd844a81cc52c9ff07250938d [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.
Gaurav Jain476c6392022-03-24 11:50:35 +05304 * Copyright 2019, 2021 NXP
Wang Huanf0ce7d62014-09-05 13:52:44 +08005 */
6
Simon Glass85d65312019-12-28 10:44:58 -07007#include <clock_legacy.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07008#include <fdt_support.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +08009#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080012#include <asm/io.h>
13#include <asm/arch/immap_ls102xa.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/fsl_serdes.h>
Yao Yuane0f8f542015-12-05 14:59:10 +080016#include <asm/arch/ls102xa_soc.h>
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +080017#include <asm/arch/ls102xa_devdis.h>
Shiji Yangbb112342023-08-03 09:47:16 +080018#include <asm/sections.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>
Alison Wang9da51782014-12-03 15:00:47 +080023#include <spl.h>
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +080024#include <fsl_devdis.h>
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053025#include <fsl_validate.h>
Shengzhou Liu15875a52016-11-21 11:36:48 +080026#include <fsl_ddr.h>
Stephen Carlsonf1790922021-06-22 16:38:21 -070027#include "../common/i2c_mux.h"
tang yuantian57296e72014-12-17 12:58:05 +080028#include "../common/sleep.h"
Wang Huanf0ce7d62014-09-05 13:52:44 +080029#include "../common/qixis.h"
30#include "ls1021aqds_qixis.h"
Zhao Qiang9fc2f302014-09-26 16:25:32 +080031#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080032#include <fsl_qe.h>
Zhao Qiang9fc2f302014-09-26 16:25:32 +080033#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080034
Yao Yuanfec6aa02014-11-26 14:54:33 +080035#define PIN_MUX_SEL_CAN 0x03
36#define PIN_MUX_SEL_IIC2 0xa0
37#define PIN_MUX_SEL_RGMII 0x00
38#define PIN_MUX_SEL_SAI 0x0c
39#define PIN_MUX_SEL_SDHC 0x00
40
41#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0x0f) | value)
42#define SET_EC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
Wang Huanf0ce7d62014-09-05 13:52:44 +080043enum {
Yao Yuanfec6aa02014-11-26 14:54:33 +080044 MUX_TYPE_CAN,
45 MUX_TYPE_IIC2,
46 MUX_TYPE_RGMII,
47 MUX_TYPE_SAI,
48 MUX_TYPE_SDHC,
Wang Huanf0ce7d62014-09-05 13:52:44 +080049 MUX_TYPE_SD_PCI4,
50 MUX_TYPE_SD_PC_SA_SG_SG,
51 MUX_TYPE_SD_PC_SA_PC_SG,
52 MUX_TYPE_SD_PC_SG_SG,
53};
54
Alison Wang29d75432014-12-09 17:38:23 +080055enum {
56 GE0_CLK125,
57 GE2_CLK125,
58 GE1_CLK125,
59};
60
Wang Huanf0ce7d62014-09-05 13:52:44 +080061int checkboard(void)
62{
Alison Wang34de5e42016-02-02 15:16:23 +080063#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanf0ce7d62014-09-05 13:52:44 +080064 char buf[64];
Alison Wang2145a372014-12-09 17:38:02 +080065#endif
Alison Wang9da51782014-12-03 15:00:47 +080066#if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
Wang Huanf0ce7d62014-09-05 13:52:44 +080067 u8 sw;
Alison Wang9da51782014-12-03 15:00:47 +080068#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080069
70 puts("Board: LS1021AQDS\n");
71
Alison Wang9da51782014-12-03 15:00:47 +080072#ifdef CONFIG_SD_BOOT
73 puts("SD\n");
74#elif CONFIG_QSPI_BOOT
75 puts("QSPI\n");
76#else
Wang Huanf0ce7d62014-09-05 13:52:44 +080077 sw = QIXIS_READ(brdcfg[0]);
78 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
79
80 if (sw < 0x8)
81 printf("vBank: %d\n", sw);
82 else if (sw == 0x8)
83 puts("PromJet\n");
84 else if (sw == 0x9)
85 puts("NAND\n");
86 else if (sw == 0x15)
87 printf("IFCCard\n");
88 else
89 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Alison Wang9da51782014-12-03 15:00:47 +080090#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080091
Alison Wang34de5e42016-02-02 15:16:23 +080092#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanf0ce7d62014-09-05 13:52:44 +080093 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
94 QIXIS_READ(id), QIXIS_READ(arch));
95
96 printf("FPGA: v%d (%s), build %d\n",
97 (int)QIXIS_READ(scver), qixis_read_tag(buf),
98 (int)qixis_read_minor());
Alison Wang2145a372014-12-09 17:38:02 +080099#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800100
101 return 0;
102}
103
Tom Riniaea2a992021-12-14 13:36:39 -0500104#ifdef CONFIG_DYNAMIC_SYS_CLK_FREQ
Wang Huanf0ce7d62014-09-05 13:52:44 +0800105unsigned 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}
Tom Riniaea2a992021-12-14 13:36:39 -0500129#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800130
Tom Rinif7246c22021-08-21 13:50:17 -0400131#ifdef CONFIG_DYNAMIC_DDR_CLK_FREQ
Wang Huanf0ce7d62014-09-05 13:52:44 +0800132unsigned long get_board_ddr_clk(void)
133{
134 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
135
136 switch ((ddrclk_conf & 0x30) >> 4) {
137 case QIXIS_DDRCLK_100:
138 return 100000000;
139 case QIXIS_DDRCLK_125:
140 return 125000000;
141 case QIXIS_DDRCLK_133:
142 return 133333333;
143 }
144 return 66666666;
145}
Tom Rinif7246c22021-08-21 13:50:17 -0400146#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800147
148int dram_init(void)
149{
Chenhui Zhao50966942014-11-06 10:51:59 +0800150 /*
151 * When resuming from deep sleep, the I2C channel may not be
152 * in the default channel. So, switch to the default channel
153 * before accessing DDR SPD.
Biwen Lid15aa9f2019-12-31 15:33:44 +0800154 *
155 * PCA9547(0x77) mount on I2C1 bus
Chenhui Zhao50966942014-11-06 10:51:59 +0800156 */
Biwen Lid15aa9f2019-12-31 15:33:44 +0800157 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600158 return fsl_initdram();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800159}
160
Wang Huanf0ce7d62014-09-05 13:52:44 +0800161int board_early_init_f(void)
162{
Tom Rini376b88a2022-10-28 20:27:13 -0400163 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800164
165#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300166 /* clear BD & FR bits for BE BD's and frame data */
167 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800168#endif
169
170#ifdef CONFIG_FSL_IFC
171 init_early_memctl_regs();
172#endif
173
Yao Yuane0f8f542015-12-05 14:59:10 +0800174 arch_soc_init();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800175
tang yuantian57296e72014-12-17 12:58:05 +0800176#if defined(CONFIG_DEEP_SLEEP)
177 if (is_warm_boot())
178 fsl_dp_disable_console();
179#endif
180
Wang Huanf0ce7d62014-09-05 13:52:44 +0800181 return 0;
182}
Alison Wang9da51782014-12-03 15:00:47 +0800183
184#ifdef CONFIG_SPL_BUILD
185void board_init_f(ulong dummy)
186{
Alison Wangab98bb52014-12-09 17:38:14 +0800187#ifdef CONFIG_NAND_BOOT
Tom Rini376b88a2022-10-28 20:27:13 -0400188 struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
Alison Wangab98bb52014-12-09 17:38:14 +0800189 u32 porsr1, pinctl;
190
191 /*
192 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
193 * NAND boot because IFC signals > IFC_AD7 are not enabled.
194 * This workaround changes RCW source to make all signals enabled.
195 */
196 porsr1 = in_be32(&gur->porsr1);
197 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
198 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
Tom Rini6a5dccc2022-11-16 13:10:41 -0500199 out_be32((unsigned int *)(CFG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
Alison Wangab98bb52014-12-09 17:38:14 +0800200 pinctl);
201#endif
202
Alison Wang9da51782014-12-03 15:00:47 +0800203 /* Clear the BSS */
204 memset(__bss_start, 0, __bss_end - __bss_start);
205
206#ifdef CONFIG_FSL_IFC
207 init_early_memctl_regs();
208#endif
209
210 get_clocks();
211
tang yuantian57296e72014-12-17 12:58:05 +0800212#if defined(CONFIG_DEEP_SLEEP)
213 if (is_warm_boot())
214 fsl_dp_disable_console();
215#endif
216
Alison Wang9da51782014-12-03 15:00:47 +0800217 preloader_console_init();
218
Simon Glassbccfc2e2021-07-10 21:14:36 -0600219#ifdef CONFIG_SPL_I2C
Alison Wang9da51782014-12-03 15:00:47 +0800220 i2c_init_all();
221#endif
Alison Wang6027eb42015-03-12 11:31:44 +0800222
Alison Wang28253032018-10-16 16:19:22 +0800223 timer_init();
Alison Wang9da51782014-12-03 15:00:47 +0800224 dram_init();
225
Alison Wang5dec9d72015-07-09 10:50:07 +0800226 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800227#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
228 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800229#endif
230
Alison Wang9da51782014-12-03 15:00:47 +0800231 board_init_r(NULL, 0);
232}
233#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800234
Alison Wang29d75432014-12-09 17:38:23 +0800235void config_etseccm_source(int etsec_gtx_125_mux)
236{
Tom Rini376b88a2022-10-28 20:27:13 -0400237 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR;
Alison Wang29d75432014-12-09 17:38:23 +0800238
239 switch (etsec_gtx_125_mux) {
240 case GE0_CLK125:
241 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
242 debug("etseccm set to GE0_CLK125\n");
243 break;
244
245 case GE2_CLK125:
246 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
247 debug("etseccm set to GE2_CLK125\n");
248 break;
249
250 case GE1_CLK125:
251 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
252 debug("etseccm set to GE1_CLK125\n");
253 break;
254
255 default:
256 printf("Error! trying to set etseccm to invalid value\n");
257 break;
258 }
259}
260
Wang Huanf0ce7d62014-09-05 13:52:44 +0800261int config_board_mux(int ctrl_type)
262{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800263 u8 reg12, reg14;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800264
265 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800266 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800267
268 switch (ctrl_type) {
Yao Yuanfec6aa02014-11-26 14:54:33 +0800269 case MUX_TYPE_CAN:
Alison Wang29d75432014-12-09 17:38:23 +0800270 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800271 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
272 break;
273 case MUX_TYPE_IIC2:
274 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
275 break;
276 case MUX_TYPE_RGMII:
277 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
278 break;
279 case MUX_TYPE_SAI:
Alison Wang29d75432014-12-09 17:38:23 +0800280 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800281 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
282 break;
283 case MUX_TYPE_SDHC:
284 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
285 break;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800286 case MUX_TYPE_SD_PCI4:
287 reg12 = 0x38;
288 break;
289 case MUX_TYPE_SD_PC_SA_SG_SG:
290 reg12 = 0x01;
291 break;
292 case MUX_TYPE_SD_PC_SA_PC_SG:
293 reg12 = 0x01;
294 break;
295 case MUX_TYPE_SD_PC_SG_SG:
296 reg12 = 0x21;
297 break;
298 default:
299 printf("Wrong mux interface type\n");
300 return -1;
301 }
302
303 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800304 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800305
306 return 0;
307}
308
309int config_serdes_mux(void)
310{
Tom Rini376b88a2022-10-28 20:27:13 -0400311 struct ccsr_gur *gur = (struct ccsr_gur *)CFG_SYS_FSL_GUTS_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800312 u32 cfg;
313
314 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
315 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
316
317 switch (cfg) {
318 case 0x0:
319 config_board_mux(MUX_TYPE_SD_PCI4);
320 break;
321 case 0x30:
322 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
323 break;
324 case 0x60:
325 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
326 break;
327 case 0x70:
328 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
329 break;
330 default:
331 printf("SRDS1 prtcl:0x%x\n", cfg);
332 break;
333 }
334
335 return 0;
336}
337
tang yuantian9f51db22015-10-16 16:06:05 +0800338#ifdef CONFIG_BOARD_LATE_INIT
339int board_late_init(void)
340{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530341#ifdef CONFIG_CHAIN_OF_TRUST
342 fsl_setenv_chain_of_trust();
343#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800344
345 return 0;
346}
347#endif
348
Ruchika Gupta901ae762014-10-15 11:39:06 +0530349int misc_init_r(void)
350{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800351 int conflict_flag;
352
353 /* some signals can not enable simultaneous*/
354 conflict_flag = 0;
355 if (hwconfig("sdhc"))
356 conflict_flag++;
357 if (hwconfig("iic2"))
358 conflict_flag++;
359 if (conflict_flag > 1) {
360 printf("WARNING: pin conflict !\n");
361 return 0;
362 }
363
364 conflict_flag = 0;
365 if (hwconfig("rgmii"))
366 conflict_flag++;
367 if (hwconfig("can"))
368 conflict_flag++;
369 if (hwconfig("sai"))
370 conflict_flag++;
371 if (conflict_flag > 1) {
372 printf("WARNING: pin conflict !\n");
373 return 0;
374 }
375
376 if (hwconfig("can"))
377 config_board_mux(MUX_TYPE_CAN);
378 else if (hwconfig("rgmii"))
379 config_board_mux(MUX_TYPE_RGMII);
380 else if (hwconfig("sai"))
381 config_board_mux(MUX_TYPE_SAI);
382
383 if (hwconfig("iic2"))
384 config_board_mux(MUX_TYPE_IIC2);
385 else if (hwconfig("sdhc"))
386 config_board_mux(MUX_TYPE_SDHC);
387
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800388#ifdef CONFIG_FSL_DEVICE_DISABLE
389 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
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}