[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240527183805.311501-17-vassilisamir@gmail.com>
Date: Mon, 27 May 2024 20:38:04 +0200
From: Vasileios Amoiridis <vassilisamir@...il.com>
To: jic23@...nel.org,
lars@...afoo.de
Cc: himanshujha199640@...il.com,
linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org,
Vasileios Amoiridis <vassilisamir@...il.com>
Subject: [PATCH v1 16/17] iio: chemical: bme680: Move forced mode setup in ->read_raw()
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@...il.com>
---
drivers/iio/chemical/bme680_core.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index a91b15626ec8..8f977667249b 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -560,13 +560,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;
-
- bme680_wait_for_eoc(data);
-
ret = regmap_bulk_read(data->regmap, BME680_REG_TEMP_MSB,
data->buf, BME680_TEMP_NUM_BYTES);
if (ret < 0) {
@@ -669,13 +662,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;
-
- bme680_wait_for_eoc(data);
-
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");
@@ -713,9 +699,17 @@ 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;
+
+ bme680_wait_for_eoc(data);
+
switch (mask) {
case IIO_CHAN_INFO_PROCESSED:
switch (chan->type) {
--
2.25.1
Powered by blists - more mailing lists