blob: 691e828c020242b805e995baff43afbec155ed1b [file] [log] [blame]
Wang Huan550e3dc2014-09-05 13:52:44 +08001/*
2 * Copyright 2014 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <i2c.h>
9#include <asm/io.h>
10#include <asm/arch/immap_ls102xa.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/fsl_serdes.h>
Minghuan Lianda419022014-10-31 13:43:44 +080013#include <asm/pcie_layerscape.h>
Wang Huan550e3dc2014-09-05 13:52:44 +080014#include <mmc.h>
15#include <fsl_esdhc.h>
16#include <fsl_ifc.h>
Ruchika Gupta4ba4a092014-10-15 11:39:06 +053017#include <fsl_sec.h>
Alison Wang86949c22014-12-03 15:00:47 +080018#include <spl.h>
Wang Huan550e3dc2014-09-05 13:52:44 +080019
20#include "../common/qixis.h"
21#include "ls1021aqds_qixis.h"
Zhao Qiang63e75fd2014-09-26 16:25:32 +080022#ifdef CONFIG_U_QE
23#include "../../../drivers/qe/qe.h"
24#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080025
26DECLARE_GLOBAL_DATA_PTR;
27
28enum {
29 MUX_TYPE_SD_PCI4,
30 MUX_TYPE_SD_PC_SA_SG_SG,
31 MUX_TYPE_SD_PC_SA_PC_SG,
32 MUX_TYPE_SD_PC_SG_SG,
33};
34
35int checkboard(void)
36{
Alison Wangd612f0a2014-12-09 17:38:02 +080037#ifndef CONFIG_QSPI_BOOT
Wang Huan550e3dc2014-09-05 13:52:44 +080038 char buf[64];
Alison Wangd612f0a2014-12-09 17:38:02 +080039#endif
Alison Wang86949c22014-12-03 15:00:47 +080040#if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
Wang Huan550e3dc2014-09-05 13:52:44 +080041 u8 sw;
Alison Wang86949c22014-12-03 15:00:47 +080042#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080043
44 puts("Board: LS1021AQDS\n");
45
Alison Wang86949c22014-12-03 15:00:47 +080046#ifdef CONFIG_SD_BOOT
47 puts("SD\n");
48#elif CONFIG_QSPI_BOOT
49 puts("QSPI\n");
50#else
Wang Huan550e3dc2014-09-05 13:52:44 +080051 sw = QIXIS_READ(brdcfg[0]);
52 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
53
54 if (sw < 0x8)
55 printf("vBank: %d\n", sw);
56 else if (sw == 0x8)
57 puts("PromJet\n");
58 else if (sw == 0x9)
59 puts("NAND\n");
60 else if (sw == 0x15)
61 printf("IFCCard\n");
62 else
63 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Alison Wang86949c22014-12-03 15:00:47 +080064#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080065
Alison Wangd612f0a2014-12-09 17:38:02 +080066#ifndef CONFIG_QSPI_BOOT
Wang Huan550e3dc2014-09-05 13:52:44 +080067 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
68 QIXIS_READ(id), QIXIS_READ(arch));
69
70 printf("FPGA: v%d (%s), build %d\n",
71 (int)QIXIS_READ(scver), qixis_read_tag(buf),
72 (int)qixis_read_minor());
Alison Wangd612f0a2014-12-09 17:38:02 +080073#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080074
75 return 0;
76}
77
78unsigned long get_board_sys_clk(void)
79{
80 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
81
82 switch (sysclk_conf & 0x0f) {
83 case QIXIS_SYSCLK_64:
84 return 64000000;
85 case QIXIS_SYSCLK_83:
86 return 83333333;
87 case QIXIS_SYSCLK_100:
88 return 100000000;
89 case QIXIS_SYSCLK_125:
90 return 125000000;
91 case QIXIS_SYSCLK_133:
92 return 133333333;
93 case QIXIS_SYSCLK_150:
94 return 150000000;
95 case QIXIS_SYSCLK_160:
96 return 160000000;
97 case QIXIS_SYSCLK_166:
98 return 166666666;
99 }
100 return 66666666;
101}
102
103unsigned long get_board_ddr_clk(void)
104{
105 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
106
107 switch ((ddrclk_conf & 0x30) >> 4) {
108 case QIXIS_DDRCLK_100:
109 return 100000000;
110 case QIXIS_DDRCLK_125:
111 return 125000000;
112 case QIXIS_DDRCLK_133:
113 return 133333333;
114 }
115 return 66666666;
116}
117
Chenhui Zhaoafff1372014-11-06 10:51:59 +0800118int select_i2c_ch_pca9547(u8 ch)
119{
120 int ret;
121
122 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
123 if (ret) {
124 puts("PCA: failed to select proper channel\n");
125 return ret;
126 }
127
128 return 0;
129}
130
Wang Huan550e3dc2014-09-05 13:52:44 +0800131int dram_init(void)
132{
Chenhui Zhaoafff1372014-11-06 10:51:59 +0800133 /*
134 * When resuming from deep sleep, the I2C channel may not be
135 * in the default channel. So, switch to the default channel
136 * before accessing DDR SPD.
137 */
138 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Wang Huan550e3dc2014-09-05 13:52:44 +0800139 gd->ram_size = initdram(0);
140
141 return 0;
142}
143
144#ifdef CONFIG_FSL_ESDHC
145struct fsl_esdhc_cfg esdhc_cfg[1] = {
146 {CONFIG_SYS_FSL_ESDHC_ADDR},
147};
148
149int board_mmc_init(bd_t *bis)
150{
151 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
152
153 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
154}
155#endif
156
Wang Huan550e3dc2014-09-05 13:52:44 +0800157int board_early_init_f(void)
158{
159 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
160 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
161
162#ifdef CONFIG_TSEC_ENET
Wang Huan550e3dc2014-09-05 13:52:44 +0800163 out_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Alison Wang0ab17232014-10-17 15:26:36 +0800164 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
Wang Huan550e3dc2014-09-05 13:52:44 +0800165#endif
166
167#ifdef CONFIG_FSL_IFC
168 init_early_memctl_regs();
169#endif
170
Alison Wangd612f0a2014-12-09 17:38:02 +0800171#ifdef CONFIG_FSL_QSPI
172 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
173#endif
174
Wang Huan550e3dc2014-09-05 13:52:44 +0800175 /* Workaround for the issue that DDR could not respond to
176 * barrier transaction which is generated by executing DSB/ISB
177 * instruction. Set CCI-400 control override register to
178 * terminate the barrier transaction. After DDR is initialized,
179 * allow barrier transaction to DDR again */
180 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
181
182 return 0;
183}
184
Alison Wang86949c22014-12-03 15:00:47 +0800185#ifdef CONFIG_SPL_BUILD
186void board_init_f(ulong dummy)
187{
188 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
189
Alison Wang8ab967b2014-12-09 17:38:14 +0800190#ifdef CONFIG_NAND_BOOT
191 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
192 u32 porsr1, pinctl;
193
194 /*
195 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
196 * NAND boot because IFC signals > IFC_AD7 are not enabled.
197 * This workaround changes RCW source to make all signals enabled.
198 */
199 porsr1 = in_be32(&gur->porsr1);
200 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
201 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
202 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
203 pinctl);
204#endif
205
Alison Wang86949c22014-12-03 15:00:47 +0800206 /* Set global data pointer */
207 gd = &gdata;
208
209 /* Clear the BSS */
210 memset(__bss_start, 0, __bss_end - __bss_start);
211
212#ifdef CONFIG_FSL_IFC
213 init_early_memctl_regs();
214#endif
215
216 get_clocks();
217
218 preloader_console_init();
219
220#ifdef CONFIG_SPL_I2C_SUPPORT
221 i2c_init_all();
222#endif
223 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
224
225 dram_init();
226
227 board_init_r(NULL, 0);
228}
229#endif
230
Wang Huan550e3dc2014-09-05 13:52:44 +0800231int config_board_mux(int ctrl_type)
232{
233 u8 reg12;
234
235 reg12 = QIXIS_READ(brdcfg[12]);
236
237 switch (ctrl_type) {
238 case MUX_TYPE_SD_PCI4:
239 reg12 = 0x38;
240 break;
241 case MUX_TYPE_SD_PC_SA_SG_SG:
242 reg12 = 0x01;
243 break;
244 case MUX_TYPE_SD_PC_SA_PC_SG:
245 reg12 = 0x01;
246 break;
247 case MUX_TYPE_SD_PC_SG_SG:
248 reg12 = 0x21;
249 break;
250 default:
251 printf("Wrong mux interface type\n");
252 return -1;
253 }
254
255 QIXIS_WRITE(brdcfg[12], reg12);
256
257 return 0;
258}
259
260int config_serdes_mux(void)
261{
262 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
263 u32 cfg;
264
265 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
266 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
267
268 switch (cfg) {
269 case 0x0:
270 config_board_mux(MUX_TYPE_SD_PCI4);
271 break;
272 case 0x30:
273 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
274 break;
275 case 0x60:
276 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
277 break;
278 case 0x70:
279 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
280 break;
281 default:
282 printf("SRDS1 prtcl:0x%x\n", cfg);
283 break;
284 }
285
286 return 0;
287}
288
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530289#if defined(CONFIG_MISC_INIT_R)
290int misc_init_r(void)
291{
292#ifdef CONFIG_FSL_CAAM
293 return sec_init();
294#endif
295}
296#endif
297
Wang Huan550e3dc2014-09-05 13:52:44 +0800298int board_init(void)
299{
300 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
301
302 /* Set CCI-400 control override register to
303 * enable barrier transaction */
304 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Jason Jin644bc7e2014-10-17 15:26:32 +0800305 /*
306 * Set CCI-400 Slave interface S0, S1, S2 Shareable Override Register
307 * All transactions are treated as non-shareable
308 */
309 out_le32(&cci->slave[0].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
310 out_le32(&cci->slave[1].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
311 out_le32(&cci->slave[2].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
Wang Huan550e3dc2014-09-05 13:52:44 +0800312
313 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
314
315#ifndef CONFIG_SYS_FSL_NO_SERDES
316 fsl_serdes_init();
317 config_serdes_mux();
318#endif
Zhao Qiang63e75fd2014-09-26 16:25:32 +0800319
320#ifdef CONFIG_U_QE
321 u_qe_init();
322#endif
323
Wang Huan550e3dc2014-09-05 13:52:44 +0800324 return 0;
325}
326
Simon Glasse895a4b2014-10-23 18:58:47 -0600327int ft_board_setup(void *blob, bd_t *bd)
Wang Huan550e3dc2014-09-05 13:52:44 +0800328{
329 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600330
Minghuan Lianda419022014-10-31 13:43:44 +0800331#ifdef CONFIG_PCIE_LAYERSCAPE
332 ft_pcie_setup(blob, bd);
333#endif
334
Simon Glasse895a4b2014-10-23 18:58:47 -0600335 return 0;
Wang Huan550e3dc2014-09-05 13:52:44 +0800336}
337
338u8 flash_read8(void *addr)
339{
340 return __raw_readb(addr + 1);
341}
342
343void flash_write16(u16 val, void *addr)
344{
345 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
346
347 __raw_writew(shftval, addr);
348}
349
350u16 flash_read16(void *addr)
351{
352 u16 val = __raw_readw(addr);
353
354 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
355}