linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vasileios Amoiridis <vassilisamir@gmail.com>
To: jic23@kernel.org
Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com,
	ang.iglesiasg@gmail.com, mazziesaccount@gmail.com,
	ak@it-klinger.de, petre.rodan@subdimension.ro,
	phil@raspberrypi.com, 579lpy@gmail.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Vasileios Amoiridis <vassilisamir@gmail.com>
Subject: [PATCH 0/4] Series to add triggered buffer support to BMP280 driver
Date: Sun,  3 Mar 2024 17:52:56 +0100	[thread overview]
Message-ID: <20240303165300.468011-1-vassilisamir@gmail.com> (raw)

This patch series aims to add triggered buffer support in the BMP280 driver.
The patches have been separated in a way that a single functionality is added
with each commit. The 1st commit is independent but the others not. Commit
no.3 needs commit no.2 and commit no.4 needs both commit no.3 and commit no.2.
More details below:

PATCH 1/4: Sort the headers of the bmp280-core.c file before adding new ones.

PATCH 2/4: The scale value for every channel is needed in order to be able to
calculate the final value in userspace. Every measurement from every device
requires a different scaling in order to apply to the IIO measurement unit
standards.

PATCH 3/4: This commit adds a channel for a soft timestamp. The indexing of
temperature and pressure channels is changed and temperature comes first. This
is because the temperature measurement is always needed for a measurement so
it is better to have it as first for the available_scan_masks. The values have
already the CPU endiannes and are already compensated. As mentioned before,
only the scale value to convert them to IIO measurement unit standards is
missing.

PATCH 4/4: This commit is adding the actual triggered buffer. An extra buffer
is added to hold the values of the measurements. This buffer is not inside the
union but rather an external buffer. The reasons for that are presented below:

i) The sensor is built in a way that first you read the raw values out of the
sensor, then you have to compensate those values in software and then you have
to convert them in IIO measurement units. This means that the values of the
data->buf (which is in the DMA safe union) cannot be used directly to push data
to userspace because even though we can have the SCALE value to convert to IIO
measurement units, we still need to compensate first. Only the latest version
of the BMP58x sensor returns directly compensated values.

ii) In order to have a pressure or a humidity measurement, a temperature
measurement needs to happen first so the t_fine variable is filled/updated.
The read_press() and read_humid() functions contain the read_temp() measurement
inside their bodies. This means that if we use an extra buffer inside the DMA
safe union in order to push data to userspace, the first 3 bytes of that buffer
will always be overwritten by a read_press() or read_humid() operation.

In order to overcome the above 2 problems the following things need to be done:

a) Remove the read_temp() function from the inside bodies of read_press/humid()
and call it before you call them.

b) Modify all the read_temp/press/humid() functions and instead of returning
the IIO measurement unit (with *val, *val2, and return IIO value) just return
the compensated value so it can be used with the SCALE value in userspace for
buffer reads and for oneshot captures just do the extra calculations for *val,
*val2 and return IIO value in the bmp280_read_raw() body.

If the solution that I have already sent in the commits is acceptable it's OK.
If it is necessary to have this iio_buffer structure that I used, inside the
union which is also DMA safe then I can immediately implement the a) and b) 
solutions and resend the patches for discussion.

Vasileios Amoiridis (4):
  iio: pressure: BMP280 core driver headers sorting
  iio: pressure: Add scale value for channels
  iio: pressure: Add timestamp and scan_masks for BMP280 driver
  iio: pressure: Add triggered buffer support for BMP280 driver

 drivers/iio/pressure/Kconfig       |   2 +
 drivers/iio/pressure/bmp280-core.c | 352 ++++++++++++++++++++++++-----
 drivers/iio/pressure/bmp280.h      |   8 +
 3 files changed, 311 insertions(+), 51 deletions(-)

-- 
2.25.1


             reply	other threads:[~2024-03-03 16:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03 16:52 Vasileios Amoiridis [this message]
2024-03-03 16:52 ` [PATCH 1/4] iio: pressure: BMP280 core driver headers sorting Vasileios Amoiridis
2024-03-04 11:36   ` Andy Shevchenko
2024-03-09 18:09   ` Jonathan Cameron
2024-03-03 16:52 ` [PATCH 2/4] iio: pressure: Add scale value for channels Vasileios Amoiridis
2024-03-04 11:42   ` Andy Shevchenko
2024-03-09 18:28   ` Jonathan Cameron
2024-03-03 16:52 ` [PATCH 3/4] iio: pressure: Add timestamp and scan_masks for BMP280 driver Vasileios Amoiridis
2024-03-04 11:47   ` Andy Shevchenko
2024-03-04 18:50     ` Vasileios Amoiridis
2024-03-04 19:07       ` Andy Shevchenko
2024-03-09 18:12         ` Jonathan Cameron
2024-03-03 16:53 ` [PATCH 4/4] iio: pressure: Add triggered buffer support " Vasileios Amoiridis
2024-03-04 11:52   ` Andy Shevchenko
2024-03-04 19:08     ` Vasileios Amoiridis
2024-03-04 19:18       ` Andy Shevchenko
2024-03-04 20:05         ` Vasileios Amoiridis
2024-03-09 18:19           ` Jonathan Cameron
2024-03-09 18:32   ` 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=20240303165300.468011-1-vassilisamir@gmail.com \
    --to=vassilisamir@gmail.com \
    --cc=579lpy@gmail.com \
    --cc=ak@it-klinger.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ang.iglesiasg@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=petre.rodan@subdimension.ro \
    --cc=phil@raspberrypi.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).