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

Commit d5820b0a authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

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

parents 8f0dfbf3 286d5160
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;
}