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

Commit 78f1fa59 authored by Umang Agrawal's avatar Umang Agrawal
Browse files

power: vm-bms: Add charge_counter property



Add charge_counter property to vm-bms which is expressed
in terms of battery FCC and SOC so that the clients can
make use of it as needed.

CRs-Fixed: 2188284
Change-Id: I7bc732f8b9b4125f8d2ad4d5e3c8d9b50a27350e
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent d7b4ab26
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
/* Copyright (c) 2013-2015, 2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2015, 2017-2018, 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
@@ -206,6 +206,7 @@ static enum power_supply_property msm_batt_power_props[] = {
	POWER_SUPPLY_PROP_VOLTAGE_NOW,
	POWER_SUPPLY_PROP_CAPACITY,
	POWER_SUPPLY_PROP_CURRENT_NOW,
	POWER_SUPPLY_PROP_CHARGE_COUNTER,
	POWER_SUPPLY_PROP_TEMP,
	POWER_SUPPLY_PROP_COOL_TEMP,
	POWER_SUPPLY_PROP_WARM_TEMP,
@@ -1348,6 +1349,23 @@ static int get_prop_capacity(struct qpnp_lbc_chip *chip)
	return DEFAULT_CAPACITY;
}

static int get_prop_charge_count(struct qpnp_lbc_chip *chip)
{
	union power_supply_propval ret = {0,};

	if (!chip->bms_psy)
		chip->bms_psy = power_supply_get_by_name("bms");

	if (chip->bms_psy) {
		chip->bms_psy->get_property(chip->bms_psy,
				POWER_SUPPLY_PROP_CHARGE_COUNTER, &ret);
	} else {
		pr_debug("No BMS supply registered return 0\n");
	}

	return ret.intval;
}

#define DEFAULT_TEMP		250
static int get_prop_batt_temp(struct qpnp_lbc_chip *chip)
{
@@ -1719,6 +1737,9 @@ static int qpnp_batt_power_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		val->intval = get_prop_current_now(chip);
		break;
	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
		val->intval = get_prop_charge_count(chip);
		break;
	case POWER_SUPPLY_PROP_CHARGING_ENABLED:
		val->intval = !(chip->cfg_charging_disabled);
		break;
+29 −1
Original line number Diff line number Diff line
/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2016, 2018, 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
@@ -2203,6 +2203,30 @@ static int get_prop_bms_current_now(struct qpnp_bms_chip *chip)
	return chip->current_now;
}

static int get_current_cc(struct qpnp_bms_chip *chip)
{
	int soc, cc_full;
	int64_t current_charge;

	if (chip->batt_data == NULL)
		return -EINVAL;

	cc_full = chip->batt_data->fcc;
	if (chip->dt.cfg_use_voltage_soc)
		soc = chip->prev_voltage_based_soc;
	else
		soc = chip->last_soc;

	/*
	 * Full charge capacity is in mAh and soc is in %
	 * current_charge capacity is defined in uAh
	 * Hence conversion ((mAh * pct * 1000) / 100) => (mAh * pct * 10)
	 */
	current_charge = cc_full * soc * 10;

	return current_charge;
}

static enum power_supply_property bms_power_props[] = {
	POWER_SUPPLY_PROP_CAPACITY,
	POWER_SUPPLY_PROP_STATUS,
@@ -2216,6 +2240,7 @@ static enum power_supply_property bms_power_props[] = {
	POWER_SUPPLY_PROP_BATTERY_TYPE,
	POWER_SUPPLY_PROP_TEMP,
	POWER_SUPPLY_PROP_CYCLE_COUNT,
	POWER_SUPPLY_PROP_CHARGE_COUNTER,
};

static int
@@ -2294,6 +2319,9 @@ static int qpnp_vm_bms_power_get_property(struct power_supply *psy,
		else
			val->intval = -EINVAL;
		break;
	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
		val->intval = get_current_cc(chip);
		break;
	default:
		return -EINVAL;
	}