mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command
@ 2012-05-11 15:42 Alexander Shiyan
  2012-05-11 15:42 ` [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
  0 siblings, 2 replies; 10+ messages in thread
From: Alexander Shiyan @ 2012-05-11 15:42 UTC (permalink / raw)
  To: barebox

Running i2c_read without the 'count' setting causes an error and reboots.

barebox@Phytec phyCORE-i.MX27:/ i2c_read -b 1 -a 0x4a -r 0x00
ERROR: out of memory
no stack data available
---
 commands/i2c.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index b3d09dc..39bae35 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -170,7 +170,7 @@ static int do_i2c_read(int argc, char *argv[])
 		}
 	}
 
-	if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+	if ((addr < 0) || (reg < 0) || (count < 1) || (addr > 0x7F))
 		return COMMAND_ERROR_USAGE;
 
 	adapter = i2c_get_adapter(bus);
-- 
1.7.3.4


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

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

* [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  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
  2012-05-11 18:15   ` Sascha Hauer
  2012-05-11 18:12 ` [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command Sascha Hauer
  1 sibling, 1 reply; 10+ messages in thread
From: Alexander Shiyan @ 2012-05-11 15:42 UTC (permalink / raw)
  To: barebox

---
 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

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

* Re: [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command
  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 ` [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses Alexander Shiyan
@ 2012-05-11 18:12 ` Sascha Hauer
  1 sibling, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-05-11 18:12 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, May 11, 2012 at 07:42:18PM +0400, Alexander Shiyan wrote:
> Running i2c_read without the 'count' setting causes an error and reboots.
> 

Applied to master.

Thanks
 Sascha

> barebox@Phytec phyCORE-i.MX27:/ i2c_read -b 1 -a 0x4a -r 0x00
> ERROR: out of memory
> no stack data available
> ---
>  commands/i2c.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/commands/i2c.c b/commands/i2c.c
> index b3d09dc..39bae35 100644
> --- a/commands/i2c.c
> +++ b/commands/i2c.c
> @@ -170,7 +170,7 @@ static int do_i2c_read(int argc, char *argv[])
>  		}
>  	}
>  
> -	if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
> +	if ((addr < 0) || (reg < 0) || (count < 1) || (addr > 0x7F))
>  		return COMMAND_ERROR_USAGE;
>  
>  	adapter = i2c_get_adapter(bus);
> -- 
> 1.7.3.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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] 10+ messages in thread

* Re: [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  2012-05-11 15:42 ` [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses Alexander Shiyan
@ 2012-05-11 18:15   ` Sascha Hauer
  2012-05-11 18:17     ` Re[2]: " Alexander Shiyan
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-05-11 18:15 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, May 11, 2012 at 07:42:19PM +0400, Alexander Shiyan wrote:
> ---
>  			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";

Can we have 'do word (16bit) accesses' here to make this a bit more
explicit?

> @@ -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";

ditto

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] 10+ messages in thread

* Re[2]: [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  2012-05-11 18:15   ` Sascha Hauer
@ 2012-05-11 18:17     ` Alexander Shiyan
  2012-05-11 18:35       ` Sascha Hauer
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Shiyan @ 2012-05-11 18:17 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Fri, 11 May 2012 20:15:08 +0200 от Sascha Hauer <s.hauer@pengutronix.de>:
> On Fri, May 11, 2012 at 07:42:19PM +0400, Alexander Shiyan wrote:
> > ---
> >  			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";
> Can we have 'do word (16bit) accesses' here to make this a bit more
> explicit?
Maybe "use 16bit-wide address access" ?
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  2012-05-11 18:17     ` Re[2]: " Alexander Shiyan
@ 2012-05-11 18:35       ` Sascha Hauer
  2012-05-11 18:58         ` Alexander Shiyan
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-05-11 18:35 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, May 11, 2012 at 10:17:25PM +0400, Alexander Shiyan wrote:
> Fri, 11 May 2012 20:15:08 +0200 от Sascha Hauer <s.hauer@pengutronix.de>:
> > On Fri, May 11, 2012 at 07:42:19PM +0400, Alexander Shiyan wrote:
> > > ---
> > >  			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";
> > Can we have 'do word (16bit) accesses' here to make this a bit more
> > explicit?
> Maybe "use 16bit-wide address access" ?

Fine. It has 16bit and a word with 'w' in it ;)

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] 10+ messages in thread

* [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  2012-05-11 18:35       ` Sascha Hauer
@ 2012-05-11 18:58         ` Alexander Shiyan
  2012-05-11 20:02           ` Sascha Hauer
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Shiyan @ 2012-05-11 18:58 UTC (permalink / raw)
  To: barebox

---
 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 16bit-wide address access\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 16bit-wide address access\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

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

* Re: [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-05-11 20:02 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, May 11, 2012 at 10:58:49PM +0400, Alexander Shiyan wrote:
> ---
>  commands/i2c.c |   26 +++++++++++++++++---------
>  1 files changed, 17 insertions(+), 9 deletions(-)
> 

Applied and realized afterwards that you forgot to sign off your
patches. Please resend this one, I'll replace it.

Sascha

> 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 16bit-wide address access\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 16bit-wide address access\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
> 

-- 
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] 10+ messages in thread

* [PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command
  2012-05-11 20:02           ` Sascha Hauer
@ 2012-05-11 20:17             ` Alexander Shiyan
  2012-05-11 20:17             ` [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses Alexander Shiyan
  1 sibling, 0 replies; 10+ messages in thread
From: Alexander Shiyan @ 2012-05-11 20:17 UTC (permalink / raw)
  To: barebox

Running i2c_read without the 'count' setting causes an error and reboots.

barebox@Phytec phyCORE-i.MX27:/ i2c_read -b 1 -a 0x4a -r 0x00
ERROR: out of memory
no stack data available

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 commands/i2c.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index b3d09dc..39bae35 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -170,7 +170,7 @@ static int do_i2c_read(int argc, char *argv[])
 		}
 	}
 
-	if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+	if ((addr < 0) || (reg < 0) || (count < 1) || (addr > 0x7F))
 		return COMMAND_ERROR_USAGE;
 
 	adapter = i2c_get_adapter(bus);
-- 
1.7.3.4


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

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

* [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses
  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             ` Alexander Shiyan
  1 sibling, 0 replies; 10+ messages in thread
From: Alexander Shiyan @ 2012-05-11 20:17 UTC (permalink / raw)
  To: barebox


Signed-off-by: Alexander Shiyan <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 16bit-wide address access\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 16bit-wide address access\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

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

end of thread, other threads:[~2012-05-11 20:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] i2c: Added switch for allowing usage 16bit register addresses Alexander Shiyan
2012-05-11 18:15   ` 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

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