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

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

power: qpnp-charger: report full when charger is plugged in at 100 SoC



Previously, the full status was only reported by the battery power
supply after charging completes. However, when at end of charge and the
charger is taken out and plugged back in, charging does not begin
because the battery is technically still full. It is confusing for the
battery power supply to report discharging in this state.

Fix this issue by reporting full if the device is:
	1. not charging
	2. has a charger attached
	3. is at 100% battery

Change-Id: Ie8f8029627fe9173b051a90d0c96bbdcc5f17bc5
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent d2056c0d
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -768,7 +768,20 @@ static int get_battery_status(struct qpnp_bms_chip *chip)

static bool is_battery_charging(struct qpnp_bms_chip *chip)
{
	return get_battery_status(chip) == POWER_SUPPLY_STATUS_CHARGING;
	union power_supply_propval ret = {0,};

	if (chip->batt_psy == NULL)
		chip->batt_psy = power_supply_get_by_name("battery");
	if (chip->batt_psy) {
		/* if battery has been registered, use the status property */
		chip->batt_psy->get_property(chip->batt_psy,
					POWER_SUPPLY_PROP_CHARGE_TYPE, &ret);
		return ret.intval != POWER_SUPPLY_CHARGE_TYPE_NONE;
	}

	/* Default to false if the battery power supply is not registered. */
	pr_debug("battery power supply is not registered\n");
	return false;
}

static bool is_battery_full(struct qpnp_bms_chip *chip)
+26 −2
Original line number Diff line number Diff line
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -2007,6 +2007,24 @@ get_prop_charge_type(struct qpnp_chg_chip *chip)
	return POWER_SUPPLY_CHARGE_TYPE_NONE;
}

#define DEFAULT_CAPACITY	50
static int
get_batt_capacity(struct qpnp_chg_chip *chip)
{
	union power_supply_propval ret = {0,};

	if (chip->fake_battery_soc >= 0)
		return chip->fake_battery_soc;
	if (chip->use_default_batt_values || !get_prop_batt_present(chip))
		return DEFAULT_CAPACITY;
	if (chip->bms_psy) {
		chip->bms_psy->get_property(chip->bms_psy,
				POWER_SUPPLY_PROP_CAPACITY, &ret);
		return ret.intval;
	}
	return DEFAULT_CAPACITY;
}

static int
get_prop_batt_status(struct qpnp_chg_chip *chip)
{
@@ -2035,6 +2053,13 @@ get_prop_batt_status(struct qpnp_chg_chip *chip)
	if (chgr_sts & FAST_CHG_ON_IRQ && bat_if_sts & BAT_FET_ON_IRQ)
		return POWER_SUPPLY_STATUS_CHARGING;

	/* report full if state of charge is 100 and a charger is connected */
	if ((qpnp_chg_is_usb_chg_plugged_in(chip) ||
		qpnp_chg_is_dc_chg_plugged_in(chip))
			&& get_batt_capacity(chip) == 100) {
		return POWER_SUPPLY_STATUS_FULL;
	}

	return POWER_SUPPLY_STATUS_DISCHARGING;
}

@@ -2086,7 +2111,6 @@ get_prop_charge_full(struct qpnp_chg_chip *chip)
	return 0;
}

#define DEFAULT_CAPACITY	50
static int
get_prop_capacity(struct qpnp_chg_chip *chip)
{