-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiiosubsys.html
More file actions
180 lines (178 loc) · 14.7 KB
/
iiosubsys.html
File metadata and controls
180 lines (178 loc) · 14.7 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Chapter 2. Industrial I/O core</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Industrial I/O driver developer's guide"><link rel="up" href="index.html" title="Industrial I/O driver developer's guide"><link rel="prev" href="intro.html" title="Chapter 1. Introduction"><link rel="next" href="API-struct-iio-dev.html" title="struct iio_dev"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. Industrial I/O core</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="API-struct-iio-dev.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="iiosubsys"></a>Chapter 2. Industrial I/O core</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="iiosubsys.html#iiodevice"> Industrial I/O devices </a></span></dt><dd><dl><dt><span class="sect2"><a href="iiosubsys.html#iioattr"> IIO device sysfs interface </a></span></dt><dt><span class="sect2"><a href="iiosubsys.html#iiochannel"> IIO device channels </a></span></dt></dl></dd><dt><span class="sect1"><a href="iiobuffer.html"> Industrial I/O buffers </a></span></dt><dd><dl><dt><span class="sect2"><a href="iiobuffer.html#iiobuffersysfs">IIO buffer sysfs interface </a></span></dt><dt><span class="sect2"><a href="iiobuffer.html#iiobuffersetup"> IIO buffer setup </a></span></dt></dl></dd><dt><span class="sect1"><a href="iiotrigger.html"> Industrial I/O triggers </a></span></dt><dd><dl><dt><span class="sect2"><a href="iiotrigger.html#iiotrigsysfs"> IIO trigger sysfs interface </a></span></dt><dt><span class="sect2"><a href="iiotrigger.html#iiotrigattr"> IIO trigger setup</a></span></dt><dt><span class="sect2"><a href="iiotrigger.html#iiotrigsetup"> IIO trigger ops</a></span></dt></dl></dd><dt><span class="sect1"><a href="iiotriggered_buffer.html"> Industrial I/O triggered buffers </a></span></dt><dd><dl><dt><span class="sect2"><a href="iiotriggered_buffer.html#iiotrigbufsetup"> IIO triggered buffer setup</a></span></dt></dl></dd></dl></div><p>
The Industrial I/O core offers:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
a unified framework for writing drivers for many different types of
embedded sensors.
</li><li class="listitem">
a standard interface to user space applications manipulating sensors.
</li></ul></div><p>
The implementation can be found under <code class="filename">
drivers/iio/industrialio-*</code>
</p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="iiodevice"></a> Industrial I/O devices </h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="refentrytitle"><a href="API-struct-iio-dev.html"><span class="phrase">struct iio_dev</span></a></span><span class="refpurpose"> —
industrial I/O device
</span></dt><dt><span class="refentrytitle"><a href="API-iio-device-alloc.html"><span class="phrase">iio_device_alloc</span></a></span><span class="refpurpose"> —
allocate an iio_dev from a driver
</span></dt><dt><span class="refentrytitle"><a href="API-iio-device-free.html"><span class="phrase">iio_device_free</span></a></span><span class="refpurpose"> —
free an iio_dev from a driver
</span></dt><dt><span class="refentrytitle"><a href="API-iio-device-register.html"><span class="phrase">iio_device_register</span></a></span><span class="refpurpose"> —
register a device with the IIO subsystem
</span></dt><dt><span class="refentrytitle"><a href="API-iio-device-unregister.html"><span class="phrase">iio_device_unregister</span></a></span><span class="refpurpose"> —
unregister a device from the IIO subsystem
</span></dt><dt><span class="sect2"><a href="iiosubsys.html#iioattr"> IIO device sysfs interface </a></span></dt><dt><span class="sect2"><a href="iiosubsys.html#iiochannel"> IIO device channels </a></span></dt></dl></div><p>
An IIO device usually corresponds to a single hardware sensor and it
provides all the information needed by a driver handling a device.
Let's first have a look at the functionality embedded in an IIO
device then we will show how a device driver makes use of an IIO
device.
</p><p>
There are two ways for a user space application to interact
with an IIO driver.
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="filename">/sys/bus/iio/iio:deviceX/</code>, this
represents a hardware sensor and groups together the data
channels of the same chip.
</li><li class="listitem"><code class="filename">/dev/iio:deviceX</code>, character device node
interface used for buffered data transfer and for events information
retrieval.
</li></ul></div><p>
</p>
A typical IIO driver will register itself as an I2C or SPI driver and will
create two routines, <code class="function"> probe </code> and <code class="function"> remove
</code>. At <code class="function">probe</code>:
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">call <code class="function">iio_device_alloc</code>, which allocates memory
for an IIO device.
</li><li class="listitem"> initialize IIO device fields with driver specific information
(e.g. device name, device channels).
</li><li class="listitem">call <code class="function"> iio_device_register</code>, this registers the
device with the IIO core. After this call the device is ready to accept
requests from user space applications.
</li></ul></div>
At <code class="function">remove</code>, we free the resources allocated in
<code class="function">probe</code> in reverse order:
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="function">iio_device_unregister</code>, unregister the device
from the IIO core.
</li><li class="listitem"><code class="function">iio_device_free</code>, free the memory allocated
for the IIO device.
</li></ul></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="iioattr"></a> IIO device sysfs interface </h3></div></div></div><p>
Attributes are sysfs files used to expose chip info and also allowing
applications to set various configuration parameters. For device
with index X, attributes can be found under
<code class="filename">/sys/bus/iio/iio:deviceX/ </code> directory.
Common attributes are:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="filename">name</code>, description of the physical
chip.
</li><li class="listitem"><code class="filename">dev</code>, shows the major:minor pair
associated with <code class="filename">/dev/iio:deviceX</code> node.
</li><li class="listitem"><code class="filename">sampling_frequency_available</code>,
available discrete set of sampling frequency values for
device.
</li></ul></div><p>
Available standard attributes for IIO devices are described in the
<code class="filename">Documentation/ABI/testing/sysfs-bus-iio </code> file
in the Linux kernel sources.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="iiochannel"></a> IIO device channels </h3></div></div></div><div class="toc"><dl class="toc"><dt><span class="refentrytitle"><a href="API-struct-iio-chan-spec.html"><span class="phrase">struct iio_chan_spec</span></a></span><span class="refpurpose"> —
specification of a single channel
</span></dt></dl></div><p>
An IIO device channel is a representation of a data channel. An
IIO device can have one or multiple channels. For example:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
a thermometer sensor has one channel representing the
temperature measurement.
</li><li class="listitem">
a light sensor with two channels indicating the measurements in
the visible and infrared spectrum.
</li><li class="listitem">
an accelerometer can have up to 3 channels representing
acceleration on X, Y and Z axes.
</li></ul></div><p>
An IIO channel is described by the <span class="type"> struct iio_chan_spec
</span>. A thermometer driver for the temperature sensor in the
example above would have to describe its channel as follows:
</p><pre class="programlisting">
static const struct iio_chan_spec temp_channel[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
},
};
</pre><p>
Channel sysfs attributes exposed to userspace are specified in
the form of <span class="emphasis"><em>bitmasks</em></span>. Depending on their
shared info, attributes can be set in one of the following masks:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><span class="emphasis"><em>info_mask_separate</em></span>, attributes will
be specific to this channel</li><li class="listitem"><span class="emphasis"><em>info_mask_shared_by_type</em></span>,
attributes are shared by all channels of the same type</li><li class="listitem"><span class="emphasis"><em>info_mask_shared_by_dir</em></span>, attributes
are shared by all channels of the same direction </li><li class="listitem"><span class="emphasis"><em>info_mask_shared_by_all</em></span>,
attributes are shared by all channels</li></ul></div><p>
When there are multiple data channels per channel type we have two
ways to distinguish between them:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> set <span class="emphasis"><em> .modified</em></span> field of <span class="type">
iio_chan_spec</span> to 1. Modifiers are specified using
<span class="emphasis"><em>.channel2</em></span> field of the same
<span class="type">iio_chan_spec</span> structure and are used to indicate a
physically unique characteristic of the channel such as its direction
or spectral response. For example, a light sensor can have two channels,
one for infrared light and one for both infrared and visible light.
</li><li class="listitem"> set <span class="emphasis"><em>.indexed </em></span> field of
<span class="type">iio_chan_spec</span> to 1. In this case the channel is
simply another instance with an index specified by the
<span class="emphasis"><em>.channel</em></span> field.
</li></ul></div><p>
Here is how we can make use of the channel's modifiers:
</p><pre class="programlisting">
static const struct iio_chan_spec light_channels[] = {
{
.type = IIO_INTENSITY,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_IR,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_INTENSITY,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_BOTH,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
}
</pre><p>
This channel's definition will generate two separate sysfs files
for raw data retrieval:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="filename">/sys/bus/iio/iio:deviceX/in_intensity_ir_raw</code></li><li class="listitem"><code class="filename">/sys/bus/iio/iio:deviceX/in_intensity_both_raw</code></li></ul></div><p>
one file for processed data:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="filename">/sys/bus/iio/iio:deviceX/in_illuminance_input
</code></li></ul></div><p>
and one shared sysfs file for sampling frequency:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="filename">/sys/bus/iio/iio:deviceX/sampling_frequency.
</code></li></ul></div><p>
</p><p>
Here is how we can make use of the channel's indexing:
</p><pre class="programlisting">
static const struct iio_chan_spec light_channels[] = {
{
.type = IIO_VOLTAGE,
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
},
{
.type = IIO_VOLTAGE,
.indexed = 1,
.channel = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
},
}
</pre><p>
This will generate two separate attributes files for raw data
retrieval:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="filename">/sys/bus/iio/devices/iio:deviceX/in_voltage0_raw</code>,
representing voltage measurement for channel 0.
</li><li class="listitem"><code class="filename">/sys/bus/iio/devices/iio:deviceX/in_voltage1_raw</code>,
representing voltage measurement for channel 1.
</li></ul></div><p>
</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="API-struct-iio-dev.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 1. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">struct iio_dev</span></td></tr></table></div></body></html>