linux-stable/drivers/iio
Javier Carrasco 0892d2c965 iio: common: ms_sensors: ms_sensors_i2c: fix humidity conversion time table
commit 54cf39ec16 upstream.

The HTU21 offers 4 sampling frequencies: 20, 40, 70 and 120, which are
associated to an index that is used to select the right measurement
resolution and its corresponding measurement time. The current
implementation selects the measurement resolution and the temperature
measurement time properly, but it does not select the right humidity
measurement time in all cases.

In summary, the 40 and 70 humidity measurement times are swapped.

The reason for that is probably the unusual coding for the measurement
resolution. According to the datasheet, the bits [7,0] of the "user
register" are used as follows to select the bit resolution:

--------------------------------------------------
| Bit 7 | Bit 0 | RH | Temp | Trh (us) | Tt (us) |
--------------------------------------------------
|   0   |   0   | 12 |  14  |  16000   |  50000  |
--------------------------------------------------
|   0   |   1   | 8  |  12  |  3000    |  13000  |
--------------------------------------------------
|   1   |   0   | 10 |  13  |  5000    |  25000  |
--------------------------------------------------
|   1   |   1   | 11 |  11  |  8000    |  7000   |
--------------------------------------------------
*This table is available in the official datasheet, page 13/21. I have
just appended the times provided in the humidity/temperature tables,
pages 3/21, 5/21. Note that always a pair of resolutions is selected.

The sampling frequencies [20, 40, 70, 120] are assigned to a linear
index [0..3] which is then coded as follows [1]:

Index    [7,0]
--------------
idx 0     0,0
idx 1     1,0
idx 2     0,1
idx 3     1,1

That is done that way because the temperature measurements are being
used as the reference for the sampling frequency (the frequencies and
the temperature measurement times are correlated), so increasing the
index always reduces the temperature measurement time and its
resolution. Therefore, the temperature measurement time array is as
simple as [50000, 25000, 13000, 7000]

On the other hand, the humidity resolution cannot follow the same
pattern because of the way it is coded in the "user register", where
both resolutions are selected at the same time. The humidity measurement
time array is the following: [16000, 3000, 5000, 8000], which defines
the following assignments:

Index    [7,0]    Trh
-----------------------
idx 0     0,0     16000  -> right, [0,0] selects 12 bits (Trh = 16000)
idx 1     1,0     3000   -> wrong! [1,0] selects 10 bits (Trh = 5000)
idx 2     0,1     5000   -> wrong! [0,1] selects 8 bits (Trh = 3000)
idx 3     1,1     8000   -> right, [1,1] selects 11 bits (Trh = 8000)

The times have been ordered as if idx = 1 -> [0,1] and idx = 2 -> [1,0],
which is not the case for the reason explained above.

So a simple modification is required to obtain the right humidity
measurement time array, swapping the values in the positions 1 and 2.

The right table should be the following: [16000, 5000, 3000, 8000]

Fix the humidity measurement time array with the right idex/value
coding.

[1] The actual code that makes this coding and assigns it to the current
value of the "user register" is the following:
config_reg &= 0x7E;
config_reg |= ((i & 1) << 7) + ((i & 2) >> 1);

Fixes: d574a87cc3 ("Add meas-spec sensors common part")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20231026-topic-htu21_conversion_time-v1-1-bd257dc44209@gmail.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-08 11:27:35 +01:00
..
accel iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word() 2023-03-11 16:32:01 +01:00
adc iio: exynos-adc: request second interupt only when touchscreen mode is used 2023-11-08 11:22:17 +01:00
addac iio: add addac subdirectory 2023-08-30 16:31:44 +02:00
afe iio: afe: rescale: use s64 for temporary scale calculations 2022-04-15 14:14:38 +02:00
amplifiers
buffer
chemical iio:chemical:ccs811: rearrange iio trigger get and register 2022-07-02 16:27:34 +02:00
common iio: common: ms_sensors: ms_sensors_i2c: fix humidity conversion time table 2024-01-08 11:27:35 +01:00
counter counter: 104-quad-8: Fix race condition between FLAG and CNTR reads 2023-04-26 11:21:53 +02:00
dac iio: dac: build ad5758 driver when AD5758 is selected 2023-06-09 10:24:01 +02:00
dummy iio: dummy: iio_simple_dummy: check the return value of kstrdup() 2022-06-14 16:59:36 +02:00
frequency
gyro iio: gyro: mpu3050: Fix the error handling in mpu3050_power_up() 2022-07-02 16:27:35 +02:00
health iio: health: afe4404: Fix oob read in afe4404_[read|write]_raw 2022-12-08 11:18:32 +01:00
humidity iio: humidity: hdc100x: Add margin to the conversion time 2021-08-26 08:36:35 -04:00
imu iio: imu: inv_mpu6050: fix an error code problem in inv_mpu6050_read_raw 2024-01-08 11:27:35 +01:00
light iio: light: rpr0521: add missing Kconfig dependencies 2022-12-08 11:18:32 +01:00
magnetometer iio: magnetometer: ak8975: Fix the error handling in ak8975_power_on() 2022-05-12 12:20:19 +02:00
multiplexer
orientation
potentiometer
potentiostat iio: potentiostat: lmp91000: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() 2021-07-20 16:15:54 +02:00
pressure iio: pressure: ms5611: ms5611_prom_is_valid false negative bug 2023-10-25 11:16:30 +02:00
proximity iio: prox: isl29501: Fix buffer alignment in iio_push_to_buffers_with_timestamp() 2021-07-20 16:15:56 +02:00
resolver
temperature iio: hid-sensor-temperature: Fix issues of timestamp channel 2021-03-24 11:07:36 +01:00
trigger iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init() 2022-11-25 17:40:27 +01:00
Kconfig iio: add addac subdirectory 2023-08-30 16:31:44 +02:00
Makefile iio: add addac subdirectory 2023-08-30 16:31:44 +02:00
iio_core.h
iio_core_trigger.h
industrialio-buffer.c iio: buffer: Fix demux update 2020-12-30 11:26:15 +01:00
industrialio-configfs.c
industrialio-core.c iio: core: Use min() instead of min_t() to make code more robust 2023-09-23 10:48:16 +02:00
industrialio-event.c
industrialio-sw-device.c
industrialio-sw-trigger.c iio: core: Fix entry not deleted when iio_register_sw_trigger_type() fails 2022-12-08 11:18:30 +01:00
industrialio-trigger.c iio: trigger: Fix reference counting 2021-12-14 10:18:09 +01:00
industrialio-triggered-event.c
inkern.c iio: inkern: only release the device node when done with it 2022-10-26 13:19:30 +02:00