net: phy: Introduce fwnode_mdio_find_device()
authorCalvin Johnson <calvin.johnson@oss.nxp.com>
Fri, 11 Jun 2021 10:53:48 +0000 (13:53 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 11 Jun 2021 20:08:52 +0000 (13:08 -0700)
Define fwnode_mdio_find_device() to get a pointer to the
mdio_device from fwnode passed to the function.

Refactor of_mdio_find_device() to use fwnode_mdio_find_device().

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Acked-by: Grant Likely <grant.likely@arm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/mdio/of_mdio.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index 8e97d5b825f5a4aaed661d10534f6feae6fbeac9..6ef8b6e401892a11b18347010c6b24f091cf6c1c 100644 (file)
@@ -347,16 +347,7 @@ EXPORT_SYMBOL(of_mdiobus_register);
  */
 struct mdio_device *of_mdio_find_device(struct device_node *np)
 {
-       struct device *d;
-
-       if (!np)
-               return NULL;
-
-       d = bus_find_device_by_of_node(&mdio_bus_type, np);
-       if (!d)
-               return NULL;
-
-       return to_mdio_device(d);
+       return fwnode_mdio_find_device(of_fwnode_handle(np));
 }
 EXPORT_SYMBOL(of_mdio_find_device);
 
index 495d86b4af7cf42858d5d77f7ba7b4fabe27e1b5..dca454b5c209f500933bbb5bdb9a496f2b91ca9e 100644 (file)
@@ -2875,6 +2875,29 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv)
        return phydrv->config_intr && phydrv->handle_interrupt;
 }
 
+/**
+ * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
+ * @fwnode: pointer to the mdio_device's fwnode
+ *
+ * If successful, returns a pointer to the mdio_device with the embedded
+ * struct device refcount incremented by one, or NULL on failure.
+ * The caller should call put_device() on the mdio_device after its use.
+ */
+struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
+{
+       struct device *d;
+
+       if (!fwnode)
+               return NULL;
+
+       d = bus_find_device_by_fwnode(&mdio_bus_type, fwnode);
+       if (!d)
+               return NULL;
+
+       return to_mdio_device(d);
+}
+EXPORT_SYMBOL(fwnode_mdio_find_device);
+
 /**
  * phy_probe - probe and init a PHY device
  * @dev: device to probe and init
index ed332ac92e251091e0629c67d2c3bfd084f20dbe..7aa97f4e53872a31c29c2253be14a0de39dea037 100644 (file)
@@ -1377,10 +1377,17 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
                                     bool is_c45,
                                     struct phy_c45_device_ids *c45_ids);
 #if IS_ENABLED(CONFIG_PHYLIB)
+struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode);
 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
 int phy_device_register(struct phy_device *phy);
 void phy_device_free(struct phy_device *phydev);
 #else
+static inline
+struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
+{
+       return 0;
+}
+
 static inline
 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
 {