summaryrefslogtreecommitdiff
path: root/drivers/usb/host/ehci-generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/ehci-generic.c')
-rw-r--r--drivers/usb/host/ehci-generic.c98
1 files changed, 68 insertions, 30 deletions
diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
index 1cb92c0338..b012d8651f 100644
--- a/drivers/usb/host/ehci-generic.c
+++ b/drivers/usb/host/ehci-generic.c
@@ -27,6 +27,56 @@ struct generic_ehci {
int reset_count;
};
+static int ehci_setup_phy(struct udevice *dev, int index)
+{
+ struct generic_ehci *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 ehci_shutdown_phy(struct udevice *dev)
+{
+ struct generic_ehci *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 ehci_usb_probe(struct udevice *dev)
{
struct generic_ehci *priv = dev_get_priv(dev);
@@ -51,7 +101,7 @@ static int ehci_usb_probe(struct udevice *dev)
break;
err = clk_enable(&priv->clocks[i]);
if (err) {
- pr_err("failed to enable clock %d\n", i);
+ dev_err(dev, "failed to enable clock %d\n", i);
clk_free(&priv->clocks[i]);
goto clk_err;
}
@@ -59,7 +109,8 @@ static int ehci_usb_probe(struct udevice *dev)
}
} else {
if (clock_nb != -ENOENT) {
- pr_err("failed to get clock phandle(%d)\n", clock_nb);
+ dev_err(dev, "failed to get clock phandle(%d)\n",
+ clock_nb);
return clock_nb;
}
}
@@ -80,7 +131,8 @@ static int ehci_usb_probe(struct udevice *dev)
break;
if (reset_deassert(&priv->resets[i])) {
- pr_err("failed to deassert reset %d\n", i);
+ dev_err(dev, "failed to deassert reset %d\n",
+ i);
reset_free(&priv->resets[i]);
goto reset_err;
}
@@ -88,25 +140,15 @@ static int ehci_usb_probe(struct udevice *dev)
}
} else {
if (reset_nb != -ENOENT) {
- pr_err("failed to get reset phandle(%d)\n", reset_nb);
+ dev_err(dev, "failed to get reset phandle(%d)\n",
+ reset_nb);
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 = ehci_setup_phy(dev, 0);
+ if (err)
+ goto reset_err;
hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE);
hcor = (struct ehci_hcor *)((uintptr_t)hccr +
@@ -119,20 +161,18 @@ static int ehci_usb_probe(struct udevice *dev)
return 0;
phy_err:
- if (generic_phy_valid(&priv->phy)) {
- ret = generic_phy_exit(&priv->phy);
- if (ret)
- pr_err("failed to release phy\n");
- }
+ ret = ehci_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);
if (ret)
- pr_err("failed to assert all resets\n");
+ dev_err(dev, "failed to assert all resets\n");
clk_err:
ret = clk_release_all(priv->clocks, priv->clock_count);
if (ret)
- pr_err("failed to disable all clocks\n");
+ dev_err(dev, "failed to disable all clocks\n");
return err;
}
@@ -146,11 +186,9 @@ static int ehci_usb_remove(struct udevice *dev)
if (ret)
return ret;
- if (generic_phy_valid(&priv->phy)) {
- ret = generic_phy_exit(&priv->phy);
- if (ret)
- return ret;
- }
+ ret = ehci_shutdown_phy(dev);
+ if (ret)
+ return ret;
ret = reset_release_all(priv->resets, priv->reset_count);
if (ret)