[PATCH v2 12/13] iio: pressure: mprls0025pa: change measurement sequence

Petre Rodan posted 13 patches 3 weeks, 6 days ago
There is a newer version of this series
[PATCH v2 12/13] iio: pressure: mprls0025pa: change measurement sequence
Posted by Petre Rodan 3 weeks, 6 days ago
This patch implements a measurement sequence that does not involve a
one byte read of the status byte before reading the conversion.

The sensor's conversions should be read either once the EoC interrupt
has triggered or 5ms after the 0xaa command. See Options 1 and 2
respectively in Tables 16 (page 15) and 18 (page 18) of the datasheet.
Note that Honeywell's example code also covered in the datasheet follows
Option 2 for both i2c and SPI.

The datasheet does not specify any of the retry parameters that are
currently implemented in the driver. A simple 5+ms sleep as specified in
Option 2 is enough for a valid measurement sequence.

The change also gets rid of the code duplication tied to the verification
of the status byte.

This change only affects users that do not define the EOC interrupt in
the device tree.

Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/micropressure-mpr-series/documents/sps-siot-mpr-series-datasheet-32332628-ciid-172626.pdf?download=false
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1 -> v2 rewrote commit message
---
 drivers/iio/pressure/mprls0025pa.c | 32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)

diff --git a/drivers/iio/pressure/mprls0025pa.c b/drivers/iio/pressure/mprls0025pa.c
index 078d1d719023..8218d931647b 100644
--- a/drivers/iio/pressure/mprls0025pa.c
+++ b/drivers/iio/pressure/mprls0025pa.c
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/property.h>
 #include <linux/string.h>
+#include <linux/time.h>
 #include <linux/units.h>
 
 #include <linux/gpio/consumer.h>
@@ -41,10 +42,6 @@
 /* bits in status byte */
 #define MPR_ST_POWER  BIT(6) /* device is powered */
 #define MPR_ST_BUSY   BIT(5) /* device is busy */
-#define MPR_ST_MEMORY BIT(2) /* integrity test passed */
-#define MPR_ST_MATH   BIT(0) /* internal math saturation */
-
-#define MPR_ST_ERR_FLAG  (MPR_ST_BUSY | MPR_ST_MEMORY | MPR_ST_MATH)
 
 /*
  * support _RAW sysfs interface:
@@ -206,8 +203,7 @@ static void mpr_reset(struct mpr_data *data)
 static int mpr_read_pressure(struct mpr_data *data, s32 *press)
 {
 	struct device *dev = data->dev;
-	int ret, i;
-	int nloops = 10;
+	int ret;
 
 	reinit_completion(&data->completion);
 
@@ -224,29 +220,7 @@ static int mpr_read_pressure(struct mpr_data *data, s32 *press)
 			return -ETIMEDOUT;
 		}
 	} else {
-		/* wait until status indicates data is ready */
-		for (i = 0; i < nloops; i++) {
-			/*
-			 * datasheet only says to wait at least 5 ms for the
-			 * data but leave the maximum response time open
-			 * --> let's try it nloops (10) times which seems to be
-			 *     quite long
-			 */
-			usleep_range(5000, 10000);
-			ret = data->ops->read(data, MPR_CMD_NOP, 1);
-			if (ret < 0) {
-				dev_err(dev,
-					"error while reading, status: %d\n",
-					ret);
-				return ret;
-			}
-			if (!(data->rx_buf[0] & MPR_ST_ERR_FLAG))
-				break;
-		}
-		if (i == nloops) {
-			dev_err(dev, "timeout while reading\n");
-			return -ETIMEDOUT;
-		}
+		fsleep(5 * USEC_PER_MSEC);
 	}
 
 	memset(data->rx_buf, 0, sizeof(data->rx_buf));

-- 
2.52.0
Re: [PATCH v2 12/13] iio: pressure: mprls0025pa: change measurement sequence
Posted by Andy Shevchenko 3 weeks, 6 days ago
On Wed, Jan 14, 2026 at 12:05:46PM +0200, Petre Rodan wrote:
> This patch implements a measurement sequence that does not involve a

s/This patch implements/Implement/

This is described in the kernel Documentation (imperative mode).

> one byte read of the status byte before reading the conversion.
> 
> The sensor's conversions should be read either once the EoC interrupt
> has triggered or 5ms after the 0xaa command. See Options 1 and 2
> respectively in Tables 16 (page 15) and 18 (page 18) of the datasheet.
> Note that Honeywell's example code also covered in the datasheet follows
> Option 2 for both i2c and SPI.
> 
> The datasheet does not specify any of the retry parameters that are
> currently implemented in the driver. A simple 5+ms sleep as specified in
> Option 2 is enough for a valid measurement sequence.
> 
> The change also gets rid of the code duplication tied to the verification
> of the status byte.
> 
> This change only affects users that do not define the EOC interrupt in
> the device tree.

-- 
With Best Regards,
Andy Shevchenko