Commit 39ed1e1a authored by Sven Neumann's avatar Sven Neumann Committed by Greg Kroah-Hartman

ds2760_battery: Fix calculation of time_to_empty_now

commit 86af9503 upstream.

A check against division by zero was modified in commit b0525b48.
Since this change time_to_empty_now is always reported as zero
while the battery is discharging and as a negative value while
the battery is charging. This is because current is negative while
the battery is discharging.

Fix the check introduced by commit b0525b48 so that time_to_empty_now
is reported correctly during discharge and as zero while charging.
Signed-off-by: default avatarSven Neumann <s.neumann@raumfeld.com>
Acked-by: default avatarDaniel Mack <daniel@caiaq.de>
Signed-off-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent fcd8c1ff
...@@ -212,7 +212,7 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di) ...@@ -212,7 +212,7 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)
if (di->rem_capacity > 100) if (di->rem_capacity > 100)
di->rem_capacity = 100; di->rem_capacity = 100;
if (di->current_uA >= 100L) if (di->current_uA < -100L)
di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 36L) di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 36L)
/ (di->current_uA / 100L); / (di->current_uA / 100L);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment