1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor
5 * Freescale LS1046ARDB board-specific CPLD controlling supports.
13 u8 cpld_read(unsigned int reg)
15 void *p = (void *)CONFIG_SYS_CPLD_BASE;
20 void cpld_write(unsigned int reg, u8 value)
22 void *p = (void *)CONFIG_SYS_CPLD_BASE;
24 out_8(p + reg, value);
27 /* Set the boot bank to the alternate bank */
28 void cpld_set_altbank(void)
30 u16 reg = CPLD_CFG_RCW_SRC_QSPI;
31 u8 reg4 = CPLD_READ(soft_mux_on);
32 u8 reg5 = (u8)(reg >> 1);
33 u8 reg6 = (u8)(reg & 1);
34 u8 reg7 = CPLD_READ(vbank);
38 CPLD_WRITE(soft_mux_on, reg4 | CPLD_SW_MUX_BANK_SEL | 1);
40 CPLD_WRITE(cfg_rcw_src1, reg5);
41 CPLD_WRITE(cfg_rcw_src2, reg6);
43 reg7 = (reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK;
44 CPLD_WRITE(vbank, reg7);
46 CPLD_WRITE(system_rst, 1);
49 /* Set the boot bank to the default bank */
50 void cpld_set_defbank(void)
52 u16 reg = CPLD_CFG_RCW_SRC_QSPI;
53 u8 reg4 = CPLD_READ(soft_mux_on);
54 u8 reg5 = (u8)(reg >> 1);
55 u8 reg6 = (u8)(reg & 1);
59 CPLD_WRITE(soft_mux_on, reg4 | CPLD_SW_MUX_BANK_SEL | 1);
61 CPLD_WRITE(cfg_rcw_src1, reg5);
62 CPLD_WRITE(cfg_rcw_src2, reg6);
66 CPLD_WRITE(system_rst, 1);
69 void cpld_set_sd(void)
71 u16 reg = CPLD_CFG_RCW_SRC_SD;
72 u8 reg5 = (u8)(reg >> 1);
73 u8 reg6 = (u8)(reg & 1);
77 CPLD_WRITE(soft_mux_on, 1);
79 CPLD_WRITE(cfg_rcw_src1, reg5);
80 CPLD_WRITE(cfg_rcw_src2, reg6);
82 CPLD_WRITE(system_rst, 1);
85 void cpld_select_core_volt(bool en_0v9)
89 CPLD_WRITE(vdd_en, 1);
90 CPLD_WRITE(vdd_sel, reg17);
94 static void cpld_dump_regs(void)
96 printf("cpld_ver = %x\n", CPLD_READ(cpld_ver));
97 printf("cpld_ver_sub = %x\n", CPLD_READ(cpld_ver_sub));
98 printf("pcba_ver = %x\n", CPLD_READ(pcba_ver));
99 printf("soft_mux_on = %x\n", CPLD_READ(soft_mux_on));
100 printf("cfg_rcw_src1 = %x\n", CPLD_READ(cfg_rcw_src1));
101 printf("cfg_rcw_src2 = %x\n", CPLD_READ(cfg_rcw_src2));
102 printf("vbank = %x\n", CPLD_READ(vbank));
103 printf("sysclk_sel = %x\n", CPLD_READ(sysclk_sel));
104 printf("uart_sel = %x\n", CPLD_READ(uart_sel));
105 printf("sd1refclk_sel = %x\n", CPLD_READ(sd1refclk_sel));
106 printf("rgmii_1588_sel = %x\n", CPLD_READ(rgmii_1588_sel));
107 printf("1588_clk_sel = %x\n", CPLD_READ(reg_1588_clk_sel));
108 printf("status_led = %x\n", CPLD_READ(status_led));
109 printf("sd_emmc = %x\n", CPLD_READ(sd_emmc));
110 printf("vdd_en = %x\n", CPLD_READ(vdd_en));
111 printf("vdd_sel = %x\n", CPLD_READ(vdd_sel));
116 void cpld_rev_bit(unsigned char *value)
123 for (i = 1; i <= 7; i++) {
132 int do_cpld(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
137 return cmd_usage(cmdtp);
139 if (strcmp(argv[1], "reset") == 0) {
140 if (strcmp(argv[2], "altbank") == 0)
142 else if (strcmp(argv[2], "sd") == 0)
147 } else if (strcmp(argv[1], "dump") == 0) {
151 rc = cmd_usage(cmdtp);
158 cpld, CONFIG_SYS_MAXARGS, 1, do_cpld,
159 "Reset the board or alternate bank",
160 "reset: reset to default bank\n"
161 "cpld reset altbank: reset to alternate bank\n"
162 "cpld reset sd: reset to boot from SD card\n"
164 "cpld dump - display the CPLD registers\n"