From 223064da402ec644dd6d490420df5e861aabd124 Mon Sep 17 00:00:00 2001 From: William Wu Date: Mon, 28 Feb 2022 20:09:41 +0800 Subject: [PATCH] usb: dwc3: fix runtime pm when current_dr_role is not set The current runtime suspend/resume do nothing when the current_dr_role is not set. It may fail to do core init in some scenes. Test on RK3588 EVB2 or NVR Demo which have Type-A OTG port, without this patch, the USB ADB enumeration failed occasionally. When this error happens, we can find that the register GUSB2PHYCFG(0) isn't initialized correctly. It's because that during dwc3 probe, if the drd_work which called from dwc3_drd_init() is scheduled behind the runtime suspend process, the current_dr_role will be uninitialized, this cause the runtime resume process doing nothing and put the dwc3 phy in uninitialized status. This patch add dwc3_core_init and dwc3_core_exit operation for runtime suspend/resume when the current_dr_role is not initialized. Signed-off-by: William Wu Change-Id: I294bcf2ad68136e9eb24a9e4a1ad389e73c974d2 --- drivers/usb/dwc3/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 4f3eb0ac7b53..9a00a2c7b87b 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1841,7 +1841,8 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) dwc3_core_exit(dwc); break; default: - /* do nothing */ + if (!pm_runtime_suspended(dwc->dev)) + dwc3_core_exit(dwc); break; } @@ -1908,7 +1909,9 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) break; default: - /* do nothing */ + ret = dwc3_core_init_for_resume(dwc); + if (ret) + return ret; break; }