Re: [PATCH v2 2/2] iio: light: Add Capella CM3217 ambient light sensor driver
From: Patrick Fischer
Date: Fri Nov 13 2026 - 16:15:11 EST
On Tue, Nov 10, 2026 at 12:31:12AM +0200, Andy Shevchenko wrote:
> > +#define CM3217_NLUX_MS (15ULL * NANO)
>
> Hmm... Can we use rather formula inside the definition? Also one of the
> multipliers from time.h might make sense here as MS are mentioned.
>
> 18.75 per 800 µs, or 1875 per 8 µs if I'm not mistaken. Hence
>
> (1875 * 8 * NSEC_PER_MSEC)
The resolution is 0.01875 lux per count at 800 ms, and the constant is
that resolution times the 800 ms, in nanolux * ms. NSEC_PER_MSEC gives
the right number, but there is no time conversion in it, so in v3 I
wrote it as the formula instead:
#define CM3217_NLUX_MS (18750000ULL * 800) /* 0.01875 lux * 800 ms */
> These NANO again are misleading.
v3 has a small helper, CM3217_NLUX_TO_VAL(), so NANO only shows up where
the nanolux value is split into the integer and nano parts of
IIO_VAL_INT_PLUS_NANO.
> Have you checked with `pahole`?
Yes: 40 bytes on 32-bit ARM, with a 2-byte hole after cmd2. As ktime_t
needs 8-byte alignment, none of the orders I tried is smaller, on ARM or
on 64-bit, so I kept the fields next to the lock that protects them.
The other points (static_assert() on one line, the margin added to
conv_ms, FIELD_MODIFY(), dev_err_probe() inside scoped_guard()) are done
in v3. The scale and integration time tables come out identical to v2.
v3:
https://lore.kernel.org/r/20261113-upstream-iio-cm3217-v3-0-c4d5b2485dff@xxxxxxxxxxxxxxxxxx
Thanks for the review,
Patrick