The IIO subsystem
The best place to start with the IIO subsystem is the iio_dummy module, which is a toy DD. This module has thousands of valuable comments that aid developers to understand the IIO internal
The IIO Dummy Channels Setup
The heart of an IIO driver is the struct iio_chan_spec. It defines the target device’s capabilities.
Definition: Channel > An IIO device channel is a representation of a data channel. A single device can have multiple channels (e.g., an accelerometer with X, Y, and Z axes).
The iio_dummy_read_raw() Function
This function handles data requests. It reads from the driver’s internal state (iio_dummy_state) and populates the val and val2 pointers.
The iio_dummy_write_raw() Function
Similar to the read function, this writes values from userspace into the iio_dummy_state. Notice that we use a mutex lock only when modifying the state to ensure consistency.
Putting Things Together: The Probe Function
The probe function is where the driver “comes to life.” It typically handles three main tasks:
-
Allocation: Memory for the IIO device and its private state.
-
Initialization: Setting up mutexes, device names, and channel descriptions.
-
Registration: Making the device known to the kernel and userspace (sysfs).
By studying iio_simple_dummy, we see how the kernel abstracts complex sensors into a clean set of channels and raw I/O functions
We can find the module in /home/lk_dev/iio/drivers/iio/dummy.
https://www.kernel.org/doc/html/latest/driver-api/iio/index.html