net: introduce helpers to get PHY ofnode from MAC
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(). Also add
corresponding UT test.
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>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 8042847..445b7ad 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -1198,3 +1198,24 @@
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 31f9e78..7ff1002 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -398,3 +398,8 @@
{
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));
+}