public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: host: plat: Enable xHCI plat runtime PM
@ 2017-03-30  3:26 Baolin Wang
  2017-04-10  7:57 ` Baolin Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Baolin Wang @ 2017-03-30  3:26 UTC (permalink / raw)
  To: mathias.nyman; +Cc: gregkh, broonie, linux-usb, linux-kernel, baolin.wang

Enable the xHCI plat runtime PM for parent device to suspend/resume
xHCI. Also call pm_runtime_forbid() in probe() function to force users
to explicitly enable runtime pm using power/control in sysfs, in case
some parent devices didn't implement runtime PM callbacks.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/usb/host/xhci-plat.c |   54 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index bd02a6c..2036c24 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -179,9 +179,15 @@ static int xhci_plat_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+	pm_runtime_get_noresume(&pdev->dev);
+
 	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
-	if (!hcd)
-		return -ENOMEM;
+	if (!hcd) {
+		ret = -ENOMEM;
+		goto disable_runtime;
+	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	hcd->regs = devm_ioremap_resource(&pdev->dev, res);
@@ -258,6 +264,14 @@ static int xhci_plat_probe(struct platform_device *pdev)
 	if (ret)
 		goto dealloc_usb2_hcd;
 
+	pm_runtime_put_noidle(&pdev->dev);
+
+	/*
+	 * Prevent runtime pm from being on as default, users should enable
+	 * runtime pm using power/control in sysfs.
+	 */
+	pm_runtime_forbid(&pdev->dev);
+
 	return 0;
 
 
@@ -277,6 +291,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
 put_hcd:
 	usb_put_hcd(hcd);
 
+disable_runtime:
+	pm_runtime_put_noidle(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
 	return ret;
 }
 
@@ -298,6 +316,9 @@ static int xhci_plat_remove(struct platform_device *dev)
 		clk_disable_unprepare(clk);
 	usb_put_hcd(hcd);
 
+	pm_runtime_set_suspended(&dev->dev);
+	pm_runtime_disable(&dev->dev);
+
 	return 0;
 }
 
@@ -325,14 +346,33 @@ static int xhci_plat_resume(struct device *dev)
 
 	return xhci_resume(xhci, 0);
 }
+#endif /* CONFIG_PM_SLEEP */
+
+#ifdef CONFIG_PM
+static int xhci_plat_runtime_suspend(struct device *dev)
+{
+	struct usb_hcd  *hcd = dev_get_drvdata(dev);
+	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+	return xhci_suspend(xhci, device_may_wakeup(dev));
+}
+
+static int xhci_plat_runtime_resume(struct device *dev)
+{
+	struct usb_hcd  *hcd = dev_get_drvdata(dev);
+	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+	return xhci_resume(xhci, 0);
+}
+#endif /* CONFIG_PM */
 
 static const struct dev_pm_ops xhci_plat_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
+
+	SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend,
+			   xhci_plat_runtime_resume,
+			   NULL)
 };
-#define DEV_PM_OPS	(&xhci_plat_pm_ops)
-#else
-#define DEV_PM_OPS	NULL
-#endif /* CONFIG_PM */
 
 static const struct acpi_device_id usb_xhci_acpi_match[] = {
 	/* XHCI-compliant USB Controller */
@@ -346,7 +386,7 @@ static int xhci_plat_resume(struct device *dev)
 	.remove	= xhci_plat_remove,
 	.driver	= {
 		.name = "xhci-hcd",
-		.pm = DEV_PM_OPS,
+		.pm = &xhci_plat_pm_ops,
 		.of_match_table = of_match_ptr(usb_xhci_of_match),
 		.acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
 	},
-- 
1.7.9.5

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

* Re: [PATCH] usb: host: plat: Enable xHCI plat runtime PM
  2017-03-30  3:26 [PATCH] usb: host: plat: Enable xHCI plat runtime PM Baolin Wang
@ 2017-04-10  7:57 ` Baolin Wang
  2017-04-10 10:09   ` Mathias Nyman
  0 siblings, 1 reply; 4+ messages in thread
From: Baolin Wang @ 2017-04-10  7:57 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: Greg KH, Mark Brown, USB, LKML, Baolin Wang

Hi Mathias,

On 30 March 2017 at 11:26, Baolin Wang <baolin.wang@linaro.org> wrote:
> Enable the xHCI plat runtime PM for parent device to suspend/resume
> xHCI. Also call pm_runtime_forbid() in probe() function to force users
> to explicitly enable runtime pm using power/control in sysfs, in case
> some parent devices didn't implement runtime PM callbacks.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
>  drivers/usb/host/xhci-plat.c |   54 ++++++++++++++++++++++++++++++++++++------
>  1 file changed, 47 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index bd02a6c..2036c24 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -179,9 +179,15 @@ static int xhci_plat_probe(struct platform_device *pdev)
>                         return ret;
>         }
>
> +       pm_runtime_set_active(&pdev->dev);
> +       pm_runtime_enable(&pdev->dev);
> +       pm_runtime_get_noresume(&pdev->dev);
> +
>         hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
> -       if (!hcd)
> -               return -ENOMEM;
> +       if (!hcd) {
> +               ret = -ENOMEM;
> +               goto disable_runtime;
> +       }
>
>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>         hcd->regs = devm_ioremap_resource(&pdev->dev, res);
> @@ -258,6 +264,14 @@ static int xhci_plat_probe(struct platform_device *pdev)
>         if (ret)
>                 goto dealloc_usb2_hcd;
>
> +       pm_runtime_put_noidle(&pdev->dev);
> +
> +       /*
> +        * Prevent runtime pm from being on as default, users should enable
> +        * runtime pm using power/control in sysfs.
> +        */
> +       pm_runtime_forbid(&pdev->dev);
> +
>         return 0;
>
>
> @@ -277,6 +291,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
>  put_hcd:
>         usb_put_hcd(hcd);
>
> +disable_runtime:
> +       pm_runtime_put_noidle(&pdev->dev);
> +       pm_runtime_disable(&pdev->dev);
> +
>         return ret;
>  }
>
> @@ -298,6 +316,9 @@ static int xhci_plat_remove(struct platform_device *dev)
>                 clk_disable_unprepare(clk);
>         usb_put_hcd(hcd);
>
> +       pm_runtime_set_suspended(&dev->dev);
> +       pm_runtime_disable(&dev->dev);
> +
>         return 0;
>  }
>
> @@ -325,14 +346,33 @@ static int xhci_plat_resume(struct device *dev)
>
>         return xhci_resume(xhci, 0);
>  }
> +#endif /* CONFIG_PM_SLEEP */
> +
> +#ifdef CONFIG_PM
> +static int xhci_plat_runtime_suspend(struct device *dev)
> +{
> +       struct usb_hcd  *hcd = dev_get_drvdata(dev);
> +       struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> +
> +       return xhci_suspend(xhci, device_may_wakeup(dev));
> +}
> +
> +static int xhci_plat_runtime_resume(struct device *dev)
> +{
> +       struct usb_hcd  *hcd = dev_get_drvdata(dev);
> +       struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> +
> +       return xhci_resume(xhci, 0);
> +}
> +#endif /* CONFIG_PM */
>
>  static const struct dev_pm_ops xhci_plat_pm_ops = {
>         SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
> +
> +       SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend,
> +                          xhci_plat_runtime_resume,
> +                          NULL)
>  };
> -#define DEV_PM_OPS     (&xhci_plat_pm_ops)
> -#else
> -#define DEV_PM_OPS     NULL
> -#endif /* CONFIG_PM */
>
>  static const struct acpi_device_id usb_xhci_acpi_match[] = {
>         /* XHCI-compliant USB Controller */
> @@ -346,7 +386,7 @@ static int xhci_plat_resume(struct device *dev)
>         .remove = xhci_plat_remove,
>         .driver = {
>                 .name = "xhci-hcd",
> -               .pm = DEV_PM_OPS,
> +               .pm = &xhci_plat_pm_ops,
>                 .of_match_table = of_match_ptr(usb_xhci_of_match),
>                 .acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
>         },

Any comments?

-- 
Baolin.wang
Best Regards

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

* Re: [PATCH] usb: host: plat: Enable xHCI plat runtime PM
  2017-04-10  7:57 ` Baolin Wang
@ 2017-04-10 10:09   ` Mathias Nyman
  2017-04-10 10:59     ` Baolin Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Mathias Nyman @ 2017-04-10 10:09 UTC (permalink / raw)
  To: Baolin Wang, Mathias Nyman; +Cc: Greg KH, Mark Brown, USB, LKML

On 10.04.2017 10:57, Baolin Wang wrote:
> Hi Mathias,
>
> On 30 March 2017 at 11:26, Baolin Wang <baolin.wang@linaro.org> wrote:
>> Enable the xHCI plat runtime PM for parent device to suspend/resume
>> xHCI. Also call pm_runtime_forbid() in probe() function to force users
>> to explicitly enable runtime pm using power/control in sysfs, in case
>> some parent devices didn't implement runtime PM callbacks.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>> ---
> Any comments?

Patch looks good, but it didn't apply cleanly on top of the series going to
usb next last Friday.
I wanted those to go forward so this got postponed.

Can you rebase this on latest usb-next?

-Mathias

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

* Re: [PATCH] usb: host: plat: Enable xHCI plat runtime PM
  2017-04-10 10:09   ` Mathias Nyman
@ 2017-04-10 10:59     ` Baolin Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2017-04-10 10:59 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: Mathias Nyman, Greg KH, Mark Brown, USB, LKML

Hi Mathias,

On 10 April 2017 at 18:09, Mathias Nyman <mathias.nyman@linux.intel.com> wrote:
> On 10.04.2017 10:57, Baolin Wang wrote:
>>
>> Hi Mathias,
>>
>> On 30 March 2017 at 11:26, Baolin Wang <baolin.wang@linaro.org> wrote:
>>>
>>> Enable the xHCI plat runtime PM for parent device to suspend/resume
>>> xHCI. Also call pm_runtime_forbid() in probe() function to force users
>>> to explicitly enable runtime pm using power/control in sysfs, in case
>>> some parent devices didn't implement runtime PM callbacks.
>>>
>>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>>> ---
>>
>> Any comments?
>
>
> Patch looks good, but it didn't apply cleanly on top of the series going to
> usb next last Friday.
> I wanted those to go forward so this got postponed.
>
> Can you rebase this on latest usb-next?

Sure. I will resend it. Thanks.

-- 
Baolin.wang
Best Regards

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

end of thread, other threads:[~2017-04-10 10:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-30  3:26 [PATCH] usb: host: plat: Enable xHCI plat runtime PM Baolin Wang
2017-04-10  7:57 ` Baolin Wang
2017-04-10 10:09   ` Mathias Nyman
2017-04-10 10:59     ` Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox