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

Commit a2f72174 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-bms: fix boot time iavg calculation algorithm



A bug was introduced in the unusable charge calculation algorithm
when the shutdown SoC and IAVG was refactored. Since the BMS driver
will try to do a SoC calculation before the shutdown data was loaded,
the shutdown IAVG never gets used to populate the IAVG sample array.
This causes the shutdown IAVG to never get used by the BMS driver,
creating a situation where the high boot time current fills the IAVG
samples array and skewing UUC to be much higher than it should be.

Fix this by moving the first time calculation flag for UUC to the end
of the SoC calculation function so that only the first real SoC
calculation after shutdown data is loaded clears the flag. Also,
add a delta time check in the UUC iavg sample array aggregation so
that recalculating SoC many times will not incorrectly skew the IAVG
and cause a incorrectly high UUC.

Change-Id: Ida355c64e60167e0a11dcbb587585273924c9da1
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 546d84cd
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -1264,7 +1264,6 @@ static int adjust_uuc(struct qpnp_bms_chip *chip,
}

#define MIN_IAVG_MA 250
#define MIN_SECONDS_FOR_VALID_SAMPLE	20
static int calculate_unusable_charge_uah(struct qpnp_bms_chip *chip,
					struct soc_params *params,
					int batt_temp)
@@ -1288,6 +1287,7 @@ static int calculate_unusable_charge_uah(struct qpnp_bms_chip *chip,
		chip->iavg_num_samples = IAVG_SAMPLES;
	}

	if (params->delta_time_s >= IAVG_MINIMAL_TIME) {
		/*
		* if charging use a nominal avg current to keep
		* a reasonable UUC while charging
@@ -1299,6 +1299,7 @@ static int calculate_unusable_charge_uah(struct qpnp_bms_chip *chip,
		chip->iavg_num_samples++;
		if (chip->iavg_num_samples >= IAVG_SAMPLES)
			chip->iavg_num_samples = IAVG_SAMPLES;
	}

	/* now that this sample is added calcualte the average */
	uuc_iavg_ma = 0;
@@ -1329,7 +1330,6 @@ static int calculate_unusable_charge_uah(struct qpnp_bms_chip *chip,
	uuc_uah_iavg = adjust_uuc(chip, params, pc_unusable,
					uuc_uah_iavg, batt_temp);

	chip->first_time_calc_uuc = 0;
	return uuc_uah_iavg;
}

@@ -2361,6 +2361,7 @@ done_calculating:

	get_current_time(&chip->last_recalc_time);
	chip->first_time_calc_soc = 0;
	chip->first_time_calc_uuc = 0;
	return chip->calculated_soc;
}