public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andreas Klinger <ak@it-klinger.de>
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	linus.walleij@linaro.org, yongjun_wei@trendmicro.com.cn,
	a.mathur@samsung.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: bmp280: properly initialize device for humidity reading
Date: Sun, 30 Jul 2017 14:41:37 +0100	[thread overview]
Message-ID: <20170730144137.41af780d@kernel.org> (raw)
In-Reply-To: <20170725091114.GA25223@arbeit>

On Tue, 25 Jul 2017 11:11:14 +0200
Andreas Klinger <ak@it-klinger.de> wrote:

> If the device is not initialized at least once it happens that the humidity
> reading is skipped, which means the special value 0x8000 is delivered.
> 
> For omitting this case the oversampling of the humidity must be set before
> the oversampling of the temperature und pressure is set as written in the
> datasheet of the BME280.
> 
> Furthermore proper error detection is added in case a skipped value is read
> from the device. This is done also for pressure and temperature reading.
> Especially it don't make sense to compensate this value and treat it as
> regular value.
> 
> Signed-off-by: Andreas Klinger <ak@it-klinger.de>
Applied to the fixes togreg branch of iio.git.

Thanks,

Jonathan
> ---
>  drivers/iio/pressure/bmp280-core.c | 27 ++++++++++++++++++++++++---
>  drivers/iio/pressure/bmp280.h      |  5 +++++
>  2 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 4d18826ac63c..d434e2c23833 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -281,6 +281,11 @@ static int bmp280_read_temp(struct bmp280_data *data,
>  	}
>  
>  	adc_temp = be32_to_cpu(tmp) >> 12;
> +	if (adc_temp == BMP280_TEMP_SKIPPED) {
> +		/* reading was skipped */
> +		dev_err(data->dev, "reading temperature skipped\n");
> +		return -EIO;
> +	}
>  	comp_temp = bmp280_compensate_temp(data, adc_temp);
>  
>  	/*
> @@ -316,6 +321,11 @@ static int bmp280_read_press(struct bmp280_data *data,
>  	}
>  
>  	adc_press = be32_to_cpu(tmp) >> 12;
> +	if (adc_press == BMP280_PRESS_SKIPPED) {
> +		/* reading was skipped */
> +		dev_err(data->dev, "reading pressure skipped\n");
> +		return -EIO;
> +	}
>  	comp_press = bmp280_compensate_press(data, adc_press);
>  
>  	*val = comp_press;
> @@ -344,6 +354,11 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
>  	}
>  
>  	adc_humidity = be16_to_cpu(tmp);
> +	if (adc_humidity == BMP280_HUMIDITY_SKIPPED) {
> +		/* reading was skipped */
> +		dev_err(data->dev, "reading humidity skipped\n");
> +		return -EIO;
> +	}
>  	comp_humidity = bmp280_compensate_humidity(data, adc_humidity);
>  
>  	*val = comp_humidity;
> @@ -596,14 +611,20 @@ static const struct bmp280_chip_info bmp280_chip_info = {
>  
>  static int bme280_chip_config(struct bmp280_data *data)
>  {
> -	int ret = bmp280_chip_config(data);
> +	int ret;
>  	u8 osrs = BMP280_OSRS_HUMIDITIY_X(data->oversampling_humid + 1);
>  
> +	/*
> +	 * Oversampling of humidity must be set before oversampling of
> +	 * temperature/pressure is set to become effective.
> +	 */
> +	ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY,
> +				  BMP280_OSRS_HUMIDITY_MASK, osrs);
> +
>  	if (ret < 0)
>  		return ret;
>  
> -	return regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY,
> -				  BMP280_OSRS_HUMIDITY_MASK, osrs);
> +	return bmp280_chip_config(data);
>  }
>  
>  static const struct bmp280_chip_info bme280_chip_info = {
> diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h
> index 2c770e13be0e..61347438b779 100644
> --- a/drivers/iio/pressure/bmp280.h
> +++ b/drivers/iio/pressure/bmp280.h
> @@ -96,6 +96,11 @@
>  #define BME280_CHIP_ID			0x60
>  #define BMP280_SOFT_RESET_VAL		0xB6
>  
> +/* BMP280 register skipped special values */
> +#define BMP280_TEMP_SKIPPED		0x80000
> +#define BMP280_PRESS_SKIPPED		0x80000
> +#define BMP280_HUMIDITY_SKIPPED		0x8000
> +
>  /* Regmap configurations */
>  extern const struct regmap_config bmp180_regmap_config;
>  extern const struct regmap_config bmp280_regmap_config;

      reply	other threads:[~2017-07-30 13:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25  9:11 [PATCH] iio: bmp280: properly initialize device for humidity reading Andreas Klinger
2017-07-30 13:41 ` Jonathan Cameron [this message]

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=20170730144137.41af780d@kernel.org \
    --to=jic23@kernel.org \
    --cc=a.mathur@samsung.com \
    --cc=ak@it-klinger.de \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=yongjun_wei@trendmicro.com.cn \
    /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