* [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
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
0 siblings, 2 replies; 3+ 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] 3+ 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-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
1 sibling, 0 replies; 3+ 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 [flat|nested] 3+ 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
1 sibling, 0 replies; 3+ 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 [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-22 19:20 UTC | newest]
Thread overview: 3+ 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-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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®