]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: dwc3: core: Defer the probe until USB power supply ready
authorKyle Tso <kyletso@google.com>
Wed, 15 Jan 2025 04:45:48 +0000 (12:45 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:50:15 +0000 (12:50 +0100)
commit 66e0ea341a2a78d14336117f19763bd9be26d45d upstream.

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 <stable@kernel.org>
Signed-off-by: Kyle Tso <kyletso@google.com>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20250115044548.2701138-1-kyletso@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.c

index f507f055f523c1d786ff6a3f6a019ead538cb83e..485d6804393d9d5107ed52eb99dfcd48509e6290 100644 (file)
@@ -1314,8 +1314,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;
@@ -1348,13 +1346,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
        else
                dwc->sysdev = dwc->dev;
 
-       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",
@@ -1564,6 +1555,23 @@ static void dwc3_check_params(struct dwc3 *dwc)
        }
 }
 
+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;
@@ -1608,6 +1616,10 @@ static int dwc3_probe(struct platform_device *pdev)
 
        dwc3_get_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))
                return PTR_ERR(dwc->reset);