All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Elson Serrao <elson.serrao@oss.qualcomm.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"jack.pham@oss.qualcomm.com" <jack.pham@oss.qualcomm.com>,
	"wesley.cheng@oss.qualcomm.com" <wesley.cheng@oss.qualcomm.com>
Subject: Re: [PATCH v2] usb: dwc3: avoid probe deferral when USB power supply is not available
Date: Tue, 2 Jun 2026 23:24:20 +0000	[thread overview]
Message-ID: <ah9elkU6NI1CsXWT@vbox> (raw)
In-Reply-To: <7ab2b045-d93e-4a25-9ef2-ef34146fd53b@oss.qualcomm.com>

On Mon, Jun 01, 2026, Elson Serrao wrote:
> 
> 
> On 5/27/2026 4:23 PM, Thinh Nguyen wrote:
> > On Tue, May 26, 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.
> >>
> 
> [...]
> 


> 
> >> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> >> index 3d4ca68e584c..303598048e9a 100644
> >> --- a/drivers/usb/dwc3/gadget.c
> >> +++ b/drivers/usb/dwc3/gadget.c
> >> @@ -3124,15 +3124,21 @@ static void dwc3_gadget_set_ssp_rate(struct usb_gadget *g,
> >>  static int dwc3_gadget_vbus_draw(struct usb_gadget *g, unsigned int mA)
> >>  {
> >>  	struct dwc3		*dwc = gadget_to_dwc(g);
> >> +	unsigned long		flags;
> >>  
> >>  	if (dwc->usb2_phy)
> >>  		return usb_phy_set_power(dwc->usb2_phy, mA);
> >>  
> >> -	if (!dwc->usb_psy)
> >> +	spin_lock_irqsave(&dwc->lock, flags);
> >> +	dwc->current_limit = mA;
> >> +	if (!dwc->usb_psy) {
> >> +		spin_unlock_irqrestore(&dwc->lock, flags);
> >> +		dev_dbg(dwc->dev, "Stored VBUS draw: %u mA (power supply not ready)\n", mA);
> > 
> > Can we use the check if dwc->psy_nb.notifier_block is set to determine
> > if we expect to have a power_supply? Then we can print the message above
> > when it's really not ready, and only return -EOPNOTSUPP if we really
> > don't have a power_supply.
> > 
> Hi Thinh,
> 
> Just to clarify, in the case where dwc->psy_nb.notifier_call is set
> (i.e., we expect the power_supply but it is not available yet), should we
> return 0 and treat it as success since the current limit is cached and
> will be applied later?

Yes, just return 0.

> 
> Or would you prefer returning an error (e.g., -ENODEV) to indicate to
> composite/upper layers that the current limit was not applied immediately
> (in case they need to observe this state)?
> 
> Currently, we update gadget->mA only if this gadget op returns success.
> Returning 0 in this case would update gadget->mA even though the limit
> has not yet been applied.
> 

The dwc->current_limit is updated unconditionally when
usb_gadget_vbus_draw() is called. The gadget->mA should also be updated
and be in sync with the cached value dwc->current_limit. Otherwise, the
gadget->mA will be stale when the notifier update the power supply
after.

BR,
Thinh

      reply	other threads:[~2026-06-03  1:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 18:30 [PATCH v2] usb: dwc3: avoid probe deferral when USB power supply is not available Elson Serrao
2026-05-27 23:23 ` Thinh Nguyen
2026-06-01 23:43   ` Elson Serrao
2026-06-02 23:24     ` Thinh Nguyen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ah9elkU6NI1CsXWT@vbox \
    --to=thinh.nguyen@synopsys.com \
    --cc=elson.serrao@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack.pham@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=wesley.cheng@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.