blob: c2d62e4aaf4b54af334372cb3226f52346bef1f5 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk1fe2c702003-03-06 21:55:29 +00009 */
10
11#include <common.h>
12#include <command.h>
Wolfgang Denk64af8132009-03-29 00:58:16 +010013#include <net.h>
wdenk1fe2c702003-03-06 21:55:29 +000014#include "vcma9.h"
15#include "../common/common_util.h"
16
Ben Warren3bf5d832009-08-25 13:09:37 -070017#if defined(CONFIG_CS8900)
Jean-Christophe PLAGNIOL-VILLARDed0ea1f2007-11-21 21:19:24 +010018#include <../drivers/net/cs8900.h>
wdenk1fe2c702003-03-06 21:55:29 +000019
20static uchar cs8900_chksum(ushort data)
21{
22 return((data >> 8) & 0x00FF) + (data & 0x00FF);
23}
24
25#endif
26
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020027DECLARE_GLOBAL_DATA_PTR;
28
wdenk1fe2c702003-03-06 21:55:29 +000029/* ------------------------------------------------------------------------- */
30
Wolfgang Denk6262d0212010-06-28 22:00:46 +020031int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk1fe2c702003-03-06 21:55:29 +000032{
Ben Warren3bf5d832009-08-25 13:09:37 -070033 struct eth_device *dev;
34 char cs8900_name[10];
wdenk1fe2c702003-03-06 21:55:29 +000035 if (strcmp(argv[1], "info") == 0)
36 {
David Müller (ELSOFT AG)d3a4d252011-05-01 21:52:51 +000037 vcma9_print_info();
Wolfgang Denka1be4762008-05-20 16:00:29 +020038 return 0;
39 }
Ben Warren3bf5d832009-08-25 13:09:37 -070040#if defined(CONFIG_CS8900)
wdenk4ea537d2003-12-07 18:32:37 +000041 if (strcmp(argv[1], "cs8900") == 0) {
Ben Warren3bf5d832009-08-25 13:09:37 -070042 sprintf(cs8900_name, "%s-0", CS8900_DRIVERNAME);
43 dev = eth_get_dev_by_name(cs8900_name);
44 if (!dev) {
45 printf("Couldn't find CS8900 driver");
46 return 0;
47 }
wdenk1fe2c702003-03-06 21:55:29 +000048 if (strcmp(argv[2], "read") == 0) {
49 uchar addr; ushort data;
50
51 addr = simple_strtoul(argv[3], NULL, 16);
Ben Warren3bf5d832009-08-25 13:09:37 -070052 cs8900_e2prom_read(dev, addr, &data);
wdenk1fe2c702003-03-06 21:55:29 +000053 printf("0x%2.2X: 0x%4.4X\n", addr, data);
54 } else if (strcmp(argv[2], "write") == 0) {
55 uchar addr; ushort data;
56
57 addr = simple_strtoul(argv[3], NULL, 16);
58 data = simple_strtoul(argv[4], NULL, 16);
Ben Warren3bf5d832009-08-25 13:09:37 -070059 cs8900_e2prom_write(dev, addr, data);
wdenk1fe2c702003-03-06 21:55:29 +000060 } else if (strcmp(argv[2], "setaddr") == 0) {
61 uchar addr, i, csum; ushort data;
Mike Frysinger69798322009-02-11 18:38:38 -050062 uchar ethaddr[6];
wdenk1fe2c702003-03-06 21:55:29 +000063
64 /* check for valid ethaddr */
Mike Frysinger69798322009-02-11 18:38:38 -050065 if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
wdenk1fe2c702003-03-06 21:55:29 +000066 addr = 1;
67 data = 0x2158;
Ben Warren3bf5d832009-08-25 13:09:37 -070068 cs8900_e2prom_write(dev, addr, data);
wdenk1fe2c702003-03-06 21:55:29 +000069 csum = cs8900_chksum(data);
70 addr++;
71 for (i = 0; i < 6; i+=2) {
Wolfgang Denk64af8132009-03-29 00:58:16 +010072 data = ethaddr[i+1] << 8 |
73 ethaddr[i];
Ben Warren3bf5d832009-08-25 13:09:37 -070074 cs8900_e2prom_write(dev, addr, data);
wdenk1fe2c702003-03-06 21:55:29 +000075 csum += cs8900_chksum(data);
76 addr++;
77 }
78 /* calculate header link byte */
79 data = 0xA100 | (addr * 2);
Ben Warren3bf5d832009-08-25 13:09:37 -070080 cs8900_e2prom_write(dev, 0, data);
wdenk1fe2c702003-03-06 21:55:29 +000081 csum += cs8900_chksum(data);
82 /* write checksum word */
Ben Warren3bf5d832009-08-25 13:09:37 -070083 cs8900_e2prom_write(dev, addr, (0 - csum) << 8);
wdenk1fe2c702003-03-06 21:55:29 +000084 } else {
wdenk4ea537d2003-12-07 18:32:37 +000085 puts("\nplease defined 'ethaddr'\n");
wdenk1fe2c702003-03-06 21:55:29 +000086 }
87 } else if (strcmp(argv[2], "dump") == 0) {
wdenk6b58f332003-03-14 20:47:52 +000088 uchar addr = 0, endaddr, csum; ushort data;
wdenk1fe2c702003-03-06 21:55:29 +000089
wdenk4ea537d2003-12-07 18:32:37 +000090 puts("Dump of CS8900 config device: ");
Ben Warren3bf5d832009-08-25 13:09:37 -070091 cs8900_e2prom_read(dev, addr, &data);
wdenk1fe2c702003-03-06 21:55:29 +000092 if ((data & 0xE000) == 0xA000) {
93 endaddr = (data & 0x00FF) / 2;
94 csum = cs8900_chksum(data);
95 for (addr = 1; addr <= endaddr; addr++) {
Ben Warren3bf5d832009-08-25 13:09:37 -070096 cs8900_e2prom_read(dev, addr, &data);
wdenk1fe2c702003-03-06 21:55:29 +000097 printf("\n0x%2.2X: 0x%4.4X", addr, data);
98 csum += cs8900_chksum(data);
99 }
100 printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
101 } else {
wdenk4ea537d2003-12-07 18:32:37 +0000102 puts("no valid config found");
wdenk1fe2c702003-03-06 21:55:29 +0000103 }
wdenk4ea537d2003-12-07 18:32:37 +0000104 puts("\n");
wdenk1fe2c702003-03-06 21:55:29 +0000105 }
106
wdenk1fe2c702003-03-06 21:55:29 +0000107 return 0;
108 }
109#endif
110
111 return (do_mplcommon(cmdtp, flag, argc, argv));
112}
wdenk25521902003-09-13 19:01:12 +0000113
114U_BOOT_CMD(
115 vcma9, 6, 1, do_vcma9,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600116 "VCMA9 specific commands",
David Müller (ELSOFT AG)d3a4d252011-05-01 21:52:51 +0000117 "flash mem [SrcAddr] - updates U-Boot with image in memory\n"
118 "vcma9 info - displays board information"
wdenk25521902003-09-13 19:01:12 +0000119);