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

Commit c43182bb authored by Anirudh Ghayal's avatar Anirudh Ghayal
Browse files

power: qpnp-qg: Add support for batt-soc based SOC scaling (BASS)



At cold temperatures, when the load on battery suddenly drops
there is a possibility of monotonic-SOC being stuck for a long
time due to a rise in system SOC. This leads to a bad UX.

Fix this by gradually dropping the monotonic-SOC if the
battery-SOC has dropped by 1%, irrespective of the increase
in system SOC.

Change-Id: I5da1cf368d523768d0b267b314394612934a620e
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent 576ac265
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ struct qg_dt {
	bool			fvss_enable;
	bool			multi_profile_load;
	bool			tcss_enable;
	bool			bass_enable;
};

struct qg_esr_data {
@@ -138,6 +139,7 @@ struct qpnp_qg {
	bool			force_soc;
	bool			fvss_active;
	bool			tcss_active;
	bool			bass_active;
	int			charge_status;
	int			charge_type;
	int			chg_iterm_ma;
@@ -154,6 +156,7 @@ struct qpnp_qg {
	int			soc_tcss;
	int			tcss_entry_count;
	int			max_fcc_limit_ma;
	int			bsoc_bass_entry;
	u32			fifo_done_count;
	u32			wa_flags;
	u32			seq_no;
+51 −0
Original line number Diff line number Diff line
@@ -268,6 +268,52 @@ static int qg_process_tcss_soc(struct qpnp_qg *chip, int sys_soc)
	return sys_soc;
}

#define BASS_SYS_MSOC_DELTA			2
static int qg_process_bass_soc(struct qpnp_qg *chip, int sys_soc)
{
	int bass_soc = sys_soc, msoc = chip->msoc;
	int batt_soc = CAP(0, 100, DIV_ROUND_CLOSEST(chip->batt_soc, 100));

	if (!chip->dt.bass_enable)
		goto exit_soc_scale;

	qg_dbg(chip, QG_DEBUG_SOC, "BASS Entry: fifo_i=%d sys_soc=%d msoc=%d batt_soc=%d fvss_active=%d\n",
			chip->last_fifo_i_ua, sys_soc, msoc,
			batt_soc, chip->fvss_active);

	/* Skip BASS if FVSS is active */
	if (chip->fvss_active)
		goto exit_soc_scale;

	if (((sys_soc - msoc) < BASS_SYS_MSOC_DELTA) ||
				chip->last_fifo_i_ua <= 0)
		goto exit_soc_scale;

	if (!chip->bass_active) {
		chip->bass_active = true;
		chip->bsoc_bass_entry = batt_soc;
	}

	/* Drop the sys_soc by 1% if batt_soc has dropped */
	if ((chip->bsoc_bass_entry - batt_soc) >= 1) {
		bass_soc = (msoc > 0) ? msoc - 1 : 0;
		chip->bass_active = false;
	}

	qg_dbg(chip, QG_DEBUG_SOC, "BASS Exit: fifo_i_ua=%d sys_soc=%d msoc=%d bsoc_bass_entry=%d batt_soc=%d bass_soc=%d\n",
			chip->last_fifo_i_ua, sys_soc, msoc,
			chip->bsoc_bass_entry, chip->batt_soc, bass_soc);

	return bass_soc;

exit_soc_scale:
	chip->bass_active = false;
	qg_dbg(chip, QG_DEBUG_SOC, "BASS Quit: enabled=%d fifo_i_ua=%d sys_soc=%d msoc=%d batt_soc=%d\n",
			chip->dt.bass_enable, chip->last_fifo_i_ua,
			sys_soc, msoc, chip->batt_soc);
	return sys_soc;
}

int qg_adjust_sys_soc(struct qpnp_qg *chip)
{
	int soc, vbat_uv, rc;
@@ -275,6 +321,7 @@ int qg_adjust_sys_soc(struct qpnp_qg *chip)

	chip->sys_soc = CAP(QG_MIN_SOC, QG_MAX_SOC, chip->sys_soc);

	/* TCSS */
	chip->sys_soc = qg_process_tcss_soc(chip, chip->sys_soc);

	if (chip->sys_soc <= 50) { /* 0.5% */
@@ -299,8 +346,12 @@ int qg_adjust_sys_soc(struct qpnp_qg *chip)
	qg_dbg(chip, QG_DEBUG_SOC, "sys_soc=%d adjusted sys_soc=%d\n",
					chip->sys_soc, soc);

	/* FVSS */
	soc = qg_process_fvss_soc(chip, soc);

	/* BASS */
	soc = qg_process_bass_soc(chip, soc);

	chip->last_adj_ssoc = soc;

	return soc;
+2 −0
Original line number Diff line number Diff line
@@ -4280,6 +4280,8 @@ static int qg_parse_dt(struct qpnp_qg *chip)
			chip->dt.tcss_entry_soc = temp;
	}

	chip->dt.bass_enable = of_property_read_bool(node, "qcom,bass-enable");

	chip->dt.multi_profile_load = of_property_read_bool(node,
					"qcom,multi-profile-load");