3 * Ladislav Michl, 2N Telekomunikace, michl@2n.cz
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * Some code shamelessly stolen back from Robin Getz.
29 #include <timestamp.h>
30 #include "../drivers/net/smc91111.h"
32 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
34 static u16 read_eeprom_reg(u16 reg)
39 SMC_outw(reg, PTR_REG);
42 SMC_outw(SMC_inw (CTL_REG) | CTL_EEPROM_SELECT | CTL_RELOAD,
45 while((SMC_inw (CTL_REG) & CTL_RELOAD) && --timeout)
48 printf("Timeout Reading EEPROM register %02x\n", reg);
52 return SMC_inw (GP_REG);
55 static int write_eeprom_reg(u16 value, u16 reg)
60 SMC_outw(reg, PTR_REG);
63 SMC_outw(value, GP_REG);
64 SMC_outw(SMC_inw (CTL_REG) | CTL_EEPROM_SELECT | CTL_STORE, CTL_REG);
66 while ((SMC_inw(CTL_REG) & CTL_STORE) && --timeout)
69 printf("Timeout Writing EEPROM register %02x\n", reg);
76 static int write_data(u16 *buf, int len)
81 write_eeprom_reg(*buf++, reg++);
86 static int verify_macaddr(char *s)
91 printf("MAC Address: ");
93 for (i = 0; i < 3; i++) {
94 reg = read_eeprom_reg(0x20 + i);
95 printf("%02x:%02x%c", reg & 0xff, reg >> 8, i != 2 ? ':' : '\n');
97 err |= reg != ((u16 *)s)[i];
103 static int set_mac(char *s)
108 /* turn string into mac value */
109 for (i = 0; i < 6; i++) {
110 eaddr[i] = simple_strtoul(s, &e, 16);
114 for (i = 0; i < 3; i++)
115 write_eeprom_reg(*(((u16 *)eaddr) + i), 0x20 + i);
120 static int parse_element(char *s, unsigned char *buf, int len)
126 id = simple_strtoul(s, &p, 16);
138 buf[cnt++] = simple_strtoul(num, NULL, 16);
146 int eeprom(int argc, char *argv[])
149 unsigned char buf[58], *p;
152 if (get_version() != XF_VERSION) {
153 printf("Wrong XF_VERSION.\n");
154 printf("Application expects ABI version %d\n", XF_VERSION);
155 printf("Actual U-Boot ABI version %d\n", (int)get_version());
159 if ((SMC_inw (BANK_SELECT) & 0xFF00) != 0x3300) {
160 printf("SMSC91111 not found.\n");
164 /* Called without parameters - print MAC address */
166 verify_macaddr(NULL);
170 /* Print help message */
171 if (argv[1][1] == 'h') {
172 printf("VoiceBlue EEPROM writer\n");
173 printf("Built: %s at %s\n", U_BOOT_DATE, U_BOOT_TIME);
174 printf("Usage:\n\t<mac_address> [<element_1>] [<...>]\n");
178 /* Try to parse information elements */
181 for (i = 2; i < argc; i++) {
182 ret = parse_element(argv[i], p, len);
185 printf("Element %d: malformed\n", i - 1);
188 printf("Element %d: odd character count\n", i - 1);
191 printf("Out of EEPROM memory\n");
199 /* First argument (MAC) is mandatory */
201 if (verify_macaddr(argv[1])) {
202 printf("*** MAC address does not match! ***\n");
209 write_data((u16 *)buf, sizeof(buf) >> 1);