From 5bbd7c61d0c64818c8ad39d57ad71d81b3096c8a Mon Sep 17 00:00:00 2001 From: Kenny Kessler Date: Fri, 19 Oct 2018 15:53:10 -0500 Subject: [PATCH] power: qpnp-smbcharger-mmi: Fix Dual SOC Report The Dual battery design could lead to a filaure where it drops the SOC to a value of 0. This happens on error but also the math could have been wrong. Only allow a change in SOC if it is within +/-2% of the current reported SOC. Also still only update if it changes and bound check 0 and 100 as min and max. Change-Id: Ie049f9edcf62371b75f1e6def29b1742a9798a88 Signed-off-by: Kenny Kessler Reviewed-on: https://gerrit.mot.com/1258474 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Ryan Lattrel Reviewed-by: Kenneth Kessler Submit-Approved: Jira Key --- drivers/power/qpnp-smbcharger-mmi/qpnp-smbcharger-mmi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/power/qpnp-smbcharger-mmi/qpnp-smbcharger-mmi.c b/drivers/power/qpnp-smbcharger-mmi/qpnp-smbcharger-mmi.c index 81d27aefe930..afe1365bb6e0 100755 --- a/drivers/power/qpnp-smbcharger-mmi/qpnp-smbcharger-mmi.c +++ b/drivers/power/qpnp-smbcharger-mmi/qpnp-smbcharger-mmi.c @@ -2033,6 +2033,7 @@ static int factory_kill_disable; module_param(factory_kill_disable, int, 0644); #define TWO_VOLT 2000000 #define SMBCHG_HEARTBEAT_INTERVAL_NS 70000000000 +#define MONOTONIC_SOC 2 /* 2 percent */ static void mmi_heartbeat_work(struct work_struct *work) { struct smb_mmi_charger *chip = container_of(work, @@ -2165,7 +2166,11 @@ static void mmi_heartbeat_work(struct work_struct *work) else batt_cap = pval.intval; - if (batt_cap != report_cap) { + if ((report_cap != batt_cap) && + (report_cap <= (batt_cap + MONOTONIC_SOC)) && + (report_cap >= (batt_cap - MONOTONIC_SOC)) && + !(report_cap < 0) && + !(report_cap > 100)) { pr_info("SMBMMI: Updating Reported Capacity to %d\n", report_cap); pval.intval = report_cap;