Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: qcom_battmgr: support disabling charge control

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>
Link: https://patch.msgid.link/20251012233333.19144-4-val@packett.cool
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Val Packett and committed by
Sebastian Reichel
446fcf49 8809980f

+8 -4
+8 -4
drivers/power/supply/qcom_battmgr.c
··· 257 257 unsigned int capacity_warning; 258 258 unsigned int cycle_count; 259 259 unsigned int charge_count; 260 + bool charge_ctrl_enable; 260 261 unsigned int charge_ctrl_start; 261 262 unsigned int charge_ctrl_end; 262 263 char model_number[BATTMGR_STRING_LEN]; ··· 660 659 } 661 660 662 661 static int qcom_battmgr_set_charge_control(struct qcom_battmgr *battmgr, 663 - u32 target_soc, u32 delta_soc) 662 + bool enable, u32 target_soc, u32 delta_soc) 664 663 { 665 664 struct qcom_battmgr_charge_ctrl_request request = { 666 665 .hdr.owner = cpu_to_le32(PMIC_GLINK_OWNER_BATTMGR), 667 666 .hdr.type = cpu_to_le32(PMIC_GLINK_REQ_RESP), 668 667 .hdr.opcode = cpu_to_le32(BATTMGR_CHG_CTRL_LIMIT_EN), 669 - .enable = cpu_to_le32(1), 668 + .enable = cpu_to_le32(enable), 670 669 .target_soc = cpu_to_le32(target_soc), 671 670 .delta_soc = cpu_to_le32(delta_soc), 672 671 }; ··· 678 677 { 679 678 u32 target_soc, delta_soc; 680 679 int ret; 680 + bool enable = start_soc != 0; 681 681 682 682 start_soc = clamp(start_soc, CHARGE_CTRL_START_THR_MIN, CHARGE_CTRL_START_THR_MAX); 683 683 ··· 698 696 } 699 697 700 698 mutex_lock(&battmgr->lock); 701 - ret = qcom_battmgr_set_charge_control(battmgr, target_soc, delta_soc); 699 + ret = qcom_battmgr_set_charge_control(battmgr, enable, target_soc, delta_soc); 702 700 mutex_unlock(&battmgr->lock); 703 701 if (!ret) { 702 + battmgr->info.charge_ctrl_enable = enable; 704 703 battmgr->info.charge_ctrl_start = start_soc; 705 704 battmgr->info.charge_ctrl_end = target_soc; 706 705 } ··· 713 710 { 714 711 u32 delta_soc = CHARGE_CTRL_DELTA_SOC; 715 712 int ret; 713 + bool enable = battmgr->info.charge_ctrl_enable; 716 714 717 715 end_soc = clamp(end_soc, CHARGE_CTRL_END_THR_MIN, CHARGE_CTRL_END_THR_MAX); 718 716 ··· 721 717 delta_soc = end_soc - battmgr->info.charge_ctrl_start; 722 718 723 719 mutex_lock(&battmgr->lock); 724 - ret = qcom_battmgr_set_charge_control(battmgr, end_soc, delta_soc); 720 + ret = qcom_battmgr_set_charge_control(battmgr, enable, end_soc, delta_soc); 725 721 mutex_unlock(&battmgr->lock); 726 722 if (!ret) { 727 723 battmgr->info.charge_ctrl_start = end_soc - delta_soc;