Skip to content

Commit 66e0ea3

Browse files
kyletsoadlgregkh
authored andcommitted
usb: dwc3: core: Defer the probe until USB power supply ready
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: 6f0764b ("usb: dwc3: add a power supply for current control") Cc: stable <[email protected]> Signed-off-by: Kyle Tso <[email protected]> Acked-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 81702d4 commit 66e0ea3

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

drivers/usb/dwc3/core.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
16841684
u8 tx_thr_num_pkt_prd = 0;
16851685
u8 tx_max_burst_prd = 0;
16861686
u8 tx_fifo_resize_max_num;
1687-
const char *usb_psy_name;
1688-
int ret;
16891687

16901688
/* default to highest possible threshold */
16911689
lpm_nyet_threshold = 0xf;
@@ -1720,13 +1718,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
17201718

17211719
dwc->sys_wakeup = device_may_wakeup(dwc->sysdev);
17221720

1723-
ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
1724-
if (ret >= 0) {
1725-
dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
1726-
if (!dwc->usb_psy)
1727-
dev_err(dev, "couldn't get usb power supply\n");
1728-
}
1729-
17301721
dwc->has_lpm_erratum = device_property_read_bool(dev,
17311722
"snps,has-lpm-erratum");
17321723
device_property_read_u8(dev, "snps,lpm-nyet-threshold",
@@ -2129,6 +2120,23 @@ static int dwc3_get_num_ports(struct dwc3 *dwc)
21292120
return 0;
21302121
}
21312122

2123+
static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc)
2124+
{
2125+
struct power_supply *usb_psy;
2126+
const char *usb_psy_name;
2127+
int ret;
2128+
2129+
ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name);
2130+
if (ret < 0)
2131+
return NULL;
2132+
2133+
usb_psy = power_supply_get_by_name(usb_psy_name);
2134+
if (!usb_psy)
2135+
return ERR_PTR(-EPROBE_DEFER);
2136+
2137+
return usb_psy;
2138+
}
2139+
21322140
static int dwc3_probe(struct platform_device *pdev)
21332141
{
21342142
struct device *dev = &pdev->dev;
@@ -2185,6 +2193,10 @@ static int dwc3_probe(struct platform_device *pdev)
21852193

21862194
dwc3_get_software_properties(dwc);
21872195

2196+
dwc->usb_psy = dwc3_get_usb_power_supply(dwc);
2197+
if (IS_ERR(dwc->usb_psy))
2198+
return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n");
2199+
21882200
dwc->reset = devm_reset_control_array_get_optional_shared(dev);
21892201
if (IS_ERR(dwc->reset)) {
21902202
ret = PTR_ERR(dwc->reset);

0 commit comments

Comments
 (0)