Received: by 10.213.65.68 with SMTP id h4csp1731896imn; Mon, 19 Mar 2018 11:43:00 -0700 (PDT) X-Google-Smtp-Source: AG47ELs44vG9qaHdK3O12dglMpfyIRJPxlgAozAL0ugdBBz0WXzniXx4+3gXaesYk0Iduil524XU X-Received: by 10.101.101.133 with SMTP id u5mr9776485pgv.151.1521484980553; Mon, 19 Mar 2018 11:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484980; cv=none; d=google.com; s=arc-20160816; b=uh+vdjQEJ2nbJVRV6EKVWBWiMZUMnU3qfFCbBO7tZSZMK1PrcoUPVGN1gjNhSHcCQU e29ELmkUKSmlIrwQ9TBhrKPuWQSHLc6LAA7SCocIaRYU8FUkw0BuZCKvuuNtXtSrEVN+ /l+nvGMLLH44hTTHuvsOyHojJfC7QMoY3TEeyjcF1vsAwJzEtKOyDwtHzqZ6R6y3I/AK 4ZwUvRIm1JGHqxPw4wBEM1kBjBp700h6Y4BnX7BGD/+LyFhYv9O8hi5pq530jBdjzTx8 QsJhY9A2nQZ0xFFa3ZQWmf5GqLwwynDHdSqbk37jD94t2JDJF6dvw9q4tMTB4DqBteI5 1cEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=oYAvJwUDA/h7Hm4HxdEFfSfSqjxiX3JXJFNzQ3x6aLY=; b=Z22VChbEYHDU9O4DzWVxkFpztsGaBlm1AxeuFR6dcbfGttNsqFtzQ4qmA5Zdof7yZv a98sjw9/LIJMrJxFTtFicYF07m2ryjFhMKWDIff3mTjMr2+6+Fqz1KuAkiAytvb/xLxL Bfm7i7ptQxLu90O7BF4mjWwx5WG8rBT1Il2tI9I6TfjdGWa99xknIWnNDKQu4X5uff8G 3/p8H5/oxVeywwwESnP2Y8v/5OLhIvFTe7TkL01eRys+qpeDLgkdTE735Vwb4DzWtZuU vQF4OfvwtJm2LlzgAmlDYSjRvGmwgTebukjRRhsBCVFOWQlK6S6JJfNXdUgzzMTGu9Jt CgyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 80si311286pfj.22.2018.03.19.11.42.46; Mon, 19 Mar 2018 11:43:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032251AbeCSSlI (ORCPT + 99 others); Mon, 19 Mar 2018 14:41:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54088 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970218AbeCSScv (ORCPT ); Mon, 19 Mar 2018 14:32:51 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B48691292; Mon, 19 Mar 2018 18:32:50 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roger Quadros , Manu Gautam , Felipe Balbi Subject: [PATCH 4.15 46/52] usb: dwc3: core: Power-off core/PHYs on system_suspend in host mode Date: Mon, 19 Mar 2018 19:08:44 +0100 Message-Id: <20180319180737.522895594@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180734.976730813@linuxfoundation.org> References: <20180319180734.976730813@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Manu Gautam commit c4a5153e87fdf6805f63ff57556260e2554155a5 upstream. 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. 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: 689bf72c6e0d ("usb: dwc3: Don't reinitialize core during host bus-suspend/resume") Reviewed-by: Roger Quadros Signed-off-by: Manu Gautam Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/core.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -100,6 +100,8 @@ static void dwc3_set_prtcap(struct dwc3 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) @@ -133,8 +135,6 @@ static void __dwc3_set_mode(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) { @@ -218,7 +218,7 @@ static int dwc3_core_soft_reset(struct d * 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); @@ -915,7 +915,6 @@ static int dwc3_core_init_mode(struct dw 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) @@ -931,7 +930,6 @@ static int dwc3_core_init_mode(struct dw } 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) @@ -1279,7 +1277,7 @@ static int dwc3_remove(struct platform_d } #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; @@ -1291,6 +1289,10 @@ static int dwc3_suspend_common(struct dw 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; @@ -1299,7 +1301,7 @@ static int dwc3_suspend_common(struct dw 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; @@ -1315,6 +1317,13 @@ static int dwc3_resume_common(struct 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; @@ -1326,12 +1335,11 @@ static int dwc3_resume_common(struct 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; @@ -1348,7 +1356,7 @@ static int dwc3_runtime_suspend(struct d 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 +1372,7 @@ static int dwc3_runtime_resume(struct de device_init_wakeup(dev, false); - ret = dwc3_resume_common(dwc); + ret = dwc3_resume_common(dwc, PMSG_AUTO_RESUME); if (ret) return ret; @@ -1411,7 +1419,7 @@ static int dwc3_suspend(struct device *d 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 +1435,7 @@ static int dwc3_resume(struct device *de pinctrl_pm_select_default_state(dev); - ret = dwc3_resume_common(dwc); + ret = dwc3_resume_common(dwc, PMSG_RESUME); if (ret) return ret;