[U-Boot] [PATCH v2 1/4] usb: dwc2: add support for external vbus supply

Marek Vasut marex at denx.de
Fri Nov 25 17:46:42 CET 2016


On 11/24/2016 08:29 AM, Kever Yang wrote:
> 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 at rock-chips.com>
> ---
> 
> Changes in v2: None
> 
>  drivers/usb/host/dwc2.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
> index d08879d..8292aa8 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"
>  
> @@ -55,6 +56,8 @@ DEFINE_ALIGN_BUFFER(uint8_t, status_buffer_addr, DWC2_STATUS_BUF_SIZE,
>  static struct dwc2_priv local;
>  #endif
>  
> +static struct udevice *g_dwc2_udev;

Can we avoid the static global var ?

> +
>  /*
>   * DWC2 IP interface
>   */
> @@ -159,6 +162,29 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
>  	mdelay(100);
>  }
>  
> +static int dwc_vbus_supply_init(void)
> +{
> +#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR) && \
> +	!defined(CONFIG_SPL_BUILD)

Why does this not work for SPL ?

btw, I'd rather see this as:

#if FOO
function bar()
{
 ...
}
#else
static inline function bar()
{
 return 0;
}
#endif

> +	struct udevice *vbus_supply;
> +	int ret;
> +
> +	ret = device_get_supply_regulator(g_dwc2_udev, "vbus-supply",
> +					  &vbus_supply);

Is this compatible with the Linux DWC2 DT bindings ?

> +	if (ret) {
> +		debug("%s: No vbus supply\n", g_dwc2_udev->name);
> +		return 0;
> +	}
> +
> +	ret = regulator_set_enable(vbus_supply, true);

Shouldn't the regulator be enabled when we enable VBUS for a port
instead of here ? And where is it disabled ?

> +	if (ret) {
> +		error("Error enabling vbus supply\n");
> +		return ret;
> +	}
> +#endif
> +	return 0;
> +}
> +
>  /*
>   * This function initializes the DWC_otg controller registers for
>   * host mode.
> @@ -248,6 +274,8 @@ static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
>  			writel(hprt0, &regs->hprt0);
>  		}
>  	}
> +
> +	dwc_vbus_supply_init();
>  }
>  
>  /*
> @@ -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;
> 


-- 
Best regards,
Marek Vasut


More information about the U-Boot mailing list