From 825677bfb54bda8aa31d6daafe1d3dd81654de4d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 4 Apr 2020 19:36:01 -0600 Subject: [PATCH] Turn off VDD3 when CPU is off and AC is not connected --- src/board/system76/lemp9/gpio.c | 1 + src/board/system76/lemp9/include/board/gpio.h | 1 + src/board/system76/lemp9/power.c | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/board/system76/lemp9/gpio.c b/src/board/system76/lemp9/gpio.c index 2e662d4..eae6c1a 100644 --- a/src/board/system76/lemp9/gpio.c +++ b/src/board/system76/lemp9/gpio.c @@ -35,6 +35,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4); struct Gpio __code VR_ON = GPIO(H, 4); struct Gpio __code WLAN_EN = GPIO(G, 1); struct Gpio __code WLAN_PWR_EN = GPIO(A, 3); +struct Gpio __code XLP_OUT = GPIO(B, 4); void gpio_init() { // Enable LPC reset on GPD2 diff --git a/src/board/system76/lemp9/include/board/gpio.h b/src/board/system76/lemp9/include/board/gpio.h index 380df8b..34e38d7 100644 --- a/src/board/system76/lemp9/include/board/gpio.h +++ b/src/board/system76/lemp9/include/board/gpio.h @@ -46,5 +46,6 @@ extern struct Gpio __code VA_EC_EN; extern struct Gpio __code VR_ON; extern struct Gpio __code WLAN_EN; extern struct Gpio __code WLAN_PWR_EN; +extern struct Gpio __code XLP_OUT; #endif // _BOARD_GPIO_H diff --git a/src/board/system76/lemp9/power.c b/src/board/system76/lemp9/power.c index 0440459..c4393e7 100644 --- a/src/board/system76/lemp9/power.c +++ b/src/board/system76/lemp9/power.c @@ -399,14 +399,14 @@ void power_event(void) { } } + static uint32_t last_time = 0; + uint32_t time = time_get(); if (power_state == POWER_STATE_S0) { // CPU on, green light gpio_set(&LED_PWR, true); gpio_set(&LED_ACIN, false); } else if (power_state == POWER_STATE_S3 || power_state == POWER_STATE_DS3) { // Suspended, flashing green light - static uint32_t last_time = 0; - uint32_t time = time_get(); if ( (time < last_time) // overflow || @@ -421,9 +421,19 @@ void power_event(void) { gpio_set(&LED_PWR, false); gpio_set(&LED_ACIN, true); } else { - // CPU off and AC adapter unplugged, no light + // CPU off and AC adapter unplugged, flashing orange light gpio_set(&LED_PWR, false); - gpio_set(&LED_ACIN, false); + if ( + (time < last_time) // overflow + || + (time >= (last_time + 1000)) // timeout + ) { + gpio_set(&LED_ACIN, !gpio_get(&LED_ACIN)); + last_time = time; + } + + // Attempt to kill VDD3 + gpio_set(&XLP_OUT, false); } #endif // DEEP_SX }