linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: phy: generic: request regulator optionally
@ 2016-09-04  4:04 Stefan Agner
  2016-09-06  7:45 ` Felipe Balbi
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Agner @ 2016-09-04  4:04 UTC (permalink / raw)
  To: balbi; +Cc: gregkh, fabio.estevam, linux-usb, linux-kernel, Stefan Agner

According to the device tree bindings the vcc-supply is optional.
So far the driver did request the regulator using devm_regulator_get
which creates a dummy regulator for convenience. Since we can have
the supply unconnected, we should make use of the optional variant
of the regulator call which does not return a dummy regulator but
-ENODEV. The driver already has checks in case the regulator is an
error pointer.

Note that with this change the behavior is slightly different in
case devm_regulator_get_optional returns -EPROBE_DEFER: The driver
returns -EPROBE_DEFER even if needs_vcc is set false. This is the
correct behavior, since even if the regulator is optional, it might
get initialized later...

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
This gets rid of warnings such as this (seen on i.MX 7):
30800000.aips-bus:usbphynop1 supply vcc not found, using dummy regulator

--
Stefan

 drivers/usb/phy/phy-generic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 980c9de..38ceadc 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -275,12 +275,12 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop,
 		}
 	}
 
-	nop->vcc = devm_regulator_get(dev, "vcc");
+	nop->vcc = devm_regulator_get_optional(dev, "vcc");
 	if (IS_ERR(nop->vcc)) {
 		dev_dbg(dev, "Error getting vcc regulator: %ld\n",
 					PTR_ERR(nop->vcc));
-		if (needs_vcc)
-			return -EPROBE_DEFER;
+		if (needs_vcc || PTR_ERR(nop->vcc) == -EPROBE_DEFER)
+			return PTR_ERR(nop->vcc);
 	}
 
 	nop->dev		= dev;
-- 
2.9.0

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-04  4:04 [PATCH] usb: phy: generic: request regulator optionally Stefan Agner
@ 2016-09-06  7:45 ` Felipe Balbi
  2016-09-06  8:22   ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Felipe Balbi @ 2016-09-06  7:45 UTC (permalink / raw)
  To: Stefan Agner
  Cc: gregkh, fabio.estevam, linux-usb, linux-kernel, Stefan Agner,
	Mark Brown, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1858 bytes --]


Mark,

Stefan Agner <stefan@agner.ch> writes:
> According to the device tree bindings the vcc-supply is optional.
> So far the driver did request the regulator using devm_regulator_get
> which creates a dummy regulator for convenience. Since we can have
> the supply unconnected, we should make use of the optional variant
> of the regulator call which does not return a dummy regulator but
> -ENODEV. The driver already has checks in case the regulator is an
> error pointer.
>
> Note that with this change the behavior is slightly different in
> case devm_regulator_get_optional returns -EPROBE_DEFER: The driver
> returns -EPROBE_DEFER even if needs_vcc is set false. This is the
> correct behavior, since even if the regulator is optional, it might
> get initialized later...
>
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
> This gets rid of warnings such as this (seen on i.MX 7):
> 30800000.aips-bus:usbphynop1 supply vcc not found, using dummy regulator
>
> --
> Stefan
>
>  drivers/usb/phy/phy-generic.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
> index 980c9de..38ceadc 100644
> --- a/drivers/usb/phy/phy-generic.c
> +++ b/drivers/usb/phy/phy-generic.c
> @@ -275,12 +275,12 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop,
>  		}
>  	}
>  
> -	nop->vcc = devm_regulator_get(dev, "vcc");
> +	nop->vcc = devm_regulator_get_optional(dev, "vcc");
>  	if (IS_ERR(nop->vcc)) {
>  		dev_dbg(dev, "Error getting vcc regulator: %ld\n",
>  					PTR_ERR(nop->vcc));
> -		if (needs_vcc)
> -			return -EPROBE_DEFER;
> +		if (needs_vcc || PTR_ERR(nop->vcc) == -EPROBE_DEFER)
> +			return PTR_ERR(nop->vcc);

does this look okay from a regulator API perspective?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-06  7:45 ` Felipe Balbi
@ 2016-09-06  8:22   ` Mark Brown
  2016-09-06 18:01     ` Stefan Agner
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2016-09-06  8:22 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Stefan Agner, gregkh, fabio.estevam, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 793 bytes --]

On Tue, Sep 06, 2016 at 10:45:19AM +0300, Felipe Balbi wrote:
> Stefan Agner <stefan@agner.ch> writes:

> > According to the device tree bindings the vcc-supply is optional.

This is nonsense unless the device can work without this supply.  Given
that the supply is called VCC that doesn't seem entirely likely.

> > +	nop->vcc = devm_regulator_get_optional(dev, "vcc");
> >  	if (IS_ERR(nop->vcc)) {
> >  		dev_dbg(dev, "Error getting vcc regulator: %ld\n",
> >  					PTR_ERR(nop->vcc));
> > -		if (needs_vcc)
> > -			return -EPROBE_DEFER;
> > +		if (needs_vcc || PTR_ERR(nop->vcc) == -EPROBE_DEFER)
> > +			return PTR_ERR(nop->vcc);

> does this look okay from a regulator API perspective?

That's how to use _get_optional() but it's really unusual that you
should be using _get_optional().

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-06  8:22   ` Mark Brown
@ 2016-09-06 18:01     ` Stefan Agner
  2016-09-07  7:25       ` Roger Quadros
  2016-09-07 18:53       ` Mark Brown
  0 siblings, 2 replies; 8+ messages in thread
From: Stefan Agner @ 2016-09-06 18:01 UTC (permalink / raw)
  To: Mark Brown; +Cc: Felipe Balbi, gregkh, fabio.estevam, linux-usb, linux-kernel

On 2016-09-06 01:22, Mark Brown wrote:
> On Tue, Sep 06, 2016 at 10:45:19AM +0300, Felipe Balbi wrote:
>> Stefan Agner <stefan@agner.ch> writes:
> 
>> > According to the device tree bindings the vcc-supply is optional.
> 
> This is nonsense unless the device can work without this supply.  Given
> that the supply is called VCC that doesn't seem entirely likely.

Afaik it is kind of a generic device tree binding, I guess the physical
device can have various appearances and properties...

A quick survey showed several device trees which do not specify
vcc-supply...

That said, I checked the device at hand, and it actually has a USB PHY
power supply inputs, but the device tree does not model them.

>> > +	nop->vcc = devm_regulator_get_optional(dev, "vcc");
>> >  	if (IS_ERR(nop->vcc)) {
>> >  		dev_dbg(dev, "Error getting vcc regulator: %ld\n",
>> >  					PTR_ERR(nop->vcc));
>> > -		if (needs_vcc)
>> > -			return -EPROBE_DEFER;
>> > +		if (needs_vcc || PTR_ERR(nop->vcc) == -EPROBE_DEFER)
>> > +			return PTR_ERR(nop->vcc);
> 
>> does this look okay from a regulator API perspective?
> 
> That's how to use _get_optional() but it's really unusual that you
> should be using _get_optional().

Despite the above findings, I still think it is the right thing to do as
long as we specify vcc-supply to be optional.

--
Stefan

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-06 18:01     ` Stefan Agner
@ 2016-09-07  7:25       ` Roger Quadros
  2016-09-07  8:03         ` Felipe Balbi
  2016-09-07 18:53       ` Mark Brown
  1 sibling, 1 reply; 8+ messages in thread
From: Roger Quadros @ 2016-09-07  7:25 UTC (permalink / raw)
  To: Stefan Agner, Mark Brown
  Cc: Felipe Balbi, gregkh, fabio.estevam, linux-usb, linux-kernel

Hi Stefan,

On 06/09/16 21:01, Stefan Agner wrote:
> On 2016-09-06 01:22, Mark Brown wrote:
>> On Tue, Sep 06, 2016 at 10:45:19AM +0300, Felipe Balbi wrote:
>>> Stefan Agner <stefan@agner.ch> writes:
>>
>>>> According to the device tree bindings the vcc-supply is optional.
>>
>> This is nonsense unless the device can work without this supply.  Given
>> that the supply is called VCC that doesn't seem entirely likely.
> 
> Afaik it is kind of a generic device tree binding, I guess the physical
> device can have various appearances and properties...
> 
> A quick survey showed several device trees which do not specify
> vcc-supply...
> 
> That said, I checked the device at hand, and it actually has a USB PHY
> power supply inputs, but the device tree does not model them.
> 
>>>> +	nop->vcc = devm_regulator_get_optional(dev, "vcc");
>>>>  	if (IS_ERR(nop->vcc)) {
>>>>  		dev_dbg(dev, "Error getting vcc regulator: %ld\n",
>>>>  					PTR_ERR(nop->vcc));
>>>> -		if (needs_vcc)
>>>> -			return -EPROBE_DEFER;
>>>> +		if (needs_vcc || PTR_ERR(nop->vcc) == -EPROBE_DEFER)
>>>> +			return PTR_ERR(nop->vcc);
>>
>>> does this look okay from a regulator API perspective?
>>
>> That's how to use _get_optional() but it's really unusual that you
>> should be using _get_optional().
> 
> Despite the above findings, I still think it is the right thing to do as
> long as we specify vcc-supply to be optional.
> 

I think the right behaviour would be that if vcc-supply is specified in the
DT then failure to get that supply is a serious failure and probe should fail.

So the correct fix would be to call devm_regulator_get() only if needs_vcc is true.

cheers,
-roger

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-07  7:25       ` Roger Quadros
@ 2016-09-07  8:03         ` Felipe Balbi
  0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2016-09-07  8:03 UTC (permalink / raw)
  To: Roger Quadros, Stefan Agner, Mark Brown
  Cc: gregkh, fabio.estevam, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1748 bytes --]


Hi,

Roger Quadros <rogerq@ti.com> writes:
>>>> Stefan Agner <stefan@agner.ch> writes:
>>>
>>>>> According to the device tree bindings the vcc-supply is optional.
>>>
>>> This is nonsense unless the device can work without this supply.  Given
>>> that the supply is called VCC that doesn't seem entirely likely.
>> 
>> Afaik it is kind of a generic device tree binding, I guess the physical
>> device can have various appearances and properties...
>> 
>> A quick survey showed several device trees which do not specify
>> vcc-supply...
>> 
>> That said, I checked the device at hand, and it actually has a USB PHY
>> power supply inputs, but the device tree does not model them.
>> 
>>>>> +	nop->vcc = devm_regulator_get_optional(dev, "vcc");
>>>>>  	if (IS_ERR(nop->vcc)) {
>>>>>  		dev_dbg(dev, "Error getting vcc regulator: %ld\n",
>>>>>  					PTR_ERR(nop->vcc));
>>>>> -		if (needs_vcc)
>>>>> -			return -EPROBE_DEFER;
>>>>> +		if (needs_vcc || PTR_ERR(nop->vcc) == -EPROBE_DEFER)
>>>>> +			return PTR_ERR(nop->vcc);
>>>
>>>> does this look okay from a regulator API perspective?
>>>
>>> That's how to use _get_optional() but it's really unusual that you
>>> should be using _get_optional().
>> 
>> Despite the above findings, I still think it is the right thing to do as
>> long as we specify vcc-supply to be optional.
>> 
>
> I think the right behaviour would be that if vcc-supply is specified
> in the DT then failure to get that supply is a serious failure and
> probe should fail.
>
> So the correct fix would be to call devm_regulator_get() only if
> needs_vcc is true.

The way it is, AFAICT, regulator fwk will return a dummy regulator for
cases where supply isn't in DT.

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-06 18:01     ` Stefan Agner
  2016-09-07  7:25       ` Roger Quadros
@ 2016-09-07 18:53       ` Mark Brown
  2016-09-07 20:32         ` Stefan Agner
  1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2016-09-07 18:53 UTC (permalink / raw)
  To: Stefan Agner; +Cc: Felipe Balbi, gregkh, fabio.estevam, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1531 bytes --]

On Tue, Sep 06, 2016 at 11:01:15AM -0700, Stefan Agner wrote:
> On 2016-09-06 01:22, Mark Brown wrote:

> > This is nonsense unless the device can work without this supply.  Given
> > that the supply is called VCC that doesn't seem entirely likely.

> Afaik it is kind of a generic device tree binding, I guess the physical
> device can have various appearances and properties...

Is it really realistic that a meaningful proportion of them will work
without power?

> A quick survey showed several device trees which do not specify
> vcc-supply...

The regulator framework will attempt to be forgiving in what it accepts,
the absence of a mandatory supply is sadly not a good indication that
the supply does not physically exist...

> That said, I checked the device at hand, and it actually has a USB PHY
> power supply inputs, but the device tree does not model them.

...like here.

> > That's how to use _get_optional() but it's really unusual that you
> > should be using _get_optional().

> Despite the above findings, I still think it is the right thing to do as
> long as we specify vcc-supply to be optional.

I disagree, and bear in mind that it is more complex all round to handle
optional supples - the reason they exist is that on devices where
supplies may be omitted you usually have to do some kind of special case
handling (like enabling internal regulators or something).  If you don't
have any such special case handling but instead simply omit enables and
disables then that's a fairly clear abuse of the API.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

* Re: [PATCH] usb: phy: generic: request regulator optionally
  2016-09-07 18:53       ` Mark Brown
@ 2016-09-07 20:32         ` Stefan Agner
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Agner @ 2016-09-07 20:32 UTC (permalink / raw)
  To: Mark Brown, Felipe Balbi; +Cc: gregkh, fabio.estevam, linux-usb, linux-kernel

On 2016-09-07 11:53, Mark Brown wrote:
> On Tue, Sep 06, 2016 at 11:01:15AM -0700, Stefan Agner wrote:
>> On 2016-09-06 01:22, Mark Brown wrote:
> 
>> > This is nonsense unless the device can work without this supply.  Given
>> > that the supply is called VCC that doesn't seem entirely likely.
> 
>> Afaik it is kind of a generic device tree binding, I guess the physical
>> device can have various appearances and properties...
> 
> Is it really realistic that a meaningful proportion of them will work
> without power?
> 

No IP in a SoC runs without power, but still we don't model the supply
to every IP....

I would have guessed that there are SoCs with an internal USB PHY which
are powered implicitly by the SoC, and/or it is unclear how they exactly
get powered... If we make the supply mandatory, we can only guess how it
is wired up and probably end up to assign some "global" SoC supply
regulator.

>> A quick survey showed several device trees which do not specify
>> vcc-supply...
> 
> The regulator framework will attempt to be forgiving in what it accepts,
> the absence of a mandatory supply is sadly not a good indication that
> the supply does not physically exist...
> 
>> That said, I checked the device at hand, and it actually has a USB PHY
>> power supply inputs, but the device tree does not model them.
> 
> ...like here.
> 
>> > That's how to use _get_optional() but it's really unusual that you
>> > should be using _get_optional().
> 
>> Despite the above findings, I still think it is the right thing to do as
>> long as we specify vcc-supply to be optional.
> 
> I disagree, and bear in mind that it is more complex all round to handle
> optional supples - the reason they exist is that on devices where
> supplies may be omitted you usually have to do some kind of special case
> handling (like enabling internal regulators or something).  If you don't
> have any such special case handling but instead simply omit enables and
> disables then that's a fairly clear abuse of the API.

Note that in this case the code already supports an optional supply e.g.
when it has not specified via platform data. The code does not do any
special in that case, it is assumed to be implicitly powered.

I am not really a USB PHY experts and don't have a good overview of what
is out there, I just did a short survey across the device trees we have,
and found some which were lacking the vcc-supply. I guess Felipe has a
better overview and just should make a call on that matter.

In case we decide to make vcc-supply mandatory for the device tree case,
I will send a new patch altering the bindings documentation accordingly
and get rid of the needs_vcc = of_property_read_bool(node,
"vcc-supply");. This should not break existing device trees since
devm_regulator_get returns the dummy regulators.

--
Stefan

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

end of thread, other threads:[~2016-09-07 20:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-04  4:04 [PATCH] usb: phy: generic: request regulator optionally Stefan Agner
2016-09-06  7:45 ` Felipe Balbi
2016-09-06  8:22   ` Mark Brown
2016-09-06 18:01     ` Stefan Agner
2016-09-07  7:25       ` Roger Quadros
2016-09-07  8:03         ` Felipe Balbi
2016-09-07 18:53       ` Mark Brown
2016-09-07 20:32         ` Stefan Agner

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).