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

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

power: qpnp-charger: do not report full when battery is warm/cool



When the battery is cool or warm, JEITA compliance demands that the
charging voltage of the battery is lowered. Since the max voltage is
lowered, it follows that the battery is not necessarily full. The
current charger driver reports full charge regardless of JEITA
conditions. This indirectly causes an issue with BMS reporting of SoC
because the BMS assumes that if the battery is full, it is at 100%
charge.

Fix this issue by adding a battery temperature condition check before
setting the charge done flag. Also, since the BMS will no longer
guarantee a 100% report after end of charge, add another check to the
SoC based resume function in order to avoid false resume of charges.

Change-Id: I2b356bb42b5289d135b87cbc11a5d3309ad5a0df
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 05ea1f9e
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -1276,6 +1276,21 @@ qpnp_chg_vddmax_and_trim_set(struct qpnp_chg_chip *chip,
	return 0;
}

static int
qpnp_chg_vddmax_get(struct qpnp_chg_chip *chip)
{
	int rc;
	u8 vddmax = 0;

	rc = qpnp_chg_read(chip, &vddmax, chip->chgr_base + CHGR_VDD_MAX, 1);
	if (rc) {
		pr_err("Failed to write vddmax: %d\n", rc);
		return rc;
	}

	return QPNP_CHG_V_MIN_MV + (int)vddmax * QPNP_CHG_V_STEP_MV;
}

/* JEITA compliance logic */
static void
qpnp_chg_set_appropriate_vddmax(struct qpnp_chg_chip *chip)
@@ -2064,6 +2079,8 @@ get_prop_capacity(struct qpnp_chg_chip *chip)
		if (battery_status != POWER_SUPPLY_STATUS_CHARGING
				&& bms_status != POWER_SUPPLY_STATUS_CHARGING
				&& charger_in
				&& !chip->bat_is_cool
				&& !chip->bat_is_warm
				&& !chip->resuming_charging
				&& !chip->charging_disabled
				&& chip->soc_resume_limit
@@ -3060,10 +3077,17 @@ qpnp_eoc_work(struct work_struct *work)
			count = 0;
		} else {
			if (count == CONSECUTIVE_COUNT) {
				if (!chip->bat_is_cool && !chip->bat_is_warm) {
					pr_info("End of Charging\n");
					chip->chg_done = true;
				} else {
					pr_info("stop charging: battery is %s, vddmax = %d reached\n",
						chip->bat_is_cool
							? "cool" : "warm",
						qpnp_chg_vddmax_get(chip));
				}
				chip->delta_vddmax_mv = 0;
				qpnp_chg_set_appropriate_vddmax(chip);
				chip->chg_done = true;
				qpnp_chg_charge_en(chip, 0);
				/* sleep for a second before enabling */
				msleep(2000);