diff options
author | Arthur Demchenkov <spinal.by@gmail.com> | 2021-01-10 21:54:01 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2021-01-14 23:42:42 +0100 |
commit | 1e64926c5dd978ae444d127b1414e6682b63733f (patch) | |
tree | c5d75368a96c648c6562823aee8ce30292c184ab /drivers/power | |
parent | faf6e9008114f105353f7b8391efdda40633adf9 (diff) | |
download | linux-1e64926c5dd978ae444d127b1414e6682b63733f.tar.gz linux-1e64926c5dd978ae444d127b1414e6682b63733f.tar.bz2 linux-1e64926c5dd978ae444d127b1414e6682b63733f.zip |
power: supply: cpcap-battery: Implement capacity reporting
Calculate percentage using charge_full value provided.
Cc: Arthur Demchenkov <spinal.by@gmail.com>
Cc: Carl Philipp Klemm <philipp@uvos.xyz>
Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Arthur Demchenkov <spinal.by@gmail.com>
[tony@atomide.com: updated to apply after dropping my earlier patch]
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/supply/cpcap-battery.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index bd89e5043484..bb27016f5906 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -546,6 +546,7 @@ static enum power_supply_property cpcap_battery_props[] = { POWER_SUPPLY_PROP_CHARGE_COUNTER, POWER_SUPPLY_PROP_POWER_NOW, POWER_SUPPLY_PROP_POWER_AVG, + POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_CAPACITY_LEVEL, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_TEMP, @@ -556,7 +557,7 @@ static int cpcap_battery_get_property(struct power_supply *psy, union power_supply_propval *val) { struct cpcap_battery_ddata *ddata = power_supply_get_drvdata(psy); - struct cpcap_battery_state_data *latest, *previous; + struct cpcap_battery_state_data *latest, *previous, *empty; u32 sample; s32 accumulator; int cached; @@ -636,6 +637,16 @@ static int cpcap_battery_get_property(struct power_supply *psy, tmp *= ((latest->voltage + previous->voltage) / 20000); val->intval = div64_s64(tmp, 100); break; + case POWER_SUPPLY_PROP_CAPACITY: + empty = cpcap_battery_get_empty(ddata); + if (!empty->voltage || !ddata->charge_full) + return -ENODATA; + /* (ddata->charge_full / 200) is needed for rounding */ + val->intval = empty->counter_uah - latest->counter_uah + + ddata->charge_full / 200; + val->intval = clamp(val->intval, 0, ddata->charge_full); + val->intval = val->intval * 100 / ddata->charge_full; + break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: if (cpcap_battery_full(ddata)) val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL; |