iio: imu: inv_icm42600: add support of accel low-power mode
Subsystems (2)
PATCH v2 1/1 iio: imu: inv_icm42600: add support of accel low-power mode
From: Jean-Baptiste Maneyrol <[email protected]>
Add channel attributes "power_mode" and "power_mode_available" for setting accel power mode (low-noise or low-power).
Differents ODRs and filter are possible depending on the power mode. Thus make ODRs and filter dynamic and check values when applying.
Signed-off-by Jean-Baptiste Maneyrol <[email protected]>
--- drivers/iio/imu/inv_icm42600/inv_icm42600.h | 12 + .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 230 ++++++++++++++---- .../iio/imu/inv_icm42600/inv_icm42600_core.c | 33 +++ 3 files changed, 226 insertions(+), 49 deletions(-)
drivers/iio/imu/inv_icm42600/inv_icm42600.h +12 -0
@@ -177,11 +177,23 @@ struct inv_icm42600_state {* struct inv_icm42600_sensor_state - sensor state variables * @scales: table of scales. * @scales_len: length (nb of items) of the scales table. +* @odrs: table of odrs. +* @odrs_len: lenght (nb of items) of the odrs table. +* @odr_convs: conversion table of odrs from Hz to register value. +* @odr_convs_len: lenght (nb of items) of the odr_convs table. +* @running_mode: sensor running mode (low power or low noise). +* @filter: sensor filter. * @ts: timestamp module states. */ struct inv_icm42600_sensor_state {const int *scales;size_t scales_len; +const int *odrs; +size_t odrs_len; +const int *odr_convs; +size_t odr_convs_len; +enum inv_icm42600_sensor_mode running_mode; +enum inv_icm42600_filter filter;struct inv_sensors_timestamp ts; };
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +181 -49
311 lines not on this page · raw message
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +33 -0
@@ -235,6 +235,7 @@ int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st, unsigned int *sleep_ms) {struct inv_icm42600_sensor_conf *oldconf = &st->conf.accel; +int min_odr, max_odr;unsigned int val;int ret;
@@ -248,6 +249,28 @@ int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,if (conf->filter <0 ) conf->filter = oldconf->filter; +/* sanitize ODR setting against power mode */ +switch (conf->mode) { +case INV_ICM42600_SENSOR_MODE_LOW_NOISE : + min_odr =INV_ICM42600_ODR_8KHZ_LN ; + max_odr =INV_ICM42600_ODR_12_5HZ ; +if (conf->odr < min_odr) + conf->odr = min_odr; +else if (conf->odr > max_odr) + conf->odr = max_odr; +break ; +case INV_ICM42600_SENSOR_MODE_LOW_POWER : + min_odr =INV_ICM42600_ODR_200HZ ; + max_odr =INV_ICM42600_ODR_1_5625HZ_LP ; +if (conf->odr < min_odr) + conf->odr = min_odr; +else if (conf->odr > max_odr) + conf->odr = max_odr; +break ; +default : +break ; + } +/* set ACCEL_CONFIG0 register (accel fullscale & odr) */ if (conf->fs != oldconf->fs || conf->odr != oldconf->odr) { val = INV_ICM42600_ACCEL_CONFIG0_FS(conf->fs) |
@@ -441,6 +464,16 @@ static int inv_icm42600_setup(struct inv_icm42600_state *st,if (ret)return ret; +/* +* Use RC clock for accel low-power to fix glitches when switching +* gyro on/off while accel low-power is on. +*/ + ret =regmap_update_bits (st->map,INV_ICM42600_REG_INTF_CONFIG1 , +INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC , +INV_ICM42600_INTF_CONFIG1_ACCEL_LP_CLK_RC ); +if (ret) +return ret; +return inv_icm42600_set_conf (st, hw->conf); }
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerQuoted 1 line · On Fri, 17 May 2024 17:09:33 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Hi Jean-Baptiste,
I'm replying mostly so I don't forget the status of this series. Discussion carried on in the v1 posting thread and we have ended up with a different approach.
See
https://lore.kernel.org/linux-iio/20240525170711.30b32904@jic23-huawei/