Linux IIO development
 help / color / mirror / Atom feed
* [RFC PATCH v3 0/9] Fixes and enhancements for the bmp280 driver
@ 2025-09-28 17:26 Achim Gratz
  2025-09-28 17:26 ` [RFC PATCH v3 1/9] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
                   ` (10 more replies)
  0 siblings, 11 replies; 19+ messages in thread
From: Achim Gratz @ 2025-09-28 17:26 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, David Lechner, Andy Shevchenko, Nuno Sá,
	Achim Gratz

Revision History:
=================

v1:
	- initial proposal, incorrectly prefixed "bmp280" instead of "RFC PATCH"
	- patch series presented in the order it was created

v1 -> v2:
	- prefix as "RFC PATCH"
	- drop channel switching
	- rewrite to present patches in smaller units and in logical steps

v2 -> v3:
	- incorporate comments/suggestions on v2
	- clean up

With v6.13 a change was made to the bmp280 drivers to use MODE_FORCED
instead of MODE_NORMAL.  This broke userspace functionality: reading
from sysfs interfaces no longer worked and an error was thrown
"Measurement cycle didn't complete".  This series fixes the underlying
bugs affecting the measurement time calculation (patches 0001 through
005) and implements additional functionality (patches 0006 through
009) not available for the BMx280 devices previously to allow the use
of the sysfs interface in MODE_NORMAL again and control the
corresponding parameters.  The implementation follows the already
existing facilities for the BMx[35]80 devices even though the actual
functionality of the BMx280 hardware is slightly different.

Achim Gratz (9):
  iio: pressure: bmp280: correct meas_time_us calculation
  iio: pressure: bmp280: implement adaptive wait for BMx280 devices
  iio: pressure: bmp280: implement adaptive wait for BMP380 devices
  iio: pressure: bmp280: rename wait_conv() to conv(), factor out
    measurement time calculation
  iio: pressure: bmp280: remove code duplication
  iio: pressure: bmp280: enable filter settings for BMx280
  iio: pressure: bmp280: implement sampling_frequency for BMx280
  iio: pressure: bmp280: implement sampling_frequency calculation for
    BMx280
  iio: pressure: bmp280: test longer autosuspend (WIP)

 drivers/iio/pressure/bmp280-core.c | 504 +++++++++++++++++++++--------
 drivers/iio/pressure/bmp280.h      |  26 +-
 2 files changed, 387 insertions(+), 143 deletions(-)

-- 

Comments:

Thanks for all suggestions and comments on my v1 and v2 patch series.

I've not had time to work on the suggested further changes to the
implementation, to recap that would entail implementing the
*_available attributes and completely reworking the handling of the
ODR and filter settings to better conform to the API:

	1. A list of available values for each setting should be
          associated via the *_available attribute (since these are a
          fixed number for each parameter due to the register
          mapping);

	2. Available output data rate settings would be variable
          depending on the OSR (at the moment the setting is fixed,
          but the reading is variable);

	3. Filter settings would be done by 3dB corner (either real or
          normalized frequency) instead of the divisor (bitshift)
          applied to produce the decay value of the underlying
          recursive IIR.

Anything from 2. on would break userspace (again), but make the
implementation more conformant with the API.  I think there needs to
be more discission of how to re-structure the code to support this:
the current static tables would become really large, however setting
dynamic calculations up so that the small number of valid register
values can get extracted would be rather complex and error-prone.  So
it is likely there should be some combination of both approaches used.


The remaining sticky point is the control of the autosuspend delay
(patch 0099).  If the sensor is suspended between measurements, then
even when it is operating in MODE_NORMAL, an additional latency of
12…15ms is incured when the interval between measurements is long
enough to trigger autosuspend.  I have set the hardcoded value to 2s
as a test (see the last patch in the series) and this additional
latency vanishes, interestingly also the tailing to long measurement
times I have observed otherwise is also much reduced.  However so far
I've not come up with an idea of how to control the autosuspend delay
from userspace, to wit:

 /sys/bus/iio/devices/iio:device0/power/async: disabled
 /sys/bus/iio/devices/iio:device0/power/autosuspend_delay_ms:
 '/sys/bus/iio/devices/iio:device0/power/autosuspend_delay_ms': Input/output error
 /sys/bus/iio/devices/iio:device0/power/control: auto
 /sys/bus/iio/devices/iio:device0/power/runtime_active_kids: 0
 /sys/bus/iio/devices/iio:device0/power/runtime_active_time: 0
 /sys/bus/iio/devices/iio:device0/power/runtime_enabled: disabled
 /sys/bus/iio/devices/iio:device0/power/runtime_status: unsupported
 /sys/bus/iio/devices/iio:device0/power/runtime_suspended_time: 0
 /sys/bus/iio/devices/iio:device0/power/runtime_usage: 0
 -rw-r--r-- 1 root root 4096 Aug 10 18:41 async
 -rw-r--r-- 1 root root 4096 Aug 10 18:41 autosuspend_delay_ms
 -rw-r--r-- 1 root root 4096 Aug 10 18:41 control
 -r--r--r-- 1 root root 4096 Aug 10 18:41 runtime_active_kids
 -r--r--r-- 1 root root 4096 Aug 10 18:41 runtime_active_time
 -r--r--r-- 1 root root 4096 Aug 10 18:41 runtime_enabled
 -r--r--r-- 1 root root 4096 Aug 10 18:41 runtime_status
 -r--r--r-- 1 root root 4096 Aug 10 18:41 runtime_suspended_time
 -r--r--r-- 1 root root 4096 Aug 10 18:41 runtime_usage

…which according to the kernel documentation is due to a lack of
unspecified support from the driver.  Now, it appears I should be able
to switch off autosuspend altogether by changing control from "auto"
to "on", but that doesn't seem to take effect; also I'd rather
configure a sensible value in accordance to my measurement settings.
The other handful of IIO drivers I've looked at that set this
parameter don't do things differently, so I don't know if there's
anything that can be done about it from within the driver
implementation.


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-10-04 16:59 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox