]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: chemical: bme680: Remove duplicate register read
authorVasileios Amoiridis <vassilisamir@gmail.com>
Sun, 9 Jun 2024 23:38:17 +0000 (01:38 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 3 Aug 2024 09:13:34 +0000 (10:13 +0100)
The LSB of the gas register was read first to check if the following
check was correct and then the MSB+LSB were read together. Simplify this
by reading together the MSB+LSB immediately.

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

index c51bf2bdf504e2b9a111516aa87dba4ad2fa7f84..b5f16ca81e706888dfbe55694c924b06c0f3db9c 100644 (file)
@@ -46,7 +46,7 @@
 #define   BME680_RSERROR_MASK                  GENMASK(7, 4)
 #define BME680_REG_RES_HEAT_0                  0x5A
 #define BME680_REG_GAS_WAIT_0                  0x64
-#define BME680_ADC_GAS_RES_SHIFT               6
+#define BME680_ADC_GAS_RES                     GENMASK(15, 6)
 #define BME680_AMB_TEMP                                25
 
 #define BME680_REG_CTRL_GAS_1                  0x71
index 72bd5445b6c01f9aa1cc52e73d26dbba8df2c358..9660ec3854a13925bd68584bcd1bc214e934040b 100644 (file)
@@ -767,7 +767,7 @@ static int bme680_read_gas(struct bme680_data *data,
        int ret;
        __be16 tmp = 0;
        unsigned int check;
-       u16 adc_gas_res;
+       u16 adc_gas_res, gas_regs_val;
        u8 gas_range;
 
        /* Set heater settings */
@@ -792,11 +792,14 @@ static int bme680_read_gas(struct bme680_data *data,
                return -EBUSY;
        }
 
-       ret = regmap_read(data->regmap, BME680_REG_GAS_R_LSB, &check);
+       ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
+                              &tmp, sizeof(tmp));
        if (ret < 0) {
-               dev_err(dev, "failed to read gas_r_lsb register\n");
+               dev_err(dev, "failed to read gas resistance\n");
                return ret;
        }
+       gas_regs_val = be16_to_cpu(tmp);
+       adc_gas_res = FIELD_GET(BME680_ADC_GAS_RES, gas_regs_val);
 
        /*
         * occurs if either the gas heating duration was insuffient
@@ -804,20 +807,12 @@ static int bme680_read_gas(struct bme680_data *data,
         * heater temperature was too high for the heater sink to
         * reach.
         */
-       if ((check & BME680_GAS_STAB_BIT) == 0) {
+       if ((gas_regs_val & BME680_GAS_STAB_BIT) == 0) {
                dev_err(dev, "heater failed to reach the target temperature\n");
                return -EINVAL;
        }
 
-       ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
-                              &tmp, sizeof(tmp));
-       if (ret < 0) {
-               dev_err(dev, "failed to read gas resistance\n");
-               return ret;
-       }
-
-       gas_range = check & BME680_GAS_RANGE_MASK;
-       adc_gas_res = be16_to_cpu(tmp) >> BME680_ADC_GAS_RES_SHIFT;
+       gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val);
 
        *val = bme680_compensate_gas(data, adc_gas_res, gas_range);
        return IIO_VAL_INT;