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

Commit 546d84cd authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-bms: improve the range of shutdown iavg



In previous revisions of the BMS peripheral, there were only 4 bits
to store the average current at shutdown. However, in the new BMS,
there are dedicated registers to store this information.

Make use of it by increasing the range and resolution of the shutdown
IAVG to 250mA + 10mA * X where X is the stored value. This will allow
for more accurate unusable charge calculations at boot time.

Change-Id: Ied413899cd05a33754c63cdc46010c941d6f083f
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent cb167fec
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -81,8 +81,7 @@

/* Configuration for saving of shutdown soc/iavg */
#define IGNORE_SOC_TEMP_DECIDEG		50
#define IAVG_STEP_SIZE_MA		50
#define IAVG_START			600
#define IAVG_STEP_SIZE_MA		10
#define IAVG_INVALID			0xFF
#define SOC_INVALID			0x7E

@@ -1639,8 +1638,8 @@ static void backup_soc_and_iavg(struct qpnp_bms_chip *chip, int batt_temp,
	int rc;
	int iavg_ma = chip->prev_uuc_iavg_ma;

	if (iavg_ma > IAVG_START)
		temp = (iavg_ma - IAVG_START) / IAVG_STEP_SIZE_MA;
	if (iavg_ma > MIN_IAVG_MA)
		temp = (iavg_ma - MIN_IAVG_MA) / IAVG_STEP_SIZE_MA;
	else
		temp = 0;

@@ -3330,17 +3329,17 @@ static int read_shutdown_iavg_ma(struct qpnp_bms_chip *chip)
	if (rc) {
		pr_err("failed to read addr = %d %d assuming %d\n",
				chip->base + IAVG_STORAGE_REG, rc,
				IAVG_START);
		return IAVG_START;
				MIN_IAVG_MA);
		return MIN_IAVG_MA;
	} else if (iavg == IAVG_INVALID) {
		pr_err("invalid iavg read from BMS1_DATA_REG_1, using %d\n",
				IAVG_START);
		return IAVG_START;
				MIN_IAVG_MA);
		return MIN_IAVG_MA;
	} else {
		if (iavg == 0)
			return IAVG_START;
			return MIN_IAVG_MA;
		else
			return IAVG_START + IAVG_STEP_SIZE_MA * (iavg + 1);
			return MIN_IAVG_MA + IAVG_STEP_SIZE_MA * iavg;
	}
}