blob: 915a8b994d5c2ba296f775bf5af6f3149aecaa01 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Huf354b532011-07-07 12:29:15 +08002/**
3 * Copyright 2011 Freescale Semiconductor
4 * Author: Mingkai Hu <Mingkai.hu@freescale.com>
5 *
Mingkai Huf354b532011-07-07 12:29:15 +08006 * This file provides support for the board-specific CPLD used on some Freescale
7 * reference boards.
8 *
9 * The following macros need to be defined:
10 *
11 * CPLD_BASE - The virtual address of the base of the CPLD register map
Mingkai Huf354b532011-07-07 12:29:15 +080012 */
13
Mingkai Huf354b532011-07-07 12:29:15 +080014#include <command.h>
15#include <asm/io.h>
16
17#include "cpld.h"
18
19static u8 __cpld_read(unsigned int reg)
20{
21 void *p = (void *)CPLD_BASE;
22
23 return in_8(p + reg);
24}
25u8 cpld_read(unsigned int reg) __attribute__((weak, alias("__cpld_read")));
26
27static void __cpld_write(unsigned int reg, u8 value)
28{
29 void *p = (void *)CPLD_BASE;
30
31 out_8(p + reg, value);
32}
33void cpld_write(unsigned int reg, u8 value)
34 __attribute__((weak, alias("__cpld_write")));
35
36/*
37 * Reset the board. This honors the por_cfg registers.
38 */
39void __cpld_reset(void)
40{
41 CPLD_WRITE(system_rst, 1);
42}
43void cpld_reset(void) __attribute__((weak, alias("__cpld_reset")));
44
45/**
46 * Set the boot bank to the alternate bank
47 */
48void __cpld_set_altbank(void)
49{
Shaohui Xie9954cd12011-09-13 17:51:39 +080050 u8 reg5 = CPLD_READ(sw_ctl_on);
51
52 CPLD_WRITE(sw_ctl_on, reg5 | CPLD_SWITCH_BANK_ENABLE);
Mingkai Huf354b532011-07-07 12:29:15 +080053 CPLD_WRITE(fbank_sel, 1);
Shaohui Xie9954cd12011-09-13 17:51:39 +080054 CPLD_WRITE(system_rst, 1);
Mingkai Huf354b532011-07-07 12:29:15 +080055}
56void cpld_set_altbank(void)
57 __attribute__((weak, alias("__cpld_set_altbank")));
58
59/**
60 * Set the boot bank to the default bank
61 */
Shaohui Xie9954cd12011-09-13 17:51:39 +080062void __cpld_set_defbank(void)
Mingkai Huf354b532011-07-07 12:29:15 +080063{
Shaohui Xie9954cd12011-09-13 17:51:39 +080064 CPLD_WRITE(system_rst_default, 1);
Mingkai Huf354b532011-07-07 12:29:15 +080065}
Shaohui Xie9954cd12011-09-13 17:51:39 +080066void cpld_set_defbank(void)
67 __attribute__((weak, alias("__cpld_set_defbank")));
Mingkai Huf354b532011-07-07 12:29:15 +080068
69#ifdef DEBUG
70static void cpld_dump_regs(void)
71{
72 printf("cpld_ver = 0x%02x\n", CPLD_READ(cpld_ver));
73 printf("cpld_ver_sub = 0x%02x\n", CPLD_READ(cpld_ver_sub));
74 printf("pcba_ver = 0x%02x\n", CPLD_READ(pcba_ver));
75 printf("system_rst = 0x%02x\n", CPLD_READ(system_rst));
Mingkai Huf354b532011-07-07 12:29:15 +080076 printf("sw_ctl_on = 0x%02x\n", CPLD_READ(sw_ctl_on));
77 printf("por_cfg = 0x%02x\n", CPLD_READ(por_cfg));
78 printf("switch_strobe = 0x%02x\n", CPLD_READ(switch_strobe));
79 printf("jtag_sel = 0x%02x\n", CPLD_READ(jtag_sel));
80 printf("sdbank1_clk = 0x%02x\n", CPLD_READ(sdbank1_clk));
81 printf("sdbank2_clk = 0x%02x\n", CPLD_READ(sdbank2_clk));
82 printf("fbank_sel = 0x%02x\n", CPLD_READ(fbank_sel));
83 printf("serdes_mux = 0x%02x\n", CPLD_READ(serdes_mux));
84 printf("SW[2] = 0x%02x\n", in_8(&CPLD_SW(2)));
85 putc('\n');
86}
87#endif
88
Simon Glassed38aef2020-05-10 11:40:03 -060089int cpld_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Mingkai Huf354b532011-07-07 12:29:15 +080090{
91 int rc = 0;
Mingkai Huf354b532011-07-07 12:29:15 +080092
93 if (argc <= 1)
94 return cmd_usage(cmdtp);
95
96 if (strcmp(argv[1], "reset") == 0) {
97 if (strcmp(argv[2], "altbank") == 0)
98 cpld_set_altbank();
99 else
Shaohui Xie9954cd12011-09-13 17:51:39 +0800100 cpld_set_defbank();
Mingkai Huf354b532011-07-07 12:29:15 +0800101 } else if (strcmp(argv[1], "lane_mux") == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600102 u32 lane = hextoul(argv[2], NULL);
103 u8 val = (u8)hextoul(argv[3], NULL);
Mingkai Huf354b532011-07-07 12:29:15 +0800104 u8 reg = CPLD_READ(serdes_mux);
105
106 switch (lane) {
107 case 0x6:
108 reg &= ~SERDES_MUX_LANE_6_MASK;
109 reg |= val << SERDES_MUX_LANE_6_SHIFT;
110 break;
111 case 0xa:
112 reg &= ~SERDES_MUX_LANE_A_MASK;
113 reg |= val << SERDES_MUX_LANE_A_SHIFT;
114 break;
115 case 0xc:
116 reg &= ~SERDES_MUX_LANE_C_MASK;
117 reg |= val << SERDES_MUX_LANE_C_SHIFT;
118 break;
119 case 0xd:
120 reg &= ~SERDES_MUX_LANE_D_MASK;
121 reg |= val << SERDES_MUX_LANE_D_SHIFT;
122 break;
123 default:
124 printf("Invalid value\n");
125 break;
126 }
127
128 CPLD_WRITE(serdes_mux, reg);
129#ifdef DEBUG
130 } else if (strcmp(argv[1], "dump") == 0) {
131 cpld_dump_regs();
132#endif
133 } else
134 rc = cmd_usage(cmdtp);
135
136 return rc;
137}
138
139U_BOOT_CMD(
140 cpld_cmd, CONFIG_SYS_MAXARGS, 1, cpld_cmd,
141 "Reset the board or pin mulexing selection using the CPLD sequencer",
142 "reset - hard reset to default bank\n"
143 "cpld_cmd reset altbank - reset to alternate bank\n"
Mingkai Huf354b532011-07-07 12:29:15 +0800144 "cpld_cmd lane_mux <lane> <mux_value> - set multiplexed lane pin\n"
Shaohui Xie99bcecf2011-09-22 17:27:29 +0800145 " lane 6: 0 -> slot1\n"
146 " 1 -> SGMII (Default)\n"
147 " lane a: 0 -> slot2\n"
148 " 1 -> AURORA (Default)\n"
149 " lane c: 0 -> slot2\n"
150 " 1 -> SATA0 (Default)\n"
151 " lane d: 0 -> slot2\n"
152 " 1 -> SATA1 (Default)\n"
Mingkai Huf354b532011-07-07 12:29:15 +0800153#ifdef DEBUG
154 "cpld_cmd dump - display the CPLD registers\n"
155#endif
156 );