diff options
Diffstat (limited to 'board/asurada/battery.c')
-rw-r--r-- | board/asurada/battery.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/board/asurada/battery.c b/board/asurada/battery.c index f8fc47034f..570d263c4a 100644 --- a/board/asurada/battery.c +++ b/board/asurada/battery.c @@ -5,7 +5,13 @@ #include "battery.h" #include "battery_fuel_gauge.h" +#include "battery_smart.h" +#include "charge_manager.h" +#include "chipset.h" #include "gpio.h" +#include "hooks.h" +#include "system.h" +#include "usb_pd.h" const struct board_batt_params board_battery_info[] = { [BATTERY_C235] = { @@ -39,3 +45,31 @@ const struct board_batt_params board_battery_info[] = { BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_C235; + +static void reduce_input_voltage_when_full(void) +{ + struct batt_params batt; + int max_pd_voltage_mv; + int active_chg_port; + + if (!system_is_locked()) + return; + + active_chg_port = charge_manager_get_active_charge_port(); + if (active_chg_port == CHARGE_PORT_NONE) + return; + + battery_get_params(&batt); + /* Lower our input voltage to 9V when battery is full. */ + if (!(batt.flags & BATT_FLAG_BAD_STATUS) && + (batt.status & STATUS_FULLY_CHARGED) && + chipset_in_state(CHIPSET_STATE_ANY_OFF)) + max_pd_voltage_mv = 9000; + else + max_pd_voltage_mv = PD_MAX_VOLTAGE_MV; + + if (pd_get_max_voltage() != max_pd_voltage_mv) + pd_set_external_voltage_limit(active_chg_port, + max_pd_voltage_mv); +} +DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT); |