Re: [RFC 5/9] i2c: rcar: honor additional i2c timings from DT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 26, 2015 at 11:59 PM, Wolfram Sang <wsa@xxxxxxxxxxxxx> wrote:
> --- a/drivers/i2c/busses/i2c-rcar.c
> +++ b/drivers/i2c/busses/i2c-rcar.c
> @@ -211,12 +214,12 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timin
>          * it is impossible to calculate large scale
>          * number on u32. separate it
>          *
> -        * F[(ticf + tr + intd) * ick]
> -        *  = F[(35 + 200 + 50)ns * ick]
> -        *  = F[285 * ick / 1000000000]
> -        *  = F[(ick / 1000000) * 285 / 1000]
> +        * F[(ticf + tr + intd) * ick] with sum = (ticf + tr + intd)
> +        *  = F[sum * ick / 1000000000]
> +        *  = F[(ick / 1000000) * sum / 1000]
>          */
> -       round = (ick + 500000) / 1000000 * 285;
> +       sum = t->scl_fall_ns + t->scl_rise_ns + t->scl_int_delay_ns;
> +       round = (ick + 500000) / 1000000 * sum;

If you're sure it cannot overflow, doing the "* sum" before the division
improves accuracy.

>         round = (round + 500) / 1000;

You can use DIV_ROUND_CLOSEST everywhere, e.g.

    round = DIV_ROUND_CLOSEST(round, 1000)

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
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux