* [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early
@ 2026-11-22 19:20 Venkat Yadlapati via B4 Relay
2026-11-22 19:20 ` [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early Venkat Yadlapati via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Venkat Yadlapati via B4 Relay @ 2026-11-22 19:20 UTC (permalink / raw)
To: Sebastian Reichel
Cc: linux-arm-msm, linux-pm, linux-kernel, Joonhoe Kim, phone-devel,
Venkat Yadlapati
On the Motorola Signature the battery manager firmware keeps the input
current limit of a USB host port at the 100 mA allowed before
enumeration, so the phone discharges while it is connected to a
computer. The dwc3 controller reports the current the host grants
through usb-psy-name, and commit be5e7367bceb made the limit writable.
The controller reports it before the battery manager service is up
though, so the first patch keeps the limit and applies it once the
service comes up. The second one applies it only to SDP, CDP and USB PD
ports, like the downstream driver, so a dedicated charger is never
throttled to what the controller reports.
Tested on a Motorola Signature: connected to a computer it charges after
enumeration instead of discharging.
I used an LLM (Claude) to help write these patches and their commit
messages. I reviewed all of them and tested the result on the device.
---
Changes in v2:
- Drop the Assisted-by trailers and the LLM notes from the commit
messages, the LLM use is stated in this cover letter.
- Link to v1: https://patch.msgid.link/20261116-vantage-battmgr-v1-0-7b59157377b7@yahoo.com
---
Venkat Yadlapati (2):
power: supply: qcom_battmgr: Apply a USB input current limit set early
power: supply: qcom_battmgr: Don't limit the input current of chargers
drivers/power/supply/qcom_battmgr.c | 61 ++++++++++++++++++++++++++++++++-----
1 file changed, 53 insertions(+), 8 deletions(-)
---
base-commit: 7071d4750856abbc68dfe431acc58a1d45dd42e8
change-id: 20261116-vantage-battmgr-945e626783c4
Best regards,
--
Venkat Yadlapati <venkat.yadlapati@yahoo.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early 2026-11-22 19:20 [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Venkat Yadlapati via B4 Relay @ 2026-11-22 19:20 ` Venkat Yadlapati via B4 Relay 2026-12-04 4:39 ` Sebastian Reichel 2026-11-22 19:20 ` [PATCH v2 2/2] power: supply: qcom_battmgr: Don't limit the input current of chargers Venkat Yadlapati via B4 Relay 2026-11-25 8:14 ` [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Qianhui Xu 2 siblings, 1 reply; 5+ messages in thread From: Venkat Yadlapati via B4 Relay @ 2026-11-22 19:20 UTC (permalink / raw) To: Sebastian Reichel Cc: linux-arm-msm, linux-pm, linux-kernel, Joonhoe Kim, phone-devel, Venkat Yadlapati From: Venkat Yadlapati <venkat.yadlapati@yahoo.com> 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. Signed-off-by: Venkat Yadlapati <venkat.yadlapati@yahoo.com> --- drivers/power/supply/qcom_battmgr.c | 45 +++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c index 431a35bcac80..fde9704d0acd 100644 --- a/drivers/power/supply/qcom_battmgr.c +++ b/drivers/power/supply/qcom_battmgr.c @@ -329,6 +329,10 @@ struct qcom_battmgr { bool service_up; + /* USB input current limit set before the service was up, in uA */ + bool usb_icl_pending; + u32 usb_icl; + struct qcom_battmgr_info info; struct qcom_battmgr_status status; struct qcom_battmgr_ac ac; @@ -1144,25 +1148,40 @@ static const struct power_supply_desc sc8280xp_usb_psy_desc = { BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID), }; +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; +} + 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; + } - return ret; + battmgr->usb_icl_pending = false; + + return qcom_battmgr_usb_set_icl(battmgr, pval->intval); } static int qcom_battmgr_usb_is_writeable(struct power_supply *psy, @@ -1742,6 +1761,14 @@ static void qcom_battmgr_enable_worker(struct work_struct *work) ret = qcom_battmgr_request(battmgr, &req, sizeof(req)); if (ret) dev_err(battmgr->dev, "failed to request power notifications\n"); + + if (battmgr->usb_icl_pending) { + battmgr->usb_icl_pending = false; + ret = qcom_battmgr_usb_set_icl(battmgr, battmgr->usb_icl); + if (ret) + dev_warn(battmgr->dev, + "failed to set the USB input current limit: %d\n", ret); + } } static void qcom_battmgr_pdr_notify(void *priv, int state) -- 2.56.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early 2026-11-22 19:20 ` [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early Venkat Yadlapati via B4 Relay @ 2026-12-04 4:39 ` Sebastian Reichel 0 siblings, 0 replies; 5+ messages in thread From: Sebastian Reichel @ 2026-12-04 4:39 UTC (permalink / raw) To: venkat.yadlapati Cc: linux-arm-msm, linux-pm, linux-kernel, Joonhoe Kim, phone-devel [-- Attachment #1: Type: text/plain, Size: 4000 bytes --] Hi, On Mon, Nov 23, 2026 at 12:50:15AM +0530, Venkat Yadlapati via B4 Relay wrote: > From: Venkat Yadlapati <venkat.yadlapati@yahoo.com> > > 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. > > Signed-off-by: Venkat Yadlapati <venkat.yadlapati@yahoo.com> > --- > drivers/power/supply/qcom_battmgr.c | 45 +++++++++++++++++++++++++++++-------- > 1 file changed, 36 insertions(+), 9 deletions(-) > > diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c > index 431a35bcac80..fde9704d0acd 100644 > --- a/drivers/power/supply/qcom_battmgr.c > +++ b/drivers/power/supply/qcom_battmgr.c > @@ -329,6 +329,10 @@ struct qcom_battmgr { > > bool service_up; > > + /* USB input current limit set before the service was up, in uA */ > + bool usb_icl_pending; usb_icl_pending can be implied by usb_icl != 0. > + u32 usb_icl; > + > struct qcom_battmgr_info info; > struct qcom_battmgr_status status; > struct qcom_battmgr_ac ac; > @@ -1144,25 +1148,40 @@ static const struct power_supply_desc sc8280xp_usb_psy_desc = { > BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID), > }; > > +static int qcom_battmgr_usb_set_icl(struct qcom_battmgr *battmgr, u32 icl) > +{ > + int ret; > + This function should just use: guard(mutex)(battmgr->lock); for the mutex. > + 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; > +} > + > 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; > + } battmgr->usb_icl = pval->intval; /* cached value is written when service is brought up */ if (!battmgr->service_up) return 0; return qcom_battmgr_usb_set_icl(battmgr, battmgr->usb_icl); > > - return ret; > + battmgr->usb_icl_pending = false; > + > + return qcom_battmgr_usb_set_icl(battmgr, pval->intval); > } > > static int qcom_battmgr_usb_is_writeable(struct power_supply *psy, > @@ -1742,6 +1761,14 @@ static void qcom_battmgr_enable_worker(struct work_struct *work) > ret = qcom_battmgr_request(battmgr, &req, sizeof(req)); > if (ret) > dev_err(battmgr->dev, "failed to request power notifications\n"); > + > + if (battmgr->usb_icl_pending) { > + battmgr->usb_icl_pending = false; > + ret = qcom_battmgr_usb_set_icl(battmgr, battmgr->usb_icl); > + if (ret) > + dev_warn(battmgr->dev, > + "failed to set the USB input current limit: %d\n", ret); > + } if (battmgr->usb_icl) { ret = qcom_battmgr_usb_set_icl(battmgr, battmgr->usb_icl); if (ret) ... } > } > > static void qcom_battmgr_pdr_notify(void *priv, int state) Greetings, -- Sebastian [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] power: supply: qcom_battmgr: Don't limit the input current of chargers 2026-11-22 19:20 [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Venkat Yadlapati via B4 Relay 2026-11-22 19:20 ` [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early Venkat Yadlapati via B4 Relay @ 2026-11-22 19:20 ` Venkat Yadlapati via B4 Relay 2026-11-25 8:14 ` [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Qianhui Xu 2 siblings, 0 replies; 5+ messages in thread From: Venkat Yadlapati via B4 Relay @ 2026-11-22 19:20 UTC (permalink / raw) To: Sebastian Reichel Cc: linux-arm-msm, linux-pm, linux-kernel, Joonhoe Kim, phone-devel, Venkat Yadlapati From: Venkat Yadlapati <venkat.yadlapati@yahoo.com> The input current limit of the USB power supply is meant for the current a USB host grants, e.g. after enumeration. Like the downstream driver, only apply it to SDP, CDP and USB PD ports, so that a dedicated charger is never throttled to what a USB controller reports. Signed-off-by: Venkat Yadlapati <venkat.yadlapati@yahoo.com> --- drivers/power/supply/qcom_battmgr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c index fde9704d0acd..db117cb64a17 100644 --- a/drivers/power/supply/qcom_battmgr.c +++ b/drivers/power/supply/qcom_battmgr.c @@ -1152,6 +1152,24 @@ static int qcom_battmgr_usb_set_icl(struct qcom_battmgr *battmgr, u32 icl) { int ret; + ret = qcom_battmgr_usb_sm8350_update(battmgr, POWER_SUPPLY_PROP_USB_TYPE); + if (ret) + return ret; + + /* + * The limit is meant for the current a USB host grants, e.g. after + * enumeration, like the downstream driver don't let it throttle + * dedicated chargers. + */ + switch (battmgr->usb.usb_type) { + case POWER_SUPPLY_USB_TYPE_SDP: + case POWER_SUPPLY_USB_TYPE_CDP: + case POWER_SUPPLY_USB_TYPE_PD: + break; + default: + return -EINVAL; + } + mutex_lock(&battmgr->lock); ret = qcom_battmgr_request_property(battmgr, BATTMGR_USB_PROPERTY_SET, USB_INPUT_CURR_LIMIT, icl); -- 2.56.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early 2026-11-22 19:20 [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Venkat Yadlapati via B4 Relay 2026-11-22 19:20 ` [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early Venkat Yadlapati via B4 Relay 2026-11-22 19:20 ` [PATCH v2 2/2] power: supply: qcom_battmgr: Don't limit the input current of chargers Venkat Yadlapati via B4 Relay @ 2026-11-25 8:14 ` Qianhui Xu 2 siblings, 0 replies; 5+ messages in thread From: Qianhui Xu @ 2026-11-25 8:14 UTC (permalink / raw) To: Venkat Yadlapati Cc: Sebastian Reichel, linux-arm-msm, linux-pm, linux-kernel, Joonhoe Kim, phone-devel Hello Venkat, Tested both patches on a second device, an SM8750 tablet (Lenovo Legion Y700 Gen 4), kernel v7.4-rc3 plus be5e7367bceb ("Allow setting the USB input current limit") plus your 1/2 and 2/2. The kernel was started over fastboot boot on the tablet itself; the probe script only reads power supply attributes and writes input_current_limit. The mechanism works here: - write 900000 -> input_current_limit reads back 900000, rc = 0 - write 500000 -> reads back 500000, rc = 0 - no "unknown message" from qcom_battmgr in dmesg after the writes - usb_type on this port reports SDP, so the filter in 2/2 lets the write through; without the filter the behaviour was the same - the firmware default here is 100 mA, not the 500 mA you saw on the Motorola, so 1/2's replay is the interesting part for devices like this one. I did not get a sample of that path itself (the limits above were written after the service was up). One observation, offered as data, not as a request: on the PC port used here the battery-side current_now did not follow the requested limit in the expected direction (500 mA -> about +1.14 A, 900 mA -> about +0.77 A, two rounds each, same boot). That number is not trustworthy on this board as a power measure - +1.14 A cannot come from a 500 mA port - so I am not claiming the limit is ineffective, only that current_now is not a usable oracle for it here. If you have a way to observe the effect on the Motorola that is less indirect, it would be worth putting in the cover. Feel free to carry: Tested-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn> # on 1/2 and 2/2 Tested against: be5e7367bceb (power-supply for-next) + this series, on SM8750 / Lenovo Legion Y700 Gen 4, USB2 SDP port of a PC. Disclosure: this test report was prepared with the help of an LLM coding assistant; every command and every number above was run and read by the author on the device. Best regards, Qianhui Xu ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 4:39 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-22 19:20 [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Venkat Yadlapati via B4 Relay 2026-11-22 19:20 ` [PATCH v2 1/2] power: supply: qcom_battmgr: Apply a USB input current limit set early Venkat Yadlapati via B4 Relay 2026-12-04 4:39 ` Sebastian Reichel 2026-11-22 19:20 ` [PATCH v2 2/2] power: supply: qcom_battmgr: Don't limit the input current of chargers Venkat Yadlapati via B4 Relay 2026-11-25 8:14 ` [PATCH v2 0/2] power: supply: qcom_battmgr: Apply the USB host current limit early Qianhui Xu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox