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

Commit 01e52384 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen4: Handle vbatt_low false positives



In certain scenarios, when FG is restarted after loading the
profile, vbatt_low interrupt can fire upon which vbatt_low flag
is set to indicate 0% SOC. vbatt_low flag once set should not be
cleared when vbatt_low condition goes away as that can cause
fluctuation in SOC being reported. To handle the false positives
of vbatt_low interrupt, don't set vbatt_low flag if the FG is
restarted as a part of profile loading within 10 seconds.

CRs-Fixed: 2445339
Change-Id: I12202b2fbca344381cac60b0bd0f5cba6c92a363
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 76b7b507
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -262,6 +262,7 @@ struct fg_gen4_chip {
	struct work_struct	pl_current_en_work;
	struct completion	mem_attn;
	struct mutex		soc_scale_lock;
	ktime_t			last_restart_time;
	char			batt_profile[PROFILE_LEN];
	enum slope_limit_status	slope_limit_sts;
	int			ki_coeff_full_soc[2];
@@ -2151,6 +2152,7 @@ static int qpnp_fg_gen4_load_profile(struct fg_gen4_chip *chip)
	}

	if (normal_profile_load) {
		chip->last_restart_time = ktime_get();
		rc = fg_restart(fg, SOC_READY_WAIT_TIME_MS);
		if (rc < 0) {
			pr_err("Error in restarting FG, rc=%d\n", rc);
@@ -3254,6 +3256,7 @@ static irqreturn_t fg_vbatt_low_irq_handler(int irq, void *data)
	struct fg_dev *fg = data;
	struct fg_gen4_chip *chip = container_of(fg, struct fg_gen4_chip, fg);
	int rc, vbatt_mv, msoc_raw;
	s64 time_us;

	rc = fg_get_battery_voltage(fg, &vbatt_mv);
	if (rc < 0)
@@ -3267,6 +3270,20 @@ static irqreturn_t fg_vbatt_low_irq_handler(int irq, void *data)
	fg_dbg(fg, FG_IRQ, "irq %d triggered vbatt_mv: %d msoc_raw:%d\n", irq,
		vbatt_mv, msoc_raw);

	if (!fg->soc_reporting_ready) {
		fg_dbg(fg, FG_IRQ, "SOC reporting is not ready\n");
		return IRQ_HANDLED;
	}

	if (chip->last_restart_time) {
		time_us = ktime_us_delta(ktime_get(), chip->last_restart_time);
		if (time_us < 10000000) {
			fg_dbg(fg, FG_IRQ, "FG restarted before %lld us\n",
				time_us);
			return IRQ_HANDLED;
		}
	}

	if (vbatt_mv < chip->dt.cutoff_volt_mv) {
		if (chip->dt.rapid_soc_dec_en) {
			/*