public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kuo-Jung Su <dantesu@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 3/4] i2c: fti2c010: serial out r/w address in MSB order
Date: Mon,  2 Dec 2013 16:02:58 +0800	[thread overview]
Message-ID: <1385971379-3096-4-git-send-email-dantesu@gmail.com> (raw)
In-Reply-To: <1385971379-3096-1-git-send-email-dantesu@gmail.com>

From: Kuo-Jung Su <dantesu@faraday-tech.com>

For a eeprom with a 2-bytes address (e.g., Ateml AT24C1024B),
the r/w address should be serial out in MSB order.

Signed-off-by: Kuo-Jung Su <dantesu@faraday-tech.com>
Cc: Heiko Schocher <hs@denx.de>
---
 Changes for v3:
  - Coding style update

 Changes for v2:
  - Initial release

 drivers/i2c/fti2c010.c |   26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/fti2c010.c b/drivers/i2c/fti2c010.c
index eccc1da..fb9fa35 100644
--- a/drivers/i2c/fti2c010.c
+++ b/drivers/i2c/fti2c010.c
@@ -179,6 +179,22 @@ static int fti2c010_probe(struct i2c_adapter *adap, u8 dev)
 	return ret;
 }

+static void to_i2c_addr(u8 *buf, uint32_t addr, int alen)
+{
+	int i, shift;
+
+	if (!buf || alen <= 0)
+		return;
+
+	/* MSB first */
+	i = 0;
+	shift = (alen - 1) * 8;
+	while (alen-- > 0) {
+		buf[i] = (u8)(addr >> shift);
+		shift -= 8;
+	}
+}
+
 static int fti2c010_read(struct i2c_adapter *adap,
 			u8 dev, uint addr, int alen, uchar *buf, int len)
 {
@@ -187,10 +203,7 @@ static int fti2c010_read(struct i2c_adapter *adap,
 	int ret, pos;
 	uchar paddr[4];

-	paddr[0] = (addr >> 0)  & 0xFF;
-	paddr[1] = (addr >> 8)  & 0xFF;
-	paddr[2] = (addr >> 16) & 0xFF;
-	paddr[3] = (addr >> 24) & 0xFF;
+	to_i2c_addr(paddr, addr, alen);

 	/*
 	 * Phase A. Set register address
@@ -252,10 +265,7 @@ static int fti2c010_write(struct i2c_adapter *adap,
 	int ret, pos;
 	uchar paddr[4];

-	paddr[0] = (addr >> 0)  & 0xFF;
-	paddr[1] = (addr >> 8)  & 0xFF;
-	paddr[2] = (addr >> 16) & 0xFF;
-	paddr[3] = (addr >> 24) & 0xFF;
+	to_i2c_addr(paddr, addr, alen);

 	/*
 	 * Phase A. Set register address
--
1.7.9.5

  parent reply	other threads:[~2013-12-02  8:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25  2:48 [U-Boot] [PATCH 0/2] i2c: fti2c010: migrate to new i2c model Kuo-Jung Su
2013-11-25  2:48 ` [U-Boot] [PATCH 1/2] i2c: fti2c010: cosmetic: coding style cleanup Kuo-Jung Su
2013-11-25  2:48 ` [U-Boot] [PATCH 2/2] i2c: fti2c010: migrate to new i2c model Kuo-Jung Su
2013-11-28  2:47 ` [U-Boot] [PATCH v2 0/4] i2c: fti2c010: bug fix & new driver model Kuo-Jung Su
2013-11-28  2:47   ` [U-Boot] [PATCH v2 1/4] i2c: fti2c010: cosmetic: coding style cleanup Kuo-Jung Su
2013-11-28  2:47   ` [U-Boot] [PATCH v2 2/4] i2c: fti2c010: migrate to new i2c model Kuo-Jung Su
2013-11-28  2:47   ` [U-Boot] [PATCH v2 3/4] i2c: fti2c010: serial out r/w address in MSB order Kuo-Jung Su
2013-11-28  2:47   ` [U-Boot] [PATCH v2 4/4] cmd_eeprom: bug fix for i2c read/write Kuo-Jung Su
2013-11-28 10:39     ` Alexey Brodkin
2013-11-29  0:59       ` Kuo-Jung Su
2013-11-29  9:10         ` Alexey Brodkin
2013-11-29  9:32           ` Kuo-Jung Su
2013-11-29  9:56             ` Alexey Brodkin
2013-11-29 15:04               ` Kuo-Jung Su
2013-12-02  2:57 ` [U-Boot] [PATCH v3 0/4] i2c: fti2c010: bug fix & new driver model Kuo-Jung Su
2013-12-02  2:57   ` [U-Boot] [PATCH v3 1/4] i2c: fti2c010: cosmetic: coding style cleanup Kuo-Jung Su
2013-12-02  7:30   ` [U-Boot] [PATCH v3 0/4] i2c: fti2c010: bug fix & new driver model Heiko Schocher
2013-12-02  8:09     ` Kuo-Jung Su
2013-12-02  8:36       ` Heiko Schocher
2013-12-02  8:02 ` Kuo-Jung Su
2013-12-02  8:02   ` [U-Boot] [PATCH v3 1/4] i2c: fti2c010: cosmetic: coding style cleanup Kuo-Jung Su
2013-12-09  6:52     ` [U-Boot] [U-Boot, v3, " Heiko Schocher
2013-12-02  8:02   ` [U-Boot] [PATCH v3 2/4] i2c: fti2c010: migrate to new i2c model Kuo-Jung Su
2013-12-09  6:53     ` [U-Boot] [U-Boot, v3, " Heiko Schocher
2013-12-02  8:02   ` Kuo-Jung Su [this message]
2013-12-09  6:55     ` [U-Boot] [U-Boot, v3, 3/4] i2c: fti2c010: serial out r/w address in MSB order Heiko Schocher
2013-12-02  8:02   ` [U-Boot] [PATCH v3 4/4] cmd_eeprom: bug fix for i2c read/write Kuo-Jung Su
2013-12-02 11:09     ` Alexey Brodkin
2013-12-03  0:55       ` Kuo-Jung Su
2013-12-03  7:42         ` Alexey Brodkin
2013-12-09  6:56     ` [U-Boot] [U-Boot, v3, " Heiko Schocher
2013-12-09 10:35       ` Alexey Brodkin
2013-12-09 11:21         ` Heiko Schocher
2013-12-10 10:18           ` Alexey Brodkin
2013-12-11  1:13             ` Kuo-Jung Su

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=1385971379-3096-4-git-send-email-dantesu@gmail.com \
    --to=dantesu@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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