diff options
author | Michal Simek <michal.simek@xilinx.com> | 2022-02-23 17:45:40 +0300 |
---|---|---|
committer | Michal Simek <michal.simek@xilinx.com> | 2022-03-09 14:43:16 +0300 |
commit | db681d4929cac3f5d0a8ce638e7e5306fe6038d2 (patch) | |
tree | 099f3103642de45f71a4098bdbadfbafbc5ee696 /drivers/core | |
parent | d24b3e32ab7f89c0b411747203d7f103f475cfbf (diff) | |
download | u-boot-db681d4929cac3f5d0a8ce638e7e5306fe6038d2.tar.xz |
net: phy: Add new read ethernet phy id function
Add new function to get ethernet phy id from compatible property
of the mdio phy node.
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Link: https://lore.kernel.org/r/16019efb3820a50330935fdaae191cec1f101b5c.1645627539.git.michal.simek@xilinx.com
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/ofnode.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 709bea272a..8042847f3c 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -898,6 +898,42 @@ int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device) return -ENOENT; } +int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device) +{ + const char *list, *end; + int len; + + list = ofnode_get_property(node, "compatible", &len); + + if (!list) + return -ENOENT; + + end = list + len; + while (list < end) { + len = strlen(list); + + if (len >= strlen("ethernet-phy-idVVVV,DDDD")) { + char *s = strstr(list, "ethernet-phy-id"); + + /* + * check if the string is something like + * ethernet-phy-idVVVV,DDDD + */ + if (s && s[19] == '.') { + s += strlen("ethernet-phy-id"); + *vendor = simple_strtol(s, NULL, 16); + s += 5; + *device = simple_strtol(s, NULL, 16); + + return 0; + } + } + list += (len + 1); + } + + return -ENOENT; +} + int ofnode_read_addr_cells(ofnode node) { if (ofnode_is_np(node)) { |