diff mbox

[U-Boot,3/6] i2c: fsl_i2c: i2c_read(): dont try to write address w/ alen=0

Message ID 1366628805-29964-4-git-send-email-eibach@gdsys.de
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Dirk Eibach April 22, 2013, 11:06 a.m. UTC
From: Reinhard Pfau <pfau@gdsys.de>

if alen is 0: no longer start a write cycle before reading data.

Signed-off-by: Dirk Eibach <eibach@gdsys.de>
Signed-off-by: Reinhard Pfau <pfau@gdsys.de>

---
 drivers/i2c/fsl_i2c.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Jim Chargin April 22, 2013, 3:49 p.m. UTC | #1
Dirk Eibach <eibach <at> gdsys.de> writes:

> 
> From: Reinhard Pfau <pfau <at> gdsys.de>
> 
> if alen is 0: no longer start a write cycle before reading data.
> 
> Signed-off-by: Dirk Eibach <eibach <at> gdsys.de>
> Signed-off-by: Reinhard Pfau <pfau <at> gdsys.de>
> 

This will break my stand alone application, which relies on a zero address
len to provide i2c_probe functionality, since i2c_probe is not exported via
_exports.h.

Is there some other way to do i2c_probe in a stand alone application?

Thanks,
Jim
Fabio Estevam April 22, 2013, 4:09 p.m. UTC | #2
On Mon, Apr 22, 2013 at 8:06 AM, Dirk Eibach <eibach@gdsys.de> wrote:

> diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
> index 1c7265d..276386d 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;

Can you return a more descriptive error code here?
diff mbox

Patch

diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
index 1c7265d..276386d 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 (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)
+	    && 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);