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

Commit e55a6aae authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy Committed by Harry Yang
Browse files

qpnp-fg-gen3: Show a fake SOC and voltage when battery is missing



During battery hotswap, a strong charger will be supplying enough
current to keep the device up and running. Currently, FG driver
shows up the monotonic SOC and voltage as-is (which is zero) to
the battery power supply and hence to the userspace.

Show a fake battery SOC (50%) and fake battery voltage (3.7 V)
when the battery is missing. If a strong charger is not present,
then the device will be powered down anyways.

Change-Id: Ia2c85d1e75bbf0c937a7e36e786362c473c7f7cd
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent de5d42f1
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -773,6 +773,7 @@ static bool is_debug_batt_id(struct fg_chip *chip)
#define FULL_CAPACITY	100
#define FULL_SOC_RAW	255
#define DEBUG_BATT_SOC	67
#define BATT_MISS_SOC	50
#define EMPTY_SOC	0
static int fg_get_prop_capacity(struct fg_chip *chip, int *val)
{
@@ -783,6 +784,16 @@ static int fg_get_prop_capacity(struct fg_chip *chip, int *val)
		return 0;
	}

	if (chip->fg_restarting) {
		*val = chip->last_soc;
		return 0;
	}

	if (chip->battery_missing) {
		*val = BATT_MISS_SOC;
		return 0;
	}

	if (is_batt_empty(chip)) {
		*val = EMPTY_SOC;
		return 0;
@@ -2494,12 +2505,12 @@ static int fg_psy_get_property(struct power_supply *psy,

	switch (psp) {
	case POWER_SUPPLY_PROP_CAPACITY:
		if (chip->fg_restarting)
			pval->intval = chip->last_soc;
		else
		rc = fg_get_prop_capacity(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
		if (chip->battery_missing)
			pval->intval = 3700000;
		else
			rc = fg_get_battery_voltage(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_CURRENT_NOW: