[PACTH v4 1/2] usb: xhci: plat: Enable runtime PM

From: robert . foss
Date: Tue Aug 09 2016 - 11:41:16 EST


From: Robert Foss <robert.foss@xxxxxxxxxxxxx>

Enable runtime PM for the xhci-plat device so that the parent device
may implement runtime PM.

Signed-off-by: Robert Foss <robert.foss@xxxxxxxxxxxxx>

Tested-by: Robert Foss <robert.foss@xxxxxxxxxxxxx>
---
drivers/usb/host/xhci-plat.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..2755a20 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -246,6 +246,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (ret)
goto dealloc_usb2_hcd;

+ pm_runtime_set_active(&pdev->dev);
+ pm_runtime_enable(&pdev->dev);
+
return 0;


@@ -274,6 +277,8 @@ static int xhci_plat_remove(struct platform_device *dev)
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct clk *clk = xhci->clk;

+ pm_runtime_disable(&dev->dev);
+
usb_remove_hcd(xhci->shared_hcd);
usb_phy_shutdown(hcd->usb_phy);

@@ -292,7 +297,12 @@ static int xhci_plat_suspend(struct device *dev)
{
struct usb_hcd *hcd = dev_get_drvdata(dev);
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+ int ret;

+ ret = pm_runtime_get_sync(dev);
+ if (ret < 0)
+ atomic_dec(&dev->power.usage_count);
+ return ret;
/*
* xhci_suspend() needs `do_wakeup` to know whether host is allowed
* to do wakeup during suspend. Since xhci_plat_suspend is currently
@@ -301,15 +311,27 @@ static int xhci_plat_suspend(struct device *dev)
* reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
* also applies to runtime suspend.
*/
- return xhci_suspend(xhci, device_may_wakeup(dev));
+ ret = xhci_suspend(xhci, device_may_wakeup(dev));
+ pm_runtime_put(dev);
+
+ return ret;
}

static int xhci_plat_resume(struct device *dev)
{
struct usb_hcd *hcd = dev_get_drvdata(dev);
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+ int ret;
+
+ ret = pm_runtime_get_sync(dev);
+ if (ret < 0)
+ atomic_dec(&dev->power.usage_count);
+ return ret;

- return xhci_resume(xhci, 0);
+ ret = xhci_resume(xhci, 0);
+ pm_runtime_put(dev);
+
+ return ret;
}

static const struct dev_pm_ops xhci_plat_pm_ops = {
--
2.7.4