Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Vasileios Amoiridis <vassilisamir@gmail.com>
Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com,
	ang.iglesiasg@gmail.com, mazziesaccount@gmail.com,
	ak@it-klinger.de, petre.rodan@subdimension.ro,
	linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/6] iio: pressure: Simplify read_* functions
Date: Thu, 14 Mar 2024 14:38:13 +0000	[thread overview]
Message-ID: <20240314143813.69087bf3@jic23-huawei> (raw)
In-Reply-To: <20240313174007.1934983-3-vassilisamir@gmail.com>

On Wed, 13 Mar 2024 18:40:03 +0100
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:

> Add the coefficients for the IIO standard units inside the chip_info
> structure.
> 
> Remove the calculations with the coefficients for the IIO compatibility
> from inside the read_(temp/press/humid) functions and move it to the
> read_raw function.
> 
> Execute the calculations with the coefficients inside the read_raw
> oneshot capture functions.
> 
> Also fix raw_* and comp_* values signs.

That needs some more explanation.  Is this a fix that needs backporting?

> 
> Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
> ---
>  drivers/iio/pressure/bmp280-core.c | 150 +++++++++++++----------------
>  drivers/iio/pressure/bmp280.h      |  10 +-
>  2 files changed, 74 insertions(+), 86 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 871b2214121b..dfd845acfa22 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -363,8 +363,7 @@ static u32 bmp280_compensate_press(struct bmp280_data *data,
>  	return (u32)p;
>  }
>  
> -static int bmp280_read_temp(struct bmp280_data *data,
> -			    int *val, int *val2)
> +static s32 bmp280_read_temp(struct bmp280_data *data)

It's returning error codes through here. If you need to force a specific type,
don't use the return code.  Pass in a variable to put it in.

static int bm280_read_temp(struct bmp280_data *data, u32 *result)


>  {
>  	s32 adc_temp, comp_temp;
>  	int ret;
> @@ -384,27 +383,17 @@ static int bmp280_read_temp(struct bmp280_data *data,
>  	}
>  	comp_temp = bmp280_compensate_temp(data, adc_temp);
>  
> -	/*
> -	 * val might be NULL if we're called by the read_press routine,
> -	 * who only cares about the carry over t_fine value.
> -	 */
> -	if (val) {
> -		*val = comp_temp * 10;
> -		return IIO_VAL_INT;
> -	}
> -
> -	return 0;
> +	return comp_temp;
>  }
>  
> -static int bmp280_read_press(struct bmp280_data *data,
> -			     int *val, int *val2)
> +static u32 bmp280_read_press(struct bmp280_data *data)
>  {
>  	u32 comp_press;
>  	s32 adc_press;
>  	int ret;
>  
>  	/* Read and compensate temperature so we get a reading of t_fine. */
> -	ret = bmp280_read_temp(data, NULL, NULL);
> +	ret = bmp280_read_temp(data);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -423,20 +412,17 @@ static int bmp280_read_press(struct bmp280_data *data,
>  	}
>  	comp_press = bmp280_compensate_press(data, adc_press);
>  
> -	*val = comp_press;
> -	*val2 = 256000;
> -
> -	return IIO_VAL_FRACTIONAL;
> +	return comp_press;
>  }
>  
> -static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
> +static u32 bmp280_read_humid(struct bmp280_data *data)
>  {
>  	u32 comp_humidity;
>  	s32 adc_humidity;
>  	int ret;
>  
>  	/* Read and compensate temperature so we get a reading of t_fine. */
> -	ret = bmp280_read_temp(data, NULL, NULL);
> +	ret = bmp280_read_temp(data);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -455,9 +441,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
>  	}
>  	comp_humidity = bmp280_compensate_humidity(data, adc_humidity);
>  
> -	*val = comp_humidity * 1000 / 1024;
> -
> -	return IIO_VAL_INT;
> +	return comp_humidity;
>  }
>  
>  static int bmp280_read_raw(struct iio_dev *indio_dev,
> @@ -474,13 +458,27 @@ static int bmp280_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_PROCESSED:
>  		switch (chan->type) {
>  		case IIO_HUMIDITYRELATIVE:
> -			ret = data->chip_info->read_humid(data, val, val2);
> +			ret = data->chip_info->read_humid(data);

You can still get an error code back from this and you must handle it.
Previously it was fine because both errors and IIO_VAL_ were returned by
the callback so error returns were handled, now they aren't.

> +			*val = data->chip_info->humid_coeffs[0] * ret;
> +			*val2 = data->chip_info->humid_coeffs[1];
> +			ret = IIO_VAL_FRACTIONAL;
>  			break;
Same applies in all the other cases.

Jonathan


  parent reply	other threads:[~2024-03-14 14:38 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 17:40 [PATCH v2 0/6] Series to add triggered buffer support to BMP280 driver Vasileios Amoiridis
2024-03-13 17:40 ` [PATCH v2 1/6] iio: pressure: BMP280 core driver headers sorting Vasileios Amoiridis
2024-03-13 17:40 ` [PATCH v2 2/6] iio: pressure: Simplify read_* functions Vasileios Amoiridis
2024-03-13 19:01   ` Andy Shevchenko
2024-03-13 19:22     ` Vasileios Amoiridis
2024-03-13 19:28       ` Andy Shevchenko
2024-03-14 14:32         ` Jonathan Cameron
2024-03-14 19:52           ` Vasileios Amoiridis
2024-03-14 14:38   ` Jonathan Cameron [this message]
2024-03-13 17:40 ` [PATCH v3 3/6] iio: pressure: add SCALE and RAW values for channels Vasileios Amoiridis
2024-03-13 19:03   ` Andy Shevchenko
2024-03-13 19:51     ` Vasileios Amoiridis
2024-03-13 20:04       ` Andy Shevchenko
2024-03-13 21:28         ` Vasileios Amoiridis
2024-03-14 10:57           ` vamoirid
2024-03-14 14:46             ` Jonathan Cameron
2024-03-14 20:06               ` Vasileios Amoiridis
2024-03-15 13:11               ` Vasileios Amoiridis
2024-03-16 13:51                 ` Jonathan Cameron
2024-03-14 14:48   ` Jonathan Cameron
2024-03-13 17:40 ` [PATCH v2 4/6] iio: pressure: Simplify and make more clear temperature readings Vasileios Amoiridis
2024-03-13 19:04   ` Andy Shevchenko
2024-03-14 14:51     ` Jonathan Cameron
2024-03-14 15:09   ` Jonathan Cameron
2024-03-14 20:17     ` Vasileios Amoiridis
2024-03-14 23:22       ` Angel Iglesias
2024-03-15  9:05         ` Vasileios Amoiridis
2024-03-15 13:28           ` Angel Iglesias
2024-03-16 14:00             ` Jonathan Cameron
2024-03-13 17:40 ` [PATCH v2 5/6] iio: pressure: Add timestamp and scan_masks for BMP280 driver Vasileios Amoiridis
2024-03-13 18:54   ` Andy Shevchenko
2024-03-13 19:55     ` Vasileios Amoiridis
2024-03-13 17:40 ` [PATCH v2 6/6] iio: pressure: Add triggered buffer support " Vasileios Amoiridis
2024-03-13 18:58   ` Andy Shevchenko
2024-03-13 20:00     ` Vasileios Amoiridis
2024-03-14 15:25   ` Jonathan Cameron
2024-03-14 20:14     ` Vasileios Amoiridis
2024-03-16 14:03       ` 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=20240314143813.69087bf3@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=579lpy@gmail.com \
    --cc=ak@it-klinger.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ang.iglesiasg@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=petre.rodan@subdimension.ro \
    --cc=phil@raspberrypi.com \
    --cc=vassilisamir@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox