2 * Copyright 2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/immap_ls102xa.h>
11 #include <asm/arch/ns_access.h>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/fsl_serdes.h>
14 #include <asm/arch/ls102xa_stream_id.h>
17 #include <fsl_esdhc.h>
22 #include "../common/sleep.h"
23 #include "../common/qixis.h"
24 #include "ls1021aqds_qixis.h"
26 #include "../../../drivers/qe/qe.h"
29 #define PIN_MUX_SEL_CAN 0x03
30 #define PIN_MUX_SEL_IIC2 0xa0
31 #define PIN_MUX_SEL_RGMII 0x00
32 #define PIN_MUX_SEL_SAI 0x0c
33 #define PIN_MUX_SEL_SDHC 0x00
35 #define SET_SDHC_MUX_SEL(reg, value) ((reg & 0x0f) | value)
36 #define SET_EC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
37 DECLARE_GLOBAL_DATA_PTR;
46 MUX_TYPE_SD_PC_SA_SG_SG,
47 MUX_TYPE_SD_PC_SA_PC_SG,
59 #ifndef CONFIG_QSPI_BOOT
62 #if !defined(CONFIG_SD_BOOT) && !defined(CONFIG_QSPI_BOOT)
66 puts("Board: LS1021AQDS\n");
70 #elif CONFIG_QSPI_BOOT
73 sw = QIXIS_READ(brdcfg[0]);
74 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
77 printf("vBank: %d\n", sw);
85 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
88 #ifndef CONFIG_QSPI_BOOT
89 printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n",
90 QIXIS_READ(id), QIXIS_READ(arch));
92 printf("FPGA: v%d (%s), build %d\n",
93 (int)QIXIS_READ(scver), qixis_read_tag(buf),
94 (int)qixis_read_minor());
100 unsigned long get_board_sys_clk(void)
102 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
104 switch (sysclk_conf & 0x0f) {
105 case QIXIS_SYSCLK_64:
107 case QIXIS_SYSCLK_83:
109 case QIXIS_SYSCLK_100:
111 case QIXIS_SYSCLK_125:
113 case QIXIS_SYSCLK_133:
115 case QIXIS_SYSCLK_150:
117 case QIXIS_SYSCLK_160:
119 case QIXIS_SYSCLK_166:
125 unsigned long get_board_ddr_clk(void)
127 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
129 switch ((ddrclk_conf & 0x30) >> 4) {
130 case QIXIS_DDRCLK_100:
132 case QIXIS_DDRCLK_125:
134 case QIXIS_DDRCLK_133:
140 unsigned int get_soc_major_rev(void)
142 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
143 unsigned int svr, major;
145 svr = in_be32(&gur->svr);
146 major = SVR_MAJ(svr);
151 int select_i2c_ch_pca9547(u8 ch)
155 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
157 puts("PCA: failed to select proper channel\n");
167 * When resuming from deep sleep, the I2C channel may not be
168 * in the default channel. So, switch to the default channel
169 * before accessing DDR SPD.
171 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
172 gd->ram_size = initdram(0);
177 #ifdef CONFIG_FSL_ESDHC
178 struct fsl_esdhc_cfg esdhc_cfg[1] = {
179 {CONFIG_SYS_FSL_ESDHC_ADDR},
182 int board_mmc_init(bd_t *bis)
184 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
186 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
190 int board_early_init_f(void)
192 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
193 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
196 #ifdef CONFIG_TSEC_ENET
197 out_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
200 #ifdef CONFIG_FSL_IFC
201 init_early_memctl_regs();
204 #ifdef CONFIG_FSL_QSPI
205 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
208 #ifdef CONFIG_FSL_DCU_FB
209 out_be32(&scfg->pixclkcr, SCFG_PIXCLKCR_PXCKEN);
213 * Enable snoop requests and DVM message requests for
214 * Slave insterface S4 (A7 core cluster)
216 out_le32(&cci->slave[4].snoop_ctrl,
217 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
219 major = get_soc_major_rev();
220 if (major == SOC_MAJOR_VER_1_0) {
222 * Set CCI-400 Slave interface S1, S2 Shareable Override
223 * Register All transactions are treated as non-shareable
225 out_le32(&cci->slave[1].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
226 out_le32(&cci->slave[2].sha_ord, CCI400_SHAORD_NON_SHAREABLE);
228 /* Workaround for the issue that DDR could not respond to
229 * barrier transaction which is generated by executing DSB/ISB
230 * instruction. Set CCI-400 control override register to
231 * terminate the barrier transaction. After DDR is initialized,
232 * allow barrier transaction to DDR again */
233 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
236 #if defined(CONFIG_DEEP_SLEEP)
238 fsl_dp_disable_console();
244 #ifdef CONFIG_SPL_BUILD
245 void board_init_f(ulong dummy)
247 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
250 #ifdef CONFIG_NAND_BOOT
251 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
255 * There is LS1 SoC issue where NOR, FPGA are inaccessible during
256 * NAND boot because IFC signals > IFC_AD7 are not enabled.
257 * This workaround changes RCW source to make all signals enabled.
259 porsr1 = in_be32(&gur->porsr1);
260 pinctl = ((porsr1 & ~(DCFG_CCSR_PORSR1_RCW_MASK)) |
261 DCFG_CCSR_PORSR1_RCW_SRC_I2C);
262 out_be32((unsigned int *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
267 memset(__bss_start, 0, __bss_end - __bss_start);
269 #ifdef CONFIG_FSL_IFC
270 init_early_memctl_regs();
275 #if defined(CONFIG_DEEP_SLEEP)
277 fsl_dp_disable_console();
280 preloader_console_init();
282 #ifdef CONFIG_SPL_I2C_SUPPORT
286 major = get_soc_major_rev();
287 if (major == SOC_MAJOR_VER_1_0)
288 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
292 board_init_r(NULL, 0);
296 void config_etseccm_source(int etsec_gtx_125_mux)
298 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
300 switch (etsec_gtx_125_mux) {
302 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE0_CLK125);
303 debug("etseccm set to GE0_CLK125\n");
307 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
308 debug("etseccm set to GE2_CLK125\n");
312 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE1_CLK125);
313 debug("etseccm set to GE1_CLK125\n");
317 printf("Error! trying to set etseccm to invalid value\n");
322 int config_board_mux(int ctrl_type)
326 reg12 = QIXIS_READ(brdcfg[12]);
327 reg14 = QIXIS_READ(brdcfg[14]);
331 config_etseccm_source(GE2_CLK125);
332 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_CAN);
335 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_IIC2);
338 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_RGMII);
341 config_etseccm_source(GE2_CLK125);
342 reg14 = SET_EC_MUX_SEL(reg14, PIN_MUX_SEL_SAI);
345 reg14 = SET_SDHC_MUX_SEL(reg14, PIN_MUX_SEL_SDHC);
347 case MUX_TYPE_SD_PCI4:
350 case MUX_TYPE_SD_PC_SA_SG_SG:
353 case MUX_TYPE_SD_PC_SA_PC_SG:
356 case MUX_TYPE_SD_PC_SG_SG:
360 printf("Wrong mux interface type\n");
364 QIXIS_WRITE(brdcfg[12], reg12);
365 QIXIS_WRITE(brdcfg[14], reg14);
370 int config_serdes_mux(void)
372 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
375 cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
376 cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT;
380 config_board_mux(MUX_TYPE_SD_PCI4);
383 config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG);
386 config_board_mux(MUX_TYPE_SD_PC_SG_SG);
389 config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG);
392 printf("SRDS1 prtcl:0x%x\n", cfg);
399 int misc_init_r(void)
403 /* some signals can not enable simultaneous*/
405 if (hwconfig("sdhc"))
407 if (hwconfig("iic2"))
409 if (conflict_flag > 1) {
410 printf("WARNING: pin conflict !\n");
415 if (hwconfig("rgmii"))
421 if (conflict_flag > 1) {
422 printf("WARNING: pin conflict !\n");
427 config_board_mux(MUX_TYPE_CAN);
428 else if (hwconfig("rgmii"))
429 config_board_mux(MUX_TYPE_RGMII);
430 else if (hwconfig("sai"))
431 config_board_mux(MUX_TYPE_SAI);
433 if (hwconfig("iic2"))
434 config_board_mux(MUX_TYPE_IIC2);
435 else if (hwconfig("sdhc"))
436 config_board_mux(MUX_TYPE_SDHC);
438 #ifdef CONFIG_FSL_CAAM
444 #ifdef CONFIG_LS102XA_NS_ACCESS
445 static struct csu_ns_dev ns_dev[] = {
446 { CSU_CSLX_PCIE2_IO, CSU_ALL_RW },
447 { CSU_CSLX_PCIE1_IO, CSU_ALL_RW },
448 { CSU_CSLX_MG2TPR_IP, CSU_ALL_RW },
449 { CSU_CSLX_IFC_MEM, CSU_ALL_RW },
450 { CSU_CSLX_OCRAM, CSU_ALL_RW },
451 { CSU_CSLX_GIC, CSU_ALL_RW },
452 { CSU_CSLX_PCIE1, CSU_ALL_RW },
453 { CSU_CSLX_OCRAM2, CSU_ALL_RW },
454 { CSU_CSLX_QSPI_MEM, CSU_ALL_RW },
455 { CSU_CSLX_PCIE2, CSU_ALL_RW },
456 { CSU_CSLX_SATA, CSU_ALL_RW },
457 { CSU_CSLX_USB3, CSU_ALL_RW },
458 { CSU_CSLX_SERDES, CSU_ALL_RW },
459 { CSU_CSLX_QDMA, CSU_ALL_RW },
460 { CSU_CSLX_LPUART2, CSU_ALL_RW },
461 { CSU_CSLX_LPUART1, CSU_ALL_RW },
462 { CSU_CSLX_LPUART4, CSU_ALL_RW },
463 { CSU_CSLX_LPUART3, CSU_ALL_RW },
464 { CSU_CSLX_LPUART6, CSU_ALL_RW },
465 { CSU_CSLX_LPUART5, CSU_ALL_RW },
466 { CSU_CSLX_DSPI2, CSU_ALL_RW },
467 { CSU_CSLX_DSPI1, CSU_ALL_RW },
468 { CSU_CSLX_QSPI, CSU_ALL_RW },
469 { CSU_CSLX_ESDHC, CSU_ALL_RW },
470 { CSU_CSLX_2D_ACE, CSU_ALL_RW },
471 { CSU_CSLX_IFC, CSU_ALL_RW },
472 { CSU_CSLX_I2C1, CSU_ALL_RW },
473 { CSU_CSLX_USB2, CSU_ALL_RW },
474 { CSU_CSLX_I2C3, CSU_ALL_RW },
475 { CSU_CSLX_I2C2, CSU_ALL_RW },
476 { CSU_CSLX_DUART2, CSU_ALL_RW },
477 { CSU_CSLX_DUART1, CSU_ALL_RW },
478 { CSU_CSLX_WDT2, CSU_ALL_RW },
479 { CSU_CSLX_WDT1, CSU_ALL_RW },
480 { CSU_CSLX_EDMA, CSU_ALL_RW },
481 { CSU_CSLX_SYS_CNT, CSU_ALL_RW },
482 { CSU_CSLX_DMA_MUX2, CSU_ALL_RW },
483 { CSU_CSLX_DMA_MUX1, CSU_ALL_RW },
484 { CSU_CSLX_DDR, CSU_ALL_RW },
485 { CSU_CSLX_QUICC, CSU_ALL_RW },
486 { CSU_CSLX_DCFG_CCU_RCPM, CSU_ALL_RW },
487 { CSU_CSLX_SECURE_BOOTROM, CSU_ALL_RW },
488 { CSU_CSLX_SFP, CSU_ALL_RW },
489 { CSU_CSLX_TMU, CSU_ALL_RW },
490 { CSU_CSLX_SECURE_MONITOR, CSU_ALL_RW },
491 { CSU_CSLX_RESERVED0, CSU_ALL_RW },
492 { CSU_CSLX_ETSEC1, CSU_ALL_RW },
493 { CSU_CSLX_SEC5_5, CSU_ALL_RW },
494 { CSU_CSLX_ETSEC3, CSU_ALL_RW },
495 { CSU_CSLX_ETSEC2, CSU_ALL_RW },
496 { CSU_CSLX_GPIO2, CSU_ALL_RW },
497 { CSU_CSLX_GPIO1, CSU_ALL_RW },
498 { CSU_CSLX_GPIO4, CSU_ALL_RW },
499 { CSU_CSLX_GPIO3, CSU_ALL_RW },
500 { CSU_CSLX_PLATFORM_CONT, CSU_ALL_RW },
501 { CSU_CSLX_CSU, CSU_ALL_RW },
502 { CSU_CSLX_ASRC, CSU_ALL_RW },
503 { CSU_CSLX_SPDIF, CSU_ALL_RW },
504 { CSU_CSLX_FLEXCAN2, CSU_ALL_RW },
505 { CSU_CSLX_FLEXCAN1, CSU_ALL_RW },
506 { CSU_CSLX_FLEXCAN4, CSU_ALL_RW },
507 { CSU_CSLX_FLEXCAN3, CSU_ALL_RW },
508 { CSU_CSLX_SAI2, CSU_ALL_RW },
509 { CSU_CSLX_SAI1, CSU_ALL_RW },
510 { CSU_CSLX_SAI4, CSU_ALL_RW },
511 { CSU_CSLX_SAI3, CSU_ALL_RW },
512 { CSU_CSLX_FTM2, CSU_ALL_RW },
513 { CSU_CSLX_FTM1, CSU_ALL_RW },
514 { CSU_CSLX_FTM4, CSU_ALL_RW },
515 { CSU_CSLX_FTM3, CSU_ALL_RW },
516 { CSU_CSLX_FTM6, CSU_ALL_RW },
517 { CSU_CSLX_FTM5, CSU_ALL_RW },
518 { CSU_CSLX_FTM8, CSU_ALL_RW },
519 { CSU_CSLX_FTM7, CSU_ALL_RW },
520 { CSU_CSLX_COP_DCSR, CSU_ALL_RW },
521 { CSU_CSLX_EPU, CSU_ALL_RW },
522 { CSU_CSLX_GDI, CSU_ALL_RW },
523 { CSU_CSLX_DDI, CSU_ALL_RW },
524 { CSU_CSLX_RESERVED1, CSU_ALL_RW },
525 { CSU_CSLX_USB3_PHY, CSU_ALL_RW },
526 { CSU_CSLX_RESERVED2, CSU_ALL_RW },
530 struct liodn_id_table sec_liodn_tbl[] = {
531 SET_SEC_JR_LIODN_ENTRY(0, 0x10, 0x10),
532 SET_SEC_JR_LIODN_ENTRY(1, 0x10, 0x10),
533 SET_SEC_JR_LIODN_ENTRY(2, 0x10, 0x10),
534 SET_SEC_JR_LIODN_ENTRY(3, 0x10, 0x10),
535 SET_SEC_RTIC_LIODN_ENTRY(a, 0x10),
536 SET_SEC_RTIC_LIODN_ENTRY(b, 0x10),
537 SET_SEC_RTIC_LIODN_ENTRY(c, 0x10),
538 SET_SEC_RTIC_LIODN_ENTRY(d, 0x10),
539 SET_SEC_DECO_LIODN_ENTRY(0, 0x10, 0x10),
540 SET_SEC_DECO_LIODN_ENTRY(1, 0x10, 0x10),
541 SET_SEC_DECO_LIODN_ENTRY(2, 0x10, 0x10),
542 SET_SEC_DECO_LIODN_ENTRY(3, 0x10, 0x10),
543 SET_SEC_DECO_LIODN_ENTRY(4, 0x10, 0x10),
544 SET_SEC_DECO_LIODN_ENTRY(5, 0x10, 0x10),
545 SET_SEC_DECO_LIODN_ENTRY(6, 0x10, 0x10),
546 SET_SEC_DECO_LIODN_ENTRY(7, 0x10, 0x10),
549 struct smmu_stream_id dev_stream_id[] = {
550 { 0x100, 0x01, "ETSEC MAC1" },
551 { 0x104, 0x02, "ETSEC MAC2" },
552 { 0x108, 0x03, "ETSEC MAC3" },
553 { 0x10c, 0x04, "PEX1" },
554 { 0x110, 0x05, "PEX2" },
555 { 0x114, 0x06, "qDMA" },
556 { 0x118, 0x07, "SATA" },
557 { 0x11c, 0x08, "USB3" },
558 { 0x120, 0x09, "QE" },
559 { 0x124, 0x0a, "eSDHC" },
560 { 0x128, 0x0b, "eMA" },
561 { 0x14c, 0x0c, "2D-ACE" },
562 { 0x150, 0x0d, "USB2" },
563 { 0x18c, 0x0e, "DEBUG" },
568 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
571 major = get_soc_major_rev();
572 if (major == SOC_MAJOR_VER_1_0) {
573 /* Set CCI-400 control override register to
574 * enable barrier transaction */
575 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
578 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
580 #ifndef CONFIG_SYS_FSL_NO_SERDES
585 ls1021x_config_caam_stream_id(sec_liodn_tbl,
586 ARRAY_SIZE(sec_liodn_tbl));
587 ls102xa_config_smmu_stream_id(dev_stream_id,
588 ARRAY_SIZE(dev_stream_id));
590 #ifdef CONFIG_LS102XA_NS_ACCESS
591 enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev));
601 #if defined(CONFIG_DEEP_SLEEP)
602 void board_sleep_prepare(void)
604 struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
607 major = get_soc_major_rev();
608 if (major == SOC_MAJOR_VER_1_0) {
609 /* Set CCI-400 control override register to
610 * enable barrier transaction */
611 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
615 #ifdef CONFIG_LS102XA_NS_ACCESS
616 enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev));
621 int ft_board_setup(void *blob, bd_t *bd)
623 ft_cpu_setup(blob, bd);
626 ft_pci_setup(blob, bd);
632 u8 flash_read8(void *addr)
634 return __raw_readb(addr + 1);
637 void flash_write16(u16 val, void *addr)
639 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
641 __raw_writew(shftval, addr);
644 u16 flash_read16(void *addr)
646 u16 val = __raw_readw(addr);
648 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);