drivers/iio/light/tcs3472.c | 357 +++++++++++++++++++++++++----------- 1 file changed, 249 insertions(+), 108 deletions(-)
This is v2 of the TCS3472 series, addressing the review comments from
Andy Shevchenko on v1. The series modernizes the tcs3472 driver by
converting it to use devm for resource management, switching to
guard(mutex) for locking, implementing wait time support exposed
through sampling_frequency (which was a long-standing TODO).
Patch 1: sorts the #include block alphabetically.
v2:
- New in v2 (suggested by Andy).
Patch 2: converts the remaining mutex_lock/unlock pairs to
guard(mutex).
v2: (suggested by Andy).
- Moved earlier in the series; dropped "Found by code inspection".
Patch 3: converts the driver to devm for resource allocation, drops
the explicit remove() callback, and adds
tcs3472_powerdown_action()
to power down the chip on cleanup or probe failure.
v2: (suggested by Andy).
- Read-modify-write in powerdown/resume rewritten as
"compute, write, commit on success".
- Use local 'struct device *dev = &client->dev' in probe.
Patch 4: implements wait time support, closing a long-standing TODO.
The user controls WTIME indirectly via sampling_frequency.
WTIME is recomputed when integration_time changes, preserving
the requested frequency.
WEN is disabled when the frequency is too high; WLONG is
enabled when the period exceeds the WTIME range.
v2: (suggested by Andy).
- validation tightened (rejects val > 0 with val2 < 0).
- target_freq_uhz uses div_u64() for 32-bit portability.
- TCS3472_ENABLE_RUN introduced here with AEN | PON | WEN,
no longer redefined between patches.
Patch 5: moves the trailing return -EINVAL in tcs3472_read_raw() and
tcs3472_write_raw() into explicit default: cases.
v2:
- New in v2 (suggested by Andy).
Testing:
All five patches were tested individually on a Raspberry Pi 3B with
an Adafruit TCS3472 breakout connected to I2C-1 at address 0x29.
Each patch was checked out and built separately to ensure the driver
remains functional in every intermediate state of the series.
Patch 1 (sort headers):
- Driver loads cleanly; RGBC channel reads return reasonable values.
- No warnings in dmesg.
Patch 2 (guard(mutex)):
- Threshold value writes (RISING=1000, FALLING=200) read back
correctly; AIHT/AILT registers on the chip mirror the values.
- Threshold enable toggles the AIEN bit in ENABLE
(sysfs '1' -> 0x13, sysfs '0' -> 0x03).
- rmmod completes with no lock leak in dmesg.
Patch 3 (devm conversion):
- Probe completes with ENABLE = 0x03 (PON|AEN, WEN not yet
introduced).
- RGBC reads return sensible values (e.g. clear=525, red=269,
green=151, blue=97).
- calibscale, integration_time, threshold value/period, and
threshold enable all work as before.
- After echo 0x29 to delete_device, ENABLE reads back as 0x00,
confirming that devm_add_action_or_reset() invokes
tcs3472_powerdown() on cleanup.
- rmmod completes with no warning.
Patch 4 (wait time / sampling_frequency):
- Initial state after probe: ATIME=0x00, WTIME=0xff, CONFIG=0x00,
ENABLE=0x0b (PON|AEN|WEN), sampling_frequency=1.614987 Hz.
- Write 1 Hz: WTIME=0x60, CONFIG=0x00, ENABLE=0x0b,
sampling_frequency reads back 0.999200 Hz.
- Write 5 Hz (too high for any wait time): WEN cleared,
ENABLE=0x03, sampling_frequency reads back 1.621271 Hz (cycle
with ATIME alone).
- Write 0.5 Hz (period exceeds WTIME range): WLONG enabled,
CONFIG=0x02, WTIME=0xd0, WEN re-enabled, ENABLE=0x0b,
sampling_frequency reads back 0.500200 Hz.
- After setting 0.5 Hz, changing integration_time to 0.024000 s:
WTIME automatically recomputed to 0xbb, sampling_frequency reads
back 0.496622 Hz (closest achievable to 0.5 Hz at the new ATIME).
- Invalid inputs (-1.0, 0.0) rejected with -EINVAL; chip state
unchanged.
- After rmmod, ENABLE reads back as 0x00 (PON, AEN and WEN all
cleared by powerdown via devm).
Patch 5 (default case):
- All read_raw and write_raw cases (raw RGBC, calibscale,
integration_time, sampling_frequency) handle attributes
identically to the previous patch.
- Invalid inputs still rejected with -EINVAL through the explicit
default: case.
- rmmod completes cleanly with ENABLE = 0x00
Aldo Conte (5):
iio: light: tcs3472: sort headers alphabetically
iio: light: tcs3472: convert remaining locking to guard(mutex)
iio: light: tcs3472: use devm for resource management
iio: light: tcs3472: implement wait time and sampling frequency
iio: light: tcs3472: move standalone return to default case
drivers/iio/light/tcs3472.c | 357 +++++++++++++++++++++++++-----------
1 file changed, 249 insertions(+), 108 deletions(-)
--
2.54.0
On Wed, 13 May 2026 00:32:10 +0200 Aldo Conte <aldocontelk@gmail.com> wrote: General comment. Cover letters provide the titles for email thread, patchwork and sashiko entries. Make sure they have same prefix as patches. iio: tcs3472: ...
© 2016 - 2026 Red Hat, Inc.