From: Nandor Han <nandor....@ge.com>

Tweak the i2c transfer to work for devices that want to read data
without addressing a register.

Signed-off-by: Nandor Han <nandor....@ge.com>
Signed-off-by: Martyn Welch <martyn.we...@collabora.co.uk>
Acked-by: Heiko Schocher <h...@denx.de>
Cc: Heiko Schocher <h...@denx.de>
Cc: Stefano Babic <sba...@denx.de>
---
Changes for v2:
   - Replacing '!= -1' with '>= 0'.

 drivers/i2c/mxc_i2c.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index abf1da2..205274e 100644
--- a/drivers/i2c/mxc_i2c.c
+++ b/drivers/i2c/mxc_i2c.c
@@ -317,16 +317,19 @@ static int i2c_init_transfer_(struct mxc_i2c_bus 
*i2c_bus, u8 chip,
        temp |= I2CR_MTX | I2CR_TX_NO_AK;
        writeb(temp, base + (I2CR << reg_shift));
 
-       /* write slave address */
-       ret = tx_byte(i2c_bus, chip << 1);
-       if (ret < 0)
-               return ret;
-
-       while (alen--) {
-               ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);
+       if (alen >= 0)  {
+               /* write slave address */
+               ret = tx_byte(i2c_bus, chip << 1);
                if (ret < 0)
                        return ret;
+
+               while (alen--) {
+                       ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);
+                       if (ret < 0)
+                               return ret;
+               }
        }
+
        return 0;
 }
 
@@ -537,9 +540,11 @@ static int bus_i2c_read(struct mxc_i2c_bus *i2c_bus, u8 
chip, u32 addr,
        if (ret < 0)
                return ret;
 
-       temp = readb(base + (I2CR << reg_shift));
-       temp |= I2CR_RSTA;
-       writeb(temp, base + (I2CR << reg_shift));
+       if (alen >= 0) {
+               temp = readb(base + (I2CR << reg_shift));
+               temp |= I2CR_RSTA;
+               writeb(temp, base + (I2CR << reg_shift));
+       }
 
        ret = tx_byte(i2c_bus, (chip << 1) | 1);
        if (ret < 0) {
-- 
2.1.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to