From patchwork Sun Apr 8 21:27:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10328623 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 690F56053B for ; Sun, 8 Apr 2018 21:28:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58BE1287A6 for ; Sun, 8 Apr 2018 21:28:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D55C28807; Sun, 8 Apr 2018 21:28:40 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI 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 96EBE287A6 for ; Sun, 8 Apr 2018 21:28:39 +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=XEweEIm8anbHpHbs1M5ZLVgNkTcv8x3X80ObIH5Ibhg=; b=ZC9LfnxNoDuTQ8qJTxLOHbk7jN AAKkTFxJrm7CKyjio5sZ3DDS2xDYtxSnILAkugGZ8TwWYPUQtkXtnaAj8LZwveEIH4ttHdMsqalc8 XuwewnfjTOzcDMIZIy2d6CJH29jo+dBy8oHpW2H2pTf0Bns63+nR4NYt807w9hy3HOwJX9Brh12Uq 25+BSdp7gS/HO4jZsDfICtYwmg0xodgasEiRf6aJQsxl1oZ9XdXpOJf3ZCYlETyBCdS0908Ch4pHN dl//R8krYOYal20w15c10Ao80c71RpX0IAywzyxkPryVP8I5CRTR3WzjLryudD7h9Xt2V8bxPYUHX z+LmlGOA==; 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 1f5HrX-0006Ja-Q8; Sun, 08 Apr 2018 21:28:35 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5HrA-0005ya-8u; Sun, 08 Apr 2018 21:28:14 +0000 Received: by mail-wr0-x241.google.com with SMTP id y55so6824612wry.3; Sun, 08 Apr 2018 14:28:01 -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=xBMJUMz7et9QK91vtZB3y+XIibJd8v2fDulvJteSDSM=; b=hCFnAIVbBNyXxag+fJFRk/RXu5BM/NnxxcJ271FzpMF4WdwFKpjsneXOOsu02RqLSh t5gW/g/RrA5efek7t4XptlVaPAaz4LPvdtmQ+QOqhAgn/UUq7CkqBVTZH8ObIrxgdffz FDjiKIQT3g6JD24JufrdQs3apzBCes74aeUwirdur2xG2d/Ggv800A07ZjqSOcnt+M0x tvW+8scYbMKkQyXBPNJ1iTZWlyH2UjpGL/a9UDOfI5VCf50nUBq8UgBBRYdNvgIC8KwN PzFWZpUSyPy/PpU8PWs3NSeEhwUkEZCdXxV5Nn2LHoIGrHOvcohd5FrQ/fqQAcj0yFsR lquQ== 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=xBMJUMz7et9QK91vtZB3y+XIibJd8v2fDulvJteSDSM=; b=V6jD8HEgEI64zNnMBkzZTDFSBm3atRiAVbE947Qf7YF14OQKry4OPZqiInpbzueREW tAVTub/lGzKBOjB1kgttASYoGbK2aRbNzzJdEaSj2Yc1/RNar3YNQ6JB4aeYrb+BIGVK qGNGN+5jW5rHT/rK6sdBlMLvp0l3DYoUEC8DKYDj5ImnnTxQU6PdthiaWpivk7GyipY9 ImY4c74DBIX03ggzJVMm6MWX2usnFIbBLqn9USf8iJtPweaytY8QGVUwBZYN8aMqRX7m b6R3WZ9vNJMPZN7Pei33l5CEyVyyKK9uG/Z/DxUeCb8U4u+qQMDtQB/4kOaRMxoL7mgo 7HNw== X-Gm-Message-State: ALQs6tC/u8dykYllB26isMiYk5whWHiH0oW8LIhVCM1qollMe6b99U/p geWZRPOkEW+NYe9arD1er9IOa27Q X-Google-Smtp-Source: AIpwx48DagIrMSGXCq9yoNLgYsEjH8fxOfakUQd4CmDSTnTiTSHnEx944ch7XS4faCgndDvp51PN4w== X-Received: by 10.223.169.215 with SMTP id b81mr10242136wrd.48.1523222880405; Sun, 08 Apr 2018 14:28:00 -0700 (PDT) Received: from blackbox.darklights.net (p5B056562.dip0.t-ipconnect.de. [91.5.101.98]) by smtp.googlemail.com with ESMTPSA id j21sm18476370wrb.49.2018.04.08.14.27.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Apr 2018 14:27:59 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH usb v5 3/6] usb: core: use phy_exit during suspend if wake up is not supported Date: Sun, 8 Apr 2018 23:27:40 +0200 Message-Id: <20180408212743.22934-4-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180408212743.22934-1-martin.blumenstingl@googlemail.com> References: <20180408212743.22934-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180408_142812_328689_409E5E03 X-CRM114-Status: GOOD ( 15.78 ) 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, eric@anholt.net, j-keerthy@ti.com, stern@rowland.harvard.edu, chunfeng.yun@mediatek.com, yamada.masahiro@socionext.com, linux-mediatek@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, matthias.bgg@gmail.com, linux-amlogic@lists.infradead.org, kishon@ti.com, Martin Blumenstingl , 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);