2 * Copyright 2016 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
6 * Freescale LS1046ARDB board-specific CPLD controlling supports.
14 u8 cpld_read(unsigned int reg)
16 void *p = (void *)CONFIG_SYS_CPLD_BASE;
21 void cpld_write(unsigned int reg, u8 value)
23 void *p = (void *)CONFIG_SYS_CPLD_BASE;
25 out_8(p + reg, value);
28 /* Set the boot bank to the alternate bank */
29 void cpld_set_altbank(void)
31 u16 reg = CPLD_CFG_RCW_SRC_QSPI;
32 u8 reg4 = CPLD_READ(soft_mux_on);
33 u8 reg5 = (u8)(reg >> 1);
34 u8 reg6 = (u8)(reg & 1);
35 u8 reg7 = CPLD_READ(vbank);
39 CPLD_WRITE(soft_mux_on, reg4 | CPLD_SW_MUX_BANK_SEL | 1);
41 CPLD_WRITE(cfg_rcw_src1, reg5);
42 CPLD_WRITE(cfg_rcw_src2, reg6);
44 reg7 = (reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK;
45 CPLD_WRITE(vbank, reg7);
47 CPLD_WRITE(system_rst, 1);
50 /* Set the boot bank to the default bank */
51 void cpld_set_defbank(void)
53 u16 reg = CPLD_CFG_RCW_SRC_QSPI;
54 u8 reg4 = CPLD_READ(soft_mux_on);
55 u8 reg5 = (u8)(reg >> 1);
56 u8 reg6 = (u8)(reg & 1);
60 CPLD_WRITE(soft_mux_on, reg4 | CPLD_SW_MUX_BANK_SEL | 1);
62 CPLD_WRITE(cfg_rcw_src1, reg5);
63 CPLD_WRITE(cfg_rcw_src2, reg6);
67 CPLD_WRITE(system_rst, 1);
70 void cpld_set_sd(void)
72 u16 reg = CPLD_CFG_RCW_SRC_SD;
73 u8 reg5 = (u8)(reg >> 1);
74 u8 reg6 = (u8)(reg & 1);
78 CPLD_WRITE(soft_mux_on, 1);
80 CPLD_WRITE(cfg_rcw_src1, reg5);
81 CPLD_WRITE(cfg_rcw_src2, reg6);
83 CPLD_WRITE(system_rst, 1);
86 static void cpld_dump_regs(void)
88 printf("cpld_ver = %x\n", CPLD_READ(cpld_ver));
89 printf("cpld_ver_sub = %x\n", CPLD_READ(cpld_ver_sub));
90 printf("pcba_ver = %x\n", CPLD_READ(pcba_ver));
91 printf("soft_mux_on = %x\n", CPLD_READ(soft_mux_on));
92 printf("cfg_rcw_src1 = %x\n", CPLD_READ(cfg_rcw_src1));
93 printf("cfg_rcw_src2 = %x\n", CPLD_READ(cfg_rcw_src2));
94 printf("vbank = %x\n", CPLD_READ(vbank));
95 printf("sysclk_sel = %x\n", CPLD_READ(sysclk_sel));
96 printf("uart_sel = %x\n", CPLD_READ(uart_sel));
97 printf("sd1refclk_sel = %x\n", CPLD_READ(sd1refclk_sel));
98 printf("rgmii_1588_sel = %x\n", CPLD_READ(rgmii_1588_sel));
99 printf("1588_clk_sel = %x\n", CPLD_READ(reg_1588_clk_sel));
100 printf("status_led = %x\n", CPLD_READ(status_led));
101 printf("sd_emmc = %x\n", CPLD_READ(sd_emmc));
102 printf("vdd_en = %x\n", CPLD_READ(vdd_en));
103 printf("vdd_sel = %x\n", CPLD_READ(vdd_sel));
108 void cpld_rev_bit(unsigned char *value)
115 for (i = 1; i <= 7; i++) {
124 int do_cpld(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
129 return cmd_usage(cmdtp);
131 if (strcmp(argv[1], "reset") == 0) {
132 if (strcmp(argv[2], "altbank") == 0)
134 else if (strcmp(argv[2], "sd") == 0)
139 } else if (strcmp(argv[1], "dump") == 0) {
143 rc = cmd_usage(cmdtp);
150 cpld, CONFIG_SYS_MAXARGS, 1, do_cpld,
151 "Reset the board or alternate bank",
152 "reset: reset to default bank\n"
153 "cpld reset altbank: reset to alternate bank\n"
154 "cpld reset sd: reset to boot from SD card\n"
156 "cpld dump - display the CPLD registers\n"