Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4680884yba; Wed, 17 Apr 2019 17:16:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsACkZTp3SFJBdRNWK8bUR6zfAvwCRJ215RGIHsfE1FFnalAXMQpoRR2t1iIIogF9FCYor X-Received: by 2002:a63:3d4c:: with SMTP id k73mr86099728pga.154.1555546571869; Wed, 17 Apr 2019 17:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555546571; cv=none; d=google.com; s=arc-20160816; b=OC8aRX9kGLU68w9RQpZEp2MHxGAa0ml89Z0UZsv7XcbuyMBim/T4WnYv2lPZv5qDw2 Fr+XGnxzteTMiL8NTXx41LolKlraB1mYNBZ4Yxqs0Acv0L33OIol6PuU5NKVzIpojpKI PWM8DjgZ8oK1ZKaKINd6/yDp3LzOHJ21ySOpcgP6V+AWCFhrHfp+4DvtSFSXoa0l3T0S wVDxHD5A2Spt7+MHTZsv6YOEI6CfDsEYr202oKh122ywhXm+YB6kJZP1B/dOQ8+ScerT MkGuGf5chPwDdHNoDqH8m1oAGQICAJOfJ8K724NYeJPMbVsjs6RmwzV7VccJ4UVX+YS5 GqBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MIQc6nb78x4dX7zZdpFCr2Ou987p1QUJbog7A/7Fv+o=; b=B8Kjug2/HXmMZ8jDs6HJIj0aZmscDzsWpB892maeXsEu+ksmmSQt7lrmau+XLGwLHW 3eiLU3fYtUL0H2fwBM5pG92g9wkTdzPC4pmixPzofWjxirZKtyhJj67p12AlNwhNdTko WiDT5YQolMqf7G5UhcWm4jIh3H4TnBQy0v4pLlpz/N0WBuBAQ/4U1Fqe4mYwa99qygqt QHHul0bDaKC7/lXvDoXchZubyGjgW1Pug5PCIkaKe8NpgcyeEtptr1SrwR1X13bYvwZR Zgnl7bpZKiRZHmROGo4lShqVzIwrhoq4K/pWcX4/5OkGfWLWhZ8HA3ygH/BflOaw0W6T SCXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mixCdUtw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si215453pgm.288.2019.04.17.17.15.56; Wed, 17 Apr 2019 17:16:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mixCdUtw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387826AbfDRAPE (ORCPT + 99 others); Wed, 17 Apr 2019 20:15:04 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34995 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387800AbfDRAPC (ORCPT ); Wed, 17 Apr 2019 20:15:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id g8so311368pgf.2 for ; Wed, 17 Apr 2019 17:15:02 -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 :mime-version:content-transfer-encoding; bh=MIQc6nb78x4dX7zZdpFCr2Ou987p1QUJbog7A/7Fv+o=; b=mixCdUtwMK+XLff4ncol1Q/8d97x7uycyS81jNA6X8UeFFCPVEiwfCbVn3fmxHXH2n WZBSKRzGfuOth7RXk3aT2rquxXh4yZsXZOePcLhgUoWHJ4g7sKlwpO34Mo86+wQ3fMkr PUbwgq85Piz5xEcnPXjzHl7xjl5SuE0gnsEnM= 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:mime-version:content-transfer-encoding; bh=MIQc6nb78x4dX7zZdpFCr2Ou987p1QUJbog7A/7Fv+o=; b=Mpoh2aQXMZfIdBo9NU5k89GDgmFAlXk50zFcndFZnNLpCWgFQoQVjdolNzBKH+ivCg Ok4HMg+kayj3baQOlH5zqyUTGXI8mzvX7SUf3wDAmpfV55B/qJr9ItFBp79e04mLsX5F VjHYfaG4IHuNAjO4MyZSxy/suc95jZdxX1uZGgCWLqlTsbsm3OPY3vdoViNDlyGFEfaA wrTKjkD2FqAbjhZMfErDM61HTHwKkttwUXFX/XYTJH6+qHBMmOcw9ek45YIItiOcE0z6 O1lK9Ctd6r0hVStxmVbY1++jfYCo/fUjCYpSUipRAYZCWdb5TwV581LsmdHTn23H+qlA hu6w== X-Gm-Message-State: APjAAAUsmm5adw3WecQCRg2PTfK+bXceZ+u4z4M8TnvASeQkWy2RuQxG 8zTOGlevc0MybJYludaZ+6kRxg== X-Received: by 2002:a63:c746:: with SMTP id v6mr84071022pgg.401.1555546501936; Wed, 17 Apr 2019 17:15:01 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q5sm447668pff.97.2019.04.17.17.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 17:15:01 -0700 (PDT) From: Douglas Anderson To: Minas Harutyunyan , Felipe Balbi , heiko@sntech.de Cc: Alan Stern , Artur Petrosyan , amstan@chromium.org, linux-rockchip@lists.infradead.org, William Wu , linux-usb@vger.kernel.org, Stefan Wahren , Randy Li , zyw@rock-chips.com, mka@chromium.org, ryandcase@chromium.org, Amelie Delaunay , jwerner@chromium.org, dinguyen@opensource.altera.com, Elaine Zhang , Douglas Anderson , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] USB: dwc2: Don't turn off the usbphy in suspend if wakeup is enabled Date: Wed, 17 Apr 2019 17:13:55 -0700 Message-Id: <20190418001356.124334-5-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190418001356.124334-1-dianders@chromium.org> References: <20190418001356.124334-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Douglas Anderson Signed-off-by: Chris Zhong --- For relevant prior discussion of this idea, see: https://lkml.kernel.org/r/1436207224-21849-4-git-send-email-dianders@chromium.org If I'm reading all the responses correctly folks were of the opinion that this patch is still the right way to go. Changes in v2: - Rebased to mainline atop rk3288 remote wake quirk series. drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 43 +++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index f30748f4fe7e..a99fe7851352 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -861,6 +861,9 @@ struct dwc2_hregs_backup { * @hibernated: True if core is hibernated * @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a * remote wakeup. + * @phy_off_for_suspend: Status of whether we turned the PHY off at suspend. + * @need_phy_for_wake: Quirk saying that we should keep the PHY on at + * suspend if we need USB to wake us up. * @frame_number: Frame number read from the core. For both device * and host modes. The value ranges are from 0 * to HFNUM_MAX_FRNUM. @@ -1049,6 +1052,8 @@ struct dwc2_hsotg { unsigned int ll_hw_enabled:1; unsigned int hibernated:1; unsigned int reset_phy_on_wake:1; + unsigned int need_phy_for_wake:1; + unsigned int phy_off_for_suspend:1; u16 frame_number; struct phy *phy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 9b65b766e0b9..6f0271c5d163 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -47,7 +47,9 @@ #include #include #include +#include +#include #include #include "core.h" @@ -450,6 +452,10 @@ static int dwc2_driver_probe(struct platform_device *dev) if (retval) goto error; + hsotg->need_phy_for_wake = + of_property_read_bool(dev->dev.of_node, + "snps,need-phy-for-wake"); + /* * Reset before dwc2_get_hwparams() then it could get power-on real * reset value form registers. @@ -481,6 +487,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); + hsotg->reset_phy_on_wake = of_property_read_bool(dev->dev.of_node, "snps,reset-phy-on-wake"); @@ -516,6 +530,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->ll_hw_enabled) + 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); @@ -524,8 +560,10 @@ static int __maybe_unused dwc2_suspend(struct device *dev) if (dwc2_is_device_mode(dwc2)) dwc2_hsotg_suspend(dwc2); - if (dwc2->ll_hw_enabled) + if (dwc2_can_poweroff_phy(dwc2)) { ret = __dwc2_lowlevel_hw_disable(dwc2); + dwc2->phy_off_for_suspend = true; + } return ret; } @@ -535,11 +573,12 @@ static int __maybe_unused dwc2_resume(struct device *dev) struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); int ret = 0; - if (dwc2->ll_hw_enabled) { + if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { ret = __dwc2_lowlevel_hw_enable(dwc2); if (ret) return ret; } + dwc2->phy_off_for_suspend = false; if (dwc2_is_device_mode(dwc2)) ret = dwc2_hsotg_resume(dwc2); -- 2.21.0.593.g511ec345e18-goog