Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: accel: adxl313: implement power-save on inactivity

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.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
Link: https://patch.msgid.link/20250702230819.19353-7-l.rubusch@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Lothar Rubusch and committed by
Jonathan Cameron
554396d4 e3fc1cad

+25
+3
drivers/iio/accel/adxl313.h
··· 41 41 #define ADXL313_RATE_BASE 6 42 42 43 43 #define ADXL313_POWER_CTL_MSK BIT(3) 44 + #define ADXL313_POWER_CTL_INACT_MSK GENMASK(5, 4) 45 + #define ADXL313_POWER_CTL_LINK BIT(5) 46 + #define ADXL313_POWER_CTL_AUTO_SLEEP BIT(4) 44 47 45 48 #define ADXL313_RANGE_MSK GENMASK(1, 0) 46 49 #define ADXL313_RANGE_MAX 3
+22
drivers/iio/accel/adxl313_core.c
··· 396 396 return adxl313_act_int_reg[type] & regval; 397 397 } 398 398 399 + static int adxl313_set_act_inact_linkbit(struct adxl313_data *data, bool en) 400 + { 401 + int act_en, inact_en; 402 + 403 + act_en = adxl313_is_act_inact_en(data, ADXL313_ACTIVITY); 404 + if (act_en < 0) 405 + return act_en; 406 + 407 + inact_en = adxl313_is_act_inact_en(data, ADXL313_INACTIVITY); 408 + if (inact_en < 0) 409 + return inact_en; 410 + 411 + return regmap_assign_bits(data->regmap, ADXL313_REG_POWER_CTL, 412 + ADXL313_POWER_CTL_AUTO_SLEEP | ADXL313_POWER_CTL_LINK, 413 + en && act_en && inact_en); 414 + } 415 + 399 416 static int adxl313_set_act_inact_en(struct adxl313_data *data, 400 417 enum adxl313_activity_type type, 401 418 bool cmd_en) ··· 469 452 /* Enable the interrupt line, according to the command */ 470 453 ret = regmap_assign_bits(data->regmap, ADXL313_REG_INT_ENABLE, 471 454 adxl313_act_int_reg[type], cmd_en); 455 + if (ret) 456 + return ret; 457 + 458 + /* Set link-bit and auto-sleep only when ACT and INACT are enabled */ 459 + ret = adxl313_set_act_inact_linkbit(data, cmd_en); 472 460 if (ret) 473 461 return ret; 474 462