public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Angel Iglesias <ang.iglesiasg@gmail.com>
Cc: linux-iio <linux-iio@vger.kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Paul Cercueil <paul@crapouillou.net>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 3/9] iio: pressure: bmp280: Simplify bmp280 calibration data reading
Date: Thu, 15 Sep 2022 15:57:41 +0100	[thread overview]
Message-ID: <20220915155741.2c19e927@jic23-huawei> (raw)
In-Reply-To: <96d81282c95006d857f4d836d2ff3ee0740a85a0.1663025017.git.ang.iglesiasg@gmail.com>

On Tue, 13 Sep 2022 01:46:42 +0200
Angel Iglesias <ang.iglesiasg@gmail.com> wrote:

> On bmp280 and bme280, the temperature and pressure calibration parameters
> are available on a contiguous memory region. Considering this arrangement,
> simplified the calibration reading function by using only one buffer
> to read in batch temperature and pressure registers.
> 
> Signed-off-by: Angel Iglesias <ang.iglesiasg@gmail.com>
Applied.  Apparently we have a plane, so I'll stop here for now...

Jonathan

> ---
>  drivers/iio/pressure/bmp280-core.c | 58 ++++++++++++------------------
>  drivers/iio/pressure/bmp280.h      |  3 ++
>  2 files changed, 26 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 0ba4ff999f33..4793bcd9f0b3 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -128,8 +128,7 @@ struct bmp280_chip_info {
>   * These enums are used for indexing into the array of compensation
>   * parameters for BMP280.
>   */
> -enum { T1, T2, T3 };
> -enum { P1, P2, P3, P4, P5, P6, P7, P8, P9 };
> +enum { T1, T2, T3, P1, P2, P3, P4, P5, P6, P7, P8, P9 };
>  
>  static const struct iio_chan_spec bmp280_channels[] = {
>  	{
> @@ -153,8 +152,7 @@ static int bmp280_read_calib(struct bmp280_data *data,
>  			     struct bmp280_calib *calib,
>  			     unsigned int chip)
>  {
> -	__le16 p_buf[BMP280_COMP_PRESS_REG_COUNT / 2];
> -	__le16 t_buf[BMP280_COMP_TEMP_REG_COUNT / 2];
> +	__le16 c_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2];
>  	struct device *dev = data->dev;
>  	unsigned int tmp;
>  	__le16 l16;
> @@ -162,43 +160,33 @@ static int bmp280_read_calib(struct bmp280_data *data,
>  	int ret;
>  
>  
> -	/* Read temperature calibration values. */
> +	/* Read temperature and pressure calibration values. */
>  	ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START,
> -			       t_buf, BMP280_COMP_TEMP_REG_COUNT);
> +			       c_buf, sizeof(c_buf));
>  	if (ret < 0) {
>  		dev_err(data->dev,
> -			"failed to read temperature calibration parameters\n");
> +			"failed to read temperature and pressure calibration parameters\n");
>  		return ret;
>  	}
>  
> -	/* Toss the temperature calibration data into the entropy pool */
> -	add_device_randomness(t_buf, sizeof(t_buf));
> -
> -	calib->T1 = le16_to_cpu(t_buf[T1]);
> -	calib->T2 = le16_to_cpu(t_buf[T2]);
> -	calib->T3 = le16_to_cpu(t_buf[T3]);
> -
> -	/* Read pressure calibration values. */
> -	ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_PRESS_START,
> -			       p_buf, BMP280_COMP_PRESS_REG_COUNT);
> -	if (ret < 0) {
> -		dev_err(data->dev,
> -			"failed to read pressure calibration parameters\n");
> -		return ret;
> -	}
> -
> -	/* Toss the pressure calibration data into the entropy pool */
> -	add_device_randomness(p_buf, sizeof(p_buf));
> -
> -	calib->P1 = le16_to_cpu(p_buf[P1]);
> -	calib->P2 = le16_to_cpu(p_buf[P2]);
> -	calib->P3 = le16_to_cpu(p_buf[P3]);
> -	calib->P4 = le16_to_cpu(p_buf[P4]);
> -	calib->P5 = le16_to_cpu(p_buf[P5]);
> -	calib->P6 = le16_to_cpu(p_buf[P6]);
> -	calib->P7 = le16_to_cpu(p_buf[P7]);
> -	calib->P8 = le16_to_cpu(p_buf[P8]);
> -	calib->P9 = le16_to_cpu(p_buf[P9]);
> +	/* Toss the temperature and pressure calibration data into the entropy pool */
> +	add_device_randomness(c_buf, sizeof(c_buf));
> +
> +	/* Parse temperature calibration values. */
> +	calib->T1 = le16_to_cpu(c_buf[T1]);
> +	calib->T2 = le16_to_cpu(c_buf[T2]);
> +	calib->T3 = le16_to_cpu(c_buf[T3]);
> +
> +	/* Parse pressure calibration values. */
> +	calib->P1 = le16_to_cpu(c_buf[P1]);
> +	calib->P2 = le16_to_cpu(c_buf[P2]);
> +	calib->P3 = le16_to_cpu(c_buf[P3]);
> +	calib->P4 = le16_to_cpu(c_buf[P4]);
> +	calib->P5 = le16_to_cpu(c_buf[P5]);
> +	calib->P6 = le16_to_cpu(c_buf[P6]);
> +	calib->P7 = le16_to_cpu(c_buf[P7]);
> +	calib->P8 = le16_to_cpu(c_buf[P8]);
> +	calib->P9 = le16_to_cpu(c_buf[P9]);
>  
>  	/*
>  	 * Read humidity calibration values.
> diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h
> index 4a501836d27a..03a539223417 100644
> --- a/drivers/iio/pressure/bmp280.h
> +++ b/drivers/iio/pressure/bmp280.h
> @@ -37,6 +37,9 @@
>  
>  #define BMP280_COMP_H5_MASK		GENMASK(15, 4)
>  
> +#define BMP280_CONTIGUOUS_CALIB_REGS	(BMP280_COMP_TEMP_REG_COUNT + \
> +					 BMP280_COMP_PRESS_REG_COUNT)
> +
>  #define BMP280_FILTER_MASK		GENMASK(4, 2)
>  #define BMP280_FILTER_OFF		0
>  #define BMP280_FILTER_2X		1


  reply	other threads:[~2022-09-15 14:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 23:43 [PATCH v6 0/9] Add support for pressure sensor Bosch BMP380 Angel Iglesias
2022-09-12 23:44 ` [PATCH v6 1/9] iio: pressure: bmp280: reorder local variables following reverse xmas tree Angel Iglesias
2022-09-12 23:45 ` [PATCH v6 2/9] iio: pressure: bmp280: use FIELD_GET, FIELD_PREP and GENMASK Angel Iglesias
2022-09-15 14:54   ` Jonathan Cameron
2022-09-12 23:46 ` [PATCH v6 3/9] iio: pressure: bmp280: Simplify bmp280 calibration data reading Angel Iglesias
2022-09-15 14:57   ` Jonathan Cameron [this message]
2022-09-12 23:47 ` [PATCH v6 4/9] iio: pressure: bmp280: simplify driver initialization logic Angel Iglesias
2022-09-17 13:16   ` Jonathan Cameron
2022-09-12 23:48 ` [PATCH v6 5/9] iio: pressure: bmp280: Fix alignment for DMA safety Angel Iglesias
2022-09-17 13:17   ` Jonathan Cameron
2022-09-12 23:50 ` [PATCH v6 6/9] iio: pressure: bmp280: reorder i2c device tables declarations Angel Iglesias
2022-09-17 13:18   ` Jonathan Cameron
2022-09-12 23:52 ` [PATCH v6 7/9] iio: pressure: bmp280: Add support for BMP380 sensor family Angel Iglesias
2022-09-13 16:46   ` Andy Shevchenko
2022-09-13 21:19     ` Angel Iglesias
2022-09-14  9:30       ` Andy Shevchenko
2022-09-17 13:25   ` Jonathan Cameron
2022-09-18 10:06     ` Angel Iglesias
2022-09-18 14:37       ` Jonathan Cameron
2022-09-12 23:53 ` [PATCH v6 8/9] dt-bindings: iio: pressure: bmp085: Add BMP380 compatible string Angel Iglesias
2022-09-12 23:54 ` [PATCH v6 9/9] iio: pressure: bmp280: Add more tunable config parameters for BMP380 Angel Iglesias
2022-09-17 13:31   ` 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=20220915155741.2c19e927@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=ang.iglesiasg@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@crapouillou.net \
    --cc=rafael.j.wysocki@intel.com \
    --cc=ulf.hansson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox