mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-11 07:34:31 +00:00
SMC911X: Add chip auto detection
Refactor the smc911x driver to allow for detecting when the chip is missing. I.e. the detect_chip() function is called earlier and will abort gracefully when the Chip ID read returns all 1's. Signed-off-by: Olof Johansson <olof@lixom.net> Acked-by: Dirk Behme <dirk.behme@googlemail.com> Acked-by: Ben Warren <biggerbadderben@gmail.com>
This commit is contained in:
parent
0297ec7e2a
commit
2a6cc97b91
2 changed files with 13 additions and 8 deletions
|
@ -146,10 +146,9 @@ static void smc911x_enable(struct eth_device *dev)
|
||||||
|
|
||||||
static int smc911x_init(struct eth_device *dev, bd_t * bd)
|
static int smc911x_init(struct eth_device *dev, bd_t * bd)
|
||||||
{
|
{
|
||||||
printf(DRIVERNAME ": initializing\n");
|
struct chip_id *id = dev->priv;
|
||||||
|
|
||||||
if (smc911x_detect_chip(dev))
|
printf(DRIVERNAME ": detected %s controller\n", id->name);
|
||||||
goto err_out;
|
|
||||||
|
|
||||||
smc911x_reset(dev);
|
smc911x_reset(dev);
|
||||||
|
|
||||||
|
@ -162,9 +161,6 @@ static int smc911x_init(struct eth_device *dev, bd_t * bd)
|
||||||
smc911x_enable(dev);
|
smc911x_enable(dev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_out:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int smc911x_send(struct eth_device *dev,
|
static int smc911x_send(struct eth_device *dev,
|
||||||
|
@ -268,6 +264,12 @@ int smc911x_initialize(u8 dev_num, int base_addr)
|
||||||
dev->recv = smc911x_rx;
|
dev->recv = smc911x_rx;
|
||||||
sprintf(dev->name, "%s-%hu", DRIVERNAME, dev_num);
|
sprintf(dev->name, "%s-%hu", DRIVERNAME, dev_num);
|
||||||
|
|
||||||
|
/* Try to detect chip. Will fail if not present. */
|
||||||
|
if (smc911x_detect_chip(dev)) {
|
||||||
|
free(dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
eth_register(dev);
|
eth_register(dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,10 @@ static int smc911x_detect_chip(struct eth_device *dev)
|
||||||
unsigned long val, i;
|
unsigned long val, i;
|
||||||
|
|
||||||
val = smc911x_reg_read(dev, BYTE_TEST);
|
val = smc911x_reg_read(dev, BYTE_TEST);
|
||||||
if (val != 0x87654321) {
|
if (val == 0xffffffff) {
|
||||||
|
/* Special case -- no chip present */
|
||||||
|
return -1;
|
||||||
|
} else if (val != 0x87654321) {
|
||||||
printf(DRIVERNAME ": Invalid chip endian 0x%08lx\n", val);
|
printf(DRIVERNAME ": Invalid chip endian 0x%08lx\n", val);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -455,7 +458,7 @@ static int smc911x_detect_chip(struct eth_device *dev)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(DRIVERNAME ": detected %s controller\n", chip_ids[i].name);
|
dev->priv = (void *)&chip_ids[i];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue