diff options
Diffstat (limited to 'drivers/core/ofnode.c')
-rw-r--r-- | drivers/core/ofnode.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8042847f3c1..a59832ebbfb 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1198,3 +1198,47 @@ 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; +} + +phy_interface_t ofnode_read_phy_mode(ofnode node) +{ + const char *mode; + int i; + + assert(ofnode_valid(node)); + + mode = ofnode_read_string(node, "phy-mode"); + if (!mode) + mode = ofnode_read_string(node, "phy-connection-type"); + + if (!mode) + return PHY_INTERFACE_MODE_NA; + + for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) + if (!strcmp(mode, phy_interface_strings[i])) + return i; + + debug("%s: Invalid PHY interface '%s'\n", __func__, mode); + + return PHY_INTERFACE_MODE_NA; +} |