From: Jonathan Cameron <jic23@kernel.org>
To: Achim Gratz <Achim.Gratz@Stromeko.DE>
Cc: linux-iio@vger.kernel.org,
"David Lechner" <dlechner@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>
Subject: Re: [RFC PATCH v3 1/9] iio: pressure: bmp280: correct meas_time_us calculation
Date: Sat, 4 Oct 2025 16:21:01 +0100 [thread overview]
Message-ID: <20251004162101.3de2397b@jic23-huawei> (raw)
In-Reply-To: <20250928172637.37138-2-Achim.Gratz@Stromeko.DE>
On Sun, 28 Sep 2025 19:26:28 +0200
Achim Gratz <Achim.Gratz@Stromeko.DE> wrote:
> Correction of meas_time_us initialization based on an observation and
> partial patch by David Lechner.
>
> The constant part of the measurement time (as described in the
> datasheet and implemented in the BM(P/E)2 Sensor API) was apparently
> forgotten (it was already correctly applied for the BMP380) and is now
> used.
>
> There was also another thinko in bmp280_wait_conv:
> data->oversampling_humid can actually have a value of 0 (for an
> oversampling_ratio of 1), so it can not be used to detect the presence
> of the humidity measurement capability. Use
> data->chip_info->oversampling_humid_avail instead, which is NULL for
> chips that cannot measure humidity and therefore must skip that part
> of the calculation.
>
> Closes: https://lore.kernel.org/linux-iio/875xgfg0wz.fsf@Gerda.invalid/
> Fixes: 26ccfaa9ddaa ("iio: pressure: bmp280: Use sleep and forced mode for oneshot captures")
> Suggested-by: David Lechner <dlechner@baylibre.com>
> Tested-by: Achim Gratz <Achim.Gratz@Stromeko.DE>
> Signed-off-by: Achim Gratz <Achim.Gratz@Stromeko.DE>
Applied this to the fixes-togreg branch of iio.git. I'll send a pull request
for that shortly after rc1. The others will have to wait until that is available upstream.
>
> ---
>
> Notes
> =====
>
> Since the BMx280 device support was added, oversampling=0 actually is
> a valid register setting (meaning that measurement channel is off),
> but actually allowing that setting to be used by changing the data
> structure to hold the actual value instead of its ilog2 would require
> more extensive changes elsewhere in the code.
>
> Further changes would be necesary to avoid the awkward use of -1 as
> the value that would currently be necessary to achieve a setting of 0
> in the register.
>
> Datasheet values and median actual measurement times through sysfs for
> a single reading with my BME280 connected to a 400kHz I²C bus provided
> by the i915 IGP VGA port:
>
> |--------------+---------+---------+----------+----------|
> | Oversampling | Typical | Maximum | Measured | Overhead |
> | Ratio | [ms] | [ms] | [ms] | [ms] |
> |--------------+---------+---------+----------+----------|
> | 16 | 98.0 | 112.8 | 122.1 | 9.3 |
> | 8 | 50.0 | 57.6 | 63.6 | 6.0 |
> | 4 | 26.0 | 30.0 | 34.6 | 4.6 |
> | 2 | 14.0 | 16.2 | 21.7 | 5.5 |
> | 1 | 8.0 | 9.3 | 14.8 | 5.5 |
> |--------------+---------+---------+----------+----------|
>
> Reading all three channels via sysfs triples those times, including
> the overhead of course as each read triggers a new measurement on all
> enabled channels. It is therefore also impossible to obtain all
> channel values from the same measurement cycle with MODE_FORCED, which
> is in a way a limitation of the sysfs interface and can only be
> obtained by using buffered reads.
> ---
> drivers/iio/pressure/bmp280-core.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 6cdc8ed53520..2078b810745b 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -1042,13 +1042,16 @@ static int bmp280_wait_conv(struct bmp280_data *data)
> unsigned int reg, meas_time_us;
> int ret;
>
> - /* Check if we are using a BME280 device */
> - if (data->oversampling_humid)
> - meas_time_us = BMP280_PRESS_HUMID_MEAS_OFFSET +
> - BIT(data->oversampling_humid) * BMP280_MEAS_DUR;
> + /* Constant part of the measurement time */
> + meas_time_us = BMP280_MEAS_OFFSET;
>
> - else
> - meas_time_us = 0;
> + /*
> + * Check if we are using a BME280 device,
> + * Humidity measurement time
> + */
> + if (data->chip_info->oversampling_humid_avail)
> + meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET +
> + BIT(data->oversampling_humid) * BMP280_MEAS_DUR;
>
> /* Pressure measurement time */
> meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET +
next prev parent reply other threads:[~2025-10-04 15:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-28 17:26 [RFC PATCH v3 0/9] Fixes and enhancements for the bmp280 driver Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 1/9] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
2025-10-04 15:21 ` Jonathan Cameron [this message]
2025-09-28 17:26 ` [RFC PATCH v3 1/1] iio: pressure: bmp280: test longer autosuspend (WIP) Achim Gratz
2025-09-28 19:10 ` ASSI
2025-09-28 17:26 ` [RFC PATCH v3 2/9] iio: pressure: bmp280: implement adaptive wait for BMx280 devices Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 3/9] iio: pressure: bmp280: implement adaptive wait for BMP380 devices Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 4/9] iio: pressure: bmp280: rename wait_conv() to conv(), factor out measurement time calculation Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 5/9] iio: pressure: bmp280: remove code duplication Achim Gratz
2025-10-04 15:12 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 6/9] iio: pressure: bmp280: enable filter settings for BMx280 Achim Gratz
2025-10-04 15:21 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 7/9] iio: pressure: bmp280: implement sampling_frequency " Achim Gratz
2025-10-04 15:32 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 8/9] iio: pressure: bmp280: implement sampling_frequency calculation " Achim Gratz
2025-10-04 15:37 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 9/9] iio: pressure: bmp280: test longer autosuspend (WIP) Achim Gratz
2025-10-04 15:07 ` [RFC PATCH v3 0/9] Fixes and enhancements for the bmp280 driver Jonathan Cameron
2025-10-04 16:59 ` ASSI
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=20251004162101.3de2397b@jic23-huawei \
--to=jic23@kernel.org \
--cc=Achim.Gratz@Stromeko.DE \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.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