Commit 689bf72c authored by Manu Gautam's avatar Manu Gautam Committed by Felipe Balbi

usb: dwc3: Don't reinitialize core during host bus-suspend/resume

Driver powers-off PHYs and reinitializes DWC3 core and gadget on
resume. While this works fine for gadget mode but in host
mode there is not re-initialization of host stack. Also, resetting
bus as part of bus_suspend/resume is not correct which could affect
(or disconnect) connected devices.
Fix this by not reinitializing core on suspend/resume in host mode
for HOST only and OTG/drd configurations.
Signed-off-by: default avatarManu Gautam <mgautam@codeaurora.org>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent ce035409
...@@ -927,6 +927,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) ...@@ -927,6 +927,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
switch (dwc->dr_mode) { switch (dwc->dr_mode) {
case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_PERIPHERAL:
dwc->current_dr_role = DWC3_GCTL_PRTCAP_DEVICE;
dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
if (dwc->usb2_phy) if (dwc->usb2_phy)
...@@ -942,6 +943,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) ...@@ -942,6 +943,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
} }
break; break;
case USB_DR_MODE_HOST: case USB_DR_MODE_HOST:
dwc->current_dr_role = DWC3_GCTL_PRTCAP_HOST;
dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
if (dwc->usb2_phy) if (dwc->usb2_phy)
...@@ -1293,21 +1295,19 @@ static int dwc3_suspend_common(struct dwc3 *dwc) ...@@ -1293,21 +1295,19 @@ static int dwc3_suspend_common(struct dwc3 *dwc)
{ {
unsigned long flags; unsigned long flags;
switch (dwc->dr_mode) { switch (dwc->current_dr_role) {
case USB_DR_MODE_PERIPHERAL: case DWC3_GCTL_PRTCAP_DEVICE:
case USB_DR_MODE_OTG:
spin_lock_irqsave(&dwc->lock, flags); spin_lock_irqsave(&dwc->lock, flags);
dwc3_gadget_suspend(dwc); dwc3_gadget_suspend(dwc);
spin_unlock_irqrestore(&dwc->lock, flags); spin_unlock_irqrestore(&dwc->lock, flags);
dwc3_core_exit(dwc);
break; break;
case USB_DR_MODE_HOST: case DWC3_GCTL_PRTCAP_HOST:
default: default:
/* do nothing */ /* do nothing */
break; break;
} }
dwc3_core_exit(dwc);
return 0; return 0;
} }
...@@ -1316,18 +1316,17 @@ static int dwc3_resume_common(struct dwc3 *dwc) ...@@ -1316,18 +1316,17 @@ static int dwc3_resume_common(struct dwc3 *dwc)
unsigned long flags; unsigned long flags;
int ret; int ret;
ret = dwc3_core_init(dwc); switch (dwc->current_dr_role) {
if (ret) case DWC3_GCTL_PRTCAP_DEVICE:
return ret; ret = dwc3_core_init(dwc);
if (ret)
return ret;
switch (dwc->dr_mode) {
case USB_DR_MODE_PERIPHERAL:
case USB_DR_MODE_OTG:
spin_lock_irqsave(&dwc->lock, flags); spin_lock_irqsave(&dwc->lock, flags);
dwc3_gadget_resume(dwc); dwc3_gadget_resume(dwc);
spin_unlock_irqrestore(&dwc->lock, flags); spin_unlock_irqrestore(&dwc->lock, flags);
/* FALLTHROUGH */ break;
case USB_DR_MODE_HOST: case DWC3_GCTL_PRTCAP_HOST:
default: default:
/* do nothing */ /* do nothing */
break; break;
...@@ -1338,7 +1337,7 @@ static int dwc3_resume_common(struct dwc3 *dwc) ...@@ -1338,7 +1337,7 @@ static int dwc3_resume_common(struct dwc3 *dwc)
static int dwc3_runtime_checks(struct dwc3 *dwc) static int dwc3_runtime_checks(struct dwc3 *dwc)
{ {
switch (dwc->dr_mode) { switch (dwc->current_dr_role) {
case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_PERIPHERAL:
case USB_DR_MODE_OTG: case USB_DR_MODE_OTG:
if (dwc->connected) if (dwc->connected)
...@@ -1381,12 +1380,11 @@ static int dwc3_runtime_resume(struct device *dev) ...@@ -1381,12 +1380,11 @@ static int dwc3_runtime_resume(struct device *dev)
if (ret) if (ret)
return ret; return ret;
switch (dwc->dr_mode) { switch (dwc->current_dr_role) {
case USB_DR_MODE_PERIPHERAL: case DWC3_GCTL_PRTCAP_DEVICE:
case USB_DR_MODE_OTG:
dwc3_gadget_process_pending_events(dwc); dwc3_gadget_process_pending_events(dwc);
break; break;
case USB_DR_MODE_HOST: case DWC3_GCTL_PRTCAP_HOST:
default: default:
/* do nothing */ /* do nothing */
break; break;
...@@ -1402,13 +1400,12 @@ static int dwc3_runtime_idle(struct device *dev) ...@@ -1402,13 +1400,12 @@ static int dwc3_runtime_idle(struct device *dev)
{ {
struct dwc3 *dwc = dev_get_drvdata(dev); struct dwc3 *dwc = dev_get_drvdata(dev);
switch (dwc->dr_mode) { switch (dwc->current_dr_role) {
case USB_DR_MODE_PERIPHERAL: case DWC3_GCTL_PRTCAP_DEVICE:
case USB_DR_MODE_OTG:
if (dwc3_runtime_checks(dwc)) if (dwc3_runtime_checks(dwc))
return -EBUSY; return -EBUSY;
break; break;
case USB_DR_MODE_HOST: case DWC3_GCTL_PRTCAP_HOST:
default: default:
/* do nothing */ /* do nothing */
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment