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
dev.iobase = CONFIG_SMC91111_BASE;
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");
69
SMC91111_EEPROM_INIT();
71
if ((SMC_inw (&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
72
printf ("Can't find SMSC91111\n");
80
/* print the prompt */
81
printf ("SMC91111> ");
86
/* Wait for a keystroke */
93
/* printf(" |%02x| ",c); */
96
case '\r': /* Enter */
105
case 0x03: /* ^C - break */
113
case 0x08: /* ^H - backspace */
114
case 0x7F: /* DEL - backspace */
122
if ((c == 'W') || (c == 'D')
123
|| (c == 'M') || (c == 'C')
132
if ((c >= '0' && c <= '9')
133
|| (c >= 'A' && c <= 'F')
134
|| (c == 'E') || (c == 'M')
152
/* Line should be w reg value */
156
/* Skip to the next space or end) */
157
while ((input[i] != ' ') && (input[i] != 0))
163
/* Are we writing to EEPROM or MAC */
176
/* skip to the next space or end */
177
while ((input[i] != ' ') && (input[i] != 0))
182
/* Find register to write into */
184
while ((input[i] != ' ') && (input[i] != 0)) {
189
reg = (reg * 0x10) + j;
193
while ((input[i] != ' ') && (input[i] != 0))
201
/* Get the value to write */
203
while ((input[i] != ' ') && (input[i] != 0)) {
208
value = (value * 0x10) + j;
214
printf ("Writing EEPROM register %02x with %04x\n", reg, value);
215
write_eeprom_reg (&dev, value, reg);
218
printf ("Writing MAC register bank %i, reg %02x with %04x\n", reg >> 4, reg & 0xE, value);
219
SMC_SELECT_BANK (&dev, reg >> 4);
220
SMC_outw (&dev, value, reg & 0xE);
234
copy_from_eeprom (&dev);
237
print_macaddr (&dev);
248
void copy_from_eeprom (struct eth_device *dev)
252
SMC_SELECT_BANK (dev, 1);
253
SMC_outw (dev, (SMC_inw (dev, CTL_REG) & !CTL_EEPROM_SELECT) |
254
CTL_RELOAD, CTL_REG);
256
while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --i)
259
printf ("Timeout Refreshing EEPROM registers\n");
261
printf ("EEPROM contents copied to MAC\n");
266
void print_macaddr (struct eth_device *dev)
270
printf ("Current MAC Address in SMSC91111 ");
271
SMC_SELECT_BANK (dev, 1);
272
for (i = 0; i < 5; i++) {
273
printf ("%02x:", SMC_inb (dev, ADDR0_REG + i));
276
printf ("%02x\n", SMC_inb (dev, ADDR0_REG + 5));
279
for (j = 0x20; j < 0x23; j++) {
280
k = read_eeprom_reg (dev, j);
287
printf ("Current MAC Address in EEPROM ");
288
for (i = 0; i < 5; i++)
289
printf ("%02x:", mac[i]);
290
printf ("%02x\n", mac[5]);
293
void dump_eeprom (struct eth_device *dev)
298
for (j = 0; j < 8; j++) {
303
for (k = 0; k < 4; k++) {
308
if ((k == 2) || (k == 3))
310
for (j = 0; j < 0x20; j += 4) {
311
printf ("%02x:%04x ", j + k,
312
read_eeprom_reg (dev, j + k));
317
for (j = 0x20; j < 0x40; j++) {
320
printf ("%02x:%04x ", j, read_eeprom_reg (dev, j));
326
int read_eeprom_reg (struct eth_device *dev, int reg)
330
SMC_SELECT_BANK (dev, 2);
331
SMC_outw (dev, reg, PTR_REG);
333
SMC_SELECT_BANK (dev, 1);
334
SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
335
CTL_RELOAD, CTL_REG);
337
while ((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --timeout)
340
printf ("Timeout Reading EEPROM register %02x\n", reg);
344
return SMC_inw (dev, GP_REG);
348
int write_eeprom_reg (struct eth_device *dev, int value, int reg)
352
SMC_SELECT_BANK (dev, 2);
353
SMC_outw (dev, reg, PTR_REG);
355
SMC_SELECT_BANK (dev, 1);
356
SMC_outw (dev, value, GP_REG);
357
SMC_outw (dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT |
360
while ((SMC_inw (dev, CTL_REG) & CTL_STORE) && --timeout)
363
printf ("Timeout Writing EEPROM register %02x\n", reg);
371
void dump_reg (struct eth_device *dev)
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++) {
383
SMC_SELECT_BANK (dev, j);
384
printf ("%04x ", SMC_inw (dev, i));