From: Antoni Pokusinski <apokusinski01@gmail.com>
To: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, marcelo.schmitt1@gmail.com
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Antoni Pokusinski <apokusinski01@gmail.com>
Subject: [PATCH v4 1/3] iio: mpl3115: use get_unaligned_be24() to retrieve pressure data
Date: Wed, 12 Nov 2025 23:56:59 +0100 [thread overview]
Message-ID: <20251112225701.32158-2-apokusinski01@gmail.com> (raw)
In-Reply-To: <20251112225701.32158-1-apokusinski01@gmail.com>
The pressure measurement result is arranged as 20-bit unsigned value
residing in three 8-bit registers. Hence, it can be retrieved using
get_unaligned_be24() and by applying 4-bit shift.
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
---
drivers/iio/pressure/mpl3115.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index c212dfdf59ff..5594256fffbd 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -16,6 +16,7 @@
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/property.h>
+#include <linux/unaligned.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
@@ -125,7 +126,7 @@ static int mpl3115_read_info_raw(struct mpl3115_data *data,
switch (chan->type) {
case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
- __be32 tmp = 0;
+ u8 press_be24[3];
guard(mutex)(&data->lock);
ret = mpl3115_request(data);
@@ -134,11 +135,17 @@ static int mpl3115_read_info_raw(struct mpl3115_data *data,
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_PRESS,
- 3, (u8 *) &tmp);
+ sizeof(press_be24),
+ press_be24);
if (ret < 0)
return ret;
- *val = be32_to_cpu(tmp) >> chan->scan_type.shift;
+ /*
+ * The pressure channel shift is applied in the case where the
+ * data (24-bit big endian) is read into a 32-bit buffer. Here
+ * the data is stored in a 24-bit buffer, so the shift is 4.
+ */
+ *val = get_unaligned_be24(press_be24) >> 4;
return IIO_VAL_INT;
}
case IIO_TEMP: { /* in 0.0625 celsius / LSB */
--
2.25.1
next prev parent reply other threads:[~2025-11-12 22:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 22:56 [PATCH v4 0/3] iio: mpl3115: support for events Antoni Pokusinski
2025-11-12 22:56 ` Antoni Pokusinski [this message]
2025-11-12 22:57 ` [PATCH v4 2/3] iio: mpl3115: add threshold events support Antoni Pokusinski
2025-11-12 22:57 ` [PATCH v4 3/3] iio: ABI: document pressure event attributes Antoni Pokusinski
2025-11-15 18:07 ` [PATCH v4 0/3] iio: mpl3115: support for events 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=20251112225701.32158-2-apokusinski01@gmail.com \
--to=apokusinski01@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--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