[<prev] [next>] [day] [month] [year] [list]
Message-ID: <46facf7f-de3e-4cb2-b452-df7ffe9b474b@gmail.com>
Date: Tue, 14 Oct 2025 09:33:41 +0200
From: Johan Korsnes <johan.korsnes@...il.com>
To: linux-kernel@...r.kernel.org
Subject: USB charging: How to determine maximum allowed current draw
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
Powered by blists - more mailing lists