Re: [PATCH 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early

From: Venkat Yadlapati

Date: Tue Dec 01 2026 - 11:09:31 EST


On 12/1/26 4:14 PM, Konrad Dybcio wrote:
> On 11/15/26 9:20 PM, Venkat Yadlapati via B4 Relay wrote:
>> Assisted-by: LLM
>
> This tag is no longer valid, please switch to linux-next/master as
> your base and run checkpatch

Thanks for the review. That line is already gone in v2 [1], which is
based on next-20261120 and otherwise has the same code as v1, so the
comments below apply to v2 as well. v3 will be on a current linux-next
and checked with checkpatch again.

>> + mutex_lock(&battmgr->lock);
>> + ret = qcom_battmgr_request_property(battmgr, BATTMGR_USB_PROPERTY_SET,
>> + USB_INPUT_CURR_LIMIT, icl);
>> + mutex_unlock(&battmgr->lock);
>> +
>> + return ret;
>
> guard(mutex)(&battmgr->lock)
>
> return qcom_battmgr_...

Will do.

>> + if (!battmgr->service_up) {
>> + battmgr->usb_icl = pval->intval;
>> + battmgr->usb_icl_pending = true;
>> + return 0;
>> + }
>
> This is the easiest workaround, but I fear this may spiral out of
> control, as the same would apply to essentially any parameter
> that's writeable.
>
> I'm thinking about whether we should perhaps defer the
> registration of the power supplies until the service first appears.
> I'm not sure of how much collateral damage that would cause. Upon
> a "service goes down" event, we could keep the "return -EAGAIN"
> behavior

Agreed, and for the dwc3 case it looks like the cleaner fix. dwc3
already copes with a supply that shows up late: since 7c87ef27af79
("usb: dwc3: avoid probe deferral when USB power supply is not
available") it waits on the power supply notifier instead of deferring
its probe, and when the supply appears it sends the current it has
stored in the meantime. So with the supplies registered from the first
SERVREG_SERVICE_STATE_UP, the limit reaches the firmware without any
caching in battmgr, and dwc3 is not held back while the ADSP boots.

The other users I can think of (the userspace battery tools, power
supply links from other drivers) already have to deal with supplies
that appear later, but I may be missing a user on the laptops.

I would do that in v3: register the power supplies from the
enable work on the first "up" notification instead of in probe, keep
returning -EAGAIN while the service is down after that, and drop the
usb_icl_pending caching from this patch.

One thing I noticed in the current version: the pending limit is
applied right after the notifications are enabled, and with 2/2 the
charger type is read at that point. It can still be unknown then, in
which case 2/2 rejects the limit. The downstream driver sleeps 200 ms
before re-applying the limit for that reason. With late registration
dwc3 sets the limit only after the supply is registered, but the type
may still not be known yet, so I will look at that in v3 too.

v3 will take a while, as the phone is going in for repair and I
don't want to send it untested.

[1] https://lore.kernel.org/all/20261123-vantage-battmgr-v2-0-03a419078d0a@xxxxxxxxx/

Thanks,
Venkat