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

Commit 2599a4cf authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen4: Publish ESR SOH parameters only once during charging



Currently, ESR parameters for SOH (State of Health) algorithm
is published only for 50% SOC (State of Charge). However, if
the delta MSOC interrupt fires frequently and MSOC is rounded
close to 50%, then it can be published more than once during
a charging cycle. Allow it only once so that we can have valid
parameters for SOH calculation.

Change-Id: I5c3a63b4f4670250cc8af5ec5a0c438e31f2fbca
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent bb702612
Loading
Loading
Loading
Loading
+49 −28
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ struct fg_gen4_chip {
	int			esr_actual;
	int			esr_nominal;
	int			soh;
	int			esr_soh_cycle_count;
	bool			first_profile_load;
	bool			ki_coeff_dischg_en;
	bool			slope_limit_en;
@@ -254,6 +255,7 @@ struct fg_gen4_chip {
	bool			esr_fast_cal_timer_expired;
	bool			esr_fast_calib_retry;
	bool			esr_fcc_ctrl_en;
	bool			esr_soh_notified;
	bool			rslow_low;
	bool			rapid_soc_dec_en;
	bool			vbatt_low;
@@ -1946,7 +1948,7 @@ static void get_batt_psy_props(struct fg_dev *fg)
static int fg_gen4_esr_soh_update(struct fg_dev *fg)
{
	struct fg_gen4_chip *chip = container_of(fg, struct fg_gen4_chip, fg);
	int rc, msoc, esr_uohms;
	int rc, msoc, esr_uohms, tmp;

	if (!fg->soc_reporting_ready || fg->battery_missing) {
		chip->esr_actual = -EINVAL;
@@ -1954,14 +1956,28 @@ static int fg_gen4_esr_soh_update(struct fg_dev *fg)
		return 0;
	}

	if (fg->charge_status == POWER_SUPPLY_STATUS_CHARGING) {
	rc = get_cycle_count(chip->counter, &tmp);
	if (rc < 0)
		pr_err("Couldn't get cycle count rc=%d\n", rc);
	else if (tmp != chip->esr_soh_cycle_count)
		chip->esr_soh_notified = false;

	if (fg->charge_status != POWER_SUPPLY_STATUS_CHARGING ||
			chip->esr_soh_notified)
		return 0;

	rc = fg_get_msoc(fg, &msoc);
	if (rc < 0) {
		pr_err("Error in getting msoc, rc=%d\n", rc);
		return rc;
	}

		if (msoc == ESR_SOH_SOC) {
	if (msoc != ESR_SOH_SOC) {
		fg_dbg(fg, FG_STATUS, "msoc: %d, not publishing ESR params\n",
			msoc);
		return 0;
	}

	rc = fg_get_sram_prop(fg, FG_SRAM_ESR_ACT, &esr_uohms);
	if (rc < 0) {
		pr_err("Error in getting esr_actual, rc=%d\n",
@@ -1984,8 +2000,12 @@ static int fg_gen4_esr_soh_update(struct fg_dev *fg)

	if (fg->batt_psy)
		power_supply_changed(fg->batt_psy);
		}
	}

	rc = get_cycle_count(chip->counter, &chip->esr_soh_cycle_count);
	if (rc < 0)
		pr_err("Couldn't get cycle count rc=%d\n", rc);

	chip->esr_soh_notified = true;

	return 0;
}
@@ -4690,6 +4710,7 @@ static int fg_gen4_probe(struct platform_device *pdev)
	fg->batt_id_ohms = -EINVAL;
	chip->ki_coeff_full_soc[0] = -EINVAL;
	chip->ki_coeff_full_soc[1] = -EINVAL;
	chip->esr_soh_cycle_count = -EINVAL;
	fg->regmap = dev_get_regmap(fg->dev->parent, NULL);
	if (!fg->regmap) {
		dev_err(fg->dev, "Parent regmap is unavailable\n");