* Some code shamelessly stolen back from Robin Getz.
*/
-#define DEBUG
-
#include <common.h>
#include <exports.h>
-#include "../drivers/smc91111.h"
+#include <timestamp.h>
+#include <net.h>
+#include "../drivers/net/smc91111.h"
-#define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
+static struct eth_device dev = {
+ .iobase = CONFIG_SMC91111_BASE
+};
static u16 read_eeprom_reg(u16 reg)
{
int timeout;
- SMC_SELECT_BANK(2);
- SMC_outw(reg, PTR_REG);
+ SMC_SELECT_BANK(&dev, 2);
+ SMC_outw(&dev, reg, PTR_REG);
+
+ SMC_SELECT_BANK(&dev, 1);
+ SMC_outw(&dev, SMC_inw(&dev, CTL_REG) | CTL_EEPROM_SELECT |
+ CTL_RELOAD, CTL_REG);
- SMC_SELECT_BANK(1);
- SMC_outw(SMC_inw (CTL_REG) | CTL_EEPROM_SELECT | CTL_RELOAD,
- CTL_REG);
timeout = 100;
- while((SMC_inw (CTL_REG) & CTL_RELOAD) && --timeout)
+
+ while ((SMC_inw(&dev, CTL_REG) & CTL_RELOAD) && --timeout)
udelay(100);
if (timeout == 0) {
- printf("Timeout Reading EEPROM register %02x\n", reg);
+ printf("Timeout reading register %02x\n", reg);
return 0;
}
- return SMC_inw (GP_REG);
+ return SMC_inw(&dev, GP_REG);
}
static int write_eeprom_reg(u16 value, u16 reg)
{
int timeout;
- SMC_SELECT_BANK(2);
- SMC_outw(reg, PTR_REG);
+ SMC_SELECT_BANK(&dev, 2);
+ SMC_outw(&dev, reg, PTR_REG);
+
+ SMC_SELECT_BANK(&dev, 1);
+
+ SMC_outw(&dev, value, GP_REG);
+ SMC_outw(&dev, SMC_inw(&dev, CTL_REG) | CTL_EEPROM_SELECT |
+ CTL_STORE, CTL_REG);
- SMC_SELECT_BANK(1);
- SMC_outw(value, GP_REG);
- SMC_outw(SMC_inw (CTL_REG) | CTL_EEPROM_SELECT | CTL_STORE, CTL_REG);
timeout = 100;
- while ((SMC_inw(CTL_REG) & CTL_STORE) && --timeout)
- udelay (100);
+
+ while ((SMC_inw(&dev, CTL_REG) & CTL_STORE) && --timeout)
+ udelay(100);
if (timeout == 0) {
- printf("Timeout Writing EEPROM register %02x\n", reg);
+ printf("Timeout writing register %02x\n", reg);
return 0;
}
u16 reg;
int i, err = 0;
- printf("MAC Address: ");
- err = i = 0;
+ puts("HWaddr: ");
for (i = 0; i < 3; i++) {
reg = read_eeprom_reg(0x20 + i);
printf("%02x:%02x%c", reg & 0xff, reg >> 8, i != 2 ? ':' : '\n');
return cnt;
}
-extern int crcek(void);
-
int eeprom(int argc, char *argv[])
{
int i, len, ret;
unsigned char buf[58], *p;
app_startup(argv);
- if (get_version() != XF_VERSION) {
- printf("Wrong XF_VERSION.\n");
- printf("Application expects ABI version %d\n", XF_VERSION);
- printf("Actual U-Boot ABI version %d\n", (int)get_version());
+ i = get_version();
+ if (i != XF_VERSION) {
+ printf("Using ABI version %d, but U-Boot provides %d\n",
+ XF_VERSION, i);
return 1;
}
- return crcek();
-
- if ((SMC_inw (BANK_SELECT) & 0xFF00) != 0x3300) {
- printf("SMSC91111 not found.\n");
+ if ((SMC_inw(&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
+ puts("SMSC91111 not found\n");
return 2;
}
/* Print help message */
if (argv[1][1] == 'h') {
- printf("VoiceBlue EEPROM writer\n");
- printf("Built: %s at %s\n", __DATE__ , __TIME__ );
- printf("Usage:\n\t<mac_address> [<element_1>] [<...>]\n");
+ puts("NetStar EEPROM writer\n"
+ "Built: " U_BOOT_DATE " at " U_BOOT_TIME "\n"
+ "Usage:\n\t<mac_address> [<element_1>] [<...>]\n");
return 0;
}
printf("Element %d: odd character count\n", i - 1);
return 3;
case -3:
- printf("Out of EEPROM memory\n");
+ puts("Out of EEPROM memory\n");
return 3;
default:
p += ret;
/* First argument (MAC) is mandatory */
set_mac(argv[1]);
if (verify_macaddr(argv[1])) {
- printf("*** MAC address does not match! ***\n");
+ puts("*** HWaddr does not match! ***\n");
return 4;
}