public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: mdiobus: add fwnode_phy_is_fixed_link()
@ 2022-10-09 16:20 Soha Jin
  2022-10-10 15:03 ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Soha Jin @ 2022-10-09 16:20 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Russell King, netdev, linux-kernel, Soha Jin

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@lohu.info>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-10 16:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-09 16:20 [PATCH] net: mdiobus: add fwnode_phy_is_fixed_link() Soha Jin
2022-10-10 15:03 ` Andrew Lunn
2022-10-10 15:44   ` Soha Jin
2022-10-10 16:43   ` Russell King (Oracle)
2022-10-10 16:52     ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox