Commit 0bd0bb1f authored by Cosmin Tanislav's avatar Cosmin Tanislav Committed by Jonathan Cameron

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: default avatarCosmin Tanislav <cosmin.tanislav@analog.com>
Link: https://lore.kernel.org/r/20220514182010.152784-1-cosmin.tanislav@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d04d46dd
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment