diff options
author | Patrice Chotard | 2022-09-06 08:15:26 +0200 |
---|---|---|
committer | Marek Vasut | 2022-10-10 18:08:18 +0200 |
commit | 84e561407a5f62a8746dcf8f920e4682690435a0 (patch) | |
tree | f09f2e8d1ea772812c45b7c0bbba336342b1dcc8 /drivers/phy/phy-uclass.c | |
parent | 7cc1af902dfad290ab39b0ee52128b18d83a151a (diff) |
phy: Add generic_{setup,shutdown}_phy() helpers
In drivers usb/host/{ehci,ohci}-generic.c, {ehci,ohci}_setup_phy() and
{ehci,ohci}_shutdown_phy() shares 95% of common code.
Factorize this code in new generic_{setup,shudown}_phy() functions.
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/phy/phy-uclass.c')
-rw-r--r-- | drivers/phy/phy-uclass.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index 8b84da3ce0d..3fef5135a9c 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -455,6 +455,48 @@ int generic_phy_power_off_bulk(struct phy_bulk *bulk) return ret; } +int generic_setup_phy(struct udevice *dev, struct phy *phy, int index) +{ + int ret = 0; + + if (!phy) + return 0; + + ret = generic_phy_get_by_index(dev, index, phy); + if (ret) { + if (ret != -ENOENT) + return ret; + } else { + ret = generic_phy_init(phy); + if (ret) + return ret; + + ret = generic_phy_power_on(phy); + if (ret) + ret = generic_phy_exit(phy); + } + + return ret; +} + +int generic_shutdown_phy(struct phy *phy) +{ + int ret = 0; + + if (!phy) + return 0; + + if (generic_phy_valid(phy)) { + ret = generic_phy_power_off(phy); + if (ret) + return ret; + + ret = generic_phy_exit(phy); + } + + return ret; +} + UCLASS_DRIVER(phy) = { .id = UCLASS_PHY, .name = "phy", |