]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: chemical: bme680: Move forced mode setup in ->read_raw()
authorVasileios Amoiridis <vassilisamir@gmail.com>
Sun, 9 Jun 2024 23:38:25 +0000 (01:38 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 3 Aug 2024 09:13:35 +0000 (10:13 +0100)
Whenever the sensor is set to forced mode, a TPHG cycle is triggered and
the values of temperature, pressure, humidity and gas become ready to be
read.

The setup of the forced mode to trigger measurements was located inside
the read_{temp/gas}() functions. This was not posing a functional problem
since read_{humid/press}() are internally calling read_temp() so the
forced mode is set through this call.

This is not very clear and it is kind of hidden that regardless of the
measurement, the setup of the forced mode needs to happen before any
measurement.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Link: https://patch.msgid.link/20240609233826.330516-15-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/chemical/bme680_core.c

index d08f32ecd1398192212c09559c856615156a9df0..3785b4d014db000912213b290907b19539639b53 100644 (file)
@@ -572,15 +572,6 @@ static int bme680_read_temp(struct bme680_data *data, int *val)
        u32 adc_temp;
        s16 comp_temp;
 
-       /* set forced mode to trigger measurement */
-       ret = bme680_set_mode(data, true);
-       if (ret < 0)
-               return ret;
-
-       ret = bme680_wait_for_eoc(data);
-       if (ret)
-               return ret;
-
        ret = regmap_bulk_read(data->regmap, BME680_REG_TEMP_MSB,
                               data->buf, BME680_TEMP_NUM_BYTES);
        if (ret < 0) {
@@ -683,15 +674,6 @@ static int bme680_read_gas(struct bme680_data *data,
        u16 adc_gas_res, gas_regs_val;
        u8 gas_range;
 
-       /* set forced mode to trigger measurement */
-       ret = bme680_set_mode(data, true);
-       if (ret < 0)
-               return ret;
-
-       ret = bme680_wait_for_eoc(data);
-       if (ret)
-               return ret;
-
        ret = regmap_read(data->regmap, BME680_REG_MEAS_STAT_0, &data->check);
        if (data->check & BME680_GAS_MEAS_BIT) {
                dev_err(dev, "gas measurement incomplete\n");
@@ -730,9 +712,19 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
                           int *val, int *val2, long mask)
 {
        struct bme680_data *data = iio_priv(indio_dev);
+       int ret;
 
        guard(mutex)(&data->lock);
 
+       /* set forced mode to trigger measurement */
+       ret = bme680_set_mode(data, true);
+       if (ret < 0)
+               return ret;
+
+       ret = bme680_wait_for_eoc(data);
+       if (ret)
+               return ret;
+
        switch (mask) {
        case IIO_CHAN_INFO_PROCESSED:
                switch (chan->type) {