public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* USB charging: How to determine maximum allowed current draw
@ 2025-10-14  7:33 Johan Korsnes
  0 siblings, 0 replies; only message in thread
From: Johan Korsnes @ 2025-10-14  7:33 UTC (permalink / raw)
  To: linux-kernel

Hi,

I'm writing logic to determine the maximum current draw my USB device
(gadget) may safely draw from a USB host port. I haven't found any
appropriate place for this logic, so as for now, it lives in the driver
for my Type-C controller.

This means I have easy access to the negotiated USB Type-C current at
either 3.0A or 1.5A. If the Type-C controller reports Default current
I would like to proceed with the BC1.2 negotiation next. This is also
quite straight-forward, as the driver handling BC1.2 updates the usbphy
that I have a reference to. Hence, the usbphy notifier callback will
inform me about the outcome of the BC1.2 negotiation.

Now, the problem is if the outcome of that negotiation is SDP. In that
case, I need to know whether the gadget is enumerated/configured or not.
If the gadget is non-enumerated, I'm only allowed to draw 100mA (USB2),
while if it's enumerated, we're allowed to draw 500mA. I don't see how
I can obtain this state from my Type-C driver.

I noticed that the UDC driver, together with the composite driver, do
inform the usbphy about the correct SDP current, based on enumeration
and suspend state. But, things are a bit racy, as the phy driver itself
uses 500mA as default/initialization value for SDP:

#define DEFAULT_SDP_CUR_MAX	500

Is there something I've missed? Reading Neil Brown's LWN articles on USB
charging, there is reference to on-going work on a dedicated driver for
handling USB charging. Or, is it the extcon framework I should be using?

Kind regards,
Johan

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-14  7:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14  7:33 USB charging: How to determine maximum allowed current draw Johan Korsnes

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