Received: by 10.192.165.148 with SMTP id m20csp175816imm; Wed, 9 May 2018 10:40:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqJk2uDM+bVDuJoPaw85u+kAzM8JqSCNsj0bcksMi6kcK74hltvtzEQFD8120qYoQN5JHbl X-Received: by 2002:a63:6ec7:: with SMTP id j190-v6mr35965085pgc.71.1525887645336; Wed, 09 May 2018 10:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525887645; cv=none; d=google.com; s=arc-20160816; b=LXcdvQXonLSEwQlvbVtd+VeFK1VGpTtKw5C+4YoPidtNa6hhir0pV8LXnzZMyykiwM Y2PcrXYx2YIhdNbyCLLQTwRknIANjveZe1+SabdF2vmO5X3L+kkdA4Zsx6BU71jtgcXc yiYepwrlaeA9Ip4KtRsM0kFvZuInIC8MekFKWKuZtjJZiN/PIH80h4zDI0KtEtz8GxH/ 01xxzfFtcrk2hhMZ/NBooA3v/bVbRfXRf0vLGHtXb1bGVfyt8ScO8+ra+XgDHmTEg2pN i3WXLbCDi/GMcpTHEqruE70ZiF+NlcfM9Ugu758yFN0XeY3tGacqdfigmjkfTQ5q+r5W GC2g== 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=z1nQsnX90H0eoFgNxVLlzWN4xlks7Aup7ZQ4LPuIC2lAxiln3V3ocWdqOTDgXY9cy1 oL8fEteGabph2hF2FcGPlgCKgOlvc1YAmdUwaNsafh2XiEqFAKErwKyn046nHxRi0fMj ruYi5Sr8GttoQahxZvBhz6WKYPZwqwXXGPjmJSEtkl0KxuTYitINL4E+NZLhuZJHxMGl sbsO7xNGYVODU5qfcyjHhtwBtoSriwtDKD/hXOP4Ybj3Gky6V1sPJz1WgXydXKIGrFEv 6C+Cjp7fH3U2jMlJUy49lAf1uvKH0MfS9x+hSNxmQKFwdfp6GoX8EWcuFruWOtwAsyCe 1OCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=GF6v2fJ9; dkim=pass header.i=@codeaurora.org header.s=default header.b=eql9ZyXl; 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 r14-v6si28226836plj.341.2018.05.09.10.40.30; Wed, 09 May 2018 10:40:45 -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=GF6v2fJ9; dkim=pass header.i=@codeaurora.org header.s=default header.b=eql9ZyXl; 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 S964876AbeEIRkM (ORCPT + 99 others); Wed, 9 May 2018 13:40:12 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:36532 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935123AbeEIRju (ORCPT ); Wed, 9 May 2018 13:39:50 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 1C83F607E1; Wed, 9 May 2018 17:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525887590; bh=CAHb/8/4FWcYAm4XgrQmqbsQkm3P6yOx0Tjemj9KId0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GF6v2fJ9eNrtqf9inxOBu6AadJxgPnTXpS4/jfEUxFDspGsCWEg2vY/XVCL/v5zay yuhtuRSgHO8YWMQUHglnFasVZXZoXxo8ZDS3oqrocD8CBpJH00ook366MapqEs1QQu QiBj3LT71dED9kihyN4jUbe2mI5CxAJnGOYnf99A= 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 0AF64601A8; Wed, 9 May 2018 17:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525887589; bh=CAHb/8/4FWcYAm4XgrQmqbsQkm3P6yOx0Tjemj9KId0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eql9ZyXljpiaVmaVHYfoYH48PyhIxmfZjZ4o4j+QqKRKs1b5cGg1GBBc6foPY/P3I OPWqQnPD2wminBrdkHn+PEg225OKCS63kDh+inhuyjGg8SMB2HP2RxouzXBGXCHbpm u8eMPLVJm+Vzvdd0Cw2LPNGPX7V9WKFGFnpYijsU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 0AF64601A8 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 v4 3/3] usb: dwc3: core: Suspend PHYs on runtime suspend in host mode Date: Wed, 9 May 2018 23:09:21 +0530 Message-Id: <1525887562-2687-4-git-send-email-mgautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525887562-2687-1-git-send-email-mgautam@codeaurora.org> References: <1525887562-2687-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