]>
git.ipfire.org Git - people/ms/u-boot.git/blob - examples/standalone/smc91111_eeprom.c
3 * Robin Getz rgetz@blacfin.uclinux.org
5 * SPDX-License-Identifier: GPL-2.0+
7 * Heavily borrowed from the following peoples GPL'ed software:
8 * - Wolfgang Denk, DENX Software Engineering, wd@denx.de
10 * - Ladislav Michl ladis@linux-mips.org
11 * A rejected patch on the U-Boot mailing list
16 #include "../drivers/net/smc91111.h"
18 #ifndef SMC91111_EEPROM_INIT
19 # define SMC91111_EEPROM_INIT()
22 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
27 void dump_reg (struct eth_device
*dev
);
28 void dump_eeprom (struct eth_device
*dev
);
29 int write_eeprom_reg (struct eth_device
*dev
, int value
, int reg
);
30 void copy_from_eeprom (struct eth_device
*dev
);
31 void print_MAC (struct eth_device
*dev
);
32 int read_eeprom_reg (struct eth_device
*dev
, int reg
);
33 void print_macaddr (struct eth_device
*dev
);
35 int smc91111_eeprom (int argc
, char * const argv
[])
37 int c
, i
, j
, done
, line
, reg
, value
, start
, what
;
40 struct eth_device dev
;
41 dev
.iobase
= CONFIG_SMC91111_BASE
;
43 /* Print the ABI version */
45 if (XF_VERSION
!= (int) get_version ()) {
46 printf ("Expects ABI version %d\n", XF_VERSION
);
47 printf ("Actual U-Boot ABI version %d\n",
48 (int) get_version ());
49 printf ("Can't run\n\n");
53 SMC91111_EEPROM_INIT();
55 if ((SMC_inw (&dev
, BANK_SELECT
) & 0xFF00) != 0x3300) {
56 printf ("Can't find SMSC91111\n");
64 /* print the prompt */
65 printf ("SMC91111> ");
70 /* Wait for a keystroke */
77 /* printf(" |%02x| ",c); */
80 case '\r': /* Enter */
89 case 0x03: /* ^C - break */
97 case 0x08: /* ^H - backspace */
98 case 0x7F: /* DEL - backspace */
106 if ((c
== 'W') || (c
== 'D')
107 || (c
== 'M') || (c
== 'C')
116 if ((c
>= '0' && c
<= '9')
117 || (c
>= 'A' && c
<= 'F')
118 || (c
== 'E') || (c
== 'M')
136 /* Line should be w reg value */
140 /* Skip to the next space or end) */
141 while ((input
[i
] != ' ') && (input
[i
] != 0))
147 /* Are we writing to EEPROM or MAC */
160 /* skip to the next space or end */
161 while ((input
[i
] != ' ') && (input
[i
] != 0))
166 /* Find register to write into */
168 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
173 reg
= (reg
* 0x10) + j
;
177 while ((input
[i
] != ' ') && (input
[i
] != 0))
185 /* Get the value to write */
187 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
192 value
= (value
* 0x10) + j
;
198 printf ("Writing EEPROM register %02x with %04x\n", reg
, value
);
199 write_eeprom_reg (&dev
, value
, reg
);
202 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg
>> 4, reg
& 0xE, value
);
203 SMC_SELECT_BANK (&dev
, reg
>> 4);
204 SMC_outw (&dev
, value
, reg
& 0xE);
218 copy_from_eeprom (&dev
);
221 print_macaddr (&dev
);
232 void copy_from_eeprom (struct eth_device
*dev
)
236 SMC_SELECT_BANK (dev
, 1);
237 SMC_outw (dev
, (SMC_inw (dev
, CTL_REG
) & !CTL_EEPROM_SELECT
) |
238 CTL_RELOAD
, CTL_REG
);
240 while ((SMC_inw (dev
, CTL_REG
) & CTL_RELOAD
) && --i
)
243 printf ("Timeout Refreshing EEPROM registers\n");
245 printf ("EEPROM contents copied to MAC\n");
250 void print_macaddr (struct eth_device
*dev
)
254 printf ("Current MAC Address in SMSC91111 ");
255 SMC_SELECT_BANK (dev
, 1);
256 for (i
= 0; i
< 5; i
++) {
257 printf ("%02x:", SMC_inb (dev
, ADDR0_REG
+ i
));
260 printf ("%02x\n", SMC_inb (dev
, ADDR0_REG
+ 5));
263 for (j
= 0x20; j
< 0x23; j
++) {
264 k
= read_eeprom_reg (dev
, j
);
271 printf ("Current MAC Address in EEPROM ");
272 for (i
= 0; i
< 5; i
++)
273 printf ("%02x:", mac
[i
]);
274 printf ("%02x\n", mac
[5]);
277 void dump_eeprom (struct eth_device
*dev
)
282 for (j
= 0; j
< 8; j
++) {
287 for (k
= 0; k
< 4; k
++) {
292 if ((k
== 2) || (k
== 3))
294 for (j
= 0; j
< 0x20; j
+= 4) {
295 printf ("%02x:%04x ", j
+ k
,
296 read_eeprom_reg (dev
, j
+ k
));
301 for (j
= 0x20; j
< 0x40; j
++) {
304 printf ("%02x:%04x ", j
, read_eeprom_reg (dev
, j
));
310 int read_eeprom_reg (struct eth_device
*dev
, int reg
)
314 SMC_SELECT_BANK (dev
, 2);
315 SMC_outw (dev
, reg
, PTR_REG
);
317 SMC_SELECT_BANK (dev
, 1);
318 SMC_outw (dev
, SMC_inw (dev
, CTL_REG
) | CTL_EEPROM_SELECT
|
319 CTL_RELOAD
, CTL_REG
);
321 while ((SMC_inw (dev
, CTL_REG
) & CTL_RELOAD
) && --timeout
)
324 printf ("Timeout Reading EEPROM register %02x\n", reg
);
328 return SMC_inw (dev
, GP_REG
);
332 int write_eeprom_reg (struct eth_device
*dev
, int value
, int reg
)
336 SMC_SELECT_BANK (dev
, 2);
337 SMC_outw (dev
, reg
, PTR_REG
);
339 SMC_SELECT_BANK (dev
, 1);
340 SMC_outw (dev
, value
, GP_REG
);
341 SMC_outw (dev
, SMC_inw (dev
, CTL_REG
) | CTL_EEPROM_SELECT
|
344 while ((SMC_inw (dev
, CTL_REG
) & CTL_STORE
) && --timeout
)
347 printf ("Timeout Writing EEPROM register %02x\n", reg
);
355 void dump_reg (struct eth_device
*dev
)
360 for (j
= 0; j
< 4; j
++) {
361 printf ("Bank%i ", j
);
364 for (i
= 0; i
< 0xF; i
+= 2) {
366 for (j
= 0; j
< 4; j
++) {
367 SMC_SELECT_BANK (dev
, j
);
368 printf ("%04x ", SMC_inw (dev
, i
));