summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2022-02-06 19:35:42 +0100
committerSebastian Reichel <sebastian.reichel@collabora.com>2022-02-11 19:08:34 +0100
commit4e456230f1ba27deed5a2148bc58c85281d214b7 (patch)
tree5178cd56f3288618cab6bfb0b13b4cb183af01bd
parent445c21d2080f6ffaad3482409fe90e8ed22db6a2 (diff)
power: supply: bq24190_charger: Disallow ccc_ireg and cvc_vreg to be higher then the fwnode values
If the fwnode data as parsed by power_supply_get_battery_info() provides max values for ccc_ireg and cvc_vreg then do not allow the user to later set these to higher values then those specified by the firmware, otherwise the battery might get damaged. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-rw-r--r--drivers/power/supply/bq24190_charger.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 974e4b6b8d4d..04aa25f2d033 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -1019,6 +1019,9 @@ static int bq24190_charger_set_current(struct bq24190_dev_info *bdi,
if (v)
curr *= 5;
+ if (curr > bdi->ichg_max)
+ return -EINVAL;
+
ret = bq24190_set_field_val(bdi, BQ24190_REG_CCC,
BQ24190_REG_CCC_ICHG_MASK, BQ24190_REG_CCC_ICHG_SHIFT,
bq24190_ccc_ichg_values,
@@ -1052,6 +1055,9 @@ static int bq24190_charger_set_voltage(struct bq24190_dev_info *bdi,
{
int ret;
+ if (val->intval > bdi->vreg_max)
+ return -EINVAL;
+
ret = bq24190_set_field_val(bdi, BQ24190_REG_CVC,
BQ24190_REG_CVC_VREG_MASK, BQ24190_REG_CVC_VREG_SHIFT,
bq24190_cvc_vreg_values,
@@ -1743,11 +1749,11 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi)
/* These are optional, so no warning when not set */
v = info->constant_charge_current_max_ua;
if (v >= bq24190_ccc_ichg_values[0] && v <= bdi->ichg_max)
- bdi->ichg = v;
+ bdi->ichg = bdi->ichg_max = v;
v = info->constant_charge_voltage_max_uv;
if (v >= bq24190_cvc_vreg_values[0] && v <= bdi->vreg_max)
- bdi->vreg = v;
+ bdi->vreg = bdi->vreg_max = v;
}
return 0;