[PATCH] net: mdiobus: add fwnode_phy_is_fixed_link()

From: Soha Jin
Date: Sun Oct 09 2022 - 12:22:24 EST


A helper function to check if PHY is fixed link with fwnode properties.
This is similar to of_phy_is_fixed_link.

Signed-off-by: Soha Jin <soha@xxxxxxxxx>
---
drivers/net/mdio/fwnode_mdio.c | 30 +++++++++++++++++++++++++++++-
include/linux/fwnode_mdio.h | 2 ++
2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index 689e728345ce..8e1773e4d304 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -6,8 +6,9 @@
* out of the fwnode and using it to populate an mii_bus.
*/

-#include <linux/acpi.h>
#include <linux/fwnode_mdio.h>
+#include <linux/property.h>
+#include <linux/acpi.h>
#include <linux/of.h>
#include <linux/phy.h>
#include <linux/pse-pd/pse.h>
@@ -183,3 +184,30 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
return rc;
}
EXPORT_SYMBOL(fwnode_mdiobus_register_phy);
+
+bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *dn;
+ int err;
+ const char *managed;
+
+ /* New binding: 'fixed-link' is a sub-node of the Ethernet device. */
+ dn = fwnode_get_named_child_node(fwnode, "fixed-link");
+ if (dn) {
+ fwnode_handle_put(dn);
+ return true;
+ }
+
+ err = fwnode_property_read_string(fwnode, "managed", &managed);
+ if (err == 0 && strcmp(managed, "auto") != 0)
+ return true;
+
+ /* Old binding: 'fixed-link' was a property with 5 cells encoding
+ * various information about the fixed PHY.
+ */
+ if (fwnode_property_count_u32(fwnode, "fixed-link") == 5)
+ return true;
+
+ return false;
+}
+EXPORT_SYMBOL(fwnode_phy_is_fixed_link);
diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h
index faf603c48c86..f35e447e524a 100644
--- a/include/linux/fwnode_mdio.h
+++ b/include/linux/fwnode_mdio.h
@@ -32,4 +32,6 @@ static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus,
}
#endif

+bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode);
+
#endif /* __LINUX_FWNODE_MDIO_H */
--
2.30.2