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

Commit 9314c652 authored by Anirudh Ghayal's avatar Anirudh Ghayal
Browse files

power: smblite/smb5-lib.c: Report the correct battery status at SOC=0



Userspace initiates a shutdown if battery_status != charging
and SOC = 0, this is to prevent a deep-discharge of the battery
when the discharge current is higher than the charge current
at SOC = 0. Report this status from the kernel driver.

Change-Id: If7dd806e6427b65427d5999bb9ccda7098ec6101
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent fb2b7441
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -1963,13 +1963,14 @@ static bool is_charging_paused(struct smb_charger *chg)
	return val & CHARGING_PAUSE_CMD_BIT;
}

#define CUTOFF_COUNT		3
int smblib_get_prop_batt_status(struct smb_charger *chg,
				union power_supply_propval *val)
{
	union power_supply_propval pval = {0, };
	bool usb_online, dc_online;
	u8 stat;
	int rc, suspend = 0;
	int rc, suspend = 0, input_present = 0;

	if (chg->fake_chg_status_on_debug_batt) {
		rc = smblib_get_prop_from_bms(chg,
@@ -1999,6 +2000,28 @@ int smblib_get_prop_batt_status(struct smb_charger *chg,
		return 0;
	}

	/*
	 * If SOC = 0 and we are discharging with input connected, report
	 * the battery status as DISCHARGING.
	 */
	smblib_is_input_present(chg, &input_present);
	rc = smblib_get_prop_from_bms(chg, POWER_SUPPLY_PROP_CAPACITY, &pval);
	if (!rc && pval.intval == 0 && input_present) {
		rc = smblib_get_prop_from_bms(chg,
				POWER_SUPPLY_PROP_CURRENT_NOW, &pval);
		if (!rc && pval.intval > 0) {
			if (chg->cutoff_count > CUTOFF_COUNT) {
				val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
				return 0;
			}
			chg->cutoff_count++;
		} else {
			chg->cutoff_count = 0;
		}
	} else {
		chg->cutoff_count = 0;
	}

	if (chg->dbc_usbov) {
		rc = smblib_get_prop_usb_present(chg, &pval);
		if (rc < 0) {
+1 −0
Original line number Diff line number Diff line
@@ -574,6 +574,7 @@ struct smb_charger {
	int			init_thermal_ua;
	u32			comp_clamp_level;
	int			wls_icl_ua;
	int			cutoff_count;
	bool			dcin_aicl_done;
	bool			hvdcp3_standalone_config;
	bool			dcin_icl_user_set;
+25 −1
Original line number Diff line number Diff line
@@ -720,13 +720,14 @@ static bool is_charging_paused(struct smb_charger *chg)
	return val & CHARGING_PAUSE_CMD_BIT;
}

#define CUTOFF_COUNT		3
int smblite_lib_get_prop_batt_status(struct smb_charger *chg,
				union power_supply_propval *val)
{
	union power_supply_propval pval = {0, };
	bool usb_online;
	u8 stat;
	int rc;
	int rc, input_present = 0;

	if (chg->fake_chg_status_on_debug_batt) {
		rc = smblite_lib_get_prop_from_bms(chg,
@@ -740,6 +741,29 @@ int smblite_lib_get_prop_batt_status(struct smb_charger *chg,
		}
	}

	/*
	 * If SOC = 0 and we are discharging with input connected, report
	 * the battery status as DISCHARGING.
	 */
	smblite_lib_is_input_present(chg, &input_present);
	rc = smblite_lib_get_prop_from_bms(chg,
				POWER_SUPPLY_PROP_CAPACITY, &pval);
	if (!rc && pval.intval == 0 && input_present) {
		rc = smblite_lib_get_prop_from_bms(chg,
				POWER_SUPPLY_PROP_CURRENT_NOW, &pval);
		if (!rc && pval.intval > 0) {
			if (chg->cutoff_count > CUTOFF_COUNT) {
				val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
				return 0;
			}
			chg->cutoff_count++;
		} else {
			chg->cutoff_count = 0;
		}
	} else {
		chg->cutoff_count = 0;
	}

	rc = smblite_lib_get_prop_usb_online(chg, &pval);
	if (rc < 0) {
		smblite_lib_err(chg, "Couldn't get usb online property rc=%d\n",
+1 −0
Original line number Diff line number Diff line
@@ -310,6 +310,7 @@ struct smb_charger {
	int			jeita_soft_fv[2];
	int			aicl_5v_threshold_mv;
	int			default_aicl_5v_threshold_mv;
	int			cutoff_count;
	bool			aicl_max_reached;
	bool			pr_swap_in_progress;
	bool			ldo_mode;