diff options
author | Miquel Raynal <miquel.raynal@bootlin.com> | 2021-09-21 14:54:04 +0300 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-10-19 10:27:33 +0300 |
commit | a0e831653ef93912c442a6d30dcb29fe94ecf050 (patch) | |
tree | 7cad5a9e8120978db0d0465243716cd9375deab8 /drivers | |
parent | c757fc070886a88ec2ad6bf016b26ec11bfcc5bb (diff) | |
download | linux-a0e831653ef93912c442a6d30dcb29fe94ecf050.tar.xz |
iio: adc: max1027: Introduce an end of conversion helper
For now this helper only waits for the maximum duration of a single
conversion.
In practice, a "temperature measurement" will take twice this
time because it will also carry another analog conversion but as here we
will only care about the temperature conversion which happens first, we
can still only wait for a single sample and get the right data.
This helper will soon be improved to properly handle the end of
conversion interrupt as well as a higher number of samples.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20210921115408.66711-13-miquel.raynal@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/iio/adc/max1027.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c index 1748b962581f..009203d8d8cf 100644 --- a/drivers/iio/adc/max1027.c +++ b/drivers/iio/adc/max1027.c @@ -60,6 +60,9 @@ #define MAX1027_NAVG_32 (0x03 << 2) #define MAX1027_AVG_EN BIT(4) +/* Device can achieve 300ksps so we assume a 3.33us conversion delay */ +#define MAX1027_CONVERSION_UDELAY 4 + enum max1027_id { max1027, max1029, @@ -272,6 +275,15 @@ struct max1027_state { u8 reg ____cacheline_aligned; }; +static int max1027_wait_eoc(struct iio_dev *indio_dev) +{ + unsigned int conversion_time = MAX1027_CONVERSION_UDELAY; + + usleep_range(conversion_time, conversion_time * 2); + + return 0; +} + /* Scan from chan 0 to the highest requested channel. Include temperature on demand. */ static int max1027_configure_chans_and_start(struct iio_dev *indio_dev) { @@ -331,9 +343,11 @@ static int max1027_read_single_value(struct iio_dev *indio_dev, /* * For an unknown reason, when we use the mode "10" (write * conversion register), the interrupt doesn't occur every time. - * So we just wait 1 ms. + * So we just wait the maximum conversion time and deliver the value. */ - mdelay(1); + ret = max1027_wait_eoc(indio_dev); + if (ret) + return ret; /* Read result */ ret = spi_read(st->spi, st->buffer, (chan->type == IIO_TEMP) ? 4 : 2); |