]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/mpl/vcma9/cmd_vcma9.c
VCMA9: various cleanups/code style fixes
[karo-tx-uboot.git] / board / mpl / vcma9 / cmd_vcma9.c
1 /*
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 <net.h>
31 #include "vcma9.h"
32 #include "../common/common_util.h"
33
34 #if defined(CONFIG_CS8900)
35 #include <../drivers/net/cs8900.h>
36
37 static uchar cs8900_chksum(ushort data)
38 {
39         return((data >> 8) & 0x00FF) + (data & 0x00FF);
40 }
41
42 #endif
43
44 DECLARE_GLOBAL_DATA_PTR;
45
46 /* ------------------------------------------------------------------------- */
47
48 int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
49 {
50         struct eth_device *dev;
51         char cs8900_name[10];
52         if (strcmp(argv[1], "info") == 0)
53         {
54                 vcma9_print_info();
55                 return 0;
56         }
57 #if defined(CONFIG_CS8900)
58         if (strcmp(argv[1], "cs8900") == 0) {
59                 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                 }
65                 if (strcmp(argv[2], "read") == 0) {
66                         uchar addr; ushort data;
67
68                         addr = simple_strtoul(argv[3], NULL, 16);
69                         cs8900_e2prom_read(dev, 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(dev, addr, data);
77                 } else if (strcmp(argv[2], "setaddr") == 0) {
78                         uchar addr, i, csum; ushort data;
79                         uchar ethaddr[6];
80
81                         /* check for valid ethaddr */
82                         if (eth_getenv_enetaddr("ethaddr", ethaddr)) {
83                                 addr = 1;
84                                 data = 0x2158;
85                                 cs8900_e2prom_write(dev, addr, data);
86                                 csum = cs8900_chksum(data);
87                                 addr++;
88                                 for (i = 0; i < 6; i+=2) {
89                                         data = ethaddr[i+1] << 8 |
90                                                ethaddr[i];
91                                         cs8900_e2prom_write(dev, addr, data);
92                                         csum += cs8900_chksum(data);
93                                         addr++;
94                                 }
95                                 /* calculate header link byte */
96                                 data = 0xA100 | (addr * 2);
97                                 cs8900_e2prom_write(dev, 0, data);
98                                 csum += cs8900_chksum(data);
99                                 /* write checksum word */
100                                 cs8900_e2prom_write(dev, addr, (0 - csum) << 8);
101                         } else {
102                                 puts("\nplease defined 'ethaddr'\n");
103                         }
104                 } else if (strcmp(argv[2], "dump") == 0) {
105                         uchar addr = 0, endaddr, csum; ushort data;
106
107                         puts("Dump of CS8900 config device: ");
108                         cs8900_e2prom_read(dev, 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(dev, 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 {
119                                 puts("no valid config found");
120                         }
121                         puts("\n");
122                 }
123
124                 return 0;
125         }
126 #endif
127
128         return (do_mplcommon(cmdtp, flag, argc, argv));
129 }
130
131 U_BOOT_CMD(
132         vcma9, 6, 1, do_vcma9,
133         "VCMA9 specific commands",
134         "flash mem [SrcAddr] - updates U-Boot with image in memory\n"
135         "vcma9 info                - displays board information"
136 );