Add a generic_phy_get_*() variant that allows the caller to resolve non-standard attributes like fsl,usbphy.
Signed-off-by: Nora Schiffer <[email protected]> --- drivers/phy/phy-uclass.c | 35 +++++++++++++++++++++++------------ include/generic-phy.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index 6ba4cc593df..51256b30247 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -137,25 +137,14 @@ static int generic_phy_xlate_offs_flags(struct phy *phy, return 0; } -int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy) +int generic_phy_get_by_phandle_args(struct ofnode_phandle_args args, struct phy *phy) { - struct ofnode_phandle_args args; struct phy_ops *ops; struct udevice *phydev, *supply = NULL; int i, ret; - debug("%s(node=%s, index=%d, phy=%p)\n", - __func__, ofnode_get_name(node), index, phy); - assert(phy); phy->dev = NULL; - ret = ofnode_parse_phandle_with_args(node, "phys", "#phy-cells", 0, - index, &args); - if (ret) { - debug("%s: dev_read_phandle_with_args failed: err=%d\n", - __func__, ret); - return ret; - } ret = uclass_get_device_by_ofnode(UCLASS_PHY, args.node, &phydev); if (ret) { @@ -213,6 +202,28 @@ err: return ret; } +int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy) +{ + struct ofnode_phandle_args args; + int ret; + + debug("%s(node=%s, index=%d, phy=%p)\n", + __func__, ofnode_get_name(node), index, phy); + + assert(phy); + phy->dev = NULL; + + ret = ofnode_parse_phandle_with_args(node, "phys", "#phy-cells", 0, + index, &args); + if (ret) { + debug("%s: dev_read_phandle_with_args failed: err=%d\n", + __func__, ret); + return ret; + } + + return generic_phy_get_by_phandle_args(args, phy); +} + int generic_phy_get_by_index(struct udevice *dev, int index, struct phy *phy) { diff --git a/include/generic-phy.h b/include/generic-phy.h index 567dd3974ad..2dbb120a188 100644 --- a/include/generic-phy.h +++ b/include/generic-phy.h @@ -360,6 +360,35 @@ int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy); int generic_phy_get_by_name(struct udevice *user, const char *phy_name, struct phy *phy); +/** + * generic_phy_get_by_phandle_args() - Get a PHY device by phandle arguments + * without a device + * + * @args: The resolved phandle arguments + * @phy: A pointer to the PHY port + * + * This is a version of generic_phy_get_by_*() that allows the caller to resolve + * a phandle itself, for example to handle non-standard property names. + * + * example: + * usb1: usb_otg_ss@xxx { + * compatible = "xxx"; + * reg = <xxx>; + * . + * . + * fsl,usbphy = <&usbphy>; + * . + * . + * }; + * Here, the PHY is referenced using a vendor-specific property + * rather than using the generic 'phys', so it must be resolved using + * ofnode_parse_phandle_with_args() and then passed to + * generic_phy_get_by_phandle_args(). + * + * Return: 0 if OK, or a negative error code + */ +int generic_phy_get_by_phandle_args(struct ofnode_phandle_args args, struct phy *phy); + /** * generic_phy_get_bulk - Get all phys of a device. * -- 2.55.0
