1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor
5 * This file provides support for the board-specific CPLD used on some Freescale
8 * The following macros need to be defined:
10 * CONFIG_SYS_CPLD_BASE-The virtual address of the base of the CPLD register map
19 u8 cpld_read(unsigned int reg)
21 void *p = (void *)CONFIG_SYS_CPLD_BASE;
26 void cpld_write(unsigned int reg, u8 value)
28 void *p = (void *)CONFIG_SYS_CPLD_BASE;
30 out_8(p + reg, value);
34 * Set the boot bank to the alternate bank
36 void cpld_set_altbank(void)
38 u8 reg = CPLD_READ(flash_ctl_status);
40 reg = (reg & ~CPLD_BANK_SEL_MASK) | CPLD_LBMAP_ALTBANK;
42 CPLD_WRITE(flash_ctl_status, reg);
43 CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
47 * Set the boot bank to the default bank
49 void cpld_set_defbank(void)
51 u8 reg = CPLD_READ(flash_ctl_status);
53 reg = (reg & ~CPLD_BANK_SEL_MASK) | CPLD_LBMAP_DFLTBANK;
55 CPLD_WRITE(flash_ctl_status, reg);
56 CPLD_WRITE(reset_ctl1, CPLD_LBMAP_RESET);
60 static void cpld_dump_regs(void)
62 printf("cpld_ver = 0x%02x\n", CPLD_READ(cpld_ver));
63 printf("cpld_ver_sub = 0x%02x\n", CPLD_READ(cpld_ver_sub));
64 printf("hw_ver = 0x%02x\n", CPLD_READ(hw_ver));
65 printf("sw_ver = 0x%02x\n", CPLD_READ(sw_ver));
66 printf("reset_ctl1 = 0x%02x\n", CPLD_READ(reset_ctl1));
67 printf("reset_ctl2 = 0x%02x\n", CPLD_READ(reset_ctl2));
68 printf("int_status = 0x%02x\n", CPLD_READ(int_status));
69 printf("flash_ctl_status = 0x%02x\n", CPLD_READ(flash_ctl_status));
70 printf("fan_ctl_status = 0x%02x\n", CPLD_READ(fan_ctl_status));
71 #if defined(CONFIG_TARGET_T1040D4D4RDB) || defined(CONFIG_TARGET_T1042D4RDB)
72 printf("int_mask = 0x%02x\n", CPLD_READ(int_mask));
74 printf("led_ctl_status = 0x%02x\n", CPLD_READ(led_ctl_status));
76 printf("sfp_ctl_status = 0x%02x\n", CPLD_READ(sfp_ctl_status));
77 printf("misc_ctl_status = 0x%02x\n", CPLD_READ(misc_ctl_status));
78 printf("boot_override = 0x%02x\n", CPLD_READ(boot_override));
79 printf("boot_config1 = 0x%02x\n", CPLD_READ(boot_config1));
80 printf("boot_config2 = 0x%02x\n", CPLD_READ(boot_config2));
85 int do_cpld(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
90 return cmd_usage(cmdtp);
92 if (strcmp(argv[1], "reset") == 0) {
93 if (strcmp(argv[2], "altbank") == 0)
98 } else if (strcmp(argv[1], "dump") == 0) {
102 rc = cmd_usage(cmdtp);
108 cpld, CONFIG_SYS_MAXARGS, 1, do_cpld,
109 "Reset the board or alternate bank",
110 "reset - hard reset to default bank\n"
111 "cpld reset altbank - reset to alternate bank\n"
113 "cpld dump - display the CPLD registers\n"