blob: 1ae822e5107b55675386b3fa164526914fbd7ea7 [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>
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>
Yao Yuanfec6aa02014-11-26 14:54:33 +080018#include <hwconfig.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080019#include <mmc.h>
Mingkai Hu5b0df8a2015-10-26 19:47:41 +080020#include <fsl_csu.h>
Wang Huanf0ce7d62014-09-05 13:52:44 +080021#include <fsl_ifc.h>
Ruchika Gupta901ae762014-10-15 11:39:06 +053022#include <fsl_sec.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>
tang yuantian57296e72014-12-17 12:58:05 +080027#include "../common/sleep.h"
Wang Huanf0ce7d62014-09-05 13:52:44 +080028#include "../common/qixis.h"
29#include "ls1021aqds_qixis.h"
Zhao Qiang9fc2f302014-09-26 16:25:32 +080030#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080031#include <fsl_qe.h>
Zhao Qiang9fc2f302014-09-26 16:25:32 +080032#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080033
Yao Yuanfec6aa02014-11-26 14:54:33 +080034#define PIN_MUX_SEL_CAN 0x03
35#define PIN_MUX_SEL_IIC2 0xa0
36#define PIN_MUX_SEL_RGMII 0x00
37#define PIN_MUX_SEL_SAI 0x0c
38#define PIN_MUX_SEL_SDHC 0x00
39
40#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0x0f) | value)
41#define SET_EC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
Wang Huanf0ce7d62014-09-05 13:52:44 +080042enum {
Yao Yuanfec6aa02014-11-26 14:54:33 +080043 MUX_TYPE_CAN,
44 MUX_TYPE_IIC2,
45 MUX_TYPE_RGMII,
46 MUX_TYPE_SAI,
47 MUX_TYPE_SDHC,
Wang Huanf0ce7d62014-09-05 13:52:44 +080048 MUX_TYPE_SD_PCI4,
49 MUX_TYPE_SD_PC_SA_SG_SG,
50 MUX_TYPE_SD_PC_SA_PC_SG,
51 MUX_TYPE_SD_PC_SG_SG,
52};
53
Alison Wang29d75432014-12-09 17:38:23 +080054enum {
55 GE0_CLK125,
56 GE2_CLK125,
57 GE1_CLK125,
58};
59
Wang Huanf0ce7d62014-09-05 13:52:44 +080060int checkboard(void)
61{
Alison Wang34de5e42016-02-02 15:16:23 +080062#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanf0ce7d62014-09-05 13:52:44 +080063 char buf[64];
Alison Wang2145a372014-12-09 17:38:02 +080064#endif
Alison Wang9da51782014-12-03 15:00:47 +080065#if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
Wang Huanf0ce7d62014-09-05 13:52:44 +080066 u8 sw;
Alison Wang9da51782014-12-03 15:00:47 +080067#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080068
69 puts("Board: LS1021AQDS\n");
70
Alison Wang9da51782014-12-03 15:00:47 +080071#ifdef CONFIG_SD_BOOT
72 puts("SD\n");
73#elif CONFIG_QSPI_BOOT
74 puts("QSPI\n");
75#else
Wang Huanf0ce7d62014-09-05 13:52:44 +080076 sw = QIXIS_READ(brdcfg[0]);
77 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
78
79 if (sw < 0x8)
80 printf("vBank: %d\n", sw);
81 else if (sw == 0x8)
82 puts("PromJet\n");
83 else if (sw == 0x9)
84 puts("NAND\n");
85 else if (sw == 0x15)
86 printf("IFCCard\n");
87 else
88 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Alison Wang9da51782014-12-03 15:00:47 +080089#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080090
Alison Wang34de5e42016-02-02 15:16:23 +080091#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanf0ce7d62014-09-05 13:52:44 +080092 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
93 QIXIS_READ(id), QIXIS_READ(arch));
94
95 printf("FPGA: v%d (%s), build %d\n",
96 (int)QIXIS_READ(scver), qixis_read_tag(buf),
97 (int)qixis_read_minor());
Alison Wang2145a372014-12-09 17:38:02 +080098#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +080099
100 return 0;
101}
102
103unsigned long get_board_sys_clk(void)
104{
105 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
106
107 switch (sysclk_conf & 0x0f) {
108 case QIXIS_SYSCLK_64:
109 return 64000000;
110 case QIXIS_SYSCLK_83:
111 return 83333333;
112 case QIXIS_SYSCLK_100:
113 return 100000000;
114 case QIXIS_SYSCLK_125:
115 return 125000000;
116 case QIXIS_SYSCLK_133:
117 return 133333333;
118 case QIXIS_SYSCLK_150:
119 return 150000000;
120 case QIXIS_SYSCLK_160:
121 return 160000000;
122 case QIXIS_SYSCLK_166:
123 return 166666666;
124 }
125 return 66666666;
126}
127
128unsigned long get_board_ddr_clk(void)
129{
130 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
131
132 switch ((ddrclk_conf & 0x30) >> 4) {
133 case QIXIS_DDRCLK_100:
134 return 100000000;
135 case QIXIS_DDRCLK_125:
136 return 125000000;
137 case QIXIS_DDRCLK_133:
138 return 133333333;
139 }
140 return 66666666;
141}
142
Biwen Lid15aa9f2019-12-31 15:33:44 +0800143int select_i2c_ch_pca9547(u8 ch, int bus_num)
Chenhui Zhao50966942014-11-06 10:51:59 +0800144{
145 int ret;
Biwen Lid15aa9f2019-12-31 15:33:44 +0800146#ifdef CONFIG_DM_I2C
147 struct udevice *dev;
Chenhui Zhao50966942014-11-06 10:51:59 +0800148
Biwen Lid15aa9f2019-12-31 15:33:44 +0800149 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
150 1, &dev);
151 if (ret) {
152 printf("%s: Cannot find udev for a bus %d\n", __func__,
153 bus_num);
154 return ret;
155 }
156 ret = dm_i2c_write(dev, 0, &ch, 1);
157#else
Chenhui Zhao50966942014-11-06 10:51:59 +0800158 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Lid15aa9f2019-12-31 15:33:44 +0800159#endif
Chenhui Zhao50966942014-11-06 10:51:59 +0800160 if (ret) {
161 puts("PCA: failed to select proper channel\n");
162 return ret;
163 }
164
165 return 0;
166}
167
Wang Huanf0ce7d62014-09-05 13:52:44 +0800168int dram_init(void)
169{
Chenhui Zhao50966942014-11-06 10:51:59 +0800170 /*
171 * When resuming from deep sleep, the I2C channel may not be
172 * in the default channel. So, switch to the default channel
173 * before accessing DDR SPD.
Biwen Lid15aa9f2019-12-31 15:33:44 +0800174 *
175 * PCA9547(0x77) mount on I2C1 bus
Chenhui Zhao50966942014-11-06 10:51:59 +0800176 */
Biwen Lid15aa9f2019-12-31 15:33:44 +0800177 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600178 return fsl_initdram();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800179}
180
Wang Huanf0ce7d62014-09-05 13:52:44 +0800181int board_early_init_f(void)
182{
183 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800184
185#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300186 /* clear BD & FR bits for BE BD's and frame data */
187 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800188#endif
189
190#ifdef CONFIG_FSL_IFC
191 init_early_memctl_regs();
192#endif
193
Yao Yuane0f8f542015-12-05 14:59:10 +0800194 arch_soc_init();
Wang Huanf0ce7d62014-09-05 13:52:44 +0800195
tang yuantian57296e72014-12-17 12:58:05 +0800196#if defined(CONFIG_DEEP_SLEEP)
197 if (is_warm_boot())
198 fsl_dp_disable_console();
199#endif
200
Wang Huanf0ce7d62014-09-05 13:52:44 +0800201 return 0;
202}
Alison Wang9da51782014-12-03 15:00:47 +0800203
204#ifdef CONFIG_SPL_BUILD
205void board_init_f(ulong dummy)
206{
Alison Wangab98bb52014-12-09 17:38:14 +0800207#ifdef CONFIG_NAND_BOOT
208 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
209 u32 porsr1, pinctl;
210
211 /*
212 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
213 * NAND boot because IFC signals > IFC_AD7 are not enabled.
214 * This workaround changes RCW source to make all signals enabled.
215 */
216 porsr1 = in_be32(&gur->porsr1);
217 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
218 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
219 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
220 pinctl);
221#endif
222
Alison Wang9da51782014-12-03 15:00:47 +0800223 /* Clear the BSS */
224 memset(__bss_start, 0, __bss_end - __bss_start);
225
226#ifdef CONFIG_FSL_IFC
227 init_early_memctl_regs();
228#endif
229
230 get_clocks();
231
tang yuantian57296e72014-12-17 12:58:05 +0800232#if defined(CONFIG_DEEP_SLEEP)
233 if (is_warm_boot())
234 fsl_dp_disable_console();
235#endif
236
Alison Wang9da51782014-12-03 15:00:47 +0800237 preloader_console_init();
238
239#ifdef CONFIG_SPL_I2C_SUPPORT
240 i2c_init_all();
241#endif
Alison Wang6027eb42015-03-12 11:31:44 +0800242
Alison Wang28253032018-10-16 16:19:22 +0800243 timer_init();
Alison Wang9da51782014-12-03 15:00:47 +0800244 dram_init();
245
Alison Wang5dec9d72015-07-09 10:50:07 +0800246 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800247#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
248 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800249#endif
250
Alison Wang9da51782014-12-03 15:00:47 +0800251 board_init_r(NULL, 0);
252}
253#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800254
Alison Wang29d75432014-12-09 17:38:23 +0800255void config_etseccm_source(int etsec_gtx_125_mux)
256{
257 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
258
259 switch (etsec_gtx_125_mux) {
260 case GE0_CLK125:
261 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
262 debug("etseccm set to GE0_CLK125\n");
263 break;
264
265 case GE2_CLK125:
266 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
267 debug("etseccm set to GE2_CLK125\n");
268 break;
269
270 case GE1_CLK125:
271 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
272 debug("etseccm set to GE1_CLK125\n");
273 break;
274
275 default:
276 printf("Error! trying to set etseccm to invalid value\n");
277 break;
278 }
279}
280
Wang Huanf0ce7d62014-09-05 13:52:44 +0800281int config_board_mux(int ctrl_type)
282{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800283 u8 reg12, reg14;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800284
285 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800286 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800287
288 switch (ctrl_type) {
Yao Yuanfec6aa02014-11-26 14:54:33 +0800289 case MUX_TYPE_CAN:
Alison Wang29d75432014-12-09 17:38:23 +0800290 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800291 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
292 break;
293 case MUX_TYPE_IIC2:
294 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
295 break;
296 case MUX_TYPE_RGMII:
297 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
298 break;
299 case MUX_TYPE_SAI:
Alison Wang29d75432014-12-09 17:38:23 +0800300 config_etseccm_source(GE2_CLK125);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800301 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
302 break;
303 case MUX_TYPE_SDHC:
304 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
305 break;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800306 case MUX_TYPE_SD_PCI4:
307 reg12 = 0x38;
308 break;
309 case MUX_TYPE_SD_PC_SA_SG_SG:
310 reg12 = 0x01;
311 break;
312 case MUX_TYPE_SD_PC_SA_PC_SG:
313 reg12 = 0x01;
314 break;
315 case MUX_TYPE_SD_PC_SG_SG:
316 reg12 = 0x21;
317 break;
318 default:
319 printf("Wrong mux interface type\n");
320 return -1;
321 }
322
323 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanfec6aa02014-11-26 14:54:33 +0800324 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800325
326 return 0;
327}
328
329int config_serdes_mux(void)
330{
331 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
332 u32 cfg;
333
334 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
335 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
336
337 switch (cfg) {
338 case 0x0:
339 config_board_mux(MUX_TYPE_SD_PCI4);
340 break;
341 case 0x30:
342 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
343 break;
344 case 0x60:
345 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
346 break;
347 case 0x70:
348 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
349 break;
350 default:
351 printf("SRDS1 prtcl:0x%x\n", cfg);
352 break;
353 }
354
355 return 0;
356}
357
tang yuantian9f51db22015-10-16 16:06:05 +0800358#ifdef CONFIG_BOARD_LATE_INIT
359int board_late_init(void)
360{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530361#ifdef CONFIG_CHAIN_OF_TRUST
362 fsl_setenv_chain_of_trust();
363#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800364
365 return 0;
366}
367#endif
368
Ruchika Gupta901ae762014-10-15 11:39:06 +0530369int misc_init_r(void)
370{
Yao Yuanfec6aa02014-11-26 14:54:33 +0800371 int conflict_flag;
372
373 /* some signals can not enable simultaneous*/
374 conflict_flag = 0;
375 if (hwconfig("sdhc"))
376 conflict_flag++;
377 if (hwconfig("iic2"))
378 conflict_flag++;
379 if (conflict_flag > 1) {
380 printf("WARNING: pin conflict !\n");
381 return 0;
382 }
383
384 conflict_flag = 0;
385 if (hwconfig("rgmii"))
386 conflict_flag++;
387 if (hwconfig("can"))
388 conflict_flag++;
389 if (hwconfig("sai"))
390 conflict_flag++;
391 if (conflict_flag > 1) {
392 printf("WARNING: pin conflict !\n");
393 return 0;
394 }
395
396 if (hwconfig("can"))
397 config_board_mux(MUX_TYPE_CAN);
398 else if (hwconfig("rgmii"))
399 config_board_mux(MUX_TYPE_RGMII);
400 else if (hwconfig("sai"))
401 config_board_mux(MUX_TYPE_SAI);
402
403 if (hwconfig("iic2"))
404 config_board_mux(MUX_TYPE_IIC2);
405 else if (hwconfig("sdhc"))
406 config_board_mux(MUX_TYPE_SDHC);
407
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800408#ifdef CONFIG_FSL_DEVICE_DISABLE
409 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
410#endif
Ruchika Gupta901ae762014-10-15 11:39:06 +0530411#ifdef CONFIG_FSL_CAAM
412 return sec_init();
413#endif
Yao Yuanfec6aa02014-11-26 14:54:33 +0800414 return 0;
Ruchika Gupta901ae762014-10-15 11:39:06 +0530415}
Ruchika Gupta901ae762014-10-15 11:39:06 +0530416
Wang Huanf0ce7d62014-09-05 13:52:44 +0800417int board_init(void)
418{
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800419#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
420 erratum_a010315();
421#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +0800422#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
423 erratum_a009942_check_cpo();
424#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800425
Biwen Lid15aa9f2019-12-31 15:33:44 +0800426 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Wang Huanf0ce7d62014-09-05 13:52:44 +0800427
428#ifndef CONFIG_SYS_FSL_NO_SERDES
429 fsl_serdes_init();
430 config_serdes_mux();
431#endif
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800432
Alison Wang69364922016-02-05 12:48:17 +0800433 ls102xa_smmu_stream_id_init();
Xiubo Li03d40aa2014-11-21 17:40:59 +0800434
Zhao Qiang9fc2f302014-09-26 16:25:32 +0800435#ifdef CONFIG_U_QE
436 u_qe_init();
437#endif
438
Wang Huanf0ce7d62014-09-05 13:52:44 +0800439 return 0;
440}
tang yuantian57296e72014-12-17 12:58:05 +0800441
442#if defined(CONFIG_DEEP_SLEEP)
443void board_sleep_prepare(void)
444{
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800445#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
446 enable_layerscape_ns_access();
tang yuantian57296e72014-12-17 12:58:05 +0800447#endif
448}
449#endif
Wang Huanf0ce7d62014-09-05 13:52:44 +0800450
Simon Glass2aec3cc2014-10-23 18:58:47 -0600451int ft_board_setup(void *blob, bd_t *bd)
Wang Huanf0ce7d62014-09-05 13:52:44 +0800452{
453 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600454
Minghuan Lian0c535242015-03-12 10:58:48 +0800455#ifdef CONFIG_PCI
456 ft_pci_setup(blob, bd);
Minghuan Liana4d6b612014-10-31 13:43:44 +0800457#endif
458
Simon Glass2aec3cc2014-10-23 18:58:47 -0600459 return 0;
Wang Huanf0ce7d62014-09-05 13:52:44 +0800460}
461
462u8 flash_read8(void *addr)
463{
464 return __raw_readb(addr + 1);
465}
466
467void flash_write16(u16 val, void *addr)
468{
469 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
470
471 __raw_writew(shftval, addr);
472}
473
474u16 flash_read16(void *addr)
475{
476 u16 val = __raw_readw(addr);
477
478 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
479}