blob: fede2e077472b6d6c0fd41eccb26f58e956f0be3 [file] [log] [blame]
stefano babic5e5803e2007-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>
Remy Bohmere5a3bc22009-05-03 12:11:40 +020026#include <dm9000.h>
stefano babic5e5803e2007-08-30 23:01:49 +020027
Wolfgang Denk54841ab2010-06-28 22:00:46 +020028static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
Remy Bohmere5a3bc22009-05-03 12:11:40 +020029 unsigned int i;
30 u8 data[2];
stefano babic5e5803e2007-08-30 23:01:49 +020031
32 for (i=0; i < 0x40; i++) {
33 if (!(i % 0x10))
Remy Bohmere5a3bc22009-05-03 12:11:40 +020034 printf("\n%08x:", i);
35 dm9000_read_srom_word(i, data);
36 printf(" %02x%02x", data[1], data[0]);
stefano babic5e5803e2007-08-30 23:01:49 +020037 }
38 printf ("\n");
39 return (0);
40}
41
Wolfgang Denk54841ab2010-06-28 22:00:46 +020042static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
stefano babic5e5803e2007-08-30 23:01:49 +020043 int offset,value;
44
45 if (argc < 4) {
Peter Tyser62c3ae72009-01-27 18:03:10 -060046 cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020047 return 1;
48 }
49
50 offset=simple_strtoul(argv[2],NULL,16);
51 value=simple_strtoul(argv[3],NULL,16);
52 if (offset > 0x40) {
53 printf("Wrong offset : 0x%x\n",offset);
Peter Tyser62c3ae72009-01-27 18:03:10 -060054 cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020055 return 1;
56 }
Remy Bohmere5a3bc22009-05-03 12:11:40 +020057 dm9000_write_srom_word(offset, value);
stefano babic5e5803e2007-08-30 23:01:49 +020058 return (0);
59}
60
Wolfgang Denk54841ab2010-06-28 22:00:46 +020061int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
stefano babic5e5803e2007-08-30 23:01:49 +020062 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -060063 cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020064 return 1;
65 }
66
67 if (strcmp (argv[1],"read") == 0) {
68 return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv));
69 } else if (strcmp (argv[1],"write") == 0) {
70 return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv));
71 } else {
Peter Tyser62c3ae72009-01-27 18:03:10 -060072 cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020073 return 1;
74 }
75}
76
77U_BOOT_CMD(
78 dm9000ee,4,1,do_dm9000_eeprom,
Peter Tyser2fb26042009-01-27 18:03:12 -060079 "Read/Write eeprom connected to Ethernet Controller",
stefano babic5e5803e2007-08-30 23:01:49 +020080 "\ndm9000ee write <word offset> <value> \n"
81 "\tdm9000ee read \n"
82 "\tword:\t\t00-02 : MAC Address\n"
83 "\t\t\t03-07 : DM9000 Configuration\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020084 "\t\t\t08-63 : User data"
85);