Skip to content

Commit

Permalink
usb: dwc3: core: Power-off core/PHYs on system_suspend in host mode
Browse files Browse the repository at this point in the history
Commit 689bf72 ("usb: dwc3: Don't reinitialize core during
host bus-suspend/resume") updated suspend/resume routines to not
power_off and reinit PHYs/core for host mode.
It broke platforms that rely on DWC3 core to power_off PHYs to
enter low power state on system suspend.

Perform dwc3_core_exit/init only during host mode system_suspend/
resume to addresses power regression from above mentioned patch
and also allow USB session to stay connected across
runtime_suspend/resume in host mode. While at it also replace
existing checks for HOST only dr_mode with current_dr_role to
have similar core driver behavior for both Host-only and DRD+Host
configurations.

Fixes: 689bf72 ("usb: dwc3: Don't reinitialize core during host bus-suspend/resume")
Reviewed-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  • Loading branch information
Manu Gautam authored and Felipe Balbi committed Feb 12, 2018
1 parent 00b4217 commit c4a5153
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions drivers/usb/dwc3/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
reg |= DWC3_GCTL_PRTCAPDIR(mode);
dwc3_writel(dwc->regs, DWC3_GCTL, reg);

dwc->current_dr_role = mode;
}

static void __dwc3_set_mode(struct work_struct *work)
Expand Down Expand Up @@ -133,8 +135,6 @@ static void __dwc3_set_mode(struct work_struct *work)

dwc3_set_prtcap(dwc, dwc->desired_dr_role);

dwc->current_dr_role = dwc->desired_dr_role;

spin_unlock_irqrestore(&dwc->lock, flags);

switch (dwc->desired_dr_role) {
Expand Down Expand Up @@ -219,7 +219,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
* XHCI driver will reset the host block. If dwc3 was configured for
* host-only mode, then we can return early.
*/
if (dwc->dr_mode == USB_DR_MODE_HOST)
if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST)
return 0;

reg = dwc3_readl(dwc->regs, DWC3_DCTL);
Expand Down Expand Up @@ -919,7 +919,6 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)

switch (dwc->dr_mode) {
case USB_DR_MODE_PERIPHERAL:
dwc->current_dr_role = DWC3_GCTL_PRTCAP_DEVICE;
dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);

if (dwc->usb2_phy)
Expand All @@ -935,7 +934,6 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
}
break;
case USB_DR_MODE_HOST:
dwc->current_dr_role = DWC3_GCTL_PRTCAP_HOST;
dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);

if (dwc->usb2_phy)
Expand Down Expand Up @@ -1287,7 +1285,7 @@ static int dwc3_remove(struct platform_device *pdev)
}

#ifdef CONFIG_PM
static int dwc3_suspend_common(struct dwc3 *dwc)
static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
{
unsigned long flags;

Expand All @@ -1299,6 +1297,10 @@ static int dwc3_suspend_common(struct dwc3 *dwc)
dwc3_core_exit(dwc);
break;
case DWC3_GCTL_PRTCAP_HOST:
/* do nothing during host runtime_suspend */
if (!PMSG_IS_AUTO(msg))
dwc3_core_exit(dwc);
break;
default:
/* do nothing */
break;
Expand All @@ -1307,7 +1309,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc)
return 0;
}

static int dwc3_resume_common(struct dwc3 *dwc)
static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
{
unsigned long flags;
int ret;
Expand All @@ -1323,6 +1325,13 @@ static int dwc3_resume_common(struct dwc3 *dwc)
spin_unlock_irqrestore(&dwc->lock, flags);
break;
case DWC3_GCTL_PRTCAP_HOST:
/* nothing to do on host runtime_resume */
if (!PMSG_IS_AUTO(msg)) {
ret = dwc3_core_init(dwc);
if (ret)
return ret;
}
break;
default:
/* do nothing */
break;
Expand All @@ -1334,12 +1343,11 @@ static int dwc3_resume_common(struct dwc3 *dwc)
static int dwc3_runtime_checks(struct dwc3 *dwc)
{
switch (dwc->current_dr_role) {
case USB_DR_MODE_PERIPHERAL:
case USB_DR_MODE_OTG:
case DWC3_GCTL_PRTCAP_DEVICE:
if (dwc->connected)
return -EBUSY;
break;
case USB_DR_MODE_HOST:
case DWC3_GCTL_PRTCAP_HOST:
default:
/* do nothing */
break;
Expand All @@ -1356,7 +1364,7 @@ static int dwc3_runtime_suspend(struct device *dev)
if (dwc3_runtime_checks(dwc))
return -EBUSY;

ret = dwc3_suspend_common(dwc);
ret = dwc3_suspend_common(dwc, PMSG_AUTO_SUSPEND);
if (ret)
return ret;

Expand All @@ -1372,7 +1380,7 @@ static int dwc3_runtime_resume(struct device *dev)

device_init_wakeup(dev, false);

ret = dwc3_resume_common(dwc);
ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME);
if (ret)
return ret;

Expand Down Expand Up @@ -1419,7 +1427,7 @@ static int dwc3_suspend(struct device *dev)
struct dwc3 *dwc = dev_get_drvdata(dev);
int ret;

ret = dwc3_suspend_common(dwc);
ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
if (ret)
return ret;

Expand All @@ -1435,7 +1443,7 @@ static int dwc3_resume(struct device *dev)

pinctrl_pm_select_default_state(dev);

ret = dwc3_resume_common(dwc);
ret = dwc3_resume_common(dwc, PMSG_RESUME);
if (ret)
return ret;

Expand Down

0 comments on commit c4a5153

Please sign in to comment.