2014-10-01 17:41:13

by Alexandru M Stan

[permalink] [raw]
Subject: [PATCH] i2c: rk3x: fix 0 length write transfers

i2cdetect -q was broken (everything was a false positive, and no transfers were
actually being sent over i2c). The way it works is by sending a 0 length write
request and checking for NACK. This patch fixes the 0 length writes and actually
sends them.

Reported-by: Doug Anderson <[email protected]>
Signed-off-by: Alexandru M Stan <[email protected]>
---
drivers/i2c/busses/i2c-rk3x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index b41d979..f486d0e 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -238,7 +238,7 @@ static void rk3x_i2c_fill_transmit_buf(struct rk3x_i2c *i2c)
for (i = 0; i < 8; ++i) {
val = 0;
for (j = 0; j < 4; ++j) {
- if (i2c->processed == i2c->msg->len)
+ if ((i2c->processed == i2c->msg->len) && (cnt != 0))
break;

if (i2c->processed == 0 && cnt == 0)
--
2.1.0.rc2.206.gedb03e5


2014-10-01 22:47:11

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH] i2c: rk3x: fix 0 length write transfers

Alex,

On Wed, Oct 1, 2014 at 10:40 AM, Alexandru M Stan <[email protected]> wrote:
> i2cdetect -q was broken (everything was a false positive, and no transfers were
> actually being sent over i2c). The way it works is by sending a 0 length write
> request and checking for NACK. This patch fixes the 0 length writes and actually
> sends them.
>
> Reported-by: Doug Anderson <[email protected]>
> Signed-off-by: Alexandru M Stan <[email protected]>
> ---
> drivers/i2c/busses/i2c-rk3x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
> index b41d979..f486d0e 100644
> --- a/drivers/i2c/busses/i2c-rk3x.c
> +++ b/drivers/i2c/busses/i2c-rk3x.c
> @@ -238,7 +238,7 @@ static void rk3x_i2c_fill_transmit_buf(struct rk3x_i2c *i2c)
> for (i = 0; i < 8; ++i) {
> val = 0;
> for (j = 0; j < 4; ++j) {
> - if (i2c->processed == i2c->msg->len)
> + if ((i2c->processed == i2c->msg->len) && (cnt != 0))

This looks good to me. Basically we still need to write the address
of the device onto the bus even if there's no data.

Reviewed-by: Doug Anderson <[email protected]>
Tested-by: Doug Anderson <[email protected]>

-Doug

2014-10-02 13:31:37

by Max Schwarz

[permalink] [raw]
Subject: Re: [PATCH] i2c: rk3x: fix 0 length write transfers

Hi Alexandru,

On Wednesday 01 October 2014 at 10:40:41, Alexandru M Stan wrote:
> i2cdetect -q was broken (everything was a false positive, and no transfers
> were actually being sent over i2c). The way it works is by sending a 0
> length write request and checking for NACK. This patch fixes the 0 length
> writes and actually sends them.
>
> Reported-by: Doug Anderson <[email protected]>
> Signed-off-by: Alexandru M Stan <[email protected]>
> ---
> drivers/i2c/busses/i2c-rk3x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
> index b41d979..f486d0e 100644
> --- a/drivers/i2c/busses/i2c-rk3x.c
> +++ b/drivers/i2c/busses/i2c-rk3x.c
> @@ -238,7 +238,7 @@ static void rk3x_i2c_fill_transmit_buf(struct rk3x_i2c
> *i2c) for (i = 0; i < 8; ++i) {
> val = 0;
> for (j = 0; j < 4; ++j) {
> - if (i2c->processed == i2c->msg->len)
> + if ((i2c->processed == i2c->msg->len) && (cnt != 0))
> break;
>
> if (i2c->processed == 0 && cnt == 0)

Yes, looks correct and makes i2cdetect work for me on Radxa Rock.

Reviewed-By: Max Schwarz <[email protected]>
Tested-By: Max Schwarz <[email protected]>

Cheers,
Max

2014-10-03 00:26:49

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: rk3x: fix 0 length write transfers

> Reviewed-By: Max Schwarz <[email protected]>
> Tested-By: Max Schwarz <[email protected]>

Checkpatch says:

WARNING: 'Tested-by:' is the preferred signature form

Same 'Reviewed-by:'


Attachments:
(No filename) (195.00 B)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-10-03 00:27:13

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: rk3x: fix 0 length write transfers

On Wed, Oct 01, 2014 at 10:40:41AM -0700, Alexandru M Stan wrote:
> i2cdetect -q was broken (everything was a false positive, and no transfers were
> actually being sent over i2c). The way it works is by sending a 0 length write
> request and checking for NACK. This patch fixes the 0 length writes and actually
> sends them.
>
> Reported-by: Doug Anderson <[email protected]>
> Signed-off-by: Alexandru M Stan <[email protected]>

Applied to for-current, thanks!


Attachments:
(No filename) (472.00 B)
signature.asc (819.00 B)
Digital signature
Download all attachments