From 0e9176d1fccd96046f3e14c67ae7d431d361a4c0 Mon Sep 17 00:00:00 2001 From: Wang Jie Date: Thu, 19 Aug 2021 21:21:10 +0800 Subject: [PATCH] usb: dwc3: core: fix pm runtime issue for rockchip platforms The rockchip platforms, such as RK3399 and RK3568 otg port enable pm runtime to swith peripheral and host mode. During dwc3 core probe, there are two place which may call pm_runtime_put_sync_suspend(), one is in dwc3_rockchip_async_probe(), the other one is in the drd_work called from dwc3_core_init_mode(). The dwc3_rockchip_async_probe() and drd_work are scheduled asynchronously, and the order of their execution is randomly. If the drd_work is handled prior to the async probe, there's no problem, but if the async probe is handled firstly, the pm_runtime_put_sync_suspend() will be duplicated twice. If this issue happens, the value of dwc3 power.usage_count is -1, in other words, the runtime put/suspend operations is unbalanced, and fail to do dwc3_runtime_suspend/resume. This patch avoids do pm_runtime_put_sync_suspend() in the drd_work if no usb connected. Fixes: bb4c791a42c6 ("usb: dwc3: core: add pm runtime for drd mode") Signed-off-by: Wang Jie Signed-off-by: William Wu Change-Id: I088a7ddb60eb817093810fe874d5fdb242c73ca7 --- drivers/usb/dwc3/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 3404080bdf5c..af8c15af4740 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -296,8 +296,10 @@ disconnect: * We should set drd_connected to false before * runtime_suspend to enable reset assert. */ - dwc->drd_connected = false; - pm_runtime_put_sync_suspend(dwc->dev); + if (dwc->drd_connected) { + dwc->drd_connected = false; + pm_runtime_put_sync_suspend(dwc->dev); + } } }