public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Francesco Dolcini <francesco@dolcini.it>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@ti.com>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	Stefan Eichenberger <stefan.eichenberger@toradex.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Francesco Dolcini <francesco.dolcini@toradex.com>
Subject: Re: [PATCH v1] USB: dwc3: only call usb_phy_set_suspend in suspend/resume
Date: Fri, 3 Nov 2023 17:49:45 +0100	[thread overview]
Message-ID: <ZUUkqeKFZmsubxu5@hovoldconsulting.com> (raw)
In-Reply-To: <20231103102236.13656-1-francesco@dolcini.it>

On Fri, Nov 03, 2023 at 11:22:36AM +0100, Francesco Dolcini wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> 
> Currently we have the following two call chains:
> dwc3_probe -> dwc3_core_init -> dwc3_phy_init -> usb_phy_init
> dwc3_probe -> dwc3_core_init -> dwc3_phy_power_on -> usb_phy_set_suspend
> 
> If we look at phy-generic we see the following calls:
> usb_gen_phy_init -> regulator_enable
> usb_gen_phy_init -> clk_prepare_enable
> 
> If we call usb_phy_set_suspend we call the following in phy-generic:
> nop_set_suspend -> clk_prepare_enable
> and we sent a patch to also call:
> nop_set_suspend -> regulator_enable
> 
> Because clk_prepare_enable and regulator_enable do reference counting we
> increased the reference counter of the clock and regulator to two. If we
> want to put the system into suspend we only decrease the reference
> counters by one and therefore the clock and regulator stay on.

No, this does not seem to be a correct description of the current
implementation.

The driver always calls both usb_phy_set_suspend() and
usb_phy_init()/usb_phy_shutdown() so those usage counters would still be
balanced (e.g. see dwc3_core_init() and dwc3_core_exit()).

> This change fixes it by not calling usb_phy_set_suspend in
> dwc3_phy_power_on but only in dwc3_suspend_common.
 
>  static int dwc3_clk_enable(struct dwc3 *dwc)
> @@ -2018,6 +2009,9 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>  		break;
>  	}
>  
> +	usb_phy_set_suspend(dwc->usb2_phy, 1);
> +	usb_phy_set_suspend(dwc->usb3_phy, 1);

This is also broken as you're now calling usb_phy_set_suspend() in paths
that do not expect it as well as after usb_phy_shutdown() in case
dwc3_core_exit() was called above.

The suspend implementation in this driver is indeed messy and probably
not tested much. It seems the expectation for the legacy PHY
implementation is to only call init()/shutdown() at probe/remove and
then use set_suspend() to handle the suspend state. The dwc3 driver is
for some reason calling both set_suspend() and shutdown() which should
not be needed. Care needs to be taken so that no one has started relying
on this behaviour if you want to change this.

When reviewing the driver I did find a bug in the xhci-plat driver which
is likely the cause for the imbalance you're seeing. I just sent a fix
here in case you want to give it a try:

	https://lore.kernel.org/lkml/20231103164323.14294-1-johan+linaro@kernel.org/

But, also, why are you using legacy PHYs? Which platform is this for?

Johan

  parent reply	other threads:[~2023-11-03 16:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 10:22 [PATCH v1] USB: dwc3: only call usb_phy_set_suspend in suspend/resume Francesco Dolcini
2023-11-03 11:05 ` Greg Kroah-Hartman
2023-11-03 16:49 ` Johan Hovold [this message]
2023-11-04 11:51   ` Stefan Eichenberger
2023-11-06  8:20     ` Johan Hovold
2023-11-07  9:42       ` Stefan Eichenberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZUUkqeKFZmsubxu5@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=balbi@ti.com \
    --cc=francesco.dolcini@toradex.com \
    --cc=francesco@dolcini.it \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stefan.eichenberger@toradex.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox