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

Commit 0b54c38b authored by Anirudh Ghayal's avatar Anirudh Ghayal Committed by Umang Agrawal
Browse files

power: qpnp-qg: Report averaged VBAT



Report the last FIFO's VBAT for usecases which
need an averaged VBAT instead of instantaneous.

Change-Id: Idf4ca48a06c012ed52ea06b187ee12ab8cfe12d3
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent 0875fed5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@
#define QG_POST_ESR_V_DATA0_REG			0x7C
#define QG_POST_ESR_I_DATA0_REG			0x7E

#define QG_S2_NORMAL_AVG_V_DATA0_REG		0x80

#define QG_V_ACCUM_DATA0_RT_REG			0x88
#define QG_I_ACCUM_DATA0_RT_REG			0x8B
#define QG_ACCUM_CNT_RT_REG			0x8E
+17 −0
Original line number Diff line number Diff line
@@ -420,3 +420,20 @@ int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv)

	return rc;
}

int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv)
{
	int rc = 0;
	u64 last_vbat = 0;

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

	*vbat_uv = V_RAW_TO_UV(last_vbat);

	return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ int qg_write_monotonic_soc(struct qpnp_qg *chip, int msoc);
int qg_get_battery_temp(struct qpnp_qg *chip, int *batt_temp);
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);

#endif
+4 −0
Original line number Diff line number Diff line
@@ -1905,6 +1905,9 @@ static int qg_psy_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CC_SOC:
		rc = qg_get_cc_soc(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_AVG:
		rc = qg_get_vbat_avg(chip, &pval->intval);
		break;
	default:
		pr_debug("Unsupported property %d\n", psp);
		break;
@@ -1958,6 +1961,7 @@ static enum power_supply_property qg_psy_props[] = {
	POWER_SUPPLY_PROP_SOH,
	POWER_SUPPLY_PROP_CC_SOC,
	POWER_SUPPLY_PROP_FG_RESET,
	POWER_SUPPLY_PROP_VOLTAGE_AVG,
};

static const struct power_supply_desc qg_psy_desc = {