blob: 3d3bc00221bfbf458ce71df1e0da90a0043be6cb [file] [log] [blame]
stefano babic6708a602007-08-30 23:01:49 +02001/*
2 * (C) Copyright 2007
3 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26
27static unsigned char srom[128];
28extern u16 read_srom_word(int);
29extern void write_srom_word(int offset, u16 val);
30
31static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {
32 int i;
33
34 for (i=0; i < 0x40; i++) {
35 if (!(i % 0x10))
36 printf("\n%08lx:", i);
37 printf(" %04x", read_srom_word(i));
38 }
39 printf ("\n");
40 return (0);
41}
42
43static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {
44 int offset,value;
45
46 if (argc < 4) {
47 printf ("Usage:\n%s\n", cmdtp->usage);
48 return 1;
49 }
50
51 offset=simple_strtoul(argv[2],NULL,16);
52 value=simple_strtoul(argv[3],NULL,16);
53 if (offset > 0x40) {
54 printf("Wrong offset : 0x%x\n",offset);
55 printf ("Usage:\n%s\n", cmdtp->usage);
56 return 1;
57 }
58 write_srom_word(offset, value);
59 return (0);
60}
61
62int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {
63 if (argc < 2) {
64 printf ("Usage:\n%s\n", cmdtp->usage);
65 return 1;
66 }
67
68 if (strcmp (argv[1],"read") == 0) {
69 return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv));
70 } else if (strcmp (argv[1],"write") == 0) {
71 return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv));
72 } else {
73 printf ("Usage:\n%s\n", cmdtp->usage);
74 return 1;
75 }
76}
77
78U_BOOT_CMD(
79 dm9000ee,4,1,do_dm9000_eeprom,
80 "dm9000ee- Read/Write eeprom connected to Ethernet Controller\n",
81 "\ndm9000ee write <word offset> <value> \n"
82 "\tdm9000ee read \n"
83 "\tword:\t\t00-02 : MAC Address\n"
84 "\t\t\t03-07 : DM9000 Configuration\n"
85 "\t\t\t08-63 : User data\n");