diff options
author | Gregor Boirie <gregor.boirie@parrot.com> | 2016-03-01 13:31:38 +0300 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-03-05 17:45:14 +0300 |
commit | 033691a9a12f684c68f443f3676806dd64011295 (patch) | |
tree | d35d94f3b5c6d90efd275b1d9d0248562c576347 /drivers/iio/pressure/ms5611_spi.c | |
parent | 7a948c5e05febd23ee8e61db95c3dc96737fe17f (diff) | |
download | linux-033691a9a12f684c68f443f3676806dd64011295.tar.xz |
iio:pressure:ms5611: oversampling rate support
Add support for setting and retrieving OverSampling Rate independently for
each of the temperature and pressure channels. This allows userspace to
fine tune hardware sampling process according to the following tradeoffs :
* the higher the OSR, the finer the resolution ;
* the higher the OSR, the lower the noise ;
BUT:
* the higher the OSR, the larger the drift ;
* the higher the OSR, the longer the response time, i.e. less samples per
unit of time.
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/pressure/ms5611_spi.c')
-rw-r--r-- | drivers/iio/pressure/ms5611_spi.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/iio/pressure/ms5611_spi.c b/drivers/iio/pressure/ms5611_spi.c index 7ec0c6498f93..7600483e8cb4 100644 --- a/drivers/iio/pressure/ms5611_spi.c +++ b/drivers/iio/pressure/ms5611_spi.c @@ -56,28 +56,29 @@ static int ms5611_spi_read_adc(struct device *dev, s32 *val) static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev, s32 *temp, s32 *pressure) { - u8 cmd; int ret; struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); + const struct ms5611_osr *osr = st->temp_osr; - cmd = MS5611_START_TEMP_CONV; - ret = spi_write_then_read(st->client, &cmd, 1, NULL, 0); + /* + * Warning: &osr->cmd MUST be aligned on a word boundary since used as + * 2nd argument (void*) of spi_write_then_read. + */ + ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0); if (ret < 0) return ret; - usleep_range(MS5611_CONV_TIME_MIN, MS5611_CONV_TIME_MAX); - + usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); ret = ms5611_spi_read_adc(dev, temp); if (ret < 0) return ret; - cmd = MS5611_START_PRESSURE_CONV; - ret = spi_write_then_read(st->client, &cmd, 1, NULL, 0); + osr = st->pressure_osr; + ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0); if (ret < 0) return ret; - usleep_range(MS5611_CONV_TIME_MIN, MS5611_CONV_TIME_MAX); - + usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL)); return ms5611_spi_read_adc(dev, pressure); } |