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

Commit b1c9e917 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen3: apply SOC linearization based on user input



Currently, SOC linearization is done when SOC masking feature is
enabled to spread out the drop in SOC across a wider range and
for better user experience. Make this configurable through a DT
property "qcom,linearize-soc" so that the user can enable it as
and when required.

Change-Id: Ic9f5f04f4e872d7804152c17206a8b204de3a9c1
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 2f60027c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -271,6 +271,14 @@ First Level Node - FG Gen3 device
	Definition: A boolean property that when defined holds SOC at 100% when
		    the battery is full.

- qcom,linearize-soc
	Usage:      optional
	Value type: <empty>
	Definition: A boolean property that when defined linearizes SOC when
		    the SOC drops after charge termination monotonically to
		    improve the user experience. This is applicable only if
		    "qcom,hold-soc-while-full" is specified.

- qcom,ki-coeff-soc-dischg
	Usage:      optional
	Value type: <prop-encoded-array>
+1 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ enum ttf_mode {
struct fg_dt_props {
	bool	force_load_profile;
	bool	hold_soc_while_full;
	bool	linearize_soc;
	bool	auto_recharge_soc;
	int	cutoff_volt_mv;
	int	empty_volt_mv;
+26 −14
Original line number Diff line number Diff line
@@ -873,7 +873,7 @@ static int fg_get_prop_capacity(struct fg_chip *chip, int *val)
	if (rc < 0)
		return rc;

	if (chip->delta_soc > 0)
	if (chip->dt.linearize_soc && chip->delta_soc > 0)
		*val = chip->maint_soc;
	else
		*val = msoc;
@@ -1751,13 +1751,14 @@ static int fg_charge_full_update(struct fg_chip *chip)
			fg_dbg(chip, FG_STATUS, "Terminated charging @ SOC%d\n",
				msoc);
		}
	} else if (msoc_raw < recharge_soc && chip->charge_full) {
	} else if (msoc_raw <= recharge_soc && chip->charge_full) {
		if (chip->dt.linearize_soc) {
			chip->delta_soc = FULL_CAPACITY - msoc;

			/*
		 * We're spreading out the delta SOC over every 10% change
		 * in monotonic SOC. We cannot spread more than 9% in the
		 * range of 0-100 skipping the first 10%.
			 * We're spreading out the delta SOC over every 10%
			 * change in monotonic SOC. We cannot spread more than
			 * 9% in the range of 0-100 skipping the first 10%.
			 */
			if (chip->delta_soc > 9) {
				chip->delta_soc = 0;
@@ -1766,6 +1767,7 @@ static int fg_charge_full_update(struct fg_chip *chip)
				chip->maint_soc = FULL_CAPACITY;
				chip->last_msoc = msoc;
			}
		}

		chip->charge_full = false;

@@ -3204,6 +3206,9 @@ static int fg_update_maint_soc(struct fg_chip *chip)
{
	int rc = 0, msoc;

	if (!chip->dt.linearize_soc)
		return 0;

	mutex_lock(&chip->charge_full_lock);
	if (chip->delta_soc <= 0)
		goto out;
@@ -3432,6 +3437,9 @@ static int fg_psy_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CAPACITY:
		rc = fg_get_prop_capacity(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_CAPACITY_RAW:
		rc = fg_get_msoc_raw(chip, &pval->intval);
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
		if (chip->battery_missing)
			pval->intval = 3700000;
@@ -3697,6 +3705,7 @@ static int fg_notifier_cb(struct notifier_block *nb,

static enum power_supply_property fg_psy_props[] = {
	POWER_SUPPLY_PROP_CAPACITY,
	POWER_SUPPLY_PROP_CAPACITY_RAW,
	POWER_SUPPLY_PROP_TEMP,
	POWER_SUPPLY_PROP_COLD_TEMP,
	POWER_SUPPLY_PROP_COOL_TEMP,
@@ -4800,6 +4809,9 @@ static int fg_parse_dt(struct fg_chip *chip)
	chip->dt.hold_soc_while_full = of_property_read_bool(node,
					"qcom,hold-soc-while-full");

	chip->dt.linearize_soc = of_property_read_bool(node,
					"qcom,linearize-soc");

	rc = fg_parse_ki_coefficients(chip);
	if (rc < 0)
		pr_err("Error in parsing Ki coefficients, rc=%d\n", rc);