All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3] usb: ehci-generic: Add vbus-supply regulator support
@ 2018-08-09 12:53 Patrice Chotard
  2018-08-09 13:00 ` Marek Vasut
  0 siblings, 1 reply; 2+ messages in thread
From: Patrice Chotard @ 2018-08-09 12:53 UTC (permalink / raw)
  To: u-boot

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@st.com>
---

Changes in v3:
      - Update test on device_get_supply_regulator() call
      - Replace pr_err() by dev_err()
      - Replace debug() by dev_dbg()

Changes in v2:
      - Add test on device_get_supply_regulator() call

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

diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
index 5a56f66cfaa6..dc7d23e95f5e 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,26 @@ static int ehci_usb_probe(struct udevice *dev)
 		}
 	}
 
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
+	if (err && err != -ENOENT)
+		goto reset_err;
+
+	if (priv->vbus_supply) {
+		err = regulator_set_enable(priv->vbus_supply, true);
+		if (err) {
+			dev_err(dev, "Error enabling VBUS supply\n");
+			goto reset_err;
+		}
+	} else {
+		dev_dbg(dev, "%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 +185,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)
+			dev_err(dev, "Error disabling VBUS supply\n");
+	}
+#endif
+
 reset_err:
 	ret = reset_release_all(priv->resets, priv->reset_count);
 	if (ret)
@@ -189,6 +219,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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH v3] usb: ehci-generic: Add vbus-supply regulator support
  2018-08-09 12:53 [U-Boot] [PATCH v3] usb: ehci-generic: Add vbus-supply regulator support Patrice Chotard
@ 2018-08-09 13:00 ` Marek Vasut
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2018-08-09 13:00 UTC (permalink / raw)
  To: u-boot

On 08/09/2018 02:53 PM, Patrice Chotard wrote:
> 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@st.com>
> ---
> 
> Changes in v3:
>       - Update test on device_get_supply_regulator() call
>       - Replace pr_err() by dev_err()
>       - Replace debug() by dev_dbg()
> 
> Changes in v2:
>       - Add test on device_get_supply_regulator() call
> 
>  drivers/usb/host/ehci-generic.c | 39 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
> index 5a56f66cfaa6..dc7d23e95f5e 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,26 @@ static int ehci_usb_probe(struct udevice *dev)
>  		}
>  	}
>  
> +#ifdef CONFIG_DM_REGULATOR
> +	err = device_get_supply_regulator(dev, "vbus-supply",
> +					  &priv->vbus_supply);
> +	if (err && err != -ENOENT)
> +		goto reset_err;
> +
> +	if (priv->vbus_supply) {
> +		err = regulator_set_enable(priv->vbus_supply, true);
> +		if (err) {
> +			dev_err(dev, "Error enabling VBUS supply\n");
> +			goto reset_err;
> +		}
> +	} else {
> +		dev_dbg(dev, "%s: No vbus supply\n", dev->name);

dev_dbg() already prints dev->name as a prefix.

Please stop cannonfodding the patches into the ML as quickly as
possible, give it a few days.

> +	}
> +#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 +185,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)
> +			dev_err(dev, "Error disabling VBUS supply\n");
> +	}
> +#endif
> +
>  reset_err:
>  	ret = reset_release_all(priv->resets, priv->reset_count);
>  	if (ret)
> @@ -189,6 +219,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;
> 


-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-09 13:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-09 12:53 [U-Boot] [PATCH v3] usb: ehci-generic: Add vbus-supply regulator support Patrice Chotard
2018-08-09 13:00 ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.