summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosmin Tanislav <demonsingur@gmail.com>2022-05-14 21:20:10 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2022-06-11 16:35:27 +0300
commit0bd0bb1fc1e4430dff6856b59ddd63c72780d9be (patch)
tree2ba4c300d2f462535f2a6aea251a830dd0a19dee
parentd04d46dd82ad10bdc3c9ce6a513e1fa1336719c4 (diff)
downloadlinux-0bd0bb1fc1e4430dff6856b59ddd63c72780d9be.tar.xz
iio: accel: adxl367: do not update FIFO watermark on scan mode update
Currently, the driver updates the FIFO watermark inside both update_scan_mode() and hwfifo_set_watermark(). Inside the IIO core, hwfifo_set_watermark() is called immediately after update_scan_mode(), making the first call to set_fifo_samples() redundant. Remove the first call to set_fifo_samples(), and merge the set_fifo_samples() function into the set_fifo_watermark() function. Also, since fifo_set_size is always set inside of update_scan_mode(), and it cannot be set to 0, remove the zero check from set_fifo_samples(). Signed-off-by: Cosmin Tanislav <cosmin.tanislav@analog.com> Link: https://lore.kernel.org/r/20220514182010.152784-1-cosmin.tanislav@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/iio/accel/adxl367.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c
index 0289ed8cf2c6..72a8c3fb27b9 100644
--- a/drivers/iio/accel/adxl367.c
+++ b/drivers/iio/accel/adxl367.c
@@ -447,21 +447,17 @@ static int adxl367_set_fifo_format(struct adxl367_state *st,
fifo_format));
}
-static int adxl367_set_fifo_samples(struct adxl367_state *st,
- unsigned int fifo_watermark,
- unsigned int fifo_set_size)
+static int adxl367_set_fifo_watermark(struct adxl367_state *st,
+ unsigned int fifo_watermark)
{
- unsigned int fifo_samples = fifo_watermark * fifo_set_size;
+ unsigned int fifo_samples = fifo_watermark * st->fifo_set_size;
unsigned int fifo_samples_h, fifo_samples_l;
int ret;
if (fifo_samples > ADXL367_FIFO_MAX_WATERMARK)
fifo_samples = ADXL367_FIFO_MAX_WATERMARK;
- if (fifo_set_size == 0)
- return 0;
-
- fifo_samples /= fifo_set_size;
+ fifo_samples /= st->fifo_set_size;
fifo_samples_h = FIELD_PREP(ADXL367_SAMPLES_H_MASK,
FIELD_GET(ADXL367_SAMPLES_VAL_H_MASK,
@@ -475,30 +471,8 @@ static int adxl367_set_fifo_samples(struct adxl367_state *st,
if (ret)
return ret;
- return regmap_update_bits(st->regmap, ADXL367_REG_FIFO_SAMPLES,
- ADXL367_SAMPLES_L_MASK, fifo_samples_l);
-}
-
-static int adxl367_set_fifo_set_size(struct adxl367_state *st,
- unsigned int fifo_set_size)
-{
- int ret;
-
- ret = adxl367_set_fifo_samples(st, st->fifo_watermark, fifo_set_size);
- if (ret)
- return ret;
-
- st->fifo_set_size = fifo_set_size;
-
- return 0;
-}
-
-static int adxl367_set_fifo_watermark(struct adxl367_state *st,
- unsigned int fifo_watermark)
-{
- int ret;
-
- ret = adxl367_set_fifo_samples(st, fifo_watermark, st->fifo_set_size);
+ ret = regmap_update_bits(st->regmap, ADXL367_REG_FIFO_SAMPLES,
+ ADXL367_SAMPLES_L_MASK, fifo_samples_l);
if (ret)
return ret;
@@ -1276,14 +1250,11 @@ static int adxl367_update_scan_mode(struct iio_dev *indio_dev,
{
struct adxl367_state *st = iio_priv(indio_dev);
enum adxl367_fifo_format fifo_format;
- unsigned int fifo_set_size;
int ret;
if (!adxl367_find_mask_fifo_format(active_scan_mask, &fifo_format))
return -EINVAL;
- fifo_set_size = bitmap_weight(active_scan_mask, indio_dev->masklength);
-
mutex_lock(&st->lock);
ret = adxl367_set_measure_en(st, false);
@@ -1294,11 +1265,12 @@ static int adxl367_update_scan_mode(struct iio_dev *indio_dev,
if (ret)
goto out;
- ret = adxl367_set_fifo_set_size(st, fifo_set_size);
+ ret = adxl367_set_measure_en(st, true);
if (ret)
goto out;
- ret = adxl367_set_measure_en(st, true);
+ st->fifo_set_size = bitmap_weight(active_scan_mask,
+ indio_dev->masklength);
out:
mutex_unlock(&st->lock);