* [PATCH 0/2] iio: imu: inv_icm42600: keep the temperature sensor always on
@ 2026-11-20 2:08 Joe LeVeque
2026-11-20 2:08 ` [PATCH 1/2] iio: imu: inv_icm42600: return -EBUSY for temperature reads when idle Joe LeVeque
2026-11-20 2:08 ` [PATCH 2/2] iio: imu: inv_icm42600: remove temperature sensor enable/disable Joe LeVeque
0 siblings, 2 replies; 3+ messages in thread
From: Joe LeVeque @ 2026-11-20 2:08 UTC (permalink / raw)
To: jean-baptiste.maneyrol, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joe LeVeque
On an ICM-42688-P, the gyro shows a large, stable offset at rest (about
8 to 23 dps) whenever the driver has the temperature sensor disabled
(PWR_MGMT0.TEMP_DIS): without it, gyro data is not temperature
compensated internally. As discussed with Jean-Baptiste and Jonathan,
this series keeps the temperature sensor always on and removes the
driver's temperature enable/disable handling; temperature reporting in
the FIFO stays switchable.
The chip only measures temperature while the accel or gyro is on; with
both off, its data register keeps the last measurement. Patch 1 makes a
temperature read return -EBUSY in that case instead of stale data, so
that patch 2 can remove the enable/disable handling without changing
what a direct temperature read reports.
Discussion:
https://lore.kernel.org/linux-iio/20261118232418.7fc702a8@jic23-hlaptop/T/#t
Tested on an ICM-42688-P (SPI) on an i.MX8M Plus board: on 6.18 with
these patches backported to the 6.18 driver (minor context adjustments,
built as an external module), and on 6.6 with the driver backported
from mainline:
- gyro correct from the first reads after boot and after runtime
suspend; accel unchanged
- idle temperature read returns -EBUSY; current values whenever accel or
gyro is on
- PWR_MGMT0.TEMP_DIS never set (regmap debugfs)
- buffered capture of gyro and accel, separately and concurrently
(including stopping one while the other runs), with and without the
temperature channel, and temperature-only: correct data at 50 Hz
- repeated buffer enable/disable; module reload
Build-tested on the IIO togreg branch.
I kept the INV_ICM42600_PWR_MGMT0_TEMP_DIS definition in inv_icm42600.h,
now unused, to document the register bit; happy to drop it if you
prefer.
Joe LeVeque (2):
iio: imu: inv_icm42600: return -EBUSY for temperature reads when idle
iio: imu: inv_icm42600: remove temperature sensor enable/disable
drivers/iio/imu/inv_icm42600/inv_icm42600.h | 6 ---
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 16 ++------
.../imu/inv_icm42600/inv_icm42600_buffer.c | 14 ++-----
.../iio/imu/inv_icm42600/inv_icm42600_core.c | 37 ++++---------------
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 16 ++------
.../iio/imu/inv_icm42600/inv_icm42600_temp.c | 10 ++++-
6 files changed, 26 insertions(+), 73 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] iio: imu: inv_icm42600: return -EBUSY for temperature reads when idle
2026-11-20 2:08 [PATCH 0/2] iio: imu: inv_icm42600: keep the temperature sensor always on Joe LeVeque
@ 2026-11-20 2:08 ` Joe LeVeque
2026-11-20 2:08 ` [PATCH 2/2] iio: imu: inv_icm42600: remove temperature sensor enable/disable Joe LeVeque
1 sibling, 0 replies; 3+ messages in thread
From: Joe LeVeque @ 2026-11-20 2:08 UTC (permalink / raw)
To: jean-baptiste.maneyrol, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joe LeVeque
The temperature sensor only measures while the accel or gyro is on.
With both off, its data register keeps the last measurement, so a
temperature read returns stale data. On an ICM-42688-P, a value held at
about 52 C was returned while the chip was at about 62 C. The data only
reads as invalid before the first measurement after power-up.
The temperature is the die temperature, used for accel and gyro
compensation, so return -EBUSY when both are off instead of stale data.
Suggested-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Signed-off-by: Joe LeVeque <joe.l@reflexrobotics.com>
---
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
index 7f80bda471c3..b35706bb1c8f 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
@@ -23,6 +23,16 @@ static int inv_icm42600_temp_read(struct inv_icm42600_state *st, s16 *temp)
pm_runtime_get_sync(dev);
mutex_lock(&st->lock);
+ /*
+ * The temperature sensor only measures while the accel or gyro is
+ * on; with both off, its data register holds a stale value.
+ */
+ if (st->conf.gyro.mode == INV_ICM42600_SENSOR_MODE_OFF &&
+ st->conf.accel.mode == INV_ICM42600_SENSOR_MODE_OFF) {
+ ret = -EBUSY;
+ goto exit;
+ }
+
ret = inv_icm42600_set_temp_conf(st, true, NULL);
if (ret)
goto exit;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] iio: imu: inv_icm42600: remove temperature sensor enable/disable
2026-11-20 2:08 [PATCH 0/2] iio: imu: inv_icm42600: keep the temperature sensor always on Joe LeVeque
2026-11-20 2:08 ` [PATCH 1/2] iio: imu: inv_icm42600: return -EBUSY for temperature reads when idle Joe LeVeque
@ 2026-11-20 2:08 ` Joe LeVeque
1 sibling, 0 replies; 3+ messages in thread
From: Joe LeVeque @ 2026-11-20 2:08 UTC (permalink / raw)
To: jean-baptiste.maneyrol, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Joe LeVeque
The driver turns the temperature sensor off (PWR_MGMT0.TEMP_DIS) whenever
nothing has requested temperature data. With the temperature sensor
disabled, gyro data is not temperature compensated internally. On an
ICM-42688-P this shows up as a large, stable gyro offset at rest: about
-139, 379 and -229 LSB at +-2000 dps (8 to 23 dps), instead of under
0.5 dps once the temperature sensor is enabled by a temperature read or
a buffer with the temperature channel.
There is no benefit in disabling the temperature sensor, so remove the
enable/disable handling and keep it always on: drop temp_en from the
sensor configuration and the suspend state, the temp argument and
TEMP_DIS handling from inv_icm42600_set_pwr_mgmt0(), the temperature
startup delay, and inv_icm42600_set_temp_conf() with its callers. The
temperature sensor now starts with the gyro or accel, whose startup
delays are longer.
Temperature reporting in the FIFO is still enabled and disabled with
the buffer's temperature channel.
Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 driver")
Suggested-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Signed-off-by: Joe LeVeque <joe.l@reflexrobotics.com>
---
drivers/iio/imu/inv_icm42600/inv_icm42600.h | 6 ---
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 16 ++------
.../imu/inv_icm42600/inv_icm42600_buffer.c | 14 ++-----
.../iio/imu/inv_icm42600/inv_icm42600_core.c | 37 ++++---------------
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 16 ++------
.../iio/imu/inv_icm42600/inv_icm42600_temp.c | 4 --
6 files changed, 18 insertions(+), 75 deletions(-)
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/inv_icm42600/inv_icm42600.h
index 3737e79dbcc1..e2b51f76198a 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h
@@ -128,13 +128,11 @@ struct inv_icm42600_sensor_conf {
struct inv_icm42600_conf {
struct inv_icm42600_sensor_conf gyro;
struct inv_icm42600_sensor_conf accel;
- bool temp_en;
};
struct inv_icm42600_suspended {
enum inv_icm42600_sensor_mode gyro;
enum inv_icm42600_sensor_mode accel;
- bool temp;
};
struct inv_icm42600_apex {
@@ -441,7 +439,6 @@ struct inv_icm42600_sensor_state {
#define INV_ICM42600_ACCEL_STARTUP_TIME_MS 20
#define INV_ICM42600_GYRO_STARTUP_TIME_MS 60
#define INV_ICM42600_GYRO_STOP_TIME_MS 150
-#define INV_ICM42600_TEMP_STARTUP_TIME_MS 14
#define INV_ICM42600_SUSPEND_DELAY_MS 2000
typedef int (*inv_icm42600_bus_setup)(struct inv_icm42600_state *);
@@ -464,9 +461,6 @@ int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
struct inv_icm42600_sensor_conf *conf,
unsigned int *sleep_ms);
-int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
- unsigned int *sleep_ms);
-
int inv_icm42600_enable_wom(struct inv_icm42600_state *st);
int inv_icm42600_disable_wom(struct inv_icm42600_state *st);
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
index cc8c074777c9..71ec968ab8fe 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
@@ -229,37 +229,29 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev,
struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev);
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
unsigned int fifo_en = 0;
- unsigned int sleep_temp = 0;
- unsigned int sleep_accel = 0;
- unsigned int sleep;
+ unsigned int sleep = 0;
int ret;
mutex_lock(&st->lock);
- if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
- /* enable temp sensor */
- ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
- if (ret)
- goto out_unlock;
+ if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP)
fifo_en |= INV_ICM42600_SENSOR_TEMP;
- }
if (*scan_mask & INV_ICM42600_SCAN_MASK_ACCEL_3AXIS) {
/* enable accel sensor */
conf.mode = accel_st->power_mode;
conf.filter = accel_st->filter;
- ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_accel);
+ ret = inv_icm42600_set_accel_conf(st, &conf, &sleep);
if (ret)
goto out_unlock;
fifo_en |= INV_ICM42600_SENSOR_ACCEL;
}
/*
- * Sleep maximum stabilization time before enabling data in FIFO.
+ * Sleep stabilization time before enabling data in FIFO.
* We need to release the driver lock to not block gyro data processing.
* There is no possible race here since we are under IIO mutex locked.
*/
- sleep = max(sleep_accel, sleep_temp);
if (sleep) {
mutex_unlock(&st->lock);
msleep(sleep);
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
index 7ecd7257921c..c946045c762f 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
@@ -366,9 +366,7 @@ static int inv_icm42600_buffer_postdisable(struct iio_dev *indio_dev)
unsigned int sensor;
unsigned int *watermark;
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
- unsigned int sleep_temp = 0;
- unsigned int sleep_sensor = 0;
- unsigned int sleep;
+ unsigned int sleep = 0;
int ret;
if (indio_dev == st->indio_gyro) {
@@ -398,21 +396,15 @@ static int inv_icm42600_buffer_postdisable(struct iio_dev *indio_dev)
conf.mode = INV_ICM42600_SENSOR_MODE_OFF;
if (sensor == INV_ICM42600_SENSOR_GYRO)
- ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_sensor);
+ ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep);
else if (!st->apex.on)
- ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_sensor);
+ ret = inv_icm42600_set_accel_conf(st, &conf, &sleep);
if (ret)
goto out_unlock;
- /* if FIFO is off, turn temperature off */
- if (!st->fifo.on)
- ret = inv_icm42600_set_temp_conf(st, false, &sleep_temp);
-
out_unlock:
mutex_unlock(&st->lock);
- /* sleep maximum required time */
- sleep = max(sleep_sensor, sleep_temp);
if (sleep)
msleep(sleep);
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
index ccaf8ec468f9..5fa6bd2bcea6 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
@@ -123,7 +123,6 @@ static const struct inv_icm42600_conf inv_icm42600_default_conf = {
.odr = INV_ICM42600_ODR_50HZ,
.filter = INV_ICM42600_FILTER_BW_ODR_DIV_2,
},
- .temp_en = false,
};
static const struct inv_icm42600_conf inv_icm42686_default_conf = {
@@ -139,7 +138,6 @@ static const struct inv_icm42600_conf inv_icm42686_default_conf = {
.odr = INV_ICM42600_ODR_50HZ,
.filter = INV_ICM42600_FILTER_BW_ODR_DIV_2,
},
- .temp_en = false,
};
static const struct inv_icm42600_hw inv_icm42600_hw[INV_CHIP_NB] = {
@@ -228,38 +226,29 @@ u32 inv_icm42600_odr_to_period(enum inv_icm42600_odr odr)
static int inv_icm42600_set_pwr_mgmt0(struct inv_icm42600_state *st,
enum inv_icm42600_sensor_mode gyro,
enum inv_icm42600_sensor_mode accel,
- bool temp, unsigned int *sleep_ms)
+ unsigned int *sleep_ms)
{
enum inv_icm42600_sensor_mode oldgyro = st->conf.gyro.mode;
enum inv_icm42600_sensor_mode oldaccel = st->conf.accel.mode;
- bool oldtemp = st->conf.temp_en;
unsigned int sleepval;
unsigned int val;
int ret;
/* if nothing changed, exit */
- if (gyro == oldgyro && accel == oldaccel && temp == oldtemp)
+ if (gyro == oldgyro && accel == oldaccel)
return 0;
val = INV_ICM42600_PWR_MGMT0_GYRO(gyro) |
INV_ICM42600_PWR_MGMT0_ACCEL(accel);
- if (!temp)
- val |= INV_ICM42600_PWR_MGMT0_TEMP_DIS;
ret = regmap_write(st->map, INV_ICM42600_REG_PWR_MGMT0, val);
if (ret)
return ret;
st->conf.gyro.mode = gyro;
st->conf.accel.mode = accel;
- st->conf.temp_en = temp;
/* compute required wait time for sensors to stabilize */
sleepval = 0;
- /* temperature stabilization time */
- if (temp && !oldtemp) {
- if (sleepval < INV_ICM42600_TEMP_STARTUP_TIME_MS)
- sleepval = INV_ICM42600_TEMP_STARTUP_TIME_MS;
- }
/* accel startup time */
if (accel != oldaccel && oldaccel == INV_ICM42600_SENSOR_MODE_OFF) {
/* block any register write for at least 200 µs */
@@ -357,7 +346,7 @@ int inv_icm42600_set_accel_conf(struct inv_icm42600_state *st,
/* set PWR_MGMT0 register (accel sensor mode) */
return inv_icm42600_set_pwr_mgmt0(st, st->conf.gyro.mode, conf->mode,
- st->conf.temp_en, sleep_ms);
+ sleep_ms);
}
int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
@@ -401,19 +390,11 @@ int inv_icm42600_set_gyro_conf(struct inv_icm42600_state *st,
/* set PWR_MGMT0 register (gyro sensor mode) */
return inv_icm42600_set_pwr_mgmt0(st, conf->mode, st->conf.accel.mode,
- st->conf.temp_en, sleep_ms);
+ sleep_ms);
return 0;
}
-int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable,
- unsigned int *sleep_ms)
-{
- return inv_icm42600_set_pwr_mgmt0(st, st->conf.gyro.mode,
- st->conf.accel.mode, enable,
- sleep_ms);
-}
-
int inv_icm42600_enable_wom(struct inv_icm42600_state *st)
{
int ret;
@@ -467,8 +448,6 @@ static int inv_icm42600_set_conf(struct inv_icm42600_state *st,
/* set PWR_MGMT0 register (gyro & accel sensor mode, temp enabled) */
val = INV_ICM42600_PWR_MGMT0_GYRO(conf->gyro.mode) |
INV_ICM42600_PWR_MGMT0_ACCEL(conf->accel.mode);
- if (!conf->temp_en)
- val |= INV_ICM42600_PWR_MGMT0_TEMP_DIS;
ret = regmap_write(st->map, INV_ICM42600_REG_PWR_MGMT0, val);
if (ret)
return ret;
@@ -841,7 +820,6 @@ static int inv_icm42600_suspend(struct device *dev)
st->suspended.gyro = st->conf.gyro.mode;
st->suspended.accel = st->conf.accel.mode;
- st->suspended.temp = st->conf.temp_en;
if (pm_runtime_suspended(dev))
return 0;
@@ -872,7 +850,7 @@ static int inv_icm42600_suspend(struct device *dev)
}
ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF,
- accel_conf, false, NULL);
+ accel_conf, NULL);
if (ret)
return ret;
@@ -917,7 +895,7 @@ static int inv_icm42600_resume(struct device *dev)
/* restore sensors state */
ret = inv_icm42600_set_pwr_mgmt0(st, st->suspended.gyro,
st->suspended.accel,
- st->suspended.temp, NULL);
+ NULL);
if (ret)
return ret;
@@ -949,8 +927,7 @@ static int inv_icm42600_runtime_suspend(struct device *dev)
/* disable all sensors */
ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF,
- INV_ICM42600_SENSOR_MODE_OFF, false,
- NULL);
+ INV_ICM42600_SENSOR_MODE_OFF, NULL);
if (ret)
return ret;
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
index 4e20d61d897b..eaa13013ba4b 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
@@ -102,36 +102,28 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev,
struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
unsigned int fifo_en = 0;
- unsigned int sleep_gyro = 0;
- unsigned int sleep_temp = 0;
- unsigned int sleep;
+ unsigned int sleep = 0;
int ret;
mutex_lock(&st->lock);
- if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
- /* enable temp sensor */
- ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
- if (ret)
- goto out_unlock;
+ if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP)
fifo_en |= INV_ICM42600_SENSOR_TEMP;
- }
if (*scan_mask & INV_ICM42600_SCAN_MASK_GYRO_3AXIS) {
/* enable gyro sensor */
conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
- ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_gyro);
+ ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep);
if (ret)
goto out_unlock;
fifo_en |= INV_ICM42600_SENSOR_GYRO;
}
/*
- * Sleep maximum stabilization time before enabling data in FIFO.
+ * Sleep stabilization time before enabling data in FIFO.
* We need to release the driver lock to not block accel data processing.
* There is no possible race here since we are under IIO mutex locked.
*/
- sleep = max(sleep_gyro, sleep_temp);
if (sleep) {
mutex_unlock(&st->lock);
msleep(sleep);
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
index b35706bb1c8f..d76459d048d7 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
@@ -33,10 +33,6 @@ static int inv_icm42600_temp_read(struct inv_icm42600_state *st, s16 *temp)
goto exit;
}
- ret = inv_icm42600_set_temp_conf(st, true, NULL);
- if (ret)
- goto exit;
-
raw = (__be16 *)&st->buffer[0];
ret = regmap_bulk_read(st->map, INV_ICM42600_REG_TEMP_DATA, raw, sizeof(*raw));
if (ret)
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 2:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 2:08 [PATCH 0/2] iio: imu: inv_icm42600: keep the temperature sensor always on Joe LeVeque
2026-11-20 2:08 ` [PATCH 1/2] iio: imu: inv_icm42600: return -EBUSY for temperature reads when idle Joe LeVeque
2026-11-20 2:08 ` [PATCH 2/2] iio: imu: inv_icm42600: remove temperature sensor enable/disable Joe LeVeque
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®