From 138fd489e3cedc44b9d8709bbf0c855678f6ab3c Mon Sep 17 00:00:00 2001 From: William Wu Date: Wed, 23 Dec 2020 18:54:25 +0800 Subject: [PATCH] usb: dwc3: core: add async probe for rockchip dwc3 The default autosuspend delay of PM runtime is 5000ms, it's too long. For Rockchip DWC3 controller, if it supports PM runtime management, e.g. RK3568 OTG port, then we expect to put the DWC3 controller in runtime suspend at the end of probe as soon as possible. This can fix the issue that race condition between power down the DWC3 in runtime suspend and access the DWC3 in dwc3_gadget_pullup() by userspace. This patch uses pm_runtime_put_sync_suspend() instead of pm_runtime_put if enable PM runtime. And according to the commit f2a2b34e456b ("usb: dwc3: rockchip: use async_schedule for initial dwc3"), we do pm_runtime_put_sync_suspend() in async schedule to avoid increasing the boot time. Change-Id: I378e57d272382d444f1ac52ea2961736e472e713 Signed-off-by: William Wu --- drivers/usb/dwc3/core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 7fecb55e288f..64dff7aa312d 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -8,6 +8,7 @@ * Sebastian Andrzej Siewior */ +#include #include #include #include @@ -1525,6 +1526,14 @@ static void dwc3_check_params(struct dwc3 *dwc) } } +static void dwc3_rockchip_async_probe(void *data, async_cookie_t cookie) +{ + struct dwc3 *dwc = data; + struct device *dev = dwc->dev; + + pm_runtime_put_sync_suspend(dev); +} + static int dwc3_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1671,7 +1680,11 @@ static int dwc3_probe(struct platform_device *pdev) goto err5; dwc3_debugfs_init(dwc); - pm_runtime_put(dev); + + if (dwc->en_runtime) + async_schedule(dwc3_rockchip_async_probe, dwc); + else + pm_runtime_put(dev); return 0;