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

From: Konrad Dybcio

Date: Tue Dec 01 2026 - 05:44:18 EST


On 11/15/26 9:20 PM, Venkat Yadlapati via B4 Relay wrote:
> From: Venkat Yadlapati <venkat.yadlapati@xxxxxxxxx>
>
> The USB controller can report the current a USB host grants, e.g. with
> the usb-psy-name property of dwc3, before the battery manager service
> is up. The input current limit is then rejected with -EAGAIN and the
> firmware keeps the 100 mA allowed before enumeration, so a phone that is
> in use discharges while it is connected to a computer.
>
> Remember the limit while the service is down and send it once the
> service comes up.
>
> Assisted-by: LLM

This tag is no longer valid, please switch to linux-next/master as
your base and run checkpatch

> Signed-off-by: Venkat Yadlapati <venkat.yadlapati@xxxxxxxxx>
> ---

[...]

> +static int qcom_battmgr_usb_set_icl(struct qcom_battmgr *battmgr, u32 icl)
> +{
> + int ret;
> +
> + 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_...


> +}
> +
> static int qcom_battmgr_usb_set_property(struct power_supply *psy,
> enum power_supply_property psp,
> const union power_supply_propval *pval)
> {
> struct qcom_battmgr *battmgr = power_supply_get_drvdata(psy);
> - int ret;
> -
> - if (!battmgr->service_up)
> - return -EAGAIN;
>
> if (psp != POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT || pval->intval < 0)
> return -EINVAL;
>
> - mutex_lock(&battmgr->lock);
> - ret = qcom_battmgr_request_property(battmgr, BATTMGR_USB_PROPERTY_SET,
> - USB_INPUT_CURR_LIMIT, pval->intval);
> - mutex_unlock(&battmgr->lock);
> + /*
> + * The USB controller can report the current a host grants before the
> + * firmware service is up, apply it once the service comes up.
> + */
> + 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

Konrad