blob: aa1f6025c1342d10cecaa407dbc03b07442ae18a [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>
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
104unsigned long get_board_sys_clk(void)
105{
106 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
107
108 switch (sysclk_conf & 0x0f) {
109 case QIXIS_SYSCLK_64:
110 return 64000000;
111 case QIXIS_SYSCLK_83:
112 return 83333333;
113 case QIXIS_SYSCLK_100:
114 return 100000000;
115 case QIXIS_SYSCLK_125:
116 return 125000000;
117 case QIXIS_SYSCLK_133:
118 return 133333333;
119 case QIXIS_SYSCLK_150:
120 return 150000000;
121 case QIXIS_SYSCLK_160:
122 return 160000000;
123 case QIXIS_SYSCLK_166:
124 return 166666666;
125 }
126 return 66666666;
127}
128
129unsigned long get_board_ddr_clk(void)
130{
131 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
132
133 switch ((ddrclk_conf & 0x30) >> 4) {
134 case QIXIS_DDRCLK_100:
135 return 100000000;
136 case QIXIS_DDRCLK_125:
137 return 125000000;
138 case QIXIS_DDRCLK_133:
139 return 133333333;
140 }
141 return 66666666;
142}
143
Biwen Lid15aa9f2019-12-31 15:33:44 +0800144int select_i2c_ch_pca9547(u8 ch, int bus_num)
Chenhui Zhao50966942014-11-06 10:51:59 +0800145{
146 int ret;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200147#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lid15aa9f2019-12-31 15:33:44 +0800148 struct udevice *dev;
Chenhui Zhao50966942014-11-06 10:51:59 +0800149
Biwen Lid15aa9f2019-12-31 15:33:44 +0800150 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
151 1, &dev);
152 if (ret) {
153 printf("%s: Cannot find udev for a bus %d\n", __func__,
154 bus_num);
155 return ret;
156 }
157 ret = dm_i2c_write(dev, 0, &ch, 1);
158#else
Chenhui Zhao50966942014-11-06 10:51:59 +0800159 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Lid15aa9f2019-12-31 15:33:44 +0800160#endif
Chenhui Zhao50966942014-11-06 10:51:59 +0800161 if (ret) {
162 puts("PCA: failed to select proper channel\n");
163 return ret;
164 }
165
166 return 0;
167}
168
Wang Huanf0ce7d62014-09-05 13:52:44 +0800169int dram_init(void)
170{
Chenhui Zhao50966942014-11-06 10:51:59 +0800171 /*
172 * When resuming from deep sleep, the I2C channel may not be
173 * in the default channel. So, switch to the default channel
174 * before accessing DDR SPD.
Biwen Lid15aa9f2019-12-31 15:33:44 +0800175 *
176 * PCA9547(0x77) mount on I2C1 bus
Chenhui Zhao50966942014-11-06 10:51:59 +0800177 */
Biwen Lid15aa9f2019-12-31 15:33:44 +0800178 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600179 return fsl_initdram();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800180}
181
Wang Huanf0ce7d62014-09-05 13:52:44 +0800182int board_early_init_f(void)
183{
184 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800185
186#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300187 /* clear BD & FR bits for BE BD's and frame data */
188 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800189#endif
190
191#ifdef CONFIG_FSL_IFC
192 init_early_memctl_regs();
193#endif
194
Yao Yuane0f8f542015-12-05 14:59:10 +0800195 arch_soc_init();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800196
tang yuantian57296e72014-12-17 12:58:05 +0800197#if defined(CONFIG_DEEP_SLEEP)
198 if (is_warm_boot())
199 fsl_dp_disable_console();
200#endif
201
Wang Huanf0ce7d62014-09-05 13:52:44 +0800202 return 0;
203}
Alison Wang9da51782014-12-03 15:00:47 +0800204
205#ifdef CONFIG_SPL_BUILD
206void board_init_f(ulong dummy)
207{
Alison Wangab98bb52014-12-09 17:38:14 +0800208#ifdef CONFIG_NAND_BOOT
209 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
210 u32 porsr1, pinctl;
211
212 /*
213 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
214 * NAND boot because IFC signals > IFC_AD7 are not enabled.
215 * This workaround changes RCW source to make all signals enabled.
216 */
217 porsr1 = in_be32(&gur->porsr1);
218 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
219 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
220 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
221 pinctl);
222#endif
223
Alison Wang9da51782014-12-03 15:00:47 +0800224 /* Clear the BSS */
225 memset(__bss_start, 0, __bss_end - __bss_start);
226
227#ifdef CONFIG_FSL_IFC
228 init_early_memctl_regs();
229#endif
230
231 get_clocks();
232
tang yuantian57296e72014-12-17 12:58:05 +0800233#if defined(CONFIG_DEEP_SLEEP)
234 if (is_warm_boot())
235 fsl_dp_disable_console();
236#endif
237
Alison Wang9da51782014-12-03 15:00:47 +0800238 preloader_console_init();
239
240#ifdef CONFIG_SPL_I2C_SUPPORT
241 i2c_init_all();
242#endif
Alison Wang6027eb42015-03-12 11:31:44 +0800243
Alison Wang28253032018-10-16 16:19:22 +0800244 timer_init();
Alison Wang9da51782014-12-03 15:00:47 +0800245 dram_init();
246
Alison Wang5dec9d72015-07-09 10:50:07 +0800247 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800248#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
249 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800250#endif
251
Alison Wang9da51782014-12-03 15:00:47 +0800252 board_init_r(NULL, 0);
253}
254#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800255
Alison Wang29d75432014-12-09 17:38:23 +0800256void config_etseccm_source(int etsec_gtx_125_mux)
257{
258 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
259
260 switch (etsec_gtx_125_mux) {
261 case GE0_CLK125:
262 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
263 debug("etseccm set to GE0_CLK125\n");
264 break;
265
266 case GE2_CLK125:
267 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
268 debug("etseccm set to GE2_CLK125\n");
269 break;
270
271 case GE1_CLK125:
272 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
273 debug("etseccm set to GE1_CLK125\n");
274 break;
275
276 default:
277 printf("Error! trying to set etseccm to invalid value\n");
278 break;
279 }
280}
281
Wang Huanf0ce7d62014-09-05 13:52:44 +0800282int config_board_mux(int ctrl_type)
283{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800284 u8 reg12, reg14;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800285
286 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800287 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800288
289 switch (ctrl_type) {
Yao Yuanfec6aa02014-11-26 14:54:33 +0800290 case MUX_TYPE_CAN:
Alison Wang29d75432014-12-09 17:38:23 +0800291 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800292 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
293 break;
294 case MUX_TYPE_IIC2:
295 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
296 break;
297 case MUX_TYPE_RGMII:
298 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
299 break;
300 case MUX_TYPE_SAI:
Alison Wang29d75432014-12-09 17:38:23 +0800301 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800302 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
303 break;
304 case MUX_TYPE_SDHC:
305 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
306 break;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800307 case MUX_TYPE_SD_PCI4:
308 reg12 = 0x38;
309 break;
310 case MUX_TYPE_SD_PC_SA_SG_SG:
311 reg12 = 0x01;
312 break;
313 case MUX_TYPE_SD_PC_SA_PC_SG:
314 reg12 = 0x01;
315 break;
316 case MUX_TYPE_SD_PC_SG_SG:
317 reg12 = 0x21;
318 break;
319 default:
320 printf("Wrong mux interface type\n");
321 return -1;
322 }
323
324 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800325 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800326
327 return 0;
328}
329
330int config_serdes_mux(void)
331{
332 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
333 u32 cfg;
334
335 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
336 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
337
338 switch (cfg) {
339 case 0x0:
340 config_board_mux(MUX_TYPE_SD_PCI4);
341 break;
342 case 0x30:
343 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
344 break;
345 case 0x60:
346 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
347 break;
348 case 0x70:
349 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
350 break;
351 default:
352 printf("SRDS1 prtcl:0x%x\n", cfg);
353 break;
354 }
355
356 return 0;
357}
358
tang yuantian9f51db22015-10-16 16:06:05 +0800359#ifdef CONFIG_BOARD_LATE_INIT
360int board_late_init(void)
361{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530362#ifdef CONFIG_CHAIN_OF_TRUST
363 fsl_setenv_chain_of_trust();
364#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800365
366 return 0;
367}
368#endif
369
Ruchika Gupta901ae762014-10-15 11:39:06 +0530370int misc_init_r(void)
371{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800372 int conflict_flag;
373
374 /* some signals can not enable simultaneous*/
375 conflict_flag = 0;
376 if (hwconfig("sdhc"))
377 conflict_flag++;
378 if (hwconfig("iic2"))
379 conflict_flag++;
380 if (conflict_flag > 1) {
381 printf("WARNING: pin conflict !\n");
382 return 0;
383 }
384
385 conflict_flag = 0;
386 if (hwconfig("rgmii"))
387 conflict_flag++;
388 if (hwconfig("can"))
389 conflict_flag++;
390 if (hwconfig("sai"))
391 conflict_flag++;
392 if (conflict_flag > 1) {
393 printf("WARNING: pin conflict !\n");
394 return 0;
395 }
396
397 if (hwconfig("can"))
398 config_board_mux(MUX_TYPE_CAN);
399 else if (hwconfig("rgmii"))
400 config_board_mux(MUX_TYPE_RGMII);
401 else if (hwconfig("sai"))
402 config_board_mux(MUX_TYPE_SAI);
403
404 if (hwconfig("iic2"))
405 config_board_mux(MUX_TYPE_IIC2);
406 else if (hwconfig("sdhc"))
407 config_board_mux(MUX_TYPE_SDHC);
408
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800409#ifdef CONFIG_FSL_DEVICE_DISABLE
410 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
411#endif
Ruchika Gupta901ae762014-10-15 11:39:06 +0530412#ifdef CONFIG_FSL_CAAM
413 return sec_init();
414#endif
Yao Yuanfec6aa02014-11-26 14:54:33 +0800415 return 0;
Ruchika Gupta901ae762014-10-15 11:39:06 +0530416}
Ruchika Gupta901ae762014-10-15 11:39:06 +0530417
Wang Huanf0ce7d62014-09-05 13:52:44 +0800418int board_init(void)
419{
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800420#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
421 erratum_a010315();
422#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +0800423#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
424 erratum_a009942_check_cpo();
425#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800426
Biwen Lid15aa9f2019-12-31 15:33:44 +0800427 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800428
429#ifndef CONFIG_SYS_FSL_NO_SERDES
430 fsl_serdes_init();
431 config_serdes_mux();
432#endif
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800433
Alison Wang69364922016-02-05 12:48:17 +0800434 ls102xa_smmu_stream_id_init();
Xiubo Li03d40aa2014-11-21 17:40:59 +0800435
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800436#ifdef CONFIG_U_QE
437 u_qe_init();
438#endif
439
Wang Huanf0ce7d62014-09-05 13:52:44 +0800440 return 0;
441}
tang yuantian57296e72014-12-17 12:58:05 +0800442
443#if defined(CONFIG_DEEP_SLEEP)
444void board_sleep_prepare(void)
445{
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800446#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
447 enable_layerscape_ns_access();
tang yuantian57296e72014-12-17 12:58:05 +0800448#endif
449}
450#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800451
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900452int ft_board_setup(void *blob, struct bd_info *bd)
Wang Huanf0ce7d62014-09-05 13:52:44 +0800453{
454 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600455
Minghuan Lian0c535242015-03-12 10:58:48 +0800456#ifdef CONFIG_PCI
457 ft_pci_setup(blob, bd);
Minghuan Liana4d6b612014-10-31 13:43:44 +0800458#endif
459
Simon Glass2aec3cc2014-10-23 18:58:47 -0600460 return 0;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800461}
462
463u8 flash_read8(void *addr)
464{
465 return __raw_readb(addr + 1);
466}
467
468void flash_write16(u16 val, void *addr)
469{
470 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
471
472 __raw_writew(shftval, addr);
473}
474
475u16 flash_read16(void *addr)
476{
477 u16 val = __raw_readw(addr);
478
479 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
480}