diff options
author | Kuo-Jung Su <dantesu@faraday-tech.com> | 2013-12-02 16:02:58 +0800 |
---|---|---|
committer | Heiko Schocher <hs@denx.de> | 2013-12-05 12:25:01 +0100 |
commit | c727618d2cee0b848e5349ec923a5ef0bc3f0447 (patch) | |
tree | 4d7e7795aaa1427a5ebc3de621d54b1c0f39d7f5 /drivers/i2c | |
parent | 49f4c762e4a14cb4b8088bcc0726d7b1ce80e014 (diff) |
i2c: fti2c010: serial out r/w address in MSB order
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>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/fti2c010.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/drivers/i2c/fti2c010.c b/drivers/i2c/fti2c010.c index eccc1da468c..fb9fa353d10 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 |