battery: Disable charger if full or not on AC

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-08-17 12:36:26 -06:00
committed by Jeremy Soller
parent 894b82d4fb
commit 34dd9ccbac
2 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/battery.h>
#include <board/gpio.h>
#include <board/smbus.h>
#include <common/debug.h>
@ -55,8 +56,14 @@ bool battery_set_end_threshold(uint8_t value) {
*/
int16_t battery_charger_configure(void) {
static bool should_charge = true;
bool ac_present = !gpio_get(&ACIN_N);
if (battery_get_end_threshold() == BATTERY_END_DEFAULT) {
if (!ac_present || (battery_info.status & BATTERY_FULLY_CHARGED)) {
// Always disable charger if:
// - AC is not plugged in, or
// - Battery is fully charged
should_charge = false;
} else if (battery_get_end_threshold() == BATTERY_END_DEFAULT) {
// Stop threshold not configured: Always charge on AC.
should_charge = true;
} else if (battery_info.charge > battery_get_end_threshold()) {

View File

@ -16,6 +16,9 @@
#define CHARGER_ADDRESS 0x09
#endif
#define BATTERY_FULLY_DISCHARGED BIT(4)
#define BATTERY_FULLY_CHARGED BIT(5)
#define BATTERY_DISCHARGING BIT(6)
#define BATTERY_INITIALIZED BIT(7)
struct battery_info {