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

Commit 499b30f7 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-smbcharger: support reading temperature and current



Currently, POWER_SUPPLY_PROP_TEMP and POWER_SUPPLY_PROP_CURRENT_NOW are
only exported by the bms power supply because they are provided by the
fuel gauge peripheral. However, android looks for temperature and
current under /sys/class/power_supply/battery/, which currently does not
support reading the temperature and current.

Fix this by exporting these properties in the battery power supply as
well, by making them read through to the bms power supply.

CRs-Fixed: 712920
Change-Id: I8832ae3ae5f0294efac08d7424e3a49233fa6a52
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 1ff026a2
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -448,6 +448,8 @@ static enum power_supply_property smbchg_battery_properties[] = {
	POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL,
	POWER_SUPPLY_PROP_FLASH_CURRENT_MAX,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
	POWER_SUPPLY_PROP_CURRENT_NOW,
	POWER_SUPPLY_PROP_TEMP,
};

#define CHGR_STS			0x0E
@@ -553,6 +555,40 @@ static int get_prop_batt_capacity(struct smbchg_chip *chip)
	return DEFAULT_BATT_CAPACITY;
}

#define DEFAULT_BATT_TEMP		200
static int get_prop_batt_temp(struct smbchg_chip *chip)
{
	union power_supply_propval ret = {0, };

	if (!chip->bms_psy && chip->bms_psy_name)
		chip->bms_psy =
			power_supply_get_by_name((char *)chip->bms_psy_name);
	if (chip->bms_psy) {
		chip->bms_psy->get_property(chip->bms_psy,
				POWER_SUPPLY_PROP_TEMP, &ret);
		return ret.intval;
	}

	return DEFAULT_BATT_TEMP;
}

#define DEFAULT_BATT_CURRENT_NOW	0
static int get_prop_batt_current_now(struct smbchg_chip *chip)
{
	union power_supply_propval ret = {0, };

	if (!chip->bms_psy && chip->bms_psy_name)
		chip->bms_psy =
			power_supply_get_by_name((char *)chip->bms_psy_name);
	if (chip->bms_psy) {
		chip->bms_psy->get_property(chip->bms_psy,
				POWER_SUPPLY_PROP_CURRENT_NOW, &ret);
		return ret.intval;
	}

	return DEFAULT_BATT_CURRENT_NOW;
}

static int get_prop_batt_health(struct smbchg_chip *chip)
{
	if (chip->batt_hot)
@@ -1568,6 +1604,12 @@ static int smbchg_battery_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CAPACITY:
		val->intval = get_prop_batt_capacity(chip);
		break;
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		val->intval = get_prop_batt_current_now(chip);
		break;
	case POWER_SUPPLY_PROP_TEMP:
		val->intval = get_prop_batt_temp(chip);
		break;
	case POWER_SUPPLY_PROP_HEALTH:
		val->intval = get_prop_batt_health(chip);
		break;