mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] phy: stm32-usbphyc: fix unbalanced phy exit
@ 2023-11-09 12:10 Ahmad Fatoum
  2023-11-10 13:16 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2023-11-09 12:10 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

On the STM32MP1, shutting down barebox can result in a

  ERROR: phy1: phy exit failed --> -22

message printed to the console. This is because the regulator is disabled
more often than it was enabled, because stm32_usbphyc_pll_disable
is called twice:

  - Once from stm32_usbphyc_remove calling stm32_usbphyc_phy_exit
  - Once from dwc2_remove calling phy_exit -> stm32_usbphyc_phy_exit

The code is taken from Linux and likely causes no issues there, because
devices are removed in reverse probe order, which barebox doesn't
enforce. Properly solving this would be a larger endeavour, so for now
just fix the stm32-usbphyc driver to ignore reference count dropping
below zero and only call __stm32_usbphyc_pll_disable once.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/phy/phy-stm32-usbphyc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
index ac82b019f44c..91f4e7f7e08d 100644
--- a/drivers/phy/phy-stm32-usbphyc.c
+++ b/drivers/phy/phy-stm32-usbphyc.c
@@ -277,7 +277,7 @@ static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
 static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
 {
 	/* Check if a phy port is still active or clk48 in use */
-	if (atomic_dec_return(&usbphyc->n_pll_cons) > 0)
+	if (atomic_dec_return(&usbphyc->n_pll_cons) != 1)
 		return 0;
 
 	return __stm32_usbphyc_pll_disable(usbphyc);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH master] phy: stm32-usbphyc: fix unbalanced phy exit
  2023-11-09 12:10 [PATCH master] phy: stm32-usbphyc: fix unbalanced phy exit Ahmad Fatoum
@ 2023-11-10 13:16 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:16 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Nov 09, 2023 at 01:10:12PM +0100, Ahmad Fatoum wrote:
> On the STM32MP1, shutting down barebox can result in a
> 
>   ERROR: phy1: phy exit failed --> -22
> 
> message printed to the console. This is because the regulator is disabled
> more often than it was enabled, because stm32_usbphyc_pll_disable
> is called twice:
> 
>   - Once from stm32_usbphyc_remove calling stm32_usbphyc_phy_exit
>   - Once from dwc2_remove calling phy_exit -> stm32_usbphyc_phy_exit
> 
> The code is taken from Linux and likely causes no issues there, because
> devices are removed in reverse probe order, which barebox doesn't
> enforce. Properly solving this would be a larger endeavour, so for now
> just fix the stm32-usbphyc driver to ignore reference count dropping
> below zero and only call __stm32_usbphyc_pll_disable once.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/phy/phy-stm32-usbphyc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
> index ac82b019f44c..91f4e7f7e08d 100644
> --- a/drivers/phy/phy-stm32-usbphyc.c
> +++ b/drivers/phy/phy-stm32-usbphyc.c
> @@ -277,7 +277,7 @@ static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
>  static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
>  {
>  	/* Check if a phy port is still active or clk48 in use */
> -	if (atomic_dec_return(&usbphyc->n_pll_cons) > 0)
> +	if (atomic_dec_return(&usbphyc->n_pll_cons) != 1)
>  		return 0;
>  
>  	return __stm32_usbphyc_pll_disable(usbphyc);
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-10 13:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 12:10 [PATCH master] phy: stm32-usbphyc: fix unbalanced phy exit Ahmad Fatoum
2023-11-10 13:16 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox