This patch utilizes the newly added fwnode_mdiobus_register_device function and enables registration of non-PHY MDIO devices. For that purpose a helper routine is added, allowing to determine, whether the device associated to ACPI node is a PHY. In addition to that update, allow matching child devices' drivers based on their ACPI ID. Signed-off-by: Marcin Wojtas <mw@xxxxxxxxxxxx> --- drivers/net/mdio/acpi_mdio.c | 40 +++++++++++++++++++- drivers/net/phy/mdio_bus.c | 4 ++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/acpi_mdio.c b/drivers/net/mdio/acpi_mdio.c index d77c987fda9c..b5d7404afc5e 100644 --- a/drivers/net/mdio/acpi_mdio.c +++ b/drivers/net/mdio/acpi_mdio.c @@ -17,6 +17,41 @@ MODULE_AUTHOR("Calvin Johnson <calvin.johnson@xxxxxxxxxxx>"); MODULE_LICENSE("GPL"); +/** + * acpi_mdiobus_child_is_phy - check if device associated with fwnode is a PHY. + * @fwnode: pointer to MDIO bus child fwnode and is expected to represent ACPI + * device object. + * + * The function returns true if the child node is for a PHY. + * It must comprise either: + * o Compatible string of "ethernet-phy-idX.X" + * o Compatible string of "ethernet-phy-ieee802.3-c45" + * o Compatible string of "ethernet-phy-ieee802.3-c22" + * o No _HID or _CID fields. + */ +static bool acpi_mdiobus_child_is_phy(struct fwnode_handle *child) +{ + struct acpi_device *adev = to_acpi_device_node(child); + u32 phy_id; + + if (fwnode_get_phy_id(child, &phy_id) != -EINVAL) + return true; + + if (fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c45") == 0) + return true; + + if (fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c22") == 0) + return true; + + /* Default to PHY if no _HID or _CID found in the fwnode. */ + if (list_empty(&adev->pnp.ids)) + return true; + + return false; +} + /** * acpi_mdiobus_register - Register mii_bus and create PHYs from the ACPI ASL. * @mdio: pointer to mii_bus structure @@ -47,7 +82,10 @@ int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode) if (ret || addr >= PHY_MAX_ADDR) continue; - ret = fwnode_mdiobus_register_phy(mdio, child, addr); + if (acpi_mdiobus_child_is_phy(child)) + ret = fwnode_mdiobus_register_phy(mdio, child, addr); + else + ret = fwnode_mdiobus_register_device(mdio, child, addr); if (ret == -ENODEV) dev_err(&mdio->dev, "MDIO device at address %d is missing.\n", diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 8a2dbe849866..b3c2f966be4b 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include <linux/acpi.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/errno.h> @@ -989,6 +990,9 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv) if (of_driver_match_device(dev, drv)) return 1; + if (acpi_driver_match_device(dev, drv)) + return 1; + if (mdio->bus_match) return mdio->bus_match(dev, drv); -- 2.29.0