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 #include "../drivers/net/smc91111.h"
34 #ifndef SMC91111_EEPROM_INIT
35 # define SMC91111_EEPROM_INIT()
38 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
43 void dump_reg (struct eth_device *dev);
44 void dump_eeprom (struct eth_device *dev);
45 int write_eeprom_reg (struct eth_device *dev, int value, int reg);
46 void copy_from_eeprom (struct eth_device *dev);
47 void print_MAC (struct eth_device *dev);
48 int read_eeprom_reg (struct eth_device *dev, int reg);
49 void print_macaddr (struct eth_device *dev);
51 int smc91111_eeprom (int argc, char *argv[])
53 int c, i, j, done, line, reg, value, start, what;
56 struct eth_device dev = {
57 .iobase = CONFIG_SMC91111_BASE
60 /* Print the ABI version */
62 if (XF_VERSION != (int) get_version ()) {
63 printf ("Expects ABI version %d\n", XF_VERSION);
64 printf ("Actual U-Boot ABI version %d\n",
65 (int) get_version ());
66 printf ("Can't run\n\n");
70 SMC91111_EEPROM_INIT();
72 if ((SMC_inw (&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
73 printf ("Can't find SMSC91111\n");
81 /* print the prompt */
82 printf ("SMC91111> ");
87 /* Wait for a keystroke */
94 /* printf(" |%02x| ",c); */
97 case '\r': /* Enter */
106 case 0x03: /* ^C - break */
114 case 0x08: /* ^H - backspace */
115 case 0x7F: /* DEL - backspace */
123 if ((c == 'W') || (c == 'D')
124 || (c == 'M') || (c == 'C')
133 if ((c >= '0' && c <= '9')
134 || (c >= 'A' && c <= 'F')
135 || (c == 'E') || (c == 'M')
153 /* Line should be w reg value */
157 /* Skip to the next space or end) */
158 while ((input[i] != ' ') && (input[i] != 0))
164 /* Are we writing to EEPROM or MAC */
177 /* skip to the next space or end */
178 while ((input[i] != ' ') && (input[i] != 0))
183 /* Find register to write into */
185 while ((input[i] != ' ') && (input[i] != 0)) {
190 reg = (reg * 0x10) + j;
194 while ((input[i] != ' ') && (input[i] != 0))
202 /* Get the value to write */
204 while ((input[i] != ' ') && (input[i] != 0)) {
209 value = (value * 0x10) + j;
215 printf ("Writing EEPROM register %02x with %04x\n", reg, value);
216 write_eeprom_reg (&dev, value, reg);
219 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg >> 4, reg & 0xE, value);
220 SMC_SELECT_BANK (&dev, reg >> 4);
221 SMC_outw (&dev, value, reg & 0xE);
235 copy_from_eeprom (&dev);
238 print_macaddr (&dev);
249 void copy_from_eeprom (struct eth_device *dev)
253 SMC_SELECT_BANK (dev, 1);
254 SMC_outw (dev, (SMC_inw (dev, CTL_REG) & !CTL_EEPROM_SELECT) |
255 CTL_RELOAD, CTL_REG);
257 while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --i)
260 printf ("Timeout Refreshing EEPROM registers\n");
262 printf ("EEPROM contents copied to MAC\n");
267 void print_macaddr (struct eth_device *dev)
271 printf ("Current MAC Address in SMSC91111 ");
272 SMC_SELECT_BANK (dev, 1);
273 for (i = 0; i < 5; i++) {
274 printf ("%02x:", SMC_inb (dev, ADDR0_REG + i));
277 printf ("%02x\n", SMC_inb (dev, ADDR0_REG + 5));
280 for (j = 0x20; j < 0x23; j++) {
281 k = read_eeprom_reg (dev, j);
288 printf ("Current MAC Address in EEPROM ");
289 for (i = 0; i < 5; i++)
290 printf ("%02x:", mac[i]);
291 printf ("%02x\n", mac[5]);
294 void dump_eeprom (struct eth_device *dev)
299 for (j = 0; j < 8; j++) {
304 for (k = 0; k < 4; k++) {
309 if ((k == 2) || (k == 3))
311 for (j = 0; j < 0x20; j += 4) {
312 printf ("%02x:%04x ", j + k,
313 read_eeprom_reg (dev, j + k));
318 for (j = 0x20; j < 0x40; j++) {
321 printf ("%02x:%04x ", j, read_eeprom_reg (dev, j));
327 int read_eeprom_reg (struct eth_device *dev, int reg)
331 SMC_SELECT_BANK (dev, 2);
332 SMC_outw (dev, reg, PTR_REG);
334 SMC_SELECT_BANK (dev, 1);
335 SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
336 CTL_RELOAD, CTL_REG);
338 while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --timeout)
341 printf ("Timeout Reading EEPROM register %02x\n", reg);
345 return SMC_inw (dev, GP_REG);
349 int write_eeprom_reg (struct eth_device *dev, int value, int reg)
353 SMC_SELECT_BANK (dev, 2);
354 SMC_outw (dev, reg, PTR_REG);
356 SMC_SELECT_BANK (dev, 1);
357 SMC_outw (dev, value, GP_REG);
358 SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
361 while ((SMC_inw (dev, CTL_REG) & CTL_STORE) && --timeout)
364 printf ("Timeout Writing EEPROM register %02x\n", reg);
372 void dump_reg (struct eth_device *dev)
377 for (j = 0; j < 4; j++) {
378 printf ("Bank%i ", j);
381 for (i = 0; i < 0xF; i += 2) {
383 for (j = 0; j < 4; j++) {
384 SMC_SELECT_BANK (dev, j);
385 printf ("%04x ", SMC_inw (dev, i));