summaryrefslogtreecommitdiff
path: root/drivers/i2c/fsl_i2c.c
diff options
context:
space:
mode:
authorReinhard Pfau <pfau@gdsys.de>2013-06-26 15:55:14 +0200
committerAndy Fleming <afleming@freescale.com>2013-07-16 17:44:30 -0500
commitb778c1b5debc4176baf93ed5085498e603f99343 (patch)
tree7407277be12748865e299c7facee99f7589ea752 /drivers/i2c/fsl_i2c.c
parentbe6c1529c1ce9718cc955f23fdaa5891d15b6551 (diff)
downloadu-boot-imx-b778c1b5debc4176baf93ed5085498e603f99343.zip
u-boot-imx-b778c1b5debc4176baf93ed5085498e603f99343.tar.gz
u-boot-imx-b778c1b5debc4176baf93ed5085498e603f99343.tar.bz2
i2c: fsl_i2c: i2c_read(): dont try to write address w/ alen=0
if alen is 0: no longer start a write cycle before reading data. Signed-off-by: Dirk Eibach <dirk.eibach@gdsys.cc> Signed-off-by: Reinhard Pfau <reinhard.pfau@gdsys.cc> Acked-by: Heiko Schocher <hs@denx.de> Signed-off-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'drivers/i2c/fsl_i2c.c')
-rw-r--r--drivers/i2c/fsl_i2c.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
index 1c7265d..5d7e010 100644
--- a/drivers/i2c/fsl_i2c.c
+++ b/drivers/i2c/fsl_i2c.c
@@ -383,13 +383,16 @@ i2c_read(u8 dev, uint addr, int alen, u8 *data, int length)
int i = -1; /* signal error */
u8 *a = (u8*)&addr;
- if (i2c_wait4bus() >= 0
+ if (i2c_wait4bus() < 0)
+ return -1;
+
+ if ((!length || alen > 0)
&& i2c_write_addr(dev, I2C_WRITE_BIT, 0) != 0
&& __i2c_write(&a[4 - alen], alen) == alen)
i = 0; /* No error so far */
- if (length
- && i2c_write_addr(dev, I2C_READ_BIT, 1) != 0)
+ if (length &&
+ i2c_write_addr(dev, I2C_READ_BIT, alen ? 1 : 0) != 0)
i = __i2c_read(data, length);
writeb(I2C_CR_MEN, &i2c_dev[i2c_bus_num]->cr);