[PATCH V13 6/9] iio: imu: inv_icm42607: Add Temp Support in icm42607

Chris Morgan macromorgan at hotmail.com
Mon Jun 22 19:35:44 PDT 2026


On Sun, Jun 21, 2026 at 06:26:12PM +0100, Jonathan Cameron wrote:
> On Mon, 15 Jun 2026 12:25:49 -0500
> Chris Morgan <macroalpha82 at gmail.com> wrote:
> 
> > From: Chris Morgan <macromorgan at hotmail.com>
> > 
> > Add functions for reading temperature sensor data.
> > 
> > Signed-off-by: Chris Morgan <macromorgan at hotmail.com>
> Another sashiko reported thing. I'd definitely have missed
> this one and I think it is correct.
> 
> When I get caught up I'll post a thread to see if people
> feel we should generally just ask for Sashiko to reply on
> list.
> 
> Jonathan
> 
> > diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> > index 64f5d263de4f..644cd7f821b9 100644
> > --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> > +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> > @@ -162,6 +162,24 @@ static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
> >  	return 0;
> >  }
> >  
> > +int inv_icm42607_set_temp_conf(struct inv_icm42607_state *st, bool enable,
> > +			       unsigned int *sleep_ms)
> > +{
> > +	unsigned int val;
> > +	int ret;
> > +
> > +	val = FIELD_PREP(INV_ICM42607_TEMP_CONFIG0_FILTER_MASK,
> > +			 INV_ICM42607_FILTER_BW_34HZ);
> > +	ret = regmap_update_bits(st->map, INV_ICM42607_REG_TEMP_CONFIG0,
> > +				 INV_ICM42607_TEMP_CONFIG0_FILTER_MASK, val);
> > +	if (ret)
> > +		return ret;
> > +
> > +	return inv_icm42607_set_pwr_mgmt0(st, st->conf.gyro.mode,
> > +					  st->conf.accel.mode, enable,
> > +					  sleep_ms);
> > +}
> 
> > diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c
> > new file mode 100644
> > index 000000000000..9a60e1a478b0
> > --- /dev/null
> > +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c
> 
> > +static int inv_icm42607_temp_read(struct inv_icm42607_state *st, s16 *temp)
> > +{
> > +	struct device *dev = regmap_get_device(st->map);
> > +	u8 raw[2];
> > +	int ret;
> > +
> > +	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
> > +	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> > +	if (ret)
> > +		return ret;
> > +
> > +	guard(mutex)(&st->lock);
> > +
> > +	st->conf.temp_en = true;
> 
> Sashiko points out (seems right) that this sets the internal state
> before the power management routine expects it to be set.  So why
> is this here as opposed to just passing true into the
> function that follows?

I'm going to take setting of state out of the power management function
entirely, as well as killing off any "temp_en" since technically there
is nothing to enable on the temp sensor. I'll do a check when you try
to read the temp to see if any sensors are on and if none are then I
will power up the accel sensor (since it uses about 5x less power than
the gyro per the datasheet).

> 
> > +	ret = inv_icm42607_set_temp_conf(st, st->conf.temp_en, NULL);
> > +	st->conf.temp_en = false;
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = regmap_bulk_read(st->map, INV_ICM42607_REG_TEMP_DATA1,
> > +			       raw, sizeof(raw));
> > +	if (ret)
> > +		return ret;
> > +
> > +	*temp = get_unaligned_be16(raw);
> > +	if (*temp == INV_ICM42607_DATA_INVALID)
> > +		return -EINVAL;
> > +
> > +	return 0;
> > +}

Thank you,
Chris



More information about the Linux-rockchip mailing list