public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] common/i2c: Add i2c write command
@ 2012-09-16 18:02 York Sun
  2012-09-17 22:16 ` Tom Rini
  2012-10-16  3:57 ` Heiko Schocher
  0 siblings, 2 replies; 9+ messages in thread
From: York Sun @ 2012-09-16 18:02 UTC (permalink / raw)
  To: u-boot

Add i2c write command to write data from memory to i2c devices.

Signed-off-by: York Sun <yorksun@freescale.com>
---
 common/cmd_i2c.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index 2cdc4ed..6099115 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -223,6 +223,54 @@ static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
 	return 0;
 }
 
+static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	u_char	chip;
+	uint	devaddr, alen, length;
+	u_char  *memaddr;
+
+	if (argc != 5)
+		return cmd_usage(cmdtp);
+
+	/*
+	 * memaddr is the address where to store things in memory
+	 */
+	memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
+
+	/*
+	 * I2C chip address
+	 */
+	chip = simple_strtoul(argv[2], NULL, 16);
+
+	/*
+	 * I2C data address within the chip.  This can be 1 or
+	 * 2 bytes long.  Some day it might be 3 bytes long :-).
+	 */
+	devaddr = simple_strtoul(argv[3], NULL, 16);
+	alen = get_alen(argv[3]);
+	if (alen > 3)
+		return cmd_usage(cmdtp);
+
+	/*
+	 * Length is the number of objects, not number of bytes.
+	 */
+	length = simple_strtoul(argv[4], NULL, 16);
+
+	while (length-- > 0) {
+		if (i2c_write(chip, devaddr++, alen, memaddr++, 1) != 0) {
+			puts("Error writing to the chip.\n");
+			return 1;
+		}
+/*
+ * No write delay with FRAM devices.
+ */
+#if !defined(CONFIG_SYS_I2C_FRAM)
+		udelay(11000);
+#endif
+	}
+	return 0;
+}
+
 /*
  * Syntax:
  *	i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
@@ -1282,6 +1330,7 @@ static cmd_tbl_t cmd_i2c_sub[] = {
 	U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
 	U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
 	U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
+	U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", ""),
 	U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
 #if defined(CONFIG_CMD_SDRAM)
 	U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
@@ -1333,6 +1382,7 @@ U_BOOT_CMD(
 	"i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
 	"i2c probe - show devices on the I2C bus\n"
 	"i2c read chip address[.0, .1, .2] length memaddress - read to memory \n"
+	"i2c write memaddress chip address[.0, .1, .2] length - write memory to i2c\n"
 	"i2c reset - re-init the I2C Controller\n"
 #if defined(CONFIG_CMD_SDRAM)
 	"i2c sdram chip - print SDRAM configuration information\n"
-- 
1.7.9.5

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-16 18:02 [U-Boot] [PATCH] common/i2c: Add i2c write command York Sun
@ 2012-09-17 22:16 ` Tom Rini
  2012-09-17 23:29   ` sun york-R58495
  2012-10-16  3:57 ` Heiko Schocher
  1 sibling, 1 reply; 9+ messages in thread
From: Tom Rini @ 2012-09-17 22:16 UTC (permalink / raw)
  To: u-boot

On Sun, Sep 16, 2012 at 01:02:30PM -0500, York Sun wrote:

> Add i2c write command to write data from memory to i2c devices.
> 
> Signed-off-by: York Sun <yorksun@freescale.com>

This feels like eeprom write, to an i2c-connected eeprom.  Is that what
you have this for, or something else?

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120917/dc99f4a4/attachment.pgp>

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-17 22:16 ` Tom Rini
@ 2012-09-17 23:29   ` sun york-R58495
  2012-09-17 23:36     ` Tom Rini
  0 siblings, 1 reply; 9+ messages in thread
From: sun york-R58495 @ 2012-09-17 23:29 UTC (permalink / raw)
  To: u-boot

Tom,

It's like eeprom write but it writes to general devices, not specificly to system eeprom. I would have to use i2c mw command a lot without this.

York

-------- Original Message --------
From: Tom Rini
Sent: Mon, Sep 17, 2012 05:16 PM
To: sun york-R58495
CC: u-boot at lists.denx.de; u-boot-release at linux.freescale.net; Heiko Schocher
Subject: Re: [U-Boot] [PATCH] common/i2c: Add i2c write command


On Sun, Sep 16, 2012 at 01:02:30PM -0500, York Sun wrote:

> Add i2c write command to write data from memory to i2c devices.
>
> Signed-off-by: York Sun <yorksun@freescale.com>

This feels like eeprom write, to an i2c-connected eeprom.  Is that what
you have this for, or something else?

--
Tom

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-17 23:29   ` sun york-R58495
@ 2012-09-17 23:36     ` Tom Rini
  2012-09-18  3:57       ` York Sun
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2012-09-17 23:36 UTC (permalink / raw)
  To: u-boot

On Mon, Sep 17, 2012 at 11:29:00PM +0000, sun york-R58495 wrote:

> Tom,
> 
> It's like eeprom write but it writes to general devices, not specificly to system eeprom. I would have to use i2c mw command a lot without this.

Right.  I guess what I'm getting at is, are you writing to some sort
of other device or writing bits to storage attached to i2c?  Does it
really not make sense to just use 'eeprom write' even if it's not
technically for The System EEPROM but rather some storage (or a number
of storage chips) attached via i2c?

I'm not objecting to i2c write mind you, I was wishing for something
like this when I stumbled on CONFIG_CMD_EEPROM which did what I needed.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120917/104a8b5c/attachment.pgp>

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-17 23:36     ` Tom Rini
@ 2012-09-18  3:57       ` York Sun
  2012-09-25 19:59         ` York Sun
  0 siblings, 1 reply; 9+ messages in thread
From: York Sun @ 2012-09-18  3:57 UTC (permalink / raw)
  To: u-boot

On 09/17/2012 06:36 PM, Tom Rini wrote:
> On Mon, Sep 17, 2012 at 11:29:00PM +0000, sun york-R58495 wrote:
>
>> Tom,
>>
>> It's like eeprom write but it writes to general devices, not specificly to system eeprom. I would have to use i2c mw command a lot without this.
>
> Right.  I guess what I'm getting at is, are you writing to some sort
> of other device or writing bits to storage attached to i2c?  Does it
> really not make sense to just use 'eeprom write' even if it's not
> technically for The System EEPROM but rather some storage (or a number
> of storage chips) attached via i2c?
>
> I'm not objecting to i2c write mind you, I was wishing for something
> like this when I stumbled on CONFIG_CMD_EEPROM which did what I needed.
>

Tom,

I have a case under debugging where I need to use i2c write to devices. 
One device (EEPROM) has two-byte address length and most others 
(including other EEPROMs) have one byte address length. I also have 
other non-storage devices but I wouldn't use "i2c write" because "i2c 
mw" will be sufficient. eeprom command has its limitation for the case 
of variable device address and variable address length.

York

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-18  3:57       ` York Sun
@ 2012-09-25 19:59         ` York Sun
  2012-09-25 20:21           ` Tom Rini
  0 siblings, 1 reply; 9+ messages in thread
From: York Sun @ 2012-09-25 19:59 UTC (permalink / raw)
  To: u-boot

On 09/17/2012 08:57 PM, York Sun wrote:
> I have a case under debugging where I need to use i2c write to devices.
> One device (EEPROM) has two-byte address length and most others
> (including other EEPROMs) have one byte address length. I also have
> other non-storage devices but I wouldn't use "i2c write" because "i2c
> mw" will be sufficient. eeprom command has its limitation for the case
> of variable device address and variable address length.
>

Tom,

Do I need to change this patch in any way? I see it is still "under 
review" in patchwork.

York

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-25 19:59         ` York Sun
@ 2012-09-25 20:21           ` Tom Rini
  2012-09-27  5:47             ` Heiko Schocher
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2012-09-25 20:21 UTC (permalink / raw)
  To: u-boot

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/25/12 12:59, York Sun wrote:
> On 09/17/2012 08:57 PM, York Sun wrote:
>> I have a case under debugging where I need to use i2c write to 
>> devices. One device (EEPROM) has two-byte address length and
>> most others (including other EEPROMs) have one byte address
>> length. I also have other non-storage devices but I wouldn't use
>> "i2c write" because "i2c mw" will be sufficient. eeprom command
>> has its limitation for the case of variable device address and 
>> variable address length.
>> 
> 
> Tom,
> 
> Do I need to change this patch in any way? I see it is still "under
> review" in patchwork.

I am fine with it.  This falls to Heiko now, thanks.

- -- 
Tom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQYhItAAoJENk4IS6UOR1WsbwP/R8Uuvih8dFBR6TTHyIuyIfF
O32bPad2IqlnZngiuiX9YKWjD2ZIr3sKCDClDJnXGqdBZl0A+JABFbWzeqfEgmTW
f62NAfNjDWlHzvCr1DbapMb6XCbJ5myHU+Bo0KDc0ObV6/Fl54p4pDmREEGGVfzN
o1quFJvBOcQSV8VNrj2YhMfZUkG9TE0+bYvZ4QUR9En8Q7PFQNyrOjni6iudV83Y
/61tIsqEQdCp5aOe0CbuWfeeTXDLlIrJ0O78f1enpfzMRxTJ6wt4a4/LCIbeI7JV
Ji78P+atTACS3p+6EpyBxLaxofOCgLSmOEB9b8X4jGZjoMrbqpc6fOYLh2xVDS6W
oUhRueEdx4NJ9gio/aekn8wnkw3u3WkD3AL+x4+APZrilTiKPtwhfgyVxbgJXAFh
VbCJ6CfVkWYpak6roJH627RsHfvBR8PrGb169sKrDPSiWOL/zNmJ6700Vd0VPJZf
462zRxeyobTA1D6YcfAPxoV7fgBho/ze6CHgizOtMGpZS+RlxnewLs0rtmSnU+2s
jY/vHQxyN+5ColfvZpvgAfME9HPD1efhTW74rS8MdPbg8iucMz1561mxjvfCGZSg
YgHIwR3ls8hb3D1b7zFLG8bs7ESWXagIKJz7Sq2B4Heg9o6JzgY2q4Yk+lway8Ib
X8Wwdk3Iv43o4oY4wd4K
=ANCQ
-----END PGP SIGNATURE-----

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-25 20:21           ` Tom Rini
@ 2012-09-27  5:47             ` Heiko Schocher
  0 siblings, 0 replies; 9+ messages in thread
From: Heiko Schocher @ 2012-09-27  5:47 UTC (permalink / raw)
  To: u-boot

Hello Tom, York,

On 25.09.2012 22:21, Tom Rini wrote:
[...]
>> Tom,
>>
>> Do I need to change this patch in any way? I see it is still "under
>> review" in patchwork.
>
> I am fine with it.  This falls to Heiko now, thanks.

It looks good to me too. I add it in the next merge window.

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

* [U-Boot] [PATCH] common/i2c: Add i2c write command
  2012-09-16 18:02 [U-Boot] [PATCH] common/i2c: Add i2c write command York Sun
  2012-09-17 22:16 ` Tom Rini
@ 2012-10-16  3:57 ` Heiko Schocher
  1 sibling, 0 replies; 9+ messages in thread
From: Heiko Schocher @ 2012-10-16  3:57 UTC (permalink / raw)
  To: u-boot

Hello York Sun,

On 16.09.2012 20:02, York Sun wrote:
> Add i2c write command to write data from memory to i2c devices.
>
> Signed-off-by: York Sun<yorksun@freescale.com>
> ---
>   common/cmd_i2c.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 50 insertions(+)

Applied to u-boot-i2c master

Thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

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

end of thread, other threads:[~2012-10-16  3:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-16 18:02 [U-Boot] [PATCH] common/i2c: Add i2c write command York Sun
2012-09-17 22:16 ` Tom Rini
2012-09-17 23:29   ` sun york-R58495
2012-09-17 23:36     ` Tom Rini
2012-09-18  3:57       ` York Sun
2012-09-25 19:59         ` York Sun
2012-09-25 20:21           ` Tom Rini
2012-09-27  5:47             ` Heiko Schocher
2012-10-16  3:57 ` Heiko Schocher

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