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

Commit 48e145a9 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-bms: use consistent IAVG for raw SOC calculation



Currently the BMS uses the instantaneous current for the raw SOC
calculation. However, this current can be very high because of the boot
tiime power draw. This can bias the UUC to unreasonably levels (100% of
the battery when at cold temperatures) and cause the saved shutdown SOC
to be needlessly discarded.

Use the more realistic IAVG of 250 mA when doing this initial raw SOC
calculation as well in other places where iavg is being reset to avoid
skewing the results. Also, do not save the percent UUC when doing the raw
SOC calculation. Rather, use the loaded shutdown IAVG if there is one.

Change-Id: I426b824a50568b01bae442a3154e7c68c42409f8
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 76f88c58
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -904,6 +904,7 @@ static int estimate_ocv(struct qpnp_bms_chip *chip)
	return ocv_est_uv;
}

#define MIN_IAVG_MA 250
static void reset_for_new_battery(struct qpnp_bms_chip *chip, int batt_temp)
{
	chip->last_ocv_uv = chip->insertion_ocv_uv;
@@ -914,7 +915,7 @@ static void reset_for_new_battery(struct qpnp_bms_chip *chip, int batt_temp)
	chip->soc_at_cv = -EINVAL;
	chip->shutdown_soc_invalid = true;
	chip->shutdown_soc = 0;
	chip->shutdown_iavg_ma = 0;
	chip->shutdown_iavg_ma = MIN_IAVG_MA;
	chip->prev_pc_unusable = -EINVAL;
	reset_cc(chip, CLEAR_CC | CLEAR_SHDW_CC);
	chip->software_cc_uah = 0;
@@ -1295,7 +1296,7 @@ static int adjust_uuc(struct qpnp_bms_chip *chip,
	max_percent_change = max(params->delta_time_s
				/ TIME_PER_PERCENT_UUC, 1);

	if (chip->prev_pc_unusable == -EINVAL
	if (chip->first_time_calc_uuc || chip->prev_pc_unusable == -EINVAL
		|| abs(chip->prev_pc_unusable - new_pc_unusable)
			<= max_percent_change) {
		chip->prev_pc_unusable = new_pc_unusable;
@@ -1328,7 +1329,6 @@ static int adjust_uuc(struct qpnp_bms_chip *chip,
	return new_uuc_uah;
}

#define MIN_IAVG_MA 250
static int calculate_unusable_charge_uah(struct qpnp_bms_chip *chip,
					struct soc_params *params,
					int batt_temp)
@@ -3496,6 +3496,7 @@ static void load_shutdown_data(struct qpnp_bms_chip *chip)
	 * Do a quick run of SoC calculation to find whether the shutdown soc
	 * is close enough.
	 */
	chip->shutdown_iavg_ma = MIN_IAVG_MA;
	calculated_soc = recalculate_raw_soc(chip);
	shutdown_soc_out_of_limit = (abs(shutdown_soc - calculated_soc)
			> chip->shutdown_soc_valid_limit);