Received: by 10.192.165.148 with SMTP id m20csp384680imm; Fri, 4 May 2018 11:49:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr99+MmM2p0MA/d101lGyzR6l+U6qfuPeRDmMe5/Jjj7nL+gu+lxt+mXr9OkdUwtN4CBRkq X-Received: by 10.98.247.19 with SMTP id h19mr18064501pfi.165.1525459741498; Fri, 04 May 2018 11:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525459741; cv=none; d=google.com; s=arc-20160816; b=twtwQnCfAXCxiFwDPkkXFpYl77tTx635PnUBtfknPZ0MNCGeHfGvLUjvoOVyaPSdcM 5EEj44+NKZTzoGOw0yAA+FlYawGeWYvNm47pnDRJdQjngFCEmLYiuXc6F0lprRCmLWRr qB0KZUl4GHZe5Q9hmcfKoddg5YyW1Djfdabe1U5pq1vIVaPOZG8DpDARlTp2CtOYiobc QdkR6P2WoUY52YMzgytVpzL5zdB8NygMWwGhwNJ8myOAoMJbn7wPut4BAR9bm6Er7WbR fkyXymN8+Uy1+FpVvMPbt8yaD4/wlCM8gggXerzyJO8dGTSJ3sHSQhc55oPFFcMOPwLE WhSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=e1B0LXemomBCdh2XelHwljap/Ikyz9KQrUcRN5S81sk=; b=j6BGzOuAQVluDcs9Qf5tqGXHs5LYHwY3FJT8VFljRjoMktR/0K2H14R72daAUS++Uo 8w0w1juICOCqxcWb0lxuRy2ahkplh/74eZ/9JIlNbSM5QxKj4WKqS6futL8mC/PC/8FV uLLiXJnzdiYYzigvBtLDbaaM7p1z8CY+J/x6AqAikqxJDlhdip7OYAD1gDvWeM0nOJYR X2Y1yf0mhyrNjuQlrBBEcYfZ8WBLcsCP3WlpJgxVzXm25di5pYkdQvcMtD0HfigPoRBY SwRSyHQyNh8SzD5VWNuFWdARp592EeyR9KA9sViipGSw003Tq19GBlxngd9aWf+oq0cl 7p1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=CapRN2Eg; dkim=pass header.i=@codeaurora.org header.s=default header.b=CapRN2Eg; 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 n12-v6si13630511pgr.437.2018.05.04.11.48.46; Fri, 04 May 2018 11:49:01 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=CapRN2Eg; dkim=pass header.i=@codeaurora.org header.s=default header.b=CapRN2Eg; 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 S1751869AbeEDSsl (ORCPT + 99 others); Fri, 4 May 2018 14:48:41 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:34896 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751847AbeEDSsg (ORCPT ); Fri, 4 May 2018 14:48:36 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D1B4B60C55; Fri, 4 May 2018 18:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525459715; bh=CAHb/8/4FWcYAm4XgrQmqbsQkm3P6yOx0Tjemj9KId0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CapRN2Eg0gHi1A/LUGEF1/Pab3sCNAnP4GagTXJ7q9Y/bQ5Ik8k9WmJlH1r0V4wqu 8+Q0zJO8n2Wq+CRxn6u9++fPF/Xp6LVJMMTNNiNDWD3T+M7EhikG9ParWpEfP7C2ms xMwFjcHP5kGrrYfJgbx4YL5k+BsXDfMdd9k0gqqs= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from mgautam-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 130AD6037B; Fri, 4 May 2018 18:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525459715; bh=CAHb/8/4FWcYAm4XgrQmqbsQkm3P6yOx0Tjemj9KId0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CapRN2Eg0gHi1A/LUGEF1/Pab3sCNAnP4GagTXJ7q9Y/bQ5Ik8k9WmJlH1r0V4wqu 8+Q0zJO8n2Wq+CRxn6u9++fPF/Xp6LVJMMTNNiNDWD3T+M7EhikG9ParWpEfP7C2ms xMwFjcHP5kGrrYfJgbx4YL5k+BsXDfMdd9k0gqqs= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 130AD6037B Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=mgautam@codeaurora.org From: Manu Gautam To: balbi@kernel.org, robh@kernel.org, andy.gross@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org, linux-arm-msm@vger.kernel.org, Manu Gautam , Greg Kroah-Hartman Subject: [PATCH v3 3/3] usb: dwc3: core: Suspend PHYs on runtime suspend in host mode Date: Sat, 5 May 2018 00:18:09 +0530 Message-Id: <1525459689-1358-4-git-send-email-mgautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525459689-1358-1-git-send-email-mgautam@codeaurora.org> References: <1525459689-1358-1-git-send-email-mgautam@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some PHY drivers (e.g. for Qualcomm QUSB2 and QMP PHYs) support runtime PM to reduce PHY power consumption during bus_suspend. Add changes to let core auto-suspend PHYs on host bus-suspend using GUSB2PHYCFG register if needed for a platform. Also perform PHYs runtime suspend/resume and let platform glue drivers e.g. dwc3-qcom handle remote wakeup during bus suspend by waking up devices on receiving wakeup event from PHY. Signed-off-by: Manu Gautam --- drivers/usb/dwc3/core.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index a15648d..449a098 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1394,6 +1394,7 @@ static int dwc3_remove(struct platform_device *pdev) static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) { unsigned long flags; + u32 reg; switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: @@ -1403,9 +1404,25 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) dwc3_core_exit(dwc); break; case DWC3_GCTL_PRTCAP_HOST: - /* do nothing during host runtime_suspend */ - if (!PMSG_IS_AUTO(msg)) + if (!PMSG_IS_AUTO(msg)) { dwc3_core_exit(dwc); + break; + } + + /* Let controller to suspend HSPHY before PHY driver suspends */ + if (dwc->dis_u2_susphy_quirk || + dwc->dis_enblslpm_quirk) { + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); + reg |= DWC3_GUSB2PHYCFG_ENBLSLPM | + DWC3_GUSB2PHYCFG_SUSPHY; + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); + + /* Give some time for USB2 PHY to suspend */ + usleep_range(5000, 6000); + } + + phy_pm_runtime_put_sync(dwc->usb2_generic_phy); + phy_pm_runtime_put_sync(dwc->usb3_generic_phy); break; case DWC3_GCTL_PRTCAP_OTG: /* do nothing during runtime_suspend */ @@ -1433,6 +1450,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) { unsigned long flags; int ret; + u32 reg; switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: @@ -1446,13 +1464,25 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) 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; dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); + break; } + /* Restore GUSB2PHYCFG bits that were modified in suspend */ + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); + if (dwc->dis_u2_susphy_quirk) + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; + + if (dwc->dis_enblslpm_quirk) + reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM; + + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); + + phy_pm_runtime_get_sync(dwc->usb2_generic_phy); + phy_pm_runtime_get_sync(dwc->usb3_generic_phy); break; case DWC3_GCTL_PRTCAP_OTG: /* nothing to do on runtime_resume */ -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project