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

phy: Move phy specific bus match into phy_device

Matching a driver to a device has both generic parts, and parts which
are specific to PHY devices. Move the PHY specific parts into
phy_device.
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 be01da72
...@@ -523,41 +523,27 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) ...@@ -523,41 +523,27 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
EXPORT_SYMBOL(mdiobus_write); EXPORT_SYMBOL(mdiobus_write);
/** /**
* mdio_bus_match - determine if given PHY driver supports the given PHY device * mdio_bus_match - determine if given MDIO driver supports the given
* @dev: target PHY device * MDIO device
* @drv: given PHY driver * @dev: target MDIO device
* @drv: given MDIO driver
* *
* Description: Given a PHY device, and a PHY driver, return 1 if * Description: Given a MDIO device, and a MDIO driver, return 1 if
* the driver supports the device. Otherwise, return 0. * the driver supports the device. Otherwise, return 0. This may
* require calling the devices own match function, since different classes
* of MDIO devices have different match criteria.
*/ */
static int mdio_bus_match(struct device *dev, struct device_driver *drv) static int mdio_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct phy_device *phydev = to_phy_device(dev); struct mdio_device *mdio = to_mdio_device(dev);
struct phy_driver *phydrv = to_phy_driver(drv);
const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids);
int i;
if (of_driver_match_device(dev, drv)) if (of_driver_match_device(dev, drv))
return 1; return 1;
if (phydrv->match_phy_device) if (mdio->bus_match)
return phydrv->match_phy_device(phydev); return mdio->bus_match(dev, drv);
if (phydev->is_c45) {
for (i = 1; i < num_ids; i++) {
if (!(phydev->c45_ids.devices_in_package & (1 << i)))
continue;
if ((phydrv->phy_id & phydrv->phy_id_mask) ==
(phydev->c45_ids.device_ids[i] &
phydrv->phy_id_mask))
return 1;
}
return 0; return 0;
} else {
return (phydrv->phy_id & phydrv->phy_id_mask) ==
(phydev->phy_id & phydrv->phy_id_mask);
}
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
......
...@@ -257,6 +257,33 @@ static int phy_scan_fixups(struct phy_device *phydev) ...@@ -257,6 +257,33 @@ static int phy_scan_fixups(struct phy_device *phydev)
return 0; return 0;
} }
static int phy_bus_match(struct device *dev, struct device_driver *drv)
{
struct phy_device *phydev = to_phy_device(dev);
struct phy_driver *phydrv = to_phy_driver(drv);
const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids);
int i;
if (phydrv->match_phy_device)
return phydrv->match_phy_device(phydev);
if (phydev->is_c45) {
for (i = 1; i < num_ids; i++) {
if (!(phydev->c45_ids.devices_in_package & (1 << i)))
continue;
if ((phydrv->phy_id & phydrv->phy_id_mask) ==
(phydev->c45_ids.device_ids[i] &
phydrv->phy_id_mask))
return 1;
}
return 0;
} else {
return (phydrv->phy_id & phydrv->phy_id_mask) ==
(phydev->phy_id & phydrv->phy_id_mask);
}
}
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
bool is_c45, bool is_c45,
struct phy_c45_device_ids *c45_ids) struct phy_c45_device_ids *c45_ids)
...@@ -275,6 +302,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, ...@@ -275,6 +302,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
mdiodev->dev.bus = &mdio_bus_type; mdiodev->dev.bus = &mdio_bus_type;
mdiodev->bus = bus; mdiodev->bus = bus;
mdiodev->pm_ops = MDIO_BUS_PHY_PM_OPS; mdiodev->pm_ops = MDIO_BUS_PHY_PM_OPS;
mdiodev->bus_match = phy_bus_match;
mdiodev->addr = addr; mdiodev->addr = addr;
mdiodev->flags = MDIO_DEVICE_FLAG_PHY; mdiodev->flags = MDIO_DEVICE_FLAG_PHY;
......
...@@ -17,6 +17,7 @@ struct mdio_device { ...@@ -17,6 +17,7 @@ struct mdio_device {
struct device dev; struct device dev;
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);
/* 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