mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 3/3] phy: add of_phy_simple_xlate()
Date: Fri, 25 Oct 2024 10:49:01 +0200	[thread overview]
Message-ID: <20241025-phy-class-v1-3-24bf51365a08@pengutronix.de> (raw)
In-Reply-To: <20241025-phy-class-v1-0-24bf51365a08@pengutronix.de>

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@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




  parent reply	other threads:[~2024-10-25  8:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25  8:48 [PATCH 0/3] phy: some updates Sascha Hauer
2024-10-25  8:48 ` [PATCH 1/3] phy: make of_phandle_args constant Sascha Hauer
2024-10-25  8:49 ` [PATCH 2/3] phy: put phy devices in class Sascha Hauer
2024-10-25  8:49 ` Sascha Hauer [this message]
2024-10-28 12:12 ` [PATCH 0/3] phy: some updates Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241025-phy-class-v1-3-24bf51365a08@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox