Skip to contentSkip to conversation

usb: dwc2: add support for external vbus supply

PATCH Superseded Simon Glass 3 participants 6 messages Dec 3, 2016 – Mar 7, 2017 USB

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 usb: dwc2: add support for external vbus supply

From: Kever Yang <[email protected]>

Some board do not use the dwc2 internal VBUS_DRV signal, but use a gpio pin to enable the 5.0V VBUS power, add interface to enable the power in dwc2 driver.

---

Changes in v3:
- Drop use of static variable

 drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
drivers/usb/host/dwc2.c +34 -5
index d08879d..fa11364 100644
@@ -15,6 +15,7 @@
 #include <usbroothubdes.h>
 #include <wait_bit.h>
 #include <asm/io.h>
+#include <power/regulator.h>
 
 #include "dwc2.h"
 
@@ -159,6 +160,28 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
 	mdelay(100);
 }
 
+static int dwc_vbus_supply_init(struct udevice *dev)
+{
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR) && \
+	!defined(CONFIG_SPL_BUILD)
+	struct udevice *vbus_supply;
+	int ret;
+
+	ret = device_get_supply_regulator(dev, "vbus-supply", &vbus_supply);
+	if (ret) {
+		debug("%s: No vbus supply\n", dev->name);
+		return 0;
+	}
+
+	ret = regulator_set_enable(vbus_supply, true);
+	if (ret) {
+		error("Error enabling vbus supply\n");
+		return ret;
+	}
+#endif
+	return 0;
+}
+
 /*
  * This function initializes the DWC_otg controller registers for
  * host mode.
@@ -167,10 +190,12 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
  * request queues. Host channels are reset to ensure that they are ready for
  * performing transfers.
  *
+ * @param dev USB Device (NULL if driver model is not being used)
  * @param regs Programming view of DWC_otg controller
  *
  */
-static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
+static void dwc_otg_core_host_init(struct udevice *dev,
+				   struct dwc2_core_regs *regs)
 {
 	uint32_t nptxfifosize = 0;
 	uint32_t ptxfifosize = 0;
@@ -248,6 +273,9 @@ static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
 			writel(hprt0, &regs->hprt0);
 		}
 	}
+
+	if (dev)
+		dwc_vbus_supply_init(dev);
 }
 
 /*
@@ -1048,7 +1076,7 @@ int _submit_int_msg(struct dwc2_priv *priv, struct usb_device *dev,
 	}
 }
 
-static int dwc2_init_common(struct dwc2_priv *priv)
+static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 {
 	struct dwc2_core_regs *regs = priv->regs;
 	uint32_t snpsid;
@@ -1070,7 +1098,7 @@ static int dwc2_init_common(struct dwc2_priv *priv)
 #endif
 
 	dwc_otg_core_init(priv);
-	dwc_otg_core_host_init(regs);
+	dwc_otg_core_host_init(dev, regs);
 
 	clrsetbits_le32(&regs->hprt0, DWC2_HPRT0_PRTENA |
 			DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
@@ -1143,7 +1171,7 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
 	if (board_usb_init(index, USB_INIT_HOST))
 		return -1;
 
-	return dwc2_init_common(priv);
+	return dwc2_init_common(NULL, priv);
 }
 
 int usb_lowlevel_stop(int index)
@@ -1194,6 +1222,7 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev)
 	const void *prop;
 	fdt_addr_t addr;
 
+	g_dwc2_udev = dev;
 	addr = dev_get_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
@@ -1214,7 +1243,7 @@ static int dwc2_usb_probe(struct udevice *dev)
 
 	bus_priv->desc_before_addr = true;
 
-	return dwc2_init_common(priv);
+	return dwc2_init_common(dev, priv);
 }
 
 static int dwc2_usb_remove(struct udevice *dev)
Signature · 1 line
2.8.0.rc3.226.g39d4020
#1 lore raw

PATCH v3 1/1 usb: dwc2: add support for external vbus supply

Quoted 109 lines · Simon Glass

From: Kever Yang <[email protected]>

Some board do not use the dwc2 internal VBUS_DRV signal, but use a gpio pin to enable the 5.0V VBUS power, add interface to enable the power in dwc2 driver.

---

Changes in v3:
- Drop use of static variable

 drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
drivers/usb/host/dwc2.c +32 -4
index d08879d..fa11364 100644
@@ -15,6 +15,7 @@
 #include <usbroothubdes.h>
 #include <wait_bit.h>
 #include <asm/io.h>
+#include <power/regulator.h>
 
 #include "dwc2.h"
 
@@ -159,6 +160,28 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
 	mdelay(100);
 }
 
+static int dwc_vbus_supply_init(struct udevice *dev)
+{
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR) && \
+	!defined(CONFIG_SPL_BUILD)
+	struct udevice *vbus_supply;
+	int ret;
+
+	ret = device_get_supply_regulator(dev, "vbus-supply", &vbus_supply);
+	if (ret) {
+		debug("%s: No vbus supply\n", dev->name);
+		return 0;
+	}
+
+	ret = regulator_set_enable(vbus_supply, true);
+	if (ret) {
+		error("Error enabling vbus supply\n");
+		return ret;
+	}
+#endif
+	return 0;
+}
+
 /*
  * This function initializes the DWC_otg controller registers for
  * host mode.
@@ -167,10 +190,12 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
  * request queues. Host channels are reset to ensure that they are ready for
  * performing transfers.
  *
+ * @param dev USB Device (NULL if driver model is not being used)
  * @param regs Programming view of DWC_otg controller
  *
  */
-static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
+static void dwc_otg_core_host_init(struct udevice *dev,
+				   struct dwc2_core_regs *regs)
 {
 	uint32_t nptxfifosize = 0;
 	uint32_t ptxfifosize = 0;
@@ -248,6 +273,9 @@ static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
 			writel(hprt0, &regs->hprt0);
 		}
 	}
+
+	if (dev)
+		dwc_vbus_supply_init(dev);
 }
 
 /*
@@ -1048,7 +1076,7 @@ int _submit_int_msg(struct dwc2_priv *priv, struct usb_device *dev,
 	}
 }
 
-static int dwc2_init_common(struct dwc2_priv *priv)
+static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)
 {
 	struct dwc2_core_regs *regs = priv->regs;
 	uint32_t snpsid;
@@ -1070,7 +1098,7 @@ static int dwc2_init_common(struct dwc2_priv *priv)
 #endif
 
 	dwc_otg_core_init(priv);
-	dwc_otg_core_host_init(regs);
+	dwc_otg_core_host_init(dev, regs);
 
 	clrsetbits_le32(&regs->hprt0, DWC2_HPRT0_PRTENA |
 			DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
@@ -1143,7 +1171,7 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
 	if (board_usb_init(index, USB_INIT_HOST))
 		return -1;
 
-	return dwc2_init_common(priv);
+	return dwc2_init_common(NULL, priv);
 }
 
 int usb_lowlevel_stop(int index)

drivers/usb/host/dwc2.c static int dwc2_usb_ofdata_to_platdata(struct udevice *dev) · line 1225

Quoted 4 lines
drivers/usb/host/dwc2.c +1 -0
@@ -1194,6 +1222,7 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev)
 	const void *prop;
 	fdt_addr_t addr;
 
+	g_dwc2_udev = dev;

Needed ? :-)

Quoted 13 lines
drivers/usb/host/dwc2.c +1 -1
 	addr = dev_get_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
@@ -1214,7 +1243,7 @@ static int dwc2_usb_probe(struct udevice *dev)
 
 	bus_priv->desc_before_addr = true;
 
-	return dwc2_init_common(priv);
+	return dwc2_init_common(dev, priv);
 }
 
 static int dwc2_usb_remove(struct udevice *dev)
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH v3 1/1 usb: dwc2: add support for external vbus supply

Hi Marek, Kever,

Quoted 11 lines · Marek Vasut
Quoted 10 lines · Simon Glass

From: Kever Yang <[email protected]>

Some board do not use the dwc2 internal VBUS_DRV signal, but use a gpio pin to enable the 5.0V VBUS power, add interface to enable the power in dwc2 driver.

---

Quoted 5 lines
Quoted 5 lines

Changes in v3:
- Drop use of static variable

 drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

Just to be clear, I will not be taking this patch. I will await Kever's new version based on my ideas in this patch and Marek's comments.

This patch was just to help explain how to drop the static variable, since that seemed to be a point of confusion.

Regards,
Simon

#3 lore raw

PATCH v3 1/1 usb: dwc2: add support for external vbus supply

Quoted 20 lines · Simon Glass

Hi Marek, Kever,

Quoted 11 lines · Marek Vasut
Quoted 10 lines · Simon Glass

From: Kever Yang <[email protected]>

Some board do not use the dwc2 internal VBUS_DRV signal, but use a gpio pin to enable the 5.0V VBUS power, add interface to enable the power in dwc2 driver.

---

Quoted 5 lines
Quoted 5 lines

Changes in v3:
- Drop use of static variable

 drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
Quoted 6 lines

Just to be clear, I will not be taking this patch. I will await Kever's new version based on my ideas in this patch and Marek's comments.

This patch was just to help explain how to drop the static variable, since that seemed to be a point of confusion.

Thanks for the V3 example though, that's real helpful.

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

PATCH v3 1/1 usb: dwc2: add support for external vbus supply

In reply to Simon Glass

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Marek, Kever,

Quoted 14 lines · Marek Vasut
Quoted 13 lines · Simon Glass

From: Kever Yang <[email protected]>

Some board do not use the dwc2 internal VBUS_DRV signal, but use a gpio pin to enable the 5.0V VBUS power, add interface to enable the power in dwc2 driver.

---

Changes in v3:
- Drop use of static variable

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
  drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
  1 file changed, 34 insertions(+), 5 deletions(-)

Just to be clear, I will not be taking this patch. I will await Kever's new version based on my ideas in this patch and Marek's comments.

This patch was just to help explain how to drop the static variable, since that seemed to be a point of confusion.

Thanks very much for your example, and really sorry for missing this patch, I will send a new version later.

Thanks,
- Kever

Quoted 6 lines

Regards,
Simon

#5 lore raw

PATCH v3 1/1 usb: dwc2: add support for external vbus supply

Quoted 26 lines · Kever Yang

Hi Simon,

Quoted 23 lines · Simon Glass

Hi Marek, Kever,

Quoted 11 lines · Marek Vasut
Quoted 10 lines · Simon Glass

From: Kever Yang <[email protected]>

Some board do not use the dwc2 internal VBUS_DRV signal, but use a gpio pin to enable the 5.0V VBUS power, add interface to enable the power in dwc2 driver.

---

Quoted 5 lines
Quoted 5 lines

Changes in v3:
- Drop use of static variable

  drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
  1 file changed, 34 insertions(+), 5 deletions(-)

Just to be clear, I will not be taking this patch. I will await Kever's new version based on my ideas in this patch and Marek's comments.

Quoted 5 lines
Quoted 2 lines

This patch was just to help explain how to drop the static variable, since that seemed to be a point of confusion.

Thanks very much for your example, and really sorry for missing this patch, I will send a new version later.

FYI, I'll deal with the USB patches once I'm back from the US, which is later this week.