Skip to contentSkip to conversation

iio: accel: fxls8962af: Fix temperature readings

PATCH Applied Sean Nyekjaer 2 participants 4 messages May 5, 2025 – May 15, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover iio: accel: fxls8962af: Fix temperature readings

Add the correct scale to get temperature in mili degree Celcius. Add sign component to temperature scan element.

---
Changes in v4:
- Blindly Copy/Pasted Andy's comment. Use the correct MILLIDEGREE_PER_DEGREE
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Dropping define infavor of inline scale value
- Added using constants from units.h
- Tweaked commit msg to make it more assertive
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Correct offset is applied before scaling component
- Added sign component to temperature scan element
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Sean Nyekjaer (2):
iio: accel: fxls8962af: Fix temperature calculation
iio: accel: fxls8962af: Fix temperature scan element sign

 drivers/iio/accel/fxls8962af-core.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

---
base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
change-id: 20250501-fxls-307ef3d6d065

Best regards,

Signature · 1 line
Sean Nyekjaer <[email protected]>
#1 lore raw

PATCH v4 1/2 iio: accel: fxls8962af: Fix temperature calculation

According to spec temperature should be returned in milli degrees Celsius. Add in_temp_scale to calculate from Celsius to milli Celsius.

Fixes a3e0b51884ee ("iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers")
---
 drivers/iio/accel/fxls8962af-core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iio/accel/fxls8962af-core.c +12 -2
index bf1d3923a181798a1c884ee08b62d86ab5aed26f..5f5e917f7aa53912448ba078027183c63bc0cd7d 100644
@@ -23,6 +23,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/regmap.h>
 #include <linux/types.h>
+#include <linux/units.h>
 
 #include <linux/iio/buffer.h>
 #include <linux/iio/events.h>
@@ -439,8 +440,16 @@ static int fxls8962af_read_raw(struct iio_dev *indio_dev,
 		*val = FXLS8962AF_TEMP_CENTER_VAL;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		*val = 0;
-		return fxls8962af_read_full_scale(data, val2);
+		switch (chan->type) {
+		case IIO_TEMP:
+			*val = MILLIDEGREE_PER_DEGREE;
+			return IIO_VAL_INT;
+		case IIO_ACCEL:
+			*val = 0;
+			return fxls8962af_read_full_scale(data, val2);
+		default:
+			return -EINVAL;
+		}
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		return fxls8962af_read_samp_freq(data, val, val2);
 	default:
@@ -736,6 +745,7 @@ static const struct iio_event_spec fxls8962af_event[] = {
 	.type = IIO_TEMP, \
 	.address = FXLS8962AF_TEMP_OUT, \
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+			      BIT(IIO_CHAN_INFO_SCALE) | \
 			      BIT(IIO_CHAN_INFO_OFFSET),\
 	.scan_index = -1, \
 	.scan_type = { \
Signature · 1 line
2.47.1
#2 lore raw

PATCH v4 2/2 iio: accel: fxls8962af: Fix temperature scan element sign

In reply to Sean Nyekjaer

Mark the temperature element signed, data read from the TEMP_OUT register is in two's complement format.
This will avoid the temperature being mishandled and miss displayed.

Fixes a3e0b51884ee ("iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers")
---
 drivers/iio/accel/fxls8962af-core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/accel/fxls8962af-core.c +1 -0
index 5f5e917f7aa53912448ba078027183c63bc0cd7d..ae965a8f560d3b9872a7197c3b540fe4f7f655df 100644
@@ -749,6 +749,7 @@ static const struct iio_event_spec fxls8962af_event[] = {
 			      BIT(IIO_CHAN_INFO_OFFSET),\
 	.scan_index = -1, \
 	.scan_type = { \
+		.sign = 's', \
 		.realbits = 8, \
 		.storagebits = 8, \
 	}, \
Signature · 1 line
2.47.1
maintainer Applied
#3 lore raw
In reply to Sean Nyekjaer
Quoted 4 lines · On Mon, 05 May 2025 21:20:06 +0200 Sean Nyekjaer <[email protected]> wrote:

Add the correct scale to get temperature in mili degree Celcius. Add sign component to temperature scan element.

Applied.

Thanks,

Quoted 28 lines

---
Changes in v4:
- Blindly Copy/Pasted Andy's comment. Use the correct MILLIDEGREE_PER_DEGREE
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Dropping define infavor of inline scale value
- Added using constants from units.h
- Tweaked commit msg to make it more assertive
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Correct offset is applied before scaling component
- Added sign component to temperature scan element
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Sean Nyekjaer (2):
iio: accel: fxls8962af: Fix temperature calculation
iio: accel: fxls8962af: Fix temperature scan element sign

 drivers/iio/accel/fxls8962af-core.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

---
base-commit: 609bc31eca06c7408e6860d8b46311ebe45c1fef
change-id: 20250501-fxls-307ef3d6d065

Best regards,