diff options
| author | Francesco Lavra <flavra@baylibre.com> | 2026-01-15 18:53:49 +0100 |
|---|---|---|
| committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2026-01-16 19:40:04 +0000 |
| commit | fabae7558722dcf41a9137f6f0f82462867d7c96 (patch) | |
| tree | 5e04ccef05e51d2aaa91a6d69f68e5a6c59fa48d /drivers/iio/accel | |
| parent | a99b000f92413f254a6dc0f6ab88b310152f9485 (diff) | |
iio: accel: adxl380: Introduce helper function for activity detection
Motion detection functionalities (such as activity and inactivity
detection) are only available when the chip is in a low-power mode; this
affects the available sampling frequency values.
In preparation for adding support for a new frequency value, introduce a
helper function that checks whether activity/inactivity detection is
currently enabled; this function will be reused in a future commit to
determine what frequency values are available at any given time.
No functional changes.
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/accel')
| -rw-r--r-- | drivers/iio/accel/adxl380.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c index 28caa88d7c32..021d19a44985 100644 --- a/drivers/iio/accel/adxl380.c +++ b/drivers/iio/accel/adxl380.c @@ -232,14 +232,35 @@ bool adxl380_readable_noinc_reg(struct device *dev, unsigned int reg) } EXPORT_SYMBOL_NS_GPL(adxl380_readable_noinc_reg, "IIO_ADXL380"); +static int adxl380_act_inact_enabled(struct adxl380_state *st, bool *enabled) +{ + unsigned int act_inact_ctl; + int ret; + + if (!st->chip_info->has_low_power) { + *enabled = false; + return 0; + } + + ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl); + if (ret) + return ret; + + *enabled = FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) || + FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl); + + return 0; +} + static int adxl380_set_measure_en(struct adxl380_state *st, bool en) { int ret; - unsigned int act_inact_ctl; u8 op_mode = ADXL380_OP_MODE_STANDBY; if (en) { - ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl); + bool act_inact_enabled; + + ret = adxl380_act_inact_enabled(st, &act_inact_enabled); if (ret) return ret; @@ -248,9 +269,7 @@ static int adxl380_set_measure_en(struct adxl380_state *st, bool en) * mode and for devices that support low power modes. Otherwise * go straight to measure mode (same bits as ADXL380_OP_MODE_HP). */ - if (st->chip_info->has_low_power && - (FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) || - FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl))) + if (act_inact_enabled) op_mode = ADXL380_OP_MODE_VLP; else op_mode = ADXL380_OP_MODE_HP; |
