Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 2 | /** |
| 3 | * Copyright 2011 Freescale Semiconductor |
| 4 | * Author: Mingkai Hu <Mingkai.hu@freescale.com> |
| 5 | * |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 6 | * 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 Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 12 | */ |
| 13 | |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 14 | #include <command.h> |
| 15 | #include <asm/io.h> |
| 16 | |
| 17 | #include "cpld.h" |
| 18 | |
| 19 | static u8 __cpld_read(unsigned int reg) |
| 20 | { |
| 21 | void *p = (void *)CPLD_BASE; |
| 22 | |
| 23 | return in_8(p + reg); |
| 24 | } |
| 25 | u8 cpld_read(unsigned int reg) __attribute__((weak, alias("__cpld_read"))); |
| 26 | |
| 27 | static void __cpld_write(unsigned int reg, u8 value) |
| 28 | { |
| 29 | void *p = (void *)CPLD_BASE; |
| 30 | |
| 31 | out_8(p + reg, value); |
| 32 | } |
| 33 | void 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 | */ |
| 39 | void __cpld_reset(void) |
| 40 | { |
| 41 | CPLD_WRITE(system_rst, 1); |
| 42 | } |
| 43 | void cpld_reset(void) __attribute__((weak, alias("__cpld_reset"))); |
| 44 | |
| 45 | /** |
| 46 | * Set the boot bank to the alternate bank |
| 47 | */ |
| 48 | void __cpld_set_altbank(void) |
| 49 | { |
Shaohui Xie | 9954cd1 | 2011-09-13 17:51:39 +0800 | [diff] [blame] | 50 | u8 reg5 = CPLD_READ(sw_ctl_on); |
| 51 | |
| 52 | CPLD_WRITE(sw_ctl_on, reg5 | CPLD_SWITCH_BANK_ENABLE); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 53 | CPLD_WRITE(fbank_sel, 1); |
Shaohui Xie | 9954cd1 | 2011-09-13 17:51:39 +0800 | [diff] [blame] | 54 | CPLD_WRITE(system_rst, 1); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 55 | } |
| 56 | void cpld_set_altbank(void) |
| 57 | __attribute__((weak, alias("__cpld_set_altbank"))); |
| 58 | |
| 59 | /** |
| 60 | * Set the boot bank to the default bank |
| 61 | */ |
Shaohui Xie | 9954cd1 | 2011-09-13 17:51:39 +0800 | [diff] [blame] | 62 | void __cpld_set_defbank(void) |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 63 | { |
Shaohui Xie | 9954cd1 | 2011-09-13 17:51:39 +0800 | [diff] [blame] | 64 | CPLD_WRITE(system_rst_default, 1); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 65 | } |
Shaohui Xie | 9954cd1 | 2011-09-13 17:51:39 +0800 | [diff] [blame] | 66 | void cpld_set_defbank(void) |
| 67 | __attribute__((weak, alias("__cpld_set_defbank"))); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 68 | |
| 69 | #ifdef DEBUG |
| 70 | static 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 Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 76 | 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 89 | int cpld_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 90 | { |
| 91 | int rc = 0; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 92 | |
| 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 Xie | 9954cd1 | 2011-09-13 17:51:39 +0800 | [diff] [blame] | 100 | cpld_set_defbank(); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 101 | } else if (strcmp(argv[1], "lane_mux") == 0) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 102 | u32 lane = hextoul(argv[2], NULL); |
| 103 | u8 val = (u8)hextoul(argv[3], NULL); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 104 | 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 | |
| 139 | U_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 Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 144 | "cpld_cmd lane_mux <lane> <mux_value> - set multiplexed lane pin\n" |
Shaohui Xie | 99bcecf | 2011-09-22 17:27:29 +0800 | [diff] [blame] | 145 | " 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 Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 153 | #ifdef DEBUG |
| 154 | "cpld_cmd dump - display the CPLD registers\n" |
| 155 | #endif |
| 156 | ); |