Re: [PATCH RFT 2/2] i2c: rcar: improve accuracy for R-Car Gen3+

From: Geert Uytterhoeven
Date: Tue Sep 19 2023 - 05:42:32 EST


Hi Wolfram,

On Wed, Sep 13, 2023 at 11:38 AM Wolfram Sang
<wsa+renesas@xxxxxxxxxxxxxxxxxxxx> wrote:
> With some new registers, SCL can be calculated to be closer to the
> desired rate. Apply the new formula for R-Car Gen3 device types.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx>

> --- a/drivers/i2c/busses/i2c-rcar.c
> +++ b/drivers/i2c/busses/i2c-rcar.c

> - /* keep icccr value */
> - priv->icccr = scgd << cdf_width | cdf;
> + priv->icccr = scgd << cdf_width | cdf;
> + } else {
> + u32 x, sum_ratio = RCAR_SCHD_RATIO + RCAR_SCLD_RATIO;
> + /*
> + * SCLD/SCHD ratio and SMD default value are explained above
> + * where they are defined. With these definitions, we can compute
> + * x as a base value for the SCLD/SCHD ratio:
> + *
> + * SCL = clkp / (8 + 2 * SMD + SCLD + SCHD + F[(ticf + tr + intd) * clkp])
> + * SCL = clkp / (8 + 2 * RCAR_DEFAULT_SMD + RCAR_SCLD_RATIO * x
> + * + RCAR_SCHD_RATIO * x + F[...])
> + *
> + * with: sum_ratio = RCAR_SCLD_RATIO + RCAR_SCHD_RATIO
> + * and: smd = 2 * RCAR_DEFAULT_SMD
> + *
> + * SCL = clkp / (8 + smd + sum_ratio * x + F[...])
> + * 8 + smd + sum_ratio * x + F[...] = SCL / clkp
> + * x = ((SCL / clkp) - 8 - smd - F[...]) / sum_ratio

Woops, I missed that both "SCL / clkp" above should be "clkp / SCL".

Fortunately I noticed your "[PATCH 2/2] i2c: rcar: add FastMode+
support for Gen4" fixed that, but I guess it's better to fix that in
this patch instead.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

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