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

Commit 1957015d authored by Xiaozhe Shi's avatar Xiaozhe Shi Committed by Abhijeet Dharmapurikar
Browse files

power: qpnp-smbcharger: reschedule vfloat work upon failure



Currently in the vfloat adjustment workqueue, if a bad sample is read,
the vfloat adjustment work simply tries to poll the fuel gauge again
immediately. This can cause an issue where the SRAM is not updated if
the mem access is already held and the update_now flag is set too
many times in succession.

Also, even if the update_now does release mem access, it should not be
used continuously in rapid succession. Saturating the fuel gauge cycle
with SRAM accesses stretches the fuel gauge cycle. This can cause
problems in fuel gauge accuracy.

Fix these issues by rescheduling the vfloat adjustment work 10 seconds
later whenever a bad sample is read, instead of redoing the fuel gauge
read immediately.

CRs-Fixed: 816594
Change-Id: I765dbbd93e6385ff31ebb32eb937591c7a3b0dfb
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent e6e4152a
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -3821,6 +3821,7 @@ static int smbchg_adjust_vfloat_mv_trim(struct smbchg_chip *chip,
	return rc;
}

#define VFLOAT_RESAMPLE_DELAY_MS	10000
static void smbchg_vfloat_adjust_work(struct work_struct *work)
{
	struct smbchg_chip *chip = container_of(work,
@@ -3829,7 +3830,6 @@ static void smbchg_vfloat_adjust_work(struct work_struct *work)
	int vbat_uv, vbat_mv, ibat_ua, rc, delta_vfloat_mv;
	bool taper, enable;

start:
	taper = (get_prop_charge_type(chip)
		== POWER_SUPPLY_CHARGE_TYPE_TAPER);
	enable = taper && (chip->parallel.current_max_ma == 0);
@@ -3853,7 +3853,7 @@ start:

	if ((vbat_mv - chip->vfloat_mv) < -1 * vf_adjust_max_delta_mv) {
		pr_smb(PR_STATUS, "Skip vbat out of range: %d\n", vbat_mv);
		goto start;
		goto reschedule;
	}

	rc = get_property_from_fg(chip,
@@ -3866,7 +3866,7 @@ start:

	if (ibat_ua / 1000 > -chip->iterm_ma) {
		pr_smb(PR_STATUS, "Skip ibat too high: %d\n", ibat_ua);
		goto start;
		goto reschedule;
	}

	pr_smb(PR_STATUS, "sample number = %d vbat_mv = %d ibat_ua = %d\n",
@@ -3879,7 +3879,7 @@ start:
	if (chip->n_vbat_samples < vf_adjust_n_samples) {
		pr_smb(PR_STATUS, "Skip %d samples; max = %d\n",
			chip->n_vbat_samples, chip->max_vbat_sample);
		goto start;
		goto reschedule;
	}
	/* if max vbat > target vfloat, delta_vfloat_mv could be negative */
	delta_vfloat_mv = chip->vfloat_mv - chip->max_vbat_sample;
@@ -3900,7 +3900,7 @@ start:
		}
		chip->max_vbat_sample = 0;
		chip->n_vbat_samples = 0;
		goto start;
		goto reschedule;
	}

stop:
@@ -3908,6 +3908,11 @@ stop:
	chip->n_vbat_samples = 0;
	smbchg_relax(chip, PM_REASON_VFLOAT_ADJUST);
	return;

reschedule:
	schedule_delayed_work(&chip->vfloat_adjust_work,
			msecs_to_jiffies(VFLOAT_RESAMPLE_DELAY_MS));
	return;
}

static int smbchg_charging_status_change(struct smbchg_chip *chip)