From 84941a85d23ee07583ce6c1f8c2859646dbdb53b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 12 Dec 2019 10:56:19 -0700 Subject: [PATCH] Add lid switch SCI --- src/board/system76/galp3-c/main.c | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index 0e9a8a8..bf7ba17 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -115,6 +115,39 @@ void touchpad_event(struct Ps2 * ps2) { } } +void lid_event(void) { + static struct Gpio __code LID_SW_N = GPIO(D, 1); + + 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"); + + //TODO: send SWI if needed + } 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; +} + struct Gpio __code LED_SSD_N = GPIO(G, 6); struct Gpio __code LED_AIRPLANE_N = GPIO(G, 6); @@ -174,6 +207,8 @@ void main(void) { kbscan_event(); // Passes through touchpad packets touchpad_event(&PS2_3); + // Handle lid close/open + lid_event(); // Checks for keyboard/mouse packets from host kbc_event(&KBC); // Only run the following once out of every 256 loops