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

Commit a7554195 authored by Kavya Nunna's avatar Kavya Nunna
Browse files

power: qpnp-qg: Add support to clear soh upon first profile load



When the battery profile is loaded first time, update the
clear soh property so that soh algorithm can clear stored
parameters.

Change-Id: Idfc25c589f8422b76768229e52dab7d670c6b231
Signed-off-by: default avatarKavya Nunna <knunna@codeaurora.org>
parent e8c7d22e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
 */

#ifndef __QG_CORE_H__
@@ -145,6 +145,7 @@ struct qpnp_qg {
	bool			fvss_active;
	bool			tcss_active;
	bool			bass_active;
	bool			first_profile_load;
	int			charge_status;
	int			charge_type;
	int			chg_iterm_ma;
+11 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
 */

#define pr_fmt(fmt)	"QG-K: %s: " fmt, __func__
@@ -2122,6 +2122,9 @@ static int qg_psy_set_property(struct power_supply *psy,
		if (chip->sp)
			soh_profile_update(chip->sp, chip->soh);
		break;
	case POWER_SUPPLY_PROP_CLEAR_SOH:
		chip->first_profile_load = pval->intval;
		break;
	case POWER_SUPPLY_PROP_ESR_ACTUAL:
		chip->esr_actual = pval->intval;
		break;
@@ -2254,6 +2257,9 @@ static int qg_psy_get_property(struct power_supply *psy,
	case POWER_SUPPLY_PROP_SOH:
		pval->intval = chip->soh;
		break;
	case POWER_SUPPLY_PROP_CLEAR_SOH:
		pval->intval = chip->first_profile_load;
		break;
	case POWER_SUPPLY_PROP_CC_SOC:
		rc = qg_get_cc_soc(chip, &pval->intval);
		break;
@@ -2296,6 +2302,7 @@ static int qg_property_is_writeable(struct power_supply *psy,
	case POWER_SUPPLY_PROP_SOH:
	case POWER_SUPPLY_PROP_FG_RESET:
	case POWER_SUPPLY_PROP_BATT_AGE_LEVEL:
	case POWER_SUPPLY_PROP_CLEAR_SOH:
		return 1;
	default:
		break;
@@ -2334,6 +2341,7 @@ static enum power_supply_property qg_psy_props[] = {
	POWER_SUPPLY_PROP_ESR_ACTUAL,
	POWER_SUPPLY_PROP_ESR_NOMINAL,
	POWER_SUPPLY_PROP_SOH,
	POWER_SUPPLY_PROP_CLEAR_SOH,
	POWER_SUPPLY_PROP_CC_SOC,
	POWER_SUPPLY_PROP_FG_RESET,
	POWER_SUPPLY_PROP_VOLTAGE_AVG,
@@ -3430,6 +3438,7 @@ static int qg_sanitize_sdam(struct qpnp_qg *chip)
		rc = qg_sdam_write(SDAM_MAGIC, SDAM_MAGIC_NUMBER);
		if (!rc)
			qg_dbg(chip, QG_DEBUG_PON, "First boot. SDAM initilized\n");
		chip->first_profile_load = true;
	} else {
		/* SDAM has invalid value */
		rc = qg_sdam_clear();
@@ -3437,6 +3446,7 @@ static int qg_sanitize_sdam(struct qpnp_qg *chip)
			pr_err("SDAM uninitialized, SDAM reset\n");
			rc = qg_sdam_write(SDAM_MAGIC, SDAM_MAGIC_NUMBER);
		}
		chip->first_profile_load = true;
	}

	if (rc < 0)