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;
+}