blob: 01607743952b88e22307b66da00f673a9eea2ed5 [file] [log] [blame]
wdenk1cb8e982003-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 Denk88685b52009-03-29 00:58:16 +010030#include <net.h>
wdenk1cb8e982003-03-06 21:55:29 +000031#include "vcma9.h"
32#include "../common/common_util.h"
33
34#if defined(CONFIG_DRIVER_CS8900)
Jean-Christophe PLAGNIOL-VILLARD2439e4b2007-11-21 21:19:24 +010035#include <../drivers/net/cs8900.h>
wdenk1cb8e982003-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 Denk1218abf2007-09-15 20:48:41 +020044DECLARE_GLOBAL_DATA_PTR;
45
wdenk1cb8e982003-03-06 21:55:29 +000046extern void print_vcma9_info(void);
wdenk531716e2003-09-13 19:01:12 +000047extern int vcma9_cantest(int);
wdenk1cb8e982003-03-06 21:55:29 +000048extern int vcma9_nandtest(void);
wdenk531716e2003-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);
wdenk1cb8e982003-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{
wdenk1cb8e982003-03-06 21:55:29 +000059 if (strcmp(argv[1], "info") == 0)
60 {
61 print_vcma9_info();
Wolfgang Denk53677ef2008-05-20 16:00:29 +020062 return 0;
63 }
wdenk1cb8e982003-03-06 21:55:29 +000064#if defined(CONFIG_DRIVER_CS8900)
wdenka2663ea2003-12-07 18:32:37 +000065 if (strcmp(argv[1], "cs8900") == 0) {
wdenk1cb8e982003-03-06 21:55:29 +000066 if (strcmp(argv[2], "read") == 0) {
67 uchar addr; ushort data;
68
69 addr = simple_strtoul(argv[3], NULL, 16);
70 cs8900_e2prom_read(addr, &data);
71 printf("0x%2.2X: 0x%4.4X\n", addr, data);
72 } else if (strcmp(argv[2], "write") == 0) {
73 uchar addr; ushort data;
74
75 addr = simple_strtoul(argv[3], NULL, 16);
76 data = simple_strtoul(argv[4], NULL, 16);
77 cs8900_e2prom_write(addr, data);
78 } else if (strcmp(argv[2], "setaddr") == 0) {
79 uchar addr, i, csum; ushort data;
Mike Frysingerb6b46252009-02-11 18:38:38 -050080 uchar ethaddr[6];
wdenk1cb8e982003-03-06 21:55:29 +000081
82 /* check for valid ethaddr */
Mike Frysingerb6b46252009-02-11 18:38:38 -050083 if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
wdenk1cb8e982003-03-06 21:55:29 +000084 addr = 1;
85 data = 0x2158;
86 cs8900_e2prom_write(addr, data);
87 csum = cs8900_chksum(data);
88 addr++;
89 for (i = 0; i < 6; i+=2) {
Wolfgang Denk88685b52009-03-29 00:58:16 +010090 data = ethaddr[i+1] << 8 |
91 ethaddr[i];
wdenk1cb8e982003-03-06 21:55:29 +000092 cs8900_e2prom_write(addr, data);
93 csum += cs8900_chksum(data);
94 addr++;
95 }
96 /* calculate header link byte */
97 data = 0xA100 | (addr * 2);
98 cs8900_e2prom_write(0, data);
99 csum += cs8900_chksum(data);
100 /* write checksum word */
101 cs8900_e2prom_write(addr, (0 - csum) << 8);
102 } else {
wdenka2663ea2003-12-07 18:32:37 +0000103 puts("\nplease defined 'ethaddr'\n");
wdenk1cb8e982003-03-06 21:55:29 +0000104 }
105 } else if (strcmp(argv[2], "dump") == 0) {
wdenk06d01db2003-03-14 20:47:52 +0000106 uchar addr = 0, endaddr, csum; ushort data;
wdenk1cb8e982003-03-06 21:55:29 +0000107
wdenka2663ea2003-12-07 18:32:37 +0000108 puts("Dump of CS8900 config device: ");
wdenk1cb8e982003-03-06 21:55:29 +0000109 cs8900_e2prom_read(addr, &data);
110 if ((data & 0xE000) == 0xA000) {
111 endaddr = (data & 0x00FF) / 2;
112 csum = cs8900_chksum(data);
113 for (addr = 1; addr <= endaddr; addr++) {
114 cs8900_e2prom_read(addr, &data);
115 printf("\n0x%2.2X: 0x%4.4X", addr, data);
116 csum += cs8900_chksum(data);
117 }
118 printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
119 } else {
wdenka2663ea2003-12-07 18:32:37 +0000120 puts("no valid config found");
wdenk1cb8e982003-03-06 21:55:29 +0000121 }
wdenka2663ea2003-12-07 18:32:37 +0000122 puts("\n");
wdenk1cb8e982003-03-06 21:55:29 +0000123 }
124
125 return 0;
126 }
127#endif
128#if 0
129 if (strcmp(argv[1], "cantest") == 0) {
wdenk531716e2003-09-13 19:01:12 +0000130 if (argc >= 3)
131 vcma9_cantest(strcmp(argv[2], "s") ? 0 : 1);
132 else
133 vcma9_cantest(0);
wdenk1cb8e982003-03-06 21:55:29 +0000134 return 0;
135 }
136 if (strcmp(argv[1], "nandtest") == 0) {
137 vcma9_nandtest();
138 return 0;
139 }
wdenk531716e2003-09-13 19:01:12 +0000140 if (strcmp(argv[1], "nanderase") == 0) {
141 vcma9_nanderase();
142 return 0;
143 }
144 if (strcmp(argv[1], "nandread") == 0) {
145 ulong offset = 0;
146
147 if (argc >= 3)
148 offset = simple_strtoul(argv[2], NULL, 16);
149
150 vcma9_nandread(offset);
151 return 0;
152 }
153 if (strcmp(argv[1], "nandwrite") == 0) {
154 ulong offset = 0;
155
156 if (argc >= 3)
157 offset = simple_strtoul(argv[2], NULL, 16);
158
159 vcma9_nandwrite(offset);
160 return 0;
161 }
wdenk1cb8e982003-03-06 21:55:29 +0000162 if (strcmp(argv[1], "dactest") == 0) {
wdenk531716e2003-09-13 19:01:12 +0000163 if (argc >= 3)
164 vcma9_dactest(strcmp(argv[2], "s") ? 0 : 1);
165 else
166 vcma9_dactest(0);
wdenk1cb8e982003-03-06 21:55:29 +0000167 return 0;
168 }
169#endif
170
171 return (do_mplcommon(cmdtp, flag, argc, argv));
172}
wdenk531716e2003-09-13 19:01:12 +0000173
174U_BOOT_CMD(
175 vcma9, 6, 1, do_vcma9,
Peter Tyser2fb26042009-01-27 18:03:12 -0600176 "VCMA9 specific commands",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200177 "flash mem [SrcAddr]\n - updates U-Boot with image in memory"
wdenk531716e2003-09-13 19:01:12 +0000178);