* [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply
@ 2016-12-03 4:29 Simon Glass
2016-12-03 13:15 ` Marek Vasut
0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2016-12-03 4:29 UTC (permalink / raw)
To: u-boot
From: Kever Yang <kever.yang@rock-chips.com>
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.
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3:
- Drop use of static variable
drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index d08879d..fa11364 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -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, ®s->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(®s->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)
--
2.8.0.rc3.226.g39d4020
^ permalink raw reply related [flat|nested] 6+ messages in thread* [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply
2016-12-03 4:29 [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply Simon Glass
@ 2016-12-03 13:15 ` Marek Vasut
2016-12-03 18:27 ` Simon Glass
0 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2016-12-03 13:15 UTC (permalink / raw)
To: u-boot
On 12/03/2016 05:29 AM, Simon Glass wrote:
> From: Kever Yang <kever.yang@rock-chips.com>
>
> 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.
>
> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3:
> - Drop use of static variable
>
> drivers/usb/host/dwc2.c | 39 ++++++++++++++++++++++++++++++++++-----
> 1 file changed, 34 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
> index d08879d..fa11364 100644
> --- a/drivers/usb/host/dwc2.c
> +++ b/drivers/usb/host/dwc2.c
> @@ -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, ®s->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(®s->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;
Needed ? :-)
> 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)
>
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 6+ messages in thread* [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply
2016-12-03 13:15 ` Marek Vasut
@ 2016-12-03 18:27 ` Simon Glass
2016-12-03 18:48 ` Marek Vasut
2017-03-06 12:36 ` Kever Yang
0 siblings, 2 replies; 6+ messages in thread
From: Simon Glass @ 2016-12-03 18:27 UTC (permalink / raw)
To: u-boot
Hi Marek, Kever,
On 3 December 2016 at 06:15, Marek Vasut <marex@denx.de> wrote:
> On 12/03/2016 05:29 AM, Simon Glass wrote:
>> From: Kever Yang <kever.yang@rock-chips.com>
>>
>> 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.
>>
>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply
2016-12-03 18:27 ` Simon Glass
@ 2016-12-03 18:48 ` Marek Vasut
2017-03-06 12:36 ` Kever Yang
1 sibling, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2016-12-03 18:48 UTC (permalink / raw)
To: u-boot
On 12/03/2016 07:27 PM, Simon Glass wrote:
> Hi Marek, Kever,
>
> On 3 December 2016 at 06:15, Marek Vasut <marex@denx.de> wrote:
>> On 12/03/2016 05:29 AM, Simon Glass wrote:
>>> From: Kever Yang <kever.yang@rock-chips.com>
>>>
>>> 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.
>>>
>>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>> 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.
Thanks for the V3 example though, that's real helpful.
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply
2016-12-03 18:27 ` Simon Glass
2016-12-03 18:48 ` Marek Vasut
@ 2017-03-06 12:36 ` Kever Yang
2017-03-07 2:53 ` Marek Vasut
1 sibling, 1 reply; 6+ messages in thread
From: Kever Yang @ 2017-03-06 12:36 UTC (permalink / raw)
To: u-boot
Hi Simon,
On 12/04/2016 02:27 AM, Simon Glass wrote:
> Hi Marek, Kever,
>
> On 3 December 2016 at 06:15, Marek Vasut <marex@denx.de> wrote:
>> On 12/03/2016 05:29 AM, Simon Glass wrote:
>>> From: Kever Yang <kever.yang@rock-chips.com>
>>>
>>> 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.
>>>
>>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>> 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.
Thanks very much for your example, and really sorry for missing this patch,
I will send a new version later.
Thanks,
- Kever
>
> Regards,
> Simon
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply
2017-03-06 12:36 ` Kever Yang
@ 2017-03-07 2:53 ` Marek Vasut
0 siblings, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2017-03-07 2:53 UTC (permalink / raw)
To: u-boot
On 03/06/2017 01:36 PM, Kever Yang wrote:
> Hi Simon,
>
> On 12/04/2016 02:27 AM, Simon Glass wrote:
>> Hi Marek, Kever,
>>
>> On 3 December 2016 at 06:15, Marek Vasut <marex@denx.de> wrote:
>>> On 12/03/2016 05:29 AM, Simon Glass wrote:
>>>> From: Kever Yang <kever.yang@rock-chips.com>
>>>>
>>>> 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.
>>>>
>>>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>>> ---
>>>>
>>>> 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.
>
> 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.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-03-07 2:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-03 4:29 [U-Boot] [PATCH v3] usb: dwc2: add support for external vbus supply Simon Glass
2016-12-03 13:15 ` Marek Vasut
2016-12-03 18:27 ` Simon Glass
2016-12-03 18:48 ` Marek Vasut
2017-03-06 12:36 ` Kever Yang
2017-03-07 2:53 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox