linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: ASSI <Stromeko@nexgo.de>,
	linux-iio@vger.kernel.org,
	Vasileios Amoiridis <vassilisamir@gmail.com>
Subject: Re: [PATCH v9 1/4] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures
Date: Sat, 28 Jun 2025 15:57:34 -0500	[thread overview]
Message-ID: <c894cfda-a775-4598-ac3b-b3d35c6a84b3@baylibre.com> (raw)
In-Reply-To: <875xgfg0wz.fsf@Gerda.invalid>

On 6/28/25 1:45 PM, ASSI wrote:
> Vasileios Amoiridis writes:
>> The idea is that the sensor is by default in sleep mode, wakes up in
>> forced mode when a oneshot capture is requested, or in normal mode
>> when the buffer is enabled. The difference lays in the fact that in
>> forced mode, the sensor does only one conversion and goes back to sleep
>> while in normal mode, the sensor does continuous measurements with the
>> frequency that was set in the ODR registers.
>>
>> The bmpX_chip_config() functions which are responsible for applying
>> the requested configuration to the sensor, are modified accordingly
>> in order to set the sensor by default in sleep mode.
> 
> Since this change went into 6.13, I've been unable to update the kernel
> since it breaks usermode quite badly for me.  I am using sysfs to read a
> BME280 sensor every second (oversampling is set to 1, so there should be
> no trouble at all to read at that rate) and most of the time the
> measurement doesn't complete and I get back an error message instead of
> the expected reading.  The journal is full of these:
> 
> Jun 28 08:19:16 Otto kernel: bmp280 1-0076: Measurement cycle didn't complete.
> Jun 28 08:19:16 Otto kernel: bmp280 1-0076: Measurement cycle didn't complete.
> Jun 28 08:19:16 Otto kernel: bmp280 1-0076: Measurement cycle didn't complete.
> 
> The exact same thing happens if I stop the process that's reading the
> sensor every second and do a manual read at much longer intervals, so
> it's indeed not the read rate, but rather that the driver apparently
> doesn't wait long enough for the measurement to complete.  There is an
> indication that the wait time is just slightly too short as I have a
> somewhat higher success rate at reading every second when the load is
> higher.  Addtionally the read time for all three values from the sensor
> went from ~7ms to ~28ms with much stronger tailing to longer read times
> than before.  This sensor is in daisy-chain with a DS3231M RTC and hangs
> off the DDC of the unsused VGA port provided by an Intel IGP.
> 
> I've not found a way to switch the operations mode via sysfs and/or
> enable the ring buffer, which may or may not solve the problem depending
> on which mode is used when the trigger arrives.  That's mainly because I
> couldn't find a complete example of how to use this facility and I've
> likely done some of the steps in the wrong order or missed one.  I've
> enabled the scan elements, but trying to enable the buffer tells me
> "write error: Invalid argument".  For starters, the system I'm on
> (openSUSE Tumbleweed) doesn't seem to have IIO trigger support enabled
> via either configfs or sysfs.  But in any case I think oneshot capturing
> from userland should still work, I just haven't found out how.
> 
> So is there some description of how to get the sysfs functionality as
> before and/or switch the operations mode to avoid this failure?  The
> easiest would be if the BME280_MEAS_OFFSET value was configurable, but
> it's a #DEFINE at the moment.
> 
> 
> Regards,
> Achim.

If this change broke your code, we need to fix it in the kernel, so
thanks for reporting the regression.

It looks like the wait time calculations in bmp280_wait_conv() don't
match up with the datasheet [1] that I found.

[1]: https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf

There, table 13 says that if pressure and temperature oversampling
are bot set to x1, then it could take up to 6.4 ms to complete the
measurement.

However, in the code, we have:

```
#define BMP280_MEAS_OFFSET		1250
#define BMP280_MEAS_DUR			2300
#define BMP280_PRESS_HUMID_MEAS_OFFSET	575
```

and 

```
	/* 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;

	else
		meas_time_us = 0;

	/* Pressure measurement time */
	meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET +
			BIT(data->oversampling_press) * BMP280_MEAS_DUR;

	/* Temperature measurement time */
	meas_time_us += BIT(data->oversampling_temp) * BMP280_MEAS_DUR;

	/* Waiting time according to the BM(P/E)2 Sensor API */
	fsleep(meas_time_us);
```

Assuming BIT(*oversampling*) is 1 for x1 oversampling, we get

meas_time_us = (0) + (575 + 1 * 2300) + (1 * 2300) = 5175
               ^     ^                  ^
               |     |                  |
               |     |                  temperature
               |     pressure
               humidity

5175 microseconds is less than the 6.4 milliseconds max time, so
that would explain the error that is seen since the error is
triggered by the status bit that says the chip is still busy taking
the measurement.

BMP280_MEAS_OFFSET is unused in the code. But 6400 - 5175 is 1225
which is very close to 1250. So I think the intention was to include
that it the calculation like this:

---
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 74505c9ec1a0..50c869e3d5c9 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -1042,14 +1042,13 @@ static int bmp280_wait_conv(struct bmp280_data *data)
 	unsigned int reg, meas_time_us;
 	int ret;
 
+	meas_time_us = BMP280_MEAS_OFFSET;
+
 	/* Check if we are using a BME280 device */
 	if (data->oversampling_humid)
-		meas_time_us = BMP280_PRESS_HUMID_MEAS_OFFSET +
+		meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET +
 				BIT(data->oversampling_humid) * BMP280_MEAS_DUR;
 
-	else
-		meas_time_us = 0;
-
 	/* Pressure measurement time */
 	meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET +
 			BIT(data->oversampling_press) * BMP280_MEAS_DUR;
---

Hopefully you can compile your own kernel and test this. If that fixes it
we can turn it into a proper patch.


  reply	other threads:[~2025-06-28 20:57 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 23:30 [PATCH v9 0/4] pressure: bmp280: Minor cleanup and interrupt support Vasileios Amoiridis
2024-10-17 23:30 ` [PATCH v9 1/4] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Vasileios Amoiridis
2025-06-28 18:45   ` ASSI
2025-06-28 20:57     ` David Lechner [this message]
2025-06-29  7:43       ` ASSI
2025-07-11 19:17       ` ASSI
2025-07-12 14:49         ` ASSI
2025-07-21 19:15           ` ASSI
2025-07-26 18:34           ` ASSI
2025-07-27 19:08             ` ASSI
2024-10-17 23:30 ` [PATCH v9 2/4] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Vasileios Amoiridis
2024-10-17 23:30 ` [PATCH v9 3/4] iio: pressure: bmp280: Add data ready trigger support Vasileios Amoiridis
2024-10-17 23:30 ` [PATCH v9 4/4] iio: pressure: bmp280: Move bmp085 interrupt to new configuration Vasileios Amoiridis
2024-10-19 13:55 ` [PATCH v9 0/4] pressure: bmp280: Minor cleanup and interrupt support Jonathan Cameron
2025-08-03 14:07 ` [bmp280 v1 0/6] Fixes and enhancements for the bmp280 driver Achim Gratz
2025-08-03 14:07   ` [bmp280 v1 1/6] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
2025-08-06 15:46     ` Jonathan Cameron
2025-08-06 17:53       ` ASSI
2025-08-10 18:04         ` Jonathan Cameron
2025-08-03 14:07   ` [bmp280 v1 2/6] iio: pressure: bmp280: reduce overhead on read with MODE_FORCED Achim Gratz
2025-08-03 20:12     ` Andy Shevchenko
2025-08-06 15:58     ` Jonathan Cameron
2025-08-06 18:00       ` ASSI
2025-08-03 14:07   ` [bmp280 v1 3/6] iio: pressure: bmp280: implement sampling_frequency for BMx280 Achim Gratz
2025-08-03 20:26     ` Andy Shevchenko
2025-08-04 17:29       ` ASSI
2025-08-10 18:11         ` Jonathan Cameron
2025-08-10 19:12           ` ASSI
2025-08-11 19:48             ` Jonathan Cameron
2025-08-12 19:53               ` ASSI
2025-08-17 15:10                 ` Jonathan Cameron
2025-08-17 16:36                   ` ASSI
2025-08-03 14:08   ` [bmp280 v1 4/6] iio: pressure: bmp280: enable filter settings " Achim Gratz
2025-08-03 20:28     ` Andy Shevchenko
2025-08-04 17:14       ` ASSI
2025-08-10 18:13     ` Jonathan Cameron
2025-08-10 19:01       ` ASSI
2025-08-11 20:14         ` Jonathan Cameron
2025-08-12 19:34           ` ASSI
2025-08-17 14:51             ` Jonathan Cameron
2025-08-03 14:08   ` [bmp280 v1 5/6] iio: pressure: bmp280: remove code duplication Achim Gratz
2025-08-03 20:30     ` Andy Shevchenko
2025-08-10 18:19     ` Jonathan Cameron
2025-08-03 14:08   ` [bmp280 v1 6/6] iio: pressure: bmp280: implement sampling_frequency calculation for BMx280 Achim Gratz
2025-08-03 20:37     ` Andy Shevchenko
2025-08-04 17:20       ` ASSI
2025-08-03 19:20   ` [bmp280 v1 0/6] Fixes and enhancements for the bmp280 driver Andy Shevchenko
2025-08-10 18:58 ` [RFC PATCH v2 0/9] " Achim Gratz
2025-08-10 18:58   ` [RFC PATCH v2 1/9] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
2025-08-17 15:16     ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 2/9] iio: pressure: bmp280: implement adaptive wait for BMx280 devices Achim Gratz
2025-08-10 19:49     ` Andy Shevchenko
2025-08-16 18:42       ` ASSI
2025-08-10 18:58   ` [RFC PATCH v2 3/9] iio: pressure: bmp280: implement adaptive wait for BMP380 devices Achim Gratz
2025-08-10 18:58   ` [RFC PATCH v2 4/9] iio: pressure: bmp280: refactoring Achim Gratz
2025-08-17 15:23     ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 5/9] iio: pressure: bmp280: remove code duplication Achim Gratz
2025-08-10 18:58   ` [RFC PATCH v2 6/9] iio: pressure: bmp280: enable filter settings for BMx280 Achim Gratz
2025-08-17 16:37     ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 7/9] iio: pressure: bmp280: implement sampling_frequency " Achim Gratz
2025-08-17 16:53     ` Jonathan Cameron
2025-08-17 17:36       ` ASSI
2025-08-10 18:58   ` [RFC PATCH v2 8/9] iio: pressure: bmp280: implement sampling_frequency calculation " Achim Gratz
2025-08-17 17:04     ` Jonathan Cameron
2025-08-17 17:40       ` ASSI
2025-08-18 17:52         ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 9/9] iio: pressure: bmp280: test longer autosuspend (WIP) Achim Gratz
2025-08-17 17:05     ` Jonathan Cameron
2025-08-17 17:44       ` ASSI
2025-08-11 12:14   ` [RFC PATCH v2 0/9] Fixes and enhancements for the bmp280 driver Andy Shevchenko
2025-08-11 20:17   ` 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=c894cfda-a775-4598-ac3b-b3d35c6a84b3@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Stromeko@nexgo.de \
    --cc=linux-iio@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).