mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* i2c master send/receive mode
@ 2018-08-21 15:18 Aleksander Morgado
  2018-08-21 15:18 ` [PATCH 1/2] i2c_write: document master send mode Aleksander Morgado
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aleksander Morgado @ 2018-08-21 15:18 UTC (permalink / raw)
  To: barebox, s.hauer

The i2c master send support was already implemented in the i2c_write command, but it was not properly documented. The first patch in the series addresses that.

In the second patch, the i2c master receive mode is implemented in the i2c_read command.

 [PATCH 1/2] i2c_write: document master send mode
 [PATCH 2/2] i2c_read: implement support for master receive mode


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] i2c_write: document master send mode
  2018-08-21 15:18 i2c master send/receive mode Aleksander Morgado
@ 2018-08-21 15:18 ` Aleksander Morgado
  2018-08-21 15:18 ` [PATCH 2/2] i2c_read: implement support for master receive mode Aleksander Morgado
  2018-08-22  7:37 ` i2c master send/receive mode Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Aleksander Morgado @ 2018-08-21 15:18 UTC (permalink / raw)
  To: barebox, s.hauer; +Cc: Aleksander Morgado

When no explicit start register is given, the i2c message is emitted
in master send mode.

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
 commands/i2c.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index f0d16af0c..57dc092c2 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -145,8 +145,12 @@ static int do_i2c_write(int argc, char *argv[])
 	ret = 0;
 
 	if (verbose) {
-		printf("wrote %i bytes starting at reg 0x%04x to i2cdev 0x%02x on bus %i\n",
-			count, reg, addr, adapter->nr);
+		if (reg >= 0)
+			printf("wrote %i bytes starting at reg 0x%04x to i2cdev 0x%02x on bus %i\n",
+			       count, reg, addr, adapter->nr);
+		else
+			printf("sent %i bytes in master send mode to i2cdev 0x%02x on bus %i\n",
+			       count, addr, adapter->nr);
 		for (i = 0; i < count; i++)
 			printf("0x%02x ", *(buf + i));
 		printf("\n");
@@ -161,7 +165,7 @@ BAREBOX_CMD_HELP_START(i2c_write)
 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 send mode if none given)")
 BAREBOX_CMD_HELP_OPT ("-w\t",       "use word (16 bit) wide access")
 BAREBOX_CMD_HELP_OPT ("-v\t",       "verbose")
 BAREBOX_CMD_HELP_END
-- 
2.18.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] i2c_read: implement support for master receive mode
  2018-08-21 15:18 i2c master send/receive mode Aleksander Morgado
  2018-08-21 15:18 ` [PATCH 1/2] i2c_write: document master send mode Aleksander Morgado
@ 2018-08-21 15:18 ` Aleksander Morgado
  2018-08-22  7:37 ` i2c master send/receive mode Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Aleksander Morgado @ 2018-08-21 15:18 UTC (permalink / raw)
  To: barebox, s.hauer; +Cc: Aleksander Morgado

If no start register is explicitly given, receive data in master
receive mode.

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
 commands/i2c.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index 57dc092c2..2f7f820d4 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")
-- 
2.18.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: i2c master send/receive mode
  2018-08-21 15:18 i2c master send/receive mode Aleksander Morgado
  2018-08-21 15:18 ` [PATCH 1/2] i2c_write: document master send mode Aleksander Morgado
  2018-08-21 15:18 ` [PATCH 2/2] i2c_read: implement support for master receive mode Aleksander Morgado
@ 2018-08-22  7:37 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-08-22  7:37 UTC (permalink / raw)
  To: Aleksander Morgado; +Cc: barebox

On Tue, Aug 21, 2018 at 05:18:24PM +0200, Aleksander Morgado wrote:
> The i2c master send support was already implemented in the i2c_write command, but it was not properly documented. The first patch in the series addresses that.
> 
> In the second patch, the i2c master receive mode is implemented in the i2c_read command.
> 
>  [PATCH 1/2] i2c_write: document master send mode
>  [PATCH 2/2] i2c_read: implement support for master receive mode

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-22  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-21 15:18 i2c master send/receive mode Aleksander Morgado
2018-08-21 15:18 ` [PATCH 1/2] i2c_write: document master send mode Aleksander Morgado
2018-08-21 15:18 ` [PATCH 2/2] i2c_read: implement support for master receive mode Aleksander Morgado
2018-08-22  7:37 ` i2c master send/receive mode Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox