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

Commit 86a5e176 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar
Browse files

power: qpnp-fg-gen3: Qualify aborting capacity learning



Currently, capacity learning algorithm is aborted when the
charging status goes to not charging. This can happen with qnovo
enabled charging where stopping the pulsing can lead to charging
status change. Qualify aborting capacity learning based on the
qnovo enable status and input presence.

While at it, abort the capacity learning when the charging status
goes to discharging and charger is removed.

Change-Id: I4546e8880be0658748157cb13f048610eee932a3
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent a17a69bb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -467,6 +467,7 @@ extern void dump_sram(u8 *buf, int addr, int len);
extern int64_t twos_compliment_extend(int64_t val, int s_bit_pos);
extern s64 fg_float_decode(u16 val);
extern bool is_input_present(struct fg_chip *chip);
extern bool is_qnovo_en(struct fg_chip *chip);
extern void fg_circ_buf_add(struct fg_circ_buf *buf, int val);
extern void fg_circ_buf_clr(struct fg_circ_buf *buf);
extern int fg_circ_buf_avg(struct fg_circ_buf *buf, int *avg);
+33 −8
Original line number Diff line number Diff line
@@ -106,14 +106,17 @@ static struct fg_dbgfs dbgfs_data = {
static bool is_usb_present(struct fg_chip *chip)
{
	union power_supply_propval pval = {0, };
	int rc;

	if (!chip->usb_psy)
		chip->usb_psy = power_supply_get_by_name("usb");

	if (chip->usb_psy)
		power_supply_get_property(chip->usb_psy,
	if (!chip->usb_psy)
		return false;

	rc = power_supply_get_property(chip->usb_psy,
			POWER_SUPPLY_PROP_PRESENT, &pval);
	else
	if (rc < 0)
		return false;

	return pval.intval != 0;
@@ -122,14 +125,17 @@ static bool is_usb_present(struct fg_chip *chip)
static bool is_dc_present(struct fg_chip *chip)
{
	union power_supply_propval pval = {0, };
	int rc;

	if (!chip->dc_psy)
		chip->dc_psy = power_supply_get_by_name("dc");

	if (chip->dc_psy)
		power_supply_get_property(chip->dc_psy,
	if (!chip->dc_psy)
		return false;

	rc = power_supply_get_property(chip->dc_psy,
			POWER_SUPPLY_PROP_PRESENT, &pval);
	else
	if (rc < 0)
		return false;

	return pval.intval != 0;
@@ -140,6 +146,25 @@ bool is_input_present(struct fg_chip *chip)
	return is_usb_present(chip) || is_dc_present(chip);
}

bool is_qnovo_en(struct fg_chip *chip)
{
	union power_supply_propval pval = {0, };
	int rc;

	if (!chip->batt_psy)
		chip->batt_psy = power_supply_get_by_name("battery");

	if (!chip->batt_psy)
		return false;

	rc = power_supply_get_property(chip->batt_psy,
			POWER_SUPPLY_PROP_CHARGE_QNOVO_ENABLE, &pval);
	if (rc < 0)
		return false;

	return pval.intval != 0;
}

#define EXPONENT_SHIFT		11
#define EXPONENT_OFFSET		-9
#define MANTISSA_SIGN_BIT	10
+25 −9
Original line number Diff line number Diff line
@@ -1402,6 +1402,7 @@ static int fg_cap_learning_done(struct fg_chip *chip)
static void fg_cap_learning_update(struct fg_chip *chip)
{
	int rc, batt_soc, batt_soc_msb;
	bool input_present = is_input_present(chip);

	mutex_lock(&chip->cl.lock);

@@ -1442,13 +1443,31 @@ static void fg_cap_learning_update(struct fg_chip *chip)
			chip->cl.init_cc_uah = 0;
		}

		if (chip->charge_status == POWER_SUPPLY_STATUS_DISCHARGING) {
			if (!input_present) {
				fg_dbg(chip, FG_CAP_LEARN, "Capacity learning aborted @ battery SOC %d\n",
					 batt_soc_msb);
				chip->cl.active = false;
				chip->cl.init_cc_uah = 0;
			}
		}

		if (chip->charge_status == POWER_SUPPLY_STATUS_NOT_CHARGING) {
			if (is_qnovo_en(chip) && input_present) {
				/*
				 * Don't abort the capacity learning when qnovo
				 * is enabled and input is present where the
				 * charging status can go to "not charging"
				 * intermittently.
				 */
			} else {
				fg_dbg(chip, FG_CAP_LEARN, "Capacity learning aborted @ battery SOC %d\n",
					batt_soc_msb);
				chip->cl.active = false;
				chip->cl.init_cc_uah = 0;
			}
		}
	}

out:
	mutex_unlock(&chip->cl.lock);
@@ -1981,7 +2000,7 @@ static int fg_esr_fcc_config(struct fg_chip *chip)
{
	union power_supply_propval prop = {0, };
	int rc;
	bool parallel_en = false, qnovo_en = false;
	bool parallel_en = false, qnovo_en;

	if (is_parallel_charger_available(chip)) {
		rc = power_supply_get_property(chip->parallel_psy,
@@ -1994,10 +2013,7 @@ static int fg_esr_fcc_config(struct fg_chip *chip)
		parallel_en = prop.intval;
	}

	rc = power_supply_get_property(chip->batt_psy,
			POWER_SUPPLY_PROP_CHARGE_QNOVO_ENABLE, &prop);
	if (!rc)
		qnovo_en = prop.intval;
	qnovo_en = is_qnovo_en(chip);

	fg_dbg(chip, FG_POWER_SUPPLY, "chg_sts: %d par_en: %d qnov_en: %d esr_fcc_ctrl_en: %d\n",
		chip->charge_status, parallel_en, qnovo_en,