Re: [PATCH v4 9/9] i2c: riic: Add `riic_bus_barrier()` to check bus availability

Geert Uytterhoeven
2025-01-03T16:09:15Z

Hi Prabhakar,

On Fri, Jan 3, 2025 at 10:19 AM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Introduce a new `riic_bus_barrier()` function to verify bus availability
> before initiating an I2C transfer. This function enhances the bus
> arbitration check by ensuring that the SDA and SCL lines are not held low,
> in addition to checking the BBSY flag using `readb_poll_timeout()`.
>
> Previously, only the BBSY flag was checked to determine bus availability.
> However, it is possible for the SDA line to remain low even when BBSY = 0.
> This new implementation performs an additional check on the SDA and SCL
> lines to avoid potential bus contention issues.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> Reviewed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---
> v3->v4
> - Propogated error code when readb_poll_timeout() failed
> - I've kept the RB/TB tags as the changes were minimal.

OK.

+ you removed a superfluous initialization of riic->err (last change below).

> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -149,13 +173,11 @@ static int riic_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
> if (ret)
> return ret;
>
> - if (riic_readb(riic, RIIC_ICCR2) & ICCR2_BBSY) {
> - riic->err = -EBUSY;
> + riic->err = riic_bus_barrier(riic);
> + if (riic->err)
> goto out;
> - }
>
> reinit_completion(&riic->msg_done);
> - riic->err = 0;
>
> riic_writeb(riic, 0, RIIC_ICSR2);
>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds