Re: [PATCH v4 04/11] iio: accel: adxl313: add function to enable measurement
From: Jonathan Cameron
Date: Sun Jun 08 2025 - 11:27:56 EST
On Sun, 1 Jun 2025 17:21:32 +0000
Lothar Rubusch <l.rubusch@xxxxxxxxx> wrote:
> Rework controlling measurement and standby of the sensor. Therefore,
> replace writing the register directly by encapsulating this and dealing
> with the return value in a separte function to enable and disable
> measurement. This will help to avoid redundant code in all locations
> where the sensor configuration needs to be adjusted, thus measurement will
> be set to standby, in follow up patches.
>
> Further, reduce the control mask to only the measurement bit. The sleep bit
> actually controls a different behavior (not just putting the sensor to
> standby for configuration, but turning it into sleep mode) and it is not
> used so far. In consequence, there is no need to cover sleep bit and
> measurement with the same mask.
>
> Signed-off-by: Lothar Rubusch <l.rubusch@xxxxxxxxx>
This is a good bit to have as a precursor patch (as you have done)
because it is refactoring the existing code. It doesn't stand on it's
own though given for now there is only one caller, so I won't pick it up
until the patch that uses it is ready to go.
Jonathan
> ---
> drivers/iio/accel/adxl313.h | 3 +--
> drivers/iio/accel/adxl313_core.c | 10 +++++++---
> 2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl313.h b/drivers/iio/accel/adxl313.h
> index fc937bdf83b6..9bf2facdbf87 100644
> --- a/drivers/iio/accel/adxl313.h
> +++ b/drivers/iio/accel/adxl313.h
> @@ -36,8 +36,7 @@
> #define ADXL313_RATE_MSK GENMASK(3, 0)
> #define ADXL313_RATE_BASE 6
>
> -#define ADXL313_POWER_CTL_MSK GENMASK(3, 2)
> -#define ADXL313_MEASUREMENT_MODE BIT(3)
> +#define ADXL313_POWER_CTL_MSK BIT(3)
>
> #define ADXL313_RANGE_MSK GENMASK(1, 0)
> #define ADXL313_RANGE_MAX 3
> diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
> index 0c893c286017..6170c9daa30f 100644
> --- a/drivers/iio/accel/adxl313_core.c
> +++ b/drivers/iio/accel/adxl313_core.c
> @@ -63,6 +63,12 @@ bool adxl313_is_volatile_reg(struct device *dev, unsigned int reg)
> }
> EXPORT_SYMBOL_NS_GPL(adxl313_is_volatile_reg, "IIO_ADXL313");
>
> +static int adxl313_set_measure_en(struct adxl313_data *data, bool en)
> +{
> + return regmap_assign_bits(data->regmap, ADXL313_REG_POWER_CTL,
> + ADXL313_POWER_CTL_MSK, en);
> +}
> +
> static int adxl312_check_id(struct device *dev,
> struct adxl313_data *data)
> {
> @@ -410,9 +416,7 @@ static int adxl313_setup(struct device *dev, struct adxl313_data *data,
> }
>
> /* Enables measurement mode */
> - return regmap_update_bits(data->regmap, ADXL313_REG_POWER_CTL,
> - ADXL313_POWER_CTL_MSK,
> - ADXL313_MEASUREMENT_MODE);
> + return adxl313_set_measure_en(data, true);
> }
>
> /**