Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3340380pxb; Mon, 1 Nov 2021 12:03:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1arDcCDYaR+grkV3SpWDsZP9sbOEscTbtB/RxeIYkb2EDT7XvdH0zhi0cXBud60Rxypvg X-Received: by 2002:a50:9d49:: with SMTP id j9mr42598942edk.39.1635793395811; Mon, 01 Nov 2021 12:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635793395; cv=none; d=google.com; s=arc-20160816; b=pEQAJmy7lpRBFyN/G9NZ+iKVdBt1MNSwQdZoCY+Yb7IspOm0PI292eYuBS5vrdPNiO I+eif+nuNNyR73IKJUsB+XjeoXwd5ZRrVsUnaKZeIG3S83mvx9dAhWAVmbqZll40rfXl Lna8vMTpEfRL1vXCETQHKnicxk9etLPvU2yrRk5KKaN4ggJwhWQgNdVxF1sNtRxrRaTC bM6vNSCOcSIjmwcVBfBJqoH7ptorsjlUPcJwaIVSQXUNtXUMpE4KDI3TnGo2fbs1a7T3 2grNM+z5QWjSxWjzLAbVJ3oE7c5UN/JTtgyQvb+0YtYxsutE3Z1kLTJW5nRR1PlldQU5 8GnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BD1QsMY1zCUqv9br05N6l/EKmY3X2SxhgDpOAJhSwOg=; b=kz8SVcLMr4Wi2uRq0AnTCJOooSdmjzoOzBG1kKIp9qjZWQn8eIOHRxlwRDRfK5Klqa MsjZt/E4LLYySRFSEHDb3S4sRdqKvLzwaItdSQdLmVcPQ732+8Cz7NuELlDrhgIw8RFn UA8Aftq1lQO25geFLxcGLW3S/SO2o+Lq5DpI5ODlJXFUeuPTUpyVR2y22cxNvTGQV4Wc D4wbdhtO9yKuY7zVWollv76v7chMtGehWD0fb84ubVqQXgIIa9Mj2KjF502Px4iTVKc/ t+sa1+qQtIqcizxxInb7lDNF/21cqSi9rE13N7YZVdg/21o4Mzfrg6HX8X6CZX8zMcIK qSzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QPo0fLjV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id y14si9636556edt.48.2021.11.01.12.02.45; Mon, 01 Nov 2021 12:03:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QPo0fLjV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232527AbhKATCv (ORCPT + 99 others); Mon, 1 Nov 2021 15:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232525AbhKATCe (ORCPT ); Mon, 1 Nov 2021 15:02:34 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 875C6C079785 for ; Mon, 1 Nov 2021 11:59:12 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id r28so18074549pga.0 for ; Mon, 01 Nov 2021 11:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BD1QsMY1zCUqv9br05N6l/EKmY3X2SxhgDpOAJhSwOg=; b=QPo0fLjV+jATSuaG4z7d8hBSW8RLlY0fKLsiIJmeEcwNnIaOhVSkbc6tymWO6B/t4l I33lEIk9z8XOsPVpQdeoep+FjLeTrkYLFoi/7QriEnA8KqIgMmyfh8eCzmNLqzKEvbkM tEb3FcUyt31GKnlkmRM561dj75yfy5Mu1S7P4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BD1QsMY1zCUqv9br05N6l/EKmY3X2SxhgDpOAJhSwOg=; b=r5HspoUAC0TwkCHCuEHkkZuntaj/+h/VAsJbDaL+oyE2WmBmX15BjlgbXB9wQy8wyh 4c0Hi3N/AJ7nlKUoiif2D88LiRZaD6FRsIPHcpQu4aBxp5b1B9btS4dtPFafvMnRxZe9 ImxFuNccrqwymNZZLmGGGbgClbf3JMof8UPjiOqPJ83IYkWCK0pvoXxfVFu67MT0yqkk Az2e4If0VXgzbyLrFX65xDZNeys3w6yC3wUi9wusjn5NMzJIhbPPrCuPSG7YzZgcsB06 5CKRAz+FPZ0fe/tR+Xx+rt4sXwciwb+xPzMsbaGcdeTbRKYexITPTi6Crdk89Bq193yU XdvQ== X-Gm-Message-State: AOAM530PIOOli15QYFLzdsCWFJq0I4bVgOO8UnwzWtIY5b4wAzMo1Sd4 t9uzCzwyFLMfrV5cAePED5eDag== X-Received: by 2002:a63:af07:: with SMTP id w7mr23594572pge.202.1635793152067; Mon, 01 Nov 2021 11:59:12 -0700 (PDT) Received: from localhost ([2620:15c:202:201:6278:520b:a2e1:4ece]) by smtp.gmail.com with UTF8SMTPSA id ml24sm191160pjb.16.2021.11.01.11.59.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Nov 2021 11:59:11 -0700 (PDT) Date: Mon, 1 Nov 2021 11:59:10 -0700 From: Matthias Kaehlcke To: Sandeep Maheswaram Cc: Andy Gross , Bjorn Andersson , Greg Kroah-Hartman , Felipe Balbi , Stephen Boyd , Doug Anderson , Mathias Nyman , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, quic_pkondeti@quicinc.com, quic_ppratap@quicinc.com Subject: Re: [PATCH v9 1/5] usb: host: xhci: plat: Add suspend quirk for dwc3 controller Message-ID: References: <1635753224-23975-1-git-send-email-quic_c_sanm@quicinc.com> <1635753224-23975-2-git-send-email-quic_c_sanm@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1635753224-23975-2-git-send-email-quic_c_sanm@quicinc.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sandeep, On Mon, Nov 01, 2021 at 01:23:40PM +0530, Sandeep Maheswaram wrote: > During suspend check if any wakeup capable devices are connected to the > controller (directly or through hubs), and set the wakeup capable property > for xhci plat device. > > Signed-off-by: Sandeep Maheswaram > --- > drivers/usb/host/xhci-plat.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c > index c1edcc9..7ab272b 100644 > --- a/drivers/usb/host/xhci-plat.c > +++ b/drivers/usb/host/xhci-plat.c > @@ -431,6 +431,14 @@ static int xhci_plat_remove(struct platform_device *dev) > return 0; > } > > +static void xhci_dwc3_suspend_quirk(struct usb_hcd *hcd, struct device *dev) > +{ > + if (usb_wakeup_enabled_descendants(hcd->self.root_hub)) > + device_set_wakeup_capable(dev, true); > + else > + device_set_wakeup_capable(dev, false); IIUC wakeup capability is typically a static property that reflects the actual hardware (or firmware) support for wakeup. In that sense it doesn't seem a good idea to change it dynamically at suspend time, depending on what is connected to the bus. I understand though that the odd split of the dwc3 driver makes it hard to do things properly ... Earlier in this discussion Felipe suggested to add a function like device_children_wakeup_capable(), to avoid having to call usb_wakeup_enabled_descendants() from the dwc3 drivers. Below is an initial implementation for device_children_wakeup_capable(), could you try if calling it from dwc3_suspend/resume_common() and dwc3_qcom_suspend() would work instead of relying on the wakeup capability? Thanks Matthias From 97c838334045ed67c3943f8e035ac70acd12b89b Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Mon, 1 Nov 2021 11:37:19 -0700 Subject: [PATCH] PM / wakeup: Add device_children_wakeup_capable() Add device_children_wakeup_capable() which checks whether the device itself or one if its descendants is wakeup capable. Change-Id: Ib359eb5ac8650ddf9889c7d1f77707f50777fe99 Suggested-by: Felipe Balbi Signed-off-by: Matthias Kaehlcke --- drivers/base/power/wakeup.c | 17 +++++++++++++++++ include/linux/pm_wakeup.h | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index 9c0932603642..2aee7fa8230f 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -483,6 +483,23 @@ int device_set_wakeup_enable(struct device *dev, bool enable) } EXPORT_SYMBOL_GPL(device_set_wakeup_enable); +static int __device_children_wakeup_capable(struct device *dev, void *dummy) +{ + return device_may_wakeup(dev) || + device_for_each_child(dev, NULL, __device_children_wakeup_capable); +} + +/** + * device_children_wakeup_capable - Check whether a device or one of its descendants is + * wakeup capable. + * @dev: Device to handle. + */ +bool device_children_wakeup_capable(struct device *dev) +{ + return __device_children_wakeup_capable(dev, NULL); +} +EXPORT_SYMBOL_GPL(device_children_wakeup_capable); + /** * wakeup_source_not_registered - validate the given wakeup source. * @ws: Wakeup source to be validated. diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h index 661efa029c96..a0ca42aac6d6 100644 --- a/include/linux/pm_wakeup.h +++ b/include/linux/pm_wakeup.h @@ -97,6 +97,7 @@ extern int device_wakeup_disable(struct device *dev); extern void device_set_wakeup_capable(struct device *dev, bool capable); extern int device_init_wakeup(struct device *dev, bool val); extern int device_set_wakeup_enable(struct device *dev, bool enable); +extern bool device_children_wakeup_capable(struct device *dev); extern void __pm_stay_awake(struct wakeup_source *ws); extern void pm_stay_awake(struct device *dev); extern void __pm_relax(struct wakeup_source *ws); @@ -167,6 +168,11 @@ static inline bool device_may_wakeup(struct device *dev) static inline void device_set_wakeup_path(struct device *dev) {} +static inline bool device_children_wakeup_capable(struct device *dev) +{ + return false; +} + static inline void __pm_stay_awake(struct wakeup_source *ws) {} static inline void pm_stay_awake(struct device *dev) {}