diff mbox series

[15/15] power: supply: cpcap-battery: Add rounding to capacity reporting

Message ID 20200315151206.30909-15-spinal.by@gmail.com (mailing list archive)
State New, archived
Headers show
Series [01/15] power: supply: cpcap-battery: Fix battery full status reporting | expand

Commit Message

Arthur D. March 15, 2020, 3:12 p.m. UTC
Add rounding to capacity reporting.

Signed-off-by: Arthur Demchenkov <spinal.by@gmail.com>
---
 drivers/power/supply/cpcap-battery.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 4e872bd36ccf..b16848cfb58c 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -627,7 +627,9 @@  static int cpcap_battery_get_property(struct power_supply *psy,
 		empty = cpcap_battery_get_empty(ddata);
 		if (!empty->voltage || !ddata->charge_full)
 			return -ENODATA;
-		val->intval = empty->counter_uah - latest->counter_uah;
+		/* (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;