diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2017-11-24 16:45:34 +0100 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-01-23 05:25:08 -0800 |
commit | b16f759652f074ee597fc4db8c403a46eab32c50 (patch) | |
tree | 7588cc544e3f88b471100d16cc2bbd1133c66a8a /util/comm-dev.c | |
parent | 96a7e9fe8120e81a40fe7fe208d17cff80f1a4b9 (diff) | |
download | chrome-ec-b16f759652f074ee597fc4db8c403a46eab32c50.tar.gz |
ectool: use poll interface
Test polling for MKBP events through the kernel cros_ec/pd/fp/.. driver
node.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=b:69460856
TEST=run on Eve EVT:
ectool --name=cros_fp fpmode fingerdown && \
ectool --name=cros_fp waitevent 5 10000
Change-Id: Ibdec137a3b646cf017a29afcf24ff5bbfb731198
Reviewed-on: https://chromium-review.googlesource.com/806167
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'util/comm-dev.c')
-rw-r--r-- | util/comm-dev.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/util/comm-dev.c b/util/comm-dev.c index 96356a6177..33a69f9d6f 100644 --- a/util/comm-dev.c +++ b/util/comm-dev.c @@ -6,6 +6,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <poll.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -219,6 +220,24 @@ static int ec_dev_is_v2(void) return 0; } +static int ec_pollevent_dev(unsigned long mask, void *buffer, size_t buf_size, + int timeout) +{ + int rv; + struct pollfd pf = { .fd = fd, .events = POLLIN }; + + ioctl(fd, CROS_EC_DEV_IOCEVENTMASK_V2, mask); + + rv = poll(&pf, 1, timeout); + if (rv != 1) + return rv; + + if (pf.revents != POLLIN) + return -pf.revents; + + return read(fd, buffer, buf_size); +} + int comm_init_dev(const char *device_name) { int (*ec_cmd_readmem)(int offset, int bytes, void *dest); @@ -257,6 +276,7 @@ int comm_init_dev(const char *device_name) if (ec_cmd_readmem(EC_MEMMAP_ID, 2, version) == 2 && version[0] == 'E' && version[1] == 'C') ec_readmem = ec_cmd_readmem; + ec_pollevent = ec_pollevent_dev; /* * Set temporary size, will be updated later. |