linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] usb: host: ehci-platform: add support for optional external vbus supply
@ 2018-03-01  9:51 Amelie Delaunay
  2018-03-01  9:51 ` [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property Amelie Delaunay
  2018-03-01  9:51 ` [PATCH v4 2/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
  0 siblings, 2 replies; 7+ messages in thread
From: Amelie Delaunay @ 2018-03-01  9:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring, Mark Rutland, Tony Prisk,
	Alan Stern, Roger Quadros, Felipe Balbi, Robin Murphy
  Cc: linux-usb, devicetree, linux-kernel, linux-arm-kernel, Amelie Delaunay

This patchset adds support for optional external vbus supply per port in
ehci-platform.

On some boards, especially when vbus supply requires large current,
and the charge pump on the PHY isn't enough, an external vbus power switch
per port may be used.

---
Changes in v4:
 * Address Roger Quadros comments: split dt-bindings and driver changes.
 * Address Robin Murphy comments: simplify vbus_spplies initialization.

Changes in v3:
 * Address Felipe Balbi comments: reduce indentation in
   ehci_platform_port_power.
 * Address Roger Quadros and Alan Stern comments: platforms can have one
   external vbus supply per port, so add support to get as many optional
   regulator as implemented ports on the host controller.

Changes in v2:
 * Address Roger Quadros comments: move regulator_enable/disable from
   ehci_platform_power_on/off to ehci_platform_port_power.

Amelie Delaunay (2):
  dt-bindings: usb: ehci: add optional external vbus supply property
  usb: host: ehci-platform: add support for optional external vbus
    supply

 Documentation/devicetree/bindings/usb/usb-ehci.txt |  1 +
 drivers/usb/host/ehci-platform.c                   | 51 +++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

-- 
2.7.4


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

* [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property
  2018-03-01  9:51 [PATCH v4 0/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
@ 2018-03-01  9:51 ` Amelie Delaunay
  2018-03-06  1:57   ` Rob Herring
  2018-03-01  9:51 ` [PATCH v4 2/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
  1 sibling, 1 reply; 7+ messages in thread
From: Amelie Delaunay @ 2018-03-01  9:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring, Mark Rutland, Tony Prisk,
	Alan Stern, Roger Quadros, Felipe Balbi, Robin Murphy
  Cc: linux-usb, devicetree, linux-kernel, linux-arm-kernel, Amelie Delaunay

On some boards, especially when vbus supply requires large current,
and the charge pump on the PHY isn't enough, an external vbus power switch
per port may be used.
Add portN_vbus-supply property to usb-ehci bindings. As the number of ports
depends on the ehci controller, and the port on which an external vbus
supply depends on the platform, <portN> is used to make it generic.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 Documentation/devicetree/bindings/usb/usb-ehci.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
index 3efde12..cd576db 100644
--- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
@@ -19,6 +19,7 @@ Optional properties:
  - phys : phandle + phy specifier pair
  - phy-names : "usb"
  - resets : phandle + reset specifier pair
+ - portN_vbus-supply : phandle of regulator supplying vbus for port N
 
 Example (Sequoia 440EPx):
     ehci@e0000300 {
-- 
2.7.4


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

* [PATCH v4 2/2] usb: host: ehci-platform: add support for optional external vbus supply
  2018-03-01  9:51 [PATCH v4 0/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
  2018-03-01  9:51 ` [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property Amelie Delaunay
@ 2018-03-01  9:51 ` Amelie Delaunay
  1 sibling, 0 replies; 7+ messages in thread
From: Amelie Delaunay @ 2018-03-01  9:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring, Mark Rutland, Tony Prisk,
	Alan Stern, Roger Quadros, Felipe Balbi, Robin Murphy
  Cc: linux-usb, devicetree, linux-kernel, linux-arm-kernel, Amelie Delaunay

On some boards, especially when vbus supply requires large current,
and the charge pump on the PHY isn't enough, an external vbus power switch
may be used.
Add support for optional external vbus supply per port in ehci-platform.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Reviewed-by: Roger Quadros <rogerq@ti.com>
---
 drivers/usb/host/ehci-platform.c | 51 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index b065a96..e0dace7 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -29,6 +29,7 @@
 #include <linux/of.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 #include <linux/reset.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
@@ -46,6 +47,7 @@ struct ehci_platform_priv {
 	struct reset_control *rsts;
 	struct phy **phys;
 	int num_phys;
+	struct regulator **vbus_supplies;
 	bool reset_on_resume;
 };
 
@@ -56,7 +58,8 @@ static int ehci_platform_reset(struct usb_hcd *hcd)
 	struct platform_device *pdev = to_platform_device(hcd->self.controller);
 	struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev);
 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
-	int retval;
+	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
+	int portnum, n_ports, retval;
 
 	ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
 
@@ -71,11 +74,56 @@ static int ehci_platform_reset(struct usb_hcd *hcd)
 	if (retval)
 		return retval;
 
+	n_ports = HCS_N_PORTS(ehci->hcs_params);
+	priv->vbus_supplies = devm_kcalloc(&pdev->dev, n_ports,
+					   sizeof(*priv->vbus_supplies),
+					   GFP_KERNEL);
+	if (!priv->vbus_supplies)
+		return -ENOMEM;
+
+	for (portnum = 0; portnum < n_ports; portnum++) {
+		struct regulator *vbus_supply;
+		char id[20];
+
+		sprintf(id, "port%d_vbus", portnum);
+
+		vbus_supply = devm_regulator_get_optional(&pdev->dev, id);
+		if (IS_ERR(vbus_supply)) {
+			retval = PTR_ERR(vbus_supply);
+			if (retval != ENODEV)
+				return retval;
+		} else {
+			priv->vbus_supplies[portnum] = vbus_supply;
+		}
+	}
+
 	if (pdata->no_io_watchdog)
 		ehci->need_io_watchdog = 0;
 	return 0;
 }
 
+static int ehci_platform_port_power(struct usb_hcd *hcd, int portnum,
+				    bool enable)
+{
+	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
+	int ret;
+
+	if (!priv->vbus_supplies[portnum])
+		return 0;
+
+	if (enable)
+		ret = regulator_enable(priv->vbus_supplies[portnum]);
+	else
+		ret = regulator_disable(priv->vbus_supplies[portnum]);
+
+	if (ret)
+		dev_err(hcd->self.controller,
+			"failed to %s vbus supply for port %d: %d\n",
+			enable ? "enable" : "disable", portnum, ret);
+
+	return ret;
+}
+
 static int ehci_platform_power_on(struct platform_device *dev)
 {
 	struct usb_hcd *hcd = platform_get_drvdata(dev);
@@ -134,6 +182,7 @@ static struct hc_driver __read_mostly ehci_platform_hc_driver;
 static const struct ehci_driver_overrides platform_overrides __initconst = {
 	.reset =		ehci_platform_reset,
 	.extra_priv_size =	sizeof(struct ehci_platform_priv),
+	.port_power =		ehci_platform_port_power,
 };
 
 static struct usb_ehci_pdata ehci_platform_defaults = {
-- 
2.7.4


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

* Re: [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property
  2018-03-01  9:51 ` [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property Amelie Delaunay
@ 2018-03-06  1:57   ` Rob Herring
  2018-03-06 14:09     ` Robin Murphy
  0 siblings, 1 reply; 7+ messages in thread
From: Rob Herring @ 2018-03-06  1:57 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Greg Kroah-Hartman, Mark Rutland, Tony Prisk, Alan Stern,
	Roger Quadros, Felipe Balbi, Robin Murphy, linux-usb, devicetree,
	linux-kernel, linux-arm-kernel

On Thu, Mar 01, 2018 at 10:51:38AM +0100, Amelie Delaunay wrote:
> On some boards, especially when vbus supply requires large current,
> and the charge pump on the PHY isn't enough, an external vbus power switch
> per port may be used.
> Add portN_vbus-supply property to usb-ehci bindings. As the number of ports
> depends on the ehci controller, and the port on which an external vbus
> supply depends on the platform, <portN> is used to make it generic.
> 
> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
> ---
>  Documentation/devicetree/bindings/usb/usb-ehci.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
> index 3efde12..cd576db 100644
> --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
> @@ -19,6 +19,7 @@ Optional properties:
>   - phys : phandle + phy specifier pair
>   - phy-names : "usb"
>   - resets : phandle + reset specifier pair
> + - portN_vbus-supply : phandle of regulator supplying vbus for port N

Just make this an array with the index being the port (and drop 
"portN_").

Rob

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

* Re: [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property
  2018-03-06  1:57   ` Rob Herring
@ 2018-03-06 14:09     ` Robin Murphy
  2018-03-06 14:40       ` Rob Herring
  0 siblings, 1 reply; 7+ messages in thread
From: Robin Murphy @ 2018-03-06 14:09 UTC (permalink / raw)
  To: Rob Herring, Amelie Delaunay
  Cc: Greg Kroah-Hartman, Mark Rutland, Tony Prisk, Alan Stern,
	Roger Quadros, Felipe Balbi, linux-usb, devicetree, linux-kernel,
	linux-arm-kernel

On 06/03/18 01:57, Rob Herring wrote:
> On Thu, Mar 01, 2018 at 10:51:38AM +0100, Amelie Delaunay wrote:
>> On some boards, especially when vbus supply requires large current,
>> and the charge pump on the PHY isn't enough, an external vbus power switch
>> per port may be used.
>> Add portN_vbus-supply property to usb-ehci bindings. As the number of ports
>> depends on the ehci controller, and the port on which an external vbus
>> supply depends on the platform, <portN> is used to make it generic.
>>
>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>> ---
>>   Documentation/devicetree/bindings/usb/usb-ehci.txt | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>> index 3efde12..cd576db 100644
>> --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
>> +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>> @@ -19,6 +19,7 @@ Optional properties:
>>    - phys : phandle + phy specifier pair
>>    - phy-names : "usb"
>>    - resets : phandle + reset specifier pair
>> + - portN_vbus-supply : phandle of regulator supplying vbus for port N
> 
> Just make this an array with the index being the port (and drop
> "portN_").

Does that still work if there is an external supply for port 1 but none 
for port 0? I believe that was brought up as a possibility before.

Robin.

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

* Re: [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property
  2018-03-06 14:09     ` Robin Murphy
@ 2018-03-06 14:40       ` Rob Herring
  2018-03-20  9:10         ` Amelie DELAUNAY
  0 siblings, 1 reply; 7+ messages in thread
From: Rob Herring @ 2018-03-06 14:40 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Amelie Delaunay, Greg Kroah-Hartman, Mark Rutland, Tony Prisk,
	Alan Stern, Roger Quadros, Felipe Balbi, Linux USB List,
	devicetree, linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

On Tue, Mar 6, 2018 at 8:09 AM, Robin Murphy <robin.murphy@arm.com> wrote:
> On 06/03/18 01:57, Rob Herring wrote:
>>
>> On Thu, Mar 01, 2018 at 10:51:38AM +0100, Amelie Delaunay wrote:
>>>
>>> On some boards, especially when vbus supply requires large current,
>>> and the charge pump on the PHY isn't enough, an external vbus power
>>> switch
>>> per port may be used.
>>> Add portN_vbus-supply property to usb-ehci bindings. As the number of
>>> ports
>>> depends on the ehci controller, and the port on which an external vbus
>>> supply depends on the platform, <portN> is used to make it generic.
>>>
>>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>>> ---
>>>   Documentation/devicetree/bindings/usb/usb-ehci.txt | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>> b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>> index 3efde12..cd576db 100644
>>> --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>> +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>> @@ -19,6 +19,7 @@ Optional properties:
>>>    - phys : phandle + phy specifier pair
>>>    - phy-names : "usb"
>>>    - resets : phandle + reset specifier pair
>>> + - portN_vbus-supply : phandle of regulator supplying vbus for port N
>>
>>
>> Just make this an array with the index being the port (and drop
>> "portN_").
>
>
> Does that still work if there is an external supply for port 1 but none for
> port 0? I believe that was brought up as a possibility before.

Yes, if you use 0 or -1 to skip over an index.

Really, this should go in the connector node instead because Vbus is
supplied to the connector, not the host controller. The connector
binding is on its way into mainline.

Rob

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

* Re: [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property
  2018-03-06 14:40       ` Rob Herring
@ 2018-03-20  9:10         ` Amelie DELAUNAY
  0 siblings, 0 replies; 7+ messages in thread
From: Amelie DELAUNAY @ 2018-03-20  9:10 UTC (permalink / raw)
  To: Rob Herring, Robin Murphy
  Cc: Greg Kroah-Hartman, Mark Rutland, Tony Prisk, Alan Stern,
	Roger Quadros, Felipe Balbi, Linux USB List, devicetree,
	linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE



On 03/06/2018 03:40 PM, Rob Herring wrote:
> On Tue, Mar 6, 2018 at 8:09 AM, Robin Murphy <robin.murphy@arm.com> wrote:
>> On 06/03/18 01:57, Rob Herring wrote:
>>>
>>> On Thu, Mar 01, 2018 at 10:51:38AM +0100, Amelie Delaunay wrote:
>>>>
>>>> On some boards, especially when vbus supply requires large current,
>>>> and the charge pump on the PHY isn't enough, an external vbus power
>>>> switch
>>>> per port may be used.
>>>> Add portN_vbus-supply property to usb-ehci bindings. As the number of
>>>> ports
>>>> depends on the ehci controller, and the port on which an external vbus
>>>> supply depends on the platform, <portN> is used to make it generic.
>>>>
>>>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>>>> ---
>>>>    Documentation/devicetree/bindings/usb/usb-ehci.txt | 1 +
>>>>    1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>>> b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>>> index 3efde12..cd576db 100644
>>>> --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>>> +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>>>> @@ -19,6 +19,7 @@ Optional properties:
>>>>     - phys : phandle + phy specifier pair
>>>>     - phy-names : "usb"
>>>>     - resets : phandle + reset specifier pair
>>>> + - portN_vbus-supply : phandle of regulator supplying vbus for port N
>>>
>>>
>>> Just make this an array with the index being the port (and drop
>>> "portN_").
>>
>>
>> Does that still work if there is an external supply for port 1 but none for
>> port 0? I believe that was brought up as a possibility before.
> 
> Yes, if you use 0 or -1 to skip over an index.
> 
> Really, this should go in the connector node instead because Vbus is
> supplied to the connector, not the host controller. The connector
> binding is on its way into mainline.
> 
> Rob
> 

Not sure to catch what you mean by "make this an array" because 
regulator framework imposes <name>-supply: phandle to the regulator node.

I may have missed something around regulator consumers management ?

Do you meant something like
vbus-supply = <&reg_port0 &reg_port1>;
or in case there is an external supply for port 1 but none for port 0
vbus-supply = <-1 &reg_port1>;
?
If yes, a new API is needed in regulator framework to get an array of 
regulators ?


Regards,
Amelie

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

end of thread, other threads:[~2018-03-20  9:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-01  9:51 [PATCH v4 0/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
2018-03-01  9:51 ` [PATCH v4 1/2] dt-bindings: usb: ehci: add optional external vbus supply property Amelie Delaunay
2018-03-06  1:57   ` Rob Herring
2018-03-06 14:09     ` Robin Murphy
2018-03-06 14:40       ` Rob Herring
2018-03-20  9:10         ` Amelie DELAUNAY
2018-03-01  9:51 ` [PATCH v4 2/2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).