Skip to contentSkip to conversation

commands: i2c_write: enable raw write to address

RFC In review Antony Pavlov 2 participants 6 messages Feb 8, 2018 – Feb 16, 2018

lore
Share & tools
lore
#0 lore raw

RFC 1/1 commands: i2c_write: enable raw write to address

Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device.
Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters:
'device address', 'register number' and 'data'.

This commit fixes the problem.

Sample usage:

barebox@barebox sandbox:/ i2c_write -a 0x24 0x01

---
 commands/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
commands/i2c.c +6 -2
index b74c53509f..21c39fe5af 100644
@@ -115,7 +115,7 @@ static int do_i2c_write(int argc, char *argv[])
 
 	count = argc - optind;
 
-	if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+	if ((addr < 0) || (count == 0) || (addr > 0x7F))
 		return COMMAND_ERROR_USAGE;
 
 	adapter = i2c_get_adapter(bus);
@@ -131,7 +131,11 @@ static int do_i2c_write(int argc, char *argv[])
 	for (i = 0; i < count; i++)
 		*(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 0);
 
-	ret = i2c_write_reg(&client, reg | wide, buf, count);
+	if (reg > 0) {
+		ret = i2c_write_reg(&client, reg | wide, buf, count);
+	} else {
+		ret = i2c_master_send(&client, buf, count);
+	}
 	if (ret != count) {
 		if (verbose)
 			printf("write aborted, count(%i) != writestatus(%i)\n",
Signature · 7 lines
2.15.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Antony,

Quoted 11 lines · Antony Pavlov

Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device.
Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters:
'device address', 'register number' and 'data'.

This commit fixes the problem.

Quoted 8 lines

Sample usage:

barebox@barebox sandbox:/ i2c_write -a 0x24 0x01

---
 commands/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Looks good to me.

I applied this one despite the [RFC] tag. If for some reason you want to resend this, feel free to do so, but otherwise consider this applied.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
Quoted 23 lines · On Fri, 9 Feb 2018 09:36:36 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 11 lines · Antony Pavlov

Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device.
Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters:
'device address', 'register number' and 'data'.

This commit fixes the problem.

Quoted 8 lines

Sample usage:

barebox@barebox sandbox:/ i2c_write -a 0x24 0x01

---
 commands/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 4 lines

Looks good to me.

I applied this one despite the [RFC] tag. If for some reason you want to resend this, feel free to do so, but otherwise consider this applied.

Thanks!

The patch is short, it's understandable and it fixes the problem. I prefere to apply this patch as is.

I see some inconsistency in drivers/i2c/i2c.c.
We have i2c_master_send() and i2c_write_reg() functions. These functions are intended to make similar work but they are written in very different style. I suppose that we can rewrite i2c_master_send() (e.g. drop FIXME) and make i2c_write_reg() work on top of i2c_master_send(). Any comments?

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
Quoted 36 lines · Antony Pavlov
Quoted 23 lines · On Fri, 9 Feb 2018 09:36:36 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 11 lines · Antony Pavlov

Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device.
Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters:
'device address', 'register number' and 'data'.

This commit fixes the problem.

Quoted 8 lines

Sample usage:

barebox@barebox sandbox:/ i2c_write -a 0x24 0x01

---
 commands/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 4 lines

Looks good to me.

I applied this one despite the [RFC] tag. If for some reason you want to resend this, feel free to do so, but otherwise consider this applied.

Thanks!

The patch is short, it's understandable and it fixes the problem. I prefere to apply this patch as is.

Quoted 6 lines

I see some inconsistency in drivers/i2c/i2c.c.
We have i2c_master_send() and i2c_write_reg() functions. These functions are intended to make similar work but they are written in very different style. I suppose that we can rewrite i2c_master_send() (e.g. drop FIXME) and make i2c_write_reg() work on top of i2c_master_send(). Any comments?

Rewrite i2c_master_send()? Do you mean rewrite i2c_write_reg() instead?

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw
Quoted 37 lines · On Tue, 13 Feb 2018 09:19:43 +0100 Sascha Hauer <[email protected]> wrote:
Quoted 36 lines · Antony Pavlov
Quoted 23 lines · On Fri, 9 Feb 2018 09:36:36 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 11 lines · Antony Pavlov

Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device.
Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters:
'device address', 'register number' and 'data'.

This commit fixes the problem.

Quoted 8 lines

Sample usage:

barebox@barebox sandbox:/ i2c_write -a 0x24 0x01

---
 commands/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 4 lines

Looks good to me.

I applied this one despite the [RFC] tag. If for some reason you want to resend this, feel free to do so, but otherwise consider this applied.

Thanks!

The patch is short, it's understandable and it fixes the problem. I prefere to apply this patch as is.

Quoted 8 lines
Quoted 6 lines

I see some inconsistency in drivers/i2c/i2c.c.
We have i2c_master_send() and i2c_write_reg() functions. These functions are intended to make similar work but they are written in very different style. I suppose that we can rewrite i2c_master_send() (e.g. drop FIXME) and make i2c_write_reg() work on top of i2c_master_send(). Any comments?

Rewrite i2c_master_send()? Do you mean rewrite i2c_write_reg() instead?

You are right, of course I propose rewrite i2c_write_reg() (there is no FIXME comment inside i2c_master_send()).

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw
Quoted 47 lines · Antony Pavlov
Quoted 44 lines · On Tue, 13 Feb 2018 09:19:43 +0100 Sascha Hauer <[email protected]> wrote:
Quoted 42 lines · Antony Pavlov
Quoted 23 lines · On Fri, 9 Feb 2018 09:36:36 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 11 lines · Antony Pavlov

Sometimes for communication with a simple I2C devices (e.g. PCF8574 or TM1650) it's necessary to send only one data byte into the I2C device.
Current i2c_write command makes this impossible because you can't just pass 'device address' and 'register number' (or 'device address' and 'one data byte') to the command. You always have to pass all three parameters:
'device address', 'register number' and 'data'.

This commit fixes the problem.

Quoted 8 lines

Sample usage:

barebox@barebox sandbox:/ i2c_write -a 0x24 0x01

---
 commands/i2c.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 4 lines

Looks good to me.

I applied this one despite the [RFC] tag. If for some reason you want to resend this, feel free to do so, but otherwise consider this applied.

Thanks!

The patch is short, it's understandable and it fixes the problem. I prefere to apply this patch as is.

I see some inconsistency in drivers/i2c/i2c.c.
We have i2c_master_send() and i2c_write_reg() functions. These functions are intended to make similar work but they are written in very different style. I suppose that we can rewrite i2c_master_send() (e.g. drop FIXME) and make i2c_write_reg() work on top of i2c_master_send(). Any comments?

Quoted 4 lines
Quoted 1 line

Rewrite i2c_master_send()? Do you mean rewrite i2c_write_reg() instead?

You are right, of course I propose rewrite i2c_write_reg() (there is no FIXME comment inside i2c_master_send()).

Ok, that should work I think. Feel free to propose a patch.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox