1 // SPDX-License-Identifier: GPL-2.0+
4 * Robin Getz rgetz@blacfin.uclinux.org
6 * Heavily borrowed from the following peoples GPL'ed software:
7 * - Wolfgang Denk, DENX Software Engineering, wd@denx.de
9 * - Ladislav Michl ladis@linux-mips.org
10 * A rejected patch on the U-Boot mailing list
15 #include "../drivers/net/smc91111.h"
17 #ifndef SMC91111_EEPROM_INIT
18 # define SMC91111_EEPROM_INIT()
21 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
26 void dump_reg (struct eth_device *dev);
27 void dump_eeprom (struct eth_device *dev);
28 int write_eeprom_reg (struct eth_device *dev, int value, int reg);
29 void copy_from_eeprom (struct eth_device *dev);
30 void print_MAC (struct eth_device *dev);
31 int read_eeprom_reg (struct eth_device *dev, int reg);
32 void print_macaddr (struct eth_device *dev);
34 int smc91111_eeprom (int argc, char * const argv[])
36 int c, i, j, done, line, reg, value, start, what;
39 struct eth_device dev;
40 dev.iobase = CONFIG_SMC91111_BASE;
42 /* Print the ABI version */
44 if (XF_VERSION != (int) get_version ()) {
45 printf ("Expects ABI version %d\n", XF_VERSION);
46 printf ("Actual U-Boot ABI version %d\n",
47 (int) get_version ());
48 printf ("Can't run\n\n");
52 SMC91111_EEPROM_INIT();
54 if ((SMC_inw (&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
55 printf ("Can't find SMSC91111\n");
63 /* print the prompt */
64 printf ("SMC91111> ");
69 /* Wait for a keystroke */
76 /* printf(" |%02x| ",c); */
79 case '\r': /* Enter */
88 case 0x03: /* ^C - break */
96 case 0x08: /* ^H - backspace */
97 case 0x7F: /* DEL - backspace */
105 if ((c == 'W') || (c == 'D')
106 || (c == 'M') || (c == 'C')
115 if ((c >= '0' && c <= '9')
116 || (c >= 'A' && c <= 'F')
117 || (c == 'E') || (c == 'M')
135 /* Line should be w reg value */
139 /* Skip to the next space or end) */
140 while ((input[i] != ' ') && (input[i] != 0))
146 /* Are we writing to EEPROM or MAC */
159 /* skip to the next space or end */
160 while ((input[i] != ' ') && (input[i] != 0))
165 /* Find register to write into */
167 while ((input[i] != ' ') && (input[i] != 0)) {
172 reg = (reg * 0x10) + j;
176 while ((input[i] != ' ') && (input[i] != 0))
184 /* Get the value to write */
186 while ((input[i] != ' ') && (input[i] != 0)) {
191 value = (value * 0x10) + j;
197 printf ("Writing EEPROM register %02x with %04x\n", reg, value);
198 write_eeprom_reg (&dev, value, reg);
201 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg >> 4, reg & 0xE, value);
202 SMC_SELECT_BANK (&dev, reg >> 4);
203 SMC_outw (&dev, value, reg & 0xE);
217 copy_from_eeprom (&dev);
220 print_macaddr (&dev);
231 void copy_from_eeprom (struct eth_device *dev)
235 SMC_SELECT_BANK (dev, 1);
236 SMC_outw (dev, (SMC_inw (dev, CTL_REG) & !CTL_EEPROM_SELECT) |
237 CTL_RELOAD, CTL_REG);
239 while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --i)
242 printf ("Timeout Refreshing EEPROM registers\n");
244 printf ("EEPROM contents copied to MAC\n");
249 void print_macaddr (struct eth_device *dev)
253 printf ("Current MAC Address in SMSC91111 ");
254 SMC_SELECT_BANK (dev, 1);
255 for (i = 0; i < 5; i++) {
256 printf ("%02x:", SMC_inb (dev, ADDR0_REG + i));
259 printf ("%02x\n", SMC_inb (dev, ADDR0_REG + 5));
262 for (j = 0x20; j < 0x23; j++) {
263 k = read_eeprom_reg (dev, j);
270 printf ("Current MAC Address in EEPROM ");
271 for (i = 0; i < 5; i++)
272 printf ("%02x:", mac[i]);
273 printf ("%02x\n", mac[5]);
276 void dump_eeprom (struct eth_device *dev)
281 for (j = 0; j < 8; j++) {
286 for (k = 0; k < 4; k++) {
291 if ((k == 2) || (k == 3))
293 for (j = 0; j < 0x20; j += 4) {
294 printf ("%02x:%04x ", j + k,
295 read_eeprom_reg (dev, j + k));
300 for (j = 0x20; j < 0x40; j++) {
303 printf ("%02x:%04x ", j, read_eeprom_reg (dev, j));
309 int read_eeprom_reg (struct eth_device *dev, int reg)
313 SMC_SELECT_BANK (dev, 2);
314 SMC_outw (dev, reg, PTR_REG);
316 SMC_SELECT_BANK (dev, 1);
317 SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
318 CTL_RELOAD, CTL_REG);
320 while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --timeout)
323 printf ("Timeout Reading EEPROM register %02x\n", reg);
327 return SMC_inw (dev, GP_REG);
331 int write_eeprom_reg (struct eth_device *dev, int value, int reg)
335 SMC_SELECT_BANK (dev, 2);
336 SMC_outw (dev, reg, PTR_REG);
338 SMC_SELECT_BANK (dev, 1);
339 SMC_outw (dev, value, GP_REG);
340 SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
343 while ((SMC_inw (dev, CTL_REG) & CTL_STORE) && --timeout)
346 printf ("Timeout Writing EEPROM register %02x\n", reg);
354 void dump_reg (struct eth_device *dev)
359 for (j = 0; j < 4; j++) {
360 printf ("Bank%i ", j);
363 for (i = 0; i < 0xF; i += 2) {
365 for (j = 0; j < 4; j++) {
366 SMC_SELECT_BANK (dev, j);
367 printf ("%04x ", SMC_inw (dev, i));