From f3b41537fc699272640cc2d45548e57ea9cedd3a Mon Sep 17 00:00:00 2001 From: Meng Dongyang Date: Thu, 8 Mar 2018 19:00:02 +0800 Subject: [PATCH] usb: dwc2: make hcd into L3 power off state when suspend The controller will reset and run into error state if turn off power when suspend in host mode. This patch stop hcd to make the controller into L3 state to make sure that the controller and driver state will reset when resume. Change-Id: If66bc1a249e919f440ecde0c66f18dabde0b2e62 Signed-off-by: Meng Dongyang Signed-off-by: Frank Wang --- drivers/usb/dwc2/platform.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 8937a28c31c1..b31430428da0 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -699,6 +699,7 @@ static int __maybe_unused dwc2_suspend(struct device *dev) static int __maybe_unused dwc2_resume(struct device *dev) { struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); + unsigned long flags; int ret = 0; if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { @@ -738,6 +739,16 @@ static int __maybe_unused dwc2_resume(struct device *dev) dwc2_drd_resume(dwc2); + /* Stop hcd if dr_mode is host and PD is power off when suspend */ + if (dwc2->op_state == OTG_STATE_A_HOST && dwc2_is_device_mode(dwc2)) { + spin_lock_irqsave(&dwc2->lock, flags); + dwc2_hcd_disconnect(dwc2, true); + dwc2->lx_state = DWC2_L3; + if (!dwc2->driver) + dwc2_hsotg_core_init_disconnected(dwc2, false); + spin_unlock_irqrestore(&dwc2->lock, flags); + } + if (dwc2_is_device_mode(dwc2)) ret = dwc2_hsotg_resume(dwc2);