diff mbox

[02/13] USB: phy: nop: Defer probe if device needs VCC/RESET

Message ID 1359993540-20780-3-git-send-email-rogerq@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Quadros Feb. 4, 2013, 3:58 p.m. UTC
Add 2 flags, needs_vcc and needs_reset to platform data.
If the flag is set and the regulator couldn't be found
then we bail out with -EPROBE_DEFER.

For device tree boot we depend on presensce of vcc-supply/
reset-supply properties to decide if we should bail out
with -EPROBE_DEFER or just continue in case the regulator
can't be found.

This is required for proper functionality in cases where the
regulator is needed but is probed later than the PHY device.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/usb/otg/nop-usb-xceiv.c   |    8 ++++++++
 include/linux/usb/nop-usb-xceiv.h |    4 ++++
 2 files changed, 12 insertions(+), 0 deletions(-)

Comments

Kishon Vijay Abraham I Feb. 5, 2013, 5:54 a.m. UTC | #1
On Monday 04 February 2013 09:28 PM, Roger Quadros wrote:
> Add 2 flags, needs_vcc and needs_reset to platform data.
> If the flag is set and the regulator couldn't be found
> then we bail out with -EPROBE_DEFER.
>
> For device tree boot we depend on presensce of vcc-supply/
> reset-supply properties to decide if we should bail out
> with -EPROBE_DEFER or just continue in case the regulator
> can't be found.
>
> This is required for proper functionality in cases where the
> regulator is needed but is probed later than the PHY device.
>
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
>   drivers/usb/otg/nop-usb-xceiv.c   |    8 ++++++++
>   include/linux/usb/nop-usb-xceiv.h |    4 ++++
>   2 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
> index adbb7ab..7860e7569 100644
> --- a/drivers/usb/otg/nop-usb-xceiv.c
> +++ b/drivers/usb/otg/nop-usb-xceiv.c
> @@ -147,6 +147,10 @@ static void nop_xeiv_get_dt_pdata(struct device *dev,
>
>   	if (!of_property_read_u32(node, "clock-frequency", &clk_rate))
>   		pdata->clk_rate = clk_rate;
> +	if (of_property_read_bool(node, "vcc-supply"))
> +		pdata->needs_vcc = true;
This can be written as..
pdata->needs_vcc = of_property_read_bool(node, "vcc-supply");

> +	if (of_property_read_bool(node, "reset-supply"))
> +		pdata->needs_reset = true;
same here..
>   }
>
>   static int nop_usb_xceiv_probe(struct platform_device *pdev)
> @@ -205,12 +209,16 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
>   	if (IS_ERR(nop->vcc)) {
>   		dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
>   					PTR_ERR(nop->vcc));
> +		if (pdata->needs_vcc)
> +			return -EPROBE_DEFER;
>   	}
>
>   	nop->reset = devm_regulator_get(&pdev->dev, "reset");
>   	if (IS_ERR(nop->reset)) {
>   		dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
>   					PTR_ERR(nop->reset));
> +		if (pdata->needs_reset)
> +			return -EPROBE_DEFER;
>   	}
>
>   	nop->dev		= &pdev->dev;
> diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
> index 3265b61..148d351 100644
> --- a/include/linux/usb/nop-usb-xceiv.h
> +++ b/include/linux/usb/nop-usb-xceiv.h
> @@ -6,6 +6,10 @@
>   struct nop_usb_xceiv_platform_data {
>   	enum usb_phy_type type;
>   	unsigned long clk_rate;
> +
> +	/* if set fails with -EPROBE_DEFER if can't get regulator */
> +	unsigned int needs_vcc:1;
> +	unsigned int needs_reset:1;

how about u8 here?

Thanks
Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Roger Quadros Feb. 5, 2013, 8:44 a.m. UTC | #2
On 02/05/2013 07:54 AM, kishon wrote:
> On Monday 04 February 2013 09:28 PM, Roger Quadros wrote:
>> Add 2 flags, needs_vcc and needs_reset to platform data.
>> If the flag is set and the regulator couldn't be found
>> then we bail out with -EPROBE_DEFER.
>>
>> For device tree boot we depend on presensce of vcc-supply/
>> reset-supply properties to decide if we should bail out
>> with -EPROBE_DEFER or just continue in case the regulator
>> can't be found.
>>
>> This is required for proper functionality in cases where the
>> regulator is needed but is probed later than the PHY device.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>>   drivers/usb/otg/nop-usb-xceiv.c   |    8 ++++++++
>>   include/linux/usb/nop-usb-xceiv.h |    4 ++++
>>   2 files changed, 12 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
>> index adbb7ab..7860e7569 100644
>> --- a/drivers/usb/otg/nop-usb-xceiv.c
>> +++ b/drivers/usb/otg/nop-usb-xceiv.c
>> @@ -147,6 +147,10 @@ static void nop_xeiv_get_dt_pdata(struct device *dev,
>>
>>       if (!of_property_read_u32(node, "clock-frequency", &clk_rate))
>>           pdata->clk_rate = clk_rate;
>> +    if (of_property_read_bool(node, "vcc-supply"))
>> +        pdata->needs_vcc = true;
> This can be written as..
> pdata->needs_vcc = of_property_read_bool(node, "vcc-supply");

OK.

> 
>> +    if (of_property_read_bool(node, "reset-supply"))
>> +        pdata->needs_reset = true;
> same here..
>>   }
>>
>>   static int nop_usb_xceiv_probe(struct platform_device *pdev)
>> @@ -205,12 +209,16 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
>>       if (IS_ERR(nop->vcc)) {
>>           dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
>>                       PTR_ERR(nop->vcc));
>> +        if (pdata->needs_vcc)
>> +            return -EPROBE_DEFER;
>>       }
>>
>>       nop->reset = devm_regulator_get(&pdev->dev, "reset");
>>       if (IS_ERR(nop->reset)) {
>>           dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
>>                       PTR_ERR(nop->reset));
>> +        if (pdata->needs_reset)
>> +            return -EPROBE_DEFER;
>>       }
>>
>>       nop->dev        = &pdev->dev;
>> diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
>> index 3265b61..148d351 100644
>> --- a/include/linux/usb/nop-usb-xceiv.h
>> +++ b/include/linux/usb/nop-usb-xceiv.h
>> @@ -6,6 +6,10 @@
>>   struct nop_usb_xceiv_platform_data {
>>       enum usb_phy_type type;
>>       unsigned long clk_rate;
>> +
>> +    /* if set fails with -EPROBE_DEFER if can't get regulator */
>> +    unsigned int needs_vcc:1;
>> +    unsigned int needs_reset:1;
> 
> how about u8 here?

Not sure. Bitfields are usually defined as unsigned int.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Felipe Balbi Feb. 5, 2013, 9:09 a.m. UTC | #3
On Tue, Feb 05, 2013 at 10:44:05AM +0200, Roger Quadros wrote:
> >> diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
> >> index 3265b61..148d351 100644
> >> --- a/include/linux/usb/nop-usb-xceiv.h
> >> +++ b/include/linux/usb/nop-usb-xceiv.h
> >> @@ -6,6 +6,10 @@
> >>   struct nop_usb_xceiv_platform_data {
> >>       enum usb_phy_type type;
> >>       unsigned long clk_rate;
> >> +
> >> +    /* if set fails with -EPROBE_DEFER if can't get regulator */
> >> +    unsigned int needs_vcc:1;
> >> +    unsigned int needs_reset:1;
> > 
> > how about u8 here?
> 
> Not sure. Bitfields are usually defined as unsigned int.

IIRC the benefit is that compiler can try to optimize those flags. I
mean, if you have 32 1-bit flags, compiler will combine those in a
single u32. Someone correct me if I'm wrong.

after you fix other comments from kishon (about of_read_bool()), you can
add my:

Acked-by: Felipe Balbi <balbi@ti.com>
Roger Quadros Feb. 5, 2013, 9:43 a.m. UTC | #4
On 02/05/2013 11:09 AM, Felipe Balbi wrote:
> On Tue, Feb 05, 2013 at 10:44:05AM +0200, Roger Quadros wrote:
>>>> diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
>>>> index 3265b61..148d351 100644
>>>> --- a/include/linux/usb/nop-usb-xceiv.h
>>>> +++ b/include/linux/usb/nop-usb-xceiv.h
>>>> @@ -6,6 +6,10 @@
>>>>   struct nop_usb_xceiv_platform_data {
>>>>       enum usb_phy_type type;
>>>>       unsigned long clk_rate;
>>>> +
>>>> +    /* if set fails with -EPROBE_DEFER if can't get regulator */
>>>> +    unsigned int needs_vcc:1;
>>>> +    unsigned int needs_reset:1;
>>>
>>> how about u8 here?
>>
>> Not sure. Bitfields are usually defined as unsigned int.
> 
> IIRC the benefit is that compiler can try to optimize those flags. I
> mean, if you have 32 1-bit flags, compiler will combine those in a
> single u32. Someone correct me if I'm wrong.
> 

Yes you are right. Kishon was asking me to use u8 instead of unsigned int, which
I don't think is necessary. AFAIK, it is a norm to use unsigned int when defining
a bitfield. Compilers are known to behave funny with bitfields. I don't mind
using bool for each.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde March 11, 2013, 3:58 p.m. UTC | #5
On 02/05/2013 10:43 AM, Roger Quadros wrote:
> On 02/05/2013 11:09 AM, Felipe Balbi wrote:
>> On Tue, Feb 05, 2013 at 10:44:05AM +0200, Roger Quadros wrote:
>>>>> diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
>>>>> index 3265b61..148d351 100644
>>>>> --- a/include/linux/usb/nop-usb-xceiv.h
>>>>> +++ b/include/linux/usb/nop-usb-xceiv.h
>>>>> @@ -6,6 +6,10 @@
>>>>>   struct nop_usb_xceiv_platform_data {
>>>>>       enum usb_phy_type type;
>>>>>       unsigned long clk_rate;
>>>>> +
>>>>> +    /* if set fails with -EPROBE_DEFER if can't get regulator */
>>>>> +    unsigned int needs_vcc:1;
>>>>> +    unsigned int needs_reset:1;
>>>>
>>>> how about u8 here?
>>>
>>> Not sure. Bitfields are usually defined as unsigned int.
>>
>> IIRC the benefit is that compiler can try to optimize those flags. I
>> mean, if you have 32 1-bit flags, compiler will combine those in a
>> single u32. Someone correct me if I'm wrong.
>>
> 
> Yes you are right. Kishon was asking me to use u8 instead of unsigned int, which
> I don't think is necessary. AFAIK, it is a norm to use unsigned int when defining
> a bitfield. Compilers are known to behave funny with bitfields. I don't mind
> using bool for each.

In the current version (rogerq/v3.8-usbhost17-dt) of this patch you've
put both needs_* into the private data struct and the pdata, but it's
only used inside the probe function.

regards,
Marc
Roger Quadros March 12, 2013, 9:10 a.m. UTC | #6
On 03/11/2013 05:58 PM, Marc Kleine-Budde wrote:
> On 02/05/2013 10:43 AM, Roger Quadros wrote:
>> On 02/05/2013 11:09 AM, Felipe Balbi wrote:
>>> On Tue, Feb 05, 2013 at 10:44:05AM +0200, Roger Quadros wrote:
>>>>>> diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
>>>>>> index 3265b61..148d351 100644
>>>>>> --- a/include/linux/usb/nop-usb-xceiv.h
>>>>>> +++ b/include/linux/usb/nop-usb-xceiv.h
>>>>>> @@ -6,6 +6,10 @@
>>>>>>   struct nop_usb_xceiv_platform_data {
>>>>>>       enum usb_phy_type type;
>>>>>>       unsigned long clk_rate;
>>>>>> +
>>>>>> +    /* if set fails with -EPROBE_DEFER if can't get regulator */
>>>>>> +    unsigned int needs_vcc:1;
>>>>>> +    unsigned int needs_reset:1;
>>>>>
>>>>> how about u8 here?
>>>>
>>>> Not sure. Bitfields are usually defined as unsigned int.
>>>
>>> IIRC the benefit is that compiler can try to optimize those flags. I
>>> mean, if you have 32 1-bit flags, compiler will combine those in a
>>> single u32. Someone correct me if I'm wrong.
>>>
>>
>> Yes you are right. Kishon was asking me to use u8 instead of unsigned int, which
>> I don't think is necessary. AFAIK, it is a norm to use unsigned int when defining
>> a bitfield. Compilers are known to behave funny with bitfields. I don't mind
>> using bool for each.
> 
> In the current version (rogerq/v3.8-usbhost17-dt) of this patch you've
> put both needs_* into the private data struct and the pdata, but it's
> only used inside the probe function.
> 

Good catch! Will fix.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index adbb7ab..7860e7569 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -147,6 +147,10 @@  static void nop_xeiv_get_dt_pdata(struct device *dev,
 
 	if (!of_property_read_u32(node, "clock-frequency", &clk_rate))
 		pdata->clk_rate = clk_rate;
+	if (of_property_read_bool(node, "vcc-supply"))
+		pdata->needs_vcc = true;
+	if (of_property_read_bool(node, "reset-supply"))
+		pdata->needs_reset = true;
 }
 
 static int nop_usb_xceiv_probe(struct platform_device *pdev)
@@ -205,12 +209,16 @@  static int nop_usb_xceiv_probe(struct platform_device *pdev)
 	if (IS_ERR(nop->vcc)) {
 		dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
 					PTR_ERR(nop->vcc));
+		if (pdata->needs_vcc)
+			return -EPROBE_DEFER;
 	}
 
 	nop->reset = devm_regulator_get(&pdev->dev, "reset");
 	if (IS_ERR(nop->reset)) {
 		dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
 					PTR_ERR(nop->reset));
+		if (pdata->needs_reset)
+			return -EPROBE_DEFER;
 	}
 
 	nop->dev		= &pdev->dev;
diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
index 3265b61..148d351 100644
--- a/include/linux/usb/nop-usb-xceiv.h
+++ b/include/linux/usb/nop-usb-xceiv.h
@@ -6,6 +6,10 @@ 
 struct nop_usb_xceiv_platform_data {
 	enum usb_phy_type type;
 	unsigned long clk_rate;
+
+	/* if set fails with -EPROBE_DEFER if can't get regulator */
+	unsigned int needs_vcc:1;
+	unsigned int needs_reset:1;
 };
 
 #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))