iio: pressure: mprls0025pa improve driver error resilience
authorPetre Rodan <petre.rodan@subdimension.ro>
Fri, 29 Dec 2023 09:24:33 +0000 (11:24 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 23 Jan 2024 22:06:53 +0000 (22:06 +0000)
Improve driver error resilience by ignoring the measurement if any of
the 3 error flags gets set while interacting with the sensor.
Based on the datasheet, in table 14 on page 14, the status byte
contains:
    bit 5 busy flag - 1 if device is busy
    bit 2 memory integrity/error flag - 1 if integrity test failed
    bit 0 math saturation - 1 if internal math saturation has occurred

Co-developed-by: Andreas Klinger <ak@it-klinger.de>
Signed-off-by: Andreas Klinger <ak@it-klinger.de>
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Link: https://lore.kernel.org/r/20231229092445.30180-6-petre.rodan@subdimension.ro
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/mprls0025pa.c

index e3f0de020a40c964750f564fe1a0e25267f63f59..233cc1dc38ad5ab64d3d5838df03356f2d36c774 100644 (file)
@@ -39,6 +39,8 @@
 #define MPR_I2C_MEMORY BIT(2)  /* integrity test passed */
 #define MPR_I2C_MATH   BIT(0)  /* internal math saturation */
 
+#define MPR_I2C_ERR_FLAG  (MPR_I2C_BUSY | MPR_I2C_MEMORY | MPR_I2C_MATH)
+
 /*
  * support _RAW sysfs interface:
  *
@@ -213,7 +215,7 @@ static int mpr_read_pressure(struct mpr_data *data, s32 *press)
                                        status);
                                return status;
                        }
-                       if (!(status & MPR_I2C_BUSY))
+                       if (!(status & MPR_I2C_ERR_FLAG))
                                break;
                }
                if (i == nloops) {
@@ -233,7 +235,7 @@ static int mpr_read_pressure(struct mpr_data *data, s32 *press)
                return -EIO;
        }
 
-       if (buf[0] & MPR_I2C_BUSY) {
+       if (buf[0] & MPR_I2C_ERR_FLAG) {
                /*
                 * it should never be the case that status still indicates
                 * business