phy: Add API for {un}registering an mdio device to a bus.
Rather than have drivers directly manipulate the mii_bus structure, provide and API for registering and unregistering devices on an MDIO bus, and performing lookups. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
801a8ef54e
commit
7f854420fb
@@ -166,6 +166,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
|
||||
mdiodev->dev.bus = &mdio_bus_type;
|
||||
mdiodev->bus = bus;
|
||||
mdiodev->addr = addr;
|
||||
mdiodev->flags = MDIO_DEVICE_FLAG_PHY;
|
||||
|
||||
dev->speed = 0;
|
||||
dev->duplex = -1;
|
||||
@@ -383,10 +384,9 @@ int phy_device_register(struct phy_device *phydev)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Don't register a phy if one is already registered at this address */
|
||||
if (phydev->mdio.bus->phy_map[phydev->mdio.addr])
|
||||
return -EINVAL;
|
||||
phydev->mdio.bus->phy_map[phydev->mdio.addr] = phydev;
|
||||
err = mdiobus_register_device(&phydev->mdio);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Run all of the fixups for this PHY */
|
||||
err = phy_scan_fixups(phydev);
|
||||
@@ -404,7 +404,7 @@ int phy_device_register(struct phy_device *phydev)
|
||||
return 0;
|
||||
|
||||
out:
|
||||
phydev->mdio.bus->phy_map[phydev->mdio.addr] = NULL;
|
||||
mdiobus_unregister_device(&phydev->mdio);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(phy_device_register);
|
||||
@@ -419,11 +419,8 @@ EXPORT_SYMBOL(phy_device_register);
|
||||
*/
|
||||
void phy_device_remove(struct phy_device *phydev)
|
||||
{
|
||||
struct mii_bus *bus = phydev->mdio.bus;
|
||||
int addr = phydev->mdio.addr;
|
||||
|
||||
device_del(&phydev->mdio.dev);
|
||||
bus->phy_map[addr] = NULL;
|
||||
mdiobus_unregister_device(&phydev->mdio);
|
||||
}
|
||||
EXPORT_SYMBOL(phy_device_remove);
|
||||
|
||||
@@ -433,11 +430,13 @@ EXPORT_SYMBOL(phy_device_remove);
|
||||
*/
|
||||
struct phy_device *phy_find_first(struct mii_bus *bus)
|
||||
{
|
||||
struct phy_device *phydev;
|
||||
int addr;
|
||||
|
||||
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
|
||||
if (bus->phy_map[addr])
|
||||
return bus->phy_map[addr];
|
||||
phydev = mdiobus_get_phy(bus, addr);
|
||||
if (phydev)
|
||||
return phydev;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user