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

Message ID 20200315151206.30909-2-spinal.by@gmail.com
State New
Headers show
Series
  • [01/15] power: supply: cpcap-battery: Fix battery full status reporting
Related show

Commit Message

Arthur D. March 15, 2020, 3:11 p.m. UTC
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(-)

Comments

Tony Lindgren March 15, 2020, 4:46 p.m. UTC | #1
* Arthur Demchenkov <spinal.by@gmail.com> [200315 15:15]:
> 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.

Hmm oh so this is against my earlier RFC patches. Care to respin
the series against v5.6-rc?

Feel free tweak my patches to leave out the unnecessary stuff as we
decided to do things in a better way :) Just add a note like:

[spinal: dropped out unusable foo and bar]

So we know what got changed compared to the RFC patches.

And then we might have a nice working set for merging in subject
to others approving this approach of course :)

Regards,

Tony

Patch
diff mbox series

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)