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

Commit 7472d046 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen4: Reset ESR_{DIS}CHG_DELTA during SOH profile loading



When the profile is loaded as a result of SOH change, reset
ESR_CHG_DELTA and ESR_DISCHG_DELTA values configured during ESR
fast calibration. This is needed to improve SOH calculations.

Change-Id: I405607db04da595f60d10e15d8bb5a8736ea5d80
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 745d6792
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ struct fg_gen4_chip {
	struct work_struct	pl_current_en_work;
	struct completion	mem_attn;
	struct mutex		soc_scale_lock;
	struct mutex		esr_calib_lock;
	ktime_t			last_restart_time;
	char			batt_profile[PROFILE_LEN];
	enum slope_limit_status	slope_limit_sts;
@@ -2360,7 +2361,31 @@ static void fg_gen4_post_profile_load(struct fg_gen4_chip *chip)
{
	struct fg_dev *fg = &chip->fg;
	int rc, act_cap_mah;
	u8 buf[16];
	u8 buf[16] = {0};

	if (chip->dt.multi_profile_load &&
		chip->batt_age_level != chip->last_batt_age_level) {

		/* Keep ESR fast calib config disabled */
		fg_gen4_esr_fast_calib_config(chip, false);
		chip->esr_fast_calib = false;

		mutex_lock(&chip->esr_calib_lock);

		rc = fg_sram_write(fg, ESR_DELTA_DISCHG_WORD,
				ESR_DELTA_DISCHG_OFFSET, buf, 2,
				FG_IMA_DEFAULT);
		if (rc < 0)
			pr_err("Error in writing ESR_DELTA_DISCHG, rc=%d\n",
				rc);

		rc = fg_sram_write(fg, ESR_DELTA_CHG_WORD, ESR_DELTA_CHG_OFFSET,
				buf, 2, FG_IMA_DEFAULT);
		if (rc < 0)
			pr_err("Error in writing ESR_DELTA_CHG, rc=%d\n", rc);

		mutex_unlock(&chip->esr_calib_lock);
	}

	/* If SDAM cookie is not set, read back from SRAM and load it in SDAM */
	if (chip->fg_nvmem && !is_sdam_cookie_set(chip)) {
@@ -3858,6 +3883,8 @@ static void esr_calib_work(struct work_struct *work)
	s16 esr_raw, esr_char_raw, esr_delta, esr_meas_diff, esr_filtered;
	u8 buf[2];

	mutex_lock(&chip->esr_calib_lock);

	if (chip->delta_esr_count > chip->dt.delta_esr_disable_count ||
		chip->esr_fast_calib_done) {
		fg_dbg(fg, FG_STATUS, "delta_esr_count: %d esr_fast_calib_done:%d\n",
@@ -3954,6 +3981,7 @@ static void esr_calib_work(struct work_struct *work)
	chip->delta_esr_count++;
	fg_dbg(fg, FG_STATUS, "Wrote ESR delta [0x%x 0x%x]\n", buf[0], buf[1]);
out:
	mutex_unlock(&chip->esr_calib_lock);
	vote(fg->awake_votable, ESR_CALIB, false, 0);
}

@@ -6101,6 +6129,7 @@ static int fg_gen4_probe(struct platform_device *pdev)
	mutex_init(&fg->sram_rw_lock);
	mutex_init(&fg->charge_full_lock);
	mutex_init(&chip->soc_scale_lock);
	mutex_init(&chip->esr_calib_lock);
	init_completion(&fg->soc_update);
	init_completion(&fg->soc_ready);
	init_completion(&chip->mem_attn);