[PATCH] iio: accel: adxl367: do not update FIFO watermark on scan mode update

Cosmin Tanislav posted 1 patch 1 week, 2 days ago
drivers/iio/accel/adxl367.c | 46 ++++++++-----------------------------
1 file changed, 9 insertions(+), 37 deletions(-)
[PATCH] iio: accel: adxl367: do not update FIFO watermark on scan mode update
Posted by Cosmin Tanislav 1 week, 2 days ago
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>
---
 drivers/iio/accel/adxl367.c | 46 ++++++++-----------------------------
 1 file 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);
-- 
2.35.3
Re: [PATCH] iio: accel: adxl367: do not update FIFO watermark on scan mode update
Posted by Jonathan Cameron 1 day, 17 hours ago
On Sat, 14 May 2022 21:20:10 +0300
Cosmin Tanislav <demonsingur@gmail.com> wrote:

> 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>

Applied to the togreg branch of iio.git and pushed out as testing
for 0-day to have it's fun

Thanks,

Jonathan

> ---
>  drivers/iio/accel/adxl367.c | 46 ++++++++-----------------------------
>  1 file 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);