summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Adolfsson <sadolfsson@google.com>2018-05-08 00:00:09 +0200
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-06-19 20:02:21 +0000
commitb1c01e91c496a658845be22d28856fd07b9e5ae3 (patch)
tree2357bec042fdb38439880ff27c1608c185f5af65
parent94ab84660f3ad4ed0590542fa10bbb3e55af70d7 (diff)
downloadchrome-ec-b1c01e91c496a658845be22d28856fd07b9e5ae3.tar.gz
npcx: CEC: Send CEC message in mkbp event
Instead of fetching incoming CEC messages using a specific read command, extend the standard mkbp event so the CEC message can be delivered directly inside the event. Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org> BUG=b:76467407 BRANCH=none TEST="ectool cec read" still working with a kernel that has support for the increased mkbp size. CQ-DEPEND=CL:1046186,CL:1051085 Reviewed-on: https://chromium-review.googlesource.com/1051105 Reviewed-by: Randall Spangler <rspangler@chromium.org> Change-Id: Id9d944be86ba85084b979d1df9057f7f3e7a1fd0 Reviewed-on: https://chromium-review.googlesource.com/1055833 Tested-by: Stefan Adolfsson <sadolfsson@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Stefan Adolfsson <sadolfsson@chromium.org>
-rw-r--r--chip/npcx/cec.c45
-rw-r--r--common/mkbp_event.c2
-rw-r--r--include/ec_commands.h53
-rw-r--r--util/ectool.c30
4 files changed, 73 insertions, 57 deletions
diff --git a/chip/npcx/cec.c b/chip/npcx/cec.c
index 073c33555a..da736edde8 100644
--- a/chip/npcx/cec.c
+++ b/chip/npcx/cec.c
@@ -294,7 +294,7 @@ static struct mutex circbuf_readoffset_mutex;
static void send_mkbp_event(uint32_t event)
{
atomic_or(&cec_events, event);
- mkbp_send_event(EC_MKBP_EVENT_CEC);
+ mkbp_send_event(EC_MKBP_EVENT_CEC_EVENT);
}
static void tmr_cap_start(enum cap_edge edge, int timeout)
@@ -976,11 +976,6 @@ static int cec_send(const uint8_t *msg, uint8_t len)
return 0;
}
-static int cec_recv(uint8_t *msg, uint8_t *len)
-{
- return rx_circbuf_pop(&cec_rx_cb, msg, len);
-}
-
static int hc_cec_write(struct host_cmd_handler_args *args)
{
const struct ec_params_cec_write *params = args->params;
@@ -998,24 +993,6 @@ static int hc_cec_write(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_CEC_WRITE_MSG, hc_cec_write, EC_VER_MASK(0));
-static int hc_cec_read(struct host_cmd_handler_args *args)
-{
- struct ec_response_cec_read *response = args->response;
- uint8_t msg_len;
-
- if (cec_state == CEC_STATE_DISABLED)
- return EC_RES_UNAVAILABLE;
-
- if (cec_recv(response->msg, &msg_len) != 0)
- return EC_RES_UNAVAILABLE;
-
- args->response_size = msg_len;
-
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_CEC_READ_MSG, hc_cec_read, EC_VER_MASK(0));
-
-
static int cec_set_enable(uint8_t enable)
{
int mdl = NPCX_MFT_MODULE_1;
@@ -1123,7 +1100,23 @@ static int cec_get_next_event(uint8_t *out)
return sizeof(event_out);
}
-DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_CEC, cec_get_next_event);
+DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_CEC_EVENT, cec_get_next_event);
+
+static int cec_get_next_msg(uint8_t *out)
+{
+ int rv;
+ uint8_t msg_len, msg[MAX_CEC_MSG_LEN];
+
+ rv = rx_circbuf_pop(&cec_rx_cb, msg, &msg_len);
+ if (rv != 0)
+ return EC_RES_UNAVAILABLE;
+
+ memcpy(out, msg, msg_len);
+
+ return msg_len;
+}
+DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_CEC_MESSAGE, cec_get_next_msg);
+
static void cec_init(void)
{
@@ -1167,7 +1160,7 @@ void cec_task(void)
rx_circbuf_push(&cec_rx_cb, cec_rx.msgt.buf,
cec_rx.msgt.byte);
}
- send_mkbp_event(EC_MKBP_CEC_HAVE_DATA);
+ mkbp_send_event(EC_MKBP_EVENT_CEC_MESSAGE);
}
}
}
diff --git a/common/mkbp_event.c b/common/mkbp_event.c
index 616f489df6..d89e740568 100644
--- a/common/mkbp_event.c
+++ b/common/mkbp_event.c
@@ -143,7 +143,7 @@ static int mkbp_get_next_event(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_GET_NEXT_EVENT,
mkbp_get_next_event,
- EC_VER_MASK(0));
+ EC_VER_MASK(0) | EC_VER_MASK(1));
#ifdef CONFIG_MKBP_WAKEUP_MASK
static int mkbp_get_wake_mask(struct host_cmd_handler_args *args)
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 6d8c2cca6b..0dec383e9e 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -21,6 +21,10 @@
#include "common.h"
#endif
+#if !defined(__KERNEL__)
+#include "compile_time_macros.h"
+#endif
+
/*
* Current version of this protocol
*
@@ -3178,7 +3182,10 @@ enum ec_mkbp_event {
EC_MKBP_EVENT_HOST_EVENT64 = 7,
/* Notify the AP that something happened on CEC */
- EC_MKBP_EVENT_CEC = 8,
+ EC_MKBP_EVENT_CEC_EVENT = 8,
+
+ /* Send an incoming CEC message to the AP */
+ EC_MKBP_EVENT_CEC_MESSAGE = 9,
/* Number of MKBP events */
EC_MKBP_EVENT_COUNT,
@@ -3209,12 +3216,46 @@ union __ec_align_offset1 ec_response_get_next_data {
uint32_t cec_events;
};
+union __ec_align_offset1 ec_response_get_next_data_v1 {
+ uint8_t key_matrix[16];
+
+ /* Unaligned */
+ uint32_t host_event;
+ uint64_t host_event64;
+
+ struct __ec_todo_unpacked {
+ /* For aligning the fifo_info */
+ uint8_t reserved[3];
+ struct ec_response_motion_sense_fifo_info info;
+ } sensor_fifo;
+
+ uint32_t buttons;
+
+ uint32_t switches;
+
+ uint32_t fp_events;
+
+ uint32_t sysrq;
+
+ /* CEC events from enum mkbp_cec_event */
+ uint32_t cec_events;
+
+ uint8_t cec_message[16];
+};
+BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
+
struct __ec_align1 ec_response_get_next_event {
uint8_t event_type;
/* Followed by event data if any */
union ec_response_get_next_data data;
};
+struct __ec_align1 ec_response_get_next_event_v1 {
+ uint8_t event_type;
+ /* Followed by event data if any */
+ union ec_response_get_next_data_v1 data;
+};
+
/* Bit indices for buttons and switches.*/
/* Buttons */
#define EC_MKBP_POWER_BUTTON 0
@@ -4094,14 +4135,6 @@ struct __ec_align1 ec_params_cec_write {
uint8_t msg[MAX_CEC_MSG_LEN];
};
-/* CEC message from a CEC sink reported back to the AP */
-#define EC_CMD_CEC_READ_MSG 0x00B9
-
-/* Message read from to the CEC bus */
-struct __ec_align1 ec_response_cec_read {
- uint8_t msg[MAX_CEC_MSG_LEN];
-};
-
/* Set various CEC parameters */
#define EC_CMD_CEC_SET 0x00BA
@@ -4134,8 +4167,6 @@ enum mkbp_cec_event {
EC_MKBP_CEC_SEND_OK = 1 << 0,
/* Outgoing message was not acknowledged */
EC_MKBP_CEC_SEND_FAILED = 1 << 1,
- /* Incoming message can be read out by AP */
- EC_MKBP_CEC_HAVE_DATA = 1 << 2,
};
/*****************************************************************************/
diff --git a/util/ectool.c b/util/ectool.c
index f9492cf52b..1d8ef280b6 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -7629,7 +7629,7 @@ err:
}
static int wait_event(long event_type,
- struct ec_response_get_next_event *buffer,
+ struct ec_response_get_next_event_v1 *buffer,
size_t buffer_size, long timeout)
{
int rv;
@@ -7643,13 +7643,13 @@ static int wait_event(long event_type,
return -EIO;
}
- return 0;
+ return rv;
}
int cmd_wait_event(int argc, char *argv[])
{
int rv, i;
- struct ec_response_get_next_event buffer;
+ struct ec_response_get_next_event_v1 buffer;
long timeout = 5000;
long event_type;
char *e;
@@ -7714,7 +7714,7 @@ static int cmd_cec_write(int argc, char *argv[])
long val;
int rv, i, msg_len;
struct ec_params_cec_write p;
- struct ec_response_get_next_event buffer;
+ struct ec_response_get_next_event_v1 buffer;
if (argc < 3 || argc > 18) {
fprintf(stderr, "Invalid number of params\n");
@@ -7741,7 +7741,7 @@ static int cmd_cec_write(int argc, char *argv[])
if (rv < 0)
return rv;
- rv = wait_event(EC_MKBP_EVENT_CEC, &buffer, sizeof(buffer), 1000);
+ rv = wait_event(EC_MKBP_EVENT_CEC_EVENT, &buffer, sizeof(buffer), 1000);
if (rv < 0)
return rv;
@@ -7760,10 +7760,9 @@ static int cmd_cec_write(int argc, char *argv[])
static int cmd_cec_read(int argc, char *argv[])
{
- int msg_len, i, rv;
+ int i, rv;
char *e;
- struct ec_response_cec_read r;
- struct ec_response_get_next_event buffer;
+ struct ec_response_get_next_event_v1 buffer;
long timeout = 5000;
if (!ec_pollevent) {
@@ -7779,21 +7778,14 @@ static int cmd_cec_read(int argc, char *argv[])
}
}
- rv = wait_event(EC_MKBP_EVENT_CEC, &buffer, sizeof(buffer), timeout);
+ rv = wait_event(EC_MKBP_EVENT_CEC_MESSAGE, &buffer,
+ sizeof(buffer), timeout);
if (rv < 0)
return rv;
- printf("Got CEC events 0x%08x\n", buffer.data.cec_events);
-
- rv = ec_command(EC_CMD_CEC_READ_MSG, 0, NULL, 0, &r, sizeof(r));
- if (rv < 0)
- return rv;
-
- msg_len = rv;
-
printf("CEC data: ");
- for (i = 0; i < msg_len; i++)
- printf("0x%02x ", r.msg[i]);
+ for (i = 0; i < rv - 1; i++)
+ printf("0x%02x ", buffer.data.cec_message[i]);
printf("\n");
return 0;