]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: ABI: Add support for floating-point numbers in buffer scan elements
authorFrancesco Lavra <flavra@baylibre.com>
Tue, 24 Mar 2026 08:47:53 +0000 (09:47 +0100)
committerJonathan Cameron <jic23@kernel.org>
Mon, 27 Apr 2026 08:58:16 +0000 (09:58 +0100)
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>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Documentation/ABI/testing/sysfs-bus-iio
Documentation/driver-api/iio/buffers.rst
Documentation/iio/iio_devbuf.rst
include/linux/iio/iio.h

index 4fc9f6bd42812189596ac111d157e93d82acc2fd..851cfe4f0a05a74c6f68bebdf1835e8a57047541 100644 (file)
@@ -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.
 
index e16abaf826fe80165b40d61fd13aafd6a677865d..8779022e3da503d1c72a65254baeb3240c95e887 100644 (file)
@@ -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
index dca1f0200b0dd8d4d4bbfe84d750371ca6a54df4..e91730fa3cea4e7185a9f5c1c2cb5073eaee78af 100644 (file)
@@ -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
index e03b7e912d7d8f33422166d7866ed00da6fbd8d9..96b05c86c325f6153ccca3b1cfce7bb27b8d5c77 100644 (file)
@@ -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.