Skip to contentSkip to conversation

usb: ehci-generic: Add vbus-supply regulator support

PATCH Superseded Patrice Chotard 2 participants 5 messages Aug 9, 2018

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: ehci-generic: Add vbus-supply regulator support

Add vbus-supply regulator support.
On some board vbus is not controlled by the phy but by an external regulator.

---

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(-)
drivers/usb/host/ehci-generic.c +38 -1
index 5a56f66cfaa6..ad926d05ac3e 100644
@@ -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,10 +149,27 @@ static int ehci_usb_probe(struct udevice *dev)
 		}
 	}
 
-	err = ehci_setup_phy(dev, 0);
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
 	if (err)
 		goto reset_err;
 
+	if (priv->vbus_supply) {
+		err = regulator_set_enable(priv->vbus_supply, true);
+		if (err) {
+			pr_err("Error enabling VBUS supply\n");
+			goto reset_err;
+		}
+	} else {
+		debug("%s: No vbus supply\n", dev->name);
+	}
+#endif
+
+	err = ehci_setup_phy(dev, 0);
+	if (err)
+		goto regulator_err;
+
 	hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE);
 	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
@@ -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)
+			pr_err("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;
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 usb: ehci-generic: Add vbus-supply regulator support

Quoted 36 lines · Patrice Chotard

Add vbus-supply regulator support.
On some board vbus is not controlled by the phy but by an external regulator.

---

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(-)
drivers/usb/host/ehci-generic.c +4 -0
index 5a56f66cfaa6..ad926d05ac3e 100644
@@ -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;
 };

drivers/usb/host/ehci-generic.c static int ehci_usb_probe(struct udevice *dev) · line 156

Quoted 9 lines
drivers/usb/host/ehci-generic.c +3 -1
@@ -145,10 +149,27 @@ static int ehci_usb_probe(struct udevice *dev)
 		}
 	}
 
-	err = ehci_setup_phy(dev, 0);
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
 	if (err)
 		goto reset_err;

What if there is no regulator, what does this return , probably a negative return value ?

Quoted 18 lines
drivers/usb/host/ehci-generic.c +14 -0
+	if (priv->vbus_supply) {
+		err = regulator_set_enable(priv->vbus_supply, true);
+		if (err) {
+			pr_err("Error enabling VBUS supply\n");
+			goto reset_err;
+		}
+	} else {
+		debug("%s: No vbus supply\n", dev->name);
+	}
+#endif
+
+	err = ehci_setup_phy(dev, 0);> +	if (err)
+		goto regulator_err;
+
 	hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE);
 	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));

drivers/usb/host/ehci-generic.c phy_err: · line 193

Quoted 9 lines
drivers/usb/host/ehci-generic.c +6 -0
@@ -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)
+			pr_err("Error disabling VBUS supply\n");

Can you use dev_err() ? Fix globally .

Quoted 21 lines
drivers/usb/host/ehci-generic.c +10 -0
+	}
+#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;
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH v2 1/1 usb: ehci-generic: Add vbus-supply regulator support

Hi Marek

Quoted 40 lines · Marek Vasut
Quoted 39 lines · Patrice Chotard

Add vbus-supply regulator support.
On some board vbus is not controlled by the phy but by an external regulator.

---

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(-)
drivers/usb/host/ehci-generic.c +4 -0
index 5a56f66cfaa6..ad926d05ac3e 100644
@@ -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,10 +149,27 @@ static int ehci_usb_probe(struct udevice *dev)
  		}
  	}
 
Quoted 8 lines

drivers/usb/host/ehci-generic.c static int ehci_usb_probe(struct udevice *dev) · line 156

Quoted 6 lines
drivers/usb/host/ehci-generic.c +3 -1
-	err = ehci_setup_phy(dev, 0);
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
  	if (err)
  		goto reset_err;

What if there is no regulator, what does this return , probably a negative return value ?

Argh yes, good catch, i will update the test.

Quoted 22 lines
Quoted 22 lines
drivers/usb/host/ehci-generic.c +14 -0
+	if (priv->vbus_supply) {
+		err = regulator_set_enable(priv->vbus_supply, true);
+		if (err) {
+			pr_err("Error enabling VBUS supply\n");
+			goto reset_err;
+		}
+	} else {
+		debug("%s: No vbus supply\n", dev->name);
+	}
+#endif
+
+	err = ehci_setup_phy(dev, 0);> +	if (err)
+		goto regulator_err;
+
  	hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE);
  	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
  				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
@@ -164,6 +185,15 @@ phy_err:
  	if (ret)
  		dev_err(dev, "failed to shutdown usb phy\n");
 
Quoted 8 lines

drivers/usb/host/ehci-generic.c phy_err: · line 193

Quoted 6 lines
drivers/usb/host/ehci-generic.c +6 -0
+regulator_err:
+#ifdef CONFIG_DM_REGULATOR
+	if (priv->vbus_supply) {
+		ret = regulator_set_enable(priv->vbus_supply, false);
+		if (ret)
+			pr_err("Error disabling VBUS supply\n");

Can you use dev_err() ? Fix globally .

yes

Thanks

Patrice

Quoted 24 lines
Quoted 22 lines
drivers/usb/host/ehci-generic.c +10 -0
+	}
+#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;
#3 lore raw

PATCH v2 1/1 usb: ehci-generic: Add vbus-supply regulator support

Quoted 52 lines · Patrice CHOTARD

Hi Marek

Quoted 40 lines · Marek Vasut
Quoted 39 lines · Patrice Chotard

Add vbus-supply regulator support.
On some board vbus is not controlled by the phy but by an external regulator.

---

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(-)
drivers/usb/host/ehci-generic.c +4 -0
index 5a56f66cfaa6..ad926d05ac3e 100644
@@ -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,10 +149,27 @@ static int ehci_usb_probe(struct udevice *dev)
  		}
  	}
 
Quoted 8 lines

drivers/usb/host/ehci-generic.c static int ehci_usb_probe(struct udevice *dev) · line 156

Quoted 6 lines
drivers/usb/host/ehci-generic.c +3 -1
-	err = ehci_setup_phy(dev, 0);
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
  	if (err)
  		goto reset_err;

What if there is no regulator, what does this return , probably a negative return value ?

Quoted 1 line

Argh yes, good catch, i will update the test.

Wait a few days before resending v3 so people can review the patches ...

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

PATCH v2 1/1 usb: ehci-generic: Add vbus-supply regulator support

Quoted 53 lines · Marek Vasut
Quoted 52 lines · Patrice CHOTARD

Hi Marek

Quoted 48 lines · Marek Vasut
Quoted 36 lines · Patrice Chotard

Add vbus-supply regulator support.
On some board vbus is not controlled by the phy but by an external regulator.

---

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(-)
drivers/usb/host/ehci-generic.c +4 -0
index 5a56f66cfaa6..ad926d05ac3e 100644
@@ -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;
   };

drivers/usb/host/ehci-generic.c static int ehci_usb_probe(struct udevice *dev) · line 156

Quoted 9 lines
drivers/usb/host/ehci-generic.c +3 -1
@@ -145,10 +149,27 @@ static int ehci_usb_probe(struct udevice *dev)
   		}
   	}
 
-	err = ehci_setup_phy(dev, 0);
+#ifdef CONFIG_DM_REGULATOR
+	err = device_get_supply_regulator(dev, "vbus-supply",
+					  &priv->vbus_supply);
   	if (err)
   		goto reset_err;

What if there is no regulator, what does this return , probably a negative return value ?

Quoted 4 lines
Quoted 1 line

Argh yes, good catch, i will update the test.

Wait a few days before resending v3 so people can review the patches ...

oups the v3 is gone ... :-(