summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-12-11 10:42:44 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-12-11 10:46:50 +0100
commit58f9167a04e5c780f07a0488a1cd9c71d28ffc08 (patch)
treec6c38614e051dc540cddd20976ef02f45107ae6f /drivers
parent5f0a71708e04ae7c5c0d4ef859d680bcce44dd86 (diff)
downloadbarebox-58f9167a04e5c780f07a0488a1cd9c71d28ffc08.tar.gz
barebox-58f9167a04e5c780f07a0488a1cd9c71d28ffc08.tar.xz
net: phy: bail out early in phy_device_connect
If an ethernet device already has a phy in phy_device_connect all we have to do is to start autonegotiation. Do this early and bail out so that for the rest of the code it's clear that we have to search for a phy device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/phy/phy.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d8966cd469..a83b35c141 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -224,6 +224,14 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr)
return dev;
}
+static void phy_config_aneg(struct phy_device *phydev)
+{
+ struct phy_driver *drv;
+
+ drv = to_phy_driver(phydev->dev.driver);
+ drv->config_aneg(phydev);
+}
+
static int phy_register_device(struct phy_device* dev)
{
int ret;
@@ -246,18 +254,37 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
void (*adjust_link) (struct eth_device *edev),
u32 flags, phy_interface_t interface)
{
- struct phy_driver* drv;
struct phy_device* dev = NULL;
unsigned int i;
int ret = -EINVAL;
- if (!edev->phydev) {
- if (addr >= 0) {
- dev = mdiobus_scan(bus, addr);
- if (IS_ERR(dev)) {
- ret = -EIO;
- goto fail;
- }
+ if (edev->phydev) {
+ phy_config_aneg(edev->phydev);
+ return 0;
+ }
+
+ if (addr >= 0) {
+ dev = mdiobus_scan(bus, addr);
+ if (IS_ERR(dev)) {
+ ret = -EIO;
+ goto fail;
+ }
+
+ dev->interface = interface;
+ dev->dev_flags = flags;
+
+ ret = phy_register_device(dev);
+ if (ret)
+ goto fail;
+ } else {
+ for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
+ /* skip masked out PHY addresses */
+ if (bus->phy_mask & (1 << i))
+ continue;
+
+ dev = mdiobus_scan(bus, i);
+ if (IS_ERR(dev) || dev->attached_dev)
+ continue;
dev->interface = interface;
dev->dev_flags = flags;
@@ -265,33 +292,14 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
ret = phy_register_device(dev);
if (ret)
goto fail;
- } else {
- for (i = 0; i < PHY_MAX_ADDR && !edev->phydev; i++) {
- /* skip masked out PHY addresses */
- if (bus->phy_mask & (1 << i))
- continue;
- dev = mdiobus_scan(bus, i);
- if (IS_ERR(dev) || dev->attached_dev)
- continue;
-
- dev->interface = interface;
- dev->dev_flags = flags;
-
- ret = phy_register_device(dev);
- if (ret)
- goto fail;
-
- break;
- }
+ break;
}
}
edev->phydev = dev;
dev->attached_dev = edev;
- drv = to_phy_driver(dev->dev.driver);
-
- drv->config_aneg(dev);
+ phy_config_aneg(edev->phydev);
dev->adjust_link = adjust_link;