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

Commit 041149db authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen4: add support to show high resolution of MSOC



Currently CAPACITY_RAW property shows the monotonic SOC read
from FG_BATT_SOC peripheral which is in the scale of 0-255. For
showing a higher resolution of monotonic SOC to the user, obtain
it from FG SRAM which is in the scale of 0-65535 and show it in
centi-percentage when "qcom,soc-hi-res" property is specified.
When the charger is removed, show CAPACITY_RAW simply as
CAPACITY multiplied by 100.

Change-Id: I01b81be1d0ad9020bb6f5d33afe1401dde289a12
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent f91711ab
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ struct fg_dt_props {
	bool	five_pin_battery;
	bool	multi_profile_load;
	bool	esr_calib_dischg;
	bool	soc_hi_res;
	int	cutoff_volt_mv;
	int	empty_volt_mv;
	int	cutoff_curr_ma;
@@ -851,6 +852,35 @@ static int fg_gen4_get_prop_capacity(struct fg_dev *fg, int *val)
	return 0;
}

static int fg_gen4_get_prop_capacity_raw(struct fg_gen4_chip *chip, int *val)
{
	struct fg_dev *fg = &chip->fg;
	int rc;

	if (!chip->dt.soc_hi_res) {
		rc = fg_get_msoc_raw(fg, val);
		return rc;
	}

	if (!is_input_present(fg)) {
		rc = fg_gen4_get_prop_capacity(fg, val);
		if (!rc)
			*val = *val * 100;
		return rc;
	}

	rc = fg_get_sram_prop(&chip->fg, FG_SRAM_MONOTONIC_SOC, val);
	if (rc < 0) {
		pr_err("Error in getting MONOTONIC_SOC, rc=%d\n", rc);
		return rc;
	}

	/* Show it in centi-percentage */
	*val = (*val * 10000) / 0xFFFF;

	return 0;
}

static inline void get_esr_meas_current(int curr_ma, u8 *val)
{
	switch (curr_ma) {
@@ -3556,7 +3586,7 @@ static int fg_psy_get_property(struct power_supply *psy,
		rc = fg_gen4_get_prop_capacity(fg, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_CAPACITY_RAW:
		rc = fg_get_msoc_raw(fg, &pval->intval);
		rc = fg_gen4_get_prop_capacity_raw(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_CC_SOC:
		rc = fg_get_sram_prop(&chip->fg, FG_SRAM_CC_SOC, &val);
@@ -4956,6 +4986,7 @@ static int fg_gen4_parse_dt(struct fg_gen4_chip *chip)
					"qcom,five-pin-battery");
	chip->dt.multi_profile_load = of_property_read_bool(node,
					"qcom,multi-profile-load");
	chip->dt.soc_hi_res = of_property_read_bool(node, "qcom,soc-hi-res");
	return 0;
}