Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell

From: Jonathan Cameron

Date: Sat Nov 28 2026 - 15:53:16 EST



> ...
>
> > > > + ret = regmap_read_poll_timeout(regmap, MAX8907_REG_TSC_STA_INT, value,
> > > > + !(value & MAX8907_MASK_NREF_OK), 10, 1000);
> > >
> > > ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
> > > !(value & MAX8907_MASK_NREF_OK),
> > > 10, 1 * USEC_PER_MSEC);
> > >
> >
> > hmm, replace 1000 (4 chars, pretty readable) with USEC_PER_MSEC (12
> > chars and twice wrapped line and needs tinkering or looking into
> > units.h), I don't think so.
>
> Because the point is missed? We have tons of much longer multipliers that kill
> two birds with one stone:
> - avoiding possible typos when many 0:s are in them (one can be missed or too many)
> - hinting reader of the units of the used values without even looking into the docs
> - (and reading 1...MSEC is quite natural, without counting 0:s and thinking how
> many of them and what 1000 microseconds, after spending time on the
> documentation, means in practice)
>
> Please, use multipliers where it's makes code better to understand for
> unprepared reader.
>
> ...
>
> > I would like to hear what Jonathan has to say.
>
> OK.

So a mixed reply. In majority of cases I'd agree with Andy that the documentation
value would make it a good idea, but let us look at the code in question.

ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
!(value & MAX8907_MASK_NREF_OK),
10, 1 * USEC_PER_MSEC);

So the reason I don't like it here is that 10 and the result that we represent
them in different ways. So I do slightly prefer the 1000 here as then we can
see immediately that we have a reasonable ratio of poll to timeout.

These are subtle so there is often no perfect answer particularly when
like this we have timeout and timing related functions with no great consistency
on timebase.

It could be made explicit.

timeout_usecs = 1 * USEC_PER_MSEC;

ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
!(value & MAX8907_MASK_NREF_OK),
timeout_usecs / 100, timeout_usecs);
Which I think is the clearest of all options for this - but at cost of
a local variable - hence not perfect either!

Jonathan