Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: mprls0025pa: change measurement sequence

Implement 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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Petre Rodan and committed by
Jonathan Cameron
500b36ee 84e15e1a

+3 -29
+3 -29
drivers/iio/pressure/mprls0025pa.c
··· 23 23 #include <linux/module.h> 24 24 #include <linux/property.h> 25 25 #include <linux/string.h> 26 + #include <linux/time.h> 26 27 #include <linux/units.h> 27 28 28 29 #include <linux/gpio/consumer.h> ··· 42 41 /* bits in status byte */ 43 42 #define MPR_ST_POWER BIT(6) /* device is powered */ 44 43 #define MPR_ST_BUSY BIT(5) /* device is busy */ 45 - #define MPR_ST_MEMORY BIT(2) /* integrity test passed */ 46 - #define MPR_ST_MATH BIT(0) /* internal math saturation */ 47 - 48 - #define MPR_ST_ERR_FLAG (MPR_ST_BUSY | MPR_ST_MEMORY | MPR_ST_MATH) 49 44 50 45 /* 51 46 * support _RAW sysfs interface: ··· 203 206 static int mpr_read_pressure(struct mpr_data *data, s32 *press) 204 207 { 205 208 struct device *dev = data->dev; 206 - int ret, i; 207 - int nloops = 10; 209 + int ret; 208 210 209 211 reinit_completion(&data->completion); 210 212 ··· 220 224 return -ETIMEDOUT; 221 225 } 222 226 } else { 223 - /* wait until status indicates data is ready */ 224 - for (i = 0; i < nloops; i++) { 225 - /* 226 - * datasheet only says to wait at least 5 ms for the 227 - * data but leave the maximum response time open 228 - * --> let's try it nloops (10) times which seems to be 229 - * quite long 230 - */ 231 - usleep_range(5000, 10000); 232 - ret = data->ops->read(data, MPR_CMD_NOP, 1); 233 - if (ret < 0) { 234 - dev_err(dev, 235 - "error while reading, status: %d\n", 236 - ret); 237 - return ret; 238 - } 239 - if (!(data->rx_buf[0] & MPR_ST_ERR_FLAG)) 240 - break; 241 - } 242 - if (i == nloops) { 243 - dev_err(dev, "timeout while reading\n"); 244 - return -ETIMEDOUT; 245 - } 227 + fsleep(5 * USEC_PER_MSEC); 246 228 } 247 229 248 230 memset(data->rx_buf, 0, sizeof(data->rx_buf));