* [PATCH v9 2/6] iio: Replace 'sign' field with union in struct iio_scan_type
[not found] <20260324084655.653781-1-flavra@baylibre.com>
@ 2026-03-24 8:47 ` Francesco Lavra
2026-03-24 8:47 ` [PATCH v9 4/6] iio: ABI: Add support for floating-point numbers in buffer scan elements Francesco Lavra
1 sibling, 0 replies; 2+ messages in thread
From: Francesco Lavra @ 2026-03-24 8:47 UTC (permalink / raw)
To: Jonathan Corbet, Shuah Khan, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, linux-doc, linux-kernel, linux-iio
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>
---
Documentation/driver-api/iio/buffers.rst | 4 ++--
include/linux/iio/iio.h | 23 +++++++++++++++++++++--
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/Documentation/driver-api/iio/buffers.rst b/Documentation/driver-api/iio/buffers.rst
index 63f364e862d1..e16abaf826fe 100644
--- a/Documentation/driver-api/iio/buffers.rst
+++ b/Documentation/driver-api/iio/buffers.rst
@@ -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,
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index a9ecff191bd9..745290bd9af4 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -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;
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH v9 4/6] iio: ABI: Add support for floating-point numbers in buffer scan elements
[not found] <20260324084655.653781-1-flavra@baylibre.com>
2026-03-24 8:47 ` [PATCH v9 2/6] iio: Replace 'sign' field with union in struct iio_scan_type Francesco Lavra
@ 2026-03-24 8:47 ` Francesco Lavra
1 sibling, 0 replies; 2+ messages in thread
From: Francesco Lavra @ 2026-03-24 8:47 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Jonathan Corbet, Shuah Khan, linux-iio, linux-kernel, linux-doc
In the data storage description of a scan element, the first character
after the colon can have the values 's' and 'u' to specify signed and
unsigned integers, respectively.
Add 'f' as an allowed value to specify floating-point numbers formatted
according to the IEEE 754 standard.
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
---
Documentation/ABI/testing/sysfs-bus-iio | 33 +++++++++++++-----------
Documentation/driver-api/iio/buffers.rst | 3 ++-
Documentation/iio/iio_devbuf.rst | 3 ++-
include/linux/iio/iio.h | 7 +++++
4 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 5f87dcee78f7..bd6c3305dd2b 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -1510,21 +1510,24 @@ Contact: linux-iio@vger.kernel.org
Description:
Description of the scan element data storage within the buffer
and hence the form in which it is read from user-space.
- Form is [be|le]:[s|u]bits/storagebits[>>shift].
- be or le specifies big or little endian. s or u specifies if
- signed (2's complement) or unsigned. bits is the number of bits
- of data and storagebits is the space (after padding) that it
- occupies in the buffer. shift if specified, is the shift that
- needs to be applied prior to masking out unused bits. Some
- devices put their data in the middle of the transferred elements
- with additional information on both sides. Note that some
- devices will have additional information in the unused bits
- so to get a clean value, the bits value must be used to mask
- the buffer output value appropriately. The storagebits value
- also specifies the data alignment. So s48/64>>2 will be a
- signed 48 bit integer stored in a 64 bit location aligned to
- a 64 bit boundary. To obtain the clean value, shift right 2
- and apply a mask to zero the top 16 bits of the result.
+ Form is [be|le]:[f|s|u]bits/storagebits[>>shift].
+ be or le specifies big or little endian. f means floating-point
+ (IEEE 754 binary format), s means signed (2's complement), u means
+ unsigned. bits is the number of bits of data and storagebits is the
+ space (after padding) that it occupies in the buffer; when using a
+ floating-point format, bits must be one of the width values defined
+ in the IEEE 754 standard for binary interchange formats (e.g. 16
+ indicates the binary16 format for half-precision numbers). shift,
+ if specified, is the shift that needs to be applied prior to
+ masking out unused bits. Some devices put their data in the middle
+ of the transferred elements with additional information on both
+ sides. Note that some devices will have additional information in
+ the unused bits, so to get a clean value the bits value must be
+ used to mask the buffer output value appropriately. The storagebits
+ value also specifies the data alignment. So s48/64>>2 will be a
+ signed 48 bit integer stored in a 64 bit location aligned to a 64
+ bit boundary. To obtain the clean value, shift right 2 and apply a
+ mask to zero the top 16 bits of the result.
For other storage combinations this attribute will be extended
appropriately.
diff --git a/Documentation/driver-api/iio/buffers.rst b/Documentation/driver-api/iio/buffers.rst
index e16abaf826fe..8779022e3da5 100644
--- a/Documentation/driver-api/iio/buffers.rst
+++ b/Documentation/driver-api/iio/buffers.rst
@@ -37,9 +37,10 @@ directory contains attributes of the following form:
* :file:`index`, the scan_index of the channel.
* :file:`type`, description of the scan element data storage within the buffer
and hence the form in which it is read from user space.
- Format is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift] .
+ Format is [be|le]:[f|s|u]bits/storagebits[Xrepeat][>>shift] .
* *be* or *le*, specifies big or little endian.
+ * *f*, specifies if floating-point.
* *s* or *u*, specifies if signed (2's complement) or unsigned.
* *bits*, is the number of valid data bits.
* *storagebits*, is the number of bits (after padding) that it occupies in the
diff --git a/Documentation/iio/iio_devbuf.rst b/Documentation/iio/iio_devbuf.rst
index dca1f0200b0d..e91730fa3cea 100644
--- a/Documentation/iio/iio_devbuf.rst
+++ b/Documentation/iio/iio_devbuf.rst
@@ -83,9 +83,10 @@ and the relevant _type attributes to establish the data storage format.
Read-only attribute containing the description of the scan element data storage
within the buffer and hence the form in which it is read from userspace. Format
-is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift], where:
+is [be|le]:[f|s|u]bits/storagebits[Xrepeat][>>shift], where:
- **be** or **le** specifies big or little-endian.
+- **f** specifies if floating-point.
- **s** or **u** specifies if signed (2's complement) or unsigned.
- **bits** is the number of valid data bits.
- **storagebits** is the number of bits (after padding) that it occupies in the
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 745290bd9af4..97ac4961585f 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -190,6 +190,13 @@ struct iio_event_spec {
*/
#define IIO_SCAN_FORMAT_UNSIGNED_INT 'u'
+/**
+ * define IIO_SCAN_FORMAT_FLOAT - floating-point data format
+ *
+ * &iio_scan_type.format value for IEEE 754 floating-point numbers.
+ */
+#define IIO_SCAN_FORMAT_FLOAT 'f'
+
/**
* struct iio_scan_type - specification for channel data format in buffer
* @sign: Deprecated, use @format instead.
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread