]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - examples/standalone/smc91111_eeprom.c
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
36 #ifndef SMC91111_EEPROM_INIT
37 # define SMC91111_EEPROM_INIT()
40 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
46 void dump_eeprom (void);
47 int write_eeprom_reg (int, int);
48 void copy_from_eeprom (void);
49 void print_MAC (void);
50 int read_eeprom_reg (int);
51 void print_macaddr (void);
53 int smc91111_eeprom (int argc
, char *argv
[])
55 int c
, i
, j
, done
, line
, reg
, value
, start
, what
;
58 /* Print the ABI version */
60 if (XF_VERSION
!= (int) get_version ()) {
61 printf ("Expects ABI version %d\n", XF_VERSION
);
62 printf ("Actual U-Boot ABI version %d\n",
63 (int) get_version ());
64 printf ("Can't run\n\n");
68 SMC91111_EEPROM_INIT();
70 if ((SMC_inw (BANK_SELECT
) & 0xFF00) != 0x3300) {
71 printf ("Can't find SMSC91111\n");
79 /* print the prompt */
80 printf ("SMC91111> ");
85 /* Wait for a keystroke */
92 /* printf(" |%02x| ",c); */
95 case '\r': /* Enter */
104 case 0x03: /* ^C - break */
112 case 0x08: /* ^H - backspace */
113 case 0x7F: /* DEL - backspace */
121 if ((c
== 'W') || (c
== 'D')
122 || (c
== 'M') || (c
== 'C')
131 if ((c
>= '0' && c
<= '9')
132 || (c
>= 'A' && c
<= 'F')
133 || (c
== 'E') || (c
== 'M')
151 /* Line should be w reg value */
155 /* Skip to the next space or end) */
156 while ((input
[i
] != ' ') && (input
[i
] != 0))
162 /* Are we writing to EEPROM or MAC */
175 /* skip to the next space or end */
176 while ((input
[i
] != ' ') && (input
[i
] != 0))
181 /* Find register to write into */
183 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
188 reg
= (reg
* 0x10) + j
;
192 while ((input
[i
] != ' ') && (input
[i
] != 0))
200 /* Get the value to write */
202 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
207 value
= (value
* 0x10) + j
;
213 printf ("Writing EEPROM register %02x with %04x\n", reg
, value
);
214 write_eeprom_reg (value
, reg
);
217 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg
>> 4, reg
& 0xE, value
);
218 SMC_SELECT_BANK (reg
>> 4);
219 SMC_outw (value
, reg
& 0xE);
247 void copy_from_eeprom (void)
252 SMC_outw ((SMC_inw (CTL_REG
) & !CTL_EEPROM_SELECT
) | CTL_RELOAD
,
255 while ((SMC_inw (CTL_REG
) & CTL_RELOAD
) && --i
)
258 printf ("Timeout Refreshing EEPROM registers\n");
260 printf ("EEPROM contents copied to MAC\n");
265 void print_macaddr (void)
269 printf ("Current MAC Address in SMSC91111 ");
271 for (i
= 0; i
< 5; i
++) {
272 printf ("%02x:", SMC_inb (ADDR0_REG
+ i
));
275 printf ("%02x\n", SMC_inb (ADDR0_REG
+ 5));
278 for (j
= 0x20; j
< 0x23; j
++) {
279 k
= read_eeprom_reg (j
);
286 printf ("Current MAC Address in EEPROM ");
287 for (i
= 0; i
< 5; i
++)
288 printf ("%02x:", mac
[i
]);
289 printf ("%02x\n", mac
[5]);
292 void dump_eeprom (void)
297 for (j
= 0; j
< 8; j
++) {
302 for (k
= 0; k
< 4; k
++) {
307 if ((k
== 2) || (k
== 3))
309 for (j
= 0; j
< 0x20; j
+= 4) {
310 printf ("%02x:%04x ", j
+ k
, read_eeprom_reg (j
+ k
));
315 for (j
= 0x20; j
< 0x40; j
++) {
318 printf ("%02x:%04x ", j
, read_eeprom_reg (j
));
324 int read_eeprom_reg (int reg
)
329 SMC_outw (reg
, PTR_REG
);
332 SMC_outw (SMC_inw (CTL_REG
) | CTL_EEPROM_SELECT
| CTL_RELOAD
,
335 while ((SMC_inw (CTL_REG
) & CTL_RELOAD
) && --timeout
)
338 printf ("Timeout Reading EEPROM register %02x\n", reg
);
342 return SMC_inw (GP_REG
);
346 int write_eeprom_reg (int value
, int reg
)
351 SMC_outw (reg
, PTR_REG
);
354 SMC_outw (value
, GP_REG
);
355 SMC_outw (SMC_inw (CTL_REG
) | CTL_EEPROM_SELECT
| CTL_STORE
, CTL_REG
);
357 while ((SMC_inw (CTL_REG
) & CTL_STORE
) && --timeout
)
360 printf ("Timeout Writing EEPROM register %02x\n", reg
);
373 for (j
= 0; j
< 4; j
++) {
374 printf ("Bank%i ", j
);
377 for (i
= 0; i
< 0xF; i
+= 2) {
379 for (j
= 0; j
< 4; j
++) {
381 printf ("%04x ", SMC_inw (i
));
389 int smc91111_eeprom (int argc
, char *argv
[])
391 printf("Not supported for this board\n");