blob: fa49918ab8ae38d73e035230a10a53f1f8598e76 [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
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070034#if defined(CONFIG_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 +000046/* ------------------------------------------------------------------------- */
47
Wolfgang Denk54841ab2010-06-28 22:00:46 +020048int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk1cb8e982003-03-06 21:55:29 +000049{
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070050 struct eth_device *dev;
51 char cs8900_name[10];
wdenk1cb8e982003-03-06 21:55:29 +000052 if (strcmp(argv[1], "info") == 0)
53 {
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000054 vcma9_print_info();
Wolfgang Denk53677ef2008-05-20 16:00:29 +020055 return 0;
56 }
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070057#if defined(CONFIG_CS8900)
wdenka2663ea2003-12-07 18:32:37 +000058 if (strcmp(argv[1], "cs8900") == 0) {
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070059 sprintf(cs8900_name, "%s-0", CS8900_DRIVERNAME);
60 dev = eth_get_dev_by_name(cs8900_name);
61 if (!dev) {
62 printf("Couldn't find CS8900 driver");
63 return 0;
64 }
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);
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070069 cs8900_e2prom_read(dev, addr, &data);
wdenk1cb8e982003-03-06 21:55:29 +000070 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);
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070076 cs8900_e2prom_write(dev, addr, data);
wdenk1cb8e982003-03-06 21:55:29 +000077 } 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;
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070085 cs8900_e2prom_write(dev, addr, data);
wdenk1cb8e982003-03-06 21:55:29 +000086 csum = cs8900_chksum(data);
87 addr++;
88 for (i = 0; i < 6; i+=2) {
Wolfgang Denk88685b52009-03-29 00:58:16 +010089 data = ethaddr[i+1] << 8 |
90 ethaddr[i];
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070091 cs8900_e2prom_write(dev, addr, data);
wdenk1cb8e982003-03-06 21:55:29 +000092 csum += cs8900_chksum(data);
93 addr++;
94 }
95 /* calculate header link byte */
96 data = 0xA100 | (addr * 2);
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070097 cs8900_e2prom_write(dev, 0, data);
wdenk1cb8e982003-03-06 21:55:29 +000098 csum += cs8900_chksum(data);
99 /* write checksum word */
Ben Warrenb1c0eaa2009-08-25 13:09:37 -0700100 cs8900_e2prom_write(dev, addr, (0 - csum) << 8);
wdenk1cb8e982003-03-06 21:55:29 +0000101 } 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: ");
Ben Warrenb1c0eaa2009-08-25 13:09:37 -0700108 cs8900_e2prom_read(dev, addr, &data);
wdenk1cb8e982003-03-06 21:55:29 +0000109 if ((data & 0xE000) == 0xA000) {
110 endaddr = (data & 0x00FF) / 2;
111 csum = cs8900_chksum(data);
112 for (addr = 1; addr <= endaddr; addr++) {
Ben Warrenb1c0eaa2009-08-25 13:09:37 -0700113 cs8900_e2prom_read(dev, addr, &data);
wdenk1cb8e982003-03-06 21:55:29 +0000114 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
wdenk1cb8e982003-03-06 21:55:29 +0000127
128 return (do_mplcommon(cmdtp, flag, argc, argv));
129}
wdenk531716e2003-09-13 19:01:12 +0000130
131U_BOOT_CMD(
132 vcma9, 6, 1, do_vcma9,
Peter Tyser2fb26042009-01-27 18:03:12 -0600133 "VCMA9 specific commands",
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000134 "flash mem [SrcAddr] - updates U-Boot with image in memory\n"
135 "vcma9 info - displays board information"
wdenk531716e2003-09-13 19:01:12 +0000136);