Refactor lid switch, disable power button when lid closed and AC disconnected
This commit is contained in:
parent
2388892649
commit
d2591be256
@ -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;
|
||||
|
11
src/board/system76/darp5/include/board/lid.h
Normal file
11
src/board/system76/darp5/include/board/lid.h
Normal 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
|
45
src/board/system76/darp5/lid.c
Normal file
45
src/board/system76/darp5/lid.c
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
45
src/board/system76/galp3-c/lid.c
Normal file
45
src/board/system76/galp3-c/lid.c
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
11
src/board/system76/lemp9/include/board/lid.h
Normal file
11
src/board/system76/lemp9/include/board/lid.h
Normal 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
|
45
src/board/system76/lemp9/lid.c
Normal file
45
src/board/system76/lemp9/lid.c
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user