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

Commit 286d5160 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen3: Fine tune the monotonic SOC calculation



Currently, all the values of raw monotonic SOC (0-255) gets
rounded off to 0-100. This can show up monotonic SOC hitting 0%
earlier when the SOC hadn't really hit zero yet. Improve the
SOC round off calculation so that 0 and 100 % can be shown when
it reaches the exact point.

Change-Id: I5bd9ebc8667a5beed9e1e97ff492aa1350f4d0f7
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent ebac0555
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -762,7 +762,19 @@ static int fg_get_msoc(struct fg_chip *chip, int *msoc)
	if (rc < 0)
		return rc;

	*msoc = DIV_ROUND_CLOSEST(*msoc * FULL_CAPACITY, FULL_SOC_RAW);
	/*
	 * To have better endpoints for 0 and 100, it is good to tune the
	 * calculation discarding values 0 and 255 while rounding off. Rest
	 * of the values 1-254 will be scaled to 1-99. DIV_ROUND_UP will not
	 * be suitable here as it rounds up any value higher than 252 to 100.
	 */
	if (*msoc == FULL_SOC_RAW)
		*msoc = 100;
	else if (*msoc == 0)
		*msoc = 0;
	else
		*msoc = DIV_ROUND_CLOSEST((*msoc - 1) * (FULL_CAPACITY - 2),
				FULL_SOC_RAW - 2) + 1;
	return 0;
}