summaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/ti-ads1015.c
diff options
context:
space:
mode:
authorLadislav Michl <ladis@linux-mips.org>2017-08-24 10:25:51 +0200
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2017-09-03 18:10:31 +0100
commitd1c11dc27e3282e787406290ead5926bb7bb4579 (patch)
tree8d4f290d15b6a870d300a1da0d4402238225c497 /drivers/iio/adc/ti-ads1015.c
parent4e57562b4846e42cd1c2e556f0ece18c1154e116 (diff)
downloadtalos-obmc-linux-d1c11dc27e3282e787406290ead5926bb7bb4579.tar.gz
talos-obmc-linux-d1c11dc27e3282e787406290ead5926bb7bb4579.zip
iio: adc: ti-ads1015: write config register only on change
There is no point writing ADS1015_CFG_REG when configuration didn't change. Avoid that. Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc/ti-ads1015.c')
-rw-r--r--drivers/iio/adc/ti-ads1015.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 731ec38276ea..7503ea56b781 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -332,7 +332,7 @@ static int ads1015_set_power_state(struct ads1015_data *data, bool on)
static
int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
{
- int ret, pga, dr, conv_time;
+ int ret, pga, dr, dr_old, conv_time;
unsigned int old, mask, cfg;
if (chan < 0 || chan >= ADS1015_CHANNELS)
@@ -358,15 +358,14 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
}
cfg = (old & ~mask) | (cfg & mask);
-
- ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
- if (ret)
- return ret;
-
- if (old != cfg || data->conv_invalid) {
- int dr_old = (old & ADS1015_CFG_DR_MASK) >>
- ADS1015_CFG_DR_SHIFT;
-
+ if (old != cfg) {
+ ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg);
+ if (ret)
+ return ret;
+ data->conv_invalid = true;
+ }
+ if (data->conv_invalid) {
+ dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]);
conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]);
usleep_range(conv_time, conv_time + 1);
OpenPOWER on IntegriCloud