From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 824F8C433E1 for ; Tue, 21 Jul 2020 21:36:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C9222068F for ; Tue, 21 Jul 2020 21:36:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YOUL4cnK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731223AbgGUVgH (ORCPT ); Tue, 21 Jul 2020 17:36:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731046AbgGUVgH (ORCPT ); Tue, 21 Jul 2020 17:36:07 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2029CC061794 for ; Tue, 21 Jul 2020 14:36:07 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id d7so2050080plq.13 for ; Tue, 21 Jul 2020 14:36:07 -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=QnFBaTSg1O0oHUaCso2bk1qAOV9FQ15i24q2Wj9c11M=; b=YOUL4cnKo2x3TaJ+BAr/95ETT6x9gObK2WQYwFGJgK/9RUBdjb9MfbaMiHffHRHyKC LGPxmxmDr3JtJgytD9mZPSCsbbH8QO2j0gNH8SXz+CGy6SykntBW6W3e46GhrYKLD/as 8vk+cPDlyjlX5x6BntZR1v6ykrBCcA+fBZIkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QnFBaTSg1O0oHUaCso2bk1qAOV9FQ15i24q2Wj9c11M=; b=aUMu0lEsYDfExqv9hN9Dxg8q56E5tpVB2cDL1kbmILUazN/FLZUBFEQrlIFinJRvJ/ ZpvqU6Xskia1MJVpZM+e0+Ay8p0lrzsQdzvtvT+BuUuN/kTHjtuOCAftTvi6TE/9FYuZ NcoohsyggB1+QJsOSxsb8pJrB3xD6YVSzNMR+HKL7nR8GleXAD6n9Fx4cGS+Xbcf5IIL grjJpDq72IRjMvV2qBXiFk57/jFMDMFerzr+BsjfYgZgIYymUdjjssz4RStc/r5OUwy4 kDuf73jnil5GnSimDVFJypuwulGvaKqeUOTl80+074BRjulERg3QBxCVaKXZdCxpLEDi DHVQ== X-Gm-Message-State: AOAM5328WHqRJDnpNOrcd2IHPdx999T8uBA3pl8KTszDsnZWilSoc8qB Aejvg6vA9hU3V5zAwSYm2i6tGA== X-Google-Smtp-Source: ABdhPJwTp73CGx2NZOG1F3slWn6h4XRPSmBMoPPr4bTFkCrHZLbZxCeKsBovc096clKCXXQIzGNjEA== X-Received: by 2002:a17:902:7c8b:: with SMTP id y11mr10339693pll.142.1595367366620; Tue, 21 Jul 2020 14:36:06 -0700 (PDT) Received: from localhost ([2620:15c:202:1:f693:9fff:fef4:e70a]) by smtp.gmail.com with ESMTPSA id b4sm21711441pfo.137.2020.07.21.14.36.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jul 2020 14:36:05 -0700 (PDT) Date: Tue, 21 Jul 2020 14:36:04 -0700 From: Matthias Kaehlcke To: Sandeep Maheswaram Cc: Andy Gross , Bjorn Andersson , Greg Kroah-Hartman , Rob Herring , Mark Rutland , Felipe Balbi , Stephen Boyd , Doug Anderson , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Manu Gautam Subject: Re: [PATCH v2 1/3] usb: dwc3: core: Host wake up support from system suspend Message-ID: <20200721213604.GW3191083@google.com> References: <1594235417-23066-1-git-send-email-sanm@codeaurora.org> <1594235417-23066-2-git-send-email-sanm@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1594235417-23066-2-git-send-email-sanm@codeaurora.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hi Sandeep, On Thu, Jul 09, 2020 at 12:40:15AM +0530, Sandeep Maheswaram wrote: > Avoiding phy powerdown in host mode so that it can be wake up by devices. > Added need_phy_for_wakeup flag to distinugush resume path and hs_phy_flags > to check connection status and set phy mode and configure interrupts. > > Signed-off-by: Sandeep Maheswaram > --- > drivers/usb/dwc3/core.c | 47 ++++++++++++++++++++++++++++++++++++++++------- > drivers/usb/dwc3/core.h | 2 ++ > 2 files changed, 42 insertions(+), 7 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index 25c686a7..eb7c225 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -31,12 +31,14 @@ > #include > #include > #include > +#include > > #include "core.h" > #include "gadget.h" > #include "io.h" > > #include "debug.h" > +#include "../host/xhci.h" > > #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ > > @@ -1627,10 +1629,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc) > return ret; > } > > +static void dwc3_set_phy_speed_flags(struct dwc3 *dwc) > +{ > + > + int i, num_ports; > + u32 reg; > + struct usb_hcd *hcd = platform_get_drvdata(dwc->xhci); > + struct xhci_hcd *xhci_hcd = hcd_to_xhci(hcd); > + > + dwc->hs_phy_flags &= ~(PHY_MODE_USB_HOST_HS | PHY_MODE_USB_HOST_LS); Where is hs_phy_flags initialized? As far as I can tell it isn't, hence when dwc3_set_phy_speed_flags() is executed the first time it is 0 (from devm_kzalloc()), and after the '&=' it is still 0. The next time it will have whatever value it was set to in the below loop, which is then cleared by the '&='. It seems you could as well just write 'dwc->hs_phy_flags = 0', which is clearer, unless the field is used in some other way that isn't obvious to me. > + > + reg = readl(&xhci_hcd->cap_regs->hcs_params1); > + > + num_ports = HCS_MAX_PORTS(reg); > + for (i = 0; i < num_ports; i++) { > + reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04); > + if (reg & PORT_PE) { > + if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg)) > + dwc->hs_phy_flags |= PHY_MODE_USB_HOST_HS; > + else if (DEV_LOWSPEED(reg)) > + dwc->hs_phy_flags |= PHY_MODE_USB_HOST_LS; Is another entry for DEV_SUPERSPEED needed? > + } > + } > + phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_flags); > +} > + > static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) > { > unsigned long flags; > u32 reg; > + struct usb_hcd *hcd = platform_get_drvdata(dwc->xhci); > > switch (dwc->current_dr_role) { > case DWC3_GCTL_PRTCAP_DEVICE: > @@ -1643,9 +1671,12 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) > dwc3_core_exit(dwc); > break; > case DWC3_GCTL_PRTCAP_HOST: > + dwc3_set_phy_speed_flags(dwc); > if (!PMSG_IS_AUTO(msg)) { > - dwc3_core_exit(dwc); > - break; > + if (usb_wakeup_enabled_descendants(hcd->self.root_hub)) > + dwc->need_phy_for_wakeup = true; > + else > + dwc->need_phy_for_wakeup = false; > } > > /* Let controller to suspend HSPHY before PHY driver suspends */ > @@ -1705,11 +1736,13 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) > break; > case DWC3_GCTL_PRTCAP_HOST: > if (!PMSG_IS_AUTO(msg)) { > - ret = dwc3_core_init_for_resume(dwc); > - if (ret) > - return ret; > - dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); > - break; > + if (!dwc->need_phy_for_wakeup) { > + ret = dwc3_core_init_for_resume(dwc); Before this patch we had the combo dwc3_core_exit() / dwc3_core_init_for_resume(), now it is only dwc3_core_init_for_resume() for !dwc->need_phy_for_wakeup. Doesn't this cause trouble with enable counts, e.g. with clk_bulk_prepare_enable() being called in dwc3_core_init_for_resume(), without the corresponding clk_bulk_disable_unprepare() calls in dwc3_core_exit()?