linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-02-14 16:34 Jon Hunter
  0 siblings, 0 replies; 7+ messages in thread
From: Jon Hunter @ 2018-02-14 16:34 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Thierry Reding
  Cc: linux-usb, linux-tegra, linux-kernel, Jon Hunter

Add runtime PM support to the Tegra XHCI driver and move the function
calls to enable/disable the clocks, regulators and PHY into the runtime
PM callbacks.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
 drivers/usb/host/xhci-tegra.c | 80 ++++++++++++++++++++++++++++++-------------
 1 file changed, 56 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 02b0b24faa58..42aa67858b53 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -18,6 +18,7 @@
 #include <linux/phy/tegra/xusb.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
+#include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
 #include <linux/reset.h>
 #include <linux/slab.h>
@@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct platform_device *pdev)
 	 */
 	platform_set_drvdata(pdev, tegra);
 
-	err = tegra_xusb_clk_enable(tegra);
-	if (err) {
-		dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
-		goto put_usb2;
-	}
-
-	err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies);
-	if (err) {
-		dev_err(&pdev->dev, "failed to enable regulators: %d\n", err);
-		goto disable_clk;
-	}
+	pm_runtime_enable(&pdev->dev);
 
-	err = tegra_xusb_phy_enable(tegra);
+	err = pm_runtime_get_sync(&pdev->dev);
 	if (err < 0) {
-		dev_err(&pdev->dev, "failed to enable PHYs: %d\n", err);
-		goto disable_regulator;
+		dev_err(&pdev->dev, "failed to enable device: %d\n", err);
+		goto disable_rpm;
 	}
 
 	tegra_xusb_ipfs_config(tegra, regs);
@@ -1090,7 +1081,7 @@ static int tegra_xusb_probe(struct platform_device *pdev)
 	err = tegra_xusb_load_firmware(tegra);
 	if (err < 0) {
 		dev_err(&pdev->dev, "failed to load firmware: %d\n", err);
-		goto disable_phy;
+		goto put_rpm;
 	}
 
 	tegra->hcd->regs = tegra->regs;
@@ -1100,7 +1091,7 @@ static int tegra_xusb_probe(struct platform_device *pdev)
 	err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED);
 	if (err < 0) {
 		dev_err(&pdev->dev, "failed to add USB HCD: %d\n", err);
-		goto disable_phy;
+		goto put_rpm;
 	}
 
 	device_wakeup_enable(tegra->hcd->self.controller);
@@ -1155,13 +1146,10 @@ static int tegra_xusb_probe(struct platform_device *pdev)
 	usb_put_hcd(xhci->shared_hcd);
 remove_usb2:
 	usb_remove_hcd(tegra->hcd);
-disable_phy:
-	tegra_xusb_phy_disable(tegra);
-disable_regulator:
-	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
-disable_clk:
-	tegra_xusb_clk_disable(tegra);
-put_usb2:
+put_rpm:
+	pm_runtime_put_sync(&pdev->dev);
+disable_rpm:
+	pm_runtime_disable(&pdev->dev);
 	usb_put_hcd(tegra->hcd);
 put_padctl:
 	tegra_xusb_padctl_put(tegra->padctl);
@@ -1181,13 +1169,55 @@ static int tegra_xusb_remove(struct platform_device *pdev)
 	dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt,
 			  tegra->fw.phys);
 
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
+	tegra_xusb_padctl_put(tegra->padctl);
+
+	return 0;
+}
+
+static int tegra_xusb_runtime_suspend(struct device *dev)
+{
+	struct tegra_xusb *tegra = dev_get_drvdata(dev);
+
 	tegra_xusb_phy_disable(tegra);
 	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
 	tegra_xusb_clk_disable(tegra);
 
-	tegra_xusb_padctl_put(tegra->padctl);
+	return 0;
+}
+
+static int tegra_xusb_runtime_resume(struct device *dev)
+{
+	struct tegra_xusb *tegra = dev_get_drvdata(dev);
+	int err;
+
+	err = tegra_xusb_clk_enable(tegra);
+	if (err) {
+		dev_err(dev, "failed to enable clocks: %d\n", err);
+		return err;
+	}
+
+	err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies);
+	if (err) {
+		dev_err(dev, "failed to enable regulators: %d\n", err);
+		goto disable_clk;
+	}
+
+	err = tegra_xusb_phy_enable(tegra);
+	if (err < 0) {
+		dev_err(dev, "failed to enable PHYs: %d\n", err);
+		goto disable_regulator;
+	}
 
 	return 0;
+
+disable_regulator:
+	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+disable_clk:
+	tegra_xusb_clk_disable(tegra);
+	return err;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -1211,6 +1241,8 @@ static int tegra_xusb_resume(struct device *dev)
 #endif
 
 static const struct dev_pm_ops tegra_xusb_pm_ops = {
+	SET_RUNTIME_PM_OPS(tegra_xusb_runtime_suspend,
+			   tegra_xusb_runtime_resume, NULL)
 	SET_SYSTEM_SLEEP_PM_OPS(tegra_xusb_suspend, tegra_xusb_resume)
 };
 

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

* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-03-01 14:18 Mathias Nyman
  0 siblings, 0 replies; 7+ messages in thread
From: Mathias Nyman @ 2018-03-01 14:18 UTC (permalink / raw)
  To: Jon Hunter, Mathias Nyman, Greg Kroah-Hartman, Thierry Reding
  Cc: linux-usb, linux-tegra, linux-kernel

On 14.02.2018 18:34, Jon Hunter wrote:
> Add runtime PM support to the Tegra XHCI driver and move the function
> calls to enable/disable the clocks, regulators and PHY into the runtime
> PM callbacks.
> 
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
>   drivers/usb/host/xhci-tegra.c | 80 ++++++++++++++++++++++++++++++-------------
>   1 file changed, 56 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
> index 02b0b24faa58..42aa67858b53 100644
> --- a/drivers/usb/host/xhci-tegra.c
> +++ b/drivers/usb/host/xhci-tegra.c
> @@ -18,6 +18,7 @@
>   #include <linux/phy/tegra/xusb.h>
>   #include <linux/platform_device.h>
>   #include <linux/pm.h>
> +#include <linux/pm_runtime.h>
>   #include <linux/regulator/consumer.h>
>   #include <linux/reset.h>
>   #include <linux/slab.h>
> @@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct platform_device *pdev)
>   	 */
>   	platform_set_drvdata(pdev, tegra);
>   
> -	err = tegra_xusb_clk_enable(tegra);
> -	if (err) {
> -		dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
> -		goto put_usb2;
> -	}
> -
> -	err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies);
> -	if (err) {
> -		dev_err(&pdev->dev, "failed to enable regulators: %d\n", err);
> -		goto disable_clk;
> -	}
> +	pm_runtime_enable(&pdev->dev);
>   
> -	err = tegra_xusb_phy_enable(tegra);
> +	err = pm_runtime_get_sync(&pdev->dev);
>   	if (err < 0) {

Does this mean that if runtime PM is disabled then clocks and regulator will never be enabled
for Tegra xhci?

How about keeping the clock and regualtor enabling in probe, and instead add something like:

pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
pm_runtime_get_noresume(&pdev->dev);

-Mathias
---
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

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

* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-03-08 21:31 Jon Hunter
  0 siblings, 0 replies; 7+ messages in thread
From: Jon Hunter @ 2018-03-08 21:31 UTC (permalink / raw)
  To: Mathias Nyman, Mathias Nyman, Greg Kroah-Hartman, Thierry Reding
  Cc: linux-usb, linux-tegra, linux-kernel

On 01/03/18 14:18, Mathias Nyman wrote:
> On 14.02.2018 18:34, Jon Hunter wrote:
>> Add runtime PM support to the Tegra XHCI driver and move the function
>> calls to enable/disable the clocks, regulators and PHY into the runtime
>> PM callbacks.
>>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>> ---
>>   drivers/usb/host/xhci-tegra.c | 80
>> ++++++++++++++++++++++++++++++-------------
>>   1 file changed, 56 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/usb/host/xhci-tegra.c
>> b/drivers/usb/host/xhci-tegra.c
>> index 02b0b24faa58..42aa67858b53 100644
>> --- a/drivers/usb/host/xhci-tegra.c
>> +++ b/drivers/usb/host/xhci-tegra.c
>> @@ -18,6 +18,7 @@
>>   #include <linux/phy/tegra/xusb.h>
>>   #include <linux/platform_device.h>
>>   #include <linux/pm.h>
>> +#include <linux/pm_runtime.h>
>>   #include <linux/regulator/consumer.h>
>>   #include <linux/reset.h>
>>   #include <linux/slab.h>
>> @@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct
>> platform_device *pdev)
>>        */
>>       platform_set_drvdata(pdev, tegra);
>>   -    err = tegra_xusb_clk_enable(tegra);
>> -    if (err) {
>> -        dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
>> -        goto put_usb2;
>> -    }
>> -
>> -    err = regulator_bulk_enable(tegra->soc->num_supplies,
>> tegra->supplies);
>> -    if (err) {
>> -        dev_err(&pdev->dev, "failed to enable regulators: %d\n", err);
>> -        goto disable_clk;
>> -    }
>> +    pm_runtime_enable(&pdev->dev);
>>   -    err = tegra_xusb_phy_enable(tegra);
>> +    err = pm_runtime_get_sync(&pdev->dev);
>>       if (err < 0) {
> 
> Does this mean that if runtime PM is disabled then clocks and regulator
> will never be enabled
> for Tegra xhci?
> 
> How about keeping the clock and regualtor enabling in probe, and instead
> add something like:
> 
> pm_runtime_set_active(&pdev->dev);
> pm_runtime_enable(&pdev->dev);
> pm_runtime_get_noresume(&pdev->dev);

For 64-bit Tegra there is a dependency on CONFIG_PM, but for 32-bit
AFAIK there is not and so yes we should handle the case when PM_RUNTIME
is disabled.

Typically we do something like ...

    pm_runtime_enable(&pdev->dev);
    if (!pm_runtime_enabled(&pdev->dev))
	ret = tegra_xusb_runtime_resume(&pdev->dev);
    else
        ret = pm_runtime_get_sync(&pdev->dev);

That way we can keep the regulator and clock stuff in the handler. I
will update this series.

Cheers
Jon

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

* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-03-09  8:36 Thierry Reding
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2018-03-09  8:36 UTC (permalink / raw)
  To: Jon Hunter
  Cc: Mathias Nyman, Mathias Nyman, Greg Kroah-Hartman, linux-usb,
	linux-tegra, linux-kernel

On Thu, Mar 08, 2018 at 09:31:07PM +0000, Jon Hunter wrote:
> 
> On 01/03/18 14:18, Mathias Nyman wrote:
> > On 14.02.2018 18:34, Jon Hunter wrote:
> >> Add runtime PM support to the Tegra XHCI driver and move the function
> >> calls to enable/disable the clocks, regulators and PHY into the runtime
> >> PM callbacks.
> >>
> >> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> >> ---
> >>   drivers/usb/host/xhci-tegra.c | 80
> >> ++++++++++++++++++++++++++++++-------------
> >>   1 file changed, 56 insertions(+), 24 deletions(-)
> >>
> >> diff --git a/drivers/usb/host/xhci-tegra.c
> >> b/drivers/usb/host/xhci-tegra.c
> >> index 02b0b24faa58..42aa67858b53 100644
> >> --- a/drivers/usb/host/xhci-tegra.c
> >> +++ b/drivers/usb/host/xhci-tegra.c
> >> @@ -18,6 +18,7 @@
> >>   #include <linux/phy/tegra/xusb.h>
> >>   #include <linux/platform_device.h>
> >>   #include <linux/pm.h>
> >> +#include <linux/pm_runtime.h>
> >>   #include <linux/regulator/consumer.h>
> >>   #include <linux/reset.h>
> >>   #include <linux/slab.h>
> >> @@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct
> >> platform_device *pdev)
> >>        */
> >>       platform_set_drvdata(pdev, tegra);
> >>   -    err = tegra_xusb_clk_enable(tegra);
> >> -    if (err) {
> >> -        dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
> >> -        goto put_usb2;
> >> -    }
> >> -
> >> -    err = regulator_bulk_enable(tegra->soc->num_supplies,
> >> tegra->supplies);
> >> -    if (err) {
> >> -        dev_err(&pdev->dev, "failed to enable regulators: %d\n", err);
> >> -        goto disable_clk;
> >> -    }
> >> +    pm_runtime_enable(&pdev->dev);
> >>   -    err = tegra_xusb_phy_enable(tegra);
> >> +    err = pm_runtime_get_sync(&pdev->dev);
> >>       if (err < 0) {
> > 
> > Does this mean that if runtime PM is disabled then clocks and regulator
> > will never be enabled
> > for Tegra xhci?
> > 
> > How about keeping the clock and regualtor enabling in probe, and instead
> > add something like:
> > 
> > pm_runtime_set_active(&pdev->dev);
> > pm_runtime_enable(&pdev->dev);
> > pm_runtime_get_noresume(&pdev->dev);
> 
> For 64-bit Tegra there is a dependency on CONFIG_PM, but for 32-bit
> AFAIK there is not and so yes we should handle the case when PM_RUNTIME
> is disabled.
> 
> Typically we do something like ...
> 
>     pm_runtime_enable(&pdev->dev);
>     if (!pm_runtime_enabled(&pdev->dev))
> 	ret = tegra_xusb_runtime_resume(&pdev->dev);
>     else
>         ret = pm_runtime_get_sync(&pdev->dev);
> 
> That way we can keep the regulator and clock stuff in the handler. I
> will update this series.

Is there any good reason why we don't depend on PM for 32-bit as well?
I'm not aware of any differences in drivers that are 32-bit specific for
Tegra, and I'm not even sure the !PM case gets any testing at all. And
even if, do we really still want to support that?

I don't see any advantage these days for having it disabled.

Thierry

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

* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-03-09  9:13 Mathias Nyman
  0 siblings, 0 replies; 7+ messages in thread
From: Mathias Nyman @ 2018-03-09  9:13 UTC (permalink / raw)
  To: Thierry Reding, Jon Hunter
  Cc: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-tegra,
	linux-kernel

On 09.03.2018 10:36, Thierry Reding wrote:
> On Thu, Mar 08, 2018 at 09:31:07PM +0000, Jon Hunter wrote:
>>
>> On 01/03/18 14:18, Mathias Nyman wrote:
>>> On 14.02.2018 18:34, Jon Hunter wrote:
>>>> Add runtime PM support to the Tegra XHCI driver and move the function
>>>> calls to enable/disable the clocks, regulators and PHY into the runtime
>>>> PM callbacks.
>>>>
>>>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>>>> ---
>>>>    drivers/usb/host/xhci-tegra.c | 80
>>>> ++++++++++++++++++++++++++++++-------------
>>>>    1 file changed, 56 insertions(+), 24 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/host/xhci-tegra.c
>>>> b/drivers/usb/host/xhci-tegra.c
>>>> index 02b0b24faa58..42aa67858b53 100644
>>>> --- a/drivers/usb/host/xhci-tegra.c
>>>> +++ b/drivers/usb/host/xhci-tegra.c
>>>> @@ -18,6 +18,7 @@
>>>>    #include <linux/phy/tegra/xusb.h>
>>>>    #include <linux/platform_device.h>
>>>>    #include <linux/pm.h>
>>>> +#include <linux/pm_runtime.h>
>>>>    #include <linux/regulator/consumer.h>
>>>>    #include <linux/reset.h>
>>>>    #include <linux/slab.h>
>>>> @@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct
>>>> platform_device *pdev)
>>>>         */
>>>>        platform_set_drvdata(pdev, tegra);
>>>>    -    err = tegra_xusb_clk_enable(tegra);
>>>> -    if (err) {
>>>> -        dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
>>>> -        goto put_usb2;
>>>> -    }
>>>> -
>>>> -    err = regulator_bulk_enable(tegra->soc->num_supplies,
>>>> tegra->supplies);
>>>> -    if (err) {
>>>> -        dev_err(&pdev->dev, "failed to enable regulators: %d\n", err);
>>>> -        goto disable_clk;
>>>> -    }
>>>> +    pm_runtime_enable(&pdev->dev);
>>>>    -    err = tegra_xusb_phy_enable(tegra);
>>>> +    err = pm_runtime_get_sync(&pdev->dev);
>>>>        if (err < 0) {
>>>
>>> Does this mean that if runtime PM is disabled then clocks and regulator
>>> will never be enabled
>>> for Tegra xhci?
>>>
>>> How about keeping the clock and regualtor enabling in probe, and instead
>>> add something like:
>>>
>>> pm_runtime_set_active(&pdev->dev);
>>> pm_runtime_enable(&pdev->dev);
>>> pm_runtime_get_noresume(&pdev->dev);
>>
>> For 64-bit Tegra there is a dependency on CONFIG_PM, but for 32-bit
>> AFAIK there is not and so yes we should handle the case when PM_RUNTIME
>> is disabled.
>>
>> Typically we do something like ...
>>
>>      pm_runtime_enable(&pdev->dev);
>>      if (!pm_runtime_enabled(&pdev->dev))
>> 	ret = tegra_xusb_runtime_resume(&pdev->dev);
>>      else
>>          ret = pm_runtime_get_sync(&pdev->dev);
>>
>> That way we can keep the regulator and clock stuff in the handler. I
>> will update this series.
> 
> Is there any good reason why we don't depend on PM for 32-bit as well?
> I'm not aware of any differences in drivers that are 32-bit specific for
> Tegra, and I'm not even sure the !PM case gets any testing at all. And
> even if, do we really still want to support that?
> 
> I don't see any advantage these days for having it disabled.

I don't know much about Tegra, but I'd still like to turn this question around:

Is there any reason why clks and regulators can't initially be turned on in probe,
and then let runtime PM handle them later if PM is supported?

Shouldn't this work in all cases, and it avoids creating new dependencies?

Thanks
Mathias
---
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

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

* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-03-09 11:13 Jon Hunter
  0 siblings, 0 replies; 7+ messages in thread
From: Jon Hunter @ 2018-03-09 11:13 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Mathias Nyman, Mathias Nyman, Greg Kroah-Hartman, linux-usb,
	linux-tegra, linux-kernel

On 09/03/18 08:36, Thierry Reding wrote:
> On Thu, Mar 08, 2018 at 09:31:07PM +0000, Jon Hunter wrote:
>>
>> On 01/03/18 14:18, Mathias Nyman wrote:
>>> On 14.02.2018 18:34, Jon Hunter wrote:
>>>> Add runtime PM support to the Tegra XHCI driver and move the function
>>>> calls to enable/disable the clocks, regulators and PHY into the runtime
>>>> PM callbacks.
>>>>
>>>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>>>> ---
>>>>   drivers/usb/host/xhci-tegra.c | 80
>>>> ++++++++++++++++++++++++++++++-------------
>>>>   1 file changed, 56 insertions(+), 24 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/host/xhci-tegra.c
>>>> b/drivers/usb/host/xhci-tegra.c
>>>> index 02b0b24faa58..42aa67858b53 100644
>>>> --- a/drivers/usb/host/xhci-tegra.c
>>>> +++ b/drivers/usb/host/xhci-tegra.c
>>>> @@ -18,6 +18,7 @@
>>>>   #include <linux/phy/tegra/xusb.h>
>>>>   #include <linux/platform_device.h>
>>>>   #include <linux/pm.h>
>>>> +#include <linux/pm_runtime.h>
>>>>   #include <linux/regulator/consumer.h>
>>>>   #include <linux/reset.h>
>>>>   #include <linux/slab.h>
>>>> @@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct
>>>> platform_device *pdev)
>>>>        */
>>>>       platform_set_drvdata(pdev, tegra);
>>>>   -    err = tegra_xusb_clk_enable(tegra);
>>>> -    if (err) {
>>>> -        dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
>>>> -        goto put_usb2;
>>>> -    }
>>>> -
>>>> -    err = regulator_bulk_enable(tegra->soc->num_supplies,
>>>> tegra->supplies);
>>>> -    if (err) {
>>>> -        dev_err(&pdev->dev, "failed to enable regulators: %d\n", err);
>>>> -        goto disable_clk;
>>>> -    }
>>>> +    pm_runtime_enable(&pdev->dev);
>>>>   -    err = tegra_xusb_phy_enable(tegra);
>>>> +    err = pm_runtime_get_sync(&pdev->dev);
>>>>       if (err < 0) {
>>>
>>> Does this mean that if runtime PM is disabled then clocks and regulator
>>> will never be enabled
>>> for Tegra xhci?
>>>
>>> How about keeping the clock and regualtor enabling in probe, and instead
>>> add something like:
>>>
>>> pm_runtime_set_active(&pdev->dev);
>>> pm_runtime_enable(&pdev->dev);
>>> pm_runtime_get_noresume(&pdev->dev);
>>
>> For 64-bit Tegra there is a dependency on CONFIG_PM, but for 32-bit
>> AFAIK there is not and so yes we should handle the case when PM_RUNTIME
>> is disabled.
>>
>> Typically we do something like ...
>>
>>     pm_runtime_enable(&pdev->dev);
>>     if (!pm_runtime_enabled(&pdev->dev))
>> 	ret = tegra_xusb_runtime_resume(&pdev->dev);
>>     else
>>         ret = pm_runtime_get_sync(&pdev->dev);
>>
>> That way we can keep the regulator and clock stuff in the handler. I
>> will update this series.
> 
> Is there any good reason why we don't depend on PM for 32-bit as well?

Not that I am aware of.

> I'm not aware of any differences in drivers that are 32-bit specific for
> Tegra, and I'm not even sure the !PM case gets any testing at all. And
> even if, do we really still want to support that?
> 
> I don't see any advantage these days for having it disabled.

It would be fine IMO.

Cheers
Jon

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

* [2/3] usb: xhci: tegra: Add runtime PM support
@ 2018-03-09 11:19 Jon Hunter
  0 siblings, 0 replies; 7+ messages in thread
From: Jon Hunter @ 2018-03-09 11:19 UTC (permalink / raw)
  To: Mathias Nyman, Thierry Reding
  Cc: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-tegra,
	linux-kernel

On 09/03/18 09:13, Mathias Nyman wrote:
> On 09.03.2018 10:36, Thierry Reding wrote:
>> On Thu, Mar 08, 2018 at 09:31:07PM +0000, Jon Hunter wrote:
>>>
>>> On 01/03/18 14:18, Mathias Nyman wrote:
>>>> On 14.02.2018 18:34, Jon Hunter wrote:
>>>>> Add runtime PM support to the Tegra XHCI driver and move the function
>>>>> calls to enable/disable the clocks, regulators and PHY into the
>>>>> runtime
>>>>> PM callbacks.
>>>>>
>>>>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>>>>> ---
>>>>>    drivers/usb/host/xhci-tegra.c | 80
>>>>> ++++++++++++++++++++++++++++++-------------
>>>>>    1 file changed, 56 insertions(+), 24 deletions(-)
>>>>>
>>>>> diff --git a/drivers/usb/host/xhci-tegra.c
>>>>> b/drivers/usb/host/xhci-tegra.c
>>>>> index 02b0b24faa58..42aa67858b53 100644
>>>>> --- a/drivers/usb/host/xhci-tegra.c
>>>>> +++ b/drivers/usb/host/xhci-tegra.c
>>>>> @@ -18,6 +18,7 @@
>>>>>    #include <linux/phy/tegra/xusb.h>
>>>>>    #include <linux/platform_device.h>
>>>>>    #include <linux/pm.h>
>>>>> +#include <linux/pm_runtime.h>
>>>>>    #include <linux/regulator/consumer.h>
>>>>>    #include <linux/reset.h>
>>>>>    #include <linux/slab.h>
>>>>> @@ -1067,22 +1068,12 @@ static int tegra_xusb_probe(struct
>>>>> platform_device *pdev)
>>>>>         */
>>>>>        platform_set_drvdata(pdev, tegra);
>>>>>    -    err = tegra_xusb_clk_enable(tegra);
>>>>> -    if (err) {
>>>>> -        dev_err(&pdev->dev, "failed to enable clocks: %d\n", err);
>>>>> -        goto put_usb2;
>>>>> -    }
>>>>> -
>>>>> -    err = regulator_bulk_enable(tegra->soc->num_supplies,
>>>>> tegra->supplies);
>>>>> -    if (err) {
>>>>> -        dev_err(&pdev->dev, "failed to enable regulators: %d\n",
>>>>> err);
>>>>> -        goto disable_clk;
>>>>> -    }
>>>>> +    pm_runtime_enable(&pdev->dev);
>>>>>    -    err = tegra_xusb_phy_enable(tegra);
>>>>> +    err = pm_runtime_get_sync(&pdev->dev);
>>>>>        if (err < 0) {
>>>>
>>>> Does this mean that if runtime PM is disabled then clocks and regulator
>>>> will never be enabled
>>>> for Tegra xhci?
>>>>
>>>> How about keeping the clock and regualtor enabling in probe, and
>>>> instead
>>>> add something like:
>>>>
>>>> pm_runtime_set_active(&pdev->dev);
>>>> pm_runtime_enable(&pdev->dev);
>>>> pm_runtime_get_noresume(&pdev->dev);
>>>
>>> For 64-bit Tegra there is a dependency on CONFIG_PM, but for 32-bit
>>> AFAIK there is not and so yes we should handle the case when PM_RUNTIME
>>> is disabled.
>>>
>>> Typically we do something like ...
>>>
>>>      pm_runtime_enable(&pdev->dev);
>>>      if (!pm_runtime_enabled(&pdev->dev))
>>>     ret = tegra_xusb_runtime_resume(&pdev->dev);
>>>      else
>>>          ret = pm_runtime_get_sync(&pdev->dev);
>>>
>>> That way we can keep the regulator and clock stuff in the handler. I
>>> will update this series.
>>
>> Is there any good reason why we don't depend on PM for 32-bit as well?
>> I'm not aware of any differences in drivers that are 32-bit specific for
>> Tegra, and I'm not even sure the !PM case gets any testing at all. And
>> even if, do we really still want to support that?
>>
>> I don't see any advantage these days for having it disabled.
> 
> I don't know much about Tegra, but I'd still like to turn this question
> around:
> 
> Is there any reason why clks and regulators can't initially be turned on
> in probe,
> and then let runtime PM handle them later if PM is supported?

I personally prefer having the regulator, clock, etc handling for
enabling and disabling for a device in their own handler. Duplicating
the calls to the regulator and clock frameworks in probe and the rpm
handlers seems more prone to mistakes. Hence, that's why I would prefer
the option I suggested above, which IMO is the best of both worlds.

> Shouldn't this work in all cases, and it avoids creating new dependencies?

Yes but when you want to use frameworks such as genpd it becomes more
complex to support !PM and that is why for 64-bit Tegra we have a
dependency today.

Cheers
Jon

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

end of thread, other threads:[~2018-03-09 11:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-09  9:13 [2/3] usb: xhci: tegra: Add runtime PM support Mathias Nyman
  -- strict thread matches above, loose matches on Subject: below --
2018-03-09 11:19 Jon Hunter
2018-03-09 11:13 Jon Hunter
2018-03-09  8:36 Thierry Reding
2018-03-08 21:31 Jon Hunter
2018-03-01 14:18 Mathias Nyman
2018-02-14 16:34 Jon Hunter

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