]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: Replace 'sign' field with union in struct iio_scan_type
authorFrancesco Lavra <flavra@baylibre.com>
Tue, 24 Mar 2026 08:47:40 +0000 (09:47 +0100)
committerJonathan Cameron <jic23@kernel.org>
Mon, 27 Apr 2026 08:58:16 +0000 (09:58 +0100)
This field is used to differentiate between signed and unsigned integers.
A following commit will extend its use in order to add support for non-
integer scan elements; therefore, replace it with a union that contains a
more generic 'format' field. This union will be dropped when all drivers
are changed to use the format field.
Opportunistically replace character literals with symbolic constants that
represent the set of allowed values for the format field.

Signed-off-by: Francesco Lavra <flavra@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Documentation/driver-api/iio/buffers.rst
include/linux/iio/iio.h

index 63f364e862d1c94b09d1675601ec350082a15a11..e16abaf826fe80165b40d61fd13aafd6a677865d 100644 (file)
@@ -78,7 +78,7 @@ fields in iio_chan_spec definition::
    /* other members */
            int scan_index
            struct {
-                   char sign;
+                   char format;
                    u8 realbits;
                    u8 storagebits;
                    u8 shift;
@@ -98,7 +98,7 @@ following channel definition::
                   /* other stuff here */
                   .scan_index = 0,
                   .scan_type = {
-                          .sign = 's',
+                          .format = IIO_SCAN_FORMAT_SIGNED_INT,
                           .realbits = 12,
                           .storagebits = 16,
                           .shift = 4,
index ecbaeecbe0ac604118a9f128c3f3c61ff6487e8f..e03b7e912d7d8f33422166d7866ed00da6fbd8d9 100644 (file)
@@ -176,9 +176,25 @@ struct iio_event_spec {
        unsigned long mask_shared_by_all;
 };
 
+/**
+ * define IIO_SCAN_FORMAT_SIGNED_INT - signed integer data format
+ *
+ * &iio_scan_type.format value for signed integers (two's complement).
+ */
+#define IIO_SCAN_FORMAT_SIGNED_INT     's'
+
+/**
+ * define IIO_SCAN_FORMAT_UNSIGNED_INT - unsigned integer data format
+ *
+ * &iio_scan_type.format value for unsigned integers.
+ */
+#define IIO_SCAN_FORMAT_UNSIGNED_INT   'u'
+
 /**
  * struct iio_scan_type - specification for channel data format in buffer
- * @sign:              's' or 'u' to specify signed or unsigned
+ * @sign:              Deprecated, use @format instead.
+ * @format:            Data format, can have any of the IIO_SCAN_FORMAT_*
+ *                     values.
  * @realbits:          Number of valid bits of data
  * @storagebits:       Realbits + padding
  * @shift:             Shift right by this before masking out realbits.
@@ -189,7 +205,10 @@ struct iio_event_spec {
  * @endianness:                little or big endian
  */
 struct iio_scan_type {
-       char    sign;
+       union {
+               char sign;
+               char format;
+       };
        u8      realbits;
        u8      storagebits;
        u8      shift;