1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013 Freescale Semiconductor
4 * Author: Mingkai Hu <Mingkai.hu@freescale.com>
5 * Po Liu <Po.Liu@freescale.com>
7 * This file provides support for the board-specific CPLD used on some Freescale
10 * The following macros need to be defined:
12 * CONFIG_SYS_CPLD_BASE - The virtual address of the base of the
23 * Set the boot bank to the alternate bank
25 void cpld_set_altbank(u8 banksel)
27 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
30 reg11 = in_8(&cpld_data->flhcsr);
34 out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
35 | CPLD_BANKSEL_EN | CPLD_SELECT_BANK1);
38 out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
39 | CPLD_BANKSEL_EN | CPLD_SELECT_BANK2);
42 out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
43 | CPLD_BANKSEL_EN | CPLD_SELECT_BANK3);
46 out_8(&cpld_data->flhcsr, (reg11 & CPLD_BANKSEL_MASK)
47 | CPLD_BANKSEL_EN | CPLD_SELECT_BANK4);
50 printf("Invalid value! [1-4]\n");
55 do_reset(NULL, 0, 0, NULL);
59 * Set the boot bank to the default bank
61 void cpld_set_defbank(void)
67 static void cpld_dump_regs(void)
69 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
71 printf("chipid1 = 0x%02x\n", in_8(&cpld_data->chipid1));
72 printf("chipid2 = 0x%02x\n", in_8(&cpld_data->chipid2));
73 printf("hwver = 0x%02x\n", in_8(&cpld_data->hwver));
74 printf("cpldver = 0x%02x\n", in_8(&cpld_data->cpldver));
75 printf("rstcon = 0x%02x\n", in_8(&cpld_data->rstcon));
76 printf("flhcsr = 0x%02x\n", in_8(&cpld_data->flhcsr));
77 printf("wdcsr = 0x%02x\n", in_8(&cpld_data->wdcsr));
78 printf("wdkick = 0x%02x\n", in_8(&cpld_data->wdkick));
79 printf("fancsr = 0x%02x\n", in_8(&cpld_data->fancsr));
80 printf("ledcsr = 0x%02x\n", in_8(&cpld_data->ledcsr));
81 printf("misc = 0x%02x\n", in_8(&cpld_data->misccsr));
82 printf("bootor = 0x%02x\n", in_8(&cpld_data->bootor));
83 printf("bootcfg1 = 0x%02x\n", in_8(&cpld_data->bootcfg1));
84 printf("bootcfg2 = 0x%02x\n", in_8(&cpld_data->bootcfg2));
85 printf("bootcfg3 = 0x%02x\n", in_8(&cpld_data->bootcfg3));
86 printf("bootcfg4 = 0x%02x\n", in_8(&cpld_data->bootcfg4));
91 #ifndef CONFIG_SPL_BUILD
92 int cpld_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
98 return cmd_usage(cmdtp);
100 if (strcmp(argv[1], "reset") == 0) {
101 if (!strcmp(argv[2], "altbank") && argv[3]) {
102 value = (u8)simple_strtoul(argv[3], NULL, 16);
103 cpld_set_altbank(value);
109 } else if (strcmp(argv[1], "dump") == 0) {
113 rc = cmd_usage(cmdtp);
119 cpld_cmd, CONFIG_SYS_MAXARGS, 1, cpld_cmd,
120 "Reset the board using the CPLD sequencer",
121 "reset - hard reset to default bank 4\n"
122 "cpld_cmd reset altbank [bank]- reset to alternate bank\n"
123 " - [bank] bank value select 1-4\n"
124 " - bank 1 on the flash 0x0000000~0x0ffffff\n"
125 " - bank 2 on the flash 0x1000000~0x1ffffff\n"
126 " - bank 3 on the flash 0x2000000~0x2ffffff\n"
127 " - bank 4 on the flash 0x3000000~0x3ffffff\n"
129 "cpld_cmd dump - display the CPLD registers\n"