Skip to content

devm conversion, wait time, locking cleanup

Aldo Conte linux-iio linux-kernel-mentees lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 25 repliesIn review
  2. v13 patches 8 repliesSuperseded

Changes in v2 from the cover letter

- New in v2 (suggested by Andy).

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5iio: light: tcs3472: sort headers alphabeticallydrivers/iio/light/tcs3472.c+4 -41 reply
2/5iio: light: tcs3472: convert remaining locking to guard(mutex)drivers/iio/light/tcs3472.c+21 -384 replies
3/5iio: light: tcs3472: use devm for resource managementdrivers/iio/light/tcs3472.c+51 -565 replies
4/5iio: light: tcs3472: implement wait time and sampling frequencydrivers/iio/light/tcs3472.c+175 -144 replies
5/5iio: light: tcs3472: move standalone return to default casedrivers/iio/light/tcs3472.c+4 -210 replies

Reviews trailers per patch

2 of 5 patches have a Reviewed-by or Acked-by.

PatchJoshua CroftsAndy Shevchenko
1/5R-b
2/5
3/5
4/5
5/5R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/5] devm conversion, wait time, locking cleanup

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(-)
Signature · 1 line
2.54.0