All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasileios Amoiridis <vassilisamir@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Vasileios Amoiridis <vassilisamir@gmail.com>,
	lars@metafoo.de, himanshujha199640@gmail.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 10/17] iio: chemical: bme680: Remove duplicate register read
Date: Sun, 2 Jun 2024 21:25:59 +0200	[thread overview]
Message-ID: <20240602192559.GC387181@vamoiridPC> (raw)
In-Reply-To: <20240602135036.27b0ee9a@jic23-huawei>

On Sun, Jun 02, 2024 at 01:50:36PM +0100, Jonathan Cameron wrote:
> On Mon, 27 May 2024 20:37:58 +0200
> Vasileios Amoiridis <vassilisamir@gmail.com> wrote:
> 
> > The LSB of the gas register was read first to check if the following
> > check was correct and then the MSB+LSB were read together. Simplify
> > this by reading together the MSB+LSB immediately.
> > 
> > Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
> A few trivial things. I wrote a nice comment on dma safe buffers then
> noticed this does a custom regmap using spi_write_then_read() so despite
> not looking like it from this code, DMA safe buffers are used.
> Just thought I'd mention it for any other reviewers!
> 
> > ---
> >  drivers/iio/chemical/bme680_core.c | 21 ++++++++-------------
> >  1 file changed, 8 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
> > index 96423861c79a..681f271f9b06 100644
> > --- a/drivers/iio/chemical/bme680_core.c
> > +++ b/drivers/iio/chemical/bme680_core.c
> > @@ -748,7 +748,7 @@ static int bme680_read_gas(struct bme680_data *data,
> >  	int ret;
> >  	__be16 tmp = 0;
> >  	unsigned int check;
> > -	u16 adc_gas_res;
> > +	u16 adc_gas_res, gas_regs_val;
> >  	u8 gas_range;
> >  
> >  	/* Set heater settings */
> > @@ -771,11 +771,14 @@ static int bme680_read_gas(struct bme680_data *data,
> >  		return -EBUSY;
> >  	}
> >  
> > -	ret = regmap_read(data->regmap, BME680_REG_GAS_R_LSB, &check);
> > +	ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
> > +			       &tmp, sizeof(tmp)); 
> >  	if (ret < 0) {
> > -		dev_err(dev, "failed to read gas_r_lsb register\n");
> > +		dev_err(dev, "failed to read gas resistance\n");
> >  		return ret;
> >  	}
> > +	gas_regs_val = be16_to_cpu(tmp);
> > +	adc_gas_res = gas_regs_val >> BME680_ADC_GAS_RES_SHIFT;
> I'd rather see this as a FIELD_GET() but given this was what was originally
> here I guess I can cope with keeping it a little longer!
> 

Well, it's not a big deal, I could put it in a FIELD_GET().

> >  
> >  	/*
> >  	 * occurs if either the gas heating duration was insuffient
> > @@ -783,20 +786,12 @@ static int bme680_read_gas(struct bme680_data *data,
> >  	 * heater temperature was too high for the heater sink to
> >  	 * reach.
> >  	 */
> > -	if ((check & BME680_GAS_STAB_BIT) == 0) {
> > +	if ((gas_regs_val & BME680_GAS_STAB_BIT) == 0) {
> >  		dev_err(dev, "heater failed to reach the target temperature\n");
> >  		return -EINVAL;
> >  	}
> >  
> > -	ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
> > -			       &tmp, sizeof(tmp));
> > -	if (ret < 0) {
> > -		dev_err(dev, "failed to read gas resistance\n");
> > -		return ret;
> > -	}
> > -
> > -	gas_range = check & BME680_GAS_RANGE_MASK;
> > -	adc_gas_res = be16_to_cpu(tmp) >> BME680_ADC_GAS_RES_SHIFT;
> > +	gas_range = gas_regs_val & BME680_GAS_RANGE_MASK;
> 
> Whilst you are here, may this a FIELD_GET() so we don't have to go
> check that it includes the LSB.
> 

I could do it here as well.

Cheers,
Vasilis
> >  
> >  	*val = bme680_compensate_gas(data, adc_gas_res, gas_range);
> >  	return IIO_VAL_INT;
> 

  reply	other threads:[~2024-06-02 19:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 18:37 [PATCH v1 00/17] iio: chemical: bme680: Driver cleanup Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 01/17] iio: chemical: bme680: Fix pressure value output Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 02/17] iio: chemical: bme680: Fix calibration data variable Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 03/17] iio: chemical: bme680: Fix overflows in compensate() functions Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 04/17] iio: chemical: bme680: Fix sensor data read operation Vasileios Amoiridis
2024-06-02 12:41   ` Jonathan Cameron
2024-06-02 19:00     ` Vasileios Amoiridis
2024-06-03 19:23       ` Jonathan Cameron
2024-06-03 20:31         ` Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 05/17] iio: chemical: bme680: Fix type in define Vasileios Amoiridis
2024-06-02 12:41   ` Jonathan Cameron
2024-06-02 19:17     ` Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 06/17] iio: chemical: bme680: Add mutexes to guard read/write to device Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 07/17] iio: chemical: bme680: Drop unnecessary casts and correct adc data types Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 08/17] iio: chemical: bme680: Remove remaining ACPI-only stuff Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 09/17] iio: chemical: bme680: Sort headers alphabetically Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 10/17] iio: chemical: bme680: Remove duplicate register read Vasileios Amoiridis
2024-06-02 12:50   ` Jonathan Cameron
2024-06-02 19:25     ` Vasileios Amoiridis [this message]
2024-05-27 18:37 ` [PATCH v1 11/17] iio: chemical: bme680: Use bulk reads for calibration data Vasileios Amoiridis
2024-06-02 12:57   ` Jonathan Cameron
2024-06-02 19:30     ` Vasileios Amoiridis
2024-06-03 19:25       ` Jonathan Cameron
2024-06-03 20:30         ` Vasileios Amoiridis
2024-06-06 19:36           ` Jonathan Cameron
2024-05-27 18:38 ` [PATCH v1 12/17] iio: chemical: bme680: Allocate IIO device before chip initialization Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 13/17] iio: chemical: bme680: Add read buffers in DMA safe region Vasileios Amoiridis
2024-06-02 12:59   ` Jonathan Cameron
2024-06-02 19:33     ` Vasileios Amoiridis
2024-06-03 19:27       ` Jonathan Cameron
2024-05-27 18:38 ` [PATCH v1 14/17] iio: chemical: bme680: Modify startup procedure Vasileios Amoiridis
2024-06-02 13:01   ` Jonathan Cameron
2024-06-02 19:40     ` Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 15/17] iio: chemical: bme680: Remove redundant gas configuration Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 16/17] iio: chemical: bme680: Move forced mode setup in ->read_raw() Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 17/17] iio: chemical: bme680: Refactorize reading functions Vasileios Amoiridis
2024-06-02 13:04   ` Jonathan Cameron
2024-06-02 19:53     ` Vasileios Amoiridis
2024-06-02 12:31 ` [PATCH v1 00/17] iio: chemical: bme680: Driver cleanup Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240602192559.GC387181@vamoiridPC \
    --to=vassilisamir@gmail.com \
    --cc=himanshujha199640@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.