blob: 0ee959507f7e516626b667ef2a6731073a5efda9 [file] [log] [blame]
wdenk1fe2c702003-03-06 21:55:29 +00001/*
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>
Wolfgang Denk64af8132009-03-29 00:58:16 +010030#include <net.h>
wdenk1fe2c702003-03-06 21:55:29 +000031#include "vcma9.h"
32#include "../common/common_util.h"
33
Ben Warren3bf5d832009-08-25 13:09:37 -070034#if defined(CONFIG_CS8900)
Jean-Christophe PLAGNIOL-VILLARDed0ea1f2007-11-21 21:19:24 +010035#include <../drivers/net/cs8900.h>
wdenk1fe2c702003-03-06 21:55:29 +000036
37static uchar cs8900_chksum(ushort data)
38{
39 return((data >> 8) & 0x00FF) + (data & 0x00FF);
40}
41
42#endif
43
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020044DECLARE_GLOBAL_DATA_PTR;
45
wdenk1fe2c702003-03-06 21:55:29 +000046extern void print_vcma9_info(void);
wdenk25521902003-09-13 19:01:12 +000047extern int vcma9_cantest(int);
wdenk1fe2c702003-03-06 21:55:29 +000048extern int vcma9_nandtest(void);
wdenk25521902003-09-13 19:01:12 +000049extern int vcma9_nanderase(void);
50extern int vcma9_nandread(ulong);
51extern int vcma9_nandwrite(ulong);
52extern int vcma9_dactest(int);
wdenk1fe2c702003-03-06 21:55:29 +000053extern int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
54
55/* ------------------------------------------------------------------------- */
56
57int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
58{
Ben Warren3bf5d832009-08-25 13:09:37 -070059 struct eth_device *dev;
60 char cs8900_name[10];
wdenk1fe2c702003-03-06 21:55:29 +000061 if (strcmp(argv[1], "info") == 0)
62 {
63 print_vcma9_info();
Wolfgang Denka1be4762008-05-20 16:00:29 +020064 return 0;
65 }
Ben Warren3bf5d832009-08-25 13:09:37 -070066#if defined(CONFIG_CS8900)
wdenk4ea537d2003-12-07 18:32:37 +000067 if (strcmp(argv[1], "cs8900") == 0) {
Ben Warren3bf5d832009-08-25 13:09:37 -070068 sprintf(cs8900_name, "%s-0", CS8900_DRIVERNAME);
69 dev = eth_get_dev_by_name(cs8900_name);
70 if (!dev) {
71 printf("Couldn't find CS8900 driver");
72 return 0;
73 }
wdenk1fe2c702003-03-06 21:55:29 +000074 if (strcmp(argv[2], "read") == 0) {
75 uchar addr; ushort data;
76
77 addr = simple_strtoul(argv[3], NULL, 16);
Ben Warren3bf5d832009-08-25 13:09:37 -070078 cs8900_e2prom_read(dev, addr, &data);
wdenk1fe2c702003-03-06 21:55:29 +000079 printf("0x%2.2X: 0x%4.4X\n", addr, data);
80 } else if (strcmp(argv[2], "write") == 0) {
81 uchar addr; ushort data;
82
83 addr = simple_strtoul(argv[3], NULL, 16);
84 data = simple_strtoul(argv[4], NULL, 16);
Ben Warren3bf5d832009-08-25 13:09:37 -070085 cs8900_e2prom_write(dev, addr, data);
wdenk1fe2c702003-03-06 21:55:29 +000086 } else if (strcmp(argv[2], "setaddr") == 0) {
87 uchar addr, i, csum; ushort data;
Mike Frysinger69798322009-02-11 18:38:38 -050088 uchar ethaddr[6];
wdenk1fe2c702003-03-06 21:55:29 +000089
90 /* check for valid ethaddr */
Mike Frysinger69798322009-02-11 18:38:38 -050091 if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
wdenk1fe2c702003-03-06 21:55:29 +000092 addr = 1;
93 data = 0x2158;
Ben Warren3bf5d832009-08-25 13:09:37 -070094 cs8900_e2prom_write(dev, addr, data);
wdenk1fe2c702003-03-06 21:55:29 +000095 csum = cs8900_chksum(data);
96 addr++;
97 for (i = 0; i < 6; i+=2) {
Wolfgang Denk64af8132009-03-29 00:58:16 +010098 data = ethaddr[i+1] << 8 |
99 ethaddr[i];
Ben Warren3bf5d832009-08-25 13:09:37 -0700100 cs8900_e2prom_write(dev, addr, data);
wdenk1fe2c702003-03-06 21:55:29 +0000101 csum += cs8900_chksum(data);
102 addr++;
103 }
104 /* calculate header link byte */
105 data = 0xA100 | (addr * 2);
Ben Warren3bf5d832009-08-25 13:09:37 -0700106 cs8900_e2prom_write(dev, 0, data);
wdenk1fe2c702003-03-06 21:55:29 +0000107 csum += cs8900_chksum(data);
108 /* write checksum word */
Ben Warren3bf5d832009-08-25 13:09:37 -0700109 cs8900_e2prom_write(dev, addr, (0 - csum) << 8);
wdenk1fe2c702003-03-06 21:55:29 +0000110 } else {
wdenk4ea537d2003-12-07 18:32:37 +0000111 puts("\nplease defined 'ethaddr'\n");
wdenk1fe2c702003-03-06 21:55:29 +0000112 }
113 } else if (strcmp(argv[2], "dump") == 0) {
wdenk6b58f332003-03-14 20:47:52 +0000114 uchar addr = 0, endaddr, csum; ushort data;
wdenk1fe2c702003-03-06 21:55:29 +0000115
wdenk4ea537d2003-12-07 18:32:37 +0000116 puts("Dump of CS8900 config device: ");
Ben Warren3bf5d832009-08-25 13:09:37 -0700117 cs8900_e2prom_read(dev, addr, &data);
wdenk1fe2c702003-03-06 21:55:29 +0000118 if ((data & 0xE000) == 0xA000) {
119 endaddr = (data & 0x00FF) / 2;
120 csum = cs8900_chksum(data);
121 for (addr = 1; addr <= endaddr; addr++) {
Ben Warren3bf5d832009-08-25 13:09:37 -0700122 cs8900_e2prom_read(dev, addr, &data);
wdenk1fe2c702003-03-06 21:55:29 +0000123 printf("\n0x%2.2X: 0x%4.4X", addr, data);
124 csum += cs8900_chksum(data);
125 }
126 printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
127 } else {
wdenk4ea537d2003-12-07 18:32:37 +0000128 puts("no valid config found");
wdenk1fe2c702003-03-06 21:55:29 +0000129 }
wdenk4ea537d2003-12-07 18:32:37 +0000130 puts("\n");
wdenk1fe2c702003-03-06 21:55:29 +0000131 }
132
133 return 0;
134 }
135#endif
136#if 0
137 if (strcmp(argv[1], "cantest") == 0) {
wdenk25521902003-09-13 19:01:12 +0000138 if (argc >= 3)
139 vcma9_cantest(strcmp(argv[2], "s") ? 0 : 1);
140 else
141 vcma9_cantest(0);
wdenk1fe2c702003-03-06 21:55:29 +0000142 return 0;
143 }
144 if (strcmp(argv[1], "nandtest") == 0) {
145 vcma9_nandtest();
146 return 0;
147 }
wdenk25521902003-09-13 19:01:12 +0000148 if (strcmp(argv[1], "nanderase") == 0) {
149 vcma9_nanderase();
150 return 0;
151 }
152 if (strcmp(argv[1], "nandread") == 0) {
153 ulong offset = 0;
154
155 if (argc >= 3)
156 offset = simple_strtoul(argv[2], NULL, 16);
157
158 vcma9_nandread(offset);
159 return 0;
160 }
161 if (strcmp(argv[1], "nandwrite") == 0) {
162 ulong offset = 0;
163
164 if (argc >= 3)
165 offset = simple_strtoul(argv[2], NULL, 16);
166
167 vcma9_nandwrite(offset);
168 return 0;
169 }
wdenk1fe2c702003-03-06 21:55:29 +0000170 if (strcmp(argv[1], "dactest") == 0) {
wdenk25521902003-09-13 19:01:12 +0000171 if (argc >= 3)
172 vcma9_dactest(strcmp(argv[2], "s") ? 0 : 1);
173 else
174 vcma9_dactest(0);
wdenk1fe2c702003-03-06 21:55:29 +0000175 return 0;
176 }
177#endif
178
179 return (do_mplcommon(cmdtp, flag, argc, argv));
180}
wdenk25521902003-09-13 19:01:12 +0000181
182U_BOOT_CMD(
183 vcma9, 6, 1, do_vcma9,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600184 "VCMA9 specific commands",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200185 "flash mem [SrcAddr]\n - updates U-Boot with image in memory"
wdenk25521902003-09-13 19:01:12 +0000186);