public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: temperature: max30208: fix wrong scale value
@ 2026-04-28 15:53 Salah Triki
  2026-04-28 16:02 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Salah Triki @ 2026-04-28 15:53 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.

Although this is a change in the ABI, the current scale is objectively
incorrect. A raw reading of 5000 (25°C) is currently reported as 25000°C,
making the driver unusable with standard IIO tools. Given the magnitude
of the error (factor of 1000) and the fact that the driver is relatively
recent, fixing it to match the hardware specification is necessary.

Fixes: 9ee95ae4cffd ("iio: temperature: Add driver support for Maxim MAX30208")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
Changes in v2:
  - Update commit message to justify the ABI change as requested by Andy.
  - Fix wrapping of the Fixes tag.

 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] 3+ messages in thread

* Re: [PATCH v2] iio: temperature: max30208: fix wrong scale value
  2026-04-28 15:53 [PATCH v2] iio: temperature: max30208: fix wrong scale value Salah Triki
@ 2026-04-28 16:02 ` Andy Shevchenko
  2026-04-28 16:13   ` Salah Triki
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-04-28 16:02 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 04:53:49PM +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.
> 
> Although this is a change in the ABI, the current scale is objectively
> incorrect. A raw reading of 5000 (25°C) is currently reported as 25000°C,
> making the driver unusable with standard IIO tools. Given the magnitude
> of the error (factor of 1000) and the fact that the driver is relatively
> recent, fixing it to match the hardware specification is necessary.

Seems the analysis is wrong (as per Jonathan's comment in v1). What are the
user space tools you referring to?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] iio: temperature: max30208: fix wrong scale value
  2026-04-28 16:02 ` Andy Shevchenko
@ 2026-04-28 16:13   ` Salah Triki
  0 siblings, 0 replies; 3+ messages in thread
From: Salah Triki @ 2026-04-28 16:13 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 07:02:16PM +0300, Andy Shevchenko wrote:
> On Tue, Apr 28, 2026 at 04:53:49PM +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.
> > 
> > Although this is a change in the ABI, the current scale is objectively
> > incorrect. A raw reading of 5000 (25°C) is currently reported as 25000°C,
> > making the driver unusable with standard IIO tools. Given the magnitude
> > of the error (factor of 1000) and the fact that the driver is relatively
> > recent, fixing it to match the hardware specification is necessary.
> 
> Seems the analysis is wrong (as per Jonathan's comment in v1). What are the
> user space tools you referring to?
> 
You are correct. My analysis was purely based on a misinterpretation of the
datasheet's resolution (0.005°C) versus the IIO ABI requirement for
temperature (milli-degrees).

I assumed the scale should convert raw values to Celsius directly, without
realizing that '5' was already the correct value in milli-degrees. Since I
don't have the hardware to verify the output, I relied solely on my reading
of the datasheet and missed the ABI unit convention.

I will withdraw this patch. Sorry for the confusion

Best regards
--
Salah Triki

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 15:53 [PATCH v2] iio: temperature: max30208: fix wrong scale value Salah Triki
2026-04-28 16:02 ` Andy Shevchenko
2026-04-28 16:13   ` Salah Triki

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