diff mbox series

[10/15] power: supply: cpcap-battery: Improve full status reporting

Message ID 20200315151206.30909-10-spinal.by@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series [01/15] power: supply: cpcap-battery: Fix battery full status reporting | expand

Commit Message

Arthur D. March 15, 2020, 3:12 p.m. UTC
Use average current when detecting the fully charged state

Signed-off-by: Arthur Demchenkov <spinal.by@gmail.com>
---
 drivers/power/supply/cpcap-battery.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index da6138df2117..6205a5e43a32 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -407,12 +407,16 @@  static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata)
 	struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata);
 	static bool is_full;
 
-	if (state->voltage >=
-	    (ddata->config.bat.constant_charge_voltage_max_uv - 18000) &&
-	    state->current_ua > (is_full ? -150000 : -100000))
-		is_full = true;
-	else
+	if (state->voltage <
+	    (ddata->config.bat.constant_charge_voltage_max_uv - 18000)) {
 		is_full = false;
+	} else if (is_full) {
+		if (state->current_ua < -150000)
+			is_full = false;
+	} else if (state->current_ua >= -150000 &&
+		   cpcap_battery_cc_get_avg_current(ddata) >= -100000) {
+		is_full = true;
+	}
 
 	return is_full;
 }