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

Commit 24b7273e authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: fg-alg: Show last TTF while clearing Ibatt samples



Currently, when the battery current (Ibatt) changes by more than
500 mA, TTF algorithm clears Ibatt samples so that Ibatt average
can be obtained with fresh set of samples. This was done to
improve TTF accuracy. However, while doing it TTF shown to the
user is shown as -1 because collecting Ibatt samples would take
few seconds. Fix this by showing last TTF to the user when Ibatt
samples are cleared until new set of Ibatt samples are obtained.

Change-Id: Ifba1d399f38893dd544be2369f600a7400530e64
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 13f67f99
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -982,6 +982,9 @@ static int get_time_to_full_locked(struct ttf *ttf, int *val)

	/* at least 10 samples are required to produce a stable IBATT */
	if (ttf->ibatt.size < MAX_TTF_SAMPLES) {
		if (ttf->clear_ibatt)
			*val = ttf->last_ttf;
		else
			*val = -1;
		return 0;
	}
@@ -998,6 +1001,7 @@ static int get_time_to_full_locked(struct ttf *ttf, int *val)
		return rc;
	}

	ttf->clear_ibatt = false;
	ibatt_avg = -ibatt_avg / MILLI_UNIT;
	vbatt_avg /= MILLI_UNIT;

@@ -1303,6 +1307,7 @@ static void ttf_work(struct work_struct *work)
			pr_debug("Clear Ibatt buffer, Ibatt_avg=%d Ibatt_now=%d\n",
					ibatt_avg, ibatt_now);
			ttf_circ_buf_clr(&ttf->ibatt);
			ttf->clear_ibatt = true;
		}

		rc = get_time_to_full_locked(ttf, &ttf_now);
@@ -1312,7 +1317,7 @@ static void ttf_work(struct work_struct *work)
		}

		/* keep the wake lock and prime the IBATT and VBATT buffers */
		if (ttf_now < 0) {
		if (ttf_now < 0 || ttf->clear_ibatt) {
			/* delay for one FG cycle */
			schedule_delayed_work(&ttf->ttf_work,
					msecs_to_jiffies(1000));
+1 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ struct ttf {
	struct range_data	*step_chg_cfg;
	bool			step_chg_cfg_valid;
	bool			ocv_step_chg_cfg_valid;
	bool			clear_ibatt;
	int			step_chg_num_params;
	int			mode;
	int			last_ttf;