From: Val Packett <val@packett.cool>
To: Sebastian Reichel <sre@kernel.org>,
Fenglin Wu <fenglin.wu@oss.qualcomm.com>,
Neil Armstrong <neil.armstrong@linaro.org>
Cc: Val Packett <val@packett.cool>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] power: supply: qcom_battmgr: support disabling charge control
Date: Sun, 12 Oct 2025 20:32:19 -0300 [thread overview]
Message-ID: <20251012233333.19144-4-val@packett.cool> (raw)
In-Reply-To: <20251012233333.19144-2-val@packett.cool>
Existing userspace (in particular, upower) disables charge control by
setting the start threshold to 0 and the stop threshold to 100.
Handle that by actually setting the enable bit to 0 when a start
threshold of 0 was requested.
Fixes: cc3e883a0625 ("power: supply: qcom_battmgr: Add charge control support")
Signed-off-by: Val Packett <val@packett.cool>
---
drivers/power/supply/qcom_battmgr.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index c8028606bba0..e6f01e0122e1 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -257,6 +257,7 @@ struct qcom_battmgr_info {
unsigned int capacity_warning;
unsigned int cycle_count;
unsigned int charge_count;
+ bool charge_ctrl_enable;
unsigned int charge_ctrl_start;
unsigned int charge_ctrl_end;
char model_number[BATTMGR_STRING_LEN];
@@ -659,13 +660,13 @@ static int qcom_battmgr_bat_get_property(struct power_supply *psy,
}
static int qcom_battmgr_set_charge_control(struct qcom_battmgr *battmgr,
- u32 target_soc, u32 delta_soc)
+ bool enable, u32 target_soc, u32 delta_soc)
{
struct qcom_battmgr_charge_ctrl_request request = {
.hdr.owner = cpu_to_le32(PMIC_GLINK_OWNER_BATTMGR),
.hdr.type = cpu_to_le32(PMIC_GLINK_REQ_RESP),
.hdr.opcode = cpu_to_le32(BATTMGR_CHG_CTRL_LIMIT_EN),
- .enable = cpu_to_le32(1),
+ .enable = cpu_to_le32(enable),
.target_soc = cpu_to_le32(target_soc),
.delta_soc = cpu_to_le32(delta_soc),
};
@@ -677,6 +678,7 @@ static int qcom_battmgr_set_charge_start_threshold(struct qcom_battmgr *battmgr,
{
u32 target_soc, delta_soc;
int ret;
+ bool enable = start_soc != 0;
start_soc = clamp(start_soc, CHARGE_CTRL_START_THR_MIN, CHARGE_CTRL_START_THR_MAX);
@@ -696,9 +698,10 @@ static int qcom_battmgr_set_charge_start_threshold(struct qcom_battmgr *battmgr,
}
mutex_lock(&battmgr->lock);
- ret = qcom_battmgr_set_charge_control(battmgr, target_soc, delta_soc);
+ ret = qcom_battmgr_set_charge_control(battmgr, enable, target_soc, delta_soc);
mutex_unlock(&battmgr->lock);
if (!ret) {
+ battmgr->info.charge_ctrl_enable = enable;
battmgr->info.charge_ctrl_start = start_soc;
battmgr->info.charge_ctrl_end = target_soc;
}
@@ -710,6 +713,7 @@ static int qcom_battmgr_set_charge_end_threshold(struct qcom_battmgr *battmgr, i
{
u32 delta_soc = CHARGE_CTRL_DELTA_SOC;
int ret;
+ bool enable = battmgr->info.charge_ctrl_enable;
end_soc = clamp(end_soc, CHARGE_CTRL_END_THR_MIN, CHARGE_CTRL_END_THR_MAX);
@@ -717,7 +721,7 @@ static int qcom_battmgr_set_charge_end_threshold(struct qcom_battmgr *battmgr, i
delta_soc = end_soc - battmgr->info.charge_ctrl_start;
mutex_lock(&battmgr->lock);
- ret = qcom_battmgr_set_charge_control(battmgr, end_soc, delta_soc);
+ ret = qcom_battmgr_set_charge_control(battmgr, enable, end_soc, delta_soc);
mutex_unlock(&battmgr->lock);
if (!ret) {
battmgr->info.charge_ctrl_start = end_soc - delta_soc;
--
2.51.0
next prev parent reply other threads:[~2025-10-12 23:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-12 23:32 [PATCH 0/2] power: supply: qcom_battmgr: improve charge control threshold handling Val Packett
2025-10-12 23:32 ` [PATCH 1/2] power: supply: qcom_battmgr: clamp charge control thresholds Val Packett
2025-10-13 9:43 ` Konrad Dybcio
2025-10-12 23:32 ` Val Packett [this message]
2025-11-17 5:22 ` [PATCH 2/2] power: supply: qcom_battmgr: support disabling charge control Fenglin Wu
2025-11-03 0:48 ` [PATCH 0/2] power: supply: qcom_battmgr: improve charge control threshold handling Sebastian Reichel
2025-11-03 3:46 ` Val Packett
2025-11-03 14:41 ` Sebastian Reichel
2025-11-17 5:12 ` Fenglin Wu
2025-11-17 12:45 ` Konrad Dybcio
2025-11-18 2:29 ` Fenglin Wu
2025-11-18 10:13 ` Konrad Dybcio
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=20251012233333.19144-4-val@packett.cool \
--to=val@packett.cool \
--cc=fenglin.wu@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=sebastian.reichel@collabora.com \
--cc=sre@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