summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2022-04-15 22:36:37 +0200
committerSebastian Reichel <sebastian.reichel@collabora.com>2022-06-09 22:09:58 +0200
commit6aa35ab9db2c9ca141ba9d64a2ad95b73dbf90e3 (patch)
treef2ddd7d5a5d568e625845061496dafeb5baf3e00 /drivers/power/supply
parent23c46bab922b856b585a5f49413f74a9a7b2400d (diff)
downloadlinux-6aa35ab9db2c9ca141ba9d64a2ad95b73dbf90e3.tar.gz
linux-6aa35ab9db2c9ca141ba9d64a2ad95b73dbf90e3.tar.bz2
linux-6aa35ab9db2c9ca141ba9d64a2ad95b73dbf90e3.zip
power: supply: ab8500: Respect charge_restart_voltage_uv
The battery info contains a voltage indicating when the voltage is so low that it is time to restart the CC/CV charging. Make the AB8500 respect and prioritize this setting over the hardcoded 95% threshold. Break out the check into its own function and add some safeguards so we do not run into unpredictable side effects. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power/supply')
-rw-r--r--drivers/power/supply/ab8500_chargalg.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index 431bbc352d1b..037ae9b4a7d0 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1217,6 +1217,34 @@ static void ab8500_chargalg_external_power_changed(struct power_supply *psy)
}
/**
+ * ab8500_chargalg_time_to_restart() - time to restart CC/CV charging?
+ * @di: charging algorithm state
+ *
+ * This checks if the voltage or capacity of the battery has fallen so
+ * low that we need to restart the CC/CV charge cycle.
+ */
+static bool ab8500_chargalg_time_to_restart(struct ab8500_chargalg *di)
+{
+ struct power_supply_battery_info *bi = di->bm->bi;
+
+ /* Sanity check - these need to have some reasonable values */
+ if (!di->batt_data.volt_uv || !di->batt_data.percent)
+ return false;
+
+ /* Some batteries tell us at which voltage we should restart charging */
+ if (bi->charge_restart_voltage_uv > 0) {
+ if (di->batt_data.volt_uv <= bi->charge_restart_voltage_uv)
+ return true;
+ /* Else we restart as we reach a certain capacity */
+ } else {
+ if (di->batt_data.percent <= AB8500_RECHARGE_CAP)
+ return true;
+ }
+
+ return false;
+}
+
+/**
* ab8500_chargalg_algorithm() - Main function for the algorithm
* @di: pointer to the ab8500_chargalg structure
*
@@ -1459,7 +1487,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
fallthrough;
case STATE_WAIT_FOR_RECHARGE:
- if (di->batt_data.percent <= AB8500_RECHARGE_CAP)
+ if (ab8500_chargalg_time_to_restart(di))
ab8500_chargalg_state_to(di, STATE_NORMAL_INIT);
break;