Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>
Cc: Sean Nyekjaer <sean@geanix.com>,
	Jonathan Cameron <jic23@kernel.org>,
	David Lechner <dlechner@baylibre.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	Andy Shevchenko <andy@kernel.org>
Subject: Re: [BUG] iio: imu: inv_icm42600: read temperature, Invalid Argument
Date: Tue, 8 Jul 2025 11:35:08 +0100	[thread overview]
Message-ID: <20250708113508.000027fb@huawei.com> (raw)
In-Reply-To: <FR3P281MB1757FE243D78E8F78DA6C576CE4FA@FR3P281MB1757.DEUP281.PROD.OUTLOOK.COM>

On Mon, 7 Jul 2025 18:13:33 +0000
Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com> wrote:

> >Hi,
> >
> >I'm having some weird issues with reading the temperature of the icm42605.
> >Kernel version: 6.16.0-rc5
> >
> ># cat /sys/bus/iio/devices/iio:device2/name
> >icm42605-accel
> >
> >When reading the temperature I get:
> ># cat /sys/bus/iio/devices/iio:device2/in_temp_raw
> >cat: read error: Invalid argument
> >
> >But if I read from the accelerometer first, I will go better:
> ># cat /sys/bus/iio/devices/iio:device2/in_accel_x_raw
> >-378
> ># cat /sys/bus/iio/devices/iio:device2/in_temp_raw
> >600
> >
> >Then after "some" time, I re-read the temperature I recieve
> >"Invalid argument" again.
> >
> >I have traced the -EINVAL to inv_icm42600_temp_read() because I receive
> >INV_ICM42600_DATA_INVALID.
> >
> >Register dump diff:
> >--- invalid-read
> >+++ ok-read
> >@@ -10,14 +10,14 @@
> > 0x1a = 0x00000010
> > 0x1b = 0x00000000
> > 0x1c = 0x00000000
> >-0x1d = 0x00000080
> >-0x1e = 0x00000000
> >-0x1f = 0x00000080
> >-0x20 = 0x00000000
> >-0x21 = 0x00000080
> >-0x22 = 0x00000000
> >-0x23 = 0x00000080
> >-0x24 = 0x00000000
> >+0x1d = 0x00000002
> >+0x1e = 0x00000038
> >+0x1f = 0x000000fe
> >+0x20 = 0x00000085
> >+0x21 = 0x000000fe
> >+0x22 = 0x000000df
> >+0x23 = 0x000000f8
> >+0x24 = 0x0000003a
> > 0x25 = 0x00000080
> > 0x26 = 0x00000000
> > 0x27 = 0x00000080
> >@@ -26,7 +26,7 @@
> > 0x2a = 0x00000000
> > 0x2b = 0x00000000
> > 0x2c = 0x00000000
> >-0x2d = 0x00000000
> >+0x2d = 0x00000008
> > 0x2e = 0x00000000
> > 0x2f = 0x00000000
> > 0x30 = 0x000000ff
> >@@ -59,11 +59,11 @@
> > 0x4b = 0x00000000
> > 0x4c = 0x00000032
> > 0x4d = 0x00000099
> >-0x4e = 0x00000000
> >+0x4e = 0x00000002
> > 0x4f = 0x00000009
> > 0x50 = 0x00000009
> > 0x51 = 0x00000016
> >-0x52 = 0x00000000
> >+0x52 = 0x00000060
> > 0x53 = 0x0000000d
> > 0x54 = 0x00000031
> > 0x55 = 0x00000000
> >
> >Will the iio core retry a read? If the -EINVAL is returned,
> >inv_icm42600_accel_read_raw() is call once more.
> >
> >One more thing...
> >When I'm removing the module, the kernel prints this:
> >inv-icm42600-i2c 1-0068: Runtime PM usage count underflow!
> >
> >I will continue investigate this
> >Br,
> >Sean  
> 
> Hello Sean,
> 
> this is expected behavior since the temperature returned is not the external
> temperature but the temperature of the mechanical component (MEMS). It will
> only work if the chip is on, meaning accelerometer and/or gyroscope is on.
> 
> That's why you can get temperature after reading accel data since it is
> turning the chip. But after a short while autosuspend is putting the chip
> back off and you cannot read temperature anymore.
> 
> You need to turn one sensor continuously on with a buffer, and then you can
> read temperature all the time since the chip is running.
> 
> Temperature data are here only to do temperature compensation of the accel
> and gyro data.

That is rather non-intuitive behavior.  Could we make a read of the temperature
channel turn on one of the components?  Given expected use case it shouldn't commonly
happen but if not too horrendous to implement it would be better to avoid the error
seen here.
 
> 
> Thanks,
> JB


  reply	other threads:[~2025-07-08 10:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 14:42 [BUG] iio: imu: inv_icm42600: read temperature, Invalid Argument Sean Nyekjaer
2025-07-07 15:15 ` David Lechner
2025-07-07 18:13 ` Jean-Baptiste Maneyrol
2025-07-08 10:35   ` Jonathan Cameron [this message]
2025-07-08 12:21     ` Jean-Baptiste Maneyrol
2025-07-13 13:46       ` Jonathan Cameron
2025-07-14  5:29         ` Sean Nyekjaer
2025-07-27 16:53           ` Jonathan Cameron
2025-08-08  7:28             ` Jean-Baptiste Maneyrol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250708113508.000027fb@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=Jean-Baptiste.Maneyrol@tdk.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=sean@geanix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox