wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch |
| 4 | * |
| 5 | * adapted for VCMA9 |
| 6 | * David Mueller, ELSOFT AG, d.mueller@elsoft.ch |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <command.h> |
| 30 | #include "vcma9.h" |
| 31 | #include "../common/common_util.h" |
| 32 | |
| 33 | #if defined(CONFIG_DRIVER_CS8900) |
| 34 | #include <../drivers/cs8900.h> |
| 35 | |
| 36 | static uchar cs8900_chksum(ushort data) |
| 37 | { |
| 38 | return((data >> 8) & 0x00FF) + (data & 0x00FF); |
| 39 | } |
| 40 | |
| 41 | #endif |
| 42 | |
| 43 | extern void print_vcma9_info(void); |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 44 | extern int vcma9_cantest(int); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 45 | extern int vcma9_nandtest(void); |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 46 | extern int vcma9_nanderase(void); |
| 47 | extern int vcma9_nandread(ulong); |
| 48 | extern int vcma9_nandwrite(ulong); |
| 49 | extern int vcma9_dactest(int); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 50 | extern int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 51 | |
| 52 | /* ------------------------------------------------------------------------- */ |
| 53 | |
| 54 | int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 55 | { |
| 56 | DECLARE_GLOBAL_DATA_PTR; |
| 57 | |
| 58 | if (strcmp(argv[1], "info") == 0) |
| 59 | { |
| 60 | print_vcma9_info(); |
| 61 | return 0; |
| 62 | } |
| 63 | #if defined(CONFIG_DRIVER_CS8900) |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 64 | if (strcmp(argv[1], "cs8900") == 0) { |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 65 | if (strcmp(argv[2], "read") == 0) { |
| 66 | uchar addr; ushort data; |
| 67 | |
| 68 | addr = simple_strtoul(argv[3], NULL, 16); |
| 69 | cs8900_e2prom_read(addr, &data); |
| 70 | printf("0x%2.2X: 0x%4.4X\n", addr, data); |
| 71 | } else if (strcmp(argv[2], "write") == 0) { |
| 72 | uchar addr; ushort data; |
| 73 | |
| 74 | addr = simple_strtoul(argv[3], NULL, 16); |
| 75 | data = simple_strtoul(argv[4], NULL, 16); |
| 76 | cs8900_e2prom_write(addr, data); |
| 77 | } else if (strcmp(argv[2], "setaddr") == 0) { |
| 78 | uchar addr, i, csum; ushort data; |
| 79 | |
| 80 | /* check for valid ethaddr */ |
| 81 | for (i = 0; i < 6; i++) |
| 82 | if (gd->bd->bi_enetaddr[i] != 0) |
| 83 | break; |
| 84 | |
| 85 | if (i < 6) { |
| 86 | addr = 1; |
| 87 | data = 0x2158; |
| 88 | cs8900_e2prom_write(addr, data); |
| 89 | csum = cs8900_chksum(data); |
| 90 | addr++; |
| 91 | for (i = 0; i < 6; i+=2) { |
| 92 | data = gd->bd->bi_enetaddr[i+1] << 8 | |
| 93 | gd->bd->bi_enetaddr[i]; |
| 94 | cs8900_e2prom_write(addr, data); |
| 95 | csum += cs8900_chksum(data); |
| 96 | addr++; |
| 97 | } |
| 98 | /* calculate header link byte */ |
| 99 | data = 0xA100 | (addr * 2); |
| 100 | cs8900_e2prom_write(0, data); |
| 101 | csum += cs8900_chksum(data); |
| 102 | /* write checksum word */ |
| 103 | cs8900_e2prom_write(addr, (0 - csum) << 8); |
| 104 | } else { |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 105 | puts("\nplease defined 'ethaddr'\n"); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 106 | } |
| 107 | } else if (strcmp(argv[2], "dump") == 0) { |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 108 | uchar addr = 0, endaddr, csum; ushort data; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 109 | |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 110 | puts("Dump of CS8900 config device: "); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 111 | cs8900_e2prom_read(addr, &data); |
| 112 | if ((data & 0xE000) == 0xA000) { |
| 113 | endaddr = (data & 0x00FF) / 2; |
| 114 | csum = cs8900_chksum(data); |
| 115 | for (addr = 1; addr <= endaddr; addr++) { |
| 116 | cs8900_e2prom_read(addr, &data); |
| 117 | printf("\n0x%2.2X: 0x%4.4X", addr, data); |
| 118 | csum += cs8900_chksum(data); |
| 119 | } |
| 120 | printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong"); |
| 121 | } else { |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 122 | puts("no valid config found"); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 123 | } |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 124 | puts("\n"); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | #endif |
| 130 | #if 0 |
| 131 | if (strcmp(argv[1], "cantest") == 0) { |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 132 | if (argc >= 3) |
| 133 | vcma9_cantest(strcmp(argv[2], "s") ? 0 : 1); |
| 134 | else |
| 135 | vcma9_cantest(0); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | if (strcmp(argv[1], "nandtest") == 0) { |
| 139 | vcma9_nandtest(); |
| 140 | return 0; |
| 141 | } |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 142 | if (strcmp(argv[1], "nanderase") == 0) { |
| 143 | vcma9_nanderase(); |
| 144 | return 0; |
| 145 | } |
| 146 | if (strcmp(argv[1], "nandread") == 0) { |
| 147 | ulong offset = 0; |
| 148 | |
| 149 | if (argc >= 3) |
| 150 | offset = simple_strtoul(argv[2], NULL, 16); |
| 151 | |
| 152 | vcma9_nandread(offset); |
| 153 | return 0; |
| 154 | } |
| 155 | if (strcmp(argv[1], "nandwrite") == 0) { |
| 156 | ulong offset = 0; |
| 157 | |
| 158 | if (argc >= 3) |
| 159 | offset = simple_strtoul(argv[2], NULL, 16); |
| 160 | |
| 161 | vcma9_nandwrite(offset); |
| 162 | return 0; |
| 163 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 164 | if (strcmp(argv[1], "dactest") == 0) { |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 165 | if (argc >= 3) |
| 166 | vcma9_dactest(strcmp(argv[2], "s") ? 0 : 1); |
| 167 | else |
| 168 | vcma9_dactest(0); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | #endif |
| 172 | |
| 173 | return (do_mplcommon(cmdtp, flag, argc, argv)); |
| 174 | } |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 175 | |
| 176 | U_BOOT_CMD( |
| 177 | vcma9, 6, 1, do_vcma9, |
| 178 | "vcma9 - VCMA9 specific commands\n", |
| 179 | "flash mem [SrcAddr]\n - updates U-Boot with image in memory\n" |
| 180 | ); |