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 #ifdef CONFIG_DRIVER_SMC91111
37 # define pFIO_DIR pFIO0_DIR
38 # define pFIO_FLAG_S pFIO0_FLAG_S
41 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
47 void dump_eeprom (void);
48 int write_eeprom_reg (int, int);
49 void copy_from_eeprom (void);
50 void print_MAC (void);
51 int read_eeprom_reg (int);
52 void print_macaddr (void);
54 int smc91111_eeprom (int argc
, char *argv
[])
56 int c
, i
, j
, done
, line
, reg
, value
, start
, what
;
59 /* Print the ABI version */
61 if (XF_VERSION
!= (int) get_version ()) {
62 printf ("Expects ABI version %d\n", XF_VERSION
);
63 printf ("Actual U-Boot ABI version %d\n",
64 (int) get_version ());
65 printf ("Can't run\n\n");
73 if ((SMC_inw (BANK_SELECT
) & 0xFF00) != 0x3300) {
74 printf ("Can't find SMSC91111\n");
82 /* print the prompt */
83 printf ("SMC91111> ");
88 /* Wait for a keystroke */
95 /* printf(" |%02x| ",c); */
98 case '\r': /* Enter */
107 case 0x03: /* ^C - break */
115 case 0x08: /* ^H - backspace */
116 case 0x7F: /* DEL - backspace */
124 if ((c
== 'W') || (c
== 'D')
125 || (c
== 'M') || (c
== 'C')
134 if ((c
>= '0' && c
<= '9')
135 || (c
>= 'A' && c
<= 'F')
136 || (c
== 'E') || (c
== 'M')
154 /* Line should be w reg value */
158 /* Skip to the next space or end) */
159 while ((input
[i
] != ' ') && (input
[i
] != 0))
165 /* Are we writing to EEPROM or MAC */
178 /* skip to the next space or end */
179 while ((input
[i
] != ' ') && (input
[i
] != 0))
184 /* Find register to write into */
186 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
191 reg
= (reg
* 0x10) + j
;
195 while ((input
[i
] != ' ') && (input
[i
] != 0))
203 /* Get the value to write */
205 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
210 value
= (value
* 0x10) + j
;
216 printf ("Writing EEPROM register %02x with %04x\n", reg
, value
);
217 write_eeprom_reg (value
, reg
);
220 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg
>> 4, reg
& 0xE, value
);
221 SMC_SELECT_BANK (reg
>> 4);
222 SMC_outw (value
, reg
& 0xE);
250 void copy_from_eeprom (void)
255 SMC_outw ((SMC_inw (CTL_REG
) & !CTL_EEPROM_SELECT
) | CTL_RELOAD
,
258 while ((SMC_inw (CTL_REG
) & CTL_RELOAD
) && --i
)
261 printf ("Timeout Refreshing EEPROM registers\n");
263 printf ("EEPROM contents copied to MAC\n");
268 void print_macaddr (void)
272 printf ("Current MAC Address in SMSC91111 ");
274 for (i
= 0; i
< 5; i
++) {
275 printf ("%02x:", SMC_inb (ADDR0_REG
+ i
));
278 printf ("%02x\n", SMC_inb (ADDR0_REG
+ 5));
281 for (j
= 0x20; j
< 0x23; j
++) {
282 k
= read_eeprom_reg (j
);
289 printf ("Current MAC Address in EEPROM ");
290 for (i
= 0; i
< 5; i
++)
291 printf ("%02x:", mac
[i
]);
292 printf ("%02x\n", mac
[5]);
295 void dump_eeprom (void)
300 for (j
= 0; j
< 8; j
++) {
305 for (k
= 0; k
< 4; k
++) {
310 if ((k
== 2) || (k
== 3))
312 for (j
= 0; j
< 0x20; j
+= 4) {
313 printf ("%02x:%04x ", j
+ k
, read_eeprom_reg (j
+ k
));
318 for (j
= 0x20; j
< 0x40; j
++) {
321 printf ("%02x:%04x ", j
, read_eeprom_reg (j
));
327 int read_eeprom_reg (int reg
)
332 SMC_outw (reg
, PTR_REG
);
335 SMC_outw (SMC_inw (CTL_REG
) | CTL_EEPROM_SELECT
| CTL_RELOAD
,
338 while ((SMC_inw (CTL_REG
) & CTL_RELOAD
) && --timeout
)
341 printf ("Timeout Reading EEPROM register %02x\n", reg
);
345 return SMC_inw (GP_REG
);
349 int write_eeprom_reg (int value
, int reg
)
354 SMC_outw (reg
, PTR_REG
);
357 SMC_outw (value
, GP_REG
);
358 SMC_outw (SMC_inw (CTL_REG
) | CTL_EEPROM_SELECT
| CTL_STORE
, CTL_REG
);
360 while ((SMC_inw (CTL_REG
) & CTL_STORE
) && --timeout
)
363 printf ("Timeout Writing EEPROM register %02x\n", reg
);
376 for (j
= 0; j
< 4; j
++) {
377 printf ("Bank%i ", j
);
380 for (i
= 0; i
< 0xF; i
+= 2) {
382 for (j
= 0; j
< 4; j
++) {
384 printf ("%04x ", SMC_inw (i
));
392 int smc91111_eeprom (int argc
, char *argv
[])
394 printf("Not supported for this board\n");