From 2e6a556e4bcde6bf9c15510492db8531c75634aa Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 13 Jan 2020 20:40:29 -0700 Subject: [PATCH] Send SWI on lid open --- src/board/system76/lemp9/acpi.c | 14 +++++++++----- src/board/system76/lemp9/main.c | 12 ++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/board/system76/lemp9/acpi.c b/src/board/system76/lemp9/acpi.c index aa4f356..f4aeac4 100644 --- a/src/board/system76/lemp9/acpi.c +++ b/src/board/system76/lemp9/acpi.c @@ -4,6 +4,8 @@ #include #include +extern bool lid_wake; + static struct Gpio __code ACIN_N = GPIO(B, 0); static struct Gpio __code LID_SW_N = GPIO(B, 1); @@ -30,6 +32,9 @@ uint8_t acpi_read(uint8_t addr) { // Lid is open data |= 1 << 0; } + if (lid_wake) { + data |= 1 << 2; + } break; // Handle AC adapter and battery present @@ -64,14 +69,13 @@ uint8_t acpi_read(uint8_t addr) { } -// If not in debug mode, data is not used, ignore warning -#pragma save -#pragma disable_warning 85 void acpi_write(uint8_t addr, uint8_t data) { DEBUG("acpi_write %02X = %02X\n", addr, data); switch (addr) { - //TODO + // Lid state and other flags + case 0x03: + lid_wake = (bool)(data & (1 << 2)); + break; } } -#pragma restore diff --git a/src/board/system76/lemp9/main.c b/src/board/system76/lemp9/main.c index 9b0c9ae..0baee19 100644 --- a/src/board/system76/lemp9/main.c +++ b/src/board/system76/lemp9/main.c @@ -72,8 +72,10 @@ void touchpad_event(struct Ps2 * ps2) { } } +bool lid_wake = false; void lid_event(void) { extern struct Gpio __code LID_SW_N; + extern struct Gpio __code SWI_N; static bool send_sci = true; static bool last = true; @@ -87,6 +89,16 @@ void lid_event(void) { DEBUG("open\n"); //TODO: send SWI if needed + 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"); }