blob: 2e798f9e90432fd27bdfc14fc08bca125cc573ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
@page page_device_iio Industrial I/O (IIO)
# IIO (Industrial I/O)
Device-tree **`io-channels`** binding and DM integration: @ref page_device_iio_dm.
## Overview
`drivers/iio.h` offers a small **channel discovery** API: `rt_iio_channel_get_by_index` and `rt_iio_channel_get_by_name` resolve a channel handle and index from a `rt_device`. IIO is a light abstraction for **ADC, DAC, temperature, accelerometer**, and similar sensors; data format and calibration are driver-specific.
## Usage
1. Associate consumer and provider via device tree `io-channels` / `io-channel-names` or private matching.
2. Call the `get` helpers for an opaque channel pointer and logical index, then use the provider’s read/write path (usually wrapped inside the driver).
## DM relation
Providers are commonly `platform` devices: `probe` brings up clocks, resets, and calibration, then registers the device. Phandle-based dependencies mirror Linux IIO bindings and ease porting.
## Practical limits (current API)
`drivers/iio.h` only exposes **`rt_iio_channel_get_by_index`** and **`rt_iio_channel_get_by_name`** returning an **opaque `void *`** channel cookie plus **`out_channel`** index. There is **no standard `put`** in this header—lifetime is **owned by the provider `rt_device`**; do not use the handle after the provider unregisters.
## When IIO glue helps
| Use IIO discovery when… | Skip it when… |
| --- | --- |
| Porting **Linux `io-channels`** consumers and you want matching property names. | You already have a **private `ioctl`** between two in-tree drivers. |
## Consumer flow
1. **`get_by_*`** after provider `probe` has finished (phandles resolved).
2. Pass **`out_channel`** index into **your provider’s** read/write routine (implemented alongside the ADC driver).
3. On remove, drop references to the **`rt_device`** only—no separate channel free unless your provider documents one.
## Pitfalls
- **Opaque pointer** is not a `struct iio_channel` like Linux—do not cast blindly across drivers.
- **Missing provider**: returns **`NULL`**—always check before dereference.
## See also
- `components/drivers/include/drivers/iio.h`
- Platform: `documentation/6.components/device-driver/platform/platform.md`
|