Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f902dadc authored by Paer-Olof Haakansson's avatar Paer-Olof Haakansson Committed by Anton Vorontsov
Browse files

ab8500_fg: Overflow in current calculation



When calculating the average current the nominator will
overflow when the charging current is high.

Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarHenrik Sölver <henrik.solver@stericsson.com>
Reviewed-by: default avatarPar-Olof HAKANSSON <par-olof.hakansson@stericsson.com>
Reviewed-by: default avatarJonas ABERG <jonas.aberg@stericsson.com>
Tested-by: default avatarPar-Olof HAKANSSON <par-olof.hakansson@stericsson.com>
Signed-off-by: default avatarAnton Vorontsov <anton@enomsg.org>
parent 4b45f4a9
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -805,12 +805,9 @@ 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->bm->fg_res * (di->fg_samples / 4));
@@ -821,6 +818,8 @@ 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->bm->fg_res, di->fg_samples, val, di->accu_charge);
	return;
exit:
	dev_err(di->dev,