From patchwork Mon Jun 22 23:52:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 6658431 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2FBC19F46B for ; Mon, 22 Jun 2015 23:53:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3438920412 for ; Mon, 22 Jun 2015 23:53:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B277820430 for ; Mon, 22 Jun 2015 23:53:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z7BWk-0002z3-9m; Mon, 22 Jun 2015 23:53:22 +0000 Received: from mail-ie0-x22f.google.com ([2607:f8b0:4001:c03::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z7BWi-0002rS-JD for linux-rockchip@lists.infradead.org; Mon, 22 Jun 2015 23:53:21 +0000 Received: by iecvh10 with SMTP id vh10so792753iec.3 for ; Mon, 22 Jun 2015 16:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6GFE/Ex2ZSAt2KtJrkVkgnFaIEL1GK4sG5fvtsyndjM=; b=Ke2b5gfEaz6fwq/HagfKmygENZWqG+A2ChsTEyOOfDJ+LMmD2fwIwB5FVkoybcYaQm cIe3SqHSlcFaJYVa3hf/d1oT5ilMEI2WOwR3ao0mUlSBjw0Ljq7C+r8CuNnFx3BrWYRB 0brNzYMDPr3sraCVSkgtw7es30F1cgedl/LbU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6GFE/Ex2ZSAt2KtJrkVkgnFaIEL1GK4sG5fvtsyndjM=; b=FttvVKITc/w3hdB1egHUQgy7+5tr6rLJjVkmg/tF7jAqsb9Z+ENqD03kD402PPYf5m kqcqVee+EwHN2QtbBq5uxJ1/93wIuOtT6zj2jxl4hveme3EEXCf/2mFTAymgHj4iax8a 4nJRUBGIbZ6qDDTw9QPS5o/PO3XfMnROqwx+HiHhO3VxWYUzit3jcbpeHbtV7daaXSgK diDH/3k/llL+L4MKR1C5aJzg/NEGPpUzWhgZNpmvgYOXN4Ka3jPVJo4qQACDlwOTgy0j pfcEhc5lL1petk9OVgm/EMsbxZL0VmC4jEkR9DpEg/ZXQAMVxXa3/hlbbMurzeLkqle0 tOMg== X-Gm-Message-State: ALoCoQkRtPB0MOy+kXSUDg/FoltKjw2d5O3eVeW5B+QXCFpLv5yAgOwx8/3DkAY6cx9nKi26W5ER X-Received: by 10.107.15.153 with SMTP id 25mr41666184iop.44.1435017178473; Mon, 22 Jun 2015 16:52:58 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by mx.google.com with ESMTPSA id pg5sm8600390igb.4.2015.06.22.16.52.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Jun 2015 16:52:58 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , John Youn , Felipe Balbi Subject: [PATCH 3/3] USB: dwc2: Don't turn off the usbphy in suspend if wakeup is enabled Date: Mon, 22 Jun 2015 16:52:24 -0700 Message-Id: <1435017144-2971-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.4.3.573.g4eafbef In-Reply-To: <1435017144-2971-1-git-send-email-dianders@chromium.org> References: <1435017144-2971-1-git-send-email-dianders@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150622_165320_726399_207A3AB4 X-CRM114-Status: GOOD ( 19.13 ) X-Spam-Score: -1.0 (-) Cc: Heiko Stuebner , Andrew Bresticker , linux-usb@vger.kernel.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, lyz@rock-chips.com, Chris Zhong , Julius Werner , Alexandru Stan X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY, URIBL_BLACK autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the 'snps,need-phy-for-wake' is set in the device tree then: - We know that we can wakeup, so call device_set_wakeup_capable(). The USB core will use this knowledge to enable wakeup by default. - We know that we should keep the PHY on during suspend if something on our root hub needs remote wakeup. This requires the patch (USB: Export usb_wakeup_enabled_descendants()). Note that we don't keep the PHY on at suspend time if it's not needed because it would be a power draw. If we later find some users of dwc2 that can support wakeup without keeping the PHY on we may want to add a way to call device_set_wakeup_capable() without keeping the PHY on at suspend time. Signed-off-by: Chris Zhong Signed-off-by: Douglas Anderson --- drivers/usb/dwc2/core.h | 2 ++ drivers/usb/dwc2/platform.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 53b8de0..b60a1e8 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -687,6 +687,8 @@ struct dwc2_hsotg { enum usb_dr_mode dr_mode; unsigned int hcd_enabled:1; unsigned int gadget_enabled:1; + unsigned int need_phy_for_wake:1; + unsigned int phy_off_for_suspend:1; struct phy *phy; struct usb_phy *uphy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 9093530..38fce75 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -42,7 +42,9 @@ #include #include #include +#include +#include #include #include "core.h" @@ -222,6 +224,10 @@ static int dwc2_driver_probe(struct platform_device *dev) hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node); + hsotg->need_phy_for_wake = + of_property_read_bool(dev->dev.of_node, + "snps,need-phy-for-wake"); + /* * Attempt to find a generic PHY, then look for an old style * USB PHY @@ -265,6 +271,14 @@ static int dwc2_driver_probe(struct platform_device *dev) hsotg->gadget_enabled = 1; } + /* + * If we need PHY for wakeup we must be wakeup capable. + * When we have a device that can wake without the PHY we + * can adjust this condition. + */ + if (hsotg->need_phy_for_wake) + device_set_wakeup_capable(&dev->dev, true); + if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { retval = dwc2_hcd_init(hsotg, irq); if (retval) { @@ -282,6 +296,28 @@ static int dwc2_driver_probe(struct platform_device *dev) return retval; } +static bool __maybe_unused dwc2_can_poweroff_phy(struct dwc2_hsotg *dwc2) +{ + struct usb_device *root_hub = dwc2_hsotg_to_hcd(dwc2)->self.root_hub; + + if (dwc2->lx_state == DWC2_L0) + return false; + + /* If the controller isn't allowed to wakeup then we can power off. */ + if (!device_may_wakeup(dwc2->dev)) + return true; + + /* + * We don't want to power off the PHY if something under the + * root hub has wakeup enabled. + */ + if (usb_wakeup_enabled_descendants(root_hub)) + return false; + + /* No reason to keep the PHY powered, so allow poweroff */ + return true; +} + static int __maybe_unused dwc2_suspend(struct device *dev) { struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); @@ -290,8 +326,10 @@ static int __maybe_unused dwc2_suspend(struct device *dev) if (dwc2_is_device_mode(dwc2)) { ret = s3c_hsotg_suspend(dwc2); } else { - if (dwc2->lx_state == DWC2_L0) + if (!dwc2_can_poweroff_phy(dwc2)) return 0; + + dwc2->phy_off_for_suspend = true; phy_exit(dwc2->phy); phy_power_off(dwc2->phy); @@ -307,9 +345,12 @@ static int __maybe_unused dwc2_resume(struct device *dev) if (dwc2_is_device_mode(dwc2)) { ret = s3c_hsotg_resume(dwc2); } else { + if (!dwc2->phy_off_for_suspend) + return ret; + phy_power_on(dwc2->phy); phy_init(dwc2->phy); - + dwc2->phy_off_for_suspend = false; } return ret; }