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

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Francesco Lavra and committed by
Jonathan Cameron
fabae755 a99b000f

+24 -5
+24 -5
drivers/iio/accel/adxl380.c
··· 232 232 } 233 233 EXPORT_SYMBOL_NS_GPL(adxl380_readable_noinc_reg, "IIO_ADXL380"); 234 234 235 + static int adxl380_act_inact_enabled(struct adxl380_state *st, bool *enabled) 236 + { 237 + unsigned int act_inact_ctl; 238 + int ret; 239 + 240 + if (!st->chip_info->has_low_power) { 241 + *enabled = false; 242 + return 0; 243 + } 244 + 245 + ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl); 246 + if (ret) 247 + return ret; 248 + 249 + *enabled = FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) || 250 + FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl); 251 + 252 + return 0; 253 + } 254 + 235 255 static int adxl380_set_measure_en(struct adxl380_state *st, bool en) 236 256 { 237 257 int ret; 238 - unsigned int act_inact_ctl; 239 258 u8 op_mode = ADXL380_OP_MODE_STANDBY; 240 259 241 260 if (en) { 242 - ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl); 261 + bool act_inact_enabled; 262 + 263 + ret = adxl380_act_inact_enabled(st, &act_inact_enabled); 243 264 if (ret) 244 265 return ret; 245 266 ··· 269 248 * mode and for devices that support low power modes. Otherwise 270 249 * go straight to measure mode (same bits as ADXL380_OP_MODE_HP). 271 250 */ 272 - if (st->chip_info->has_low_power && 273 - (FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) || 274 - FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl))) 251 + if (act_inact_enabled) 275 252 op_mode = ADXL380_OP_MODE_VLP; 276 253 else 277 254 op_mode = ADXL380_OP_MODE_HP;