Day33 - Minimal IIO Driver (Single Channel, Direct Mode)¶
Overview¶
This day focuses on implementing a minimal IIO driver to understand:
- How IIO devices are registered
- How sysfs attributes are generated automatically
- How user-space maps to driver callbacks
The driver is intentionally simple:
- Single channel (voltage0)
- No buffer
- No trigger
- Only
read_raw()supported
Key Concepts¶
1. IIO Device Lifecycle¶
module load
↓
platform_device created
↓
platform_driver probe()
↓
iio_device_register()
↓
/sys/bus/iio/devices/iio:deviceX appears
Important¶
- An IIO device is NOT created at module load
- It is created inside
probe() - A matching device must exist for probe to run
2. struct iio_dev¶
Represents an IIO device instance.
Similar to:
struct mygpio_devstruct mysensor_data
But managed by the IIO framework.
3. Channel Definition (iio_chan_spec)¶
This directly generates:
Key Insight¶
sysfs attribute names are derived from channel metadata, not manually created.
4. info_mask¶
Controls which attributes appear in sysfs.
| Flag | Result |
|---|---|
| RAW | in_voltage0_raw |
| SCALE | in_voltage0_scale |
5. read_raw()¶
Handles all data access.
Mapping:
| sysfs | mask |
|---|---|
| in_voltage0_raw | IIO_CHAN_INFO_RAW |
| in_voltage0_scale | IIO_CHAN_INFO_SCALE |
6. Return Value Format¶
Example:
Meaning:
Example:
Data Flow¶
sysfs read¶
Comparison with Previous Work¶
vs hwmon¶
| hwmon | IIO |
|---|---|
| Manual sysfs | Auto-generated sysfs |
| show() functions | read_raw() |
| Fixed attributes | Channel-driven attributes |
vs Character Driver¶
| Char driver | IIO |
|---|---|
| read/write | read_raw |
| protocol-based | measurement-based |
| user-defined format | framework-defined format |
vs TTY¶
| TTY | IIO |
|---|---|
| byte stream | structured data |
| flip buffer | IIO buffer (future) |
| RX-driven | trigger-driven |
Limitations of Current Implementation¶
This minimal driver:
- Does NOT support buffer
- Does NOT support trigger
- Does NOT support multi-channel
It behaves like:
Key Takeaways¶
- IIO sysfs is automatically generated from channel metadata
read_raw()is the central data path- Device must exist before probe runs
- IIO abstraction is higher than hwmon
Next Step (Day34)¶
- Multi-channel support
- Deeper dive into
iio_chan_spec - Prepare for buffer / scan elements