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

power: supply: qcom_battmgr: clamp charge control thresholds

The sysfs API documentation says that drivers "round written values to
the nearest supported value" for charge_control_end_threshold.

Let's do this for both thresholds, as userspace (e.g. upower) generally
does not expect these writes to fail at all.

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-3-val@packett.cool
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Val Packett and committed by
Sebastian Reichel
8809980f ea14bae6

+2 -12
+2 -12
drivers/power/supply/qcom_battmgr.c
··· 678 678 u32 target_soc, delta_soc; 679 679 int ret; 680 680 681 - if (start_soc < CHARGE_CTRL_START_THR_MIN || 682 - start_soc > CHARGE_CTRL_START_THR_MAX) { 683 - dev_err(battmgr->dev, "charge control start threshold exceed range: [%u - %u]\n", 684 - CHARGE_CTRL_START_THR_MIN, CHARGE_CTRL_START_THR_MAX); 685 - return -EINVAL; 686 - } 681 + start_soc = clamp(start_soc, CHARGE_CTRL_START_THR_MIN, CHARGE_CTRL_START_THR_MAX); 687 682 688 683 /* 689 684 * If the new start threshold is larger than the old end threshold, ··· 711 716 u32 delta_soc = CHARGE_CTRL_DELTA_SOC; 712 717 int ret; 713 718 714 - if (end_soc < CHARGE_CTRL_END_THR_MIN || 715 - end_soc > CHARGE_CTRL_END_THR_MAX) { 716 - dev_err(battmgr->dev, "charge control end threshold exceed range: [%u - %u]\n", 717 - CHARGE_CTRL_END_THR_MIN, CHARGE_CTRL_END_THR_MAX); 718 - return -EINVAL; 719 - } 719 + end_soc = clamp(end_soc, CHARGE_CTRL_END_THR_MIN, CHARGE_CTRL_END_THR_MAX); 720 720 721 721 if (battmgr->info.charge_ctrl_start && end_soc > battmgr->info.charge_ctrl_start) 722 722 delta_soc = end_soc - battmgr->info.charge_ctrl_start;