[PATCH 3/3] phy: add of_phy_simple_xlate()
Sascha Hauer
s.hauer at pengutronix.de
Fri Oct 25 01:49:01 PDT 2024
of_phy_provider_register() needs a of_xlate function. For simple
one-phy-per-device-node type phys of_phy_simple_xlate() can be used.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/phy/phy-core.c | 25 +++++++++++++++++++++++++
include/linux/phy/phy.h | 3 +++
2 files changed, 28 insertions(+)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index cd9b59f1fd..f876dc2dea 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -254,6 +254,31 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
return ERR_PTR(-EPROBE_DEFER);
}
+/**
+ * of_phy_simple_xlate() - returns the phy instance from phy provider
+ * @dev: the PHY provider device
+ * @args: of_phandle_args (not used here)
+ *
+ * Intended to be used by phy provider for the common case where #phy-cells is
+ * 0. For other cases where #phy-cells is greater than '0', the phy provider
+ * should provide a custom of_xlate function that reads the *args* and returns
+ * the appropriate phy.
+ */
+struct phy *of_phy_simple_xlate(struct device *dev,
+ const struct of_phandle_args *args)
+{
+ struct phy *phy;
+
+ for_each_phy(phy) {
+ if (args->np != phy->dev.of_node)
+ continue;
+
+ return phy;
+ }
+
+ return ERR_PTR(-ENODEV);
+}
+
/**
* _of_phy_get() - lookup and obtain a reference to a phy by phandle
* @np: device_node for which to get the phy
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index e861e50f76..dd28c6eeef 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -147,6 +147,9 @@ static inline void *phy_get_drvdata(struct phy *phy)
return phy->dev.priv;
}
+struct phy *of_phy_simple_xlate(struct device *dev,
+ const struct of_phandle_args *args);
+
#if IS_ENABLED(CONFIG_GENERIC_PHY)
int phy_init(struct phy *phy);
int phy_exit(struct phy *phy);
--
2.39.5
More information about the barebox
mailing list