diff mbox

[4/4] usb: phy: omap-usb2: enable 960Mhz clock for omap5

Message ID 1348054229-27362-5-git-send-email-kishon@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kishon Vijay Abraham I Sept. 19, 2012, 11:30 a.m. UTC
"usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
omap4, the clk_get of this clock will fail since it does not have this
clock.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
 drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

Comments

Felipe Balbi Sept. 19, 2012, 11:56 a.m. UTC | #1
On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
> omap4, the clk_get of this clock will fail since it does not have this
> clock.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
>  2 files changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
> index 7c5fd89..d5626de 100644
> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
> @@ -24,6 +24,9 @@ Required properties:
>  add the address of control module phy power register until a driver for
>  control module is added
>  
> +Optional properties:
> + - has960mhzclk: should be added if the phy needs 960mhz clock
> +
>  This is usually a subnode of ocp2scp to which it is connected.
>  
>  usb3phy@4a084400 {
> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
> index d36c282..d6612ba 100644
> --- a/drivers/usb/phy/omap-usb2.c
> +++ b/drivers/usb/phy/omap-usb2.c
> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>  	struct omap_usb			*phy;
>  	struct usb_otg			*otg;
>  	struct resource			*res;
> +	struct device_node		*np = pdev->dev.of_node;
>  
>  	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
>  	if (!phy) {
> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>  	}
>  	clk_prepare(phy->wkupclk);
>  
> +	if (of_property_read_bool(np, "has960mhzclk")) {
> +		phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
> +		if (IS_ERR(phy->optclk)) {
> +			dev_err(&pdev->dev, "unable to get refclk960m\n");
> +			return PTR_ERR(phy->optclk);
> +		}
> +		clk_prepare(phy->optclk);
> +	}

instead, can't you just always try to get the clock but ignore the error
if it fails ?

If it works you can set a flag to let you know that you can use that
optional clock.
Felipe Balbi Sept. 19, 2012, 2:42 p.m. UTC | #2
On Wed, Sep 19, 2012 at 04:45:01PM +0200, Marc Kleine-Budde wrote:
> On 09/19/2012 01:56 PM, Felipe Balbi wrote:
> > On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
> >> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
> >> omap4, the clk_get of this clock will fail since it does not have this
> >> clock.
> >>
> >> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> >> ---
> >>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
> >>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
> >>  2 files changed, 30 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> index 7c5fd89..d5626de 100644
> >> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> @@ -24,6 +24,9 @@ Required properties:
> >>  add the address of control module phy power register until a driver for
> >>  control module is added
> >>  
> >> +Optional properties:
> >> + - has960mhzclk: should be added if the phy needs 960mhz clock
> >> +
> >>  This is usually a subnode of ocp2scp to which it is connected.
> >>  
> >>  usb3phy@4a084400 {
> >> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
> >> index d36c282..d6612ba 100644
> >> --- a/drivers/usb/phy/omap-usb2.c
> >> +++ b/drivers/usb/phy/omap-usb2.c
> >> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
> >>  	struct omap_usb			*phy;
> >>  	struct usb_otg			*otg;
> >>  	struct resource			*res;
> >> +	struct device_node		*np = pdev->dev.of_node;
> >>  
> >>  	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
> >>  	if (!phy) {
> >> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
> >>  	}
> >>  	clk_prepare(phy->wkupclk);
> >>  
> >> +	if (of_property_read_bool(np, "has960mhzclk")) {
> >> +		phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
> >> +		if (IS_ERR(phy->optclk)) {
> >> +			dev_err(&pdev->dev, "unable to get refclk960m\n");
> >> +			return PTR_ERR(phy->optclk);
> >> +		}
> >> +		clk_prepare(phy->optclk);
> >> +	}
> > 
> > instead, can't you just always try to get the clock but ignore the error
> > if it fails ?
> 
> On imx we add no-op dummy clocks, so that the drivers will always find
> all needed clocks. If a clk_get fails it's an error.

It's an error from a clk API point of view, it doesn't mean device can't
work without that optional clock. Drivers are free to treat errors
however they like, even by ignoring it and defaulting to some other
behavior.

Adding dummy clocks just bloats the kernel with useless data IMHO.

my 2 cents.
Marc Kleine-Budde Sept. 19, 2012, 2:45 p.m. UTC | #3
On 09/19/2012 01:56 PM, Felipe Balbi wrote:
> On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
>> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
>> omap4, the clk_get of this clock will fail since it does not have this
>> clock.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
>>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
>>  2 files changed, 30 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> index 7c5fd89..d5626de 100644
>> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
>> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> @@ -24,6 +24,9 @@ Required properties:
>>  add the address of control module phy power register until a driver for
>>  control module is added
>>  
>> +Optional properties:
>> + - has960mhzclk: should be added if the phy needs 960mhz clock
>> +
>>  This is usually a subnode of ocp2scp to which it is connected.
>>  
>>  usb3phy@4a084400 {
>> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
>> index d36c282..d6612ba 100644
>> --- a/drivers/usb/phy/omap-usb2.c
>> +++ b/drivers/usb/phy/omap-usb2.c
>> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>>  	struct omap_usb			*phy;
>>  	struct usb_otg			*otg;
>>  	struct resource			*res;
>> +	struct device_node		*np = pdev->dev.of_node;
>>  
>>  	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
>>  	if (!phy) {
>> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>>  	}
>>  	clk_prepare(phy->wkupclk);
>>  
>> +	if (of_property_read_bool(np, "has960mhzclk")) {
>> +		phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
>> +		if (IS_ERR(phy->optclk)) {
>> +			dev_err(&pdev->dev, "unable to get refclk960m\n");
>> +			return PTR_ERR(phy->optclk);
>> +		}
>> +		clk_prepare(phy->optclk);
>> +	}
> 
> instead, can't you just always try to get the clock but ignore the error
> if it fails ?

On imx we add no-op dummy clocks, so that the drivers will always find
all needed clocks. If a clk_get fails it's an error.

> If it works you can set a flag to let you know that you can use that
> optional clock.

Marc
Marc Kleine-Budde Sept. 19, 2012, 2:50 p.m. UTC | #4
On 09/19/2012 04:42 PM, Felipe Balbi wrote:
> On Wed, Sep 19, 2012 at 04:45:01PM +0200, Marc Kleine-Budde wrote:
>> On 09/19/2012 01:56 PM, Felipe Balbi wrote:
>>> On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
>>>> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
>>>> omap4, the clk_get of this clock will fail since it does not have this
>>>> clock.
>>>>
>>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>>> ---
>>>>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
>>>>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
>>>>  2 files changed, 30 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
>>>> index 7c5fd89..d5626de 100644
>>>> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
>>>> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
>>>> @@ -24,6 +24,9 @@ Required properties:
>>>>  add the address of control module phy power register until a driver for
>>>>  control module is added
>>>>  
>>>> +Optional properties:
>>>> + - has960mhzclk: should be added if the phy needs 960mhz clock
>>>> +
>>>>  This is usually a subnode of ocp2scp to which it is connected.
>>>>  
>>>>  usb3phy@4a084400 {
>>>> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
>>>> index d36c282..d6612ba 100644
>>>> --- a/drivers/usb/phy/omap-usb2.c
>>>> +++ b/drivers/usb/phy/omap-usb2.c
>>>> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>>>>  	struct omap_usb			*phy;
>>>>  	struct usb_otg			*otg;
>>>>  	struct resource			*res;
>>>> +	struct device_node		*np = pdev->dev.of_node;
>>>>  
>>>>  	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
>>>>  	if (!phy) {
>>>> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>>>>  	}
>>>>  	clk_prepare(phy->wkupclk);
>>>>  
>>>> +	if (of_property_read_bool(np, "has960mhzclk")) {
>>>> +		phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
>>>> +		if (IS_ERR(phy->optclk)) {
>>>> +			dev_err(&pdev->dev, "unable to get refclk960m\n");
>>>> +			return PTR_ERR(phy->optclk);
>>>> +		}
>>>> +		clk_prepare(phy->optclk);
>>>> +	}
>>>
>>> instead, can't you just always try to get the clock but ignore the error
>>> if it fails ?
>>
>> On imx we add no-op dummy clocks, so that the drivers will always find
>> all needed clocks. If a clk_get fails it's an error.
> 
> It's an error from a clk API point of view, it doesn't mean device can't
> work without that optional clock. Drivers are free to treat errors
> however they like, even by ignoring it and defaulting to some other
> behavior.

Sure.

> Adding dummy clocks just bloats the kernel with useless data IMHO.

Just wanted to point out there's more than one way to do it.

Marc
Kishon Vijay Abraham I Sept. 26, 2012, 5:40 a.m. UTC | #5
Hi,

On Wed, Sep 19, 2012 at 5:26 PM, Felipe Balbi <balbi@ti.com> wrote:
> On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
>> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
>> omap4, the clk_get of this clock will fail since it does not have this
>> clock.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
>>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
>>  2 files changed, 30 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> index 7c5fd89..d5626de 100644
>> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
>> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> @@ -24,6 +24,9 @@ Required properties:
>>  add the address of control module phy power register until a driver for
>>  control module is added
>>
>> +Optional properties:
>> + - has960mhzclk: should be added if the phy needs 960mhz clock
>> +
>>  This is usually a subnode of ocp2scp to which it is connected.
>>
>>  usb3phy@4a084400 {
>> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
>> index d36c282..d6612ba 100644
>> --- a/drivers/usb/phy/omap-usb2.c
>> +++ b/drivers/usb/phy/omap-usb2.c
>> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>>       struct omap_usb                 *phy;
>>       struct usb_otg                  *otg;
>>       struct resource                 *res;
>> +     struct device_node              *np = pdev->dev.of_node;
>>
>>       phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
>>       if (!phy) {
>> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>>       }
>>       clk_prepare(phy->wkupclk);
>>
>> +     if (of_property_read_bool(np, "has960mhzclk")) {
>> +             phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
>> +             if (IS_ERR(phy->optclk)) {
>> +                     dev_err(&pdev->dev, "unable to get refclk960m\n");
>> +                     return PTR_ERR(phy->optclk);
>> +             }
>> +             clk_prepare(phy->optclk);
>> +     }
>
> instead, can't you just always try to get the clock but ignore the error
> if it fails ?

This clock is needed for usb2 to work in dwc3 (omap5). So we have to
report the error in case we dont get the clock no?

Thanks
Kishon
Felipe Balbi Sept. 26, 2012, 6:27 p.m. UTC | #6
Hi,

On Wed, Sep 26, 2012 at 11:10:48AM +0530, ABRAHAM, KISHON VIJAY wrote:
> Hi,
> 
> On Wed, Sep 19, 2012 at 5:26 PM, Felipe Balbi <balbi@ti.com> wrote:
> > On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
> >> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
> >> omap4, the clk_get of this clock will fail since it does not have this
> >> clock.
> >>
> >> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> >> ---
> >>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
> >>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
> >>  2 files changed, 30 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> index 7c5fd89..d5626de 100644
> >> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> @@ -24,6 +24,9 @@ Required properties:
> >>  add the address of control module phy power register until a driver for
> >>  control module is added
> >>
> >> +Optional properties:
> >> + - has960mhzclk: should be added if the phy needs 960mhz clock
> >> +
> >>  This is usually a subnode of ocp2scp to which it is connected.
> >>
> >>  usb3phy@4a084400 {
> >> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
> >> index d36c282..d6612ba 100644
> >> --- a/drivers/usb/phy/omap-usb2.c
> >> +++ b/drivers/usb/phy/omap-usb2.c
> >> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
> >>       struct omap_usb                 *phy;
> >>       struct usb_otg                  *otg;
> >>       struct resource                 *res;
> >> +     struct device_node              *np = pdev->dev.of_node;
> >>
> >>       phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
> >>       if (!phy) {
> >> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
> >>       }
> >>       clk_prepare(phy->wkupclk);
> >>
> >> +     if (of_property_read_bool(np, "has960mhzclk")) {
> >> +             phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
> >> +             if (IS_ERR(phy->optclk)) {
> >> +                     dev_err(&pdev->dev, "unable to get refclk960m\n");
> >> +                     return PTR_ERR(phy->optclk);
> >> +             }
> >> +             clk_prepare(phy->optclk);
> >> +     }
> >
> > instead, can't you just always try to get the clock but ignore the error
> > if it fails ?
> 
> This clock is needed for usb2 to work in dwc3 (omap5). So we have to
> report the error in case we dont get the clock no?

sure, but you don't need to bail out. Print a warning message such as:

dev_dbg(&pdev->dev, "couldn't get refclk960m, trying without\n");

or something similar. Then you don't need to add this has960mhzclk flag
to dts files.
Kishon Vijay Abraham I Sept. 27, 2012, 5:13 a.m. UTC | #7
Hi,

On Wed, Sep 26, 2012 at 11:57 PM, Felipe Balbi <balbi@ti.com> wrote:
> Hi,
>
> On Wed, Sep 26, 2012 at 11:10:48AM +0530, ABRAHAM, KISHON VIJAY wrote:
>> Hi,
>>
>> On Wed, Sep 19, 2012 at 5:26 PM, Felipe Balbi <balbi@ti.com> wrote:
>> > On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
>> >> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
>> >> omap4, the clk_get of this clock will fail since it does not have this
>> >> clock.
>> >>
>> >> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> >> ---
>> >>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
>> >>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
>> >>  2 files changed, 30 insertions(+), 1 deletion(-)
>> >>
>> >> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> >> index 7c5fd89..d5626de 100644
>> >> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
>> >> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> >> @@ -24,6 +24,9 @@ Required properties:
>> >>  add the address of control module phy power register until a driver for
>> >>  control module is added
>> >>
>> >> +Optional properties:
>> >> + - has960mhzclk: should be added if the phy needs 960mhz clock
>> >> +
>> >>  This is usually a subnode of ocp2scp to which it is connected.
>> >>
>> >>  usb3phy@4a084400 {
>> >> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
>> >> index d36c282..d6612ba 100644
>> >> --- a/drivers/usb/phy/omap-usb2.c
>> >> +++ b/drivers/usb/phy/omap-usb2.c
>> >> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>> >>       struct omap_usb                 *phy;
>> >>       struct usb_otg                  *otg;
>> >>       struct resource                 *res;
>> >> +     struct device_node              *np = pdev->dev.of_node;
>> >>
>> >>       phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
>> >>       if (!phy) {
>> >> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
>> >>       }
>> >>       clk_prepare(phy->wkupclk);
>> >>
>> >> +     if (of_property_read_bool(np, "has960mhzclk")) {
>> >> +             phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
>> >> +             if (IS_ERR(phy->optclk)) {
>> >> +                     dev_err(&pdev->dev, "unable to get refclk960m\n");
>> >> +                     return PTR_ERR(phy->optclk);
>> >> +             }
>> >> +             clk_prepare(phy->optclk);
>> >> +     }
>> >
>> > instead, can't you just always try to get the clock but ignore the error
>> > if it fails ?
>>
>> This clock is needed for usb2 to work in dwc3 (omap5). So we have to
>> report the error in case we dont get the clock no?
>
> sure, but you don't need to bail out. Print a warning message such as:
>
> dev_dbg(&pdev->dev, "couldn't get refclk960m, trying without\n");

but then we'll get this debug message for omap4 which actually doesn't
need 960m clk.

Thanks
Kishon
Felipe Balbi Sept. 27, 2012, 5:13 a.m. UTC | #8
On Thu, Sep 27, 2012 at 10:43:06AM +0530, ABRAHAM, KISHON VIJAY wrote:
> Hi,
> 
> On Wed, Sep 26, 2012 at 11:57 PM, Felipe Balbi <balbi@ti.com> wrote:
> > Hi,
> >
> > On Wed, Sep 26, 2012 at 11:10:48AM +0530, ABRAHAM, KISHON VIJAY wrote:
> >> Hi,
> >>
> >> On Wed, Sep 19, 2012 at 5:26 PM, Felipe Balbi <balbi@ti.com> wrote:
> >> > On Wed, Sep 19, 2012 at 05:00:29PM +0530, Kishon Vijay Abraham I wrote:
> >> >> "usb_otg_ss_refclk960m" is needed by usb2 phy present in omap5. For
> >> >> omap4, the clk_get of this clock will fail since it does not have this
> >> >> clock.
> >> >>
> >> >> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> >> >> ---
> >> >>  Documentation/devicetree/bindings/usb/usb-phy.txt |    3 +++
> >> >>  drivers/usb/phy/omap-usb2.c                       |   28 ++++++++++++++++++++-
> >> >>  2 files changed, 30 insertions(+), 1 deletion(-)
> >> >>
> >> >> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> >> index 7c5fd89..d5626de 100644
> >> >> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> >> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
> >> >> @@ -24,6 +24,9 @@ Required properties:
> >> >>  add the address of control module phy power register until a driver for
> >> >>  control module is added
> >> >>
> >> >> +Optional properties:
> >> >> + - has960mhzclk: should be added if the phy needs 960mhz clock
> >> >> +
> >> >>  This is usually a subnode of ocp2scp to which it is connected.
> >> >>
> >> >>  usb3phy@4a084400 {
> >> >> diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
> >> >> index d36c282..d6612ba 100644
> >> >> --- a/drivers/usb/phy/omap-usb2.c
> >> >> +++ b/drivers/usb/phy/omap-usb2.c
> >> >> @@ -146,6 +146,7 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
> >> >>       struct omap_usb                 *phy;
> >> >>       struct usb_otg                  *otg;
> >> >>       struct resource                 *res;
> >> >> +     struct device_node              *np = pdev->dev.of_node;
> >> >>
> >> >>       phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
> >> >>       if (!phy) {
> >> >> @@ -190,6 +191,15 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
> >> >>       }
> >> >>       clk_prepare(phy->wkupclk);
> >> >>
> >> >> +     if (of_property_read_bool(np, "has960mhzclk")) {
> >> >> +             phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
> >> >> +             if (IS_ERR(phy->optclk)) {
> >> >> +                     dev_err(&pdev->dev, "unable to get refclk960m\n");
> >> >> +                     return PTR_ERR(phy->optclk);
> >> >> +             }
> >> >> +             clk_prepare(phy->optclk);
> >> >> +     }
> >> >
> >> > instead, can't you just always try to get the clock but ignore the error
> >> > if it fails ?
> >>
> >> This clock is needed for usb2 to work in dwc3 (omap5). So we have to
> >> report the error in case we dont get the clock no?
> >
> > sure, but you don't need to bail out. Print a warning message such as:
> >
> > dev_dbg(&pdev->dev, "couldn't get refclk960m, trying without\n");
> 
> but then we'll get this debug message for omap4 which actually doesn't
> need 960m clk.

then make it dev_vdbg(). It's just a debugging message, it's not saying
it will fail, it's just stating that clock isn't present and we're
trying without because it's known that some versions don't need that
clock.

Another way to do it, would be to request or not the extra clock, based
on the Revision Register (if this IP has one).
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 7c5fd89..d5626de 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -24,6 +24,9 @@  Required properties:
 add the address of control module phy power register until a driver for
 control module is added
 
+Optional properties:
+ - has960mhzclk: should be added if the phy needs 960mhz clock
+
 This is usually a subnode of ocp2scp to which it is connected.
 
 usb3phy@4a084400 {
diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
index d36c282..d6612ba 100644
--- a/drivers/usb/phy/omap-usb2.c
+++ b/drivers/usb/phy/omap-usb2.c
@@ -146,6 +146,7 @@  static int __devinit omap_usb2_probe(struct platform_device *pdev)
 	struct omap_usb			*phy;
 	struct usb_otg			*otg;
 	struct resource			*res;
+	struct device_node		*np = pdev->dev.of_node;
 
 	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
 	if (!phy) {
@@ -190,6 +191,15 @@  static int __devinit omap_usb2_probe(struct platform_device *pdev)
 	}
 	clk_prepare(phy->wkupclk);
 
+	if (of_property_read_bool(np, "has960mhzclk")) {
+		phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
+		if (IS_ERR(phy->optclk)) {
+			dev_err(&pdev->dev, "unable to get refclk960m\n");
+			return PTR_ERR(phy->optclk);
+		}
+		clk_prepare(phy->optclk);
+	}
+
 	usb_add_phy(&phy->phy, USB_PHY_TYPE_USB2);
 
 	platform_set_drvdata(pdev, phy);
@@ -204,6 +214,7 @@  static int __devexit omap_usb2_remove(struct platform_device *pdev)
 	struct omap_usb	*phy = platform_get_drvdata(pdev);
 
 	clk_unprepare(phy->wkupclk);
+	clk_unprepare(phy->optclk);
 	usb_remove_phy(&phy->phy);
 
 	return 0;
@@ -217,6 +228,7 @@  static int omap_usb2_runtime_suspend(struct device *dev)
 	struct omap_usb	*phy = platform_get_drvdata(pdev);
 
 	clk_disable(phy->wkupclk);
+	clk_disable(phy->optclk);
 
 	return 0;
 }
@@ -228,8 +240,22 @@  static int omap_usb2_runtime_resume(struct device *dev)
 	struct omap_usb	*phy = platform_get_drvdata(pdev);
 
 	ret = clk_enable(phy->wkupclk);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret);
+		return ret;
+	}
+
+	if (phy->optclk) {
+		ret = clk_enable(phy->optclk);
+		if (ret) {
+			dev_err(phy->dev, "Failed to enable optclk %d\n", ret);
+			goto err;
+		}
+	}
+
+	return 0;
+err:
+	clk_disable(phy->wkupclk);
 
 	return ret;
 }