Re: [PATCH v4 09/11] iio: accel: adxl313: implement power-save on inactivity

From: Jonathan Cameron
Date: Sun Jun 08 2025 - 12:16:03 EST


On Sun, 1 Jun 2025 17:21:37 +0000
Lothar Rubusch <l.rubusch@xxxxxxxxx> wrote:

> Link activity and inactivity to indicate the internal power-saving state.
> Add auto-sleep to be linked to inactivity.
>
> Signed-off-by: Lothar Rubusch <l.rubusch@xxxxxxxxx>
> ---
> drivers/iio/accel/adxl313.h | 3 +++
> drivers/iio/accel/adxl313_core.c | 20 ++++++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/drivers/iio/accel/adxl313.h b/drivers/iio/accel/adxl313.h
> index d7e8cb44855b..75ef54b60f75 100644
> --- a/drivers/iio/accel/adxl313.h
> +++ b/drivers/iio/accel/adxl313.h
> @@ -41,6 +41,9 @@
> #define ADXL313_RATE_BASE 6
>
> #define ADXL313_POWER_CTL_MSK BIT(3)
> +#define ADXL313_POWER_CTL_INACT_MSK GENMASK(5, 4)
> +#define ADXL313_POWER_CTL_LINK BIT(5)
> +#define ADXL313_POWER_CTL_AUTO_SLEEP BIT(4)
>
> #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 c5767d56b0cb..1598562a38e2 100644
> --- a/drivers/iio/accel/adxl313_core.c
> +++ b/drivers/iio/accel/adxl313_core.c
> @@ -396,6 +396,7 @@ static int adxl313_set_act_inact_en(struct adxl313_data *data,
> unsigned int axis_ctrl;
> unsigned int threshold;
> unsigned int inact_time_s;
> + int act_en, inact_en;
> bool en;
> int ret;
>
> @@ -431,6 +432,25 @@ static int adxl313_set_act_inact_en(struct adxl313_data *data,
> if (ret)
> return ret;
>
> + /*
> + * Set sleep and link bit only when ACT and INACT are enabled.
> + */

Single line comment style preferred.

> + act_en = adxl313_is_act_inact_en(data, ADXL313_ACTIVITY);
> + if (act_en < 0)
> + return act_en;
> +
> + inact_en = adxl313_is_act_inact_en(data, ADXL313_INACTIVITY);
> + if (inact_en < 0)
> + return inact_en;
> +
> + en = en && act_en && inact_en;
> +
> + ret = regmap_assign_bits(data->regmap, ADXL313_REG_POWER_CTL,
> + (ADXL313_POWER_CTL_AUTO_SLEEP | ADXL313_POWER_CTL_LINK),
> + en);
> + if (ret)
> + return ret;
> +
> return adxl313_set_measure_en(data, true);
> }
>