Re: [PATCH v3] i2c: designware: Replace magic numbers with named constants
From: Andy Shevchenko
Date: Thu Dec 04 2025 - 13:54:46 EST
On Thu, Dec 04, 2025 at 07:13:08PM +0300, Artem Shimko wrote:
> Replace various magic numbers with properly named constants to improve
> code readability and maintainability. This includes constants for
> register access, timing adjustments, timeouts, FIFO parameters,
> and default values.
>
> The change makes the code more self-documenting without altering any
s/The change/This/
> functionality.
...
> +#define DW_IC_DEFAULT_BUS_CAPACITANCE_PF 100
_pF
(yes, it's fine to use CamelCase for unit suffixes, some of them historically
use capital letters, but it's better to follow the actual unit spelling from
Système International d'Unité)
> +#define DW_IC_ABORT_TIMEOUT_US 10
> +#define DW_IC_ABORT_TOTAL_TIMEOUT_US 100
Those TOTAL are not needed, just use a multiplier in place, this will be
basically the explicit number of "iterations" (yes, I know that the real
ones are 2x or 4x more).
> +#define DW_IC_BUSY_POLL_TIMEOUT_US 1100
Why not 1000?
(Yeah, I see the original value, but I think it makes no sense to go
specifically with 1100).
And in this case it might be better to write it as (1 * USEC_PER_MSEC)
which makes it easier to get that this is 1 millisecond (in µs units).
--
With Best Regards,
Andy Shevchenko