blob: 377f4b7bce02a90062dae68d61b7062025ec0d5e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huan550e3dc2014-09-05 13:52:44 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Wang Huan550e3dc2014-09-05 13:52:44 +08004 */
5
6#include <common.h>
Simon Glass807765b2019-12-28 10:44:54 -07007#include <fdt_support.h>
Wang Huan550e3dc2014-09-05 13:52:44 +08008#include <i2c.h>
Simon Glass52559322019-11-14 12:57:46 -07009#include <init.h>
Wang Huan550e3dc2014-09-05 13:52:44 +080010#include <asm/io.h>
11#include <asm/arch/immap_ls102xa.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/fsl_serdes.h>
Yao Yuan7ba02612015-12-05 14:59:10 +080014#include <asm/arch/ls102xa_soc.h>
Zhuoyu Zhang03c22442015-08-17 18:55:12 +080015#include <asm/arch/ls102xa_devdis.h>
Yao Yuanbca11bd2014-11-26 14:54:33 +080016#include <hwconfig.h>
Wang Huan550e3dc2014-09-05 13:52:44 +080017#include <mmc.h>
Mingkai Hu435acd82015-10-26 19:47:41 +080018#include <fsl_csu.h>
Wang Huan550e3dc2014-09-05 13:52:44 +080019#include <fsl_ifc.h>
Ruchika Gupta4ba4a092014-10-15 11:39:06 +053020#include <fsl_sec.h>
Alison Wang86949c22014-12-03 15:00:47 +080021#include <spl.h>
Zhuoyu Zhang03c22442015-08-17 18:55:12 +080022#include <fsl_devdis.h>
Aneesh Bansald0412882016-01-22 16:37:26 +053023#include <fsl_validate.h>
Shengzhou Liu02fb2762016-11-21 11:36:48 +080024#include <fsl_ddr.h>
tang yuantian41ba57d2014-12-17 12:58:05 +080025#include "../common/sleep.h"
Wang Huan550e3dc2014-09-05 13:52:44 +080026#include "../common/qixis.h"
27#include "ls1021aqds_qixis.h"
Zhao Qiang63e75fd2014-09-26 16:25:32 +080028#ifdef CONFIG_U_QE
Qianyu Gong2459afb2016-02-18 13:01:59 +080029#include <fsl_qe.h>
Zhao Qiang63e75fd2014-09-26 16:25:32 +080030#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080031
Yao Yuanbca11bd2014-11-26 14:54:33 +080032#define PIN_MUX_SEL_CAN 0x03
33#define PIN_MUX_SEL_IIC2 0xa0
34#define PIN_MUX_SEL_RGMII 0x00
35#define PIN_MUX_SEL_SAI 0x0c
36#define PIN_MUX_SEL_SDHC 0x00
37
38#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0x0f) | value)
39#define SET_EC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
Wang Huan550e3dc2014-09-05 13:52:44 +080040enum {
Yao Yuanbca11bd2014-11-26 14:54:33 +080041 MUX_TYPE_CAN,
42 MUX_TYPE_IIC2,
43 MUX_TYPE_RGMII,
44 MUX_TYPE_SAI,
45 MUX_TYPE_SDHC,
Wang Huan550e3dc2014-09-05 13:52:44 +080046 MUX_TYPE_SD_PCI4,
47 MUX_TYPE_SD_PC_SA_SG_SG,
48 MUX_TYPE_SD_PC_SA_PC_SG,
49 MUX_TYPE_SD_PC_SG_SG,
50};
51
Alison Wang0f5e5572014-12-09 17:38:23 +080052enum {
53 GE0_CLK125,
54 GE2_CLK125,
55 GE1_CLK125,
56};
57
Wang Huan550e3dc2014-09-05 13:52:44 +080058int checkboard(void)
59{
Alison Wang70097022016-02-02 15:16:23 +080060#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huan550e3dc2014-09-05 13:52:44 +080061 char buf[64];
Alison Wangd612f0a2014-12-09 17:38:02 +080062#endif
Alison Wang86949c22014-12-03 15:00:47 +080063#if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
Wang Huan550e3dc2014-09-05 13:52:44 +080064 u8 sw;
Alison Wang86949c22014-12-03 15:00:47 +080065#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080066
67 puts("Board: LS1021AQDS\n");
68
Alison Wang86949c22014-12-03 15:00:47 +080069#ifdef CONFIG_SD_BOOT
70 puts("SD\n");
71#elif CONFIG_QSPI_BOOT
72 puts("QSPI\n");
73#else
Wang Huan550e3dc2014-09-05 13:52:44 +080074 sw = QIXIS_READ(brdcfg[0]);
75 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
76
77 if (sw < 0x8)
78 printf("vBank: %d\n", sw);
79 else if (sw == 0x8)
80 puts("PromJet\n");
81 else if (sw == 0x9)
82 puts("NAND\n");
83 else if (sw == 0x15)
84 printf("IFCCard\n");
85 else
86 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Alison Wang86949c22014-12-03 15:00:47 +080087#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080088
Alison Wang70097022016-02-02 15:16:23 +080089#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huan550e3dc2014-09-05 13:52:44 +080090 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
91 QIXIS_READ(id), QIXIS_READ(arch));
92
93 printf("FPGA: v%d (%s), build %d\n",
94 (int)QIXIS_READ(scver), qixis_read_tag(buf),
95 (int)qixis_read_minor());
Alison Wangd612f0a2014-12-09 17:38:02 +080096#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080097
98 return 0;
99}
100
101unsigned long get_board_sys_clk(void)
102{
103 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
104
105 switch (sysclk_conf & 0x0f) {
106 case QIXIS_SYSCLK_64:
107 return 64000000;
108 case QIXIS_SYSCLK_83:
109 return 83333333;
110 case QIXIS_SYSCLK_100:
111 return 100000000;
112 case QIXIS_SYSCLK_125:
113 return 125000000;
114 case QIXIS_SYSCLK_133:
115 return 133333333;
116 case QIXIS_SYSCLK_150:
117 return 150000000;
118 case QIXIS_SYSCLK_160:
119 return 160000000;
120 case QIXIS_SYSCLK_166:
121 return 166666666;
122 }
123 return 66666666;
124}
125
126unsigned long get_board_ddr_clk(void)
127{
128 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
129
130 switch ((ddrclk_conf & 0x30) >> 4) {
131 case QIXIS_DDRCLK_100:
132 return 100000000;
133 case QIXIS_DDRCLK_125:
134 return 125000000;
135 case QIXIS_DDRCLK_133:
136 return 133333333;
137 }
138 return 66666666;
139}
140
Chenhui Zhaoafff1372014-11-06 10:51:59 +0800141int select_i2c_ch_pca9547(u8 ch)
142{
143 int ret;
144
145 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
146 if (ret) {
147 puts("PCA: failed to select proper channel\n");
148 return ret;
149 }
150
151 return 0;
152}
153
Wang Huan550e3dc2014-09-05 13:52:44 +0800154int dram_init(void)
155{
Chenhui Zhaoafff1372014-11-06 10:51:59 +0800156 /*
157 * When resuming from deep sleep, the I2C channel may not be
158 * in the default channel. So, switch to the default channel
159 * before accessing DDR SPD.
160 */
161 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Simon Glass3eace372017-04-06 12:47:04 -0600162 return fsl_initdram();
Wang Huan550e3dc2014-09-05 13:52:44 +0800163}
164
Wang Huan550e3dc2014-09-05 13:52:44 +0800165int board_early_init_f(void)
166{
167 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Wang Huan550e3dc2014-09-05 13:52:44 +0800168
169#ifdef CONFIG_TSEC_ENET
Claudiu Manoilebe4c1e2015-08-12 13:29:14 +0300170 /* clear BD & FR bits for BE BD's and frame data */
171 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huan550e3dc2014-09-05 13:52:44 +0800172#endif
173
174#ifdef CONFIG_FSL_IFC
175 init_early_memctl_regs();
176#endif
177
Yao Yuan7ba02612015-12-05 14:59:10 +0800178 arch_soc_init();
Wang Huan550e3dc2014-09-05 13:52:44 +0800179
tang yuantian41ba57d2014-12-17 12:58:05 +0800180#if defined(CONFIG_DEEP_SLEEP)
181 if (is_warm_boot())
182 fsl_dp_disable_console();
183#endif
184
Wang Huan550e3dc2014-09-05 13:52:44 +0800185 return 0;
186}
187
Alison Wang86949c22014-12-03 15:00:47 +0800188#ifdef CONFIG_SPL_BUILD
189void board_init_f(ulong dummy)
190{
Alison Wang8ab967b2014-12-09 17:38:14 +0800191#ifdef CONFIG_NAND_BOOT
192 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
193 u32 porsr1, pinctl;
194
195 /*
196 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
197 * NAND boot because IFC signals > IFC_AD7 are not enabled.
198 * This workaround changes RCW source to make all signals enabled.
199 */
200 porsr1 = in_be32(&gur->porsr1);
201 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
202 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
203 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
204 pinctl);
205#endif
206
Alison Wang86949c22014-12-03 15:00:47 +0800207 /* Clear the BSS */
208 memset(__bss_start, 0, __bss_end - __bss_start);
209
210#ifdef CONFIG_FSL_IFC
211 init_early_memctl_regs();
212#endif
213
214 get_clocks();
215
tang yuantian41ba57d2014-12-17 12:58:05 +0800216#if defined(CONFIG_DEEP_SLEEP)
217 if (is_warm_boot())
218 fsl_dp_disable_console();
219#endif
220
Alison Wang86949c22014-12-03 15:00:47 +0800221 preloader_console_init();
222
223#ifdef CONFIG_SPL_I2C_SUPPORT
224 i2c_init_all();
225#endif
Alison Wang036f3f32015-03-12 11:31:44 +0800226
Alison Wangf668c522018-10-16 16:19:22 +0800227 timer_init();
Alison Wang86949c22014-12-03 15:00:47 +0800228 dram_init();
229
Alison Wang8f0c7cb2015-07-09 10:50:07 +0800230 /* Allow OCRAM access permission as R/W */
Mingkai Hu435acd82015-10-26 19:47:41 +0800231#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
232 enable_layerscape_ns_access();
Alison Wang8f0c7cb2015-07-09 10:50:07 +0800233#endif
234
Alison Wang86949c22014-12-03 15:00:47 +0800235 board_init_r(NULL, 0);
236}
237#endif
238
Alison Wang0f5e5572014-12-09 17:38:23 +0800239void config_etseccm_source(int etsec_gtx_125_mux)
240{
241 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
242
243 switch (etsec_gtx_125_mux) {
244 case GE0_CLK125:
245 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
246 debug("etseccm set to GE0_CLK125\n");
247 break;
248
249 case GE2_CLK125:
250 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
251 debug("etseccm set to GE2_CLK125\n");
252 break;
253
254 case GE1_CLK125:
255 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
256 debug("etseccm set to GE1_CLK125\n");
257 break;
258
259 default:
260 printf("Error! trying to set etseccm to invalid value\n");
261 break;
262 }
263}
264
Wang Huan550e3dc2014-09-05 13:52:44 +0800265int config_board_mux(int ctrl_type)
266{
Yao Yuanbca11bd2014-11-26 14:54:33 +0800267 u8 reg12, reg14;
Wang Huan550e3dc2014-09-05 13:52:44 +0800268
269 reg12 = QIXIS_READ(brdcfg[12]);
Yao Yuanbca11bd2014-11-26 14:54:33 +0800270 reg14 = QIXIS_READ(brdcfg[14]);
Wang Huan550e3dc2014-09-05 13:52:44 +0800271
272 switch (ctrl_type) {
Yao Yuanbca11bd2014-11-26 14:54:33 +0800273 case MUX_TYPE_CAN:
Alison Wang0f5e5572014-12-09 17:38:23 +0800274 config_etseccm_source(GE2_CLK125);
Yao Yuanbca11bd2014-11-26 14:54:33 +0800275 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
276 break;
277 case MUX_TYPE_IIC2:
278 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
279 break;
280 case MUX_TYPE_RGMII:
281 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
282 break;
283 case MUX_TYPE_SAI:
Alison Wang0f5e5572014-12-09 17:38:23 +0800284 config_etseccm_source(GE2_CLK125);
Yao Yuanbca11bd2014-11-26 14:54:33 +0800285 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
286 break;
287 case MUX_TYPE_SDHC:
288 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
289 break;
Wang Huan550e3dc2014-09-05 13:52:44 +0800290 case MUX_TYPE_SD_PCI4:
291 reg12 = 0x38;
292 break;
293 case MUX_TYPE_SD_PC_SA_SG_SG:
294 reg12 = 0x01;
295 break;
296 case MUX_TYPE_SD_PC_SA_PC_SG:
297 reg12 = 0x01;
298 break;
299 case MUX_TYPE_SD_PC_SG_SG:
300 reg12 = 0x21;
301 break;
302 default:
303 printf("Wrong mux interface type\n");
304 return -1;
305 }
306
307 QIXIS_WRITE(brdcfg[12], reg12);
Yao Yuanbca11bd2014-11-26 14:54:33 +0800308 QIXIS_WRITE(brdcfg[14], reg14);
Wang Huan550e3dc2014-09-05 13:52:44 +0800309
310 return 0;
311}
312
313int config_serdes_mux(void)
314{
315 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
316 u32 cfg;
317
318 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
319 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
320
321 switch (cfg) {
322 case 0x0:
323 config_board_mux(MUX_TYPE_SD_PCI4);
324 break;
325 case 0x30:
326 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
327 break;
328 case 0x60:
329 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
330 break;
331 case 0x70:
332 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
333 break;
334 default:
335 printf("SRDS1 prtcl:0x%x\n", cfg);
336 break;
337 }
338
339 return 0;
340}
341
tang yuantian4632ad72015-10-16 16:06:05 +0800342#ifdef CONFIG_BOARD_LATE_INIT
343int board_late_init(void)
344{
Aneesh Bansald0412882016-01-22 16:37:26 +0530345#ifdef CONFIG_CHAIN_OF_TRUST
346 fsl_setenv_chain_of_trust();
347#endif
tang yuantian4632ad72015-10-16 16:06:05 +0800348
349 return 0;
350}
351#endif
352
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530353int misc_init_r(void)
354{
Yao Yuanbca11bd2014-11-26 14:54:33 +0800355 int conflict_flag;
356
357 /* some signals can not enable simultaneous*/
358 conflict_flag = 0;
359 if (hwconfig("sdhc"))
360 conflict_flag++;
361 if (hwconfig("iic2"))
362 conflict_flag++;
363 if (conflict_flag > 1) {
364 printf("WARNING: pin conflict !\n");
365 return 0;
366 }
367
368 conflict_flag = 0;
369 if (hwconfig("rgmii"))
370 conflict_flag++;
371 if (hwconfig("can"))
372 conflict_flag++;
373 if (hwconfig("sai"))
374 conflict_flag++;
375 if (conflict_flag > 1) {
376 printf("WARNING: pin conflict !\n");
377 return 0;
378 }
379
380 if (hwconfig("can"))
381 config_board_mux(MUX_TYPE_CAN);
382 else if (hwconfig("rgmii"))
383 config_board_mux(MUX_TYPE_RGMII);
384 else if (hwconfig("sai"))
385 config_board_mux(MUX_TYPE_SAI);
386
387 if (hwconfig("iic2"))
388 config_board_mux(MUX_TYPE_IIC2);
389 else if (hwconfig("sdhc"))
390 config_board_mux(MUX_TYPE_SDHC);
391
Zhuoyu Zhang03c22442015-08-17 18:55:12 +0800392#ifdef CONFIG_FSL_DEVICE_DISABLE
393 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
394#endif
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530395#ifdef CONFIG_FSL_CAAM
396 return sec_init();
397#endif
Yao Yuanbca11bd2014-11-26 14:54:33 +0800398 return 0;
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530399}
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530400
Wang Huan550e3dc2014-09-05 13:52:44 +0800401int board_init(void)
402{
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800403#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
404 erratum_a010315();
405#endif
Shengzhou Liu02fb2762016-11-21 11:36:48 +0800406#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
407 erratum_a009942_check_cpo();
408#endif
Wang Huan550e3dc2014-09-05 13:52:44 +0800409
410 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
411
412#ifndef CONFIG_SYS_FSL_NO_SERDES
413 fsl_serdes_init();
414 config_serdes_mux();
415#endif
Zhao Qiang63e75fd2014-09-26 16:25:32 +0800416
Alison Wanga08b1922016-02-05 12:48:17 +0800417 ls102xa_smmu_stream_id_init();
Xiubo Li660673a2014-11-21 17:40:59 +0800418
Zhao Qiang63e75fd2014-09-26 16:25:32 +0800419#ifdef CONFIG_U_QE
420 u_qe_init();
421#endif
422
Wang Huan550e3dc2014-09-05 13:52:44 +0800423 return 0;
424}
425
tang yuantian41ba57d2014-12-17 12:58:05 +0800426#if defined(CONFIG_DEEP_SLEEP)
427void board_sleep_prepare(void)
428{
Mingkai Hu435acd82015-10-26 19:47:41 +0800429#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
430 enable_layerscape_ns_access();
tang yuantian41ba57d2014-12-17 12:58:05 +0800431#endif
432}
433#endif
434
Simon Glasse895a4b2014-10-23 18:58:47 -0600435int ft_board_setup(void *blob, bd_t *bd)
Wang Huan550e3dc2014-09-05 13:52:44 +0800436{
437 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600438
Minghuan Liand42bd342015-03-12 10:58:48 +0800439#ifdef CONFIG_PCI
440 ft_pci_setup(blob, bd);
Minghuan Lianda419022014-10-31 13:43:44 +0800441#endif
442
Simon Glasse895a4b2014-10-23 18:58:47 -0600443 return 0;
Wang Huan550e3dc2014-09-05 13:52:44 +0800444}
445
446u8 flash_read8(void *addr)
447{
448 return __raw_readb(addr + 1);
449}
450
451void flash_write16(u16 val, void *addr)
452{
453 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
454
455 __raw_writew(shftval, addr);
456}
457
458u16 flash_read16(void *addr)
459{
460 u16 val = __raw_readw(addr);
461
462 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
463}