summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoni Pokusinski <apokusinski01@gmail.com>2025-11-12 23:56:59 +0100
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2025-11-15 18:06:47 +0000
commit47e4b1ca441cc4f1d9db13ff5e9b89e53aae0198 (patch)
tree20b755d6fbcda615dd800fbb9ada84625e45a8c7
parent0de73abe5f5c2b58d66d6dcb7d44df05b0f73684 (diff)
iio: mpl3115: use get_unaligned_be24() to retrieve pressure data
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> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/iio/pressure/mpl3115.c13
1 files 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 */