Skip to content

Commit 8809980

Browse files
valpackettsre
authored andcommitted
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: cc3e883 ("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>
1 parent ea14bae commit 8809980

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

drivers/power/supply/qcom_battmgr.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,7 @@ static int qcom_battmgr_set_charge_start_threshold(struct qcom_battmgr *battmgr,
678678
u32 target_soc, delta_soc;
679679
int ret;
680680

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);
687682

688683
/*
689684
* If the new start threshold is larger than the old end threshold,
@@ -716,12 +711,7 @@ static int qcom_battmgr_set_charge_end_threshold(struct qcom_battmgr *battmgr, i
716711
u32 delta_soc = CHARGE_CTRL_DELTA_SOC;
717712
int ret;
718713

719-
if (end_soc < CHARGE_CTRL_END_THR_MIN ||
720-
end_soc > CHARGE_CTRL_END_THR_MAX) {
721-
dev_err(battmgr->dev, "charge control end threshold exceed range: [%u - %u]\n",
722-
CHARGE_CTRL_END_THR_MIN, CHARGE_CTRL_END_THR_MAX);
723-
return -EINVAL;
724-
}
714+
end_soc = clamp(end_soc, CHARGE_CTRL_END_THR_MIN, CHARGE_CTRL_END_THR_MAX);
725715

726716
if (battmgr->info.charge_ctrl_start && end_soc > battmgr->info.charge_ctrl_start)
727717
delta_soc = end_soc - battmgr->info.charge_ctrl_start;

0 commit comments

Comments
 (0)