All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amelie DELAUNAY <amelie.delaunay@st.com>
To: Roger Quadros <rogerq@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Tony Prisk <linux@prisktech.co.nz>,
	Alan Stern <stern@rowland.harvard.edu>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2] usb: host: ehci-platform: add support for optional external vbus supply
Date: Tue, 20 Feb 2018 14:46:07 +0000	[thread overview]
Message-ID: <2ef38200-947c-1419-1c91-f033da390f74@st.com> (raw)
In-Reply-To: <bfaa3001-d90f-7903-17e8-90af9a03c338@ti.com>

Hi,

On 02/20/2018 03:00 PM, Roger Quadros wrote:
> Hi,
> 
> On 20/02/18 14:58, 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
>> may be used.
>> Add support for this optional external vbus supply in ehci-platform.
>>
>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>>
>> ---
>> Changes in v2:
>>   * Address Roger Quadros comments: move regulator_enable/disable from
>> ehci_platform_power_on/off to ehci_platform_port_power.
>> ---
>>   Documentation/devicetree/bindings/usb/usb-ehci.txt |  1 +
>>   drivers/usb/host/ehci-platform.c                   | 31 ++++++++++++++++++++++
>>   2 files changed, 32 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>> index 3efde12..fc480cd 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
>> + - vbus-supply : phandle of regulator supplying vbus
>>   
> 
> Can platforms have more than one regulator e.g. one regulator per port?
> 

I imagine that yes, platforms could have one regulator per port.
Regulator consumers bindings impose a <name>-supply property per 
regulator, so, what do you think about :
vbus0-supply for port#0
vbus1-supply for port#1
...
vbusN-supply for port#N

And then in probe, allocate 'struct regulator *vbus_supplies' with a 
size corresponding to 'HCS_N_PORTS(ehci->hcs_params) * sizeof(struct 
regulator *)'.
And loop to get optional regulator vbus0, vbus1,..., vbusN.
And then enable/disable the corresponding regulator in 
ehci_platform_port_power thanks to portnum.

>>   Example (Sequoia 440EPx):
>>       ehci@e0000300 {
>> diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
>> index b065a96..05be100 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_supply;
>>   	bool reset_on_resume;
>>   };
>>   
>> @@ -76,6 +78,25 @@ static int ehci_platform_reset(struct usb_hcd *hcd)
>>   	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 = 0;
>> +
>> +	if (priv->vbus_supply) {
>> +		if (enable)
>> +			ret = regulator_enable(priv->vbus_supply);
>> +		else
>> +			ret = regulator_disable(priv->vbus_supply);
>> +		if (ret)
>> +			dev_err(hcd->self.controller,
>> +				"failed to %s vbus supply: %d\n",
>> +				enable ? "enable" : "disable", ret);
>> +	}
>> +	return ret;
>> +}
>> +
>>   static int ehci_platform_power_on(struct platform_device *dev)
>>   {
>>   	struct usb_hcd *hcd = platform_get_drvdata(dev);
>> @@ -134,6 +155,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 = {
>> @@ -247,6 +269,15 @@ static int ehci_platform_probe(struct platform_device *dev)
>>   	if (err)
>>   		goto err_put_clks;
>>   
>> +	priv->vbus_supply = devm_regulator_get_optional(&dev->dev, "vbus");
>> +	if (IS_ERR(priv->vbus_supply)) {
>> +		err = PTR_ERR(priv->vbus_supply);
>> +		if (err == -ENODEV)
>> +			priv->vbus_supply = NULL;
>> +		else
>> +			goto err_reset;
>> +	}
>> +
>>   	if (pdata->big_endian_desc)
>>   		ehci->big_endian_desc = 1;
>>   	if (pdata->big_endian_mmio)
>>
> 

WARNING: multiple messages have this Message-ID (diff)
From: Amelie DELAUNAY <amelie.delaunay@st.com>
To: Roger Quadros <rogerq@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Tony Prisk <linux@prisktech.co.nz>,
	Alan Stern <stern@rowland.harvard.edu>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2] usb: host: ehci-platform: add support for optional external vbus supply
Date: Tue, 20 Feb 2018 14:46:07 +0000	[thread overview]
Message-ID: <2ef38200-947c-1419-1c91-f033da390f74@st.com> (raw)
In-Reply-To: <bfaa3001-d90f-7903-17e8-90af9a03c338@ti.com>

Hi,

On 02/20/2018 03:00 PM, Roger Quadros wrote:
> Hi,
> 
> On 20/02/18 14:58, 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
>> may be used.
>> Add support for this optional external vbus supply in ehci-platform.
>>
>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>>
>> ---
>> Changes in v2:
>>   * Address Roger Quadros comments: move regulator_enable/disable from
>> ehci_platform_power_on/off to ehci_platform_port_power.
>> ---
>>   Documentation/devicetree/bindings/usb/usb-ehci.txt |  1 +
>>   drivers/usb/host/ehci-platform.c                   | 31 ++++++++++++++++++++++
>>   2 files changed, 32 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>> index 3efde12..fc480cd 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
>> + - vbus-supply : phandle of regulator supplying vbus
>>   
> 
> Can platforms have more than one regulator e.g. one regulator per port?
> 

I imagine that yes, platforms could have one regulator per port.
Regulator consumers bindings impose a <name>-supply property per 
regulator, so, what do you think about :
vbus0-supply for port#0
vbus1-supply for port#1
...
vbusN-supply for port#N

And then in probe, allocate 'struct regulator *vbus_supplies' with a 
size corresponding to 'HCS_N_PORTS(ehci->hcs_params) * sizeof(struct 
regulator *)'.
And loop to get optional regulator vbus0, vbus1,..., vbusN.
And then enable/disable the corresponding regulator in 
ehci_platform_port_power thanks to portnum.

>>   Example (Sequoia 440EPx):
>>       ehci@e0000300 {
>> diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
>> index b065a96..05be100 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_supply;
>>   	bool reset_on_resume;
>>   };
>>   
>> @@ -76,6 +78,25 @@ static int ehci_platform_reset(struct usb_hcd *hcd)
>>   	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 = 0;
>> +
>> +	if (priv->vbus_supply) {
>> +		if (enable)
>> +			ret = regulator_enable(priv->vbus_supply);
>> +		else
>> +			ret = regulator_disable(priv->vbus_supply);
>> +		if (ret)
>> +			dev_err(hcd->self.controller,
>> +				"failed to %s vbus supply: %d\n",
>> +				enable ? "enable" : "disable", ret);
>> +	}
>> +	return ret;
>> +}
>> +
>>   static int ehci_platform_power_on(struct platform_device *dev)
>>   {
>>   	struct usb_hcd *hcd = platform_get_drvdata(dev);
>> @@ -134,6 +155,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 = {
>> @@ -247,6 +269,15 @@ static int ehci_platform_probe(struct platform_device *dev)
>>   	if (err)
>>   		goto err_put_clks;
>>   
>> +	priv->vbus_supply = devm_regulator_get_optional(&dev->dev, "vbus");
>> +	if (IS_ERR(priv->vbus_supply)) {
>> +		err = PTR_ERR(priv->vbus_supply);
>> +		if (err == -ENODEV)
>> +			priv->vbus_supply = NULL;
>> +		else
>> +			goto err_reset;
>> +	}
>> +
>>   	if (pdata->big_endian_desc)
>>   		ehci->big_endian_desc = 1;
>>   	if (pdata->big_endian_mmio)
>>
> 

WARNING: multiple messages have this Message-ID (diff)
From: Amelie Delaunay <amelie.delaunay@st.com>
To: Roger Quadros <rogerq@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Tony Prisk <linux@prisktech.co.nz>,
	Alan Stern <stern@rowland.harvard.edu>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: [v2] usb: host: ehci-platform: add support for optional external vbus supply
Date: Tue, 20 Feb 2018 14:46:07 +0000	[thread overview]
Message-ID: <2ef38200-947c-1419-1c91-f033da390f74@st.com> (raw)

SGksDQoNCk9uIDAyLzIwLzIwMTggMDM6MDAgUE0sIFJvZ2VyIFF1YWRyb3Mgd3JvdGU6DQo+IEhp
LA0KPiANCj4gT24gMjAvMDIvMTggMTQ6NTgsIEFtZWxpZSBEZWxhdW5heSB3cm90ZToNCj4+IE9u
IHNvbWUgYm9hcmRzLCBlc3BlY2lhbGx5IHdoZW4gdmJ1cyBzdXBwbHkgcmVxdWlyZXMgbGFyZ2Ug
Y3VycmVudCwNCj4+IGFuZCB0aGUgY2hhcmdlIHB1bXAgb24gdGhlIFBIWSBpc24ndCBlbm91Z2gs
IGFuIGV4dGVybmFsIHZidXMgcG93ZXIgc3dpdGNoDQo+PiBtYXkgYmUgdXNlZC4NCj4+IEFkZCBz
dXB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4+
ICsJCWVsc2UNCj4+ICsJCQlnb3RvIGVycl9yZXNldDsNCj4+ICsJfQ0KPj4gKw0KPj4gICAJaWYg
KHBkYXRhLT5iaWdfZW5kaWFuX2Rlc2MpDQo+PiAgIAkJZWhjaS0+YmlnX2VuZGlhbl9kZXNjID0g
MTsNCj4+ICAgCWlmIChwZGF0YS0+YmlnX2VuZGlhbl9tbWlvKQ0KPj4NCj4g
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: amelie.delaunay@st.com (Amelie DELAUNAY)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] usb: host: ehci-platform: add support for optional external vbus supply
Date: Tue, 20 Feb 2018 14:46:07 +0000	[thread overview]
Message-ID: <2ef38200-947c-1419-1c91-f033da390f74@st.com> (raw)
In-Reply-To: <bfaa3001-d90f-7903-17e8-90af9a03c338@ti.com>

Hi,

On 02/20/2018 03:00 PM, Roger Quadros wrote:
> Hi,
> 
> On 20/02/18 14:58, 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
>> may be used.
>> Add support for this optional external vbus supply in ehci-platform.
>>
>> Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
>>
>> ---
>> Changes in v2:
>>   * Address Roger Quadros comments: move regulator_enable/disable from
>> ehci_platform_power_on/off to ehci_platform_port_power.
>> ---
>>   Documentation/devicetree/bindings/usb/usb-ehci.txt |  1 +
>>   drivers/usb/host/ehci-platform.c                   | 31 ++++++++++++++++++++++
>>   2 files changed, 32 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
>> index 3efde12..fc480cd 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
>> + - vbus-supply : phandle of regulator supplying vbus
>>   
> 
> Can platforms have more than one regulator e.g. one regulator per port?
> 

I imagine that yes, platforms could have one regulator per port.
Regulator consumers bindings impose a <name>-supply property per 
regulator, so, what do you think about :
vbus0-supply for port#0
vbus1-supply for port#1
...
vbusN-supply for port#N

And then in probe, allocate 'struct regulator *vbus_supplies' with a 
size corresponding to 'HCS_N_PORTS(ehci->hcs_params) * sizeof(struct 
regulator *)'.
And loop to get optional regulator vbus0, vbus1,..., vbusN.
And then enable/disable the corresponding regulator in 
ehci_platform_port_power thanks to portnum.

>>   Example (Sequoia 440EPx):
>>       ehci at e0000300 {
>> diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
>> index b065a96..05be100 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_supply;
>>   	bool reset_on_resume;
>>   };
>>   
>> @@ -76,6 +78,25 @@ static int ehci_platform_reset(struct usb_hcd *hcd)
>>   	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 = 0;
>> +
>> +	if (priv->vbus_supply) {
>> +		if (enable)
>> +			ret = regulator_enable(priv->vbus_supply);
>> +		else
>> +			ret = regulator_disable(priv->vbus_supply);
>> +		if (ret)
>> +			dev_err(hcd->self.controller,
>> +				"failed to %s vbus supply: %d\n",
>> +				enable ? "enable" : "disable", ret);
>> +	}
>> +	return ret;
>> +}
>> +
>>   static int ehci_platform_power_on(struct platform_device *dev)
>>   {
>>   	struct usb_hcd *hcd = platform_get_drvdata(dev);
>> @@ -134,6 +155,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 = {
>> @@ -247,6 +269,15 @@ static int ehci_platform_probe(struct platform_device *dev)
>>   	if (err)
>>   		goto err_put_clks;
>>   
>> +	priv->vbus_supply = devm_regulator_get_optional(&dev->dev, "vbus");
>> +	if (IS_ERR(priv->vbus_supply)) {
>> +		err = PTR_ERR(priv->vbus_supply);
>> +		if (err == -ENODEV)
>> +			priv->vbus_supply = NULL;
>> +		else
>> +			goto err_reset;
>> +	}
>> +
>>   	if (pdata->big_endian_desc)
>>   		ehci->big_endian_desc = 1;
>>   	if (pdata->big_endian_mmio)
>>
> 

  reply	other threads:[~2018-02-20 14:46 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-20 12:58 [PATCH v2] usb: host: ehci-platform: add support for optional external vbus supply Amelie Delaunay
2018-02-20 12:58 ` Amelie Delaunay
2018-02-20 12:58 ` [v2] " Amelie Delaunay
2018-02-20 12:58 ` [PATCH v2] " Amelie Delaunay
2018-02-20 13:02 ` Felipe Balbi
2018-02-20 13:02   ` Felipe Balbi
2018-02-20 13:02   ` [v2] " Felipe Balbi
2018-02-20 13:02   ` [PATCH v2] " Felipe Balbi
2018-02-20 13:48   ` Amelie DELAUNAY
2018-02-20 13:48     ` Amelie DELAUNAY
2018-02-20 13:48     ` [v2] " Amelie Delaunay
2018-02-20 13:48     ` [PATCH v2] " Amelie DELAUNAY
2018-02-20 14:00 ` Roger Quadros
2018-02-20 14:00   ` Roger Quadros
2018-02-20 14:00   ` [v2] " Roger Quadros
2018-02-20 14:00   ` [PATCH v2] " Roger Quadros
2018-02-20 14:46   ` Amelie DELAUNAY [this message]
2018-02-20 14:46     ` Amelie DELAUNAY
2018-02-20 14:46     ` [v2] " Amelie Delaunay
2018-02-20 14:46     ` [PATCH v2] " Amelie DELAUNAY
2018-02-20 16:33     ` Roger Quadros
2018-02-20 16:33       ` Roger Quadros
2018-02-20 16:33       ` [v2] " Roger Quadros
2018-02-20 16:33       ` [PATCH v2] " Roger Quadros
2018-02-20 18:10       ` Alan Stern
2018-02-20 18:10         ` Alan Stern
2018-02-20 18:10         ` [v2] " Alan Stern
2018-02-20 18:10         ` [PATCH v2] " Alan Stern
2018-02-22 10:17         ` Amelie DELAUNAY
2018-02-22 10:17           ` Amelie DELAUNAY
2018-02-22 10:17           ` [v2] " Amelie Delaunay
2018-02-22 10:17           ` [PATCH v2] " Amelie DELAUNAY
2018-02-22 18:27           ` Alan Stern
2018-02-22 18:27             ` Alan Stern
2018-02-22 18:27             ` [v2] " Alan Stern
2018-02-22 18:27             ` [PATCH v2] " Alan Stern
2018-02-23 10:46             ` Amelie DELAUNAY
2018-02-23 10:46               ` Amelie DELAUNAY
2018-02-23 10:46               ` [v2] " Amelie Delaunay
2018-02-23 10:46               ` [PATCH v2] " Amelie DELAUNAY

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ef38200-947c-1419-1c91-f033da390f74@st.com \
    --to=amelie.delaunay@st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@prisktech.co.nz \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=rogerq@ti.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.