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

Commit 90d259ed authored by Anirudh Ghayal's avatar Anirudh Ghayal Committed by Gerrit - the friendly Code Review server
Browse files

power: qpnp-qg: Report instantaneous-IBAT if averaged-IBAT is not ready



The averaged-IBAT holds the reset value 0x8000 (which corresponds to
5A/10A max supported QG current) if its read before the fist-ever fifo
is complete. In such a case report the instantaneous IBAT.

Change-Id: I65b3c93ad2cb54d82356907c809c70b0414036d1
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent b8e1fe0e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -450,6 +450,15 @@ int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua)
		return rc;
	}

	if (last_ibat == FIFO_I_RESET_VAL) {
		/* First FIFO is not complete, read instantaneous IBAT */
		rc = qg_get_battery_current(chip, ibat_ua);
		if (rc < 0)
			pr_err("Failed to read inst. IBAT rc=%d\n", rc);

		return rc;
	}

	last_ibat = sign_extend32(last_ibat, 15);
	*ibat_ua = qg_iraw_to_ua(chip, last_ibat);