wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
Wolfgang Denk | 88685b5 | 2009-03-29 00:58:16 +0100 | [diff] [blame] | 13 | #include <net.h> |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 14 | #include "vcma9.h" |
| 15 | #include "../common/common_util.h" |
| 16 | |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 17 | #if defined(CONFIG_CS8900) |
Jean-Christophe PLAGNIOL-VILLARD | 2439e4b | 2007-11-21 21:19:24 +0100 | [diff] [blame] | 18 | #include <../drivers/net/cs8900.h> |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 19 | |
| 20 | static uchar cs8900_chksum(ushort data) |
| 21 | { |
| 22 | return((data >> 8) & 0x00FF) + (data & 0x00FF); |
| 23 | } |
| 24 | |
| 25 | #endif |
| 26 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 29 | /* ------------------------------------------------------------------------- */ |
| 30 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 31 | int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 32 | { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 33 | struct eth_device *dev; |
| 34 | char cs8900_name[10]; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 35 | if (strcmp(argv[1], "info") == 0) |
| 36 | { |
David Müller (ELSOFT AG) | f310830 | 2011-05-01 21:52:51 +0000 | [diff] [blame] | 37 | vcma9_print_info(); |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 38 | return 0; |
| 39 | } |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 40 | #if defined(CONFIG_CS8900) |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 41 | if (strcmp(argv[1], "cs8900") == 0) { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 42 | 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 | } |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 48 | if (strcmp(argv[2], "read") == 0) { |
| 49 | uchar addr; ushort data; |
| 50 | |
| 51 | addr = simple_strtoul(argv[3], NULL, 16); |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 52 | cs8900_e2prom_read(dev, addr, &data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 53 | 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 Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 59 | cs8900_e2prom_write(dev, addr, data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 60 | } else if (strcmp(argv[2], "setaddr") == 0) { |
| 61 | uchar addr, i, csum; ushort data; |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 62 | uchar ethaddr[6]; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 63 | |
| 64 | /* check for valid ethaddr */ |
Mike Frysinger | b6b4625 | 2009-02-11 18:38:38 -0500 | [diff] [blame] | 65 | if (eth_getenv_enetaddr("ethaddr", ethaddr)) { |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 66 | addr = 1; |
| 67 | data = 0x2158; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 68 | cs8900_e2prom_write(dev, addr, data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 69 | csum = cs8900_chksum(data); |
| 70 | addr++; |
| 71 | for (i = 0; i < 6; i+=2) { |
Wolfgang Denk | 88685b5 | 2009-03-29 00:58:16 +0100 | [diff] [blame] | 72 | data = ethaddr[i+1] << 8 | |
| 73 | ethaddr[i]; |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 74 | cs8900_e2prom_write(dev, addr, data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 75 | csum += cs8900_chksum(data); |
| 76 | addr++; |
| 77 | } |
| 78 | /* calculate header link byte */ |
| 79 | data = 0xA100 | (addr * 2); |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 80 | cs8900_e2prom_write(dev, 0, data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 81 | csum += cs8900_chksum(data); |
| 82 | /* write checksum word */ |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 83 | cs8900_e2prom_write(dev, addr, (0 - csum) << 8); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 84 | } else { |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 85 | puts("\nplease defined 'ethaddr'\n"); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 86 | } |
| 87 | } else if (strcmp(argv[2], "dump") == 0) { |
wdenk | 06d01db | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 88 | uchar addr = 0, endaddr, csum; ushort data; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 89 | |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 90 | puts("Dump of CS8900 config device: "); |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 91 | cs8900_e2prom_read(dev, addr, &data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 92 | if ((data & 0xE000) == 0xA000) { |
| 93 | endaddr = (data & 0x00FF) / 2; |
| 94 | csum = cs8900_chksum(data); |
| 95 | for (addr = 1; addr <= endaddr; addr++) { |
Ben Warren | b1c0eaa | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 96 | cs8900_e2prom_read(dev, addr, &data); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 97 | 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 { |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 102 | puts("no valid config found"); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 103 | } |
wdenk | a2663ea | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 104 | puts("\n"); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | #endif |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 110 | |
| 111 | return (do_mplcommon(cmdtp, flag, argc, argv)); |
| 112 | } |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 113 | |
| 114 | U_BOOT_CMD( |
| 115 | vcma9, 6, 1, do_vcma9, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 116 | "VCMA9 specific commands", |
David Müller (ELSOFT AG) | f310830 | 2011-05-01 21:52:51 +0000 | [diff] [blame] | 117 | "flash mem [SrcAddr] - updates U-Boot with image in memory\n" |
| 118 | "vcma9 info - displays board information" |
wdenk | 531716e | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 119 | ); |