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

Commit 54dda8cf authored by Anirudh Ghayal's avatar Anirudh Ghayal
Browse files

power: qpnp-qg: Report average battery-current



Use the CURRENT_AVG power-supply property to report
average battery current.

Change-Id: I38c4dc78efde74ed790725fab7b0203c0be6a641
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent eb78e980
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
/* Copyright (c) 2018-2020 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
@@ -97,6 +97,7 @@
#define QG_POST_ESR_I_DATA0_REG			0x7E

#define QG_S2_NORMAL_AVG_V_DATA0_REG		0x80
#define QG_S2_NORMAL_AVG_I_DATA0_REG		0x82

#define QG_V_ACCUM_DATA0_RT_REG			0x88
#define QG_I_ACCUM_DATA0_RT_REG			0x8B
+19 −1
Original line number Diff line number Diff line
/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
/* Copyright (c) 2018-2020 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
@@ -444,3 +444,21 @@ int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv)

	return 0;
}

int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua)
{
	int rc = 0;
	int last_ibat = 0;

	rc = qg_read(chip, chip->qg_base + QG_S2_NORMAL_AVG_I_DATA0_REG,
				(u8 *)&last_ibat, 2);
	if (rc < 0) {
		pr_err("Failed to read S2_NORMAL_AVG_I reg, rc=%d\n", rc);
		return rc;
	}

	last_ibat = sign_extend32(last_ibat, 15);
	*ibat_ua = qg_iraw_to_ua(chip, last_ibat);

	return 0;
}
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
/* Copyright (c) 2018-2020 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
@@ -31,5 +31,6 @@ int qg_get_battery_current(struct qpnp_qg *chip, int *ibat_ua);
int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv);
int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv);
s64 qg_iraw_to_ua(struct qpnp_qg *chip, int iraw);
int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua);

#endif
+5 −1
Original line number Diff line number Diff line
/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
/* Copyright (c) 2018-2020 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
@@ -2163,6 +2163,9 @@ static int qg_psy_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_VOLTAGE_AVG:
		rc = qg_get_vbat_avg(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_CURRENT_AVG:
		rc = qg_get_ibat_avg(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_POWER_NOW:
		rc = qg_get_power(chip, &pval->intval, false);
		break;
@@ -2232,6 +2235,7 @@ static enum power_supply_property qg_psy_props[] = {
	POWER_SUPPLY_PROP_FG_RESET,
	POWER_SUPPLY_PROP_CC_SOC,
	POWER_SUPPLY_PROP_VOLTAGE_AVG,
	POWER_SUPPLY_PROP_CURRENT_AVG,
	POWER_SUPPLY_PROP_POWER_AVG,
	POWER_SUPPLY_PROP_POWER_NOW,
	POWER_SUPPLY_PROP_SCALE_MODE_EN,