summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2013-10-21 08:41:35 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-21 20:05:41 +0000
commit35916b4bc19743e6fcc0930094be4bba56c790fd (patch)
tree413a8f82146148db33bd3fca32343e5ee7b69d7e
parent2d37bb2a644071bdf411b8d97f4aff085fe0712b (diff)
downloadchrome-ec-35916b4bc19743e6fcc0930094be4bba56c790fd.tar.gz
i2c: Add common i2cxfer console command
This console command is useful during bringup to interrogate devices on the EC I2C interfaces. Ported from STM32 into the common file. This command now takes an additional argument for the port to be used. BUG=chrome-os-partner:23449 BRANCH=samus TEST=emerge-samus chromeos-ec, tested on samus Change-Id: I8308fbc2f34e369a20051dca9c5d43872f239777 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/173837 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/stm32/i2c-stm32f.c93
-rw-r--r--chip/stm32/i2c-stm32l.c86
-rw-r--r--common/i2c_common.c93
3 files changed, 93 insertions, 179 deletions
diff --git a/chip/stm32/i2c-stm32f.c b/chip/stm32/i2c-stm32f.c
index 36cbd857df..baac384121 100644
--- a/chip/stm32/i2c-stm32f.c
+++ b/chip/stm32/i2c-stm32f.c
@@ -891,96 +891,3 @@ int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
i2c_lock(port, 0);
return rv;
}
-
-/*****************************************************************************/
-/* Console commands */
-
-#ifdef I2C_PORT_HOST
-
-static int command_i2c(int argc, char **argv)
-{
- int rw = 0;
- int slave_addr, offset;
- int value = 0;
- char *e;
- int rv = 0;
-
- if (argc < 4) {
- ccputs("Usage: i2c r/r16/w/w16 slave_addr offset [value]\n");
- return EC_ERROR_UNKNOWN;
- }
-
- if (strcasecmp(argv[1], "r") == 0) {
- rw = 0;
- } else if (strcasecmp(argv[1], "r16") == 0) {
- rw = 1;
- } else if (strcasecmp(argv[1], "w") == 0) {
- rw = 2;
- } else if (strcasecmp(argv[1], "w16") == 0) {
- rw = 3;
- } else {
- ccputs("Invalid rw mode : r / w / r16 / w16\n");
- return EC_ERROR_INVAL;
- }
-
- slave_addr = strtoi(argv[2], &e, 0);
- if (*e) {
- ccputs("Invalid slave_addr\n");
- return EC_ERROR_INVAL;
- }
-
- offset = strtoi(argv[3], &e, 0);
- if (*e) {
- ccputs("Invalid addr\n");
- return EC_ERROR_INVAL;
- }
-
- if (rw > 1) {
- if (argc < 5) {
- ccputs("No write value\n");
- return EC_ERROR_INVAL;
- }
- value = strtoi(argv[4], &e, 0);
- if (*e) {
- ccputs("Invalid write value\n");
- return EC_ERROR_INVAL;
- }
- }
-
-
- switch (rw) {
- case 0:
- rv = i2c_read8(I2C_PORT_HOST, slave_addr, offset, &value);
- break;
- case 1:
- rv = i2c_read16(I2C_PORT_HOST, slave_addr, offset, &value);
- break;
- case 2:
- rv = i2c_write8(I2C_PORT_HOST, slave_addr, offset, value);
- break;
- case 3:
- rv = i2c_write16(I2C_PORT_HOST, slave_addr, offset, value);
- break;
- }
-
-
- if (rv) {
- ccprintf("i2c command failed\n", rv);
- return rv;
- }
-
- if (rw == 0)
- ccprintf("0x%02x [%d]\n", value);
- else if (rw == 1)
- ccprintf("0x%04x [%d]\n", value);
-
- ccputs("ok\n");
-
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(i2c, command_i2c,
- "r/r16/w/w16 slave_addr offset [value]",
- "Read write i2c",
- NULL);
-
-#endif /* I2C_PORT_HOST */
diff --git a/chip/stm32/i2c-stm32l.c b/chip/stm32/i2c-stm32l.c
index 71b93a2953..8e02f693cd 100644
--- a/chip/stm32/i2c-stm32l.c
+++ b/chip/stm32/i2c-stm32l.c
@@ -532,92 +532,6 @@ DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
/* Console commands */
-static int command_i2c(int argc, char **argv)
-{
- int rw = 0;
- int slave_addr, offset;
- int value = 0;
- char *e;
- int rv = 0;
-
- if (argc < 4) {
- ccputs("Usage: i2c r/r16/w/w16 slave_addr offset [value]\n");
- return EC_ERROR_UNKNOWN;
- }
-
- if (strcasecmp(argv[1], "r") == 0) {
- rw = 0;
- } else if (strcasecmp(argv[1], "r16") == 0) {
- rw = 1;
- } else if (strcasecmp(argv[1], "w") == 0) {
- rw = 2;
- } else if (strcasecmp(argv[1], "w16") == 0) {
- rw = 3;
- } else {
- ccputs("Invalid rw mode : r / w / r16 / w16\n");
- return EC_ERROR_INVAL;
- }
-
- slave_addr = strtoi(argv[2], &e, 0);
- if (*e) {
- ccputs("Invalid slave_addr\n");
- return EC_ERROR_INVAL;
- }
-
- offset = strtoi(argv[3], &e, 0);
- if (*e) {
- ccputs("Invalid addr\n");
- return EC_ERROR_INVAL;
- }
-
- if (rw > 1) {
- if (argc < 5) {
- ccputs("No write value\n");
- return EC_ERROR_INVAL;
- }
- value = strtoi(argv[4], &e, 0);
- if (*e) {
- ccputs("Invalid write value\n");
- return EC_ERROR_INVAL;
- }
- }
-
-
- switch (rw) {
- case 0:
- rv = i2c_read8(I2C_PORT_HOST, slave_addr, offset, &value);
- break;
- case 1:
- rv = i2c_read16(I2C_PORT_HOST, slave_addr, offset, &value);
- break;
- case 2:
- rv = i2c_write8(I2C_PORT_HOST, slave_addr, offset, value);
- break;
- case 3:
- rv = i2c_write16(I2C_PORT_HOST, slave_addr, offset, value);
- break;
- }
-
-
- if (rv) {
- ccprintf("i2c command failed\n", rv);
- return rv;
- }
-
- if (rw == 0)
- ccprintf("0x%02x [%d]\n", value);
- else if (rw == 1)
- ccprintf("0x%04x [%d]\n", value);
-
- ccputs("ok\n");
-
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(i2cxfer, command_i2c,
- "r/r16/w/w16 slave_addr offset [value]",
- "Read write I2C",
- NULL);
-
static int command_i2cdump(int argc, char **argv)
{
dump_i2c_reg(I2C_PORT_HOST, "dump");
diff --git a/common/i2c_common.c b/common/i2c_common.c
index dcbc4fb73d..ed3a888872 100644
--- a/common/i2c_common.c
+++ b/common/i2c_common.c
@@ -374,3 +374,96 @@ DECLARE_CONSOLE_COMMAND(i2cscan, command_scan,
NULL,
"Scan I2C ports for devices",
NULL);
+
+
+static int command_i2cxfer(int argc, char **argv)
+{
+ int rw = 0;
+ int port, slave_addr, offset;
+ int value = 0;
+ char *e;
+ int rv = 0;
+
+ if (argc < 5) {
+ ccputs("Usage: i2cxfer r/r16/w/w16 port addr offset [value]\n");
+ return EC_ERROR_UNKNOWN;
+ }
+
+ if (strcasecmp(argv[1], "r") == 0) {
+ rw = 0;
+ } else if (strcasecmp(argv[1], "r16") == 0) {
+ rw = 1;
+ } else if (strcasecmp(argv[1], "w") == 0) {
+ rw = 2;
+ } else if (strcasecmp(argv[1], "w16") == 0) {
+ rw = 3;
+ } else {
+ ccputs("Invalid rw mode : r / w / r16 / w16\n");
+ return EC_ERROR_INVAL;
+ }
+
+ port = strtoi(argv[2], &e, 0);
+ if (*e) {
+ ccputs("Invalid port\n");
+ return EC_ERROR_INVAL;
+ }
+
+ slave_addr = strtoi(argv[3], &e, 0);
+ if (*e) {
+ ccputs("Invalid slave_addr\n");
+ return EC_ERROR_INVAL;
+ }
+
+ offset = strtoi(argv[4], &e, 0);
+ if (*e) {
+ ccputs("Invalid addr\n");
+ return EC_ERROR_INVAL;
+ }
+
+ if (rw > 1) {
+ if (argc < 6) {
+ ccputs("No write value\n");
+ return EC_ERROR_INVAL;
+ }
+ value = strtoi(argv[5], &e, 0);
+ if (*e) {
+ ccputs("Invalid write value\n");
+ return EC_ERROR_INVAL;
+ }
+ }
+
+
+ switch (rw) {
+ case 0:
+ rv = i2c_read8(port, slave_addr, offset, &value);
+ break;
+ case 1:
+ rv = i2c_read16(port, slave_addr, offset, &value);
+ break;
+ case 2:
+ rv = i2c_write8(port, slave_addr, offset, value);
+ break;
+ case 3:
+ rv = i2c_write16(port, slave_addr, offset, value);
+ break;
+ }
+
+
+ if (rv) {
+ ccprintf("i2c command failed\n", rv);
+ return rv;
+ }
+
+ if (rw == 0)
+ ccprintf("0x%02x [%d]\n", value);
+ else if (rw == 1)
+ ccprintf("0x%04x [%d]\n", value);
+
+ ccputs("ok\n");
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(i2cxfer, command_i2cxfer,
+ "r/r16/w/w16 port addr offset [value]",
+ "Read write I2C",
+ NULL);