public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>
Cc: u-boot@lists.denx.de, "Marek Behún" <marek.behun@nic.cz>,
	"Bin Meng" <bmeng.cn@gmail.com>,
	"Chen Guanqiao" <chenguanqiao@kuaishou.com>,
	"Dario Binacchi" <dariobin@libero.it>,
	"Jagan Teki" <jagan@amarulasolutions.com>,
	"Kishon Vijay Abraham I" <kishon@ti.com>,
	"Leo Yu-Chi Liang" <ycliang@andestech.com>,
	"Lokesh Vutla" <lokeshvutla@ti.com>,
	"Michael Walle" <michael@walle.cc>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
	"Priyanka Jain" <priyanka.jain@nxp.com>,
	"Simon Glass" <sjg@chromium.org>,
	"Vladimir Oltean" <vladimir.oltean@nxp.com>
Subject: [PATCH u-boot-net 03/14] net: introduce helpers to get PHY ofnode from MAC
Date: Thu, 17 Mar 2022 13:49:47 +0100	[thread overview]
Message-ID: <20220317124958.27921-4-kabel@kernel.org> (raw)
In-Reply-To: <20220317124958.27921-1-kabel@kernel.org>

From: Marek Behún <marek.behun@nic.cz>

Add helpers ofnode_get_phy_node() and dev_get_phy_node() and use it in
net/mdio-uclass.c function dm_eth_connect_phy_handle().

This is useful because other part's of U-Boot may want to get PHY ofnode
without connecting a PHY.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 drivers/core/ofnode.c | 21 +++++++++++++++++++++
 drivers/core/read.c   |  5 +++++
 include/dm/ofnode.h   | 14 ++++++++++++++
 include/dm/read.h     | 19 +++++++++++++++++++
 net/mdio-uclass.c     | 24 ++++++------------------
 5 files changed, 65 insertions(+), 18 deletions(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 709bea272a..eaad2c989b 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -1162,3 +1162,24 @@ const char *ofnode_conf_read_str(const char *prop_name)
 
 	return ofnode_read_string(node, prop_name);
 }
+
+ofnode ofnode_get_phy_node(ofnode node)
+{
+	/* DT node properties that reference a PHY node */
+	static const char * const phy_handle_str[] = {
+		"phy-handle", "phy", "phy-device",
+	};
+	struct ofnode_phandle_args args = {
+		.node = ofnode_null()
+	};
+	int i;
+
+	assert(ofnode_valid(node));
+
+	for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++)
+		if (!ofnode_parse_phandle_with_args(node, phy_handle_str[i],
+						    NULL, 0, 0, &args))
+			break;
+
+	return args.node;
+}
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 31f9e78a06..7ff100218d 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -398,3 +398,8 @@ int dev_decode_display_timing(const struct udevice *dev, int index,
 {
 	return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
 }
+
+ofnode dev_get_phy_node(const struct udevice *dev)
+{
+	return ofnode_get_phy_node(dev_ofnode(dev));
+}
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 0cb324c8b0..8164386043 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -1204,4 +1204,18 @@ int ofnode_conf_read_int(const char *prop_name, int default_val);
  */
 const char *ofnode_conf_read_str(const char *prop_name);
 
+/**
+ * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
+ *
+ * This function parses PHY handle from the Ethernet controller's ofnode
+ * (trying all possible PHY handle property names), and returns the PHY ofnode.
+ *
+ * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
+ * if the result to that is true, this function should not be called.
+ *
+ * @eth_node:	ofnode belonging to the Ethernet controller
+ * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
+ */
+ofnode ofnode_get_phy_node(ofnode eth_node);
+
 #endif
diff --git a/include/dm/read.h b/include/dm/read.h
index 233af3c063..899eb813fd 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -743,6 +743,20 @@ int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
 int dev_decode_display_timing(const struct udevice *dev, int index,
 			      struct display_timing *config);
 
+/**
+ * dev_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
+ *
+ * This function parses PHY handle from the Ethernet controller's ofnode
+ * (trying all possible PHY handle property names), and returns the PHY ofnode.
+ *
+ * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
+ * if the result to that is true, this function should not be called.
+ *
+ * @dev: device representing the MAC
+ * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
+ */
+ofnode dev_get_phy_node(const struct udevice *dev);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 #include <asm/global_data.h>
 
@@ -1092,6 +1106,11 @@ static inline int dev_decode_display_timing(const struct udevice *dev,
 	return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
 }
 
+static inline ofnode dev_get_phy_node(const struct udevice *dev)
+{
+	return ofnode_get_phy_node(dev_ofnode(dev));
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
index 649dc60f73..233b70171b 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -20,11 +20,6 @@ static const char * const phy_mode_str[] = {
 	"phy-mode", "phy-connection-type"
 };
 
-/* DT node properties that reference a PHY node */
-static const char * const phy_handle_str[] = {
-	"phy-handle", "phy", "phy-device"
-};
-
 void dm_mdio_probe_devices(void)
 {
 	struct udevice *it;
@@ -137,23 +132,16 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
 	u32 phy_addr;
 	struct udevice *mdiodev;
 	struct phy_device *phy;
-	struct ofnode_phandle_args phandle = {.node = ofnode_null()};
 	ofnode phynode;
-	int i;
 
 	if (CONFIG_IS_ENABLED(PHY_FIXED) &&
 	    ofnode_phy_is_fixed_link(dev_ofnode(ethdev), &phynode)) {
 		phy = phy_connect(NULL, 0, ethdev, interface);
-		phandle.node = phynode;
 		goto out;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++)
-		if (!dev_read_phandle_with_args(ethdev, phy_handle_str[i], NULL,
-						0, 0, &phandle))
-			break;
-
-	if (!ofnode_valid(phandle.node)) {
+	phynode = dev_get_phy_node(ethdev);
+	if (!ofnode_valid(phynode)) {
 		dev_dbg(ethdev, "can't find PHY node\n");
 		return NULL;
 	}
@@ -162,16 +150,16 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
 	 * reading 'reg' directly should be fine.  This is a PHY node, the
 	 * address is always size 1 and requires no translation
 	 */
-	if (ofnode_read_u32(phandle.node, "reg", &phy_addr)) {
+	if (ofnode_read_u32(phynode, "reg", &phy_addr)) {
 		dev_dbg(ethdev, "missing reg property in phy node\n");
 		return NULL;
 	}
 
 	if (uclass_get_device_by_ofnode(UCLASS_MDIO,
-					ofnode_get_parent(phandle.node),
+					ofnode_get_parent(phynode),
 					&mdiodev)) {
 		dev_dbg(ethdev, "can't find MDIO bus for node %s\n",
-			ofnode_get_name(ofnode_get_parent(phandle.node)));
+			ofnode_get_name(ofnode_get_parent(phynode)));
 		return NULL;
 	}
 
@@ -179,7 +167,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
 
 out:
 	if (phy)
-		phy->node = phandle.node;
+		phy->node = phynode;
 
 	return phy;
 }
-- 
2.34.1


  parent reply	other threads:[~2022-03-17 12:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 12:49 [PATCH u-boot-net 00/14] u-boot-net refactors, fixes, cleanups Marek Behún
2022-03-17 12:49 ` [PATCH u-boot-net 01/14] net: mdio-uclass: fix type for phy_mode_str and phy_handle_str Marek Behún
2022-03-18  7:54   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 02/14] net: mdio-uclass: use ARRAY_SIZE() Marek Behún
2022-03-18  7:55   ` Ramon Fried
2022-03-17 12:49 ` Marek Behún [this message]
2022-03-18  8:02   ` [PATCH u-boot-net 03/14] net: introduce helpers to get PHY ofnode from MAC Ramon Fried
2022-03-28  6:35   ` Simon Glass
2022-03-28 21:51     ` Marek Behún
2022-03-17 12:49 ` [PATCH u-boot-net 04/14] net: mdio-uclass: add wrappers for read/write/reset operations Marek Behún
2022-03-18  8:00   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 05/14] treewide: use dm_mdio_read/write/reset() wrappers Marek Behún
2022-03-18  8:04   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 06/14] net: phy: fix parsing wrong property Marek Behún
2022-03-18  8:05   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 07/14] net: introduce helpers to get PHY interface mode from a device/ofnode Marek Behún
2022-03-18  8:07   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 08/14] treewide: Rename PHY_INTERFACE_MODE_COUNT to PHY_INTERFACE_MODE_MAX Marek Behún
2022-03-18  7:34   ` Stefan Roese
2022-03-17 12:49 ` [PATCH u-boot-net 09/14] treewide: Rename PHY_INTERFACE_MODE_NONE to PHY_INTERFACE_MODE_NA Marek Behún
2022-03-18  7:34   ` Stefan Roese
2022-03-18  8:07   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 10/14] phy: Move PHY_INTERFACE_MODE_NA to the beginning of the enum definition Marek Behún
2022-03-18  7:34   ` Stefan Roese
2022-03-18  8:08   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 11/14] net: phy: xilinx: Check interface type in ->config(), not ->probe() Marek Behún
2022-03-18  8:09   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 12/14] net: phy: use ->is_c45 instead of is_10g_interface() Marek Behún
2022-03-18  8:10   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 13/14] bcmgenet, sun8i_emac: Don't connect PHY two times Marek Behún
2022-03-18  8:10   ` Ramon Fried
2022-03-17 12:49 ` [PATCH u-boot-net 14/14] net: phy: don't require PHY interface mode during PHY creation Marek Behún
2022-03-18  8:12   ` Ramon Fried
2022-03-18  8:13 ` [PATCH u-boot-net 00/14] u-boot-net refactors, fixes, cleanups Ramon Fried

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=20220317124958.27921-4-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=bmeng.cn@gmail.com \
    --cc=chenguanqiao@kuaishou.com \
    --cc=dariobin@libero.it \
    --cc=jagan@amarulasolutions.com \
    --cc=joe.hershberger@ni.com \
    --cc=kishon@ti.com \
    --cc=lokeshvutla@ti.com \
    --cc=marek.behun@nic.cz \
    --cc=michael@walle.cc \
    --cc=miquel.raynal@bootlin.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=priyanka.jain@nxp.com \
    --cc=rfried.dev@gmail.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=vladimir.oltean@nxp.com \
    --cc=ycliang@andestech.com \
    /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