[PATCH v2 15/19] iio: chemical: bme680: Modify startup procedure

From: Vasileios Amoiridis
Date: Thu Jun 06 2024 - 17:28:47 EST


Modify the startup procedure to reflect the procedure of
the Bosch BME68x Sensor API. The initial readings and
configuration of the sensor need to happen in the
following order:

1) Read calibration data [1,2]
2) Chip general configuration [3]
3) Gas configuration [4]

After the chip configuration it is necessary to ensure that
the sensor is in sleeping mode, in order to apply the gas
configuration settings [5].

Also, after the soft reset, it is advised to wait for 5ms [6].

[1]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L162
[2]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/examples/forced_mode/forced_mode.c#L44
[3]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/examples/forced_mode/forced_mode.c#L53
[4]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/examples/forced_mode/forced_mode.c#L60
[5]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L640
[6]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L294
Signed-off-by: Vasileios Amoiridis <vassilisamir@xxxxxxxxx>
---
drivers/iio/chemical/bme680.h | 2 ++
drivers/iio/chemical/bme680_core.c | 21 ++++++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h
index 7d0ff294725a..b2c547ac8d34 100644
--- a/drivers/iio/chemical/bme680.h
+++ b/drivers/iio/chemical/bme680.h
@@ -63,6 +63,8 @@

#define BME680_MEAS_TRIM_MASK GENMASK(24, 4)

+#define BME680_STARTUP_TIME_US 5000
+
/* Calibration Parameters */
#define BME680_T2_LSB_REG 0x8A
#define BME680_H2_MSB_REG 0xE1
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index 25d128e1ddcf..e354eaa34d59 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -531,6 +531,11 @@ static int bme680_gas_config(struct bme680_data *data)
int ret;
u8 heatr_res, heatr_dur;

+ /* Go to sleep */
+ ret = bme680_set_mode(data, false);
+ if (ret < 0)
+ return ret;
+
heatr_res = bme680_calc_heater_res(data, data->heater_temp);

/* set target heater temperature */
@@ -866,6 +871,8 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
return ret;
}

+ usleep_range(BME680_STARTUP_TIME_US, BME680_STARTUP_TIME_US + 1000);
+
ret = regmap_read(regmap, BME680_REG_CHIP_ID, &data->check);
if (ret < 0) {
dev_err(dev, "Error reading chip ID\n");
@@ -878,22 +885,22 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
return -ENODEV;
}

- ret = bme680_chip_config(data);
+ ret = bme680_read_calib(data, &data->bme680);
if (ret < 0) {
- dev_err(dev, "failed to set chip_config data\n");
+ dev_err(dev,
+ "failed to read calibration coefficients at probe\n");
return ret;
}

- ret = bme680_gas_config(data);
+ ret = bme680_chip_config(data);
if (ret < 0) {
- dev_err(dev, "failed to set gas config data\n");
+ dev_err(dev, "failed to set chip_config data\n");
return ret;
}

- ret = bme680_read_calib(data, &data->bme680);
+ ret = bme680_gas_config(data);
if (ret < 0) {
- dev_err(dev,
- "failed to read calibration coefficients at probe\n");
+ dev_err(dev, "failed to set gas config data\n");
return ret;
}

--
2.25.1