blob: 1318edc5d63ae77abe5f78d3d48206ed4b547495 [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 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
stefano babic5e5803e2007-08-30 23:01:49 +02006 */
7
8#include <common.h>
9#include <command.h>
Remy Bohmere5a3bc22009-05-03 12:11:40 +020010#include <dm9000.h>
stefano babic5e5803e2007-08-30 23:01:49 +020011
Wolfgang Denk54841ab2010-06-28 22:00:46 +020012static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
Remy Bohmere5a3bc22009-05-03 12:11:40 +020013 unsigned int i;
14 u8 data[2];
stefano babic5e5803e2007-08-30 23:01:49 +020015
16 for (i=0; i < 0x40; i++) {
17 if (!(i % 0x10))
Remy Bohmere5a3bc22009-05-03 12:11:40 +020018 printf("\n%08x:", i);
19 dm9000_read_srom_word(i, data);
20 printf(" %02x%02x", data[1], data[0]);
stefano babic5e5803e2007-08-30 23:01:49 +020021 }
22 printf ("\n");
23 return (0);
24}
25
Wolfgang Denk54841ab2010-06-28 22:00:46 +020026static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
stefano babic5e5803e2007-08-30 23:01:49 +020027 int offset,value;
28
Wolfgang Denk47e26b12010-07-17 01:06:04 +020029 if (argc < 4)
30 return cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020031
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 Denk47e26b12010-07-17 01:06:04 +020036 return cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020037 }
Remy Bohmere5a3bc22009-05-03 12:11:40 +020038 dm9000_write_srom_word(offset, value);
stefano babic5e5803e2007-08-30 23:01:49 +020039 return (0);
40}
41
Wolfgang Denk54841ab2010-06-28 22:00:46 +020042int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +020043 if (argc < 2)
44 return cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020045
Wolfgang Denk47e26b12010-07-17 01:06:04 +020046 if (strcmp (argv[1],"read") == 0)
stefano babic5e5803e2007-08-30 23:01:49 +020047 return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv));
Wolfgang Denk47e26b12010-07-17 01:06:04 +020048 else if (strcmp (argv[1],"write") == 0)
stefano babic5e5803e2007-08-30 23:01:49 +020049 return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv));
Wolfgang Denk47e26b12010-07-17 01:06:04 +020050 else
51 return cmd_usage(cmdtp);
stefano babic5e5803e2007-08-30 23:01:49 +020052}
53
54U_BOOT_CMD(
55 dm9000ee,4,1,do_dm9000_eeprom,
Peter Tyser2fb26042009-01-27 18:03:12 -060056 "Read/Write eeprom connected to Ethernet Controller",
stefano babic5e5803e2007-08-30 23:01:49 +020057 "\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 Denka89c33d2009-05-24 17:06:54 +020061 "\t\t\t08-63 : User data"
62);