diff options
author | Carl Philipp Klemm <philipp@uvos.xyz> | 2021-04-23 15:58:31 +0300 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2021-06-04 15:28:31 +0300 |
commit | aecd127b45eac8ce0ff667a4a855ff66905fb88c (patch) | |
tree | bf8fd93efd438a1d06f42c4da2ee8f08384142fc /drivers/power/supply/cpcap-battery.c | |
parent | 6a0fcc87c9e35191d37a8819fdab9d30e523515b (diff) | |
download | linux-aecd127b45eac8ce0ff667a4a855ff66905fb88c.tar.xz |
power: supply: cpcap-battery: invalidate config when incompatible measurements are read
This invalidates empty->counter_uah and charge_full when charge_now
indicates that they are grossly wrong and adds some tolerance to
POWER_SUPPLY_PROP_CHARGE_FULL to allow for inaccuracies in the charge
counter and manufacturing tolerances in the battery.
Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power/supply/cpcap-battery.c')
-rw-r--r-- | drivers/power/supply/cpcap-battery.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index a3fc0084cda0..8d62d4241da3 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -667,10 +667,23 @@ static int cpcap_battery_get_property(struct power_supply *psy, if (!empty->voltage) return -ENODATA; val->intval = empty->counter_uah - latest->counter_uah; - if (val->intval < 0) + if (val->intval < 0) { + /* Assume invalid config if CHARGE_NOW is -20% */ + if (ddata->charge_full && abs(val->intval) > ddata->charge_full/5) { + empty->voltage = 0; + ddata->charge_full = 0; + return -ENODATA; + } val->intval = 0; - else if (ddata->charge_full && ddata->charge_full < val->intval) + } else if (ddata->charge_full && ddata->charge_full < val->intval) { + /* Assume invalid config if CHARGE_NOW exceeds CHARGE_FULL by 20% */ + if (val->intval > (6*ddata->charge_full)/5) { + empty->voltage = 0; + ddata->charge_full = 0; + return -ENODATA; + } val->intval = ddata->charge_full; + } break; case POWER_SUPPLY_PROP_CHARGE_FULL: if (!ddata->charge_full) @@ -747,7 +760,7 @@ static int cpcap_battery_set_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CHARGE_FULL: if (val->intval < 0) return -EINVAL; - if (val->intval > ddata->config.info.charge_full_design) + if (val->intval > (6*ddata->config.info.charge_full_design)/5) return -EINVAL; ddata->charge_full = val->intval; |