2 * Copyright 2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/immap_ls102xa.h>
11 #include <asm/arch/clock.h>
12 #include <asm/arch/fsl_serdes.h>
13 #include <asm/arch/ls102xa_soc.h>
14 #include <asm/arch/ls102xa_devdis.h>
15 #include <asm/arch/ls102xa_sata.h>
19 #include <fsl_esdhc.h>
23 #include <fsl_devdis.h>
24 #include <fsl_validate.h>
26 #include "../common/sleep.h"
27 #include "../common/qixis.h"
28 #include "ls1021aqds_qixis.h"
33 #define PIN_MUX_SEL_CAN 0x03
34 #define PIN_MUX_SEL_IIC2 0xa0
35 #define PIN_MUX_SEL_RGMII 0x00
36 #define PIN_MUX_SEL_SAI 0x0c
37 #define PIN_MUX_SEL_SDHC 0x00
39 #define SET_SDHC_MUX_SEL(reg, value) ((reg & 0x0f) | value)
40 #define SET_EC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
41 DECLARE_GLOBAL_DATA_PTR;
50 MUX_TYPE_SD_PC_SA_SG_SG,
51 MUX_TYPE_SD_PC_SA_PC_SG,
63 #if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
66 #if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
70 puts("Board: LS1021AQDS\n");
74 #elif CONFIG_QSPI_BOOT
77 sw = QIXIS_READ(brdcfg[0]);
78 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
81 printf("vBank: %d\n", sw);
89 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
92 #if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
93 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
94 QIXIS_READ(id), QIXIS_READ(arch));
96 printf("FPGA: v%d (%s), build %d\n",
97 (int)QIXIS_READ(scver), qixis_read_tag(buf),
98 (int)qixis_read_minor());
104 unsigned long get_board_sys_clk(void)
106 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
108 switch (sysclk_conf & 0x0f) {
109 case QIXIS_SYSCLK_64:
111 case QIXIS_SYSCLK_83:
113 case QIXIS_SYSCLK_100:
115 case QIXIS_SYSCLK_125:
117 case QIXIS_SYSCLK_133:
119 case QIXIS_SYSCLK_150:
121 case QIXIS_SYSCLK_160:
123 case QIXIS_SYSCLK_166:
129 unsigned long get_board_ddr_clk(void)
131 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
133 switch ((ddrclk_conf & 0x30) >> 4) {
134 case QIXIS_DDRCLK_100:
136 case QIXIS_DDRCLK_125:
138 case QIXIS_DDRCLK_133:
144 int select_i2c_ch_pca9547(u8 ch)
148 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
150 puts("PCA: failed to select proper channel\n");
160 * When resuming from deep sleep, the I2C channel may not be
161 * in the default channel. So, switch to the default channel
162 * before accessing DDR SPD.
164 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
165 return fsl_initdram();
168 #ifdef CONFIG_FSL_ESDHC
169 struct fsl_esdhc_cfg esdhc_cfg[1] = {
170 {CONFIG_SYS_FSL_ESDHC_ADDR},
173 int board_mmc_init(bd_t *bis)
175 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
177 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
181 int board_early_init_f(void)
183 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
185 #ifdef CONFIG_TSEC_ENET
186 /* clear BD & FR bits for BE BD's and frame data */
187 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
190 #ifdef CONFIG_FSL_IFC
191 init_early_memctl_regs();
196 #if defined(CONFIG_DEEP_SLEEP)
198 fsl_dp_disable_console();
204 #ifdef CONFIG_SPL_BUILD
205 void board_init_f(ulong dummy)
207 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
210 #ifdef CONFIG_NAND_BOOT
211 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
215 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
216 * NAND boot because IFC signals > IFC_AD7 are not enabled.
217 * This workaround changes RCW source to make all signals enabled.
219 porsr1 = in_be32(&gur->porsr1);
220 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
221 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
222 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
227 memset(__bss_start, 0, __bss_end - __bss_start);
229 #ifdef CONFIG_FSL_IFC
230 init_early_memctl_regs();
235 #if defined(CONFIG_DEEP_SLEEP)
237 fsl_dp_disable_console();
240 preloader_console_init();
242 #ifdef CONFIG_SPL_I2C_SUPPORT
246 major = get_soc_major_rev();
247 if (major == SOC_MAJOR_VER_1_0)
248 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
252 /* Allow OCRAM access permission as R/W */
253 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
254 enable_layerscape_ns_access();
257 board_init_r(NULL, 0);
261 void config_etseccm_source(int etsec_gtx_125_mux)
263 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
265 switch (etsec_gtx_125_mux) {
267 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
268 debug("etseccm set to GE0_CLK125\n");
272 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
273 debug("etseccm set to GE2_CLK125\n");
277 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
278 debug("etseccm set to GE1_CLK125\n");
282 printf("Error! trying to set etseccm to invalid value\n");
287 int config_board_mux(int ctrl_type)
291 reg12 = QIXIS_READ(brdcfg[12]);
292 reg14 = QIXIS_READ(brdcfg[14]);
296 config_etseccm_source(GE2_CLK125);
297 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
300 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
303 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
306 config_etseccm_source(GE2_CLK125);
307 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
310 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
312 case MUX_TYPE_SD_PCI4:
315 case MUX_TYPE_SD_PC_SA_SG_SG:
318 case MUX_TYPE_SD_PC_SA_PC_SG:
321 case MUX_TYPE_SD_PC_SG_SG:
325 printf("Wrong mux interface type\n");
329 QIXIS_WRITE(brdcfg[12], reg12);
330 QIXIS_WRITE(brdcfg[14], reg14);
335 int config_serdes_mux(void)
337 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
340 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
341 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
345 config_board_mux(MUX_TYPE_SD_PCI4);
348 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
351 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
354 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
357 printf("SRDS1 prtcl:0x%x\n", cfg);
364 #ifdef CONFIG_BOARD_LATE_INIT
365 int board_late_init(void)
367 #ifdef CONFIG_SCSI_AHCI_PLAT
370 #ifdef CONFIG_CHAIN_OF_TRUST
371 fsl_setenv_chain_of_trust();
378 int misc_init_r(void)
382 /* some signals can not enable simultaneous*/
384 if (hwconfig("sdhc"))
386 if (hwconfig("iic2"))
388 if (conflict_flag > 1) {
389 printf("WARNING: pin conflict !\n");
394 if (hwconfig("rgmii"))
400 if (conflict_flag > 1) {
401 printf("WARNING: pin conflict !\n");
406 config_board_mux(MUX_TYPE_CAN);
407 else if (hwconfig("rgmii"))
408 config_board_mux(MUX_TYPE_RGMII);
409 else if (hwconfig("sai"))
410 config_board_mux(MUX_TYPE_SAI);
412 if (hwconfig("iic2"))
413 config_board_mux(MUX_TYPE_IIC2);
414 else if (hwconfig("sdhc"))
415 config_board_mux(MUX_TYPE_SDHC);
417 #ifdef CONFIG_FSL_DEVICE_DISABLE
418 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
420 #ifdef CONFIG_FSL_CAAM
428 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
431 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
434 #ifdef CONFIG_SYS_FSL_ERRATUM_A009942
435 erratum_a009942_check_cpo();
437 major = get_soc_major_rev();
438 if (major == SOC_MAJOR_VER_1_0) {
439 /* Set CCI-400 control override register to
440 * enable barrier transaction */
441 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
444 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
446 #ifndef CONFIG_SYS_FSL_NO_SERDES
451 ls102xa_smmu_stream_id_init();
460 #if defined(CONFIG_DEEP_SLEEP)
461 void board_sleep_prepare(void)
463 struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
466 major = get_soc_major_rev();
467 if (major == SOC_MAJOR_VER_1_0) {
468 /* Set CCI-400 control override register to
469 * enable barrier transaction */
470 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
474 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
475 enable_layerscape_ns_access();
480 int ft_board_setup(void *blob, bd_t *bd)
482 ft_cpu_setup(blob, bd);
485 ft_pci_setup(blob, bd);
491 u8 flash_read8(void *addr)
493 return __raw_readb(addr + 1);
496 void flash_write16(u16 val, void *addr)
498 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
500 __raw_writew(shftval, addr);
503 u16 flash_read16(void *addr)
505 u16 val = __raw_readw(addr);
507 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);