Skip to content

Commit a46f2b4

Browse files
committed
usb: dwc3: rockchip: fix usb peripheral connection fail
This patch fix the issue that usb peripheral fails to connect to PC after resume from deep sleep. In my test case, I use a rk3399 sapphire excavator board, and test usb as follows: - Let the system enter deep sleep without usb connection. - During deep sleep, connect the Type-C0 of rk3399 with PC usb port. - Press power key to wakeup system, and check if the PC can detect usb. Without this patch, the usb enumeration often fail with the error log "dwc3 fe800000.dwc3: failed to enable ep0out". It's because that after system resume, the dwc3 pm resume and dwc3 pm runtime resume are running asynchronously. If dwc3 runtime resume before pm resume, the dwc3_resume_common() maybe called twice, and cause ep enable failure. This patch use the suspend flag of dev to wait until the dwc3 core resume from PM suspend successfully before do dwc3 pm runtime resume. Change-Id: I6a67ad636630699569e16346ac167b785b800f85 Signed-off-by: William Wu <william.wu@rock-chips.com>
1 parent 690646e commit a46f2b4

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

drivers/usb/dwc3/dwc3-rockchip.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ static void dwc3_rockchip_otg_extcon_evt_work(struct work_struct *work)
408408
unsigned long flags;
409409
int ret;
410410
int val;
411-
u32 reg, count;
411+
u32 reg;
412+
u32 count = 0;
412413

413414
mutex_lock(&rockchip->lock);
414415

@@ -442,6 +443,16 @@ static void dwc3_rockchip_otg_extcon_evt_work(struct work_struct *work)
442443
udelay(1);
443444
reset_control_deassert(rockchip->otg_rst);
444445

446+
/* Wait until dwc3 core resume from PM suspend */
447+
while (dwc->dev->power.is_suspended) {
448+
if (++count > 1000) {
449+
dev_err(rockchip->dev,
450+
"wait for dwc3 core resume timeout!\n");
451+
goto out;
452+
}
453+
usleep_range(100, 200);
454+
}
455+
445456
pm_runtime_get_sync(rockchip->dev);
446457
pm_runtime_get_sync(dwc->dev);
447458
} else {
@@ -574,7 +585,6 @@ static void dwc3_rockchip_otg_extcon_evt_work(struct work_struct *work)
574585

575586
if (hcd->state != HC_STATE_HALT) {
576587
xhci->xhc_state |= XHCI_STATE_REMOVING;
577-
count = 0;
578588

579589
/*
580590
* Wait until XHCI controller resume from

0 commit comments

Comments
 (0)