diff --git a/src/board/system76/common/battery.c b/src/board/system76/common/battery.c index 4074707..06d2abf 100644 --- a/src/board/system76/common/battery.c +++ b/src/board/system76/common/battery.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include +#include #include #include @@ -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()) { diff --git a/src/board/system76/common/include/board/battery.h b/src/board/system76/common/include/board/battery.h index 170a365..b1523e7 100644 --- a/src/board/system76/common/include/board/battery.h +++ b/src/board/system76/common/include/board/battery.h @@ -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 {