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 "../drivers/smc91111.h"
31 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
33 static int verify_macaddr(char *);
34 static int set_mac(char *);
36 int eeprom(int argc, char *argv[])
39 if (get_version() != XF_VERSION) {
40 printf("Wrong XF_VERSION.\n");
41 printf("Application expects ABI version %d\n", XF_VERSION);
42 printf("Actual U-Boot ABI version %d\n", (int)get_version());
46 if ((SMC_inw (BANK_SELECT) & 0xFF00) != 0x3300) {
47 printf("SMSC91111 not found.\n");
52 printf("VoiceBlue EEPROM writer\n");
53 printf("Built: %s at %s\n", __DATE__ , __TIME__ );
54 printf("Usage:\n\t<mac_address>");
59 if (verify_macaddr(argv[1])) {
60 printf("*** ERROR ***\n");
67 static u16 read_eeprom_reg(u16 reg)
72 SMC_outw(reg, PTR_REG);
75 SMC_outw(SMC_inw (CTL_REG) | CTL_EEPROM_SELECT | CTL_RELOAD,
78 while((SMC_inw (CTL_REG) & CTL_RELOAD) && --timeout)
81 printf("Timeout Reading EEPROM register %02x\n", reg);
85 return SMC_inw (GP_REG);
88 static int write_eeprom_reg(u16 value, u16 reg)
93 SMC_outw(reg, PTR_REG);
96 SMC_outw(value, GP_REG);
97 SMC_outw(SMC_inw (CTL_REG) | CTL_EEPROM_SELECT | CTL_STORE, CTL_REG);
99 while ((SMC_inw(CTL_REG) & CTL_STORE) && --timeout)
102 printf("Timeout Writing EEPROM register %02x\n", reg);
109 static int verify_macaddr(char *s)
114 printf("Verifying MAC Address: ");
116 for (i = 0; i < 3; i++) {
117 reg = read_eeprom_reg(0x20 + i);
118 printf("%02x:%02x%c", reg & 0xff, reg >> 8, i != 2 ? ':' : '\n');
119 err |= reg != ((u16 *)s)[i];
125 static int set_mac(char *s)
130 /* turn string into mac value */
131 for (i = 0; i < 6; i++) {
132 eaddr[i] = simple_strtoul(s, &e, 16);
136 for (i = 0; i < 3; i++)
137 write_eeprom_reg(*(((u16 *)eaddr) + i), 0x20 + i);