The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v1] usb: dwc3: core: Defer the probe until USB power supply ready
@ 2025-01-14 14:16 Kyle Tso
  2025-01-15  1:23 ` Thinh Nguyen
  0 siblings, 1 reply; 2+ messages in thread
From: Kyle Tso @ 2025-01-14 14:16 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, raychi
  Cc: badhri, linux-kernel, linux-usb, royluo, bvanassche, Kyle Tso,
	stable

Currently, DWC3 driver attempts to acquire the USB power supply only
once during the probe. If the USB power supply is not ready at that
time, the driver simply ignores the failure and continues the probe,
leading to permanent non-functioning of the gadget vbus_draw callback.

Address this problem by delaying the dwc3 driver initialization until
the USB power supply is registered.

Fixes: 6f0764b5adea ("usb: dwc3: add a power supply for current control")
Cc: stable@vger.kernel.org
Signed-off-by: Kyle Tso <kyletso@google.com>
---
Note: This is a follow-up of https://lore.kernel.org/all/20240804084612.2561230-1-kyletso@google.com/
---
 drivers/usb/dwc3/core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7578c5133568..1550c39e792a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1669,7 +1669,7 @@ static void dwc3_get_software_properties(struct dwc3 *dwc)
 	}
 }
 
-static void dwc3_get_properties(struct dwc3 *dwc)
+static int dwc3_get_properties(struct dwc3 *dwc)
 {
 	struct device		*dev = dwc->dev;
 	u8			lpm_nyet_threshold;
@@ -1724,7 +1724,7 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	if (ret >= 0) {
 		dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
 		if (!dwc->usb_psy)
-			dev_err(dev, "couldn't get usb power supply\n");
+			return dev_err_probe(dev, -EPROBE_DEFER, "couldn't get usb power supply\n");
 	}
 
 	dwc->has_lpm_erratum = device_property_read_bool(dev,
@@ -1847,6 +1847,8 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	dwc->imod_interval = 0;
 
 	dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
+
+	return 0;
 }
 
 /* check whether the core supports IMOD */
@@ -2181,7 +2183,9 @@ static int dwc3_probe(struct platform_device *pdev)
 	dwc->regs	= regs;
 	dwc->regs_size	= resource_size(&dwc_res);
 
-	dwc3_get_properties(dwc);
+	ret = dwc3_get_properties(dwc);
+	if (ret)
+		return ret;
 
 	dwc3_get_software_properties(dwc);
 
-- 
2.47.1.688.g23fc6f90ad-goog


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

* Re: [PATCH v1] usb: dwc3: core: Defer the probe until USB power supply ready
  2025-01-14 14:16 [PATCH v1] usb: dwc3: core: Defer the probe until USB power supply ready Kyle Tso
@ 2025-01-15  1:23 ` Thinh Nguyen
  0 siblings, 0 replies; 2+ messages in thread
From: Thinh Nguyen @ 2025-01-15  1:23 UTC (permalink / raw)
  To: Kyle Tso
  Cc: Thinh Nguyen, gregkh@linuxfoundation.org, raychi@google.com,
	badhri@google.com, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org, royluo@google.com, bvanassche@acm.org,
	stable@vger.kernel.org

On Tue, Jan 14, 2025, Kyle Tso wrote:
> Currently, DWC3 driver attempts to acquire the USB power supply only
> once during the probe. If the USB power supply is not ready at that
> time, the driver simply ignores the failure and continues the probe,
> leading to permanent non-functioning of the gadget vbus_draw callback.
> 
> Address this problem by delaying the dwc3 driver initialization until
> the USB power supply is registered.
> 
> Fixes: 6f0764b5adea ("usb: dwc3: add a power supply for current control")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Tso <kyletso@google.com>
> ---
> Note: This is a follow-up of https://urldefense.com/v3/__https://lore.kernel.org/all/20240804084612.2561230-1-kyletso@google.com/__;!!A4F2R9G_pg!ZTwcKSid-i7kN4_N622H1QDeC3jzi0uCKRqjzrTNStFGr8guMe3xY0EF30CnGGPyBK25ZCGgUc_Wg3koxwqa$ 
> ---
>  drivers/usb/dwc3/core.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 7578c5133568..1550c39e792a 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1669,7 +1669,7 @@ static void dwc3_get_software_properties(struct dwc3 *dwc)
>  	}
>  }
>  
> -static void dwc3_get_properties(struct dwc3 *dwc)
> +static int dwc3_get_properties(struct dwc3 *dwc)

It doesn't make sense for dwc3_get_properties() to return -EPROBE_DEFER.

>  {
>  	struct device		*dev = dwc->dev;
>  	u8			lpm_nyet_threshold;
> @@ -1724,7 +1724,7 @@ static void dwc3_get_properties(struct dwc3 *dwc)
>  	if (ret >= 0) {
>  		dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
>  		if (!dwc->usb_psy)
> -			dev_err(dev, "couldn't get usb power supply\n");
> +			return dev_err_probe(dev, -EPROBE_DEFER, "couldn't get usb power supply\n");
>  	}

Move this logic (including power_supply_get_by_name()) outside of
dwc3_get_properties(). It doesn't belong here.

Thanks,
Thinh

>  
>  	dwc->has_lpm_erratum = device_property_read_bool(dev,
> @@ -1847,6 +1847,8 @@ static void dwc3_get_properties(struct dwc3 *dwc)
>  	dwc->imod_interval = 0;
>  
>  	dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
> +
> +	return 0;
>  }
>  
>  /* check whether the core supports IMOD */
> @@ -2181,7 +2183,9 @@ static int dwc3_probe(struct platform_device *pdev)
>  	dwc->regs	= regs;
>  	dwc->regs_size	= resource_size(&dwc_res);
>  
> -	dwc3_get_properties(dwc);
> +	ret = dwc3_get_properties(dwc);
> +	if (ret)
> +		return ret;
>  
>  	dwc3_get_software_properties(dwc);
>  
> -- 
> 2.47.1.688.g23fc6f90ad-goog
> 

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

end of thread, other threads:[~2025-01-15  1:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-14 14:16 [PATCH v1] usb: dwc3: core: Defer the probe until USB power supply ready Kyle Tso
2025-01-15  1:23 ` Thinh Nguyen

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