diff options
author | Duncan Laurie <dlaurie@chromium.org> | 2012-04-04 18:47:20 -0700 |
---|---|---|
committer | Duncan Laurie <dlaurie@chromium.org> | 2012-04-06 14:49:42 -0700 |
commit | 9936df2b8b1cf697357123756d8eb09a0db09428 (patch) | |
tree | af3971da6660aee1da26944993ffe0440db91a31 /chip/lm4 | |
parent | 6abb3579af819e5915b103b5518282e8ed62a81f (diff) | |
download | chrome-ec-9936df2b8b1cf697357123756d8eb09a0db09428.tar.gz |
Split lid handling into separate functions and add command interface
This has been useful for me to be able to test lid behavior remotely
since it is not available via servo.
This also has a minor change to send a task message after sending
the power button pulse so the state machine behaves properly.
BUG=none
TEST=Execute 'lidclose' and 'lidopen' commands via ec uart and
see the appropriate events set and wake behavior when the system
is off. With a (not yet published) coreboot I am able to handle
lid close events to enter suspend.
Change-Id: Iec1c68121d42b66305ba5dfd20e81453538a97e2
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Diffstat (limited to 'chip/lm4')
-rw-r--r-- | chip/lm4/power_button.c | 72 |
1 files changed, 53 insertions, 19 deletions
diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c index 24af579690..d28220b29e 100644 --- a/chip/lm4/power_button.c +++ b/chip/lm4/power_button.c @@ -177,33 +177,51 @@ static void power_button_changed(uint64_t tnow) } -/* Handle debounced lid switch changing state */ -static void lid_switch_changed(uint64_t tnow) +/* Lid open */ +static void lid_switch_open(uint64_t tnow) { - int v = gpio_get_level(GPIO_LID_SWITCHn); - uart_printf("[%T PB lid %s]\n", v ? "open" : "closed"); + uart_printf("[%T PB lid open]\n"); - lpc_set_host_events(EC_LPC_HOST_EVENT_MASK((v ? - EC_LPC_HOST_EVENT_LID_OPEN : EC_LPC_HOST_EVENT_LID_CLOSED))); + *memmap_switches |= EC_LPC_SWITCH_LID_OPEN; - if (v) { - /* Lid open */ - *memmap_switches |= EC_LPC_SWITCH_LID_OPEN; + lpc_set_host_events(EC_LPC_HOST_EVENT_MASK( + EC_LPC_HOST_EVENT_LID_OPEN)); - /* If the chipset is is soft-off, send a power button pulse to - * wake up the chipset. */ - if (chipset_in_state(CHIPSET_STATE_SOFT_OFF)) { - set_pwrbtn_to_pch(0); - pwrbtn_state = PWRBTN_STATE_STOPPING; - tnext_state = tnow + LID_PWRBTN_US; - } - } else { - /* Lid closed */ - *memmap_switches &= ~EC_LPC_SWITCH_LID_OPEN; + /* If the chipset is is soft-off, send a power button pulse to + * wake up the chipset. */ + if (chipset_in_state(CHIPSET_STATE_SOFT_OFF)) { + set_pwrbtn_to_pch(0); + pwrbtn_state = PWRBTN_STATE_STOPPING; + tnext_state = tnow + LID_PWRBTN_US; + task_wake(TASK_ID_POWERBTN); } } +/* Lid close */ +static void lid_switch_close(uint64_t tnow) +{ + uart_printf("[%T PB lid close]\n"); + + *memmap_switches &= ~EC_LPC_SWITCH_LID_OPEN; + + lpc_set_host_events(EC_LPC_HOST_EVENT_MASK( + EC_LPC_HOST_EVENT_LID_CLOSED)); +} + + +/* Handle debounced lid switch changing state */ +static void lid_switch_changed(uint64_t tnow) +{ + int v = gpio_get_level(GPIO_LID_SWITCHn); + + if (v) + lid_switch_open(tnow); + else + lid_switch_close(tnow); +} + + void power_button_interrupt(enum gpio_signal signal) { /* Reset debounce time for the changed signal */ @@ -346,3 +364,19 @@ static int command_powerbtn(int argc, char **argv) return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn); + + +static int command_lidopen(int argc, char **argv) +{ + lid_switch_open(get_time().val); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(lidopen, command_lidopen); + + +static int command_lidclose(int argc, char **argv) +{ + lid_switch_close(get_time().val); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(lidclose, command_lidclose); |