From patchwork Mon Mar 26 20:38:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10308659 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 AEA4360353 for ; Mon, 26 Mar 2018 20:39:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A373F2985B for ; Mon, 26 Mar 2018 20:39:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97F7F29873; Mon, 26 Mar 2018 20:39:25 +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 BAC6F2985B for ; Mon, 26 Mar 2018 20:39:24 +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=+Jop+YaeprRQgcuvehG0AltW7fdP2yapD5CnPRRFdEk=; b=Kp3SG7O1NpDCTYLHwr5WSG7vbN zw8+jDnl7HPAnudAbuUYBgQt2IEhrTkgeO/v65LmWeH4IJX9GxY8SqrGxFFnbYGkIA6stfNhzzmxM octJ3uSTC0TkKIseZ2X7NR/6+gVC9zdQNaM9eWJxJ3gz6F4ayVZUpDFQzaLqSxfqRE85q/R9w/mfT qGRYFTxA32aGx/TrF3vr9E0iaXDa+d8LlT9kZi5OhEgUJkLZAc0yCwEw8RzwFErbxS1/ClfGlZEPX FLJ1sTbdFYpSzS3V5Nl/G55AOjog1lgQ40oPzAE59pPdCwmLOthaIAIN2U7jTY0FdSjtwcmMSP6Kg iTZr/AnQ==; 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 1f0Ytn-0003d7-7e; Mon, 26 Mar 2018 20:39:23 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0Ytf-0003Wc-PE; Mon, 26 Mar 2018 20:39:17 +0000 Received: by mail-wr0-x244.google.com with SMTP id s18so20208611wrg.9; Mon, 26 Mar 2018 13:39:05 -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=rAF4DFuVCdTBjQfUMr6z/ExV6RDWsbtoqLIRjAVMx8s=; b=QbG+8wWA+ZPc/zbbdKuAMYbwSbwyDzjsUug48CA0Z3ZNXPawDY5nK2NpnUBTQaH04C ehfH0gtMww7/X/9dTxybTaP/ymFHwD9rD7IiKkszGlrjKWL0jNjR8ewnqIo5OQDdyayk liUd9MU2C8n/4VLbKyb+b2p31G2yjwqLhJyNQB0ve4K4eiCl6KQvnNtk0blc8R+L/2wF 4HIZo4xZ9a6iNzO/+2F9xmc2GU3jycTfk6RaN74vOvm6HMBrMeX8PqXHVdJrgbOVTq5i Aq7AItpJIfo74NOPduDK2jLEgVdOgU8HsKeNNVApXO3JqVk/taUlTpsXyNT72qb0YIy6 yrDw== 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=rAF4DFuVCdTBjQfUMr6z/ExV6RDWsbtoqLIRjAVMx8s=; b=IadOhHWRPwt0RAHZQvOL+VJ/22fc1KJCTDSyiPI7cHCc7koPK2dnT2JEd1aaCPcwNS HpV90bJRzqWo69kLzs9OLBmQsNCIj1BI0svCBYxbCHSZtUGNXpUYuteh6lUX7iFICKoy 2M7dteNB46GTot5m9aeccJJRYhlYAC32pDwZGDbctC8yJCVHtmt7zd/66aSOYTILQ+SW FFLIbGw7tdBkm069p1kp6fRbVN3nOGX98UUcV2Zng1ICaVrrFHzlSDC8IiR/vYzI+Cvg /OfezOH2EGF2jX3jXw+S25d0oAfo8RplTFiqeopKlSPantE1GFeu26AAoWPxrtzfmuE6 RyFg== X-Gm-Message-State: AElRT7E1Jrf9cj6X6AFOR1GxLyc0twnJn4rEO811NzoKWIR+Kh2Lu3K4 UurKa54AG6kGMYN+mSxtWLY= X-Google-Smtp-Source: AIpwx4/9urUGKoBWOJe9oYUEIGGg1dylE/B9GOEmysKU1G5CNO+EXZ0VrjCEvi0aah7+dS5PTRIRgQ== X-Received: by 10.223.225.4 with SMTP id d4mr7319008wri.24.1522096743855; Mon, 26 Mar 2018 13:39:03 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD741650468A1A7E01A883D6D.dip0.t-ipconnect.de. [2003:dc:d741:6504:68a1:a7e0:1a88:3d6d]) by smtp.googlemail.com with ESMTPSA id m126sm4897040wmf.43.2018.03.26.13.39.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 13:39:03 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Subject: [RFC usb-next v3 2/2] usb: core: use phy_exit during suspend if wake up is not supported Date: Mon, 26 Mar 2018 22:38:46 +0200 Message-Id: <20180326203846.7248-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180326203846.7248-1-martin.blumenstingl@googlemail.com> References: <20180326203846.7248-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180326_133915_822321_E89DADBD X-CRM114-Status: GOOD ( 16.48 ) 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 , j-keerthy@ti.com, stern@rowland.harvard.edu, chunfeng.yun@mediatek.com, linux-mediatek@lists.infradead.org, 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 reaching the lowest power levels in 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 Tested-by: Chunfeng Yun Reviewed-by: Roger Quadros --- drivers/usb/core/hcd.c | 8 +++++--- drivers/usb/core/phy.c | 35 +++++++++++++++++++++++++++++++++++ drivers/usb/core/phy.h | 5 +++++ 3 files changed, 45 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 44f008cda7a8..a39d9bb26a4f 100644 --- a/drivers/usb/core/phy.c +++ b/drivers/usb/core/phy.c @@ -157,3 +157,38 @@ 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); + + /* undo _init if _power_on failed */ + if (err && !device_may_wakeup(controller_dev)) + usb_phy_roothub_exit(phy_roothub); + + return err; +} +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);