Re: [PATCH v3] usb: dwc3: avoid probe deferral when USB power supply is not available

From: Thinh Nguyen

Date: Fri Jun 05 2026 - 21:16:10 EST


On Fri, Jun 05, 2026, Elson Serrao wrote:
> The dwc3 driver currently defers probe if the USB power supply is not yet
> registered. On some platforms, even though charging and power supply
> functionality is available during normal operation, there may exist
> minimal booting modes (such as recovery or diagnostic environments) where
> the relevant USB power supply device is not registered. In such cases,
> probe deferral prevents USB gadget operation entirely.
>
> USB data functionality for basic operation does not inherently depend on
> the power supply framework, which is only required for enforcing VBUS
> current control. The configured VBUS current limit is typically enforced
> through the charger or PMIC power path. When charging functionality is
> unavailable, applying a current limit has no practical effect, reducing
> the benefit of strict probe-time enforcement in these environments.
>
> Instead of deferring probe, register a power supply notifier when the
> USB power supply is not yet available. Cache the requested VBUS current
> limit and apply it once the matching power supply becomes available, as
> notified through the registered callback.
>
> Signed-off-by: Elson Serrao <elson.serrao@xxxxxxxxxxxxxxxx>
> ---
> Changes in v3:
> - Introduced DWC3_CURRENT_UNSPECIFIED macro to replace UINT_MAX for
> improved code readability.
> - Enhanced dwc3_gadget_vbus_draw() to return success when power supply
> is expected but not ready yet, and only return -EOPNOTSUPP when truly
> not supported.
> - Link to v2: https://urldefense.com/v3/__https://lore.kernel.org/all/20260526183016.3501307-1-elson.serrao@xxxxxxxxxxxxxxxx/__;!!A4F2R9G_pg!egKWg179wv3MYHggzavFR-zdG3Gq6GJjN6GBi2AglShH2RXQxXHLGjTHEt0gzdZjdg_cIyWWawXOKJlhFaJKUFkM6EGLbF1z$
>
> Changes in v2:
> - Removed notifier unregistration from the vbus_draw work function to
> avoid a race with remove callback.
> - Added an early psy registration check in the notifier callback.
> - Moved power supply registration check after notifier registration
> in dwc3_get_usb_power_supply() to address the race identified in v1.
> - Link to v1: https://urldefense.com/v3/__https://lore.kernel.org/all/20260407232410.4101455-1-elson.serrao@xxxxxxxxxxxxxxxx/__;!!A4F2R9G_pg!egKWg179wv3MYHggzavFR-zdG3Gq6GJjN6GBi2AglShH2RXQxXHLGjTHEt0gzdZjdg_cIyWWawXOKJlhFaJKUFkM6JWOc-1o$
> ---
> drivers/usb/dwc3/core.c | 99 +++++++++++++++++++++++++++++++++------
> drivers/usb/dwc3/core.h | 6 +++
> drivers/usb/dwc3/gadget.c | 15 +++++-
> 3 files changed, 104 insertions(+), 16 deletions(-)
>

[...]

> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index e0dee9d28740..d722d3f1402a 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -677,6 +677,8 @@
> /* Force Gen1 speed on Gen2 link */
> #define DWC3_LLUCTL_FORCE_GEN1 BIT(10)
>
> +#define DWC3_CURRENT_UNSPECIFIED UINT_MAX

Would be nice if we can place this macro right under the current_limit
field of the dwc3 struct.

But I know it's minor and not a blocker for this patch, so feel free to
ignore this comment if you think it's not worth the change.

Acked-by: Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx>

Thanks,
Thinh