From: Johan Korsnes <johan.korsnes@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: USB charging: How to determine maximum allowed current draw
Date: Tue, 14 Oct 2025 09:33:41 +0200 [thread overview]
Message-ID: <46facf7f-de3e-4cb2-b452-df7ffe9b474b@gmail.com> (raw)
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
reply other threads:[~2025-10-14 7:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=46facf7f-de3e-4cb2-b452-df7ffe9b474b@gmail.com \
--to=johan.korsnes@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox