3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
6 * David Mueller, ELSOFT AG, d.mueller@elsoft.ch
8 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #include "../common/common_util.h"
34 #if defined(CONFIG_CS8900)
35 #include <../drivers/net/cs8900.h>
37 static uchar cs8900_chksum(ushort data)
39 return((data >> 8) & 0x00FF) + (data & 0x00FF);
44 DECLARE_GLOBAL_DATA_PTR;
46 extern void print_vcma9_info(void);
47 extern int vcma9_cantest(int);
48 extern int vcma9_nandtest(void);
49 extern int vcma9_nanderase(void);
50 extern int vcma9_nandread(ulong);
51 extern int vcma9_nandwrite(ulong);
52 extern int vcma9_dactest(int);
53 extern int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
55 /* ------------------------------------------------------------------------- */
57 int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
59 struct eth_device *dev;
61 if (strcmp(argv[1], "info") == 0)
66 #if defined(CONFIG_CS8900)
67 if (strcmp(argv[1], "cs8900") == 0) {
68 sprintf(cs8900_name, "%s-0", CS8900_DRIVERNAME);
69 dev = eth_get_dev_by_name(cs8900_name);
71 printf("Couldn't find CS8900 driver");
74 if (strcmp(argv[2], "read") == 0) {
75 uchar addr; ushort data;
77 addr = simple_strtoul(argv[3], NULL, 16);
78 cs8900_e2prom_read(dev, addr, &data);
79 printf("0x%2.2X: 0x%4.4X\n", addr, data);
80 } else if (strcmp(argv[2], "write") == 0) {
81 uchar addr; ushort data;
83 addr = simple_strtoul(argv[3], NULL, 16);
84 data = simple_strtoul(argv[4], NULL, 16);
85 cs8900_e2prom_write(dev, addr, data);
86 } else if (strcmp(argv[2], "setaddr") == 0) {
87 uchar addr, i, csum; ushort data;
90 /* check for valid ethaddr */
91 if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
94 cs8900_e2prom_write(dev, addr, data);
95 csum = cs8900_chksum(data);
97 for (i = 0; i < 6; i+=2) {
98 data = ethaddr[i+1] << 8 |
100 cs8900_e2prom_write(dev, addr, data);
101 csum += cs8900_chksum(data);
104 /* calculate header link byte */
105 data = 0xA100 | (addr * 2);
106 cs8900_e2prom_write(dev, 0, data);
107 csum += cs8900_chksum(data);
108 /* write checksum word */
109 cs8900_e2prom_write(dev, addr, (0 - csum) << 8);
111 puts("\nplease defined 'ethaddr'\n");
113 } else if (strcmp(argv[2], "dump") == 0) {
114 uchar addr = 0, endaddr, csum; ushort data;
116 puts("Dump of CS8900 config device: ");
117 cs8900_e2prom_read(dev, addr, &data);
118 if ((data & 0xE000) == 0xA000) {
119 endaddr = (data & 0x00FF) / 2;
120 csum = cs8900_chksum(data);
121 for (addr = 1; addr <= endaddr; addr++) {
122 cs8900_e2prom_read(dev, addr, &data);
123 printf("\n0x%2.2X: 0x%4.4X", addr, data);
124 csum += cs8900_chksum(data);
126 printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
128 puts("no valid config found");
137 if (strcmp(argv[1], "cantest") == 0) {
139 vcma9_cantest(strcmp(argv[2], "s") ? 0 : 1);
144 if (strcmp(argv[1], "nandtest") == 0) {
148 if (strcmp(argv[1], "nanderase") == 0) {
152 if (strcmp(argv[1], "nandread") == 0) {
156 offset = simple_strtoul(argv[2], NULL, 16);
158 vcma9_nandread(offset);
161 if (strcmp(argv[1], "nandwrite") == 0) {
165 offset = simple_strtoul(argv[2], NULL, 16);
167 vcma9_nandwrite(offset);
170 if (strcmp(argv[1], "dactest") == 0) {
172 vcma9_dactest(strcmp(argv[2], "s") ? 0 : 1);
179 return (do_mplcommon(cmdtp, flag, argc, argv));
183 vcma9, 6, 1, do_vcma9,
184 "VCMA9 specific commands",
185 "flash mem [SrcAddr]\n - updates U-Boot with image in memory"