: chemical: bme680: 2nd set of clean and add
Subsystems (2)
cover : chemical: bme680: 2nd set of clean and add
This patch series is continuing the work that started on [1] by improving some small issues of the driver in the commits 1,2,3.
Commits 4,5 are refactorizing existing code.
Commits 6,7,8 are adding DT, regulator and PM support.
Commit 9 is refactorizing one macro to attribute.
Commit 10,11,12 are refactorizing the read/compensate functions to become generic and add triggered buffer support.
Finally, commit 13 adds support for an *output* channel of type IIO_CURRENT in order to preheat the plate that is used to measure the quality of the air.
This and the previous series [1] started with the idea to add support for the new bme688 device but due to the structure of the driver I decided that it is better to restructure and improve some things before adding extra funcitonalities.
[1]: https://lore.kernel.org/linux-iio/[email protected]
Vasileios Amoiridis (13):
iio: chemical: bme680: Fix indentation and unnecessary spaces
iio: chemical: bme680: avoid using camel case
iio: chemical: bme680: fix startup time
iio: chemical: bme680: move to fsleep()
iio: chemical: bme680: refactorize set_mode() mode
dt-bindings: iio: add binding for BME680 driver
iio: chemical: bme680: add regulators
iio: chemical: bme680: add power management
iio: chemical: bme680: Move ambient temperature to attributes
iio: chemical: bme680: generalize read_*() functions
iio: chemical: bme680: Add SCALE and RAW channels
iio: chemical: bme680: Add triggered buffer support
iio: chemical: bme680: Add support for preheat current
.../bindings/iio/chemical/bosch,bme680.yaml | 64 ++ drivers/iio/chemical/Kconfig | 2 + drivers/iio/chemical/bme680.h | 7 +- drivers/iio/chemical/bme680_core.c | 554 +++++++++++++++--- 4 files changed, 556 insertions(+), 71 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml
Signature · 1 line
2.43.0
PATCH 1/13 iio: chemical: bme680: Fix indentation and unnecessary spaces
From: Vasileios Amoiridis <[email protected]>
Fix indentation issues, line breaking and unnecessary spaces reported by checkpatch.pl.
--- drivers/iio/chemical/bme680_core.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/iio/chemical/bme680_core.c +13 -20
@@ -224,7 +224,7 @@ static int bme680_read_calib(struct bme680_data *data, calib->res_heat_val = data->bme680_cal_buf_3[RES_HEAT_VAL ]; calib->res_heat_range =FIELD_GET (BME680_RHRANGE_MASK , - data->bme680_cal_buf_3[RES_HEAT_RANGE ]); + data->bme680_cal_buf_3[RES_HEAT_RANGE ]); calib->range_sw_err =FIELD_GET (BME680_RSERROR_MASK , data->bme680_cal_buf_3[RANGE_SW_ERR ]);
@@ -294,8 +294,7 @@ static int bme680_get_t_fine(struct bme680_data *data, s32 *t_fine)return 0 ; } -static s16 bme680_compensate_temp (struct bme680_data *data, -u32 adc_temp) +static s16 bme680_compensate_temp (struct bme680_data *data,u32 adc_temp) {return (bme680_calc_t_fine (data, adc_temp) *5 +128 ) /256 ; }
@@ -445,12 +444,12 @@ static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc,2136746228u ,2147483647u ,2126008810u , 2147483647u, 2147483647u}; - var1 = ((1340 + (5 * (s64 ) calib->range_sw_err)) * - ((s64 ) lookupTable[gas_range])) >>16 ; + var1 = ((1340 + (5 * (s64 )calib->range_sw_err)) * + ((s64 )lookupTable[gas_range])) >>16 ; var2 = ((gas_res_adc <<15 ) -16777216 ) + var1; var3 = ((125000 << (15 - gas_range)) * var1) >>9 ; var3 += (var2 >>1 ); - calc_gas_res =div64_s64 (var3, (s64 ) var2); + calc_gas_res =div64_s64 (var3, (s64 )var2);return calc_gas_res; }
@@ -468,7 +467,7 @@ static u8 bme680_calc_heater_res(struct bme680_data *data, u16 temp)if (temp >400 )/* Cap temperature */ temp =400 ; - var1 = (((s32 )BME680_AMB_TEMP * calib->par_gh3) /1000 ) *256 ; + var1 = (((s32 )BME680_AMB_TEMP * calib->par_gh3) /1000 ) *256 ; var2 = (calib->par_gh1 +784 ) * (((((calib->par_gh2 +154009 ) * temp *5 ) /100 ) +3276800 ) /10 );
@@ -571,9 +570,8 @@ static int bme680_chip_config(struct bme680_data *data)int ret;u8 osrs; - osrs =FIELD_PREP ( -BME680_OSRS_HUMIDITY_MASK , -bme680_oversampling_to_reg (data->oversampling_humid)); + osrs =FIELD_PREP (BME680_OSRS_HUMIDITY_MASK , +bme680_oversampling_to_reg (data->oversampling_humid));/* * Highly recommended to set oversampling of humidity before * temperature/pressure oversampling.
@@ -587,8 +585,7 @@ static int bme680_chip_config(struct bme680_data *data)/* IIR filter settings */ ret =regmap_update_bits (data->regmap,BME680_REG_CONFIG , -BME680_FILTER_MASK , -BME680_FILTER_COEFF_VAL ); +BME680_FILTER_MASK ,BME680_FILTER_COEFF_VAL );if (ret <0 ) {dev_err (dev,"failed to write config register\n" );return ret;
@@ -664,8 +661,7 @@ static int bme680_read_temp(struct bme680_data *data, int *val)return IIO_VAL_INT ; } -static int bme680_read_press (struct bme680_data *data, -int *val,int *val2) +static int bme680_read_press (struct bme680_data *data,int *val,int *val2) {int ret;u32 adc_press;
@@ -684,8 +680,7 @@ static int bme680_read_press(struct bme680_data *data,return IIO_VAL_FRACTIONAL ; } -static int bme680_read_humid (struct bme680_data *data, -int *val,int *val2) +static int bme680_read_humid (struct bme680_data *data,int *val,int *val2) {int ret;u32 adc_humidity, comp_humidity;
@@ -706,8 +701,7 @@ static int bme680_read_humid(struct bme680_data *data,return IIO_VAL_FRACTIONAL ; } -static int bme680_read_gas (struct bme680_data *data, -int *val) +static int bme680_read_gas (struct bme680_data *data,int *val) {struct device *dev =regmap_get_device (data->regmap);int ret;
@@ -889,8 +883,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->heater_temp =320 ;/* degree Celsius */ data->heater_dur =150 ;/* milliseconds */ - ret =regmap_write (regmap,BME680_REG_SOFT_RESET , -BME680_CMD_SOFTRESET ); + ret =regmap_write (regmap,BME680_REG_SOFT_RESET ,BME680_CMD_SOFTRESET );if (ret <0 )return dev_err_probe (dev, ret,"Failed to reset chip\n" );
Signature · 1 line
2.43.0
Re: [PATCH v1 01/13] iio: chemical: bme680: Fix indentation and unnecessary spaces
Quoted 4 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Fix indentation issues, line breaking and unnecessary spaces reported by checkpatch.pl.
Can we move this to be the last (or close to the end) in the series?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 01/13] iio: chemical: bme680: Fix indentation and unnecessary spaces
Quoted 13 lines · Andy Shevchenko
Quoted 4 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Fix indentation issues, line breaking and unnecessary spaces reported by checkpatch.pl.
Can we move this to be the last (or close to the end) in the series?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
Yes, will do it.
PATCH 2/13 iio: chemical: bme680: avoid using camel case
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Rename camel case variable, as checkpatch.pl complains.
--- drivers/iio/chemical/bme680_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +2 -2
@@ -437,7 +437,7 @@ static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc,u32 calc_gas_res;/* Look up table for the possible gas range values */ -static const u32 lookupTable[16 ] = {2147483647u ,2147483647u , +static const u32 lookup_table[16 ] = {2147483647u ,2147483647u ,2147483647u ,2147483647u ,2147483647u ,2126008810u ,2147483647u ,2130303777u ,2147483647u ,2147483647u ,2143188679u ,
@@ -445,7 +445,7 @@ static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, 2147483647u, 2147483647u}; var1 = ((1340 + (5 * (s64 )calib->range_sw_err)) * - ((s64 )lookupTable[gas_range])) >>16 ; + ((s64 )lookup_table[gas_range])) >>16 ; var2 = ((gas_res_adc <<15 ) -16777216 ) + var1; var3 = ((125000 << (15 - gas_range)) * var1) >>9 ; var3 += (var2 >>1 );
Signature · 1 line
2.43.0
Re: [PATCH v1 02/13] iio: chemical: bme680: avoid using camel case
Quoted 3 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Rename camel case variable, as checkpatch.pl complains.
With given reply to the first patch...
...
drivers/iio/chemical/bme680_core.c static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, · line 443
Quoted 6 lines
drivers/iio/chemical/bme680_core.c +1
-1/* Look up table for the possible gas range values */ -static const u32 lookupTable[16 ] = {2147483647u ,2147483647u , +static const u32 lookup_table[16 ] = {2147483647u ,2147483647u ,2147483647u ,2147483647u ,2147483647u ,2126008810u ,2147483647u ,2130303777u ,2147483647u ,2147483647u ,2143188679u ,
...here is the opportunity to fix indentation while at fixing the code. I.o.w. I would reformat the entire table to be
static const u32 lookup_table[16] = {
2147483647u, 2147483647u, 2147483647u, 2147483647u,
2147483647u, 2126008810u, 2147483647u, 2130303777u,
2147483647u, 2147483647u, 2143188679u, ...(also note power-of-2 number of items per line which much easier to read and
find one you need).
...
drivers/iio/chemical/bme680_core.c static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, · line 448
Quoted 3 lines
drivers/iio/chemical/bme680_core.c +1
-1var1 = ((1340 + (5 * (s64 )calib->range_sw_err)) * - ((s64 )lookupTable[gas_range])) >>16 ; + ((s64 )lookup_table[gas_range])) >>16 ;
Also an opportunity to make this neater like
var1 = (1340 + (5 * (s64)calib->range_sw_err)) * (s64)lookup_table[gas_range]); var1 >>= 16;
So, at bare minumym there are redundant parentheses. And looking at the table and the first argument of multiplication I'm puzzled why casting is needed for the second? Shouldn't s64 already be implied by the first one?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 02/13] iio: chemical: bme680: avoid using camel case
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Rename camel case variable, as checkpatch.pl complains.
With given reply to the first patch...
Hi Andy,
Quoted 12 lines
...
drivers/iio/chemical/bme680_core.c static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, · line 443
Quoted 6 lines
drivers/iio/chemical/bme680_core.c +1
-1/* Look up table for the possible gas range values */ -static const u32 lookupTable[16 ] = {2147483647u ,2147483647u , +static const u32 lookup_table[16 ] = {2147483647u ,2147483647u ,2147483647u ,2147483647u ,2147483647u ,2126008810u ,2147483647u ,2130303777u ,2147483647u ,2147483647u ,2143188679u ,...here is the opportunity to fix indentation while at fixing the code. I.o.w. I would reformat the entire table to be
Quoted 8 lines
static const u32 lookup_table[16] = { 2147483647u, 2147483647u, 2147483647u, 2147483647u, 2147483647u, 2126008810u, 2147483647u, 2130303777u, 2147483647u, 2147483647u, 2143188679u, ...(also note power-of-2 number of items per line which much easier to read and
find one you need).
ACK.
Quoted 8 lines
...
drivers/iio/chemical/bme680_core.c static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, · line 448
Quoted 3 lines
drivers/iio/chemical/bme680_core.c +1
-1var1 = ((1340 + (5 * (s64 )calib->range_sw_err)) * - ((s64 )lookupTable[gas_range])) >>16 ; + ((s64 )lookup_table[gas_range])) >>16 ;Also an opportunity to make this neater like
Quoted 12 lines
var1 = (1340 + (5 * (s64)calib->range_sw_err)) * (s64)lookup_table[gas_range]); var1 >>= 16;So, at bare minumym there are redundant parentheses. And looking at the table and the first argument of multiplication I'm puzzled why casting is needed for the second? Shouldn't s64 already be implied by the first one?
Signature · 2 lines
With Best Regards, Andy Shevchenko
I think the 2nd cast indeed is not needed since the 1st one forces the s64 so I can remove it.
Cheers,
Vasilis
Re: [PATCH v1 02/13] iio: chemical: bme680: avoid using camel case
Fri, Oct 11, 2024 at 08:50:27PM +0200, Vasileios Aoiridis kirjoitti:
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · vamoirid
...
Quoted 9 lines
Quoted 9 lines
drivers/iio/chemical/bme680_core.c static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, · line 448
Quoted 3 lines
drivers/iio/chemical/bme680_core.c +1
-1var1 = ((1340 + (5 * (s64 )calib->range_sw_err)) * - ((s64 )lookupTable[gas_range])) >>16 ; + ((s64 )lookup_table[gas_range])) >>16 ;Also an opportunity to make this neater like
var1 = (1340 + (5 * (s64)calib->range_sw_err)) * (s64)lookup_table[gas_range]); var1 >>= 16;
Quoted 6 lines
Quoted 3 lines
So, at bare minumym there are redundant parentheses. And looking at the table and the first argument of multiplication I'm puzzled why casting is needed for the second? Shouldn't s64 already be implied by the first one?
I think the 2nd cast indeed is not needed since the 1st one forces the s64 so I can remove it.
Thinking about this more, you don't need the first either, if using 5LL instead of 5.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 3/13 iio: chemical: bme680: fix startup time
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms.
--- drivers/iio/chemical/bme680.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/bme680.h +1 -1
@@ -63,7 +63,7 @@#define BME680_MEAS_TRIM_MASK GENMASK(24, 4) -#define BME680_STARTUP_TIME_US 5000 +#define BME680_STARTUP_TIME_US 2000/* Calibration Parameters */ #define BME680_T2_LSB_REG 0x8A
Signature · 1 line
2.43.0
Re: [PATCH v1 03/13] iio: chemical: bme680: fix startup time
Quoted 4 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms.
Fixes tag?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 03/13] iio: chemical: bme680: fix startup time
Quoted 13 lines · Andy Shevchenko
Quoted 4 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms.
Fixes tag?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
It is not affecting at all the operation of the driver so I was not sure if it was worth it to be backported to the previous versions. This is why I didn't put a fixes tag. You think for such a fix is necessary?
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 03/13] iio: chemical: bme680: fix startup time
Quoted 15 lines · On Fri, 11 Oct 2024 20:51:41 +0200 Vasileios Aoiridis <[email protected]>…
Quoted 13 lines · Andy Shevchenko
Quoted 4 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms.
Fixes tag?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines
Hi Andy,
It is not affecting at all the operation of the driver so I was not sure if it was worth it to be backported to the previous versions. This is why I didn't put a fixes tag. You think for such a fix is necessary?
Not for a reduction in sleep and not a huge one at that. It's an optimization, not a fix to my eyes!
Quoted 2 lines
Cheers,
Vasilis
Re: [PATCH v1 03/13] iio: chemical: bme680: fix startup time
In reply to Vasileios AoiridisFri, Oct 11, 2024 at 08:51:41PM +0200, Vasileios Aoiridis kirjoitti:
Quoted 11 lines · Andy Shevchenko
Quoted 6 lines · vamoirid
Quoted 3 lines
According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms.
Fixes tag?
It is not affecting at all the operation of the driver so I was not sure if it was worth it to be backported to the previous versions. This is why I didn't put a fixes tag. You think for such a fix is necessary?
The commit message siggests that this is a fix. If you want to make it clear, that it shouldn't be considered as a such, perhaps you need to rephrase it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 4/13 iio: chemical: bme680: move to fsleep()
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Use the new fsleep() function in the remaining driver instances.
--- drivers/iio/chemical/bme680_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +2 -2
@@ -545,7 +545,7 @@ static int bme680_wait_for_eoc(struct bme680_data *data) data->oversampling_humid) * 1936) + (477 * 4) + (477 *5 ) +1000 + (data->heater_dur *1000 ); -usleep_range (wait_eoc_us, wait_eoc_us +100 ); +fsleep (wait_eoc_us); ret =regmap_read (data->regmap,BME680_REG_MEAS_STAT_0 , &data->check);if (ret) {
@@ -887,7 +887,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,if (ret <0 )return dev_err_probe (dev, ret,"Failed to reset chip\n" ); -usleep_range (BME680_STARTUP_TIME_US ,BME680_STARTUP_TIME_US +1000 ); +fsleep (BME680_STARTUP_TIME_US ); ret =regmap_read (regmap,BME680_REG_CHIP_ID , &data->check);if (ret <0 )
Signature · 1 line
2.43.0
PATCH 5/13 iio: chemical: bme680: refactorize set_mode() mode
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Refactorize the set_mode() function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode.
--- drivers/iio/chemical/bme680_core.c | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-)
drivers/iio/chemical/bme680_core.c +19 -17
@@ -95,6 +95,11 @@ struct bme680_calib {s8 range_sw_err; }; +enum bme680_op_mode { +BME680_SLEEP , +BME680_FORCED , +}; +struct bme680_data {struct regmap *regmap;struct bme680_calib bme680;
@@ -501,25 +506,24 @@ static u8 bme680_calc_heater_dur(u16 dur)return durval; } -static int bme680_set_mode (struct bme680_data *data,bool mode) +static int bme680_set_mode (struct bme680_data *data,enum bme680_op_mode mode) {struct device *dev =regmap_get_device (data->regmap);int ret; -if (mode) { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_FORCED ); -if (ret <0 ) -dev_err (dev,"failed to set forced mode\n" ); - - }else { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_SLEEP ); -if (ret <0 ) -dev_err (dev,"failed to set sleep mode\n" ); - +switch (mode) { +case BME680_SLEEP : +case BME680_FORCED : +break ; +default : +return -EINVAL ; } + ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , +BME680_MODE_MASK , mode); +if (ret <0 ) +dev_err (dev,"failed to set ctrl_meas register\n" ); +return ret; }
@@ -612,8 +616,7 @@ 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); + ret =bme680_set_mode (data,BME680_SLEEP );if (ret <0 )return ret;
@@ -750,8 +753,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev,guard (mutex)(&data->lock); -/* set forced mode to trigger measurement */ - ret =bme680_set_mode (data, true); + ret =bme680_set_mode (data,BME680_FORCED );if (ret <0 )return ret;
Signature · 1 line
2.43.0
Re: [PATCH v1 05/13] iio: chemical: bme680: refactorize set_mode() mode
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Refactorize the
set_mode()function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode.
...
Quoted 14 lines
drivers/iio/chemical/bme680_core.c +2
-12-if (mode) { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_FORCED ); -if (ret <0 ) -dev_err (dev,"failed to set forced mode\n" ); - - }else { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_SLEEP ); -if (ret <0 ) -dev_err (dev,"failed to set sleep mode\n" ); - +switch (mode) { +case BME680_SLEEP :
drivers/iio/chemical/bme680_core.c static u8 bme680_calc_heater_dur(u16 dur) · line 525
Quoted 10 lines
drivers/iio/chemical/bme680_core.c +8
-0+case BME680_FORCED : +break ; +default : +return -EINVAL ; } + ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , +BME680_MODE_MASK , mode); +if (ret <0 ) +dev_err (dev,"failed to set ctrl_meas register\n" );
This is an information loss. You shuld probably still have a value of mode to be printed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 05/13] iio: chemical: bme680: refactorize set_mode() mode
Quoted 29 lines · Andy Shevchenko
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Refactorize the
set_mode()function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode....
Quoted 20 lines
drivers/iio/chemical/bme680_core.c +6
-12-if (mode) { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_FORCED ); -if (ret <0 ) -dev_err (dev,"failed to set forced mode\n" ); - - }else { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_SLEEP ); -if (ret <0 ) -dev_err (dev,"failed to set sleep mode\n" ); - +switch (mode) { +case BME680_SLEEP : +case BME680_FORCED : +break ; +default : +return -EINVAL ; }
Quoted 13 lines
drivers/iio/chemical/bme680_core.c static u8 bme680_calc_heater_dur(u16 dur) · line 525
Quoted 4 lines
drivers/iio/chemical/bme680_core.c +4
-0+ ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , +BME680_MODE_MASK , mode); +if (ret <0 ) +dev_err (dev,"failed to set ctrl_meas register\n" );This is an information loss. You shuld probably still have a value of mode to be printed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
You are right, I missed a return here.
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 05/13] iio: chemical: bme680: refactorize set_mode() mode
In reply to vamoiridQuoted 42 lines · On Thu, 10 Oct 2024 23:00:22 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Refactorize the
set_mode()function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode.Signed-off-by Vasileios Amoiridis <[email protected]>--- drivers/iio/chemical/bme680_core.c | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-)drivers/iio/chemical/bme680_core.c +6
-6@@ -95,6 +95,11 @@ struct bme680_calib {s8 range_sw_err; }; +enum bme680_op_mode { +BME680_SLEEP , +BME680_FORCED , +}; +struct bme680_data {struct regmap *regmap;struct bme680_calib bme680;@@ -501,25 +506,24 @@ static u8 bme680_calc_heater_dur(u16 dur)return durval; } -static int bme680_set_mode (struct bme680_data *data,bool mode) +static int bme680_set_mode (struct bme680_data *data,enum bme680_op_mode mode) {struct device *dev =regmap_get_device (data->regmap);int ret; -if (mode) { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_FORCED ); -if (ret <0 ) -dev_err (dev,"failed to set forced mode\n" );
drivers/iio/chemical/bme680_core.c static u8 bme680_calc_heater_dur(u16 dur) · line 516
Quoted 10 lines
drivers/iio/chemical/bme680_core.c +3
-7- - }else { - ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , -BME680_MODE_MASK ,BME680_MODE_SLEEP ); -if (ret <0 ) -dev_err (dev,"failed to set sleep mode\n" ); - +switch (mode) { +case BME680_SLEEP : +case BME680_FORCED :
You are passing in an enum that currently has no other values. The compiler should complain if it isn't one of these (and it can tell)
So unless I'm missing you adding another enum value later, this switch should be unnecessary.
Quoted 33 lines
drivers/iio/chemical/bme680_core.c +10
-4+break ; +default : +return -EINVAL ; } + ret =regmap_write_bits (data->regmap,BME680_REG_CTRL_MEAS , +BME680_MODE_MASK , mode); +if (ret <0 ) +dev_err (dev,"failed to set ctrl_meas register\n" ); +return ret; }@@ -612,8 +616,7 @@ 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); + ret =bme680_set_mode (data,BME680_SLEEP );if (ret <0 )return ret;@@ -750,8 +753,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev,guard (mutex)(&data->lock); -/* set forced mode to trigger measurement */ - ret =bme680_set_mode (data, true); + ret =bme680_set_mode (data,BME680_FORCED );if (ret <0 )return ret;
PATCH 6/13 dt-bindings: iio: add binding for BME680 driver
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Add dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors.
--- .../bindings/iio/chemical/bosch,bme680.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml
Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml new file +64 -0
@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/bosch,bme680.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch BME680 Gas sensor + +maintainers: + - Vasileios Amoiridis <[email protected]> + +description: + BME680 is a gas sensor which combines relative humidity, barometric pressure, + ambient temperature and gas (VOC - Volatile Organic Compounds) measurements. + + https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme680-ds001.pdf + +properties: + compatible: + const: bosch,bme680 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + bme680@77 { + compatible = "bosch,bme680"; + reg = <0x77>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + bme680@0 { + compatible = "bosch,bme680"; + reg = <0>; + spi-max-frequency = <500000>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + };
Signature · 1 line
2.43.0
Rob Herring (Arm)
maintainerRe: [PATCH v1 06/13] dt-bindings: iio: add binding for BME680 driver
Quoted 11 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors.
Signed-off-by Vasileios Amoiridis <[email protected]>--- .../bindings/iio/chemical/bosch,bme680.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
Warning: Duplicate compatible "bosch,bme680" found in schemas matching "$id":
http://devicetree.org/schemas/iio/chemical/bosch,bme680.yaml#
http://devicetree.org/schemas/trivial-devices.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.example.dtb: bme680@77: 'vdd-supply', 'vddio-supply' do not match any of the regexes: 'pinctrl-[0-9]+'
from schema $id: http://devicetree.org/schemas/trivial-devices.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.example.dtb: bme680@0: 'vdd-supply', 'vddio-supply' do not match any of the regexes: 'pinctrl-[0-9]+'
from schema $id: http://devicetree.org/schemas/trivial-devices.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v1 06/13] dt-bindings: iio: add binding for BME680 driver
In reply to vamoiridQuoted 10 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors.
Signed-off-by Vasileios Amoiridis <[email protected]>--- .../bindings/iio/chemical/bosch,bme680.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml
The device is already documented. You need to move it from trivial devices.
Best regards,
Krzysztof
Re: [PATCH v1 06/13] dt-bindings: iio: add binding for BME680 driver
Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors.
Signed-off-by Vasileios Amoiridis <[email protected]>--- .../bindings/iio/chemical/bosch,bme680.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml
Quoted 5 lines
The device is already documented. You need to move it from trivial devices.
Best regards,
Krzysztof
Hi Krzysztof!
Thanks for your time to have a look at this!
You mean to keep this new dt-binging and remove it from trivial devices?
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 06/13] dt-bindings: iio: add binding for BME680 driver
Quoted 19 lines · On Fri, 11 Oct 2024 20:44:51 +0200 Vasileios Aoiridis <[email protected]>…
Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors.
Signed-off-by Vasileios Amoiridis <[email protected]>--- .../bindings/iio/chemical/bosch,bme680.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yamlQuoted 5 lines
The device is already documented. You need to move it from trivial devices.
Best regards,
Krzysztof
Quoted 6 lines
Hi Krzysztof!
Thanks for your time to have a look at this!
You mean to keep this new dt-binging and remove it from trivial devices?
Yes
Quoted 3 lines
Cheers,
Vasilis
PATCH 7/13 iio: chemical: bme680: add regulators
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Add support for the regulators described in the dt-binding.
--- drivers/iio/chemical/bme680_core.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/iio/chemical/bme680_core.c +30 -0
@@ -15,6 +15,7 @@#include <linux/log2.h> #include <linux/module.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -100,6 +101,12 @@ enum bme680_op_mode { BME680_FORCED, }; +static const char *const bme680_supply_names[] = { +"vdd" ,"vddio" +}; + +#define BME680_NUM_SUPPLIES ARRAY_SIZE(bme680_supply_names) +struct bme680_data {struct regmap *regmap;struct bme680_calib bme680;
@@ -110,6 +117,8 @@ struct bme680_data {u16 heater_dur;u16 heater_temp; +struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ]; +union {u8 buf[3 ];unsigned int check;
@@ -857,6 +866,13 @@ static const struct iio_info bme680_info = { .attrs = &bme680_attribute_group, }; +static void bme680_regulators_disable (void *data) +{ +struct regulator_bulk_data *supplies = data; + +regulator_bulk_disable (BME680_NUM_SUPPLIES , supplies); +} +int bme680_core_probe (struct device *dev,struct regmap *regmap,const char *name) {
@@ -885,6 +901,20 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->heater_temp =320 ;/* degree Celsius */ data->heater_dur =150 ;/* milliseconds */ +regulator_bulk_set_supply_names (data->supplies, bme680_supply_names, +BME680_NUM_SUPPLIES ); + ret =devm_regulator_bulk_get (dev,BME680_NUM_SUPPLIES , data->supplies); +if (ret) +return dev_err_probe (dev, ret,"failed to get regulators\n" ); + + ret =regulator_bulk_enable (BME680_NUM_SUPPLIES , data->supplies); +if (ret) +return dev_err_probe (dev, ret,"failed to enable regulators\n" ); + +devm_add_action_or_reset (dev, bme680_regulators_disable, data->supplies); + +fsleep (BME680_STARTUP_TIME_US ); + ret =regmap_write (regmap,BME680_REG_SOFT_RESET ,BME680_CMD_SOFTRESET );if (ret <0 )return dev_err_probe (dev, ret,"Failed to reset chip\n" );
Signature · 1 line
2.43.0
Re: [PATCH v1 07/13] iio: chemical: bme680: add regulators
Quoted 3 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add support for the regulators described in the dt-binding.
...
drivers/iio/chemical/bme680_core.c enum bme680_op_mode { · line 105
Quoted 2 lines
drivers/iio/chemical/bme680_core.c +2
-0+static const char *const bme680_supply_names[] = { +"vdd" ,"vddio"
Leave trailing comma.
Quoted 1 line
+};
...
drivers/iio/chemical/bme680_core.c int bme680_core_probe(struct device *dev, struct regmap *regmap, · line 914
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+devm_add_action_or_reset (dev, bme680_regulators_disable, data->supplies);
No error check?! Why?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 07/13] iio: chemical: bme680: add regulators
Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add support for the regulators described in the dt-binding.
...
drivers/iio/chemical/bme680_core.c enum bme680_op_mode { · line 105
Quoted 2 lines
drivers/iio/chemical/bme680_core.c +2
-0+static const char *const bme680_supply_names[] = { +"vdd" ,"vddio" Leave trailing comma.
ACK.
Quoted 8 lines
Quoted 1 line
+};
...
drivers/iio/chemical/bme680_core.c int bme680_core_probe(struct device *dev, struct regmap *regmap, · line 914
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+devm_add_action_or_reset (dev, bme680_regulators_disable, data->supplies);No error check?! Why?
You are right, I should put it, I probably didnit see it!
Quoted 5 lines
Signature · 2 lines
With Best Regards, Andy Shevchenko
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 07/13] iio: chemical: bme680: add regulators
In reply to vamoiridQuoted 58 lines · On Thu, 10 Oct 2024 23:00:24 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Add support for the regulators described in the dt-binding.
Signed-off-by Vasileios Amoiridis <[email protected]>--- drivers/iio/chemical/bme680_core.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)drivers/iio/chemical/bme680_core.c +16
-0@@ -15,6 +15,7 @@#include <linux/log2.h> #include <linux/module.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -100,6 +101,12 @@ enum bme680_op_mode { BME680_FORCED, }; +static const char *const bme680_supply_names[] = { +"vdd" ,"vddio" +}; + +#define BME680_NUM_SUPPLIES ARRAY_SIZE(bme680_supply_names) +struct bme680_data {struct regmap *regmap;struct bme680_calib bme680;@@ -110,6 +117,8 @@ struct bme680_data {u16 heater_dur;u16 heater_temp; +struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ]; +union {u8 buf[3 ];unsigned int check;@@ -857,6 +866,13 @@ static const struct iio_info bme680_info = { .attrs = &bme680_attribute_group, }; +static void bme680_regulators_disable (void *data) +{ +struct regulator_bulk_data *supplies = data; + +regulator_bulk_disable (BME680_NUM_SUPPLIES , supplies); +} +int bme680_core_probe (struct device *dev,struct regmap *regmap,const char *name) {
drivers/iio/chemical/bme680_core.c int bme680_core_probe(struct device *dev, struct regmap *regmap, · line 906
Quoted 6 lines
drivers/iio/chemical/bme680_core.c +3
-0@@ -885,6 +901,20 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->heater_temp =320 ;/* degree Celsius */ data->heater_dur =150 ;/* milliseconds */ +regulator_bulk_set_supply_names (data->supplies, bme680_supply_names, +BME680_NUM_SUPPLIES ); + ret =devm_regulator_bulk_get (dev,BME680_NUM_SUPPLIES , data->supplies);
devm_regulator_bulk_get_enable() should replace all this with functionally equivalent code. You can also have the supplies list local as you don't then need to hang on to a copy.
Quoted 15 lines
drivers/iio/chemical/bme680_core.c +11
-0+if (ret) +return dev_err_probe (dev, ret,"failed to get regulators\n" ); + + ret =regulator_bulk_enable (BME680_NUM_SUPPLIES , data->supplies); +if (ret) +return dev_err_probe (dev, ret,"failed to enable regulators\n" ); + +devm_add_action_or_reset (dev, bme680_regulators_disable, data->supplies); + +fsleep (BME680_STARTUP_TIME_US ); + ret =regmap_write (regmap,BME680_REG_SOFT_RESET ,BME680_CMD_SOFTRESET );if (ret <0 )return
dev_err_probe(dev, ret, "Failed to reset chip\n");
PATCH 8/13 iio: chemical: bme680: add power management
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Add runtime power management to the device. To facilitate this, add also a struct dev * inside the bme680_data structure to have the device accesible from the data structure.
--- drivers/iio/chemical/bme680.h | 1 + drivers/iio/chemical/bme680_core.c | 100 +++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 6 deletions(-)
drivers/iio/chemical/bme680.h +1 -0
@@ -75,6 +75,7 @@#define BME680_CALIB_RANGE_3_LEN 5extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bmp280_dev_pm_ops;int bme680_core_probe (struct device *dev,struct regmap *regmap,const char *name);
drivers/iio/chemical/bme680_core.c +94 -6
157 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v1 08/13] iio: chemical: bme680: add power management
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add runtime power management to the device. To facilitate this, add also a struct dev * inside the
bme680_datastructure to have the device accesible from the data structure.
...
drivers/iio/chemical/bme680.h line 78
Quoted 7 lines
drivers/iio/chemical/bme680.h +1
-0@@ -75,6 +75,7 @@#define BME680_CALIB_RANGE_3_LEN 5extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bmp280_dev_pm_ops;
Is pm.h being included already in this header? Otherwise you need to add it.
...
drivers/iio/chemical/bme680.h
Quoted 4 lines
drivers/iio/chemical/bme680.h +1
-0struct regmap *regmap;struct bme680_calib bme680;struct mutex lock;/* Protect multiple serial R/W ops to device. */ +struct device *dev;
Is it the same that you may get wia regmap_get_device()?
Quoted 3 lines
drivers/iio/chemical/bme680.h +0
-0u8 oversampling_temp;u8 oversampling_press;u8 oversampling_humid;
...
drivers/iio/chemical/bme680.h
Quoted 7 lines
drivers/iio/chemical/bme680.h +7
-0+/* Enable runtime PM */ +pm_runtime_get_noresume (dev); +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_set_autosuspend_delay (dev,BME680_STARTUP_TIME_US *100 ); +pm_runtime_use_autosuspend (dev); +pm_runtime_put (dev);
Can we use devm_pm_runtime_enable() for some of the above?
Quoted 3 lines
drivers/iio/chemical/bme680.h +3
-0+ ret =devm_add_action_or_reset (dev, bme680_pm_disable, dev); +if (ret) +return ret;
...
Quoted 11 lines
drivers/iio/chemical/bme680.h +11
-0+static int bme680_runtime_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct bme680_data *data =iio_priv (indio_dev); +int ret; + + ret =regulator_bulk_enable (BME680_NUM_SUPPLIES , data->supplies); +if (ret) +return ret; + +fsleep (BME680_STARTUP_TIME_US );
drivers/iio/chemical/bme680.h
Quoted 10 lines
drivers/iio/chemical/bme680.h +9
-0+ + ret =bme680_chip_config (data); +if (ret) +return ret; + ret =bme680_gas_config (data); +if (ret) +return ret; + +return 0 ;
return bme680_gas_config(...);
Quoted 1 line
+}
...
drivers/iio/chemical/bme680.h
Quoted 2 lines
drivers/iio/chemical/bme680.h +2
-0+EXPORT_RUNTIME_DEV_PM_OPS (bme680_dev_pm_ops, bme680_runtime_suspend, + bme680_runtime_resume,NULL );
You also need pm.h for the macro IIRC.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 08/13] iio: chemical: bme680: add power management
Quoted 14 lines · Andy Shevchenko
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add runtime power management to the device. To facilitate this, add also a struct dev * inside the
bme680_datastructure to have the device accesible from the data structure....
Quoted 5 lines
drivers/iio/chemical/bme680.h +0
-0@@ -75,6 +75,7 @@#define BME680_CALIB_RANGE_3_LEN 5
Quoted 5 lines
drivers/iio/chemical/bme680.h line 78
Quoted 2 lines
drivers/iio/chemical/bme680.h +1
-0extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bmp280_dev_pm_ops;Is
pm.hbeing included already in this header? Otherwise you need to add it.
No it is not, and indeed I need to add it. Probably because it was included by some other file I didn't get an error from gcc?
Quoted 9 lines
...
drivers/iio/chemical/bme680.h
Quoted 4 lines
drivers/iio/chemical/bme680.h +1
-0struct regmap *regmap;struct bme680_calib bme680;struct mutex lock;/* Protect multiple serial R/W ops to device. */ +struct device *dev;Is it the same that you may get wia
regmap_get_device()?
Yes it is the same. Maybe I can try and see if I can use the following
regmap_get_device(data->regmap)
in the places where the pm functions are used in order to not declare a new value inside the struct bme680_data. But in general, is this approach prefered?
Quoted 6 lines
Quoted 3 lines
drivers/iio/chemical/bme680.h +0
-0u8 oversampling_temp;u8 oversampling_press;u8 oversampling_humid;...
Quoted 10 lines
drivers/iio/chemical/bme680.h
Quoted 7 lines
drivers/iio/chemical/bme680.h +7
-0+/* Enable runtime PM */ +pm_runtime_get_noresume (dev); +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_set_autosuspend_delay (dev,BME680_STARTUP_TIME_US *100 ); +pm_runtime_use_autosuspend (dev); +pm_runtime_put (dev);Can we use
devm_pm_runtime_enable()for some of the above?
I will have to check its use, and I will let you know.
Quoted 22 lines
Quoted 3 lines
drivers/iio/chemical/bme680.h +3
-0+ ret =devm_add_action_or_reset (dev, bme680_pm_disable, dev); +if (ret) +return ret;...
Quoted 15 lines
drivers/iio/chemical/bme680.h +15
-0+static int bme680_runtime_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct bme680_data *data =iio_priv (indio_dev); +int ret; + + ret =regulator_bulk_enable (BME680_NUM_SUPPLIES , data->supplies); +if (ret) +return ret; + +fsleep (BME680_STARTUP_TIME_US ); + + ret =bme680_chip_config (data); +if (ret) +return ret;
Quoted 8 lines
drivers/iio/chemical/bme680.h
Quoted 5 lines
drivers/iio/chemical/bme680.h +5
-0+ ret =bme680_gas_config (data); +if (ret) +return ret; + +return 0 ;return bme680_gas_config(...);
Indeed, much cleaner, thanks!
Quoted 9 lines
Quoted 1 line
+}
...
drivers/iio/chemical/bme680.h
Quoted 2 lines
drivers/iio/chemical/bme680.h +2
-0+EXPORT_RUNTIME_DEV_PM_OPS (bme680_dev_pm_ops, bme680_runtime_suspend, + bme680_runtime_resume,NULL );You also need
pm.hfor the macro IIRC.
ACK.
Quoted 5 lines
Signature · 2 lines
With Best Regards, Andy Shevchenko
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 08/13] iio: chemical: bme680: add power management
Quoted 34 lines · On Fri, 11 Oct 2024 21:02:32 +0200 Vasileios Aoiridis <[email protected]>…
Quoted 14 lines · Andy Shevchenko
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add runtime power management to the device. To facilitate this, add also a struct dev * inside the
bme680_datastructure to have the device accesible from the data structure....
Quoted 5 lines
drivers/iio/chemical/bme680.h +0
-0@@ -75,6 +75,7 @@#define BME680_CALIB_RANGE_3_LEN 5Quoted 5 lines
drivers/iio/chemical/bme680.h line 78
Quoted 2 lines
drivers/iio/chemical/bme680.h +1
-0extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bmp280_dev_pm_ops;Is
pm.hbeing included already in this header? Otherwise you need to add it.No it is not, and indeed I need to add it. Probably because it was included by some other file I didn't get an error from gcc?
Quoted 9 lines
...
drivers/iio/chemical/bme680.h
Quoted 4 lines
drivers/iio/chemical/bme680.h +1
-0struct regmap *regmap;struct bme680_calib bme680;struct mutex lock;/* Protect multiple serial R/W ops to device. */ +struct device *dev;Is it the same that you may get wia
regmap_get_device()?
Quoted 7 lines
Yes it is the same. Maybe I can try and see if I can use the following
regmap_get_device(data->regmap)in the places where the pm functions are used in order to not declare a new value inside the struct
bme680_data. But in general, is this approach prefered?
slightly by me. I tend not to poke on that if people have chosen a local variable, but it is a little neater.
This patch might get caught up in an effort to simplify the autosuspend handling but if it is we'll deal with that whilst merging. There 'should' be a clean path to transition from this style to the proposed new one where a simple pm_runtime_put() without the mark_last_busy stuff is enough for autosuspend cases.
Jonathan
Re: [PATCH v1 08/13] iio: chemical: bme680: add power management
In reply to Vasileios AoiridisFri, Oct 11, 2024 at 09:02:32PM +0200, Vasileios Aoiridis kirjoitti:
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · vamoirid
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+extern const struct
dev_pm_opsbmp280_dev_pm_ops;Is
pm.hbeing included already in this header? Otherwise you need to add it.No it is not, and indeed I need to add it. Probably because it was included by some other file I didn't get an error from gcc?
Yeah, it's called a "proxy" header in general meaning. We should try hard not to use such headers (meaning not to use them in a "proxy" mode).
...
Quoted 8 lines
Quoted 7 lines
drivers/iio/chemical/bme680_core.c struct bme680_data { · line 115
Quoted 4 lines
drivers/iio/chemical/bme680_core.c +1
-0struct regmap *regmap;struct bme680_calib bme680;struct mutex lock;/* Protect multiple serial R/W ops to device. */ +struct device *dev;Is it the same that you may get wia
regmap_get_device()?
Quoted 7 lines
Yes it is the same. Maybe I can try and see if I can use the following
regmap_get_device(data->regmap)in the places where the pm functions are used in order to not declare a new value inside the struct
bme680_data. But in general, is this approach prefered?
Since there is a getter already available, I prefer not to shortcut it via adding a duplicating information to the data structure.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/chemical/bme680_core.c +0
-0u8 oversampling_temp;u8 oversampling_press;u8 oversampling_humid;
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 9/13 iio: chemical: bme680: Move ambient temperature to attributes
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
--- drivers/iio/chemical/bme680.h | 1 - drivers/iio/chemical/bme680_core.c | 35 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680.h +0 -1
@@ -45,7 +45,6 @@#define BME680_REG_RES_HEAT_0 0x5A#define BME680_REG_GAS_WAIT_0 0x64#define BME680_ADC_GAS_RES GENMASK(15, 6) -#define BME680_AMB_TEMP 25#define BME680_REG_CTRL_GAS_1 0x71#define BME680_RUN_GAS_MASK BIT(4)
drivers/iio/chemical/bme680_core.c +34 -1
@@ -120,6 +120,7 @@ struct bme680_data {u16 heater_temp;struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ]; +int ambient_temp;union {u8 buf[3 ];
@@ -483,7 +484,7 @@ static u8 bme680_calc_heater_res(struct bme680_data *data, u16 temp)if (temp >400 )/* Cap temperature */ temp =400 ; - var1 = (((s32 )BME680_AMB_TEMP * calib->par_gh3) /1000 ) *256 ; + var1 = (((s32 )data->ambient_temp * calib->par_gh3) /1000 ) *256 ; var2 = (calib->par_gh1 +784 ) * (((((calib->par_gh2 +154009 ) * temp *5 ) /100 ) +3276800 ) /10 );
@@ -878,6 +879,37 @@ static int bme680_write_raw(struct iio_dev *indio_dev,return ret; } +static ssize_t ambient_temp_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct bme680_data *data =iio_priv (indio_dev); +int vals[2 ]; + + vals[0 ] = data->ambient_temp; + vals[1 ] =1 ; + +return iio_format_value (buf,IIO_VAL_INT ,1 , vals); +} + +static ssize_t ambient_temp_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct bme680_data *data =iio_priv (indio_dev); +int ret, val_int, val_fract; + + ret =iio_str_to_fixpoint (buf,1 , &val_int, &val_fract); +if (ret) +return ret; + + data->ambient_temp = val_int; +return len; +} + +static IIO_DEVICE_ATTR_RW(ambient_temp, 0); +static const char bme680_oversampling_ratio_show[] ="1 2 4 8 16" ; static IIO_CONST_ATTR(oversampling_ratio_available,
@@ -885,6 +917,7 @@ static IIO_CONST_ATTR(oversampling_ratio_available,static struct attribute *bme680_attributes[] = { &iio_const_attr_oversampling_ratio_available.dev_attr.attr, + &iio_dev_attr_ambient_temp.dev_attr.attr,NULL , };
Signature · 1 line
2.43.0
Re: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
Quoted 6 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
...
drivers/iio/chemical/bme680_core.c static u8 bme680_calc_heater_res(struct bme680_data *data, u16 temp) · line 487
Quoted 2 lines
drivers/iio/chemical/bme680_core.c +1
-1- var1 = (((s32 )BME680_AMB_TEMP * calib->par_gh3) /1000 ) *256 ; + var1 = (((s32 )data->ambient_temp * calib->par_gh3) /1000 ) *256 ;
MILLI? KILO?
...
drivers/iio/chemical/bme680_core.c static IIO_CONST_ATTR(oversampling_ratio_available, · line 921
Quoted 4 lines
static struct attribute *bme680_attributes[] = {
drivers/iio/chemical/bme680_core.c +1
-0&iio_const_attr_oversampling_ratio_available.dev_attr.attr, + &iio_dev_attr_ambient_temp.dev_attr.attr, NULL,
Side note: Perhaps a patch or an additional change in the existing one to drop the trailing comma here.
Quoted 1 line
};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
Quoted 7 lines
...
drivers/iio/chemical/bme680_core.c static u8 bme680_calc_heater_res(struct bme680_data *data, u16 temp) · line 487
Quoted 2 lines
drivers/iio/chemical/bme680_core.c +1
-1- var1 = (((s32 )BME680_AMB_TEMP * calib->par_gh3) /1000 ) *256 ; + var1 = (((s32 )data->ambient_temp * calib->par_gh3) /1000 ) *256 ;MILLI? KILO?
I could do it yes.
Quoted 10 lines
...
drivers/iio/chemical/bme680_core.c static IIO_CONST_ATTR(oversampling_ratio_available, · line 921
Quoted 4 lines
static struct attribute *bme680_attributes[] = {
drivers/iio/chemical/bme680_core.c +1
-0&iio_const_attr_oversampling_ratio_available.dev_attr.attr, + &iio_dev_attr_ambient_temp.dev_attr.attr, NULL,Side note: Perhaps a patch or an additional change in the existing one to drop the trailing comma here.
I could add an additional change if you think it is worth the churn.
Quoted 7 lines
Quoted 1 line
};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
In reply to vamoiridQuoted 8 lines · On Thu, 10 Oct 2024 23:00:26 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
Signed-off-by Vasileios Amoiridis <[email protected]>
New ABI? Would need docs.
However, I 'think' we have a few cases where we handle this via the slightly odd interface of out_temp_processed / _raw with a label saying it's ambient temperature.
The tenuous argument is that we have heaters that actually control the temperature and the affect of either heating the thing or just happening to know the external temperature ends up being the same. Hence use an output channel for this control.
Jonathan
Re: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 10 Oct 2024 23:00:26 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
Signed-off-by Vasileios Amoiridis <[email protected]>New ABI? Would need docs.
However, I 'think' we have a few cases where we handle this via the slightly odd interface of
out_temp_processed/_rawwith a label saying it's ambient temperature.
Quoted 6 lines
The tenuous argument is that we have heaters that actually control the temperature and the affect of either heating the thing or just happening to know the external temperature ends up being the same. Hence use an output channel for this control.
Jonathan
Hi Jonathan,
Thanks for taking the time to review this. I saw your previous messages, and I am not responding to all of them so as to not flood you with ACK messages.
For this one though I have to ask. The last commit of this series is adding support for an output current channel that controls the current that is being inserted into an internal plate that is heated up in order to have more precise acquisition of humidity and gas measurement. Does it makes sense to add an ambient temp output channel as well?
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
Quoted 31 lines · On Mon, 14 Oct 2024 22:14:23 +0200 Vasileios Amoiridis…
Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 10 Oct 2024 23:00:26 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
Signed-off-by Vasileios Amoiridis <[email protected]>New ABI? Would need docs.
However, I 'think' we have a few cases where we handle this via the slightly odd interface of
out_temp_processed/_rawwith a label saying it's ambient temperature.Quoted 6 lines
The tenuous argument is that we have heaters that actually control the temperature and the affect of either heating the thing or just happening to know the external temperature ends up being the same. Hence use an output channel for this control.
Jonathan
Hi Jonathan,
Thanks for taking the time to review this. I saw your previous messages, and I am not responding to all of them so as to not flood you with ACK messages.
Quoted 5 lines
For this one though I have to ask. The last commit of this series is adding support for an output current channel that controls the current that is being inserted into an internal plate that is heated up in order to have more precise acquisition of humidity and gas measurement. Does it makes sense to add an ambient temp output channel as well?
If we need to know that temperature to calculate the meaning of the pressure channels then I think it does.
I am a little confused though as this device measures the temperature. Why isn't that the right value to use? Is that because the heater is confusing things?
Quoted 4 lines
Cheers,
Vasilis
Re: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
Quoted 40 lines · Jonathan Cameron
Quoted 31 lines · On Mon, 14 Oct 2024 22:14:23 +0200 Vasileios Amoiridis…
Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 10 Oct 2024 23:00:26 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
Signed-off-by Vasileios Amoiridis <[email protected]>New ABI? Would need docs.
However, I 'think' we have a few cases where we handle this via the slightly odd interface of
out_temp_processed/_rawwith a label saying it's ambient temperature.Quoted 6 lines
The tenuous argument is that we have heaters that actually control the temperature and the affect of either heating the thing or just happening to know the external temperature ends up being the same. Hence use an output channel for this control.
Jonathan
Hi Jonathan,
Thanks for taking the time to review this. I saw your previous messages, and I am not responding to all of them so as to not flood you with ACK messages.
Quoted 5 lines
For this one though I have to ask. The last commit of this series is adding support for an output current channel that controls the current that is being inserted into an internal plate that is heated up in order to have more precise acquisition of humidity and gas measurement. Does it makes sense to add an ambient temp output channel as well?
Quoted 8 lines
If we need to know that temperature to calculate the meaning of the pressure channels then I think it does.
I am a little confused though as this device measures the temperature. Why isn't that the right value to use? Is that because the heater is confusing things?
Hi Jonathan,
Thank you very much for your message! So, I digged a bit more into the device datasheet and I found out that the ambient temperature can actually be taken directly from the measured temperature (p.22 of [1]), I can use this one. This means, that the ambient temp can be fully dropped since the temperature of the sensor is the information we need. Is it ok to drop it fully since it is an ABI change? If not how should I approach this?
Another thing that I had missed because of the way the code was written is that actually we can (and should) use output channel for setting the temperature of the internal heater plate. This sensor essentially has an internal heater plate that allows it to measure the VOC. Currently if you check the driver [2], the value of the requested temperature of the heater is set only once in the probe function and stays all the time like this. This doesn't allow for much flexibility. But it is something that I will do in another series and not this one, since this one is already quite heavy.
Cheers,
Vasilis
PS: I don't understand why Bosch designed the sensor in this way. Since the value of the ambient temp can be either hardcoded or the actual value of the temperature sensor, they could have had all this logic in hardware. They could actually even implement the compensation functions in hardware and just return RAW values to us. It's kind of the same situation with the BME280 and BMP{1,2,3,5}80 drivers that we have.
[1]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme680-ds001.pdf
[2]: https://elixir.bootlin.com/linux/v6.11.4/source/drivers/iio/chemical/bme680_core.c#L989
Quoted 5 lines
Quoted 4 lines
Cheers,
Vasilis
Re: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes
Quoted 52 lines · Vasileios Amoiridis
Quoted 40 lines · Jonathan Cameron
Quoted 31 lines · On Mon, 14 Oct 2024 22:14:23 +0200 Vasileios Amoiridis…
Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 10 Oct 2024 23:00:26 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements.
Signed-off-by Vasileios Amoiridis <[email protected]>New ABI? Would need docs.
However, I 'think' we have a few cases where we handle this via the slightly odd interface of
out_temp_processed/_rawwith a label saying it's ambient temperature.Quoted 6 lines
The tenuous argument is that we have heaters that actually control the temperature and the affect of either heating the thing or just happening to know the external temperature ends up being the same. Hence use an output channel for this control.
Jonathan
Hi Jonathan,
Thanks for taking the time to review this. I saw your previous messages, and I am not responding to all of them so as to not flood you with ACK messages.
Quoted 5 lines
For this one though I have to ask. The last commit of this series is adding support for an output current channel that controls the current that is being inserted into an internal plate that is heated up in order to have more precise acquisition of humidity and gas measurement. Does it makes sense to add an ambient temp output channel as well?
Quoted 8 lines
If we need to know that temperature to calculate the meaning of the pressure channels then I think it does.
I am a little confused though as this device measures the temperature. Why isn't that the right value to use? Is that because the heater is confusing things?
Hi Jonathan,
Quoted 8 lines
Thank you very much for your message! So, I digged a bit more into the device datasheet and I found out that the ambient temperature can actually be taken directly from the measured temperature (p.22 of [1]), I can use this one. This means, that the ambient temp can be fully dropped since the temperature of the sensor is the information we need. Is it ok to drop it fully since it is an ABI change? If not how should I approach this?
Actually in the end, no ABI change because the temperature will be taken from the internal measurement so nothing that has to do with userspace so there is no ABI change here, my mistake!
Vasilis
Quoted 27 lines
Another thing that I had missed because of the way the code was written is that actually we can (and should) use output channel for setting the temperature of the internal heater plate. This sensor essentially has an internal heater plate that allows it to measure the VOC. Currently if you check the driver [2], the value of the requested temperature of the heater is set only once in the probe function and stays all the time like this. This doesn't allow for much flexibility. But it is something that I will do in another series and not this one, since this one is already quite heavy.
Cheers,
VasilisPS: I don't understand why Bosch designed the sensor in this way. Since the value of the ambient temp can be either hardcoded or the actual value of the temperature sensor, they could have had all this logic in hardware. They could actually even implement the compensation functions in hardware and just return RAW values to us. It's kind of the same situation with the BME280 and BMP{1,2,3,5}80 drivers that we have.
[1]: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme680-ds001.pdf
[2]: https://elixir.bootlin.com/linux/v6.11.4/source/drivers/iio/chemical/bme680_core.c#L989Quoted 5 lines
Quoted 4 lines
Cheers,
Vasilis
PATCH 10/13 iio: chemical: bme680: generalize read_*() functions
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Remove the IIO specific scaling measurement units from the read functions and add them inside the ->read_raw() function to keep the read_*() generic. This way they can be used in other parts of the driver.
--- drivers/iio/chemical/bme680_core.c | 65 ++++++++++++++++++------------ 1 file changed, 40 insertions(+), 25 deletions(-)
drivers/iio/chemical/bme680_core.c +40 -25
@@ -661,22 +661,20 @@ static int bme680_gas_config(struct bme680_data *data)return ret; } -static int bme680_read_temp (struct bme680_data *data,int *val) +static int bme680_read_temp (struct bme680_data *data,s16 *comp_temp) {int ret;u32 adc_temp; -s16 comp_temp; ret =bme680_read_temp_adc (data, &adc_temp);if (ret)return ret; - comp_temp =bme680_compensate_temp (data, adc_temp); - *val = comp_temp *10 ;/* Centidegrees to millidegrees */ -return IIO_VAL_INT ; + *comp_temp =bme680_compensate_temp (data, adc_temp); +return 0 ; } -static int bme680_read_press (struct bme680_data *data,int *val,int *val2) +static int bme680_read_press (struct bme680_data *data,u32 *comp_press) {int ret;u32 adc_press;
@@ -690,15 +688,14 @@ static int bme680_read_press(struct bme680_data *data, int *val, int *val2)if (ret)return ret; - *val =bme680_compensate_press (data, adc_press, t_fine); - *val2 =1000 ; -return IIO_VAL_FRACTIONAL ; + *comp_press =bme680_compensate_press (data, adc_press, t_fine); +return 0 ; } -static int bme680_read_humid (struct bme680_data *data,int *val,int *val2) +static int bme680_read_humid (struct bme680_data *data,u32 *comp_humidity) {int ret; -u32 adc_humidity, comp_humidity; +u32 adc_humidity;s32 t_fine; ret =bme680_get_t_fine (data, &t_fine);
@@ -709,14 +706,11 @@ static int bme680_read_humid(struct bme680_data *data, int *val, int *val2)if (ret)return ret; - comp_humidity =bme680_compensate_humid (data, adc_humidity, t_fine); - - *val = comp_humidity; - *val2 =1000 ; -return IIO_VAL_FRACTIONAL ; + *comp_humidity =bme680_compensate_humid (data, adc_humidity, t_fine); +return 0 ; } -static int bme680_read_gas (struct bme680_data *data,int *val) +static int bme680_read_gas (struct bme680_data *data,int *comp_gas_res) {struct device *dev =regmap_get_device (data->regmap);int ret;
@@ -751,9 +745,8 @@ static int bme680_read_gas(struct bme680_data *data, int *val) } 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 ; + *comp_gas_res =bme680_compensate_gas (data, adc_gas_res, gas_range); +return 0 ; } static int __bme680_read_raw(struct iio_dev *indio_dev,
@@ -761,7 +754,7 @@ 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; +int chan_val, ret;guard (mutex)(&data->lock);
@@ -777,13 +770,35 @@ static int __bme680_read_raw(struct iio_dev *indio_dev,case IIO_CHAN_INFO_PROCESSED :switch (chan->type) {case IIO_TEMP : -return bme680_read_temp (data, val); + ret =bme680_read_temp (data, (s16 *)&chan_val); +if (ret) +return ret; + + *val = chan_val *10 ; +return IIO_VAL_INT ;case IIO_PRESSURE : -return bme680_read_press (data, val, val2); + ret =bme680_read_press (data, &chan_val); +if (ret) +return ret; + + *val = chan_val; + *val2 =1000 ; +return IIO_VAL_FRACTIONAL ;case IIO_HUMIDITYRELATIVE : -return bme680_read_humid (data, val, val2); + ret =bme680_read_humid (data, &chan_val); +if (ret) +return ret; + + *val = chan_val; + *val2 =1000 ; +return IIO_VAL_FRACTIONAL ;case IIO_RESISTANCE : -return bme680_read_gas (data, val); + ret =bme680_read_gas (data, &chan_val); +if (ret) +return ret; + + *val = chan_val; +return IIO_VAL_INT ;default :return -EINVAL ; }
Signature · 1 line
2.43.0
PATCH 11/13 iio: chemical: bme680: Add SCALE and RAW channels
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Add SCALE,RAW channels to the device. Even though PROCESSED should be kept for backwards compatibility add comment to avoid using it if the value is not actually reported in IIO values.
--- drivers/iio/chemical/bme680_core.c | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/iio/chemical/bme680_core.c +51 -0
@@ -155,17 +155,26 @@ EXPORT_SYMBOL_NS(bme680_regmap_config, IIO_BME680);static const struct iio_chan_spec bme680_channels[] = { { .type =IIO_TEMP , +/* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate =BIT (IIO_CHAN_INFO_PROCESSED ) | +BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ), }, { .type =IIO_PRESSURE , +/* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate =BIT (IIO_CHAN_INFO_PROCESSED ) | +BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ), }, { .type =IIO_HUMIDITYRELATIVE , +/* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate =BIT (IIO_CHAN_INFO_PROCESSED ) | +BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) |BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ), }, {
@@ -802,6 +811,48 @@ static int __bme680_read_raw(struct iio_dev *indio_dev,default :return -EINVAL ; } +case IIO_CHAN_INFO_RAW : +switch (chan->type) { +case IIO_TEMP : + ret =bme680_read_temp (data, (s16 *)&chan_val); +if (ret) +return ret; + + *val = chan_val; +return IIO_VAL_INT ; +case IIO_PRESSURE : + ret =bme680_read_press (data, &chan_val); +if (ret) +return ret; + + *val = chan_val; +return IIO_VAL_INT ; +case IIO_HUMIDITYRELATIVE : + ret =bme680_read_humid (data, &chan_val); +if (ret) +return ret; + + *val = chan_val; +return IIO_VAL_INT ; +default : +return -EINVAL ; + } +case IIO_CHAN_INFO_SCALE : +switch (chan->type) { +case IIO_TEMP : + *val =10 ; +return IIO_VAL_INT ; +case IIO_PRESSURE : + *val =1 ; + *val2 =1000 ; +return IIO_VAL_FRACTIONAL ; +case IIO_HUMIDITYRELATIVE : + *val =1 ; + *val2 =1000 ; +return IIO_VAL_FRACTIONAL ; +default : +return -EINVAL ; + }case IIO_CHAN_INFO_OVERSAMPLING_RATIO :switch (chan->type) {case IIO_TEMP :
Signature · 1 line
2.43.0
PATCH 12/13 iio: chemical: bme680: Add triggered buffer support
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode.
--- drivers/iio/chemical/Kconfig | 2 + drivers/iio/chemical/bme680.h | 2 + drivers/iio/chemical/bme680_core.c | 168 ++++++++++++++++++++++++++++- 3 files changed, 171 insertions(+), 1 deletion(-)
drivers/iio/chemical/Kconfig +2 -0
@@ -50,6 +50,8 @@ config BME680 select REGMAP select BME680_I2C if I2C select BME680_SPI if SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Say yes here to build support for Bosch Sensortec BME680 sensor with temperature, pressure, humidity and gas sensing capability.
drivers/iio/chemical/bme680.h +2 -0
@@ -64,6 +64,8 @@#define BME680_STARTUP_TIME_US 2000 +#define BME680_NUM_CHANNELS 4 +/* Calibration Parameters */ #define BME680_T2_LSB_REG 0x8A#define BME680_H2_MSB_REG 0xE1
drivers/iio/chemical/bme680_core.c +167 -1
230 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v1 12/13] iio: chemical: bme680: Add triggered buffer support
Quoted 6 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode.
...
drivers/iio/chemical/bme680_core.c struct bme680_data { · line 136
Quoted 5 lines
drivers/iio/chemical/bme680_core.c +2
-0struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ];int ambient_temp; +u8 buffer[ALIGN (sizeof (s32) *BME680_NUM_CHANNELS ,sizeof (s64)) + +sizeof (s64)]__aligned(sizeof(s64)) ;
Can it be represented as a structure?
We also have aligned_s64 for the timestamp.
Quoted 6 lines
drivers/iio/chemical/bme680_core.c +1
-1union { -u8 buf[3 ]; +u8 buf[15 ];unsigned int check;__be16 be16;u8 bme680_cal_buf_1[BME680_CALIB_RANGE_1_LEN ];
...
drivers/iio/chemical/bme680_core.c static const struct iio_info bme680_info = { · line 1053
Quoted 8 lines
drivers/iio/chemical/bme680_core.c +7
-0+static irqreturn_t bme680_trigger_handler (int irq,void *p) +{ +struct iio_poll_func *pf = p; +struct iio_dev *indio_dev = pf->indio_dev; +struct bme680_data *data =iio_priv (indio_dev); +u32 adc_temp, adc_press, adc_humid, comp_press, comp_humid; +s32 *chans = (s32 *)data->buffer;
With the structure in place this becomes much more readable.
Quoted 36 lines
drivers/iio/chemical/bme680_core.c +36
-0+u16 adc_gas_res, gas_regs_val; +s32 t_fine, comp_gas_res; +s16 comp_temp; +u8 gas_range; +int ret; + +guard (mutex)(&data->lock); + + ret =bme680_set_mode (data,BME680_FORCED ); +if (ret <0 ) + goto out; + + ret =bme680_wait_for_eoc (data); +if (ret) + goto out; + +/* Burst read data regs */ + ret =regmap_bulk_read (data->regmap,BME680_REG_MEAS_STAT_0 , + data->buf,sizeof (data->buf)); +if (ret) { +dev_err (data->dev,"failed to burst read sensor data\n" ); + goto out; + } +if (data->buf[0 ] &BME680_GAS_MEAS_BIT ) { +dev_err (data->dev,"gas measurement incomplete\n" ); + goto out; + } + +/* Temperature calculations */ + adc_temp =FIELD_GET (BME680_MEAS_TRIM_MASK ,get_unaligned_be24 (&data->buf[5 ])); +if (adc_temp ==BME680_MEAS_SKIPPED ) { +dev_err (data->dev,"reading temperature skipped\n" ); + goto out; + } + comp_temp =bme680_compensate_temp (data, adc_temp); + t_fine =bme680_calc_t_fine (data, adc_temp);
drivers/iio/chemical/bme680_core.c static const struct iio_info bme680_info = { · line 1098
Quoted 10 lines
drivers/iio/chemical/bme680_core.c +9
-0+ +/* Pressure calculations */ + adc_press =FIELD_GET (BME680_MEAS_TRIM_MASK ,get_unaligned_be24 (&data->buf[2 ])); +if (adc_press ==BME680_MEAS_SKIPPED ) { +dev_err (data->dev,"reading pressure skipped\n" ); + goto out; + } + comp_press =bme680_compensate_press (data, adc_press, t_fine); +pr_info ("comp_press: %d\n" , comp_press);
No debugging in the production code. Or if you really need that, it should use dev_dbg().
drivers/iio/chemical/bme680_core.c static const struct iio_info bme680_info = { · line 1107
Quoted 9 lines
drivers/iio/chemical/bme680_core.c +8
-0+/* Humidity calculations */ + adc_humid =get_unaligned_be16 (&data->buf[8 ]); +if (adc_humid ==BME680_MEAS_SKIPPED ) { +dev_err (data->dev,"reading humidity skipped\n" ); + goto out; + } + comp_humid =bme680_compensate_humid (data, adc_humid, t_fine); +pr_info ("comp_humid: %d\n" , comp_humid);
Ditto.
Quoted 24 lines
drivers/iio/chemical/bme680_core.c +24
-0+ +/* Gas calculations */ + gas_regs_val =get_unaligned_be16 (&data->buf[13 ]); + adc_gas_res =FIELD_GET (BME680_ADC_GAS_RES , gas_regs_val); +if ((gas_regs_val &BME680_GAS_STAB_BIT ) ==0 ) { +dev_err (data->dev,"heater failed to reach the target temperature\n" ); + goto out; + } + gas_range =FIELD_GET (BME680_GAS_RANGE_MASK , gas_regs_val); + comp_gas_res =bme680_compensate_gas (data, adc_gas_res, gas_range); +pr_info ("comp_gas_res: %d\n" , comp_gas_res); + + chans[0 ] = comp_temp; + chans[1 ] = comp_press; + chans[2 ] = comp_humid; + chans[3 ] = comp_gas_res; + +/* Push to buffer */ +iio_push_to_buffers_with_timestamp (indio_dev, &data->buffer, +iio_get_time_ns (indio_dev)); +out: +iio_trigger_notify_done (indio_dev->trig); +return IRQ_HANDLED ; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 12/13] iio: chemical: bme680: Add triggered buffer support
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode.
...
Quoted 9 lines
drivers/iio/chemical/bme680_core.c struct bme680_data { · line 136
Quoted 5 lines
drivers/iio/chemical/bme680_core.c +2
-0struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ];int ambient_temp; +u8 buffer[ALIGN (sizeof (s32) *BME680_NUM_CHANNELS ,sizeof (s64)) + +sizeof (s64)]__aligned(sizeof(s64)) ;Can it be represented as a structure?
We also havealigned_s64for the timestamp.
Hi Andy,
The same approach was used also for the bmp280 driver and since I was working on the bmp280 as well, I did it here. You think the representation as a struct would look better? Personally I like the nature of this one because of the ALIGN() but I have no problem of using a struct here.
Quoted 65 lines
Quoted 6 lines
drivers/iio/chemical/bme680_core.c +1
-1union { -u8 buf[3 ]; +u8 buf[15 ];unsigned int check;__be16 be16;u8 bme680_cal_buf_1[BME680_CALIB_RANGE_1_LEN ];...
drivers/iio/chemical/bme680_core.c static const struct iio_info bme680_info = { · line 1053
Quoted 8 lines
drivers/iio/chemical/bme680_core.c +7
-0+static irqreturn_t bme680_trigger_handler (int irq,void *p) +{ +struct iio_poll_func *pf = p; +struct iio_dev *indio_dev = pf->indio_dev; +struct bme680_data *data =iio_priv (indio_dev); +u32 adc_temp, adc_press, adc_humid, comp_press, comp_humid; +s32 *chans = (s32 *)data->buffer;With the structure in place this becomes much more readable.
Quoted 44 lines
drivers/iio/chemical/bme680_core.c +44
-0+u16 adc_gas_res, gas_regs_val; +s32 t_fine, comp_gas_res; +s16 comp_temp; +u8 gas_range; +int ret; + +guard (mutex)(&data->lock); + + ret =bme680_set_mode (data,BME680_FORCED ); +if (ret <0 ) + goto out; + + ret =bme680_wait_for_eoc (data); +if (ret) + goto out; + +/* Burst read data regs */ + ret =regmap_bulk_read (data->regmap,BME680_REG_MEAS_STAT_0 , + data->buf,sizeof (data->buf)); +if (ret) { +dev_err (data->dev,"failed to burst read sensor data\n" ); + goto out; + } +if (data->buf[0 ] &BME680_GAS_MEAS_BIT ) { +dev_err (data->dev,"gas measurement incomplete\n" ); + goto out; + } + +/* Temperature calculations */ + adc_temp =FIELD_GET (BME680_MEAS_TRIM_MASK ,get_unaligned_be24 (&data->buf[5 ])); +if (adc_temp ==BME680_MEAS_SKIPPED ) { +dev_err (data->dev,"reading temperature skipped\n" ); + goto out; + } + comp_temp =bme680_compensate_temp (data, adc_temp); + t_fine =bme680_calc_t_fine (data, adc_temp); + +/* Pressure calculations */ + adc_press =FIELD_GET (BME680_MEAS_TRIM_MASK ,get_unaligned_be24 (&data->buf[2 ])); +if (adc_press ==BME680_MEAS_SKIPPED ) { +dev_err (data->dev,"reading pressure skipped\n" ); + goto out; + } + comp_press =bme680_compensate_press (data, adc_press, t_fine);
Quoted 5 lines
drivers/iio/chemical/bme680_core.c static const struct iio_info bme680_info = { · line 1098
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+pr_info ("comp_press: %d\n" , comp_press);No debugging in the production code. Or if you really need that, it should use
dev_dbg().
ACK. I shouldn't have forgotten those here..
Quoted 8 lines
Quoted 7 lines
drivers/iio/chemical/bme680_core.c +7
-0+/* Humidity calculations */ + adc_humid =get_unaligned_be16 (&data->buf[8 ]); +if (adc_humid ==BME680_MEAS_SKIPPED ) { +dev_err (data->dev,"reading humidity skipped\n" ); + goto out; + } + comp_humid =bme680_compensate_humid (data, adc_humid, t_fine);
Quoted 4 lines
drivers/iio/chemical/bme680_core.c static const struct iio_info bme680_info = { · line 1107
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+pr_info ("comp_humid: %d\n" , comp_humid);Ditto.
ACK.
Quoted 16 lines
Quoted 16 lines
drivers/iio/chemical/bme680_core.c +16
-0+ +/* Gas calculations */ + gas_regs_val =get_unaligned_be16 (&data->buf[13 ]); + adc_gas_res =FIELD_GET (BME680_ADC_GAS_RES , gas_regs_val); +if ((gas_regs_val &BME680_GAS_STAB_BIT ) ==0 ) { +dev_err (data->dev,"heater failed to reach the target temperature\n" ); + goto out; + } + gas_range =FIELD_GET (BME680_GAS_RANGE_MASK , gas_regs_val); + comp_gas_res =bme680_compensate_gas (data, adc_gas_res, gas_range); +pr_info ("comp_gas_res: %d\n" , comp_gas_res); + + chans[0 ] = comp_temp; + chans[1 ] = comp_press; + chans[2 ] = comp_humid; + chans[3 ] = comp_gas_res;
Quoted 14 lines
Quoted 8 lines
drivers/iio/chemical/bme680_core.c +8
-0+ +/* Push to buffer */ +iio_push_to_buffers_with_timestamp (indio_dev, &data->buffer, +iio_get_time_ns (indio_dev)); +out: +iio_trigger_notify_done (indio_dev->trig); +return IRQ_HANDLED ; +}Signature · 2 lines
With Best Regards, Andy Shevchenko
Cheers,
Vasilis
Jonathan Cameron
maintainerRe: [PATCH v1 12/13] iio: chemical: bme680: Add triggered buffer support
Quoted 21 lines · On Fri, 11 Oct 2024 21:07:20 +0200 Vasileios Aoiridis <[email protected]>…
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode.
...
Quoted 9 lines
drivers/iio/chemical/bme680_core.c struct bme680_data { · line 136
Quoted 5 lines
drivers/iio/chemical/bme680_core.c +2
-0struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ];int ambient_temp; +u8 buffer[ALIGN (sizeof (s32) *BME680_NUM_CHANNELS ,sizeof (s64)) + +sizeof (s64)]__aligned(sizeof(s64)) ;Can it be represented as a structure?
We also havealigned_s64for the timestamp.
Quoted 7 lines
Hi Andy,
The same approach was used also for the bmp280 driver and since I was working on the bmp280 as well, I did it here. You think the representation as a struct would look better? Personally I like the nature of this one because of the
ALIGN()but I have no problem of using a struct here.
Depends if you can enable sufficiently few channels that the timestamp moves. If that is the case, a structure is missleading as a representation of this buffer so I prefer the above fun as it doesn't give the wrong impression (by giving no impression at all of the data layout!)
Jonathan
Jonathan Cameron
maintainerRe: [PATCH v1 12/13] iio: chemical: bme680: Add triggered buffer support
Quoted 32 lines · On Sat, 12 Oct 2024 13:04:02 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 21 lines · On Fri, 11 Oct 2024 21:07:20 +0200 Vasileios Aoiridis <[email protected]>…
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode.
...
Quoted 9 lines
drivers/iio/chemical/bme680_core.c struct bme680_data { · line 136
Quoted 5 lines
drivers/iio/chemical/bme680_core.c +2
-0struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES ];int ambient_temp; +u8 buffer[ALIGN (sizeof (s32) *BME680_NUM_CHANNELS ,sizeof (s64)) + +sizeof (s64)]__aligned(sizeof(s64)) ;Can it be represented as a structure?
We also havealigned_s64for the timestamp.Quoted 7 lines
Hi Andy,
The same approach was used also for the bmp280 driver and since I was working on the bmp280 as well, I did it here. You think the representation as a struct would look better? Personally I like the nature of this one because of the
ALIGN()but I have no problem of using a struct here.
Quoted 4 lines
Depends if you can enable sufficiently few channels that the timestamp moves. If that is the case, a structure is missleading as a representation of this buffer so I prefer the above fun as it doesn't give the wrong impression (by giving no impression at all of the data layout!)
Looks like you always write them all to the buffer. So structure indeed appropriate here. (I should have read the code before commenting!)
J
Quoted 2 lines
Jonathan
PATCH 13/13 iio: chemical: bme680: Add support for preheat current
In reply to vamoiridFrom: Vasileios Amoiridis <[email protected]>
Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature.
--- drivers/iio/chemical/bme680.h | 1 + drivers/iio/chemical/bme680_core.c | 38 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/iio/chemical/bme680.h +1 -0
@@ -42,6 +42,7 @@#define BME680_RHRANGE_MASK GENMASK(5, 4)#define BME680_REG_RES_HEAT_VAL 0x00#define BME680_RSERROR_MASK GENMASK(7, 4) +#define BME680_REG_IDAC_HEAT_0 0x50#define BME680_REG_RES_HEAT_0 0x5A#define BME680_REG_GAS_WAIT_0 0x64#define BME680_ADC_GAS_RES GENMASK(15, 6)
drivers/iio/chemical/bme680_core.c +38 -0
@@ -126,6 +126,7 @@ struct bme680_data {u8 oversampling_temp;u8 oversampling_press;u8 oversampling_humid; +u8 preheat_curr;u16 heater_dur;u16 heater_temp;
@@ -223,6 +224,12 @@ static const struct iio_chan_spec bme680_channels[] = { }, }, IIO_CHAN_SOFT_TIMESTAMP(4), + { + .type = IIO_CURRENT, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .output = 1, + .scan_index = 5, + }, }; static int bme680_read_calib(struct bme680_data *data,
@@ -569,6 +576,12 @@ static u8 bme680_calc_heater_dur(u16 dur)return durval; } +/* Taken from datasheet, section 5.3.3 */ +static u8 bme680_calc_heater_preheat_current (u8 curr) +{ +return 8 * curr -1 ; +} +static int bme680_set_mode (struct bme680_data *data,enum bme680_op_mode mode) {struct device *dev =regmap_get_device (data->regmap);
@@ -673,6 +686,19 @@ static int bme680_chip_config(struct bme680_data *data)return 0 ; } +static int bme680_preheat_curr_config (struct bme680_data *data,u8 val) +{ +u8 heatr_curr; +int ret; + + heatr_curr =bme680_calc_heater_preheat_current (val); + ret =regmap_write (data->regmap,BME680_REG_IDAC_HEAT_0 , heatr_curr); +if (ret <0 ) +dev_err (data->dev,"failed to write idac_heat_0 register\n" ); + +return ret; +} +static int bme680_gas_config (struct bme680_data *data) {struct device *dev =regmap_get_device (data->regmap);
@@ -701,6 +727,10 @@ static int bme680_gas_config(struct bme680_data *data)return ret; } + ret =bme680_preheat_curr_config (data, data->preheat_curr); +if (ret) +return ret; +/* Enable the gas sensor and select heater profile set-point 0 */ ret = regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1, BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK,
@@ -967,6 +997,13 @@ static int __bme680_write_raw(struct iio_dev *indio_dev,return bme680_chip_config (data); } +case IIO_CHAN_INFO_RAW : + { +if (chan->type !=IIO_CURRENT ) +return -EINVAL ; + +return bme680_preheat_curr_config (data, (u8 )val); + }default :return -EINVAL ; }
@@ -1199,6 +1236,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->oversampling_temp =8 ;/* 8X oversampling rate */ data->heater_temp =320 ;/* degree Celsius */ data->heater_dur =150 ;/* milliseconds */ + data->preheat_curr =0 ;/* milliamps */ regulator_bulk_set_supply_names (data->supplies, bme680_supply_names,BME680_NUM_SUPPLIES );
Signature · 1 line
2.43.0
Re: [PATCH v1 13/13] iio: chemical: bme680: Add support for preheat current
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature.
...
drivers/iio/chemical/bme680_core.c int bme680_core_probe(struct device *dev, struct regmap *regmap, · line 1239
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+ data->preheat_curr =0 ;/* milliamps */
Instead of the comment, make it better to any appearance of the variable in the code by adding unit suffix.
data->preheat_curr_mA = 0;
(yes, capital 'A').
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 13/13] iio: chemical: bme680: Add support for preheat current
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · vamoirid
From: Vasileios Amoiridis <[email protected]>
Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature.
...
Quoted 9 lines
drivers/iio/chemical/bme680_core.c int bme680_core_probe(struct device *dev, struct regmap *regmap, · line 1239
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+ data->preheat_curr =0 ;/* milliamps */ Instead of the comment, make it better to any appearance of the variable in the code by adding unit suffix.
data->preheat_curr_mA = 0;(yes, capital 'A').
Hi Andy,
I used the comment here because it is exactly like this above and I though it is more consistent if I do the same. But I guess repeating a not so good design choice for consistency might not be the best decision.
Cheers,
Vasilis
Quoted 5 lines
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 13/13] iio: chemical: bme680: Add support for preheat current
Fri, Oct 11, 2024 at 09:08:51PM +0200, Vasileios Aoiridis kirjoitti:
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · vamoirid
...
Quoted 5 lines
Quoted 5 lines
drivers/iio/chemical/bme680_core.c int bme680_core_probe(struct device *dev, struct regmap *regmap, · line 1239
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+ data->preheat_curr =0 ;/* milliamps */ Instead of the comment, make it better to any appearance of the variable in the code by adding unit suffix.
Quoted 8 lines
Quoted 3 lines
data->preheat_curr_mA = 0;(yes, capital 'A').
I used the comment here because it is exactly like this above and I though it is more consistent if I do the same. But I guess repeating a not so good design choice for consistency might not be the best decision.
Right. I would rather see an additional patch that adds unit suffixes here and there...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v1 13/13] iio: chemical: bme680: Add support for preheat current
In reply to vamoiridQuoted 37 lines · On Thu, 10 Oct 2024 23:00:30 +0200 vamoirid <[email protected]> wrote:
From: Vasileios Amoiridis <[email protected]>
Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature.
Signed-off-by Vasileios Amoiridis <[email protected]>--- drivers/iio/chemical/bme680.h | 1 + drivers/iio/chemical/bme680_core.c | 38 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)drivers/iio/chemical/bme680.h +1
-0@@ -42,6 +42,7 @@#define BME680_RHRANGE_MASK GENMASK(5, 4)#define BME680_REG_RES_HEAT_VAL 0x00#define BME680_RSERROR_MASK GENMASK(7, 4) +#define BME680_REG_IDAC_HEAT_0 0x50#define BME680_REG_RES_HEAT_0 0x5A#define BME680_REG_GAS_WAIT_0 0x64#define BME680_ADC_GAS_RES GENMASK(15, 6)drivers/iio/chemical/bme680_core.c +1
-0@@ -126,6 +126,7 @@ struct bme680_data {u8 oversampling_temp;u8 oversampling_press;u8 oversampling_humid; +u8 preheat_curr;u16 heater_dur;u16 heater_temp;
drivers/iio/chemical/bme680_core.c static const struct iio_chan_spec bme680_channels[] = { · line 231
Quoted 8 lines
drivers/iio/chemical/bme680_core.c +5
-0@@ -223,6 +224,12 @@ static const struct iio_chan_spec bme680_channels[] = { }, }, IIO_CHAN_SOFT_TIMESTAMP(4), + { + .type = IIO_CURRENT, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .output = 1, + .scan_index = 5,
Set scan index to -1
you don't want to create the buffer related attrs for this one
Quoted 1 line
drivers/iio/chemical/bme680_core.c +1
-0+ },
Quoted 12 lines · vamoirid
This patch series is continuing the work that started on [1] by improving some small issues of the driver in the commits 1,2,3.
Commits 4,5 are refactorizing existing code.
Commits 6,7,8 are adding DT, regulator and PM support.
Commit 9 is refactorizing one macro to attribute.
Commit 10,11,12 are refactorizing the read/compensate functions to become generic and add triggered buffer support.
Quoted 8 lines
Finally, commit 13 adds support for an *output* channel of type
IIO_CURRENTin order to preheat the plate that is used to measure the quality of the air.This and the previous series [1] started with the idea to add support for the new bme688 device but due to the structure of the driver I decided that it is better to restructure and improve some things before adding extra funcitonalities.
Besides the small comments here and there I think you need to rearrange the patches layout in the series.
In general it should go in these blocks:
1) bug fixes (if any);
2) cleanups (note, whitespace-cleanup-like are the last);
3) new feature.
Note that PM runtime belongs to the last group quite close to the patches where you more or less start using it more.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 25 lines · Andy Shevchenko
Quoted 12 lines · vamoirid
This patch series is continuing the work that started on [1] by improving some small issues of the driver in the commits 1,2,3.
Commits 4,5 are refactorizing existing code.
Commits 6,7,8 are adding DT, regulator and PM support.
Commit 9 is refactorizing one macro to attribute.
Commit 10,11,12 are refactorizing the read/compensate functions to become generic and add triggered buffer support.
Quoted 8 lines
Finally, commit 13 adds support for an *output* channel of type
IIO_CURRENTin order to preheat the plate that is used to measure the quality of the air.This and the previous series [1] started with the idea to add support for the new bme688 device but due to the structure of the driver I decided that it is better to restructure and improve some things before adding extra funcitonalities.
Besides the small comments here and there I think you need to rearrange the patches layout in the series.
Quoted 13 lines
In general it should go in these blocks:
1) bug fixes (if any);
2) cleanups (note, whitespace-cleanup-like are the last);
3) new feature.Note that PM runtime belongs to the last group quite close to the patches where you more or less start using it more.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hello Andy,
Thank you very much for taking the time to review this, I appreciate it a lot. I was not sure about the order of the patches but what you explained here makes total sense. I will rework the order and address the rest of the comments.
Cheers,
Vasilis