Re: [PATCH 2/2] i2c: i2c-stm32f7: allows for any bus frequency

From: Andy Shevchenko
Date: Wed Mar 25 2020 - 14:53:59 EST


On Wed, Mar 25, 2020 at 8:38 PM Alain Volmat <alain.volmat@xxxxxx> wrote:
>
> Do not limitate to the 3 (100KHz, 400KHz, 1MHz) bus frequency but
> instead allows any frequency (if it matches timing requirements).
> Depending on the requested frequency, use the spec data from either
> Standard, Fast or Fast Plus mode.
>
> Hardcoding of min/max bus frequencies is removed and is instead computed.
>
> The driver do not use anymore speed identifier but instead handle
> directly the frequency and figure out the spec data (necessary
> for the computation of the timing register) based on the frequency.

...

> +static struct stm32f7_i2c_spec *get_specs(u32 rate)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(i2c_specs); i++)
> + if (rate <= i2c_specs[i].rate)
> + return &i2c_specs[i];
> +

> + /* NOT REACHED */
> + return ERR_PTR(-EINVAL);

WARN_ONCE() ?

> +}

...

> - if ((tscl_l < i2c_specs[setup->speed].l_min) ||
> + if ((tscl_l < specs->l_min) ||

> (i2cclk >=
> ((tscl_l - af_delay_min - dnf_delay) / 4))) {

Perhaps squash above two to one line at the same time?

...

> + int i;
> +
> + for (i = ARRAY_SIZE(i2c_specs) - 1; i >= 0; i--)


Perhaps

int i = ARRAY_SIZE(i2c_specs);

while(i--)

?

> + if (i2c_specs[i].rate < rate)
> + return i2c_specs[i].rate;

--
With Best Regards,
Andy Shevchenko