From 10829a37d7c10896bd65597a4d0450a99bfd81d3 Mon Sep 17 00:00:00 2001 From: Anirudh Ghayal Date: Wed, 27 Jan 2021 11:16:34 +0530 Subject: [PATCH] power: smb5-lib: Improve the charge-termination WA handling In rare scenarios when the battery enters/exits JEITA conditions post termination, the termination workaround restarts thus resetting the reference values. Improve this handling by restarting the WA only if the existing WA timer is not running thus avoiding WA restarts across minor JEITA oscillations. Change-Id: I5bf91367b633abf79cbc60ef5bdf93cca9559022 Signed-off-by: Anirudh Ghayal --- drivers/power/supply/qcom/smb5-lib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/qcom/smb5-lib.c b/drivers/power/supply/qcom/smb5-lib.c index 799c0bf199c5..6ef8ca6f7bcd 100644 --- a/drivers/power/supply/qcom/smb5-lib.c +++ b/drivers/power/supply/qcom/smb5-lib.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "smb5-lib.h" #include "smb5-reg.h" #include "schgm-flash.h" @@ -5194,7 +5195,9 @@ static void smblib_eval_chg_termination(struct smb_charger *chg, u8 batt_status) * battery. Trigger the charge termination WA once charging is completed * to prevent overcharing. */ - if ((batt_status == TERMINATE_CHARGE) && (pval.intval == 100)) { + if ((batt_status == TERMINATE_CHARGE) && (pval.intval == 100) && + (ktime_to_ms(alarm_expires_remaining(/* alarm not pending */ + &chg->chg_termination_alarm)) <= 0)) { chg->cc_soc_ref = 0; chg->last_cc_soc = 0; chg->term_vbat_uv = 0;