[PATCH v2 0/5] iio: chemical: sgp40: add funtions for serial number readback, self-test, and heater control.

From: Jaakko Koivisto

Date: Mon Nov 02 2026 - 04:19:40 EST


Add commands for getting the Sensirion SGP40 VOC-sensor
serial number, controlling the device's internal heater,
and running the device self-test.

Replace the manual mutex_lock()/mutex_unlock() with guard(mutex).
Simplifies the locking patterns, making it easier to add new mutex-guarded
variable 'heater_enabled' in patch 5.
Extends the lock to cover i2c communications with the device.

Fixes issue with converting all i2c errors to EIO in
sgp40_measure_resistance_raw(). Included in the patchset as it was found
due to reviewer flagging the same issue in the v1 patches.

Changes in v2:
- Added patch for replacing mutex_lock()/mutex_unlock() with guard().

- Added guard against concurrent access to the device in
sgp40_get_serial_number(), sgp40_execute_self_test(),
and sgp40_turn_heater_off().

- Return EIO if CRC check fails in sgp40_get_serial_number(),
sgp40_execute_self_test(), sgp40_and turn_heater_off().

- Fixed formatting issues, missing newlines, unnecessary debug-print and
unnecessary 0LL constant, added comments for sleep times.

- Changed 1 ms sleeps in sgp40_get_serial_number() and
sgp40_turn_heater_off() to use fsleep instead of msleep
(checkpatch.pl warning against using short msleep)

- Removed storing serial-number in driver-data, instead retrieve it when
requested.

- Use the existing serialnumber ABI for presenting the SN to userspace.

- Fixed error paths in sgp40_turn_heater_off(). In v1 positive
numbers were returned for errors. Fail the driver probe if the self-test
fails to run, or the response is not PASS or FAIL.

- Use the existing heater_enable ABI for heater control.

- Return any negative errors from i2c_master_send() without
converting them to -EIO in get_serial_number, execute_self_test,
and turn_heater_off.

- Added patch for fixing the i2c error conversion issue in
sgp40_measure_resistance_raw().

- Log errors with dev_err_probe() instead of dev_err().

- Link to v1: https://lore.kernel.org/linux-iio/20260918134019.1101308-1-jmatko@xxxxxx/

Jaakko Koivisto (5):
iio: chemical: sgp40: Do not convert I2C errors to EIO
iio: chemical: sgp40: Replace manual locking with guard()
iio: chemical: sgp40: Implement get_serial_number-command
iio: chemical: sgp40: Implement execute_self_test-command
iio: chemical: sgp40: Implement turn_heater_off-command

drivers/iio/chemical/sgp40.c | 231 +++++++++++++++++++++++++++++++----
1 file changed, 210 insertions(+), 21 deletions(-)

--
2.56.0