diff mbox series

[v3,3/7] iio: pressure: bmp280: Remove config error check for IIR filter updates

Message ID 20240823181714.64545-4-vassilisamir@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series pressure: bmp280: Minor cleanup and interrupt support | expand

Commit Message

Vasileios Amoiridis Aug. 23, 2024, 6:17 p.m. UTC
When there is a change in the configuration of the BMP3xx device, several
steps take place. These steps include:

1) Update the OSR settings and check if there was an update
2) Update the ODR settings and check if there was an update
3) Update the IIR settings and check if there was an update
4) Check if there was an update with the following procedure:
	a) Set sensor to SLEEP mode and after to NORMAL mode to trigger
	   a new measurement.
	b) Wait the maximum amount possible depending on the OSR settings
	c) Check the configuration error register if there was an error
	   during the configuration of the sensor.

This check is necessary, because there could be a case where the OSR is
too high for the requested ODR so either the ODR needs to be slower or the
OSR needs to be less. This is something that is checked internally by the
sensor when it runs in NORMAL mode.

In the BMP58x devices the previous steps are done internally by the sensor.

The IIR filter settings do not depend on the OSR or ODR settings, and there
is no need to run a check in case they change.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
---
 drivers/iio/pressure/bmp280-core.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

Comments

Andy Shevchenko Aug. 23, 2024, 7:15 p.m. UTC | #1
On Fri, Aug 23, 2024 at 08:17:10PM +0200, Vasileios Amoiridis wrote:
> When there is a change in the configuration of the BMP3xx device, several
> steps take place. These steps include:
> 
> 1) Update the OSR settings and check if there was an update
> 2) Update the ODR settings and check if there was an update
> 3) Update the IIR settings and check if there was an update
> 4) Check if there was an update with the following procedure:
> 	a) Set sensor to SLEEP mode and after to NORMAL mode to trigger
> 	   a new measurement.
> 	b) Wait the maximum amount possible depending on the OSR settings
> 	c) Check the configuration error register if there was an error
> 	   during the configuration of the sensor.
> 
> This check is necessary, because there could be a case where the OSR is
> too high for the requested ODR so either the ODR needs to be slower or the
> OSR needs to be less. This is something that is checked internally by the
> sensor when it runs in NORMAL mode.
> 
> In the BMP58x devices the previous steps are done internally by the sensor.
> 
> The IIR filter settings do not depend on the OSR or ODR settings, and there
> is no need to run a check in case they change.

...

> +	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
> +				 BMP580_DSP_IIR_PRESS_MASK |
> +				 BMP580_DSP_IIR_TEMP_MASK, reg_val);

Better to split on logical bounds

	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
				 BMP580_DSP_IIR_PRESS_MASK | BMP580_DSP_IIR_TEMP_MASK,
				 reg_val);
Vasileios Amoiridis Aug. 24, 2024, 11:18 a.m. UTC | #2
On Fri, Aug 23, 2024 at 10:15:29PM +0300, Andy Shevchenko wrote:
> On Fri, Aug 23, 2024 at 08:17:10PM +0200, Vasileios Amoiridis wrote:
> > When there is a change in the configuration of the BMP3xx device, several
> > steps take place. These steps include:
> > 
> > 1) Update the OSR settings and check if there was an update
> > 2) Update the ODR settings and check if there was an update
> > 3) Update the IIR settings and check if there was an update
> > 4) Check if there was an update with the following procedure:
> > 	a) Set sensor to SLEEP mode and after to NORMAL mode to trigger
> > 	   a new measurement.
> > 	b) Wait the maximum amount possible depending on the OSR settings
> > 	c) Check the configuration error register if there was an error
> > 	   during the configuration of the sensor.
> > 
> > This check is necessary, because there could be a case where the OSR is
> > too high for the requested ODR so either the ODR needs to be slower or the
> > OSR needs to be less. This is something that is checked internally by the
> > sensor when it runs in NORMAL mode.
> > 
> > In the BMP58x devices the previous steps are done internally by the sensor.
> > 
> > The IIR filter settings do not depend on the OSR or ODR settings, and there
> > is no need to run a check in case they change.
> 
> ...
> 
> > +	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
> > +				 BMP580_DSP_IIR_PRESS_MASK |
> > +				 BMP580_DSP_IIR_TEMP_MASK, reg_val);
> 
> Better to split on logical bounds
> 
> 	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
> 				 BMP580_DSP_IIR_PRESS_MASK | BMP580_DSP_IIR_TEMP_MASK,
> 				 reg_val);
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 


This goes beyond the 80 char limit. I know that there is the relaxed
limit of 100 chars but I didn't feel it was more readable like this.
I could definitely use it though, thanks!

Cheers,
Vasilis
Andy Shevchenko Aug. 26, 2024, 10:12 a.m. UTC | #3
On Sat, Aug 24, 2024 at 01:18:06PM +0200, Vasileios Amoiridis wrote:
> On Fri, Aug 23, 2024 at 10:15:29PM +0300, Andy Shevchenko wrote:
> > On Fri, Aug 23, 2024 at 08:17:10PM +0200, Vasileios Amoiridis wrote:

...

> > > +	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
> > > +				 BMP580_DSP_IIR_PRESS_MASK |
> > > +				 BMP580_DSP_IIR_TEMP_MASK, reg_val);
> > 
> > Better to split on logical bounds
> > 
> > 	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
> > 				 BMP580_DSP_IIR_PRESS_MASK | BMP580_DSP_IIR_TEMP_MASK,
> > 				 reg_val);
> 
> This goes beyond the 80 char limit. I know that there is the relaxed
> limit of 100 chars but I didn't feel it was more readable like this.
> I could definitely use it though, thanks!

The readability has a priority over that limit. That's even mentioned in
the documentation besides the relaxed limit.
diff mbox series

Patch

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index e01c9369bd67..736a1f4fd5dc 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -1557,14 +1557,12 @@  static int bmp380_chip_config(struct bmp280_data *data)
 	change = change || aux;
 
 	/* Set filter data */
-	ret = regmap_update_bits_check(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK,
-				       FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff),
-				       &aux);
+	ret = regmap_update_bits(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK,
+				 FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff));
 	if (ret) {
 		dev_err(data->dev, "failed to write config register\n");
 		return ret;
 	}
-	change = change || aux;
 
 	if (change) {
 		/*
@@ -2154,15 +2152,13 @@  static int bmp580_chip_config(struct bmp280_data *data)
 	reg_val = FIELD_PREP(BMP580_DSP_IIR_PRESS_MASK, data->iir_filter_coeff) |
 		  FIELD_PREP(BMP580_DSP_IIR_TEMP_MASK, data->iir_filter_coeff);
 
-	ret = regmap_update_bits_check(data->regmap, BMP580_REG_DSP_IIR,
-				       BMP580_DSP_IIR_PRESS_MASK |
-				       BMP580_DSP_IIR_TEMP_MASK,
-				       reg_val, &aux);
+	ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR,
+				 BMP580_DSP_IIR_PRESS_MASK |
+				 BMP580_DSP_IIR_TEMP_MASK, reg_val);
 	if (ret) {
 		dev_err(data->dev, "failed to write config register\n");
 		return ret;
 	}
-	change = change || aux;
 
 	/* Restore sensor to normal operation mode */
 	ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG,