Skip to contentSkip to conversation

ds2760_battery: fix calculation of time_to_empty_now

PATCH In review Sven Neumann 2 participants 2 messages Nov 12, 2010 – Nov 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ds2760_battery: fix calculation of time_to_empty_now

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.

---
 drivers/power/ds2760_battery.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/power/ds2760_battery.c +1 -1
index 4d3b272..c8d26df 100644
@@ -212,7 +212,7 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di)
 	if (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->current_uA / 100L);
 	else
Signature · 1 line
1.7.1
#1 lore raw
Quoted 11 lines · Sven Neumann

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.

Applied (with Cc: [email protected] [2.6.32..2.6.36]).

Thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2