[PATCH v2] i2c: rcar_i2c: Fix i2c read/write errors

commit 7c8f821e ("i2c: rcar_i2c: Set the slave address from rcar_i2c_xfer"), blindly called rcar_i2c_set_addr() with read argument always set to 1 during xfer which introduced read/write errors, whereas earlier rcar_i2c_read_common() called rcar_i2c_set_addr() with read set to 1 and rcar_i2c_write_common() called rcar_i2c_set_addr() with read set 0.
Fixes: 7c8f821e ("i2c: rcar_i2c: Set the slave address from rcar_i2c_xfer") Signed-off-by: Lad Prabhakar prabhakar.mahadev-lad.rj@bp.renesas.com Reviewed-by: Biju Das biju.das.jz@bp.renesas.com --- v1->v2 * Incorporated suggestion from Heiko
v1: https://patchwork.ozlabs.org/project/uboot/patch/ 20200921163353.5540-1-prabhakar.mahadev-lad.rj@bp.renesas.com/
Without this patch below errors are seen: => i2c probe Valid chip addresses: 34 47 68 => i2c md 0x47 0 100 Error reading the chip: -110 => i2c mw 0x47 0x0a 0x06 Error writing the chip: -110 => --- drivers/i2c/rcar_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/rcar_i2c.c b/drivers/i2c/rcar_i2c.c index 4267bbfa5a..e76201df6b 100644 --- a/drivers/i2c/rcar_i2c.c +++ b/drivers/i2c/rcar_i2c.c @@ -211,7 +211,7 @@ static int rcar_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs) int ret;
for (; nmsgs > 0; nmsgs--, msg++) { - ret = rcar_i2c_set_addr(dev, msg->addr, 1); + ret = rcar_i2c_set_addr(dev, msg->addr, msg->flags & I2C_M_RD); if (ret) return ret;

On 9/30/20 11:16 AM, Lad Prabhakar wrote: [...]
diff --git a/drivers/i2c/rcar_i2c.c b/drivers/i2c/rcar_i2c.c index 4267bbfa5a..e76201df6b 100644 --- a/drivers/i2c/rcar_i2c.c +++ b/drivers/i2c/rcar_i2c.c @@ -211,7 +211,7 @@ static int rcar_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs) int ret;
for (; nmsgs > 0; nmsgs--, msg++) {
ret = rcar_i2c_set_addr(dev, msg->addr, 1);
ret = rcar_i2c_set_addr(dev, msg->addr, msg->flags & I2C_M_RD);
Don't you need !!(msg->flags & I2C_M_RD) here ? There is 140 writel((chip << 1) | read, priv->base + RCAR_I2C_ICMAR); in rcar_i2c_set_addr(), so if I2C_M_RD is ever changed from 0x1 to anything else, this will fail.

Hi Marek,
Thank you for the review.
On Wed, Sep 30, 2020 at 10:57 AM Marek Vasut marek.vasut@gmail.com wrote:
On 9/30/20 11:16 AM, Lad Prabhakar wrote: [...]
diff --git a/drivers/i2c/rcar_i2c.c b/drivers/i2c/rcar_i2c.c index 4267bbfa5a..e76201df6b 100644 --- a/drivers/i2c/rcar_i2c.c +++ b/drivers/i2c/rcar_i2c.c @@ -211,7 +211,7 @@ static int rcar_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs) int ret;
for (; nmsgs > 0; nmsgs--, msg++) {
ret = rcar_i2c_set_addr(dev, msg->addr, 1);
ret = rcar_i2c_set_addr(dev, msg->addr, msg->flags & I2C_M_RD);
Don't you need !!(msg->flags & I2C_M_RD) here ? There is 140 writel((chip << 1) | read, priv->base + RCAR_I2C_ICMAR); in rcar_i2c_set_addr(), so if I2C_M_RD is ever changed from 0x1 to anything else, this will fail.
Agreed will fix that and post a v3.
Cheers, Prabhakar
participants (3)
-
Lad Prabhakar
-
Lad, Prabhakar
-
Marek Vasut