[02/15] power: supply: cpcap-battery: Improve battery full status detection

Message ID 20200315151206.30909-2-spinal.by@gmail.com
State New
Headers show
Series
  • Untitled series #38499
Related show

Commit Message

Arthur Demchenkov March 15, 2020, 3:11 p.m.
If the battery status is detected as full for the charging current that
doesn't exceed 100 mA, it will then be reported as full for charging
currents in the range of 100-150 mA. This is needed because
charge_current value has a spread.

We don't use avg_current here because it can trigger wrong battery full
status on charger connected event.

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

Patch

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 34a9dbcd1a23..52f03a2662a5 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -406,13 +406,16 @@  static int cpcap_battery_cc_get_avg_current(struct cpcap_battery_ddata *ddata)
 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 > -100000)
-		return true;
+	    state->current_ua > (is_full ? -150000 : -100000))
+		is_full = true;
+	else
+		is_full = false;
 
-	return false;
+	return is_full;
 }
 
 static bool cpcap_battery_low(struct cpcap_battery_ddata *ddata)