stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefano Babic, DENX Software Engineering, sbabic@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Remy Bohmer | e5a3bc2 | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 10 | #include <dm9000.h> |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 11 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 12 | static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
Remy Bohmer | e5a3bc2 | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 13 | unsigned int i; |
| 14 | u8 data[2]; |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 15 | |
| 16 | for (i=0; i < 0x40; i++) { |
| 17 | if (!(i % 0x10)) |
Remy Bohmer | e5a3bc2 | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 18 | printf("\n%08x:", i); |
| 19 | dm9000_read_srom_word(i, data); |
| 20 | printf(" %02x%02x", data[1], data[0]); |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 21 | } |
| 22 | printf ("\n"); |
| 23 | return (0); |
| 24 | } |
| 25 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 26 | static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 27 | int offset,value; |
| 28 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 29 | if (argc < 4) |
| 30 | return cmd_usage(cmdtp); |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 31 | |
| 32 | offset=simple_strtoul(argv[2],NULL,16); |
| 33 | value=simple_strtoul(argv[3],NULL,16); |
| 34 | if (offset > 0x40) { |
| 35 | printf("Wrong offset : 0x%x\n",offset); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 36 | return cmd_usage(cmdtp); |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 37 | } |
Remy Bohmer | e5a3bc2 | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 38 | dm9000_write_srom_word(offset, value); |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 39 | return (0); |
| 40 | } |
| 41 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 42 | int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 43 | if (argc < 2) |
| 44 | return cmd_usage(cmdtp); |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 45 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 46 | if (strcmp (argv[1],"read") == 0) |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 47 | return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv)); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 48 | else if (strcmp (argv[1],"write") == 0) |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 49 | return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv)); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 50 | else |
| 51 | return cmd_usage(cmdtp); |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | U_BOOT_CMD( |
| 55 | dm9000ee,4,1,do_dm9000_eeprom, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 56 | "Read/Write eeprom connected to Ethernet Controller", |
stefano babic | 5e5803e | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 57 | "\ndm9000ee write <word offset> <value> \n" |
| 58 | "\tdm9000ee read \n" |
| 59 | "\tword:\t\t00-02 : MAC Address\n" |
| 60 | "\t\t\t03-07 : DM9000 Configuration\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 61 | "\t\t\t08-63 : User data" |
| 62 | ); |