[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251218-mprls_cleanup-v1-8-b36a170f1a5c@subdimension.ro>
Date: Thu, 18 Dec 2025 13:05:50 +0200
From: Petre Rodan <petre.rodan@...dimension.ro>
To: Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, Andreas Klinger <ak@...klinger.de>
Cc: linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
Jonathan Cameron <Jonathan.Cameron@...wei.com>
Subject: [PATCH 08/14] iio: pressure: mprls0025pa: stricter checks for the
status byte
Make sure a valid conversion comes with a status byte that only has
the MPR_ST_POWER bit set.
Return -EBUSY if also MPR_ST_BUSY is set or -EIO otherwise.
Signed-off-by: Petre Rodan <petre.rodan@...dimension.ro>
---
drivers/iio/pressure/mprls0025pa.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/pressure/mprls0025pa.c b/drivers/iio/pressure/mprls0025pa.c
index 7f8dc47d7073..973d205da3e9 100644
--- a/drivers/iio/pressure/mprls0025pa.c
+++ b/drivers/iio/pressure/mprls0025pa.c
@@ -12,6 +12,7 @@
#include <linux/array_size.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/errno.h>
#include <linux/math64.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
@@ -195,9 +196,10 @@ static void mpr_reset(struct mpr_data *data)
* waits for a maximum of one second for the interrupt.
*
* Return:
- * * 0 - OK, the pressure value could be read
- * * -ETIMEDOUT - Timeout while waiting for the EOC interrupt or busy flag is
- * still set after nloops attempts of reading
+ * * 0 - OK, the pressure value could be read
+ * * -EBUSY - Sensor does not have a new conversion ready
+ * * -ETIMEDOUT - Timeout while waiting for the EOC interrupt
+ * * -EIO - Invalid status byte received from sensor
*/
static int mpr_read_pressure(struct mpr_data *data, s32 *press)
{
@@ -250,10 +252,25 @@ static int mpr_read_pressure(struct mpr_data *data, s32 *press)
if (ret < 0)
return ret;
- if (data->rx_buf[0] & MPR_ST_ERR_FLAG) {
+ /*
+ * Status byte flags
+ * bit7 SANITY_CHK - must always be 0
+ * bit6 MPR_ST_POWER - 1 if device is powered
+ * bit5 MPR_ST_BUSY - 1 if device has no new conversion ready
+ * bit4 SANITY_CHK - must always be 0
+ * bit3 SANITY_CHK - must always be 0
+ * bit2 MEMORY_ERR - 1 if integrity test has failed
+ * bit1 SANITY_CHK - must always be 0
+ * bit0 MATH_ERR - 1 during internal math saturation error
+ */
+
+ if (data->rx_buf[0] == (MPR_ST_POWER | MPR_ST_BUSY))
+ return -EBUSY;
+
+ if (data->rx_buf[0] != MPR_ST_POWER) {
dev_err(data->dev,
- "unexpected status byte %02x\n", data->rx_buf[0]);
- return -ETIMEDOUT;
+ "unexpected status byte 0x%02x\n", data->rx_buf[0]);
+ return -EIO;
}
*press = get_unaligned_be24(&data->rx_buf[1]);
--
2.51.2
Powered by blists - more mailing lists