1

iio: chemical: bme680: Modify startup procedure

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].

Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L162 # [1]
Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/examples/forced_mode/forced_mode.c#L44 # [2]
Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/examples/forced_mode/forced_mode.c#L53 # [3]
Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/examples/forced_mode/forced_mode.c#L60 # [4]
Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L640 # [5]
Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L294 # [6]
Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Link: https://patch.msgid.link/20240609233826.330516-12-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Vasileios Amoiridis 2024-06-10 01:38:22 +02:00 committed by Jonathan Cameron
parent 8bc1f428ba
commit fe358e57af
2 changed files with 16 additions and 7 deletions

View File

@ -63,6 +63,8 @@
#define BME680_MEAS_TRIM_MASK GENMASK(24, 4) #define BME680_MEAS_TRIM_MASK GENMASK(24, 4)
#define BME680_STARTUP_TIME_US 5000
/* Calibration Parameters */ /* Calibration Parameters */
#define BME680_T2_LSB_REG 0x8A #define BME680_T2_LSB_REG 0x8A
#define BME680_H2_MSB_REG 0xE1 #define BME680_H2_MSB_REG 0xE1

View File

@ -531,6 +531,11 @@ static int bme680_gas_config(struct bme680_data *data)
int ret; int ret;
u8 heatr_res, heatr_dur; 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); heatr_res = bme680_calc_heater_res(data, data->heater_temp);
/* set target heater temperature */ /* set target heater temperature */
@ -866,6 +871,8 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
return ret; return ret;
} }
usleep_range(BME680_STARTUP_TIME_US, BME680_STARTUP_TIME_US + 1000);
ret = regmap_read(regmap, BME680_REG_CHIP_ID, &data->check); ret = regmap_read(regmap, BME680_REG_CHIP_ID, &data->check);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "Error reading chip ID\n"); dev_err(dev, "Error reading chip ID\n");
@ -878,6 +885,13 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
return -ENODEV; return -ENODEV;
} }
ret = bme680_read_calib(data, &data->bme680);
if (ret < 0) {
dev_err(dev,
"failed to read calibration coefficients at probe\n");
return ret;
}
ret = bme680_chip_config(data); ret = bme680_chip_config(data);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "failed to set chip_config data\n"); dev_err(dev, "failed to set chip_config data\n");
@ -890,13 +904,6 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
return ret; return ret;
} }
ret = bme680_read_calib(data, &data->bme680);
if (ret < 0) {
dev_err(dev,
"failed to read calibration coefficients at probe\n");
return ret;
}
return devm_iio_device_register(dev, indio_dev); return devm_iio_device_register(dev, indio_dev);
} }
EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680); EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680);