diff mbox series

[v2,02/32] usb: dwc3-generic: support external vbus regulator

Message ID 20231219-b4-qcom-common-target-v2-2-b6dd9704219e@linaro.org
State Superseded
Headers show
Series Qualcomm generic board support | expand

Commit Message

Caleb Connolly Dec. 19, 2023, 4:04 p.m. UTC
Add support for a vbus-supply regulator specified in devicetree. This
provides generic support to avoid hardcoded GPIO configuration in board
init code.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
This patch has no dependencies

Cc: Marek Vasut <marex@denx.de>
---
 drivers/usb/dwc3/dwc3-generic.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Neil Armstrong Dec. 21, 2023, 4:14 p.m. UTC | #1
On 19/12/2023 17:04, Caleb Connolly wrote:
> Add support for a vbus-supply regulator specified in devicetree. This
> provides generic support to avoid hardcoded GPIO configuration in board
> init code.
> 
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
> This patch has no dependencies
> 
> Cc: Marek Vasut <marex@denx.de>
> ---
>   drivers/usb/dwc3/dwc3-generic.c | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
> index 744fde806948..e66e7961c70f 100644
> --- a/drivers/usb/dwc3/dwc3-generic.c
> +++ b/drivers/usb/dwc3/dwc3-generic.c
> @@ -21,6 +21,7 @@
>   #include <linux/usb/ch9.h>
>   #include <linux/usb/gadget.h>
>   #include <malloc.h>
> +#include <power/regulator.h>
>   #include <usb.h>
>   #include "core.h"
>   #include "gadget.h"
> @@ -47,6 +48,7 @@ struct dwc3_generic_priv {
>   struct dwc3_generic_host_priv {
>   	struct xhci_ctrl xhci_ctrl;
>   	struct dwc3_generic_priv gen_priv;
> +	struct udevice *vbus_dev;
>   };
>   
>   static int dwc3_generic_probe(struct udevice *dev,
> @@ -240,6 +242,13 @@ static int dwc3_generic_host_probe(struct udevice *dev)
>   	if (rc)
>   		return rc;
>   
> +	rc = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_dev);
> +	if (rc)
> +		debug("%s: No vbus regulator found: %d\n", dev->name, rc);
> +
> +	if (priv->vbus_dev)
> +		regulator_set_enable(priv->vbus_dev, true);
> +
>   	hccr = (struct xhci_hccr *)priv->gen_priv.base;
>   	hcor = (struct xhci_hcor *)(priv->gen_priv.base +
>   			HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
> @@ -256,6 +265,9 @@ static int dwc3_generic_host_remove(struct udevice *dev)
>   	if (rc)
>   		return rc;
>   
> +	if (priv->vbus_dev)
> +		regulator_set_enable(priv->vbus_dev, false);
> +
>   	return dwc3_generic_remove(dev, &priv->gen_priv);
>   }
>   
> 

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 744fde806948..e66e7961c70f 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -21,6 +21,7 @@ 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <malloc.h>
+#include <power/regulator.h>
 #include <usb.h>
 #include "core.h"
 #include "gadget.h"
@@ -47,6 +48,7 @@  struct dwc3_generic_priv {
 struct dwc3_generic_host_priv {
 	struct xhci_ctrl xhci_ctrl;
 	struct dwc3_generic_priv gen_priv;
+	struct udevice *vbus_dev;
 };
 
 static int dwc3_generic_probe(struct udevice *dev,
@@ -240,6 +242,13 @@  static int dwc3_generic_host_probe(struct udevice *dev)
 	if (rc)
 		return rc;
 
+	rc = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_dev);
+	if (rc)
+		debug("%s: No vbus regulator found: %d\n", dev->name, rc);
+
+	if (priv->vbus_dev)
+		regulator_set_enable(priv->vbus_dev, true);
+
 	hccr = (struct xhci_hccr *)priv->gen_priv.base;
 	hcor = (struct xhci_hcor *)(priv->gen_priv.base +
 			HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
@@ -256,6 +265,9 @@  static int dwc3_generic_host_remove(struct udevice *dev)
 	if (rc)
 		return rc;
 
+	if (priv->vbus_dev)
+		regulator_set_enable(priv->vbus_dev, false);
+
 	return dwc3_generic_remove(dev, &priv->gen_priv);
 }