diff options
author | Patrice Chotard <patrice.chotard@st.com> | 2018-03-14 17:48:57 +0100 |
---|---|---|
committer | Marek Vasut <marex@denx.de> | 2018-03-17 03:20:53 +0100 |
commit | cab4d48a939537ab10e00429fc774825b743ed10 (patch) | |
tree | c25946e78b0cea21baa09fc8e14e7458d56714e5 /drivers/usb/host | |
parent | 633e1ec6bf7131d3c8fecbb4adcc96e17925a015 (diff) |
usb: ohci-generic: factorize PHY operation
Factorize PHY get/init/poweron and PHY poweroff/exit operations
into separate function, it simplify the error path.
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r-- | drivers/usb/host/ohci-generic.c | 99 |
1 files changed, 59 insertions, 40 deletions
diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c index 4843b4ac85..590fe4ca74 100644 --- a/drivers/usb/host/ohci-generic.c +++ b/drivers/usb/host/ohci-generic.c @@ -25,6 +25,56 @@ struct generic_ohci { int reset_count; /* number of reset in reset list */ }; +static int ohci_setup_phy(struct udevice *dev, int index) +{ + struct generic_ohci *priv = dev_get_priv(dev); + int ret; + + ret = generic_phy_get_by_index(dev, index, &priv->phy); + if (ret) { + if (ret != -ENOENT) { + dev_err(dev, "failed to get usb phy\n"); + return ret; + } + } else { + ret = generic_phy_init(&priv->phy); + if (ret) { + dev_err(dev, "failed to init usb phy\n"); + return ret; + } + + ret = generic_phy_power_on(&priv->phy); + if (ret) { + dev_err(dev, "failed to power on usb phy\n"); + return generic_phy_exit(&priv->phy); + } + } + + return 0; +} + +static int ohci_shutdown_phy(struct udevice *dev) +{ + struct generic_ohci *priv = dev_get_priv(dev); + int ret = 0; + + if (generic_phy_valid(&priv->phy)) { + ret = generic_phy_power_off(&priv->phy); + if (ret) { + dev_err(dev, "failed to power off usb phy\n"); + return ret; + } + + ret = generic_phy_exit(&priv->phy); + if (ret) { + dev_err(dev, "failed to power off usb phy\n"); + return ret; + } + } + + return 0; +} + static int ohci_usb_probe(struct udevice *dev) { struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev); @@ -85,26 +135,10 @@ static int ohci_usb_probe(struct udevice *dev) goto clk_err; } - err = generic_phy_get_by_index(dev, 0, &priv->phy); - if (err) { - if (err != -ENOENT) { - pr_err("failed to get usb phy\n"); - goto reset_err; - } - } else { - - err = generic_phy_init(&priv->phy); - if (err) { - pr_err("failed to init usb phy\n"); - goto reset_err; - } + err = ohci_setup_phy(dev, 0); + if (err) - err = generic_phy_power_on(&priv->phy); - if (err) { - dev_err(dev, "failed to power on usb phy\n"); - goto phy_power_err; - } - } + goto reset_err; err = ohci_register(dev, regs); if (err) @@ -113,18 +147,9 @@ static int ohci_usb_probe(struct udevice *dev) return 0; phy_err: - if (generic_phy_valid(&priv->phy)) { - ret = generic_phy_power_off(&priv->phy); - if (ret) - dev_err(dev, "failed to power off usb phy\n"); - } - -phy_power_err: - if (generic_phy_valid(&priv->phy)) { - ret = generic_phy_exit(&priv->phy); - if (ret) - pr_err("failed to release phy\n"); - } + ret = ohci_shutdown_phy(dev); + if (ret) + dev_err(dev, "failed to shutdown usb phy\n"); reset_err: ret = reset_release_all(priv->resets, priv->reset_count); @@ -147,15 +172,9 @@ static int ohci_usb_remove(struct udevice *dev) if (ret) return ret; - if (generic_phy_valid(&priv->phy)) { - ret = generic_phy_power_off(&priv->phy); - if (ret) - return ret; - - ret = generic_phy_exit(&priv->phy); - if (ret) - return ret; - } + ret = ohci_shutdown_phy(dev); + if (ret) + return ret; ret = reset_release_all(priv->resets, priv->reset_count); if (ret) |