diff options
author | Marek BehĂșn <marek.behun@nic.cz> | 2022-04-07 01:32:57 +0300 |
---|---|---|
committer | Ramon Fried <ramon@neureality.ai> | 2022-04-10 08:44:12 +0300 |
commit | f3dd213e151ece2a382e730f5e75156536b2419d (patch) | |
tree | 1a88d8bbb2a4a09f78f986d2097ae333d10a3ac7 /drivers/core | |
parent | a7a96ef812976d9fa73376fa44686a1ee4af16ee (diff) | |
download | u-boot-f3dd213e151ece2a382e730f5e75156536b2419d.tar.xz |
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>
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/ofnode.c | 21 | ||||
-rw-r--r-- | drivers/core/read.c | 5 |
2 files changed, 26 insertions, 0 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8042847f3c..445b7ad5ad 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1198,3 +1198,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)); +} |