]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: accel: fxls8962af: Fix temperature calculation
authorSean Nyekjaer <sean@geanix.com>
Mon, 5 May 2025 19:20:07 +0000 (21:20 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 15 May 2025 16:17:01 +0000 (17:17 +0100)
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")
Cc: stable@vger.kernel.org
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Link: https://patch.msgid.link/20250505-fxls-v4-1-a38652e21738@geanix.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/fxls8962af-core.c

index bf1d3923a181798a1c884ee08b62d86ab5aed26f..5f5e917f7aa53912448ba078027183c63bc0cd7d 100644 (file)
@@ -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 = { \