summaryrefslogtreecommitdiff
path: root/util/comm-i2c.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-06-28 15:50:43 -0700
committerGerrit <chrome-bot@google.com>2012-06-29 10:46:18 -0700
commit7e50e844a3bf1888f5abfa57cc82a6f94b87cbe2 (patch)
treecae0ab6e5aa33bf14630ce93b2b02c62e2ff64c0 /util/comm-i2c.c
parent70718f97e3afd8621a15a5d281a82a057d35b21a (diff)
downloadchrome-ec-7e50e844a3bf1888f5abfa57cc82a6f94b87cbe2.tar.gz
Change ec_command() to return negative values for errors
This is more compatible with kernel and u-boot, and will make it easier to share code between the ec project and those. BUG=none TEST=manual: ectool version -> should work normally on ec, do 'hostevent set 0x40000'. Then at root shell ectool queryec EC returned error result code 19 ectool flashread 0x100000 16 foo Reading 16 bytes at offset 1048576... EC returned error result code 2 Read error at offset 0 Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: I5e2a85f96c874d0730c14e1438a533649cd594f8 Reviewed-on: https://gerrit.chromium.org/gerrit/26359 Commit-Ready: Randall Spangler <rspangler@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util/comm-i2c.c')
-rw-r--r--util/comm-i2c.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/util/comm-i2c.c b/util/comm-i2c.c
index 63af28b8ce..7e968f035a 100644
--- a/util/comm-i2c.c
+++ b/util/comm-i2c.c
@@ -91,11 +91,11 @@ int ec_command(int command, const void *indata, int insize,
struct i2c_msg i2c_msg[2];
if (i2c_fd < 0)
- return -1;
+ return -EC_RES_ERROR;
if (ioctl(i2c_fd, I2C_SLAVE, EC_I2C_ADDR) < 0) {
fprintf(stderr, "Cannot set I2C slave address\n");
- return -1;
+ return -EC_RES_ERROR;
}
i2c_msg[0].addr = EC_I2C_ADDR;
@@ -149,6 +149,7 @@ int ec_command(int command, const void *indata, int insize,
if (ret < 0) {
fprintf(stderr, "i2c transfer failed: %d (err: %d)\n",
ret, errno);
+ ret = -EC_RES_ERROR;
goto done;
}
@@ -157,6 +158,8 @@ int ec_command(int command, const void *indata, int insize,
if (ret) {
debug("command 0x%02x returned an error %d\n",
command, i2c_msg[1].buf[0]);
+ /* Translate ERROR to -ERROR */
+ ret = -ret;
} else if (outsize) {
debug("i2c resp :");
/* copy response packet payload and compute checksum */
@@ -169,9 +172,12 @@ int ec_command(int command, const void *indata, int insize,
if (sum != resp_buf[outsize + 1]) {
debug("bad packet checksum\n");
- ret = -1;
+ ret = -EC_RES_ERROR;
goto done;
}
+
+ /* Return output buffer size */
+ ret = outsize;
}
done:
if (resp_buf)