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,
31 #include "../common/common_util.h"
33 #if defined(CONFIG_DRIVER_CS8900)
34 #include <../drivers/net/cs8900.h>
36 static uchar cs8900_chksum(ushort data)
38 return((data >> 8) & 0x00FF) + (data & 0x00FF);
43 DECLARE_GLOBAL_DATA_PTR;
45 extern void print_vcma9_info(void);
46 extern int vcma9_cantest(int);
47 extern int vcma9_nandtest(void);
48 extern int vcma9_nanderase(void);
49 extern int vcma9_nandread(ulong);
50 extern int vcma9_nandwrite(ulong);
51 extern int vcma9_dactest(int);
52 extern int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
54 /* ------------------------------------------------------------------------- */
56 int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
58 if (strcmp(argv[1], "info") == 0)
63 #if defined(CONFIG_DRIVER_CS8900)
64 if (strcmp(argv[1], "cs8900") == 0) {
65 if (strcmp(argv[2], "read") == 0) {
66 uchar addr; ushort data;
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;
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;
81 /* check for valid ethaddr */
82 if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
85 cs8900_e2prom_write(addr, data);
86 csum = cs8900_chksum(data);
88 for (i = 0; i < 6; i+=2) {
89 data = enetaddr[i+1] << 8 |
91 cs8900_e2prom_write(addr, data);
92 csum += cs8900_chksum(data);
95 /* calculate header link byte */
96 data = 0xA100 | (addr * 2);
97 cs8900_e2prom_write(0, data);
98 csum += cs8900_chksum(data);
99 /* write checksum word */
100 cs8900_e2prom_write(addr, (0 - csum) << 8);
102 puts("\nplease defined 'ethaddr'\n");
104 } else if (strcmp(argv[2], "dump") == 0) {
105 uchar addr = 0, endaddr, csum; ushort data;
107 puts("Dump of CS8900 config device: ");
108 cs8900_e2prom_read(addr, &data);
109 if ((data & 0xE000) == 0xA000) {
110 endaddr = (data & 0x00FF) / 2;
111 csum = cs8900_chksum(data);
112 for (addr = 1; addr <= endaddr; addr++) {
113 cs8900_e2prom_read(addr, &data);
114 printf("\n0x%2.2X: 0x%4.4X", addr, data);
115 csum += cs8900_chksum(data);
117 printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
119 puts("no valid config found");
128 if (strcmp(argv[1], "cantest") == 0) {
130 vcma9_cantest(strcmp(argv[2], "s") ? 0 : 1);
135 if (strcmp(argv[1], "nandtest") == 0) {
139 if (strcmp(argv[1], "nanderase") == 0) {
143 if (strcmp(argv[1], "nandread") == 0) {
147 offset = simple_strtoul(argv[2], NULL, 16);
149 vcma9_nandread(offset);
152 if (strcmp(argv[1], "nandwrite") == 0) {
156 offset = simple_strtoul(argv[2], NULL, 16);
158 vcma9_nandwrite(offset);
161 if (strcmp(argv[1], "dactest") == 0) {
163 vcma9_dactest(strcmp(argv[2], "s") ? 0 : 1);
170 return (do_mplcommon(cmdtp, flag, argc, argv));
174 vcma9, 6, 1, do_vcma9,
175 "VCMA9 specific commands",
176 "flash mem [SrcAddr]\n - updates U-Boot with image in memory\n"