The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_icm42600: Fix temperature calculation
@ 2025-05-02  9:37 Sean Nyekjaer
  2025-05-04 15:28 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Nyekjaer @ 2025-05-02  9:37 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol, Jonathan Cameron, Lars-Peter Clausen
  Cc: Jean-Baptiste Maneyrol, Jonathan Cameron, linux-iio, linux-kernel,
	Sean Nyekjaer

From the documentation:
"offset to be added to <type>[Y]_raw prior toscaling by <type>[Y]_scale"
Offset should be applied before multiplying scale, so divide offset by
scale to make this correct.

Fixes: bc3eb0207fb5 ("iio: imu: inv_icm42600: add temperature sensor support")
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
 drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
index 213cce1c31110e669e7191c8b42c9524c0d3e5db..91f0f381082bda3dbb95dfe1a38adcdc4eaf5419 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
@@ -67,16 +67,18 @@ int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
 		return IIO_VAL_INT;
 	/*
 	 * T°C = (temp / 132.48) + 25
-	 * Tm°C = 1000 * ((temp * 100 / 13248) + 25)
+	 * Tm°C = 1000 * ((temp / 132.48) + 25)
+	 * Tm°C = 7.548309 * temp + 25000
+	 * Tm°C = (temp + 3312) * 7.548309
 	 * scale: 100000 / 13248 ~= 7.548309
-	 * offset: 25000
+	 * offset: 3312
 	 */
 	case IIO_CHAN_INFO_SCALE:
 		*val = 7;
 		*val2 = 548309;
 		return IIO_VAL_INT_PLUS_MICRO;
 	case IIO_CHAN_INFO_OFFSET:
-		*val = 25000;
+		*val = 3312;
 		return IIO_VAL_INT;
 	default:
 		return -EINVAL;

---
base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
change-id: 20250502-imu-edc0faa6dae9

Best regards,
-- 
Sean Nyekjaer <sean@geanix.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: inv_icm42600: Fix temperature calculation
  2025-05-02  9:37 [PATCH] iio: imu: inv_icm42600: Fix temperature calculation Sean Nyekjaer
@ 2025-05-04 15:28 ` Jonathan Cameron
  2025-05-04 16:46   ` Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2025-05-04 15:28 UTC (permalink / raw)
  To: Sean Nyekjaer
  Cc: Jean-Baptiste Maneyrol, Lars-Peter Clausen,
	Jean-Baptiste Maneyrol, Jonathan Cameron, linux-iio, linux-kernel

On Fri, 02 May 2025 11:37:26 +0200
Sean Nyekjaer <sean@geanix.com> wrote:

> From the documentation:
> "offset to be added to <type>[Y]_raw prior toscaling by <type>[Y]_scale"
> Offset should be applied before multiplying scale, so divide offset by
> scale to make this correct.
> 
> Fixes: bc3eb0207fb5 ("iio: imu: inv_icm42600: add temperature sensor support")
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Looks correct to me.  Given this is going to have impacts on userspace
I'd definitely like to know Jean-Baptiste has seen it though before I apply.
So, Jean-Baptiste please take a look!

Thanks,

Jonathan


> ---
>  drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> index 213cce1c31110e669e7191c8b42c9524c0d3e5db..91f0f381082bda3dbb95dfe1a38adcdc4eaf5419 100644
> --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> @@ -67,16 +67,18 @@ int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT;
>  	/*
>  	 * T°C = (temp / 132.48) + 25
> -	 * Tm°C = 1000 * ((temp * 100 / 13248) + 25)
> +	 * Tm°C = 1000 * ((temp / 132.48) + 25)
> +	 * Tm°C = 7.548309 * temp + 25000
> +	 * Tm°C = (temp + 3312) * 7.548309
>  	 * scale: 100000 / 13248 ~= 7.548309
> -	 * offset: 25000
> +	 * offset: 3312
>  	 */
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 7;
>  		*val2 = 548309;
>  		return IIO_VAL_INT_PLUS_MICRO;
>  	case IIO_CHAN_INFO_OFFSET:
> -		*val = 25000;
> +		*val = 3312;
>  		return IIO_VAL_INT;
>  	default:
>  		return -EINVAL;
> 
> ---
> base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
> change-id: 20250502-imu-edc0faa6dae9
> 
> Best regards,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: inv_icm42600: Fix temperature calculation
  2025-05-04 15:28 ` Jonathan Cameron
@ 2025-05-04 16:46   ` Jean-Baptiste Maneyrol
  2025-05-05 16:33     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Baptiste Maneyrol @ 2025-05-04 16:46 UTC (permalink / raw)
  To: Jonathan Cameron, Sean Nyekjaer
  Cc: Lars-Peter Clausen, Jonathan Cameron, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org

Hello Sean, Jonathan,

good catch indeed!
This is all good for me, thanks for your fix.

Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>

Best regards,
JB

________________________________________
From: Jonathan Cameron <jic23@kernel.org>
Sent: Sunday, May 4, 2025 17:28
To: Sean Nyekjaer <sean@geanix.com>
Cc: Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Lars-Peter Clausen <lars@metafoo.de>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Jonathan Cameron <Jonathan.Cameron@huawei.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: imu: inv_icm42600: Fix temperature calculation
 
This Message Is From an External Sender
This message came from outside your organization.
 
On Fri, 02 May 2025 11:37:26 +0200
Sean Nyekjaer <sean@geanix.com> wrote:

> From the documentation:
> "offset to be added to <type>[Y]_raw prior toscaling by <type>[Y]_scale"
> Offset should be applied before multiplying scale, so divide offset by
> scale to make this correct.
> 
> Fixes: bc3eb0207fb5 ("iio: imu: inv_icm42600: add temperature sensor support")
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Looks correct to me.  Given this is going to have impacts on userspace
I'd definitely like to know Jean-Baptiste has seen it though before I apply.
So, Jean-Baptiste please take a look!

Thanks,

Jonathan


> ---
>  drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> index 213cce1c31110e669e7191c8b42c9524c0d3e5db..91f0f381082bda3dbb95dfe1a38adcdc4eaf5419 100644
> --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> @@ -67,16 +67,18 @@ int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT;
>  	/*
>  	 * T°C = (temp / 132.48) + 25
> -	 * Tm°C = 1000 * ((temp * 100 / 13248) + 25)
> +	 * Tm°C = 1000 * ((temp / 132.48) + 25)
> +	 * Tm°C = 7.548309 * temp + 25000
> +	 * Tm°C = (temp + 3312) * 7.548309
>  	 * scale: 100000 / 13248 ~= 7.548309
> -	 * offset: 25000
> +	 * offset: 3312
>  	 */
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 7;
>  		*val2 = 548309;
>  		return IIO_VAL_INT_PLUS_MICRO;
>  	case IIO_CHAN_INFO_OFFSET:
> -		*val = 25000;
> +		*val = 3312;
>  		return IIO_VAL_INT;
>  	default:
>  		return -EINVAL;
> 
> ---
> base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
> change-id: 20250502-imu-edc0faa6dae9
> 
> Best regards,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: inv_icm42600: Fix temperature calculation
  2025-05-04 16:46   ` Jean-Baptiste Maneyrol
@ 2025-05-05 16:33     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-05-05 16:33 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol
  Cc: Sean Nyekjaer, Lars-Peter Clausen, Jonathan Cameron,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org

On Sun, 4 May 2025 16:46:00 +0000
Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com> wrote:

> Hello Sean, Jonathan,
> 
> good catch indeed!
> This is all good for me, thanks for your fix.
> 
> Acked-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
> 
Applied.
> Best regards,
> JB
> 
> ________________________________________
> From: Jonathan Cameron <jic23@kernel.org>
> Sent: Sunday, May 4, 2025 17:28
> To: Sean Nyekjaer <sean@geanix.com>
> Cc: Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Lars-Peter Clausen <lars@metafoo.de>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>; Jonathan Cameron <Jonathan.Cameron@huawei.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH] iio: imu: inv_icm42600: Fix temperature calculation
>  
> This Message Is From an External Sender
> This message came from outside your organization.
>  
> On Fri, 02 May 2025 11:37:26 +0200
> Sean Nyekjaer <sean@geanix.com> wrote:
> 
> > From the documentation:
> > "offset to be added to <type>[Y]_raw prior toscaling by <type>[Y]_scale"
> > Offset should be applied before multiplying scale, so divide offset by
> > scale to make this correct.
> > 
> > Fixes: bc3eb0207fb5 ("iio: imu: inv_icm42600: add temperature sensor support")
> > Signed-off-by: Sean Nyekjaer <sean@geanix.com>  
> Looks correct to me.  Given this is going to have impacts on userspace
> I'd definitely like to know Jean-Baptiste has seen it though before I apply.
> So, Jean-Baptiste please take a look!
> 
> Thanks,
> 
> Jonathan
> 
> 
> > ---
> >  drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> > index 213cce1c31110e669e7191c8b42c9524c0d3e5db..91f0f381082bda3dbb95dfe1a38adcdc4eaf5419 100644
> > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
> > @@ -67,16 +67,18 @@ int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
> >  		return IIO_VAL_INT;
> >  	/*
> >  	 * T°C = (temp / 132.48) + 25
> > -	 * Tm°C = 1000 * ((temp * 100 / 13248) + 25)
> > +	 * Tm°C = 1000 * ((temp / 132.48) + 25)
> > +	 * Tm°C = 7.548309 * temp + 25000
> > +	 * Tm°C = (temp + 3312) * 7.548309
> >  	 * scale: 100000 / 13248 ~= 7.548309
> > -	 * offset: 25000
> > +	 * offset: 3312
> >  	 */
> >  	case IIO_CHAN_INFO_SCALE:
> >  		*val = 7;
> >  		*val2 = 548309;
> >  		return IIO_VAL_INT_PLUS_MICRO;
> >  	case IIO_CHAN_INFO_OFFSET:
> > -		*val = 25000;
> > +		*val = 3312;
> >  		return IIO_VAL_INT;
> >  	default:
> >  		return -EINVAL;
> > 
> > ---
> > base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
> > change-id: 20250502-imu-edc0faa6dae9
> > 
> > Best regards,  
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-05 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02  9:37 [PATCH] iio: imu: inv_icm42600: Fix temperature calculation Sean Nyekjaer
2025-05-04 15:28 ` Jonathan Cameron
2025-05-04 16:46   ` Jean-Baptiste Maneyrol
2025-05-05 16:33     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox