Re: [PATCH] i2c: riic: remove clock and frequency restrictions

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

 



Hi Chris,

On Wed, Oct 18, 2017 at 5:10 PM, Chris Brandt <Chris.Brandt@xxxxxxxxxxx> wrote:
> On Wednesday, October 18, 2017 1, Geert Uytterhoeven wrote:
>> > +       /*
>> > +        * Remove clock ticks for rise and fall times. Convert ns to
>> clock
>> > +        * ticks.
>> > +        */
>> > +       brl -= t->scl_fall_ns / (1000000000/rate);
>> > +       brh -= t->scl_rise_ns / (1000000000/rate);
>>
>> To avoid losing too much precision by the division, you can rewrite this
>> as
>> e.g.
>>
>>     brl -= t->scl_fall_ns * rate / 1000000000;
>>
>> ("scl_fall_ns * rate" should not overflow).
>> Perhaps DIV_ROUND_UP(), too?
>
> Unfortunately, I do not get the correct number every time.
>
> Sometimes I get the correct number, but most of the time I get 0.
>
> Note, if rate=33,330,000 and t->scl_fall_ns=300, then
>
> t->scl_fall_ns * rate  = 9,999,000,000 (0x253FCA1C0) a 34-bit number.
>
> So, I'd rather just stick with the less precision because it's not that
> much of a bit deal.

Oops, so the numbers are bigger than I had expected, naively.

Alternatively, you can use a 64-by-32 division, e.g.

    DIV_ROUND_UP_ULL((u64)t->scl_fall_ns * rate, 1000000000)

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



[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