Re: [PATCH v5 3/6] i2c: npcm: Modify timeout evaluation mechanism
From: Andy Shevchenko
Date: Tue Oct 01 2024 - 09:14:42 EST
On Tue, Oct 01, 2024 at 02:28:52PM +0800, Tyrone Ting wrote:
> From: Tyrone Ting <kfting@xxxxxxxxxxx>
>
> The users want to connect a lot of masters on the same bus.
> This timeout is used to determine the time it takes to take bus ownership.
> The transactions are very long, so waiting 35ms is not enough.
>
> Increase the timeout and treat it as the total timeout, including retries.
> The total timeout is 2 seconds now.
>
> The i2c core layer will have chances to retry to call the i2c driver
> transfer function if the i2c driver reports that the bus is busy and
> returns EAGAIN.
-EAGAIN
...
> + /*
> + * Adaptive TimeOut: estimated time in usec + 100% margin:
> + * 2: double the timeout for clock stretching case
> + * 9: bits per transaction (including the ack/nack)
> + */
> + timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite);
Side note (as I see it was in the original code), from physics
point of view the USEC_PER_SEC here should be simply MICRO
(as 1/Hz == s, and here it will be read as s^2 in the result),
but if one finds the current more understandable, okay then.
--
With Best Regards,
Andy Shevchenko