Re: [PATCH v1] USB: dwc3: only call usb_phy_set_suspend in suspend/resume

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 03, 2023 at 11:22:36AM +0100, Francesco Dolcini wrote:
> From: Stefan Eichenberger <stefan.eichenberger@xxxxxxxxxxx>
> 
> 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@xxxxxxxxxx/

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

Johan




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux