From patchwork Wed Jan 17 10:46:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 10169027 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F2EF6603B5 for ; Wed, 17 Jan 2018 10:46:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF9592848B for ; Wed, 17 Jan 2018 10:46:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D356A284F5; Wed, 17 Jan 2018 10:46:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376122848B for ; Wed, 17 Jan 2018 10:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752742AbeAQKql (ORCPT ); Wed, 17 Jan 2018 05:46:41 -0500 Received: from lelnx193.ext.ti.com ([198.47.27.77]:35270 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbeAQKqh (ORCPT ); Wed, 17 Jan 2018 05:46:37 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id w0HAkYGd026612; Wed, 17 Jan 2018 04:46:34 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1516185994; bh=i7emcHQb7gEinZ2shr3+QZkfWRpGtzpKe6QXWo4HcjY=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=EMlw99etFV5XBsWRLuhP//2aJbf7Z55M5EtwFq7StTwBBH1mFDtrrgvfzZF7k3Fsy CTtW96YT4F8Cl3yj7xv48BkF+a9vFRjO+kr3OT6tev9wAHIgM7+XTENNKk/YY0BLB5 k+x5Q6oJSjBqidSUyrTbvpMrzkn08sTwWpF/UKz8= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0HAkY8X026564; Wed, 17 Jan 2018 04:46:34 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Wed, 17 Jan 2018 04:46:33 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Wed, 17 Jan 2018 04:46:33 -0600 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0HAkWnP007746; Wed, 17 Jan 2018 04:46:32 -0600 Subject: Re: [PATCH] usb: dwc3: core: Power-off core/PHYs on system_suspend in host mode To: Manu Gautam , Felipe Balbi CC: , References: <1516083989-2129-1-git-send-email-mgautam@codeaurora.org> From: Roger Quadros Message-ID: <7ecefa87-6214-f3f1-f08f-03589ea9400b@ti.com> Date: Wed, 17 Jan 2018 12:46:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1516083989-2129-1-git-send-email-mgautam@codeaurora.org> Content-Language: en-GB X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Manu, On 16/01/18 08:26, Manu Gautam wrote: > Commit 689bf72c6e0d ("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. > > Fixes: 689bf72c6e0d ("usb: dwc3: Don't reinitialize core during host bus-suspend/resume") > Signed-off-by: Manu Gautam > --- > drivers/usb/dwc3/core.c | 23 +++++++++++++++-------- > 1 file changed, 15 insertions(+), 8 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index 0783250..e9fbee9 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -1279,7 +1279,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; > > @@ -1292,14 +1292,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc) > break; > case DWC3_GCTL_PRTCAP_HOST: > default: > - /* do nothing */ > + /* do nothing during host runtime_suspend */ > + if (!PMSG_IS_AUTO(msg)) > + dwc3_core_exit(dwc); > break; since we're now doing something specific to HOST case we need to separate out the 'default' case so, + default: + break; > } > > 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; > @@ -1316,7 +1318,12 @@ static int dwc3_resume_common(struct dwc3 *dwc) > break; > case DWC3_GCTL_PRTCAP_HOST: > default: > - /* do nothing */ > + /* nothing to do on host runtime_resume */ > + if (!PMSG_IS_AUTO(msg)) { > + ret = dwc3_core_init(dwc); > + if (ret) > + return ret; > + } > break; same here. > } > > @@ -1348,7 +1355,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; > > @@ -1364,7 +1371,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; > > @@ -1411,7 +1418,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; > > @@ -1427,7 +1434,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; > > You also need to fix-up index e9fbee9..a213295 100644 After these changes applied, I could get suspend/resume working properly on dra7x-evm for host, device and dual-role cases. --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1333,12 +1333,11 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) 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; and finally index a213295..728955c 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -218,7 +218,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);