On Thu, Nov 26, 2015 at 11:59 PM, Wolfram Sang <[email protected]> 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 -- [email protected]
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html