Skip to contentSkip to conversation

iio: imu: inv_icm42600: add support of accel low-power mode

PATCH Superseded [email protected] 4 participants 6 messages May 7, 2024 – May 25, 2024

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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
index c4ac91f6bafe..83219088e697 100644
@@ -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
index 96116a68ab29..50380f2a5ebb 100644
@@ -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);
 }
 

--
2.34.1

#1 lore raw
Quoted 7 lines · On Tue, 7 May 2024 10:30:56 +0000 [email protected] wrote:

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.

Hi Jean-Baptiste

No Sign-off?

We have never provided this sort of control because it's near impossible for user space to know what to do with it.

Various attempts happened in the past to provide enough info to userspace, but didn't succeed because what low power means is incredibly chip dependent. As a general rule everyone wants low power, but at 0 perf cost :)

What are the results of low power mode? Normally it maps as something we can enable when some other set of states is set or automatically control based on how often the device is being accessed etc.

For example, what do we loose by choosing this mode for everything below 200Hz?

I see there is some reference to 'low noise' - what does that actually mean for this device? Is it oversampling or running lower resolution on the ADCs? If so those are the things to look at as ways to control this. Choose lowest power to meet a given set of requirements.

Jonathan

#2 lore raw

Hello Jonathan,

sorry for the patch malformation, I will send a V2 fixed.

Our chips have usually 2 working modes called "low-noise" and "low-power".

"Low-noise" is the standard mode where the chip (ADC/MEMS) runs continuously with high precision oscillator. Measures are the best with the less jitter (low noise), you can use the highest possible frequencies (> 500Hz), but power consumption is high, and you cannot use the lowest frequencies (< 12.5Hz).

"Low-power" is duty cycling the chip, turning ADC and MEMS on only when measuring and then turns it off. Power consumption is then much lower (low power), you can use the lowest frequencies (< 12.5Hz), but measures have more jitter, and you cannot use the highest frequencies.

Depending on the use case, you may prefer to have the "low-noise" mode with better measures and high frequencies, or the "low-power" mode with less power consumption and low frequencies. The main point is the frequencies availability depending on the power mode.

We could have the driver switching automatically from low-noise to low-power to support all possible frequencies, but we need to arbitrary choose the mode for the common frequencies, and the configured hardware bias in bias registers are not the same depending on the power mode. We prefer handling all this from userspace, switching the mode when needed depending on the use case and dealing with the 2 sets of hardware bias depending on the modes.

I hope I am clear enough with my description.

Thanks,
JB

________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Thursday, May 9, 2024 15:13
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]> Subject: Re: [PATCH] iio: imu: inv_icm42600: add support of accel low-power mode

This Message Is From an External Sender
This message came from outside your organization.

Quoted 7 lines · On Tue, 7 May 2024 10:30:56 +0000 [email protected] wrote:

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.

Hi Jean-Baptiste

No Sign-off?

We have never provided this sort of control because it's near impossible for user space to know what to do with it.

Various attempts happened in the past to provide enough info to userspace, but didn't succeed because what low power means is incredibly chip dependent. As a general rule everyone wants low power, but at 0 perf cost :)

What are the results of low power mode? Normally it maps as something we can enable when some other set of states is set or automatically control based on how often the device is being accessed etc.

For example, what do we loose by choosing this mode for everything below 200Hz?

I see there is some reference to 'low noise' - what does that actually mean for this device? Is it oversampling or running lower resolution on the ADCs? If so those are the things to look at as ways to control this. Choose lowest power to meet a given set of requirements.

Jonathan

maintainer
#3 lore raw
Quoted 8 lines · On Mon, 13 May 2024 09:18:34 +0000 Jean-Baptiste Maneyrol…

Hello Jonathan,

sorry for the patch malformation, I will send a V2 fixed.

Our chips have usually 2 working modes called "low-noise" and "low-power".

"Low-noise" is the standard mode where the chip (ADC/MEMS) runs continuously with high precision oscillator. Measures are the best with the less jitter (low noise), you can use the highest possible frequencies (> 500Hz), but power consumption is high, and you cannot use the lowest frequencies (< 12.5Hz).

Quoted 8 lines

"Low-power" is duty cycling the chip, turning ADC and MEMS on only when measuring and then turns it off. Power consumption is then much lower (low power), you can use the lowest frequencies (< 12.5Hz), but measures have more jitter, and you cannot use the highest frequencies.

Depending on the use case, you may prefer to have the "low-noise" mode with better measures and high frequencies, or the "low-power" mode with less power consumption and low frequencies. The main point is the frequencies availability depending on the power mode.

We could have the driver switching automatically from low-noise to low-power to support all possible frequencies, but we need to arbitrary choose the mode for the common frequencies, and the configured hardware bias in bias registers are not the same depending on the power mode. We prefer handling all this from userspace, switching the mode when needed depending on the use case and dealing with the 2 sets of hardware bias depending on the modes.

I hope I am clear enough with my description.

Whilst I understand the motivation, the problem with this is that most userspace software will have no idea what these controls do. It is very challenging to provide enough discoverability to userspace because these modes tend to have weird and wonderful side effects (e.g. the hardware bias here).

So I'd very strongly suggest at least a 'default' option to figure it out from the requested frequencies probably defaulting to low noise on the common frequencies
- "when in doubt give the best possible data".

With that in place, I'd be more likely to be persuaded of the need for a 'tweak' bit of custom ABI that overrides this automatic parameter setting. Thus things would work as well as possible for normal software, and advanced software, by which I mean your userspace stack, would have access to a way to bias the low power / low noise decision in the common frequencies.

The sticky bit here is that hardware bias. I'm assuming that is what we are controlling via calibbias? If so is there any sane way to relate the two sets of bias values?
Normally (I think) that stuff is about fixing variability in the analog signal part of the device, so I'd expect any change in value to be predictable unless there is something odd going on with digital filtering perhaps?

Finally I do wonder how often people use those mid frequencies where there is a direct choice. In broad terms the reason for low power is to do detection of background stuff - screen rotation etc in which case they'd also pick low frequency to save even more power. The low noise modes are for when the precise data matters a lot more and those tend to also need at least moderately high sampling rates because people are typically running some sensor fusion on top and accurate data but at low frequency is usually no good for that unless you know something is mechanically filtering the motion (i.e it's fine on measuring shaft rotation on something with lots of inertial, not so much human motion).

Jonathan

Quoted 50 lines

Thanks,
JB

________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Thursday, May 9, 2024 15:13
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]> Subject: Re: [PATCH] iio: imu: inv_icm42600: add support of accel low-power mode

This Message Is From an External Sender
This message came from outside your organization.

Quoted 7 lines · On Tue, 7 May 2024 10:30:56 +0000 [email protected] wrote:

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.

Hi Jean-Baptiste

No Sign-off?

We have never provided this sort of control because it's near impossible for user space to know what to do with it.

Various attempts happened in the past to provide enough info to userspace, but didn't succeed because what low power means is incredibly chip dependent. As a general rule everyone wants low power, but at 0 perf cost :)

What are the results of low power mode? Normally it maps as something we can enable when some other set of states is set or automatically control based on how often the device is being accessed etc.

For example, what do we loose by choosing this mode for everything below 200Hz?

I see there is some reference to 'low noise' - what does that actually mean for this device? Is it oversampling or running lower resolution on the ADCs? If so those are the things to look at as ways to control this. Choose lowest power to meet a given set of requirements.

Jonathan

#4 lore raw

Hello Jonathan,

the hardware bias changes (inside calibbias exactly) is due to the noise differences of the 2 modes, introducing a little change in offset (these comes from the MEMS mechanical parts). This change cannot be anticipated sadly.

Most of the time, the low power mode is used for accelerometer, since most used accelerometer features are motion monitoring in the background (pedometer, activity, ...). But high frequencies can be needed for very fast event like tap our double taps on the device.

We could default to low-power mode and switch to low-noise mode automatically only for the high frequencies where it is mandatory. And we could add a sysfs entry like low_noise_mode to enforce low-noise mode for lower frequencies supporting it.

This way traditional userspace can ignore the power_mode setup and use all frequencies. And only specialized userpsace components can set this low_noise_mode to have better noise values for specific use cases. For the hardware bias issue, the high frequency use cases are usually not impacted by the absolute offset, so it should not be a big issue.

Is that OK for you?

Thanks,
JB

________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Sunday, May 19, 2024 13:52
To: Jean-Baptiste Maneyrol <[email protected]>
Cc: Jonathan Cameron <[email protected]>; INV Git Commit <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> Subject: Re: [PATCH] iio: imu: inv_icm42600: add support of accel low-power mode

This Message Is From an External Sender
This message came from outside your organization.

Quoted 8 lines · On Mon, 13 May 2024 09:18:34 +0000 Jean-Baptiste Maneyrol…

Hello Jonathan,

sorry for the patch malformation, I will send a V2 fixed.

Our chips have usually 2 working modes called "low-noise" and "low-power".

"Low-noise" is the standard mode where the chip (ADC/MEMS) runs continuously with high precision oscillator. Measures are the best with the less jitter (low noise), you can use the highest possible frequencies (> 500Hz), but power consumption is high, and you cannot use the lowest frequencies (< 12.5Hz).

Quoted 8 lines

"Low-power" is duty cycling the chip, turning ADC and MEMS on only when measuring and then turns it off. Power consumption is then much lower (low power), you can use the lowest frequencies (< 12.5Hz), but measures have more jitter, and you cannot use the highest frequencies.

Depending on the use case, you may prefer to have the "low-noise" mode with better measures and high frequencies, or the "low-power" mode with less power consumption and low frequencies. The main point is the frequencies availability depending on the power mode.

We could have the driver switching automatically from low-noise to low-power to support all possible frequencies, but we need to arbitrary choose the mode for the common frequencies, and the configured hardware bias in bias registers are not the same depending on the power mode. We prefer handling all this from userspace, switching the mode when needed depending on the use case and dealing with the 2 sets of hardware bias depending on the modes.

I hope I am clear enough with my description.

Whilst I understand the motivation, the problem with this is that most userspace software will have no idea what these controls do. It is very challenging to provide enough discoverability to userspace because these modes tend to have weird and wonderful side effects (e.g. the hardware bias here).

So I'd very strongly suggest at least a 'default' option to figure it out from the requested frequencies probably defaulting to low noise on the common frequencies
- "when in doubt give the best possible data".

With that in place, I'd be more likely to be persuaded of the need for a 'tweak' bit of custom ABI that overrides this automatic parameter setting. Thus things would work as well as possible for normal software, and advanced software, by which I mean your userspace stack, would have access to a way to bias the low power / low noise decision in the common frequencies.

The sticky bit here is that hardware bias. I'm assuming that is what we are controlling via calibbias? If so is there any sane way to relate the two sets of bias values?
Normally (I think) that stuff is about fixing variability in the analog signal part of the device, so I'd expect any change in value to be predictable unless there is something odd going on with digital filtering perhaps?

Finally I do wonder how often people use those mid frequencies where there is a direct choice. In broad terms the reason for low power is to do detection of background stuff - screen rotation etc in which case they'd also pick low frequency to save even more power. The low noise modes are for when the precise data matters a lot more and those tend to also need at least moderately high sampling rates because people are typically running some sensor fusion on top and accurate data but at low frequency is usually no good for that unless you know something is mechanically filtering the motion (i.e it's fine on measuring shaft rotation on something with lots of inertial, not so much human motion).

Jonathan

Quoted 50 lines

Thanks,
JB

________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Thursday, May 9, 2024 15:13
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]> Subject: Re: [PATCH] iio: imu: inv_icm42600: add support of accel low-power mode

This Message Is From an External Sender
This message came from outside your organization.

Quoted 7 lines · On Tue, 7 May 2024 10:30:56 +0000 [email protected] wrote:

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.

Hi Jean-Baptiste

No Sign-off?

We have never provided this sort of control because it's near impossible for user space to know what to do with it.

Various attempts happened in the past to provide enough info to userspace, but didn't succeed because what low power means is incredibly chip dependent. As a general rule everyone wants low power, but at 0 perf cost :)

What are the results of low power mode? Normally it maps as something we can enable when some other set of states is set or automatically control based on how often the device is being accessed etc.

For example, what do we loose by choosing this mode for everything below 200Hz?

I see there is some reference to 'low noise' - what does that actually mean for this device? Is it oversampling or running lower resolution on the ADCs? If so those are the things to look at as ways to control this. Choose lowest power to meet a given set of requirements.

Jonathan

maintainer
#5 lore raw
Quoted 17 lines · On Wed, 22 May 2024 15:35:45 +0000 Jean-Baptiste Maneyrol…

Hello Jonathan,

the hardware bias changes (inside calibbias exactly) is due to the noise differences of the 2 modes, introducing a little change in offset (these comes from the MEMS mechanical parts). This change cannot be anticipated sadly.

Most of the time, the low power mode is used for accelerometer, since most used accelerometer features are motion monitoring in the background (pedometer, activity, ...). But high frequencies can be needed for very fast event like tap our double taps on the device.

We could default to low-power mode and switch to low-noise mode automatically only for the high frequencies where it is mandatory. And we could add a sysfs entry like low_noise_mode to enforce low-noise mode for lower frequencies supporting it.

Quoted 8 lines

This way traditional userspace can ignore the power_mode setup and use all frequencies. And only specialized userpsace components can set this low_noise_mode to have better noise values for specific use cases. For the hardware bias issue, the high frequency use cases are usually not impacted by the absolute offset, so it should not be a big issue.

Is that OK for you?

The part about defaulting to low power mode where possible on basis that's what is normally wanted makes sense.

A low_noise_mode switch for special users is a reasonable compromise I think, but let's see if we get other replies on this or on a patch implementing the above.

Jonathan

Quoted 146 lines

Thanks,
JB

________________________________________
From: Jonathan Cameron <[email protected]>
Sent: Sunday, May 19, 2024 13:52
To: Jean-Baptiste Maneyrol <[email protected]> Cc: Jonathan Cameron <[email protected]>; INV Git Commit <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> Subject: Re:
[PATCH] iio: imu: inv_icm42600: add support of accel low-power mode This Message Is From an External Sender This message came from outside your organization.

Quoted 32 lines · On Mon, 13 May 2024 09:18:34 +0000 Jean-Baptiste Maneyrol…

Hello Jonathan,

sorry for the patch malformation, I will send a V2 fixed.

Our chips have usually 2 working modes called "low-noise" and "low-power".

"Low-noise" is the standard mode where the chip (ADC/MEMS) runs continuously with high precision oscillator. Measures are the best with the less jitter (low noise), you can use the highest possible frequencies (> 500Hz), but power consumption is high, and you cannot use the lowest frequencies (< 12.5Hz).

"Low-power" is duty cycling the chip, turning ADC and MEMS on only when measuring and then turns it off. Power consumption is then much lower (low power), you can use the lowest frequencies (< 12.5Hz), but measures have more jitter, and you cannot use the highest frequencies.

Depending on the use case, you may prefer to have the "low-noise" mode with better measures and high frequencies, or the "low-power" mode with less power consumption and low frequencies. The main point is the frequencies availability depending on the power mode.

We could have the driver switching automatically from low-noise to low-power to support all possible frequencies, but we need to arbitrary choose the mode for the common frequencies, and the configured hardware bias in bias registers are not the same depending on the power mode. We prefer handling all this from userspace, switching the mode when needed depending on the use case and dealing with the 2 sets of hardware bias depending on the modes.

Quoted 2 lines

I hope I am clear enough with my description.

Whilst I understand the motivation, the problem with this is that most userspace software will have no idea what these controls do. It is very challenging to provide enough discoverability to userspace because these modes tend to have weird and wonderful side effects (e.g. the hardware bias here).

So I'd very strongly suggest at least a 'default' option to figure it out from the requested frequencies probably defaulting to low noise on the common frequencies
- "when in doubt give the best possible data".

With that in place, I'd be more likely to be persuaded of the need for a 'tweak' bit of custom ABI that overrides this automatic parameter setting. Thus things would work as well as possible for normal software, and advanced software, by which I mean your userspace stack, would have access to a way to bias the low power / low noise decision in the common frequencies.

The sticky bit here is that hardware bias. I'm assuming that is what we are controlling via calibbias? If so is there any sane way to relate the two sets of bias values?
Normally (I think) that stuff is about fixing variability in the analog signal part of the device, so I'd expect any change in value to be predictable unless there is something odd going on with digital filtering perhaps?

Finally I do wonder how often people use those mid frequencies where there is a direct choice. In broad terms the reason for low power is to do detection of background stuff - screen rotation etc in which case they'd also pick low frequency to save even more power. The low noise modes are for when the precise data matters a lot more and those tend to also need at least moderately high sampling rates because people are typically running some sensor fusion on top and accurate data but at low frequency is usually no good for that unless you know something is mechanically filtering the motion (i.e it's fine on measuring shaft rotation on something with lots of inertial, not so much human motion).

Jonathan

Quoted 53 lines

Thanks,
JB

________________________________________
From: Jonathan Cameron <[email protected]> Sent: Thursday, May 9, 2024 15:13
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]> Subject: Re: [PATCH] iio: imu:
inv_icm42600: add support of accel low-power mode This Message Is From an External Sender This message came from outside your organization. On Tue, 7 May 2024 10:30:56 +0000

Quoted 8 lines · [email protected] wrote:

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.

Hi Jean-Baptiste

No Sign-off?

We have never provided this sort of control because it's near impossible for user space to know what to do with it.

Various attempts happened in the past to provide enough info to userspace, but didn't succeed because what low power means is incredibly chip dependent. As a general rule everyone wants low power, but at 0 perf cost :)

What are the results of low power mode? Normally it maps as something we can enable when some other set of states is set or automatically control based on how often the device is being accessed etc.

For example, what do we loose by choosing this mode for everything below 200Hz?

I see there is some reference to 'low noise' - what does that actually mean for this device? Is it oversampling or running lower resolution on the ADCs? If so those are the things to look at as ways to control this. Choose lowest power to meet a given set of requirements.

Jonathan