summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorPaer-Olof Haakansson <par-olof.hakansson@stericsson.com>2012-05-10 10:41:55 +0200
committerMathieu J. Poirier <mathieu.poirier@linaro.org>2012-09-25 09:37:06 -0600
commit997a88a15aa6b98732341daf54fec6f116982408 (patch)
tree7db677b90f19867551364ca41927fa5d8b5f9255 /drivers/power
parentcf0886a6e03f2de0735ee8aa8dc674ca1510972d (diff)
power: Overflow in current calculation
When calculating the average current the nominator will overflow when the charging current is high. Signed-off-by: Henrik Sölver <henrik.solver@stericsson.com> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Par-Olof HAKANSSON <par-olof.hakansson@stericsson.com> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/ab8500_fg.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index 46010ecaaf0b..7c421504f18a 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -805,15 +805,13 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work)
/*
* Convert to unit value in mA
- * Full scale input voltage is
- * 66.660mV => LSB = 66.660mV/(4096*res) = 1.627mA
- * Given a 250ms conversion cycle time the LSB corresponds
- * to 112.9 nAh. Convert to current by dividing by the conversion
+ * by dividing by the conversion
* time in hours (= samples / (3600 * 4)h)
- * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm
+ * and multiply with 1000
*/
- di->avg_curr = (val * QLSB_NANO_AMP_HOURS_X10 * 36) /
- (1000 * di->bat->fg_res * (di->fg_samples / 4));
+
+ di->avg_curr = (di->accu_charge * 36) /
+ ((di->fg_samples / 4) * 10);
di->flags.conv_done = true;
@@ -821,6 +819,9 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work)
queue_work(di->fg_wq, &di->fg_work);
+ dev_dbg(di->dev,
+ "fg_res: %d, fg_samples: %d, gasg: %d, accu_charge: %d\n",
+ di->bat->fg_res, di->fg_samples, val, di->accu_charge);
return;
exit:
dev_err(di->dev,