summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/sasuke/battery.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/board/sasuke/battery.c b/board/sasuke/battery.c
index d560a2d894..ad7ea9c2fe 100644
--- a/board/sasuke/battery.c
+++ b/board/sasuke/battery.c
@@ -144,21 +144,29 @@ enum ec_status charger_profile_override_set_param(uint32_t param,
}
/* Lower our input voltage to 5V in S0iX when battery is full. */
+#define PD_VOLTAGE_WHEN_FULL 5000
static void reduce_input_voltage_when_full(void)
{
- int max_pd_voltage_mv;
- int port;
+ static int saved_input_voltage = -1;
+ int max_pd_voltage_mv = pd_get_max_voltage();
+ int port;
- if (charge_get_percent() == 100 &&
- chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
- max_pd_voltage_mv = 5000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
+ if (charge_get_percent() == 100 &&
+ chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) {
+ if (max_pd_voltage_mv != PD_VOLTAGE_WHEN_FULL) {
+ saved_input_voltage = max_pd_voltage_mv;
+ max_pd_voltage_mv = PD_VOLTAGE_WHEN_FULL;
+ }
+ } else if (saved_input_voltage != -1) {
+ if (max_pd_voltage_mv == PD_VOLTAGE_WHEN_FULL)
+ max_pd_voltage_mv = saved_input_voltage;
+ saved_input_voltage = -1;
+ }
- if (pd_get_max_voltage() != max_pd_voltage_mv) {
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++)
- pd_set_external_voltage_limit(port, max_pd_voltage_mv);
- }
+ if (pd_get_max_voltage() != max_pd_voltage_mv) {
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++)
+ pd_set_external_voltage_limit(port, max_pd_voltage_mv);
+ }
}
DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full,
HOOK_PRIO_DEFAULT);