Skip to content

Commit

Permalink
power: supply: ab8500: Respect charge_restart_voltage_uv
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Walleij authored and Sebastian Reichel committed Jun 9, 2022
1 parent 23c46ba commit 6aa35ab
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion drivers/power/supply/ab8500_chargalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,34 @@ static void ab8500_chargalg_external_power_changed(struct power_supply *psy)
queue_work(di->chargalg_wq, &di->chargalg_work);
}

/**
* 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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 6aa35ab

Please sign in to comment.