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.
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
---
Documentation/driver-api/iio/buffers.rst | 4 ++--
include/linux/iio/iio.h | 7 +++++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Documentation/driver-api/iio/buffers.rst b/Documentation/driver-api/iio/buffers.rst
index 63f364e862d1..f36e6d00173f 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 = 's',
.realbits = 12,
.storagebits = 16,
.shift = 4,
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index a9ecff191bd9..61f1dfc14e02 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -178,7 +178,7 @@ struct iio_event_spec {
/**
* struct iio_scan_type - specification for channel data format in buffer
- * @sign: 's' or 'u' to specify signed or unsigned
+ * @format: (signed or unsigned) integer, or floating point
* @realbits: Number of valid bits of data
* @storagebits: Realbits + padding
* @shift: Shift right by this before masking out realbits.
@@ -189,7 +189,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
On Wed, 4 Mar 2026 09:06:40 +0100
Francesco Lavra <flavra@baylibre.com> wrote:
> 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.
>
> Signed-off-by: Francesco Lavra <flavra@baylibre.com>
> ---
> Documentation/driver-api/iio/buffers.rst | 4 ++--
> include/linux/iio/iio.h | 7 +++++--
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/driver-api/iio/buffers.rst b/Documentation/driver-api/iio/buffers.rst
> index 63f364e862d1..f36e6d00173f 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 = 's',
This made me wonder if we should use this opportunity to restrict
the flexibility of what can go in .format via some defines?
#define IIO_SCAN_FORMAT_SIGNED_INT 's'
#define IIO_SCAN_FORMAT_UNSIGNED_INT 'u'
#define IIO_SCAN_FORMAT_FLOAT 'f'
or something like that. Given the aim is to convert all current
instances we can move to the macros as part of switching from
sign to format.
> .realbits = 12,
> .storagebits = 16,
> .shift = 4,
On 3/4/26 2:06 AM, Francesco Lavra wrote:
> 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.
>
> Signed-off-by: Francesco Lavra <flavra@baylibre.com>
> ---
> Documentation/driver-api/iio/buffers.rst | 4 ++--
> include/linux/iio/iio.h | 7 +++++--
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/driver-api/iio/buffers.rst b/Documentation/driver-api/iio/buffers.rst
> index 63f364e862d1..f36e6d00173f 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 = 's',
> .realbits = 12,
> .storagebits = 16,
> .shift = 4,
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index a9ecff191bd9..61f1dfc14e02 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -178,7 +178,7 @@ struct iio_event_spec {
>
> /**
> * struct iio_scan_type - specification for channel data format in buffer
> - * @sign: 's' or 'u' to specify signed or unsigned
> + * @format: (signed or unsigned) integer, or floating point
We should keep the list of valid values here.
> * @realbits: Number of valid bits of data
> * @storagebits: Realbits + padding
> * @shift: Shift right by this before masking out realbits.
> @@ -189,7 +189,10 @@ struct iio_event_spec {
> * @endianness: little or big endian
> */
> struct iio_scan_type {
> - char sign;
> + union {
> + char sign;
> + char format;
Could add some comments here to say that format should be used
in new code and sign will be removed eventually.
> + };
> u8 realbits;
> u8 storagebits;
> u8 shift;
On Wed, 4 Mar 2026 16:55:42 -0600
David Lechner <dlechner@baylibre.com> wrote:
> On 3/4/26 2:06 AM, Francesco Lavra wrote:
> > 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.
> >
> > Signed-off-by: Francesco Lavra <flavra@baylibre.com>
> > ---
> > Documentation/driver-api/iio/buffers.rst | 4 ++--
> > include/linux/iio/iio.h | 7 +++++--
> > 2 files changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/Documentation/driver-api/iio/buffers.rst b/Documentation/driver-api/iio/buffers.rst
> > index 63f364e862d1..f36e6d00173f 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 = 's',
> > .realbits = 12,
> > .storagebits = 16,
> > .shift = 4,
> > diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> > index a9ecff191bd9..61f1dfc14e02 100644
> > --- a/include/linux/iio/iio.h
> > +++ b/include/linux/iio/iio.h
> > @@ -178,7 +178,7 @@ struct iio_event_spec {
> >
> > /**
> > * struct iio_scan_type - specification for channel data format in buffer
> > - * @sign: 's' or 'u' to specify signed or unsigned
I think this is going to trigger kernel-doc warnings. So I'd keep the docs
but mention it's deprecated in favour of format.
> > + * @format: (signed or unsigned) integer, or floating point
>
> We should keep the list of valid values here.
>
> > * @realbits: Number of valid bits of data
> > * @storagebits: Realbits + padding
> > * @shift: Shift right by this before masking out realbits.
> > @@ -189,7 +189,10 @@ struct iio_event_spec {
> > * @endianness: little or big endian
> > */
> > struct iio_scan_type {
> > - char sign;
> > + union {
> > + char sign;
> > + char format;
>
> Could add some comments here to say that format should be used
> in new code and sign will be removed eventually.
>
> > + };
> > u8 realbits;
> > u8 storagebits;
> > u8 shift;
>
© 2016 - 2026 Red Hat, Inc.