Configure the link bit to associate activity and inactivity sensing, allowing the sensor to reflect its internal power-saving state. Additionally, enable the auto-sleep bit to transition the sensor into auto-sleep mode during periods of inactivity, as outlined in the datasheet. Signed-off-by: Lothar Rubusch <l.rubusch@xxxxxxxxx> --- drivers/iio/accel/adxl313.h | 3 +++ drivers/iio/accel/adxl313_core.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 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 95f52c95682a..d8a263b2a6f6 100644 --- a/drivers/iio/accel/adxl313_core.c +++ b/drivers/iio/accel/adxl313_core.c @@ -396,6 +396,25 @@ static int adxl313_is_act_inact_en(struct adxl313_data *data, return adxl313_act_int_reg[type] & regval; } +static int adxl313_set_act_inact_linkbit(struct adxl313_data *data, bool en) +{ + int act_en, inact_en; + + 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; + + return regmap_assign_bits(data->regmap, ADXL313_REG_POWER_CTL, + (ADXL313_POWER_CTL_AUTO_SLEEP | ADXL313_POWER_CTL_LINK), + en); +} + static int adxl313_set_act_inact_en(struct adxl313_data *data, enum adxl313_activity_type type, bool cmd_en) @@ -426,6 +445,7 @@ static int adxl313_set_act_inact_en(struct adxl313_data *data, } } + /* Start modifying configuration registers */ ret = adxl313_set_measure_en(data, false); if (ret) return ret; @@ -452,6 +472,11 @@ static int adxl313_set_act_inact_en(struct adxl313_data *data, if (ret) return ret; + /* Set link-bit and auto-sleep only when ACT and INACT are enabled */ + ret = adxl313_set_act_inact_linkbit(data, cmd_en); + if (ret) + return ret; + return adxl313_set_measure_en(data, true); } -- 2.39.5