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: bb4c791a42 ("usb: dwc3: core: add pm runtime for drd mode")
Signed-off-by: Wang Jie <dave.wang@rock-chips.com>
Signed-off-by: William Wu <william.wu@rock-chips.com>
Change-Id: I088a7ddb60eb817093810fe874d5fdb242c73ca7
This commit is contained in:
Wang Jie
2021-08-19 21:21:10 +08:00
committed by Tao Huang
parent e05d38ded5
commit 0e9176d1fc

View File

@@ -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);
}
}
}