stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 1 | /* |
| 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 Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 26 | #include <dm9000.h> |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 27 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 28 | static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
Remy Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 29 | unsigned int i; |
| 30 | u8 data[2]; |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 31 | |
| 32 | for (i=0; i < 0x40; i++) { |
| 33 | if (!(i % 0x10)) |
Remy Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 34 | printf("\n%08x:", i); |
| 35 | dm9000_read_srom_word(i, data); |
| 36 | printf(" %02x%02x", data[1], data[0]); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 37 | } |
| 38 | printf ("\n"); |
| 39 | return (0); |
| 40 | } |
| 41 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 42 | static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 43 | int offset,value; |
| 44 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 45 | if (argc < 4) |
| 46 | return cmd_usage(cmdtp); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 47 | |
| 48 | offset=simple_strtoul(argv[2],NULL,16); |
| 49 | value=simple_strtoul(argv[3],NULL,16); |
| 50 | if (offset > 0x40) { |
| 51 | printf("Wrong offset : 0x%x\n",offset); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 52 | return cmd_usage(cmdtp); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 53 | } |
Remy Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 54 | dm9000_write_srom_word(offset, value); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 55 | return (0); |
| 56 | } |
| 57 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 58 | int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 59 | if (argc < 2) |
| 60 | return cmd_usage(cmdtp); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 61 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 62 | if (strcmp (argv[1],"read") == 0) |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 63 | return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv)); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 64 | else if (strcmp (argv[1],"write") == 0) |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 65 | return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv)); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 66 | else |
| 67 | return cmd_usage(cmdtp); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | U_BOOT_CMD( |
| 71 | dm9000ee,4,1,do_dm9000_eeprom, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 72 | "Read/Write eeprom connected to Ethernet Controller", |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 73 | "\ndm9000ee write <word offset> <value> \n" |
| 74 | "\tdm9000ee read \n" |
| 75 | "\tword:\t\t00-02 : MAC Address\n" |
| 76 | "\t\t\t03-07 : DM9000 Configuration\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 77 | "\t\t\t08-63 : User data" |
| 78 | ); |