From patchwork Tue Mar 27 21:26: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: 10311697 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 31ADE60212 for ; Tue, 27 Mar 2018 21:27:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 260032853E for ; Tue, 27 Mar 2018 21:27:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A98C28A19; Tue, 27 Mar 2018 21:27: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 56EF12853E for ; Tue, 27 Mar 2018 21:26:58 +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=w1Qmkux10Z213xEKVhCdzbXacNZCBlLewWPkkR+hH2A=; b=eY+w93qAHF/R2GijgbmqrO63Da HzILdzQ5UqxLec8FGx3bsA/6nKQaiWJu8jCkQWI53x0jS6wcwJykPsVLKbBLy9WLbVZtBdlZ3WiIQ AOm5HjXXOvh+C0Gx/tdCnZ5xaFLMgdDEMkKoH1jKzSyZOYmDPZ3SoaJmOIYzomoYWN3RHyfv7Vsr2 6/nxj2WpMocjf5io9DIRaQHatzAMeKv0CIzRmDnRJOk/AKQFxI7R4hmK1ATtnlI9G38j1lhrRHtT/ vij6kdgTFBMq4SuimKkKXEwRLp9kylA1cONghK12q6DSETVHMHGScfxkL5FIp6PEQqjLvsNugwLoc +X8xs0ow==; 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 1f0w7L-0003rO-MC; Tue, 27 Mar 2018 21:26:55 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0w7G-0003mM-QQ; Tue, 27 Mar 2018 21:26:52 +0000 Received: by mail-wm0-x243.google.com with SMTP id v21so1309989wmc.1; Tue, 27 Mar 2018 14:26:41 -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=6Y4ZBrBb6LzBzzPMVBD8AWbPgnCY7FK+Ldsdhy3yxlo=; b=ESY9RghZSX4nsm7mmG/Tp5YADP6Y8DPKmmBAv2Kt9ArwK1H3KbgY0W13ptFCVm3cu4 YYBbAaMeh7vrf3wgtbqkWD2LMX4youOSXhJ82cCXLUCPuleuuKKqbmCUSP5qEHCmq8Pt 5gHXtLT4QYpVpIntS+Dnu0G89lD+nF9ltq/cIwh6JoMIgu17mWX/7hyDgd3NK76USkF+ A9ySnYj10j3mg71q6JyiVbLVH8jpmeCK/FwNhvDIcVPg0pJvJgRmEJiUXd9zO6x8Jbz9 7kpbVpzpoM04RslVPsiOYpuJJKUBP/y3SYi+ztgjNhl6oj4HHQbGYI94nfPFATXcoNl6 zFXQ== 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=6Y4ZBrBb6LzBzzPMVBD8AWbPgnCY7FK+Ldsdhy3yxlo=; b=HgNoJdcs6M9zOmOtx8Fa0bA9fTiDDpSXh484QoMfdUnpeuuAN3RYFnSe50egDCv3hq HfkBciLgWG4s6Di7LDkSgEKZCEcrjaQUtlDvZy8170XrACTZdF5lWXCU9SCFcFU+i4F8 5b9Y2E0sZVtdIuRKbyXQKHzJ7+rbu6J2+dNADc9R/tVMEzWT6MhrnacJmOOQyseTg0Ct xkByzOBzM/TzonlmmFCKdnuqmmPwQ5skN95Mo4cAu8JhESTIhlpHUE7GqlP5G+IBWV97 Y1WvPttPMWMqVzNh1xA+1K1kNUtHiN4ilD3pS+SRjPfTErMGwAtV0o19Qw/p3D8XzGrD FVEA== X-Gm-Message-State: AElRT7G7WrNbHki73ekAYyMQuwYZ22xKUO9mD8q972HpCYjnh+h/trnY z+JZcZeu01+9cs+3S23lt54= X-Google-Smtp-Source: AIpwx489eMxG2i25KOB3RR6a6d9SKLd64Wv3Tdzzrs8zmKq8Z6NNGwzrhWaL6ih6Ny6vf9axT3CwvA== X-Received: by 10.28.37.134 with SMTP id l128mr686272wml.10.1522186000560; Tue, 27 Mar 2018 14:26:40 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD741650438E4DF4717ABE1C9.dip0.t-ipconnect.de. [2003:dc:d741:6504:38e4:df47:17ab:e1c9]) by smtp.googlemail.com with ESMTPSA id d85sm3438344wmi.23.2018.03.27.14.26.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 14:26:39 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH usb-next v4 2/2] usb: core: use phy_exit during suspend if wake up is not supported Date: Tue, 27 Mar 2018 23:26:21 +0200 Message-Id: <20180327212621.3400-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327212621.3400-1-martin.blumenstingl@googlemail.com> References: <20180327212621.3400-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180327_142650_871028_2F350DDB X-CRM114-Status: GOOD ( 16.09 ) 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);