Skip to contentSkip to conversation

iio: temperature: max30208: fix wrong scale value

PATCH Superseded Salah Triki 3 participants 6 messages Apr 28

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: temperature: max30208: fix wrong scale value

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")

---
 drivers/iio/temperature/max30208.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/temperature/max30208.c +2 -1
index 720469f9dc36..96f63c4fb2b6 100644
@@ -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;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · 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.

Quoted 5 lines

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.

Quoted 1 line

...

drivers/iio/temperature/max30208.c static int max30208_read(struct iio_dev *indio_dev, · line 167

Quoted 5 lines
drivers/iio/temperature/max30208.c +2 -1
 	case IIO_CHAN_INFO_SCALE:
 		*val = 5;
-		return IIO_VAL_INT;
+		*val2 = 1000;
+		return IIO_VAL_FRACTIONAL;

Isn't it an ABI change?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · 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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 5 lines
Quoted 2 lines

...

Quoted 8 lines

drivers/iio/temperature/max30208.c static int max30208_read(struct iio_dev *indio_dev, · line 167

Quoted 5 lines
drivers/iio/temperature/max30208.c +2 -1
 	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

maintainer
#3 lore raw
Quoted 37 lines · On Tue, 28 Apr 2026 14:36:00 +0100 Salah Triki <[email protected]> wrote:
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · 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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 5 lines
Quoted 2 lines

...

Quoted 8 lines

drivers/iio/temperature/max30208.c static int max30208_read(struct iio_dev *indio_dev, · line 167

Quoted 5 lines
drivers/iio/temperature/max30208.c +2 -1
 	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).

Quoted 6 lines

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

Quoted 6 lines

What do you think?

Best regards,
--
Salah Triki

#4 lore raw
Quoted 4 lines · Jonathan Cameron
Quoted 2 lines · On Tue, 28 Apr 2026 14:36:00 +0100 Salah Triki <[email protected]> wrote:
Quoted 1 line · Andy Shevchenko

On Tue, Apr 28, 2026 at 09:54:15AM +0100, Salah Triki wrote:

...

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

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).

Quoted 10 lines
Quoted 5 lines

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!

Quoted 1 line

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
In reply to Salah Triki
Quoted 35 lines · On Tue, 28 Apr 2026 14:36:00 +0100 Salah Triki <[email protected]> wrote:
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · 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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 5 lines
Quoted 2 lines

...

Quoted 8 lines

drivers/iio/temperature/max30208.c static int max30208_read(struct iio_dev *indio_dev, · line 167

Quoted 5 lines
drivers/iio/temperature/max30208.c +2 -1
 	case IIO_CHAN_INFO_SCALE:
 		*val = 5;
-		return IIO_VAL_INT;
+		*val2 = 1000;
+		return IIO_VAL_FRACTIONAL;  

Isn't it an ABI change?

Quoted 6 lines

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.

Quoted 10 lines

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