mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <shc_work@mail.ru>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
Date: Fri, 11 May 2012 19:42:19 +0400	[thread overview]
Message-ID: <1336750939-18572-2-git-send-email-shc_work@mail.ru> (raw)
In-Reply-To: <1336750939-18572-1-git-send-email-shc_work@mail.ru>

---
 commands/i2c.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index 39bae35..1eaa968 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -74,10 +74,10 @@ static int do_i2c_write(int argc, char *argv[])
 {
 	struct i2c_adapter *adapter = NULL;
 	struct i2c_client client;
-	int addr = -1, reg = -1, count = -1, verbose = 0, ret, opt, i, bus = 0;
+	int addr = -1, reg = -1, count = -1, verbose = 0, ret, opt, i, bus = 0, wide = 0;
 	u8 *buf;
 
-	while ((opt = getopt(argc, argv, "a:b:r:v")) > 0) {
+	while ((opt = getopt(argc, argv, "a:b:r:v:w")) > 0) {
 		switch (opt) {
 		case 'a':
 			addr = simple_strtol(optarg, NULL, 0);
@@ -91,6 +91,9 @@ static int do_i2c_write(int argc, char *argv[])
 		case 'v':
 			verbose = 1;
 			break;
+		case 'w':
+			wide = 1;
+			break;
 		}
 	}
 
@@ -112,13 +115,13 @@ static int do_i2c_write(int argc, char *argv[])
 	for (i = 0; i < count; i++)
 		*(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 16);
 
-	ret = i2c_write_reg(&client, reg, buf, count);
+	ret = i2c_write_reg(&client, reg | (wide ? I2C_ADDR_16_BIT : 0), buf, count);
 	if (ret != count)
 		goto out;
 	ret = 0;
 
 	if (verbose) {
-		printf("wrote %i bytes starting at reg 0x%02x to i2cdev 0x%02x on bus %i\n",
+		printf("wrote %i bytes starting at reg 0x%04x to i2cdev 0x%02x on bus %i\n",
 			count, reg, addr, adapter->nr);
 		for (i = 0; i < count; i++)
 			printf("0x%02x ", *(buf + i));
@@ -135,7 +138,8 @@ static const __maybe_unused char cmd_i2c_write_help[] =
 "write to i2c device.\n"
 "  -a 0x<addr>   i2c device address\n"
 "  -b <bus_num>  i2c bus number (default = 0)\n"
-"  -r 0x<reg>    start register\n";
+"  -r 0x<reg>    start register\n"
+"  -w            use the word as an address\n";
 
 BAREBOX_CMD_START(i2c_write)
 	.cmd		= do_i2c_write,
@@ -148,9 +152,9 @@ static int do_i2c_read(int argc, char *argv[])
 	struct i2c_adapter *adapter = NULL;
 	struct i2c_client client;
 	u8 *buf;
-	int count = -1, addr = -1, reg = -1, verbose = 0, ret, opt, bus = 0;
+	int count = -1, addr = -1, reg = -1, verbose = 0, ret, opt, bus = 0, wide = 0;
 
-	while ((opt = getopt(argc, argv, "a:b:c:r:v")) > 0) {
+	while ((opt = getopt(argc, argv, "a:b:c:r:v:w")) > 0) {
 		switch (opt) {
 		case 'a':
 			addr = simple_strtol(optarg, NULL, 0);
@@ -167,6 +171,9 @@ static int do_i2c_read(int argc, char *argv[])
 		case 'v':
 			verbose = 1;
 			break;
+		case 'w':
+			wide = 1;
+			break;
 		}
 	}
 
@@ -183,11 +190,11 @@ static int do_i2c_read(int argc, char *argv[])
 	client.addr = addr;
 
 	buf = xmalloc(count);
-	ret = i2c_read_reg(&client, reg, buf, count);
+	ret = i2c_read_reg(&client, reg | (wide ? I2C_ADDR_16_BIT : 0), buf, count);
 	if (ret == count) {
 		int i;
 		if (verbose)
-			printf("read %i bytes starting at reg 0x%02x from i2cdev 0x%02x on bus %i\n",
+			printf("read %i bytes starting at reg 0x%04x from i2cdev 0x%02x on bus %i\n",
 				count, reg, addr, adapter->nr);
 		for (i = 0; i < count; i++)
 			printf("0x%02x ", *(buf + i));
@@ -205,6 +212,7 @@ static const __maybe_unused char cmd_i2c_read_help[] =
 "  -a 0x<addr>   i2c device address\n"
 "  -b <bus_num>  i2c bus number (default = 0)\n"
 "  -r 0x<reg>    start register\n"
+"  -w            use the word as an address\n"
 "  -c <count>    byte count\n";
 
 BAREBOX_CMD_START(i2c_read)
-- 
1.7.3.4


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

  reply	other threads:[~2012-05-11 15:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 15:42 [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command Alexander Shiyan
2012-05-11 15:42 ` Alexander Shiyan [this message]
2012-05-11 18:15   ` [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses Sascha Hauer
2012-05-11 18:17     ` Re[2]: " Alexander Shiyan
2012-05-11 18:35       ` Sascha Hauer
2012-05-11 18:58         ` Alexander Shiyan
2012-05-11 20:02           ` Sascha Hauer
2012-05-11 20:17             ` [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command Alexander Shiyan
2012-05-11 20:17             ` [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses Alexander Shiyan
2012-05-11 18:12 ` [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336750939-18572-2-git-send-email-shc_work@mail.ru \
    --to=shc_work@mail.ru \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox