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

Commit bbf9c0b8 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-fg: report zero soc immediately when empty



The empty soc interrupt is a voltage based interrupt that triggers
whenever the battery voltage is below a programmed threshold. This is
intended to be a last line of defense in case the soc count is
inaccurate.

In order to prevent UVLOs, immediately report zero soc whenever the empty
soc is raised.

CRs-Fixed: 756489
Change-Id: Ib3c8cc06efa1a834704fc166a393e9959ed01f0e
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent de4cd7bb
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -943,6 +943,27 @@ out:
	return rc;
}

#define SOC_EMPTY	BIT(3)
static bool fg_is_batt_empty(struct fg_chip *chip)
{
	u8 fg_soc_sts;
	int rc;

	rc = fg_read(chip, &fg_soc_sts,
				 INT_RT_STS(chip->soc_base), 1);
	if (rc) {
		pr_err("spmi read failed: addr=%03X, rc=%d\n",
				INT_RT_STS(chip->soc_base), rc);
		return false;
	}

	if (fg_debug_mask & FG_IRQS)
		pr_info("fg soc sts 0x%x\n", fg_soc_sts);

	return (fg_soc_sts & SOC_EMPTY) != 0;
}

#define EMPTY_CAPACITY		0
#define DEFAULT_CAPACITY	50
#define MISSING_CAPACITY	100
static int get_prop_capacity(struct fg_chip *chip)
@@ -954,7 +975,12 @@ static int get_prop_capacity(struct fg_chip *chip)
		return MISSING_CAPACITY;
	if (!chip->profile_loaded && !chip->use_otp_profile)
		return DEFAULT_CAPACITY;

	if (fg_is_batt_empty(chip)) {
		if (fg_debug_mask & FG_POWER_SUPPLY)
			pr_info_ratelimited("capacity: %d, EMPTY\n",
					EMPTY_CAPACITY);
		return EMPTY_CAPACITY;
	}
	while (tries < MAX_TRIES_SOC) {
		rc = fg_read(chip, cap,
				chip->soc_base + SOC_MONOTONIC_SOC, 2);