[U-Boot] [PATCH] usb: ehci-generic: Add vbus-supply regulator support

Patrice Chotard patrice.chotard at st.com
Wed Aug 8 14:10:16 UTC 2018


Add vbus-supply regulator support.
On some board vbus is not controlled by the phy but by
an external regulator.

Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
---

 drivers/usb/host/ehci-generic.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
index 5a56f66cfaa6..c4f34c85f798 100644
--- a/drivers/usb/host/ehci-generic.c
+++ b/drivers/usb/host/ehci-generic.c
@@ -11,6 +11,7 @@
 #include <asm/io.h>
 #include <dm.h>
 #include "ehci.h"
+#include <power/regulator.h>
 
 /*
  * Even though here we don't explicitly use "struct ehci_ctrl"
@@ -22,6 +23,9 @@ struct generic_ehci {
 	struct clk *clocks;
 	struct reset_ctl *resets;
 	struct phy phy;
+#ifdef CONFIG_DM_REGULATOR
+	struct udevice *vbus_supply;
+#endif
 	int clock_count;
 	int reset_count;
 };
@@ -145,9 +149,24 @@ static int ehci_usb_probe(struct udevice *dev)
 		}
 	}
 
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
+
+	if (priv->vbus_supply) {
+		err = regulator_set_enable(priv->vbus_supply, true);
+		if (err) {
+			pr_err("Error enabling VBUS supply\n");
+			goto reset_err;
+		}
+	} else {
+		debug("%s: No vbus supply\n", dev->name);
+	}
+#endif
+
 	err = ehci_setup_phy(dev, 0);
 	if (err)
-		goto reset_err;
+		goto regulator_err;
 
 	hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE);
 	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
@@ -164,6 +183,15 @@ phy_err:
 	if (ret)
 		dev_err(dev, "failed to shutdown usb phy\n");
 
+regulator_err:
+#ifdef CONFIG_DM_REGULATOR
+	if (priv->vbus_supply) {
+		ret = regulator_set_enable(priv->vbus_supply, false);
+		if (ret)
+			pr_err("Error disabling VBUS supply\n");
+	}
+#endif
+
 reset_err:
 	ret = reset_release_all(priv->resets, priv->reset_count);
 	if (ret)
@@ -189,6 +217,13 @@ static int ehci_usb_remove(struct udevice *dev)
 	if (ret)
 		return ret;
 
+#ifdef CONFIG_DM_REGULATOR
+	if (priv->vbus_supply) {
+		ret = regulator_set_enable(priv->vbus_supply, false);
+		if (ret)
+			return ret;
+	}
+#endif
 	ret =  reset_release_all(priv->resets, priv->reset_count);
 	if (ret)
 		return ret;
-- 
1.9.1



More information about the U-Boot mailing list