iio: temperature: mlx90632: Interface to change object ambient temperature
authorCrt Mori <cmo@melexis.com>
Sun, 6 Sep 2020 21:02:31 +0000 (23:02 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 13 Sep 2020 09:21:37 +0000 (10:21 +0100)
Since object temperature might be different than the sensor temperature
the infrared sensors should provide an interface to inject ambient
temperature. This was in past done via write to ambient temperature
interface (in_temp_ambient_raw), but I think most people did not know
about it. This solution introduces a new iio type of the CALIBAMBIENT
which is hopefully more descriptive and more explicit about the purpose
and capabilities of the sensors.

Signed-off-by: Crt Mori <cmo@melexis.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20200906210231.383976-1-cmo@melexis.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Documentation/ABI/testing/sysfs-bus-iio
drivers/iio/industrialio-core.c
drivers/iio/temperature/mlx90632.c
include/linux/iio/types.h

index c20334454dbf65042c75bdc53b9d7fd75b79278f..a9d51810a3bad5e1005fd450d885d585ab96f83a 100644 (file)
@@ -1758,6 +1758,14 @@ Contact: linux-iio@vger.kernel.org
 Description:
                One of the following thermocouple types: B, E, J, K, N, R, S, T.
 
+What:          /sys/bus/iio/devices/iio:deviceX/in_temp_object_calibambient
+What:          /sys/bus/iio/devices/iio:deviceX/in_tempX_object_calibambient
+KernelVersion: 5.10
+Contact:       linux-iio@vger.kernel.org
+Description:
+               Calibrated ambient temperature for object temperature
+               calculation in milli degrees Celsius.
+
 What:          /sys/bus/iio/devices/iio:deviceX/in_intensity_x_raw
 What:          /sys/bus/iio/devices/iio:deviceX/in_intensity_y_raw
 What:          /sys/bus/iio/devices/iio:deviceX/in_intensity_z_raw
index 59003dc44e60232e4a04a89ece3f4c6ee314745f..8ddc6dfc8ed499850c09d694928753fc7242abb1 100644 (file)
@@ -166,6 +166,7 @@ static const char * const iio_chan_info_postfix[] = {
        [IIO_CHAN_INFO_CALIBEMISSIVITY] = "calibemissivity",
        [IIO_CHAN_INFO_OVERSAMPLING_RATIO] = "oversampling_ratio",
        [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
+       [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient",
 };
 
 #if defined(CONFIG_DEBUG_FS)
index 472a7fb2061595938e320ec137f63b9514a5595c..503fe54a0bb937ad9684b001cf3dd59dbf2741b1 100644 (file)
@@ -761,7 +761,9 @@ static int mlx90632_read_raw(struct iio_dev *indio_dev,
                        *val2 = data->emissivity * 1000;
                }
                return IIO_VAL_INT_PLUS_MICRO;
-
+       case IIO_CHAN_INFO_CALIBAMBIENT:
+               *val = data->object_ambient_temperature;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -781,6 +783,9 @@ static int mlx90632_write_raw(struct iio_dev *indio_dev,
                        return -EINVAL;
                data->emissivity = val * 1000 + val2 / 1000;
                return 0;
+       case IIO_CHAN_INFO_CALIBAMBIENT:
+               data->object_ambient_temperature = val;
+               return 0;
        default:
                return -EINVAL;
        }
@@ -798,7 +803,7 @@ static const struct iio_chan_spec mlx90632_channels[] = {
                .modified = 1,
                .channel2 = IIO_MOD_TEMP_OBJECT,
                .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
-                       BIT(IIO_CHAN_INFO_CALIBEMISSIVITY),
+                       BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) | BIT(IIO_CHAN_INFO_CALIBAMBIENT),
        },
 };
 
index e6fd3645963ca11510aff489b91031d066a9c953..1e3ed6f55bca03d7a4ad1aab2679f303873f6475 100644 (file)
@@ -59,6 +59,7 @@ enum iio_chan_info_enum {
        IIO_CHAN_INFO_CALIBEMISSIVITY,
        IIO_CHAN_INFO_OVERSAMPLING_RATIO,
        IIO_CHAN_INFO_THERMOCOUPLE_TYPE,
+       IIO_CHAN_INFO_CALIBAMBIENT,
 };
 
 #endif /* _IIO_TYPES_H_ */