blob: 7d2aa3cceeb68222f8f2f5c142e0b30b015575a1 [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>
30#include "vcma9.h"
31#include "../common/common_util.h"
32
33#if defined(CONFIG_DRIVER_CS8900)
Jean-Christophe PLAGNIOL-VILLARD2439e4b2007-11-21 21:19:24 +010034#include <../drivers/net/cs8900.h>
wdenk1cb8e982003-03-06 21:55:29 +000035
36static uchar cs8900_chksum(ushort data)
37{
38 return((data >> 8) & 0x00FF) + (data & 0x00FF);
39}
40
41#endif
42
Wolfgang Denk1218abf2007-09-15 20:48:41 +020043DECLARE_GLOBAL_DATA_PTR;
44
wdenk1cb8e982003-03-06 21:55:29 +000045extern void print_vcma9_info(void);
wdenk531716e2003-09-13 19:01:12 +000046extern int vcma9_cantest(int);
wdenk1cb8e982003-03-06 21:55:29 +000047extern int vcma9_nandtest(void);
wdenk531716e2003-09-13 19:01:12 +000048extern int vcma9_nanderase(void);
49extern int vcma9_nandread(ulong);
50extern int vcma9_nandwrite(ulong);
51extern int vcma9_dactest(int);
wdenk1cb8e982003-03-06 21:55:29 +000052extern int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
53
54/* ------------------------------------------------------------------------- */
55
56int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
57{
wdenk1cb8e982003-03-06 21:55:29 +000058 if (strcmp(argv[1], "info") == 0)
59 {
60 print_vcma9_info();
Wolfgang Denk53677ef2008-05-20 16:00:29 +020061 return 0;
62 }
wdenk1cb8e982003-03-06 21:55:29 +000063#if defined(CONFIG_DRIVER_CS8900)
wdenka2663ea2003-12-07 18:32:37 +000064 if (strcmp(argv[1], "cs8900") == 0) {
wdenk1cb8e982003-03-06 21:55:29 +000065 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;
Mike Frysingerb6b46252009-02-11 18:38:38 -050079 uchar ethaddr[6];
wdenk1cb8e982003-03-06 21:55:29 +000080
81 /* check for valid ethaddr */
Mike Frysingerb6b46252009-02-11 18:38:38 -050082 if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
wdenk1cb8e982003-03-06 21:55:29 +000083 addr = 1;
84 data = 0x2158;
85 cs8900_e2prom_write(addr, data);
86 csum = cs8900_chksum(data);
87 addr++;
88 for (i = 0; i < 6; i+=2) {
Mike Frysingerb6b46252009-02-11 18:38:38 -050089 data = enetaddr[i+1] << 8 |
90 enetaddr[i];
wdenk1cb8e982003-03-06 21:55:29 +000091 cs8900_e2prom_write(addr, data);
92 csum += cs8900_chksum(data);
93 addr++;
94 }
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);
101 } else {
wdenka2663ea2003-12-07 18:32:37 +0000102 puts("\nplease defined 'ethaddr'\n");
wdenk1cb8e982003-03-06 21:55:29 +0000103 }
104 } else if (strcmp(argv[2], "dump") == 0) {
wdenk06d01db2003-03-14 20:47:52 +0000105 uchar addr = 0, endaddr, csum; ushort data;
wdenk1cb8e982003-03-06 21:55:29 +0000106
wdenka2663ea2003-12-07 18:32:37 +0000107 puts("Dump of CS8900 config device: ");
wdenk1cb8e982003-03-06 21:55:29 +0000108 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);
116 }
117 printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
118 } else {
wdenka2663ea2003-12-07 18:32:37 +0000119 puts("no valid config found");
wdenk1cb8e982003-03-06 21:55:29 +0000120 }
wdenka2663ea2003-12-07 18:32:37 +0000121 puts("\n");
wdenk1cb8e982003-03-06 21:55:29 +0000122 }
123
124 return 0;
125 }
126#endif
127#if 0
128 if (strcmp(argv[1], "cantest") == 0) {
wdenk531716e2003-09-13 19:01:12 +0000129 if (argc >= 3)
130 vcma9_cantest(strcmp(argv[2], "s") ? 0 : 1);
131 else
132 vcma9_cantest(0);
wdenk1cb8e982003-03-06 21:55:29 +0000133 return 0;
134 }
135 if (strcmp(argv[1], "nandtest") == 0) {
136 vcma9_nandtest();
137 return 0;
138 }
wdenk531716e2003-09-13 19:01:12 +0000139 if (strcmp(argv[1], "nanderase") == 0) {
140 vcma9_nanderase();
141 return 0;
142 }
143 if (strcmp(argv[1], "nandread") == 0) {
144 ulong offset = 0;
145
146 if (argc >= 3)
147 offset = simple_strtoul(argv[2], NULL, 16);
148
149 vcma9_nandread(offset);
150 return 0;
151 }
152 if (strcmp(argv[1], "nandwrite") == 0) {
153 ulong offset = 0;
154
155 if (argc >= 3)
156 offset = simple_strtoul(argv[2], NULL, 16);
157
158 vcma9_nandwrite(offset);
159 return 0;
160 }
wdenk1cb8e982003-03-06 21:55:29 +0000161 if (strcmp(argv[1], "dactest") == 0) {
wdenk531716e2003-09-13 19:01:12 +0000162 if (argc >= 3)
163 vcma9_dactest(strcmp(argv[2], "s") ? 0 : 1);
164 else
165 vcma9_dactest(0);
wdenk1cb8e982003-03-06 21:55:29 +0000166 return 0;
167 }
168#endif
169
170 return (do_mplcommon(cmdtp, flag, argc, argv));
171}
wdenk531716e2003-09-13 19:01:12 +0000172
173U_BOOT_CMD(
174 vcma9, 6, 1, do_vcma9,
Peter Tyser2fb26042009-01-27 18:03:12 -0600175 "VCMA9 specific commands",
wdenk531716e2003-09-13 19:01:12 +0000176 "flash mem [SrcAddr]\n - updates U-Boot with image in memory\n"
177);