summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2018-08-21 17:18:26 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-22 09:36:58 +0200
commit079f92099a694544a04e619a3748da3defe4f4b4 (patch)
tree602ca2145b9ee92909fb57ce748e88e67b67e835 /commands
parent0657fdc4cdc847c3f3bdc567405c1d115fc54ba2 (diff)
downloadbarebox-079f92099a694544a04e619a3748da3defe4f4b4.tar.gz
i2c_read: implement support for master receive mode
If no start register is explicitly given, receive data in master receive mode. Signed-off-by: Aleksander Morgado <aleksander@aleksander.es> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/i2c.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/commands/i2c.c b/commands/i2c.c
index 57dc092..2f7f820 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -208,7 +208,7 @@ static int do_i2c_read(int argc, char *argv[])
}
}
- if ((addr < 0) || (reg < 0) || (count < 1) || (addr > 0x7F))
+ if ((addr < 0) || (count < 1) || (addr > 0x7F))
return COMMAND_ERROR_USAGE;
adapter = i2c_get_adapter(bus);
@@ -221,12 +221,21 @@ static int do_i2c_read(int argc, char *argv[])
client.addr = addr;
buf = xmalloc(count);
- ret = i2c_read_reg(&client, reg | wide, buf, count);
+ if (reg >= 0)
+ ret = i2c_read_reg(&client, reg | wide, buf, count);
+ else
+ ret = i2c_master_recv(&client, buf, count);
if (ret == count) {
int i;
- if (verbose)
- printf("read %i bytes starting at reg 0x%04x from i2cdev 0x%02x on bus %i\n",
- count, reg, addr, adapter->nr);
+ if (verbose) {
+ if (reg >= 0)
+ printf("read %i bytes starting at reg 0x%04x from i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ else
+ printf("received %i bytes in master receive mode from i2cdev 0x%02x on bus %i\n",
+ count, addr, adapter->nr);
+ }
+
for (i = 0; i < count; i++)
printf("0x%02x ", *(buf + i));
printf("\n");
@@ -241,7 +250,7 @@ BAREBOX_CMD_HELP_START(i2c_read)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT("-b BUS\t", "i2c bus number (default 0)")
BAREBOX_CMD_HELP_OPT("-a ADDR\t", "i2c device address")
-BAREBOX_CMD_HELP_OPT("-r START", "start register")
+BAREBOX_CMD_HELP_OPT("-r START", "start register (optional, master receive mode if none given)")
BAREBOX_CMD_HELP_OPT("-w\t", "use word (16 bit) wide access")
BAREBOX_CMD_HELP_OPT("-c COUNT", "byte count")
BAREBOX_CMD_HELP_OPT("-v\t", "verbose")