summaryrefslogtreecommitdiff
path: root/common/keyboard_mkbp.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/keyboard_mkbp.c')
-rw-r--r--common/keyboard_mkbp.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c
index 08ec9d8c80..85e9a7b106 100644
--- a/common/keyboard_mkbp.c
+++ b/common/keyboard_mkbp.c
@@ -161,7 +161,6 @@ test_mockable int keyboard_fifo_add(const uint8_t *buffp)
test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp)
{
- int ret = EC_SUCCESS;
uint8_t size;
/*
@@ -175,8 +174,8 @@ test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp)
if (fifo_entries >= config.fifo_max_depth) {
CPRINTS("MKBP common FIFO depth %d reached",
config.fifo_max_depth);
- ret = EC_ERROR_OVERFLOW;
- goto fifo_push_done;
+
+ return EC_ERROR_OVERFLOW;
}
size = get_data_size(event_type);
@@ -185,14 +184,17 @@ test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp)
memcpy(&fifo[fifo_end].data, buffp, size);
fifo_end = (fifo_end + 1) % FIFO_DEPTH;
atomic_add(&fifo_entries, 1);
- mutex_unlock(&fifo_mutex);
-fifo_push_done:
-
- if (ret == EC_SUCCESS)
- mkbp_send_event(event_type);
+ /*
+ * If our event didn't generate an interrupt then the host is still
+ * asleep. In this case, we don't want to queue our event, except if
+ * another event just woke the host (and wake is already in progress).
+ */
+ if (!mkbp_send_event(event_type) && fifo_entries == 1)
+ mkbp_clear_fifo();
- return ret;
+ mutex_unlock(&fifo_mutex);
+ return EC_SUCCESS;
}
void mkbp_update_switches(uint32_t sw, int state)