Refactor lid switch, disable power button when lid closed and AC disconnected

This commit is contained in:
Jeremy Soller 2020-02-04 13:33:39 -07:00
parent 2388892649
commit d2591be256
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
14 changed files with 178 additions and 135 deletions

View File

@ -1,11 +1,10 @@
#include <board/acpi.h>
#include <board/battery.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/peci.h>
#include <common/debug.h>
extern bool lid_wake;
extern uint8_t sci_extra;
uint8_t fcmd = 0;

View File

@ -0,0 +1,11 @@
#ifndef _BOARD_LID_H
#define _BOARD_LID_H
#include <stdbool.h>
extern bool lid_state;
extern bool lid_wake;
void lid_event(void);
#endif // _BOARD_LID_H

View File

@ -0,0 +1,45 @@
#include <arch/delay.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/pmc.h>
#include <common/debug.h>
bool lid_state = true;
bool lid_wake = false;
void lid_event(void) {
static bool send_sci = true;
// Check if the lid switch has changed
bool new = gpio_get(&LID_SW_N);
if (new != lid_state) {
DEBUG("Lid ");
if (new) {
DEBUG("open\n");
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
// Send SCI
send_sci = true;
}
lid_state = new;
if (send_sci) {
// Send SCI 0x1B for lid event
if (pmc_sci(&PMC_1, 0x1B)) {
send_sci = false;
}
}
}

View File

@ -1,6 +1,4 @@
#include <8051.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <arch/arch.h>
@ -12,6 +10,7 @@
#include <board/gctrl.h>
#include <board/kbc.h>
#include <board/kbscan.h>
#include <board/lid.h>
#include <board/peci.h>
#include <board/pmc.h>
#include <board/power.h>
@ -66,47 +65,6 @@ void touchpad_event(struct Ps2 * ps2) {
}
}
bool lid_wake = false;
void lid_event(void) {
static bool send_sci = true;
static bool last = true;
// Check if the adapter line goes low
bool new = gpio_get(&LID_SW_N);
// If there has been a change, print
if (new != last) {
DEBUG("Lid ");
if (new) {
DEBUG("open\n");
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
// Send SCI
send_sci = true;
}
if (send_sci) {
// Send SCI 0x1B for lid event
if (pmc_sci(&PMC_1, 0x1B)) {
send_sci = false;
}
}
last = new;
}
void main(void) {
init();

View File

@ -2,6 +2,7 @@
#include <arch/time.h>
#include <board/battery.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/power.h>
#include <board/pmc.h>
#include <board/pnp.h>
@ -207,6 +208,10 @@ void power_event(void) {
// Read power switch state
static bool ps_last = true;
bool ps_new = gpio_get(&PWR_SW_N);
// Disable power button if lid is closed and AC is disconnected
if (!lid_state && ac_last) {
ps_new = true;
}
if (!ps_new && ps_last) {
// Ensure press is not spurious
delay_ms(10);

View File

@ -2,11 +2,10 @@
#include <board/battery.h>
#include <board/gpio.h>
#include <board/kbled.h>
#include <board/lid.h>
#include <board/peci.h>
#include <common/debug.h>
extern bool lid_wake;
extern uint8_t sci_extra;
static uint8_t fcmd = 0;

View File

@ -0,0 +1,45 @@
#include <arch/delay.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/pmc.h>
#include <common/debug.h>
bool lid_state = true;
bool lid_wake = false;
void lid_event(void) {
static bool send_sci = true;
// Check if the lid switch has changed
bool new = gpio_get(&LID_SW_N);
if (new != lid_state) {
DEBUG("Lid ");
if (new) {
DEBUG("open\n");
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
// Send SCI
send_sci = true;
}
lid_state = new;
if (send_sci) {
// Send SCI 0x1B for lid event
if (pmc_sci(&PMC_1, 0x1B)) {
send_sci = false;
}
}
}

View File

@ -1,6 +1,4 @@
#include <8051.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <arch/arch.h>
@ -13,6 +11,7 @@
#include <board/kbc.h>
#include <board/kbled.h>
#include <board/kbscan.h>
#include <board/lid.h>
#include <board/peci.h>
#include <board/pmc.h>
#include <board/power.h>
@ -68,47 +67,6 @@ void touchpad_event(struct Ps2 * ps2) {
}
}
bool lid_wake = false;
void lid_event(void) {
static bool send_sci = true;
static bool last = true;
// Check if the adapter line goes low
bool new = gpio_get(&LID_SW_N);
// If there has been a change, print
if (new != last) {
DEBUG("Lid ");
if (new) {
DEBUG("open\n");
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
// Send SCI
send_sci = true;
}
if (send_sci) {
// Send SCI 0x1B for lid event
if (pmc_sci(&PMC_1, 0x1B)) {
send_sci = false;
}
}
last = new;
}
void main(void) {
init();

View File

@ -2,6 +2,7 @@
#include <arch/time.h>
#include <board/battery.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/power.h>
#include <board/pmc.h>
#include <board/pnp.h>
@ -207,6 +208,10 @@ void power_event(void) {
// Read power switch state
static bool ps_last = true;
bool ps_new = gpio_get(&PWR_SW_N);
// Disable power button if lid is closed and AC is disconnected
if (!lid_state && ac_last) {
ps_new = true;
}
if (!ps_new && ps_last) {
// Ensure press is not spurious
delay_ms(10);

View File

@ -2,11 +2,10 @@
#include <board/battery.h>
#include <board/gpio.h>
#include <board/kbled.h>
#include <board/lid.h>
#include <board/peci.h>
#include <common/debug.h>
extern bool lid_wake;
extern uint8_t sci_extra;
static uint8_t fcmd = 0;

View File

@ -0,0 +1,11 @@
#ifndef _BOARD_LID_H
#define _BOARD_LID_H
#include <stdbool.h>
extern bool lid_state;
extern bool lid_wake;
void lid_event(void);
#endif // _BOARD_LID_H

View File

@ -0,0 +1,45 @@
#include <arch/delay.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/pmc.h>
#include <common/debug.h>
bool lid_state = true;
bool lid_wake = false;
void lid_event(void) {
static bool send_sci = true;
// Check if the lid switch has changed
bool new = gpio_get(&LID_SW_N);
if (new != lid_state) {
DEBUG("Lid ");
if (new) {
DEBUG("open\n");
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
// Send SCI
send_sci = true;
}
lid_state = new;
if (send_sci) {
// Send SCI 0x1B for lid event
if (pmc_sci(&PMC_1, 0x1B)) {
send_sci = false;
}
}
}

View File

@ -1,6 +1,4 @@
#include <8051.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <arch/arch.h>
@ -13,6 +11,7 @@
#include <board/kbc.h>
#include <board/kbled.h>
#include <board/kbscan.h>
#include <board/lid.h>
#include <board/peci.h>
#include <board/pmc.h>
#include <board/power.h>
@ -68,47 +67,6 @@ void touchpad_event(struct Ps2 * ps2) {
}
}
bool lid_wake = false;
void lid_event(void) {
static bool send_sci = true;
static bool last = true;
// Check if the adapter line goes low
bool new = gpio_get(&LID_SW_N);
// If there has been a change, print
if (new != last) {
DEBUG("Lid ");
if (new) {
DEBUG("open\n");
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
// Send SCI
send_sci = true;
}
if (send_sci) {
// Send SCI 0x1B for lid event
if (pmc_sci(&PMC_1, 0x1B)) {
send_sci = false;
}
}
last = new;
}
void main(void) {
init();

View File

@ -2,6 +2,7 @@
#include <arch/time.h>
#include <board/battery.h>
#include <board/gpio.h>
#include <board/lid.h>
#include <board/power.h>
#include <board/pmc.h>
#include <board/pnp.h>
@ -207,6 +208,10 @@ void power_event(void) {
// Read power switch state
static bool ps_last = true;
bool ps_new = gpio_get(&PWR_SW_N);
// Disable power button if lid is closed and AC is disconnected
if (!lid_state && ac_last) {
ps_new = true;
}
if (!ps_new && ps_last) {
// Ensure press is not spurious
delay_ms(10);