Skip to content

IIO Subsystem

The Industrial I/O (IIO) subsystem is used for devices that produce sampled data, such as ADCs, sensors, and mixed-signal devices. It is more suitable than a custom character device when the device has channels, sampling frequency, triggers, buffers, scan elements, or timestamps.

What Problem It Solves

A sensor driver often needs to expose more than a single value:

  • multiple channels
  • raw and scaled values
  • sampling frequency
  • triggered buffer support
  • FIFO or watermark-based acquisition
  • timestamps
  • scan element layout

IIO provides a standard model for all of these features.

Core Concepts

Concept Description
iio_dev Main IIO device object registered by the driver.
Channel spec Describes available channels and scan layout.
read_raw() / write_raw() Standard callbacks for direct-mode attributes.
Trigger Controls when samples are captured.
Triggered buffer Kernel-side buffer path for streaming samples.
Scan mask Selects which channels are enabled in the buffer.
Timestamp Optional time reference attached to pushed samples.

Typical Driver Flow

probe()
allocate iio_dev
configure channels and iio_info
register trigger or triggered buffer
devm_iio_device_register()

For buffered acquisition:

IRQ / timer / trigger
iio_trigger_poll()
pollfunc reads samples
iio_push_to_buffers_with_timestamp()
/dev/iio:deviceX

Direct Mode vs Buffered Mode

Mode Use Case User-Space Interface
Direct mode Read one value on demand sysfs attributes such as in_voltage0_raw
Buffered mode Stream repeated samples /dev/iio:deviceX with enabled scan elements

Important Design Notes

  • Use direct mode for simple register reads and debugging.
  • Use triggered buffers when samples must be captured consistently.
  • Use timestamps carefully when FIFO data was sampled earlier than the push time.
  • Keep scan element layout and alignment consistent with the pushed frame.
  • Avoid mixing private sysfs control with standard IIO attributes unless there is a clear reason.