Commit 711fdba3 authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller

mdio: Abstract device_remove() and device_free()

Make device_free and device_remove operations in the mdio device
structure, so the core code does not need to differentiate between
phy devices and generic mdio devices.
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a9049e0c
...@@ -299,6 +299,7 @@ static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio, ...@@ -299,6 +299,7 @@ static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,
*/ */
int __mdiobus_register(struct mii_bus *bus, struct module *owner) int __mdiobus_register(struct mii_bus *bus, struct module *owner)
{ {
struct mdio_device *mdiodev;
int i, err; int i, err;
if (NULL == bus || NULL == bus->name || if (NULL == bus || NULL == bus->name ||
...@@ -344,11 +345,12 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) ...@@ -344,11 +345,12 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
error: error:
while (--i >= 0) { while (--i >= 0) {
struct phy_device *phydev = mdiobus_get_phy(bus, i); mdiodev = bus->mdio_map[i];
if (phydev) { if (!mdiodev)
phy_device_remove(phydev); continue;
phy_device_free(phydev);
} mdiodev->device_remove(mdiodev);
mdiodev->device_free(mdiodev);
} }
device_del(&bus->dev); device_del(&bus->dev);
return err; return err;
...@@ -358,7 +360,6 @@ EXPORT_SYMBOL(__mdiobus_register); ...@@ -358,7 +360,6 @@ EXPORT_SYMBOL(__mdiobus_register);
void mdiobus_unregister(struct mii_bus *bus) void mdiobus_unregister(struct mii_bus *bus)
{ {
struct mdio_device *mdiodev; struct mdio_device *mdiodev;
struct phy_device *phydev;
int i; int i;
BUG_ON(bus->state != MDIOBUS_REGISTERED); BUG_ON(bus->state != MDIOBUS_REGISTERED);
...@@ -369,14 +370,8 @@ void mdiobus_unregister(struct mii_bus *bus) ...@@ -369,14 +370,8 @@ void mdiobus_unregister(struct mii_bus *bus)
if (!mdiodev) if (!mdiodev)
continue; continue;
if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY)) { mdiodev->device_remove(mdiodev);
phydev = container_of(mdiodev, struct phy_device, mdio); mdiodev->device_free(mdiodev);
phy_device_remove(phydev);
phy_device_free(phydev);
} else {
mdio_device_remove(mdiodev);
mdio_device_free(mdiodev);
}
} }
device_del(&bus->dev); device_del(&bus->dev);
} }
......
...@@ -46,6 +46,8 @@ struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr) ...@@ -46,6 +46,8 @@ struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr)
mdiodev->dev.release = mdio_device_release; mdiodev->dev.release = mdio_device_release;
mdiodev->dev.parent = &bus->dev; mdiodev->dev.parent = &bus->dev;
mdiodev->dev.bus = &mdio_bus_type; mdiodev->dev.bus = &mdio_bus_type;
mdiodev->device_free = mdio_device_free;
mdiodev->device_remove = mdio_device_remove;
mdiodev->bus = bus; mdiodev->bus = bus;
mdiodev->addr = addr; mdiodev->addr = addr;
......
...@@ -47,11 +47,27 @@ void phy_device_free(struct phy_device *phydev) ...@@ -47,11 +47,27 @@ void phy_device_free(struct phy_device *phydev)
} }
EXPORT_SYMBOL(phy_device_free); EXPORT_SYMBOL(phy_device_free);
static void phy_mdio_device_free(struct mdio_device *mdiodev)
{
struct phy_device *phydev;
phydev = container_of(mdiodev, struct phy_device, mdio);
phy_device_free(phydev);
}
static void phy_device_release(struct device *dev) static void phy_device_release(struct device *dev)
{ {
kfree(to_phy_device(dev)); kfree(to_phy_device(dev));
} }
static void phy_mdio_device_remove(struct mdio_device *mdiodev)
{
struct phy_device *phydev;
phydev = container_of(mdiodev, struct phy_device, mdio);
phy_device_remove(phydev);
}
enum genphy_driver { enum genphy_driver {
GENPHY_DRV_1G, GENPHY_DRV_1G,
GENPHY_DRV_10G, GENPHY_DRV_10G,
...@@ -308,6 +324,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, ...@@ -308,6 +324,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
mdiodev->bus_match = phy_bus_match; mdiodev->bus_match = phy_bus_match;
mdiodev->addr = addr; mdiodev->addr = addr;
mdiodev->flags = MDIO_DEVICE_FLAG_PHY; mdiodev->flags = MDIO_DEVICE_FLAG_PHY;
mdiodev->device_free = phy_mdio_device_free;
mdiodev->device_remove = phy_mdio_device_remove;
dev->speed = 0; dev->speed = 0;
dev->duplex = -1; dev->duplex = -1;
......
...@@ -18,7 +18,11 @@ struct mdio_device { ...@@ -18,7 +18,11 @@ struct mdio_device {
const struct dev_pm_ops *pm_ops; const struct dev_pm_ops *pm_ops;
struct mii_bus *bus; struct mii_bus *bus;
int (*bus_match)(struct device *dev, struct device_driver *drv); int (*bus_match)(struct device *dev, struct device_driver *drv);
void (*device_free)(struct mdio_device *mdiodev);
void (*device_remove)(struct mdio_device *mdiodev);
/* Bus address of the MDIO device (0-31) */ /* Bus address of the MDIO device (0-31) */
int addr; int addr;
int flags; int flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment