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 4:04 PM, Chris Brandt <chris.brandt@xxxxxxxxxxx> wrote:
> Remove the restriction that the parent clock has to be a specific frequency
> and also allow any speed to be supported.
>
> Signed-off-by: Chris Brandt <chris.brandt@xxxxxxxxxxx>

Thanks for your patch!

> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -288,48 +283,101 @@ static const struct i2c_algorithm riic_algo = {
>         .functionality  = riic_func,
>  };
>
> -static int riic_init_hw(struct riic_dev *riic, u32 spd)
> +static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
>  {

> +       /*
> +        * Determine reference clock rate. We must be able to get the desired
> +        * frequency with only 62 clock ticks max (31 high, 31 low).
> +        * Aim for a duty of 60% LOW, 40% HIGH.
> +        */
> +       total_ticks = rate / t->bus_freq_hz;
> +       if (rate % t->bus_freq_hz)              /* round up */
> +               total_ticks++;

DIV_ROUND_UP()

> +       /*
> +        * 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?

> +       pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n",
> +                rate/total_ticks, ((brl+3)*100)/(brl+brh+6),
> +                t->scl_fall_ns / (1000000000/rate),
> +                t->scl_rise_ns / (1000000000/rate), cks, brl, brh);

Likewise (or: reuse the values from above?).

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