blob: 9eab42d6c7ea9308dcff3aaadd489633aaf84b19 [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{
37 char buf[64];
Alison Wang86949c22014-12-03 15:00:47 +080038#if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
Wang Huan550e3dc2014-09-05 13:52:44 +080039 u8 sw;
Alison Wang86949c22014-12-03 15:00:47 +080040#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080041
42 puts("Board: LS1021AQDS\n");
43
Alison Wang86949c22014-12-03 15:00:47 +080044#ifdef CONFIG_SD_BOOT
45 puts("SD\n");
46#elif CONFIG_QSPI_BOOT
47 puts("QSPI\n");
48#else
Wang Huan550e3dc2014-09-05 13:52:44 +080049 sw = QIXIS_READ(brdcfg[0]);
50 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
51
52 if (sw < 0x8)
53 printf("vBank: %d\n", sw);
54 else if (sw == 0x8)
55 puts("PromJet\n");
56 else if (sw == 0x9)
57 puts("NAND\n");
58 else if (sw == 0x15)
59 printf("IFCCard\n");
60 else
61 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Alison Wang86949c22014-12-03 15:00:47 +080062#endif
Wang Huan550e3dc2014-09-05 13:52:44 +080063
64 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
65 QIXIS_READ(id), QIXIS_READ(arch));
66
67 printf("FPGA: v%d (%s), build %d\n",
68 (int)QIXIS_READ(scver), qixis_read_tag(buf),
69 (int)qixis_read_minor());
70
71 return 0;
72}
73
74unsigned long get_board_sys_clk(void)
75{
76 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
77
78 switch (sysclk_conf & 0x0f) {
79 case QIXIS_SYSCLK_64:
80 return 64000000;
81 case QIXIS_SYSCLK_83:
82 return 83333333;
83 case QIXIS_SYSCLK_100:
84 return 100000000;
85 case QIXIS_SYSCLK_125:
86 return 125000000;
87 case QIXIS_SYSCLK_133:
88 return 133333333;
89 case QIXIS_SYSCLK_150:
90 return 150000000;
91 case QIXIS_SYSCLK_160:
92 return 160000000;
93 case QIXIS_SYSCLK_166:
94 return 166666666;
95 }
96 return 66666666;
97}
98
99unsigned long get_board_ddr_clk(void)
100{
101 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
102
103 switch ((ddrclk_conf & 0x30) >> 4) {
104 case QIXIS_DDRCLK_100:
105 return 100000000;
106 case QIXIS_DDRCLK_125:
107 return 125000000;
108 case QIXIS_DDRCLK_133:
109 return 133333333;
110 }
111 return 66666666;
112}
113
Chenhui Zhaoafff1372014-11-06 10:51:59 +0800114int select_i2c_ch_pca9547(u8 ch)
115{
116 int ret;
117
118 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
119 if (ret) {
120 puts("PCA: failed to select proper channel\n");
121 return ret;
122 }
123
124 return 0;
125}
126
Wang Huan550e3dc2014-09-05 13:52:44 +0800127int dram_init(void)
128{
Chenhui Zhaoafff1372014-11-06 10:51:59 +0800129 /*
130 * When resuming from deep sleep, the I2C channel may not be
131 * in the default channel. So, switch to the default channel
132 * before accessing DDR SPD.
133 */
134 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Wang Huan550e3dc2014-09-05 13:52:44 +0800135 gd->ram_size = initdram(0);
136
137 return 0;
138}
139
140#ifdef CONFIG_FSL_ESDHC
141struct fsl_esdhc_cfg esdhc_cfg[1] = {
142 {CONFIG_SYS_FSL_ESDHC_ADDR},
143};
144
145int board_mmc_init(bd_t *bis)
146{
147 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
148
149 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
150}
151#endif
152
Wang Huan550e3dc2014-09-05 13:52:44 +0800153int board_early_init_f(void)
154{
155 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
156 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
157
158#ifdef CONFIG_TSEC_ENET
Wang Huan550e3dc2014-09-05 13:52:44 +0800159 out_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Alison Wang0ab17232014-10-17 15:26:36 +0800160 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
Wang Huan550e3dc2014-09-05 13:52:44 +0800161#endif
162
163#ifdef CONFIG_FSL_IFC
164 init_early_memctl_regs();
165#endif
166
167 /* Workaround for the issue that DDR could not respond to
168 * barrier transaction which is generated by executing DSB/ISB
169 * instruction. Set CCI-400 control override register to
170 * terminate the barrier transaction. After DDR is initialized,
171 * allow barrier transaction to DDR again */
172 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
173
174 return 0;
175}
176
Alison Wang86949c22014-12-03 15:00:47 +0800177#ifdef CONFIG_SPL_BUILD
178void board_init_f(ulong dummy)
179{
180 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
181
182 /* Set global data pointer */
183 gd = &gdata;
184
185 /* Clear the BSS */
186 memset(__bss_start, 0, __bss_end - __bss_start);
187
188#ifdef CONFIG_FSL_IFC
189 init_early_memctl_regs();
190#endif
191
192 get_clocks();
193
194 preloader_console_init();
195
196#ifdef CONFIG_SPL_I2C_SUPPORT
197 i2c_init_all();
198#endif
199 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
200
201 dram_init();
202
203 board_init_r(NULL, 0);
204}
205#endif
206
Wang Huan550e3dc2014-09-05 13:52:44 +0800207int config_board_mux(int ctrl_type)
208{
209 u8 reg12;
210
211 reg12 = QIXIS_READ(brdcfg[12]);
212
213 switch (ctrl_type) {
214 case MUX_TYPE_SD_PCI4:
215 reg12 = 0x38;
216 break;
217 case MUX_TYPE_SD_PC_SA_SG_SG:
218 reg12 = 0x01;
219 break;
220 case MUX_TYPE_SD_PC_SA_PC_SG:
221 reg12 = 0x01;
222 break;
223 case MUX_TYPE_SD_PC_SG_SG:
224 reg12 = 0x21;
225 break;
226 default:
227 printf("Wrong mux interface type\n");
228 return -1;
229 }
230
231 QIXIS_WRITE(brdcfg[12], reg12);
232
233 return 0;
234}
235
236int config_serdes_mux(void)
237{
238 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
239 u32 cfg;
240
241 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
242 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
243
244 switch (cfg) {
245 case 0x0:
246 config_board_mux(MUX_TYPE_SD_PCI4);
247 break;
248 case 0x30:
249 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
250 break;
251 case 0x60:
252 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
253 break;
254 case 0x70:
255 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
256 break;
257 default:
258 printf("SRDS1 prtcl:0x%x\n", cfg);
259 break;
260 }
261
262 return 0;
263}
264
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530265#if defined(CONFIG_MISC_INIT_R)
266int misc_init_r(void)
267{
268#ifdef CONFIG_FSL_CAAM
269 return sec_init();
270#endif
271}
272#endif
273
Wang Huan550e3dc2014-09-05 13:52:44 +0800274int board_init(void)
275{
276 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
277
278 /* Set CCI-400 control override register to
279 * enable barrier transaction */
280 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Jason Jin644bc7e2014-10-17 15:26:32 +0800281 /*
282 * Set CCI-400 Slave interface S0, S1, S2 Shareable Override Register
283 * All transactions are treated as non-shareable
284 */
285 out_le32(&cci->slave[0].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
286 out_le32(&cci->slave[1].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
287 out_le32(&cci->slave[2].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
Wang Huan550e3dc2014-09-05 13:52:44 +0800288
289 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
290
291#ifndef CONFIG_SYS_FSL_NO_SERDES
292 fsl_serdes_init();
293 config_serdes_mux();
294#endif
Zhao Qiang63e75fd2014-09-26 16:25:32 +0800295
296#ifdef CONFIG_U_QE
297 u_qe_init();
298#endif
299
Wang Huan550e3dc2014-09-05 13:52:44 +0800300 return 0;
301}
302
Simon Glasse895a4b2014-10-23 18:58:47 -0600303int ft_board_setup(void *blob, bd_t *bd)
Wang Huan550e3dc2014-09-05 13:52:44 +0800304{
305 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600306
Minghuan Lianda419022014-10-31 13:43:44 +0800307#ifdef CONFIG_PCIE_LAYERSCAPE
308 ft_pcie_setup(blob, bd);
309#endif
310
Simon Glasse895a4b2014-10-23 18:58:47 -0600311 return 0;
Wang Huan550e3dc2014-09-05 13:52:44 +0800312}
313
314u8 flash_read8(void *addr)
315{
316 return __raw_readb(addr + 1);
317}
318
319void flash_write16(u16 val, void *addr)
320{
321 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
322
323 __raw_writew(shftval, addr);
324}
325
326u16 flash_read16(void *addr)
327{
328 u16 val = __raw_readw(addr);
329
330 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
331}