]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/netstar/eeprom.c
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.
27 #include <timestamp.h>
29 #include "../drivers/net/smc91111.h"
31 static struct eth_device dev
= {
32 .iobase
= CONFIG_SMC91111_BASE
35 static u16
read_eeprom_reg(u16 reg
)
39 SMC_SELECT_BANK(&dev
, 2);
40 SMC_outw(&dev
, reg
, PTR_REG
);
42 SMC_SELECT_BANK(&dev
, 1);
43 SMC_outw(&dev
, SMC_inw(&dev
, CTL_REG
) | CTL_EEPROM_SELECT
|
48 while ((SMC_inw(&dev
, CTL_REG
) & CTL_RELOAD
) && --timeout
)
51 printf("Timeout reading register %02x\n", reg
);
55 return SMC_inw(&dev
, GP_REG
);
58 static int write_eeprom_reg(u16 value
, u16 reg
)
62 SMC_SELECT_BANK(&dev
, 2);
63 SMC_outw(&dev
, reg
, PTR_REG
);
65 SMC_SELECT_BANK(&dev
, 1);
67 SMC_outw(&dev
, value
, GP_REG
);
68 SMC_outw(&dev
, SMC_inw(&dev
, CTL_REG
) | CTL_EEPROM_SELECT
|
73 while ((SMC_inw(&dev
, CTL_REG
) & CTL_STORE
) && --timeout
)
76 printf("Timeout writing register %02x\n", reg
);
83 static int write_data(u16
*buf
, int len
)
88 write_eeprom_reg(*buf
++, reg
++);
93 static int verify_macaddr(char *s
)
99 for (i
= 0; i
< 3; i
++) {
100 reg
= read_eeprom_reg(0x20 + i
);
101 printf("%02x:%02x%c", reg
& 0xff, reg
>> 8, i
!= 2 ? ':' : '\n');
103 err
|= reg
!= ((u16
*)s
)[i
];
109 static int set_mac(char *s
)
114 /* turn string into mac value */
115 for (i
= 0; i
< 6; i
++) {
116 eaddr
[i
] = simple_strtoul(s
, &e
, 16);
120 for (i
= 0; i
< 3; i
++)
121 write_eeprom_reg(*(((u16
*)eaddr
) + i
), 0x20 + i
);
126 static int parse_element(char *s
, unsigned char *buf
, int len
)
132 id
= simple_strtoul(s
, &p
, 16);
144 buf
[cnt
++] = simple_strtoul(num
, NULL
, 16);
152 int eeprom(int argc
, char * const argv
[])
155 unsigned char buf
[58], *p
;
159 if (i
!= XF_VERSION
) {
160 printf("Using ABI version %d, but U-Boot provides %d\n",
165 if ((SMC_inw(&dev
, BANK_SELECT
) & 0xFF00) != 0x3300) {
166 puts("SMSC91111 not found\n");
170 /* Called without parameters - print MAC address */
172 verify_macaddr(NULL
);
176 /* Print help message */
177 if (argv
[1][1] == 'h') {
178 puts("NetStar EEPROM writer\n"
179 "Built: " U_BOOT_DATE
" at " U_BOOT_TIME
"\n"
180 "Usage:\n\t<mac_address> [<element_1>] [<...>]\n");
184 /* Try to parse information elements */
187 for (i
= 2; i
< argc
; i
++) {
188 ret
= parse_element(argv
[i
], p
, len
);
191 printf("Element %d: malformed\n", i
- 1);
194 printf("Element %d: odd character count\n", i
- 1);
197 puts("Out of EEPROM memory\n");
205 /* First argument (MAC) is mandatory */
207 if (verify_macaddr(argv
[1])) {
208 puts("*** HWaddr does not match! ***\n");
215 write_data((u16
*)buf
, sizeof(buf
) >> 1);