mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] usb: dwc3: core: Defer the probe until USB power supply ready
@ 2025-01-15  4:45 Kyle Tso
  2025-01-15 23:47 ` Thinh Nguyen
  0 siblings, 1 reply; 2+ messages in thread
From: Kyle Tso @ 2025-01-15  4:45 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>
---
v1 -> v2:
- get the power supply in a dedicated function

---
 drivers/usb/dwc3/core.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7578c5133568..dfa1b5fe48dc 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1684,8 +1684,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	u8			tx_thr_num_pkt_prd = 0;
 	u8			tx_max_burst_prd = 0;
 	u8			tx_fifo_resize_max_num;
-	const char		*usb_psy_name;
-	int			ret;
 
 	/* default to highest possible threshold */
 	lpm_nyet_threshold = 0xf;
@@ -1720,13 +1718,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 
 	dwc->sys_wakeup = device_may_wakeup(dwc->sysdev);
 
-	ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
-	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");
-	}
-
 	dwc->has_lpm_erratum = device_property_read_bool(dev,
 				"snps,has-lpm-erratum");
 	device_property_read_u8(dev, "snps,lpm-nyet-threshold",
@@ -2129,6 +2120,23 @@ static int dwc3_get_num_ports(struct dwc3 *dwc)
 	return 0;
 }
 
+static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc)
+{
+	struct power_supply *usb_psy;
+	const char *usb_psy_name;
+	int ret;
+
+	ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name);
+	if (ret < 0)
+		return NULL;
+
+	usb_psy = power_supply_get_by_name(usb_psy_name);
+	if (!usb_psy)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	return usb_psy;
+}
+
 static int dwc3_probe(struct platform_device *pdev)
 {
 	struct device		*dev = &pdev->dev;
@@ -2185,6 +2193,10 @@ static int dwc3_probe(struct platform_device *pdev)
 
 	dwc3_get_software_properties(dwc);
 
+	dwc->usb_psy = dwc3_get_usb_power_supply(dwc);
+	if (IS_ERR(dwc->usb_psy))
+		return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n");
+
 	dwc->reset = devm_reset_control_array_get_optional_shared(dev);
 	if (IS_ERR(dwc->reset)) {
 		ret = PTR_ERR(dwc->reset);
-- 
2.48.0.rc2.279.g1de40edade-goog


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

* Re: [PATCH v2] usb: dwc3: core: Defer the probe until USB power supply ready
  2025-01-15  4:45 [PATCH v2] usb: dwc3: core: Defer the probe until USB power supply ready Kyle Tso
@ 2025-01-15 23:47 ` Thinh Nguyen
  0 siblings, 0 replies; 2+ messages in thread
From: Thinh Nguyen @ 2025-01-15 23:47 UTC (permalink / raw)
  To: Kyle Tso
  Cc: Thinh Nguyen, gregkh, raychi, badhri, linux-kernel, linux-usb,
	royluo, bvanassche, stable

On Wed, Jan 15, 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>
> ---
> v1 -> v2:
> - get the power supply in a dedicated function
> 
> ---
>  drivers/usb/dwc3/core.c | 30 +++++++++++++++++++++---------
>  1 file changed, 21 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 7578c5133568..dfa1b5fe48dc 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1684,8 +1684,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
>  	u8			tx_thr_num_pkt_prd = 0;
>  	u8			tx_max_burst_prd = 0;
>  	u8			tx_fifo_resize_max_num;
> -	const char		*usb_psy_name;
> -	int			ret;
>  
>  	/* default to highest possible threshold */
>  	lpm_nyet_threshold = 0xf;
> @@ -1720,13 +1718,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
>  
>  	dwc->sys_wakeup = device_may_wakeup(dwc->sysdev);
>  
> -	ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
> -	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");
> -	}
> -
>  	dwc->has_lpm_erratum = device_property_read_bool(dev,
>  				"snps,has-lpm-erratum");
>  	device_property_read_u8(dev, "snps,lpm-nyet-threshold",
> @@ -2129,6 +2120,23 @@ static int dwc3_get_num_ports(struct dwc3 *dwc)
>  	return 0;
>  }
>  
> +static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc)
> +{
> +	struct power_supply *usb_psy;
> +	const char *usb_psy_name;
> +	int ret;
> +
> +	ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name);
> +	if (ret < 0)
> +		return NULL;
> +
> +	usb_psy = power_supply_get_by_name(usb_psy_name);
> +	if (!usb_psy)
> +		return ERR_PTR(-EPROBE_DEFER);
> +
> +	return usb_psy;
> +}
> +
>  static int dwc3_probe(struct platform_device *pdev)
>  {
>  	struct device		*dev = &pdev->dev;
> @@ -2185,6 +2193,10 @@ static int dwc3_probe(struct platform_device *pdev)
>  
>  	dwc3_get_software_properties(dwc);
>  
> +	dwc->usb_psy = dwc3_get_usb_power_supply(dwc);
> +	if (IS_ERR(dwc->usb_psy))
> +		return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n");
> +
>  	dwc->reset = devm_reset_control_array_get_optional_shared(dev);
>  	if (IS_ERR(dwc->reset)) {
>  		ret = PTR_ERR(dwc->reset);
> -- 
> 2.48.0.rc2.279.g1de40edade-goog
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh

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

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

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

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

all inboxes | Powered by JetHome®