public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: max30208: fix wrong scale value
@ 2026-04-28  8:54 Salah Triki
  2026-04-28 11:00 ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Salah Triki @ 2026-04-28  8:54 UTC (permalink / raw)
  To: Marcelo Schmitt, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel, Salah Triki

The driver currently returns a scale of 5 for IIO_CHAN_INFO_SCALE, which
leads to incorrect temperature readings.

According to the MAX30208 datasheet, the temperature resolution is 0.005°C
per LSB. Using IIO_VAL_FRACTIONAL with 5/1000 correctly represents this
16-bit resolution.

Fix the scale value to ensure user space tools report the temperature
correctly in Celsius.

Fixes: 9ee95ae4cffd ("iio: temperature: Add driver support for Maxim
MAX30208")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/iio/temperature/max30208.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/temperature/max30208.c b/drivers/iio/temperature/max30208.c
index 720469f9dc36..96f63c4fb2b6 100644
--- a/drivers/iio/temperature/max30208.c
+++ b/drivers/iio/temperature/max30208.c
@@ -163,7 +163,8 @@ static int max30208_read(struct iio_dev *indio_dev,
 
 	case IIO_CHAN_INFO_SCALE:
 		*val = 5;
-		return IIO_VAL_INT;
+		*val2 = 1000;
+		return IIO_VAL_FRACTIONAL;
 
 	default:
 		return -EINVAL;
-- 
2.43.0


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

* Re: [PATCH] iio: temperature: max30208: fix wrong scale value
  2026-04-28  8:54 [PATCH] iio: temperature: max30208: fix wrong scale value Salah Triki
@ 2026-04-28 11:00 ` Andy Shevchenko
  2026-04-28 13:36   ` Salah Triki
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-04-28 11:00 UTC (permalink / raw)
  To: Salah Triki
  Cc: Marcelo Schmitt, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Tue, Apr 28, 2026 at 09:54:15AM +0100, Salah Triki wrote:
> The driver currently returns a scale of 5 for IIO_CHAN_INFO_SCALE, which
> leads to incorrect temperature readings.
> 
> According to the MAX30208 datasheet, the temperature resolution is 0.005°C
> per LSB. Using IIO_VAL_FRACTIONAL with 5/1000 correctly represents this
> 16-bit resolution.
> 
> Fix the scale value to ensure user space tools report the temperature
> correctly in Celsius.

> Fixes: 9ee95ae4cffd ("iio: temperature: Add driver support for Maxim
> MAX30208")

The tags should go with 1 tag per one (single) line. Do not wrap them.

> Signed-off-by: Salah Triki <salah.triki@gmail.com>

...

>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 5;
> -		return IIO_VAL_INT;
> +		*val2 = 1000;
> +		return IIO_VAL_FRACTIONAL;

Isn't it an ABI change?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] iio: temperature: max30208: fix wrong scale value
  2026-04-28 11:00 ` Andy Shevchenko
@ 2026-04-28 13:36   ` Salah Triki
  2026-04-28 15:34     ` Jonathan Cameron
  2026-04-28 15:56     ` Jonathan Cameron
  0 siblings, 2 replies; 6+ messages in thread
From: Salah Triki @ 2026-04-28 13:36 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Marcelo Schmitt, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Tue, Apr 28, 2026 at 02:00:48PM +0300, Andy Shevchenko wrote:
> On Tue, Apr 28, 2026 at 09:54:15AM +0100, Salah Triki wrote:
> > The driver currently returns a scale of 5 for IIO_CHAN_INFO_SCALE, which
> > leads to incorrect temperature readings.
> > 
> > According to the MAX30208 datasheet, the temperature resolution is 0.005°C
> > per LSB. Using IIO_VAL_FRACTIONAL with 5/1000 correctly represents this
> > 16-bit resolution.
> > 
> > Fix the scale value to ensure user space tools report the temperature
> > correctly in Celsius.
> 
> > Fixes: 9ee95ae4cffd ("iio: temperature: Add driver support for Maxim
> > MAX30208")
> 
> The tags should go with 1 tag per one (single) line. Do not wrap them.

Sorry about that, I will fix the tag wrapping in v2.

> 
> > Signed-off-by: Salah Triki <salah.triki@gmail.com>
> 
> ...
> 
> >  	case IIO_CHAN_INFO_SCALE:
> >  		*val = 5;
> > -		return IIO_VAL_INT;
> > +		*val2 = 1000;
> > +		return IIO_VAL_FRACTIONAL;
> 
> Isn't it an ABI change?
> 

Yes, it technically changes the value exposed to user space. However, the
current scale (5) is objectively incorrect according to the datasheet 
(0.005°C per LSB).

With the current scale, a raw reading of 5000 (25°C) is reported as 
25000°C by user space tools. This makes the driver practically unusable 
for standard IIO consumers without custom workarounds. Since the driver is
relatively recent, I believe fixing it now to match the hardware 
specification is preferable to keeping a broken ABI.

What do you think?

Best regards,
--
Salah Triki

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

* Re: [PATCH] iio: temperature: max30208: fix wrong scale value
  2026-04-28 13:36   ` Salah Triki
@ 2026-04-28 15:34     ` Jonathan Cameron
  2026-04-28 15:43       ` Andy Shevchenko
  2026-04-28 15:56     ` Jonathan Cameron
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2026-04-28 15:34 UTC (permalink / raw)
  To: Salah Triki
  Cc: Andy Shevchenko, Marcelo Schmitt, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Tue, 28 Apr 2026 14:36:00 +0100
Salah Triki <salah.triki@gmail.com> wrote:

> On Tue, Apr 28, 2026 at 02:00:48PM +0300, Andy Shevchenko wrote:
> > On Tue, Apr 28, 2026 at 09:54:15AM +0100, Salah Triki wrote:  
> > > The driver currently returns a scale of 5 for IIO_CHAN_INFO_SCALE, which
> > > leads to incorrect temperature readings.
> > > 
> > > According to the MAX30208 datasheet, the temperature resolution is 0.005°C
> > > per LSB. Using IIO_VAL_FRACTIONAL with 5/1000 correctly represents this
> > > 16-bit resolution.
> > > 
> > > Fix the scale value to ensure user space tools report the temperature
> > > correctly in Celsius.  
> >   
> > > Fixes: 9ee95ae4cffd ("iio: temperature: Add driver support for Maxim
> > > MAX30208")  
> > 
> > The tags should go with 1 tag per one (single) line. Do not wrap them.  
> 
> Sorry about that, I will fix the tag wrapping in v2.
> 
> >   
> > > Signed-off-by: Salah Triki <salah.triki@gmail.com>  
> > 
> > ...
> >   
> > >  	case IIO_CHAN_INFO_SCALE:
> > >  		*val = 5;
> > > -		return IIO_VAL_INT;
> > > +		*val2 = 1000;
> > > +		return IIO_VAL_FRACTIONAL;  
> > 
> > Isn't it an ABI change?
> >   
> 
> Yes, it technically changes the value exposed to user space. However, the
> current scale (5) is objectively incorrect according to the datasheet 
> (0.005°C per LSB).
> 
> With the current scale, a raw reading of 5000 (25°C) is reported as 
> 25000°C by user space tools. This makes the driver practically unusable 
> for standard IIO consumers without custom workarounds. Since the driver is
> relatively recent, I believe fixing it now to match the hardware 
> specification is preferable to keeping a broken ABI.
> 

Yes.  It's fine to fix completely wrong ABI like this.  It can get messier
in more subtle corners but out by a factor of 1000 is an easy one!

Jonathan

> What do you think?
> 
> Best regards,
> --
> Salah Triki
> 


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

* Re: [PATCH] iio: temperature: max30208: fix wrong scale value
  2026-04-28 15:34     ` Jonathan Cameron
@ 2026-04-28 15:43       ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-04-28 15:43 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Salah Triki, Marcelo Schmitt, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Tue, Apr 28, 2026 at 04:34:58PM +0100, Jonathan Cameron wrote:
> On Tue, 28 Apr 2026 14:36:00 +0100
> Salah Triki <salah.triki@gmail.com> wrote:
> > On Tue, Apr 28, 2026 at 02:00:48PM +0300, Andy Shevchenko wrote:
> > > On Tue, Apr 28, 2026 at 09:54:15AM +0100, Salah Triki wrote:  

...

> > > Isn't it an ABI change?
> > 
> > Yes, it technically changes the value exposed to user space. However, the
> > current scale (5) is objectively incorrect according to the datasheet 
> > (0.005°C per LSB).
> > 
> > With the current scale, a raw reading of 5000 (25°C) is reported as 
> > 25000°C by user space tools. This makes the driver practically unusable 
> > for standard IIO consumers without custom workarounds. Since the driver is
> > relatively recent, I believe fixing it now to match the hardware 
> > specification is preferable to keeping a broken ABI.
> 
> Yes.  It's fine to fix completely wrong ABI like this.  It can get messier
> in more subtle corners but out by a factor of 1000 is an easy one!
> 
> > What do you think?

I think you need to write a wrap-up of the above and add to the commit message.
With that it will be justified as far as I am concerned.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] iio: temperature: max30208: fix wrong scale value
  2026-04-28 13:36   ` Salah Triki
  2026-04-28 15:34     ` Jonathan Cameron
@ 2026-04-28 15:56     ` Jonathan Cameron
  1 sibling, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2026-04-28 15:56 UTC (permalink / raw)
  To: Salah Triki
  Cc: Andy Shevchenko, Marcelo Schmitt, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Tue, 28 Apr 2026 14:36:00 +0100
Salah Triki <salah.triki@gmail.com> wrote:

> On Tue, Apr 28, 2026 at 02:00:48PM +0300, Andy Shevchenko wrote:
> > On Tue, Apr 28, 2026 at 09:54:15AM +0100, Salah Triki wrote:  
> > > The driver currently returns a scale of 5 for IIO_CHAN_INFO_SCALE, which
> > > leads to incorrect temperature readings.
> > > 
> > > According to the MAX30208 datasheet, the temperature resolution is 0.005°C
> > > per LSB. Using IIO_VAL_FRACTIONAL with 5/1000 correctly represents this
> > > 16-bit resolution.
> > > 
> > > Fix the scale value to ensure user space tools report the temperature
> > > correctly in Celsius.  
> >   
> > > Fixes: 9ee95ae4cffd ("iio: temperature: Add driver support for Maxim
> > > MAX30208")  
> > 
> > The tags should go with 1 tag per one (single) line. Do not wrap them.  
> 
> Sorry about that, I will fix the tag wrapping in v2.


> 
> >   
> > > Signed-off-by: Salah Triki <salah.triki@gmail.com>  
> > 
> > ...
> >   
> > >  	case IIO_CHAN_INFO_SCALE:
> > >  		*val = 5;
> > > -		return IIO_VAL_INT;
> > > +		*val2 = 1000;
> > > +		return IIO_VAL_FRACTIONAL;  
> > 
> > Isn't it an ABI change?
> >   
> 
> Yes, it technically changes the value exposed to user space. However, the
> current scale (5) is objectively incorrect according to the datasheet 
> (0.005°C per LSB).
> 
> With the current scale, a raw reading of 5000 (25°C) is reported as 
> 25000°C by user space tools. This makes the driver practically unusable 
It should be reporting in milli degrees C.

There are a few IIO units that are a bit odd like this because long long
ago in a galaxy far away, I decided to start from the scaling hwmon uses.
It turned out that gets really messy as you add more unit types so we
later standardized any new units on SI without a multiplier.  However
having to maintain ABI compatibility meant we were stuck with milli for
several units including temperature.

So I think this driver is correct as it stands.



> for standard IIO consumers without custom workarounds. Since the driver is
> relatively recent, I believe fixing it now to match the hardware 
> specification is preferable to keeping a broken ABI.
> 
> What do you think?
> 
> Best regards,
> --
> Salah Triki
> 


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

end of thread, other threads:[~2026-04-28 15:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28  8:54 [PATCH] iio: temperature: max30208: fix wrong scale value Salah Triki
2026-04-28 11:00 ` Andy Shevchenko
2026-04-28 13:36   ` Salah Triki
2026-04-28 15:34     ` Jonathan Cameron
2026-04-28 15:43       ` Andy Shevchenko
2026-04-28 15:56     ` Jonathan Cameron

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