diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2012-05-24 21:39:12 +0000 |
---|---|---|
committer | Vincent Palatin <vpalatin@chromium.org> | 2012-05-24 23:34:01 +0000 |
commit | 304d207117bb82db7f38303ba402c6f1be1112a8 (patch) | |
tree | 49e832bffd61dcd981c856237dabdf13424beb0f /util/lbplay.c | |
parent | b0fe45560828542ec3dd129db7d9cf59e92349d4 (diff) | |
download | chrome-ec-304d207117bb82db7f38303ba402c6f1be1112a8.tar.gz |
Split communication functions from host tools
Preparatory work to re-use the tools on ARM boards using I2C
communications.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BUG=None
TEST=make BOARD=link && make BOARD=bds && make BOard=DAISY
Change-Id: I31d41f30c3231a4a9349b939bf6bba871ed4c383
Diffstat (limited to 'util/lbplay.c')
-rw-r--r-- | util/lbplay.c | 69 |
1 files changed, 2 insertions, 67 deletions
diff --git a/util/lbplay.c b/util/lbplay.c index 6e0ceefcba..71511c581c 100644 --- a/util/lbplay.c +++ b/util/lbplay.c @@ -10,6 +10,7 @@ #include <sys/io.h> #include <unistd.h> +#include "comm-host.h" #include "lightbar.h" #include "ec_commands.h" @@ -17,68 +18,6 @@ #define BUILD_ASSERT(cond) ((void)sizeof(char[1 - 2*!(cond)])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -/* Waits for the EC to be unbusy. Returns 0 if unbusy, non-zero if - * timeout. */ -static int wait_for_ec(int status_addr, int timeout_usec) -{ - int i; - for (i = 0; i < timeout_usec; i += 10) { - usleep(10); /* Delay first, in case we just sent a command */ - if (!(inb(status_addr) & EC_LPC_STATUS_BUSY_MASK)) - return 0; - } - return -1; /* Timeout */ -} - - -/* Sends a command to the EC. Returns the command status code, or - * -1 if other error. */ -static int ec_command(int command, const void *indata, int insize, - void *outdata, int outsize) { - uint8_t *d; - int i; - - /* TODO: add command line option to use kernel command/param window */ - int cmd_addr = EC_LPC_ADDR_USER_CMD; - int data_addr = EC_LPC_ADDR_USER_DATA; - int param_addr = EC_LPC_ADDR_USER_PARAM; - - if (insize > EC_PARAM_SIZE || outsize > EC_PARAM_SIZE) { - fprintf(stderr, "Data size too big\n"); - return -1; - } - - if (wait_for_ec(cmd_addr, 1000000)) { - fprintf(stderr, "Timeout waiting for EC ready\n"); - return -1; - } - - /* Write data, if any */ - /* TODO: optimized copy using outl() */ - for (i = 0, d = (uint8_t *)indata; i < insize; i++, d++) - outb(*d, param_addr + i); - - outb(command, cmd_addr); - - if (wait_for_ec(cmd_addr, 1000000)) { - fprintf(stderr, "Timeout waiting for EC response\n"); - return -1; - } - - /* Check result */ - i = inb(data_addr); - if (i) { - fprintf(stderr, "EC returned error result code %d\n", i); - return i; - } - - /* Read data, if any */ - /* TODO: optimized copy using outl() */ - for (i = 0, d = (uint8_t *)outdata; i < outsize; i++, d++) - *d = inb(param_addr + i); - - return 0; -} static const struct { uint8_t insize; @@ -201,12 +140,8 @@ int main(int argc, char **argv) BUILD_ASSERT(ARRAY_SIZE(lb_command_paramcount) == LIGHTBAR_NUM_CMDS); - /* Request I/O privilege */ - if (iopl(3) < 0) { - perror("Error getting I/O privilege"); + if (comm_init() < 0) return -3; - } - /* Tell the EC to let us drive. */ lightbar_sequence(LIGHTBAR_STOP); |