3 * Robin Getz rgetz@blacfin.uclinux.org
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * Heavily borrowed from the following peoples GPL'ed software:
24 * - Wolfgang Denk, DENX Software Engineering, wd@denx.de
26 * - Ladislav Michl ladis@linux-mips.org
27 * A rejected patch on the U-Boot mailing list
32 /* the smc91111.h gets base addr through eth_device' iobase */
33 struct eth_device { unsigned long iobase; };
34 #include "../drivers/net/smc91111.h"
36 #ifndef SMC91111_EEPROM_INIT
37 # define SMC91111_EEPROM_INIT()
40 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
45 void dump_reg (struct eth_device *dev);
46 void dump_eeprom (struct eth_device *dev);
47 int write_eeprom_reg (struct eth_device *dev, int value, int reg);
48 void copy_from_eeprom (struct eth_device *dev);
49 void print_MAC (struct eth_device *dev);
50 int read_eeprom_reg (struct eth_device *dev, int reg);
51 void print_macaddr (struct eth_device *dev);
53 int smc91111_eeprom (int argc, char *argv[])
55 int c, i, j, done, line, reg, value, start, what;
58 struct eth_device dev = {
59 .iobase = CONFIG_SMC91111_BASE
62 /* Print the ABI version */
64 if (XF_VERSION != (int) get_version ()) {
65 printf ("Expects ABI version %d\n", XF_VERSION);
66 printf ("Actual U-Boot ABI version %d\n",
67 (int) get_version ());
68 printf ("Can't run\n\n");
72 SMC91111_EEPROM_INIT();
74 if ((SMC_inw (&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
75 printf ("Can't find SMSC91111\n");
83 /* print the prompt */
84 printf ("SMC91111> ");
89 /* Wait for a keystroke */
96 /* printf(" |%02x| ",c); */
99 case '\r': /* Enter */
108 case 0x03: /* ^C - break */
116 case 0x08: /* ^H - backspace */
117 case 0x7F: /* DEL - backspace */
125 if ((c == 'W') || (c == 'D')
126 || (c == 'M') || (c == 'C')
135 if ((c >= '0' && c <= '9')
136 || (c >= 'A' && c <= 'F')
137 || (c == 'E') || (c == 'M')
155 /* Line should be w reg value */
159 /* Skip to the next space or end) */
160 while ((input[i] != ' ') && (input[i] != 0))
166 /* Are we writing to EEPROM or MAC */
179 /* skip to the next space or end */
180 while ((input[i] != ' ') && (input[i] != 0))
185 /* Find register to write into */
187 while ((input[i] != ' ') && (input[i] != 0)) {
192 reg = (reg * 0x10) + j;
196 while ((input[i] != ' ') && (input[i] != 0))
204 /* Get the value to write */
206 while ((input[i] != ' ') && (input[i] != 0)) {
211 value = (value * 0x10) + j;
217 printf ("Writing EEPROM register %02x with %04x\n", reg, value);
218 write_eeprom_reg (&dev, value, reg);
221 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg >> 4, reg & 0xE, value);
222 SMC_SELECT_BANK (&dev, reg >> 4);
223 SMC_outw (&dev, value, reg & 0xE);
237 copy_from_eeprom (&dev);
240 print_macaddr (&dev);
251 void copy_from_eeprom (struct eth_device *dev)
255 SMC_SELECT_BANK (dev, 1);
256 SMC_outw (dev, (SMC_inw (dev, CTL_REG) & !CTL_EEPROM_SELECT) |
257 CTL_RELOAD, CTL_REG);
259 while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --i)
262 printf ("Timeout Refreshing EEPROM registers\n");
264 printf ("EEPROM contents copied to MAC\n");
269 void print_macaddr (struct eth_device *dev)
273 printf ("Current MAC Address in SMSC91111 ");
274 SMC_SELECT_BANK (dev, 1);
275 for (i = 0; i < 5; i++) {
276 printf ("%02x:", SMC_inb (dev, ADDR0_REG + i));
279 printf ("%02x\n", SMC_inb (dev, ADDR0_REG + 5));
282 for (j = 0x20; j < 0x23; j++) {
283 k = read_eeprom_reg (dev, j);
290 printf ("Current MAC Address in EEPROM ");
291 for (i = 0; i < 5; i++)
292 printf ("%02x:", mac[i]);
293 printf ("%02x\n", mac[5]);
296 void dump_eeprom (struct eth_device *dev)
301 for (j = 0; j < 8; j++) {
306 for (k = 0; k < 4; k++) {
311 if ((k == 2) || (k == 3))
313 for (j = 0; j < 0x20; j += 4) {
314 printf ("%02x:%04x ", j + k,
315 read_eeprom_reg (dev, j + k));
320 for (j = 0x20; j < 0x40; j++) {
323 printf ("%02x:%04x ", j, read_eeprom_reg (dev, j));
329 int read_eeprom_reg (struct eth_device *dev, int reg)
333 SMC_SELECT_BANK (dev, 2);
334 SMC_outw (dev, reg, PTR_REG);
336 SMC_SELECT_BANK (dev, 1);
337 SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
338 CTL_RELOAD, CTL_REG);
340 while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --timeout)
343 printf ("Timeout Reading EEPROM register %02x\n", reg);
347 return SMC_inw (dev, GP_REG);
351 int write_eeprom_reg (struct eth_device *dev, int value, int reg)
355 SMC_SELECT_BANK (dev, 2);
356 SMC_outw (dev, reg, PTR_REG);
358 SMC_SELECT_BANK (dev, 1);
359 SMC_outw (dev, value, GP_REG);
360 SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
363 while ((SMC_inw (dev, CTL_REG) & CTL_STORE) && --timeout)
366 printf ("Timeout Writing EEPROM register %02x\n", reg);
374 void dump_reg (struct eth_device *dev)
379 for (j = 0; j < 4; j++) {
380 printf ("Bank%i ", j);
383 for (i = 0; i < 0xF; i += 2) {
385 for (j = 0; j < 4; j++) {
386 SMC_SELECT_BANK (dev, j);
387 printf ("%04x ", SMC_inw (dev, i));