Skip to content

Commit b0c69b4

Browse files
wangbaolin719gregkh
authored andcommitted
usb: host: plat: Enable xHCI plat runtime PM
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. [set do_wakeup to true when runtime suspending -Mathias] Signed-off-by: Baolin Wang <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 21470e3 commit b0c69b4

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

drivers/usb/host/xhci-plat.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,16 @@ static int xhci_plat_probe(struct platform_device *pdev)
197197
return ret;
198198
}
199199

200+
pm_runtime_set_active(&pdev->dev);
201+
pm_runtime_enable(&pdev->dev);
202+
pm_runtime_get_noresume(&pdev->dev);
203+
200204
hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
201205
dev_name(&pdev->dev), NULL);
202-
if (!hcd)
203-
return -ENOMEM;
206+
if (!hcd) {
207+
ret = -ENOMEM;
208+
goto disable_runtime;
209+
}
204210

205211
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
206212
hcd->regs = devm_ioremap_resource(&pdev->dev, res);
@@ -278,6 +284,13 @@ static int xhci_plat_probe(struct platform_device *pdev)
278284
goto dealloc_usb2_hcd;
279285

280286
device_enable_async_suspend(&pdev->dev);
287+
pm_runtime_put_noidle(&pdev->dev);
288+
289+
/*
290+
* Prevent runtime pm from being on as default, users should enable
291+
* runtime pm using power/control in sysfs.
292+
*/
293+
pm_runtime_forbid(&pdev->dev);
281294

282295
return 0;
283296

@@ -298,6 +311,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
298311
put_hcd:
299312
usb_put_hcd(hcd);
300313

314+
disable_runtime:
315+
pm_runtime_put_noidle(&pdev->dev);
316+
pm_runtime_disable(&pdev->dev);
317+
301318
return ret;
302319
}
303320

@@ -319,6 +336,9 @@ static int xhci_plat_remove(struct platform_device *dev)
319336
clk_disable_unprepare(clk);
320337
usb_put_hcd(hcd);
321338

339+
pm_runtime_set_suspended(&dev->dev);
340+
pm_runtime_disable(&dev->dev);
341+
322342
return 0;
323343
}
324344

@@ -346,14 +366,33 @@ static int xhci_plat_resume(struct device *dev)
346366

347367
return xhci_resume(xhci, 0);
348368
}
369+
#endif /* CONFIG_PM_SLEEP */
370+
371+
#ifdef CONFIG_PM
372+
static int xhci_plat_runtime_suspend(struct device *dev)
373+
{
374+
struct usb_hcd *hcd = dev_get_drvdata(dev);
375+
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
376+
377+
return xhci_suspend(xhci, true);
378+
}
379+
380+
static int xhci_plat_runtime_resume(struct device *dev)
381+
{
382+
struct usb_hcd *hcd = dev_get_drvdata(dev);
383+
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
384+
385+
return xhci_resume(xhci, 0);
386+
}
387+
#endif /* CONFIG_PM */
349388

350389
static const struct dev_pm_ops xhci_plat_pm_ops = {
351390
SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
391+
392+
SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend,
393+
xhci_plat_runtime_resume,
394+
NULL)
352395
};
353-
#define DEV_PM_OPS (&xhci_plat_pm_ops)
354-
#else
355-
#define DEV_PM_OPS NULL
356-
#endif /* CONFIG_PM */
357396

358397
static const struct acpi_device_id usb_xhci_acpi_match[] = {
359398
/* XHCI-compliant USB Controller */
@@ -368,7 +407,7 @@ static struct platform_driver usb_xhci_driver = {
368407
.shutdown = usb_hcd_platform_shutdown,
369408
.driver = {
370409
.name = "xhci-hcd",
371-
.pm = DEV_PM_OPS,
410+
.pm = &xhci_plat_pm_ops,
372411
.of_match_table = of_match_ptr(usb_xhci_of_match),
373412
.acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
374413
},

0 commit comments

Comments
 (0)