From patchwork Sat Mar 24 14:21:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10306065 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 70544600CC for ; Sat, 24 Mar 2018 14:22:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61872292E7 for ; Sat, 24 Mar 2018 14:22:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55EC7292E9; Sat, 24 Mar 2018 14:22:01 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 948CD292E7 for ; Sat, 24 Mar 2018 14:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=W+U3QCNljz8uzj1+Qbj8+L+PhWvGhoKB5221g6bp4WA=; b=SJcc8Ftq1QSHF1LmEgsW01W/Ea VSnSkYctx9mPgbqHzljHRohrpP8g2p9UC6apQfFfMqsBwIgX7aQyc6XYGFMJwJz/HNFyrnWjy9dz1 CvrV/42yYI7KSJDr4fDZTD1XIygEhm74KqmsSiRKQMBNDyQ7vw8ondfhrGYhTkjfu6yr79oQKZUM7 534amjVVQuliuWTwt+VkmC1iyLOXDbdVbDJBhP3dCmiR1OoFHKwPJzUdzFly/5IMBurITb6eWRKbA TJmTz/84PsqAS7JyOS5LlgdnEywpARYQumKDjagkRglLgg4gU7qkTD792rXmLdz7wTpdgkotOVJNt 47aiZ2EQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezk3S-0005vU-7l; Sat, 24 Mar 2018 14:21:58 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezk3F-0005nd-Mo; Sat, 24 Mar 2018 14:21:49 +0000 Received: by mail-wm0-x244.google.com with SMTP id t7so8191687wmh.5; Sat, 24 Mar 2018 07:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HsXWZWhGy4xJMJosOtL9tzqEDuKn2gs3VSpZ3qnaR/M=; b=uNXoSeniZ3GmaFiMGlViKOD/DHrTzqi6YqgMvv0vj1D0wr4ZZ4a7zcgzo3GAct7NNI rApBVPFnmvKLIrgqUE56L9RGw7iXcJkTkYcNCpBuF0ve+AdIFUVhRZumv2or1q/zz7JC 9WSQG1Kg+CaTwMAllBZ1Uxex6JFpIu+zAgQN3T7wO7NSHUOC5Yvzoa5OscgE1LCii0ue eusTzcw9W9gm/XrPhT0dBn28m84QUVWcaTWPNd3jkG1+AwEnhfJec4mgg3VVDHAo2mp0 9atl8kBj/58cexjrpogxPr//RvhnHd2dsUCZKjX1vIAEab7G86TbIQwMqUlJzEkgOwm8 CZzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HsXWZWhGy4xJMJosOtL9tzqEDuKn2gs3VSpZ3qnaR/M=; b=iTmQEc8DASvz2WoTQ3DDWy/kYMPsQ+/5AiWHKdWkJxSBUQeVwnSzrjOqvMY3PUhscj 3JrmlmO/XbY2QCSSubENMouKglSr/MaZ+OmjmjVjwSvN8x3qRz4zt8KVcwkmOy9CaHJ6 Z6ldZSF9ZGxOEnnP11CFJwu06wYxcC5GF03VKhnp7rhHAoSunEJcBeqY40K+1ro6y9os B7L2UBp7ktw1HMEfY69t9jDyAU3St+zqeECnFzS7Xni11TeTjc67nIQ4HTZ9hd9Ysi6D 2PEvLePdN/4dRH2tb4qAJJI3rtXmWrjdRXtTBWP+b5pa32Fz61hFF8lF2sI06gQfOWlO XrrQ== X-Gm-Message-State: AElRT7FuzlA+gZUUyQ4uekloLadphRA1qAVfZJlp17mb+MCfCoUpHpho r1w0ZdSs9P/wI2d7j/e4eLY= X-Google-Smtp-Source: AIpwx4/QCoWRW2yww7cmd01GfNTex541xrRy7I2vWFc8cESIfTcQ06AY3JzHDY1VSO8pTYbgMRvhVw== X-Received: by 10.28.114.10 with SMTP id n10mr1486209wmc.124.1521901295149; Sat, 24 Mar 2018 07:21:35 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD7416504613646B2A165589A.dip0.t-ipconnect.de. [2003:dc:d741:6504:6136:46b2:a165:589a]) by smtp.googlemail.com with ESMTPSA id n64sm11132247wmd.11.2018.03.24.07.21.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 07:21:34 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org Subject: [RFC usb-next v2 2/2] usb: core: use phy_exit during suspend if wake up is not supported Date: Sat, 24 Mar 2018 15:21:21 +0100 Message-Id: <20180324142121.8618-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180324142121.8618-1-martin.blumenstingl@googlemail.com> References: <20180324142121.8618-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180324_072145_794154_32502D00 X-CRM114-Status: GOOD ( 15.80 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: d-gerlach@ti.com, Martin Blumenstingl , gregkh@linuxfoundation.org, stern@rowland.harvard.edu, chunfeng.yun@mediatek.com, linux-mediatek@lists.infradead.org, j-keerthy@ti.com, matthias.bgg@gmail.com, linux-amlogic@lists.infradead.org, kishon@ti.com, rogerq@ti.com MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If the USB controller can wake up the system (which is the case for example with the Mediatek USB3 IP) then we must not call phy_exit during suspend to ensure that the USB controller doesn't have to re-enumerate the devices during resume. However, if the USB controller cannot wake up the system (which is the case for example on various TI platforms using a dwc3 controller) then we must call phy_exit during suspend. Otherwise the PHY driver keeps the clocks enabled, which prevents the system from entering the suspend state. Solve this by introducing two new functions in the PHY wrapper which are dedicated to the suspend and resume handling. If the controller can wake up the system the new usb_phy_roothub_suspend function will simply call usb_phy_roothub_power_off. However, if wake up is not supported by the controller it will also call usb_phy_roothub_exit. The also new usb_phy_roothub_resume function takes care of calling usb_phy_roothub_init (if the controller can't wake up the system) in addition to usb_phy_roothub_power_on. Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the HCD") Fixes: 178a0bce05cbc1 ("usb: core: hcd: integrate the PHY wrapper into the HCD core") Reported-by: Roger Quadros Suggested-by: Roger Quadros Suggested-by: Chunfeng Yun Signed-off-by: Martin Blumenstingl --- drivers/usb/core/hcd.c | 8 +++++--- drivers/usb/core/phy.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/usb/core/phy.h | 5 +++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 15b0418e3b6a..78bae4ecd68b 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2262,7 +2262,8 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) hcd->state = HC_STATE_SUSPENDED; if (!PMSG_IS_AUTO(msg)) - usb_phy_roothub_power_off(hcd->phy_roothub); + usb_phy_roothub_suspend(hcd->self.sysdev, + hcd->phy_roothub); /* Did we race with a root-hub wakeup event? */ if (rhdev->do_remote_wakeup) { @@ -2302,7 +2303,8 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) } if (!PMSG_IS_AUTO(msg)) { - status = usb_phy_roothub_power_on(hcd->phy_roothub); + status = usb_phy_roothub_resume(hcd->self.sysdev, + hcd->phy_roothub); if (status) return status; } @@ -2344,7 +2346,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) } } else { hcd->state = old_state; - usb_phy_roothub_power_off(hcd->phy_roothub); + usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", "resume", status); if (status != -ESHUTDOWN) diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c index d1861c5a74de..e794cbee97e9 100644 --- a/drivers/usb/core/phy.c +++ b/drivers/usb/core/phy.c @@ -155,3 +155,40 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub) phy_power_off(roothub_entry->phy); } EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off); + +int usb_phy_roothub_suspend(struct device *controller_dev, + struct usb_phy_roothub *phy_roothub) +{ + usb_phy_roothub_power_off(phy_roothub); + + /* keep the PHYs initialized so the device can wake up the system */ + if (device_may_wakeup(controller_dev)) + return 0; + + return usb_phy_roothub_exit(phy_roothub); +} +EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend); + +int usb_phy_roothub_resume(struct device *controller_dev, + struct usb_phy_roothub *phy_roothub) +{ + int err; + + /* if the device can't wake up the system _exit was called */ + if (device_may_wakeup(controller_dev)) { + err = usb_phy_roothub_init(phy_roothub); + if (err) + return err; + } + + err = usb_phy_roothub_power_on(phy_roothub); + if (err) { + if (device_may_wakeup(controller_dev)) + usb_phy_roothub_exit(phy_roothub); + + return err; + } + + return 0; +} +EXPORT_SYMBOL_GPL(usb_phy_roothub_resume); diff --git a/drivers/usb/core/phy.h b/drivers/usb/core/phy.h index eb31253201ad..605555901d44 100644 --- a/drivers/usb/core/phy.h +++ b/drivers/usb/core/phy.h @@ -7,3 +7,8 @@ int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub); int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub); void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub); + +int usb_phy_roothub_suspend(struct device *controller_dev, + struct usb_phy_roothub *phy_roothub); +int usb_phy_roothub_resume(struct device *controller_dev, + struct usb_phy_roothub *phy_roothub);