]>
git.ipfire.org Git - people/ms/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 /* the smc91111.h gets base addr through eth_device' iobase */
33 struct eth_device
{ unsigned long iobase
; };
34 #include "../drivers/net/smc91111.h"
36 #ifdef CONFIG_SMC91111
38 #ifndef SMC91111_EEPROM_INIT
39 # define SMC91111_EEPROM_INIT()
42 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
47 void dump_reg (struct eth_device
*dev
);
48 void dump_eeprom (struct eth_device
*dev
);
49 int write_eeprom_reg (struct eth_device
*dev
, int value
, int reg
);
50 void copy_from_eeprom (struct eth_device
*dev
);
51 void print_MAC (struct eth_device
*dev
);
52 int read_eeprom_reg (struct eth_device
*dev
, int reg
);
53 void print_macaddr (struct eth_device
*dev
);
55 int smc91111_eeprom (int argc
, char *argv
[])
57 int c
, i
, j
, done
, line
, reg
, value
, start
, what
;
60 struct eth_device dev
= {
61 .iobase
= CONFIG_SMC91111_BASE
64 /* Print the ABI version */
66 if (XF_VERSION
!= (int) get_version ()) {
67 printf ("Expects ABI version %d\n", XF_VERSION
);
68 printf ("Actual U-Boot ABI version %d\n",
69 (int) get_version ());
70 printf ("Can't run\n\n");
74 SMC91111_EEPROM_INIT();
76 if ((SMC_inw (&dev
, BANK_SELECT
) & 0xFF00) != 0x3300) {
77 printf ("Can't find SMSC91111\n");
85 /* print the prompt */
86 printf ("SMC91111> ");
91 /* Wait for a keystroke */
98 /* printf(" |%02x| ",c); */
101 case '\r': /* Enter */
110 case 0x03: /* ^C - break */
118 case 0x08: /* ^H - backspace */
119 case 0x7F: /* DEL - backspace */
127 if ((c
== 'W') || (c
== 'D')
128 || (c
== 'M') || (c
== 'C')
137 if ((c
>= '0' && c
<= '9')
138 || (c
>= 'A' && c
<= 'F')
139 || (c
== 'E') || (c
== 'M')
157 /* Line should be w reg value */
161 /* Skip to the next space or end) */
162 while ((input
[i
] != ' ') && (input
[i
] != 0))
168 /* Are we writing to EEPROM or MAC */
181 /* skip to the next space or end */
182 while ((input
[i
] != ' ') && (input
[i
] != 0))
187 /* Find register to write into */
189 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
194 reg
= (reg
* 0x10) + j
;
198 while ((input
[i
] != ' ') && (input
[i
] != 0))
206 /* Get the value to write */
208 while ((input
[i
] != ' ') && (input
[i
] != 0)) {
213 value
= (value
* 0x10) + j
;
219 printf ("Writing EEPROM register %02x with %04x\n", reg
, value
);
220 write_eeprom_reg (&dev
, value
, reg
);
223 printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg
>> 4, reg
& 0xE, value
);
224 SMC_SELECT_BANK (&dev
, reg
>> 4);
225 SMC_outw (&dev
, value
, reg
& 0xE);
239 copy_from_eeprom (&dev
);
242 print_macaddr (&dev
);
253 void copy_from_eeprom (struct eth_device
*dev
)
257 SMC_SELECT_BANK (dev
, 1);
258 SMC_outw (dev
, (SMC_inw (dev
, CTL_REG
) & !CTL_EEPROM_SELECT
) |
259 CTL_RELOAD
, CTL_REG
);
261 while ((SMC_inw (dev
, CTL_REG
) & CTL_RELOAD
) && --i
)
264 printf ("Timeout Refreshing EEPROM registers\n");
266 printf ("EEPROM contents copied to MAC\n");
271 void print_macaddr (struct eth_device
*dev
)
275 printf ("Current MAC Address in SMSC91111 ");
276 SMC_SELECT_BANK (dev
, 1);
277 for (i
= 0; i
< 5; i
++) {
278 printf ("%02x:", SMC_inb (dev
, ADDR0_REG
+ i
));
281 printf ("%02x\n", SMC_inb (dev
, ADDR0_REG
+ 5));
284 for (j
= 0x20; j
< 0x23; j
++) {
285 k
= read_eeprom_reg (dev
, j
);
292 printf ("Current MAC Address in EEPROM ");
293 for (i
= 0; i
< 5; i
++)
294 printf ("%02x:", mac
[i
]);
295 printf ("%02x\n", mac
[5]);
298 void dump_eeprom (struct eth_device
*dev
)
303 for (j
= 0; j
< 8; j
++) {
308 for (k
= 0; k
< 4; k
++) {
313 if ((k
== 2) || (k
== 3))
315 for (j
= 0; j
< 0x20; j
+= 4) {
316 printf ("%02x:%04x ", j
+ k
,
317 read_eeprom_reg (dev
, j
+ k
));
322 for (j
= 0x20; j
< 0x40; j
++) {
325 printf ("%02x:%04x ", j
, read_eeprom_reg (dev
, j
));
331 int read_eeprom_reg (struct eth_device
*dev
, 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
, SMC_inw (dev
, CTL_REG
) | CTL_EEPROM_SELECT
|
340 CTL_RELOAD
, CTL_REG
);
342 while ((SMC_inw (dev
, CTL_REG
) & CTL_RELOAD
) && --timeout
)
345 printf ("Timeout Reading EEPROM register %02x\n", reg
);
349 return SMC_inw (dev
, GP_REG
);
353 int write_eeprom_reg (struct eth_device
*dev
, int value
, int reg
)
357 SMC_SELECT_BANK (dev
, 2);
358 SMC_outw (dev
, reg
, PTR_REG
);
360 SMC_SELECT_BANK (dev
, 1);
361 SMC_outw (dev
, value
, GP_REG
);
362 SMC_outw (dev
, SMC_inw (dev
, CTL_REG
) | CTL_EEPROM_SELECT
|
365 while ((SMC_inw (dev
, CTL_REG
) & CTL_STORE
) && --timeout
)
368 printf ("Timeout Writing EEPROM register %02x\n", reg
);
376 void dump_reg (struct eth_device
*dev
)
381 for (j
= 0; j
< 4; j
++) {
382 printf ("Bank%i ", j
);
385 for (i
= 0; i
< 0xF; i
+= 2) {
387 for (j
= 0; j
< 4; j
++) {
388 SMC_SELECT_BANK (dev
, j
);
389 printf ("%04x ", SMC_inw (dev
, i
));
397 int smc91111_eeprom (int argc
, char *argv
[])
399 printf("Not supported for this board\n");