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

Commit 6314dfd6 authored by Jie Cheng's avatar Jie Cheng
Browse files

power: vm_bms: use DIV_ROUND_CLOSEST for soc and acc calculation



The kernel does not provide the round off feature for normal div
function. The DIV_ROUND_CLOSEST macro should be used in the soc and
acc calculation for rounding off the data.

Change-Id: I72d5b3ed5f90859b01909677f66c2abb65d4c9ec
Signed-off-by: default avatarJie Cheng <rockiec@codeaurora.org>
parent d2d9cb96
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -835,7 +835,8 @@ static int lookup_soc_ocv(struct qpnp_bms_chip *chip, int ocv_uv, int batt_temp)
	soc_cutoff = interpolate_pc(chip->batt_data->pc_temp_ocv_lut,
				batt_temp, chip->dt.cfg_v_cutoff_uv / 1000);

	soc_final = (100 * (soc_ocv - soc_cutoff)) / (100 - soc_cutoff);
	soc_final = DIV_ROUND_CLOSEST(100 * (soc_ocv - soc_cutoff),
							(100 - soc_cutoff));

	if (chip->batt_data->ibat_acc_lut) {
		/* Apply  ACC logic only if we discharging */
@@ -853,11 +854,12 @@ static int lookup_soc_ocv(struct qpnp_bms_chip *chip, int ocv_uv, int batt_temp)
				else
					acc = fcc;
			}
			soc_uuc = ((fcc - acc) * 100) / acc;
			soc_uuc = ((fcc - acc) * 100) / fcc;

			soc_uuc = adjust_uuc(chip, soc_uuc);

			soc_acc = soc_final - soc_uuc;
			soc_acc = DIV_ROUND_CLOSEST(100 * (soc_ocv - soc_uuc),
							(100 - soc_uuc));

			pr_debug("fcc=%d acc=%d soc_final=%d soc_uuc=%d soc_acc=%d current_now=%d iavg_ma=%d\n",
				fcc, acc, soc_final, soc_uuc,