diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2016-08-11 17:02:41 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-12 13:45:35 -0700 |
commit | de4d25964de310effe8ede09e5ba6fa2f40dc52b (patch) | |
tree | ff590ba65dfe3063d9c9e504f89bbd760e838f92 | |
parent | 88428882b827b818df9b99ca37ef26b8f1927e9a (diff) | |
download | chrome-ec-de4d25964de310effe8ede09e5ba6fa2f40dc52b.tar.gz |
mkbp_event: Allow host to report sleep state for non-wake event skipping
Allow the host to self-report its sleep state through
EC_CMD_HOST_SLEEP_EVENT, which will typically be sent with SUSPEND
param when the host begins its sleep process. While the host has
self-reported that it is in SUSPEND, don't assert the interrupt
line, except for designated wake events.
BUG=chrome-os-partner:56156
BRANCH=None
TEST=On kevin, run 'ectool hostsleepstate suspend', verify that
interrupt assertion is skipped for battery host event. Run 'ectool
hostsleepstate resume' and verify interrupt is again asserted by the
battery host event.
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I74288465587ccf7185cec717f7c1810602361b8c
Reviewed-on: https://chromium-review.googlesource.com/368391
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | board/kevin/board.h | 1 | ||||
-rw-r--r-- | common/mkbp_event.c | 20 | ||||
-rw-r--r-- | include/config.h | 7 | ||||
-rw-r--r-- | include/ec_commands.h | 4 | ||||
-rw-r--r-- | include/power.h | 8 | ||||
-rw-r--r-- | power/common.c | 21 | ||||
-rw-r--r-- | util/ectool.c | 29 |
7 files changed, 84 insertions, 6 deletions
diff --git a/board/kevin/board.h b/board/kevin/board.h index 711494cdf9..3ddcad4d5c 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -51,6 +51,7 @@ #define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2 #define CONFIG_LTO #define CONFIG_POWER_BUTTON +#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE #define CONFIG_VBOOT_HASH #define CONFIG_CHARGER diff --git a/common/mkbp_event.c b/common/mkbp_event.c index d2545f3f7e..b59d8dd23c 100644 --- a/common/mkbp_event.c +++ b/common/mkbp_event.c @@ -11,6 +11,7 @@ #include "host_command.h" #include "link_defs.h" #include "mkbp_event.h" +#include "power.h" #include "util.h" static uint32_t events; @@ -44,13 +45,28 @@ static void set_host_interrupt(int active) #endif } +/** + * Check if the host is sleeping. Check our power state in addition to the + * self-reported sleep state of host (CONFIG_POWER_TRACK_HOST_SLEEP_STATE). + */ +static inline int host_is_sleeping(void) +{ + int is_sleeping = !chipset_in_state(CHIPSET_STATE_ON); + +#ifdef CONFIG_POWER_TRACK_HOST_SLEEP_STATE + is_sleeping |= + (power_get_host_sleep_state() == HOST_SLEEP_EVENT_S3_SUSPEND); +#endif + return is_sleeping; +} + void mkbp_send_event(uint8_t event_type) { set_event(event_type); #ifdef CONFIG_MKBP_WAKEUP_MASK - /* checking the event if AP is not in S0 */ - if (!chipset_in_state(CHIPSET_STATE_ON)) { + /* Only assert interrupt for wake events if host is sleeping */ + if (host_is_sleeping()) { uint32_t events; events = *(uint32_t *)host_get_memmap(EC_MEMMAP_HOST_EVENTS); /* diff --git a/include/config.h b/include/config.h index dc5eb0707b..64ecab1eff 100644 --- a/include/config.h +++ b/include/config.h @@ -1527,6 +1527,13 @@ /* Support S0ix */ #undef CONFIG_POWER_S0IX + +/* + * Allow the host to self-report its sleep state, in case there is some delay + * between the host beginning to enter the sleep state and power signals + * actually reflecting the new state. + */ +#undef CONFIG_POWER_TRACK_HOST_SLEEP_STATE /*****************************************************************************/ /* Support PWM control */ #undef CONFIG_PWM diff --git a/include/ec_commands.h b/include/ec_commands.h index fd3b1b3df4..0c1cd48a2a 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -3186,10 +3186,6 @@ struct ec_params_host_sleep_event { uint8_t sleep_event; } __packed; -struct ec_response_host_sleep_event { - uint8_t sleep_event; -} __packed; - /*****************************************************************************/ /* Smart battery pass-through */ diff --git a/include/power.h b/include/power.h index 5d1c040d9e..ab8d7ac46a 100644 --- a/include/power.h +++ b/include/power.h @@ -133,4 +133,12 @@ int power_get_pause_in_s5(void); */ void power_set_pause_in_s5(int pause); +#ifdef CONFIG_POWER_TRACK_HOST_SLEEP_STATE +/** + * Get sleep state of host, as reported by the host. + * + * @return Believed sleep state of host. + */ +enum host_sleep_event power_get_host_sleep_state(void); +#endif #endif /* __CROS_EC_POWER_H */ diff --git a/power/common.c b/power/common.c index 696fed1fb0..7f5d1aa873 100644 --- a/power/common.c +++ b/power/common.c @@ -686,3 +686,24 @@ DECLARE_CONSOLE_COMMAND(pause_in_s5, command_pause_in_s5, "Should the AP pause in S5 during shutdown?", NULL); #endif /* CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5 */ + +#ifdef CONFIG_POWER_TRACK_HOST_SLEEP_STATE +/* Track last reported sleep event */ +static enum host_sleep_event host_sleep_state; + +static int host_command_host_sleep_event(struct host_cmd_handler_args *args) +{ + const struct ec_params_host_sleep_event *p = args->params; + + host_sleep_state = p->sleep_event; + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_HOST_SLEEP_EVENT, + host_command_host_sleep_event, + EC_VER_MASK(0)); + +enum host_sleep_event power_get_host_sleep_state(void) +{ + return host_sleep_state; +} +#endif /* CONFIG_POWER_TRACK_HOST_SLEEP_STATE */ diff --git a/util/ectool.c b/util/ectool.c index 6d9c09737d..a32b67e3aa 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -119,6 +119,8 @@ const char help_str[] = " Checks for basic communication with EC\n" " hibdelay [sec]\n" " Set the delay before going into hibernation\n" + " hostsleepstate\n" + " Report host sleep state to the EC\n" " kbpress\n" " Simulate key press\n" " kbfactorytest\n" @@ -380,6 +382,32 @@ int cmd_hibdelay(int argc, char *argv[]) return 0; } +int cmd_hostsleepstate(int argc, char *argv[]) +{ + struct ec_params_host_sleep_event p; + + if (argc < 2) { + fprintf(stderr, "Usage: %s [suspend|resume|freeze|thaw]\n", + argv[0]); + return -1; + } + + if (!strcmp(argv[1], "suspend")) + p.sleep_event = HOST_SLEEP_EVENT_S3_SUSPEND; + else if (!strcmp(argv[1], "resume")) + p.sleep_event = HOST_SLEEP_EVENT_S3_RESUME; + else if (!strcmp(argv[1], "freeze")) + p.sleep_event = HOST_SLEEP_EVENT_S0IX_SUSPEND; + else if (!strcmp(argv[1], "thaw")) + p.sleep_event = HOST_SLEEP_EVENT_S0IX_RESUME; + else { + fprintf(stderr, "Unknown command: %s\n", argv[1]); + return -1; + } + + return ec_command(EC_CMD_HOST_SLEEP_EVENT, 0, &p, sizeof(p), NULL, 0); +} + int cmd_test(int argc, char *argv[]) { struct ec_params_test_protocol p = { @@ -6881,6 +6909,7 @@ const struct command commands[] = { {"hangdetect", cmd_hang_detect}, {"hello", cmd_hello}, {"hibdelay", cmd_hibdelay}, + {"hostsleepstate", cmd_hostsleepstate}, {"kbpress", cmd_kbpress}, {"i2cprotect", cmd_i2c_protect}, {"i2cread", cmd_i2c_read}, |