DocBook documentation for IIO
Subsystems (2)
PATCH v2 1/1 DocBook documentation for IIO
In our effort to support vendors writing drivers for their own sensors we introduce IIO documentation in DocBook format.
It documents Industrial I/O core including IIO devices, buffers, triggers and triggered buffers. It also offers a short list of online resources for the IIO subsystem.
This is far from being complete any suggestions are welcomed. At a first glance we also need to add documentation for events. We are also working on auto-generating template drivers based on the type of the IIO sensors.
Generated html files should be available online here http://dbaluta.github.io/
or you could run make htmldocs in the root of your kernel repo to get them.
Changes since v1:
* mostly typos and clarifications
* addressed comments from Jonathan Corbet and Jonathan Cameron
* http://marc.info/?l=linux-iio&m=143704226629498&w=2
* http://marc.info/?l=linux-iio&m=143707511006898&w=2
* for DocBook warnings reported by Randy, Cristina (Cc'ed) will send a patch series fixes.
Daniel Baluta (1):
DocBook: Add initial documentation for IIO
Documentation/DocBook/Makefile | 2 +- Documentation/DocBook/iio.tmpl | 680 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 681 insertions(+), 1 deletion(-) create mode 100644 Documentation/DocBook/iio.tmpl
Signature · 1 line
1.9.1
PATCH v2 1/1 DocBook: Add initial documentation for IIO
This is intended to help developers faster find their way inside the Industrial I/O core and reduce time spent on IIO drivers development.
--- Documentation/DocBook/Makefile | 2 +- Documentation/DocBook/iio.tmpl | 680 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 681 insertions(+), 1 deletion(-) create mode 100644 Documentation/DocBook/iio.tmpl
Documentation/DocBook/Makefile +1 -1
@@ -15,7 +15,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \ 80211.xml debugobjects.xml sh.xml regulator.xml \ alsa-driver-api.xml writing-an-alsa-driver.xml \ tracepoint.xml drm.xml media_api.xml w1.xml \ - writing_musb_glue_layer.xml crypto-API.xml + writing_musb_glue_layer.xml crypto-API.xml iio.xml include Documentation/DocBook/media/Makefile
Documentation/DocBook/iio.tmpl new file +680 -0
680 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v2] DocBook: Add initial documentation for IIO
Quoted 5 lines · Daniel Baluta
This is intended to help developers faster find their way inside the Industrial I/O core and reduce time spent on IIO drivers development.
Signed-off-by Daniel Baluta <[email protected]>
Thanks for doing this.
Quoted 39 lines
Documentation/DocBook/iio.tmpl new file +33
-0@@ -0,0 +1,680 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" + "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> + +<book id="iioid"> + <bookinfo> + <title>Industrial I/O driver developer's guide </title> + + <authorgroup> + <author> + <firstname>Daniel</firstname> + <surname>Baluta</surname> + <affiliation> + <address> + <email>[email protected]</email> + </address> + </affiliation> + </author> + </authorgroup> + + <copyright> + <year>2015</year> + <holder>Intel Corporation</holder> + </copyright> + + <legalnotice> + <para> + This documentation is free software; you can redistribute + it and/or modify it under the terms of the GNU General Public + License version 2. + </para> + </legalnotice> + </bookinfo>
Documentation/DocBook/iio.tmpl line 43
Quoted 10 lines
Documentation/DocBook/iio.tmpl new file +10
-0+ + <toc></toc> + + <chapter id="intro"> + <title>Introduction</title> + <para> + The main purpose of the Industrial I/O subsystem (IIO) is to provide + support for devices that in some sense are analog to digital converters + (ADCs). As many actual devices combine some ADCs with digital to analog + converters (DACs), that functionality is also supported.
I wouldn't necessarily treat DACs and ADCs differently here. Maybe something like:
The main purpose of the Industrial I/O subsystem (IIO) is to provide support for devices that in some sense perform either analog-to-digital conversion (ADC) or digital-to-analog conversion (DAC) or both.
[...]
Quoted 22 lines
Documentation/DocBook/iio.tmpl new file +22
-0+ + <sect1 id="iiobuffer"> <title> Industrial I/O buffers </title> +!Finclude/linux/iio/buffer.h iio_buffer +!Edrivers/iio/industrialio-buffer.c + + <para> + The Industrial I/O core offers a way for continuous data capture + based on a trigger source. Multiple data channels can be read at once + from <filename>/dev/iio:deviceX</filename> character device node, + thus reducing the CPU load. + </para> + + <sect2 id="iiobuffersysfs"> + <title>IIO buffer sysfs interface </title> + <para> + An IIO buffer has an associated attributes directory under <filename> + /sys/bus/iio/iio:deviceX/buffer/</filename>. Here are the existing + attributes: + <itemizedlist> + <listitem> + <emphasis>length</emphasis>, number of data samples contained by the + buffer.
Documentation/DocBook/iio.tmpl line 365
Quoted 10 lines
Documentation/DocBook/iio.tmpl new file +10
-0+ </listitem> + <listitem> + <emphasis>enable</emphasis>, activate buffer capture. + </listitem> + </itemizedlist> + </para> + <para> In order to be useful, a buffer needs to have an associated + trigger. Future chapters will add details about triggers and how + drivers use triggers to start data capture, moving samples from device + registers to buffer storage and then upward to user space applications.
Buffers don't have to have a trigger, only triggered buffers need them. Although admittedly most buffers will be triggered buffers. I think it's better to talk about buffers in general first and then discuss the different types of buffers and when to use them. In this context it should be mentioned that a triggered buffer needs a trigger to function.
Quoted 26 lines
Documentation/DocBook/iio.tmpl new file +26
-0+ </para> + </sect2> + <sect2 id="iiobuffersetup"> <title> IIO buffer setup </title> + <para>The meta information associated with a channel reading + placed in a buffer is called a <emphasis> scan element </emphasis>. + The important bits configuring scan elements are exposed to + userspace applications via the <filename> + /sys/bus/iio/iio:deviceX/scan_elements/</filename> directory. This + file contains attributes of the following form: + <itemizedlist> + <listitem><emphasis>enable</emphasis>, used for enabling a channel. + If and only if its attribute is non zero, then a triggered capture + will contain data samples for this channel. + </listitem> + <listitem><emphasis>type</emphasis>, description of the scan element + data storage within the buffer and hence the form in which it is + read from user space. Format is <emphasis> + [be|le]:[s|u]bits/storagebits[>>shift] </emphasis>. + <itemizedlist> + <listitem> <emphasis>be</emphasis> or <emphasis>le</emphasis> specifies + big or little endian. + </listitem> + <listitem> + <emphasis>s </emphasis>or <emphasis>u</emphasis> specifies if + signed (2's complement) or unsigned. + </listitem>
Documentation/DocBook/iio.tmpl line 401
Quoted 10 lines
Documentation/DocBook/iio.tmpl new file +10
-0+ <listitem><emphasis>bits</emphasis> is the number of bits of data + </listitem> + <listitem><emphasis>storagebits</emphasis> is the space (after padding) + that it occupies in the buffer. + </listitem> + <listitem> + <emphasis>shift</emphasis> if specified, is the shift that needs + to be a applied prior to masking out unused bits + </listitem> + </itemizedlist>
The scan type gained a repeat field a while ago.
Quoted 55 lines
Documentation/DocBook/iio.tmpl new file +55
-0+ </listitem> + </itemizedlist> + For example, a driver for a 3-axis accelerometer with 12 bit + resolution where data is stored in two 8-bits registers as + follows: + <programlisting> + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + |D3 |D2 |D1 |D0 | X | X | X | X | (LOW byte, address 0x06) + +---+---+---+---+---+---+---+---+ + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + |D11|D10|D9 |D8 |D7 |D6 |D5 |D4 | (HIGH byte, address 0x07) + +---+---+---+---+---+---+---+---+ + </programlisting> + + will have the following scan element type for each axis: + <programlisting> + $ cat /sys/bus/iio/devices/iio:device0/scan_elements/in_accel_y_type + le:s12/16>>4 + </programlisting> + The userspace applications will interpret data samples read from buffer + as two byte little endian signed data, that needs a 4 bits right + shift before masking out the only 12 valid bits of real data. + </para> + <para> + For implementing buffer support a driver should initialize the following + fields in <type>iio_chan_spec</type> definition: + <programlisting> + struct iio_chan_spec { + /* other members */ + int scan_index + struct { + char sign; + u8 realbits; + u8 storagebits; + u8 shift; + enum iio_endian endianness; + } scan_type; + }; + </programlisting> + The driver implementing the accelerometer described above will + have the following channel definition: + <programlisting> + struct struct iio_chan_spec accel_channels[] = { + { + .type = IIO_ACCEL, + .modified = 1, + .channel2 = IIO_MOD_X, + /* other stuff here */ + .scan_index = 0, + .scan_type = { + .sign = 's', + .realbits = 12,
Documentation/DocBook/iio.tmpl line 466
Quoted 10 lines
Documentation/DocBook/iio.tmpl new file +10
-0+ .storgebits = 16, + .shift = 4, + .endianness = IIO_LE, + }, + } + /* similar for Y and Z axis */ + } + </programlisting> + Here <emphasis> scan_index </emphasis> is used for ordering data samples + (scans) when read from buffer.
A bit more:
scan_index defines the relative order in which the enabled channels are placed inside the buffer, a channel with a lower scan_index will be placed before a channel with a higher index. Each channels needs to have a unique scan_index.
It is important to realize that the scan_index does not define the absolution position in the buffer. E.g. a channel with the scan_index = 3 will not be at offset 3 bytes or 3 words, but rather will be placed in the buffer after any channel with a scan_index lower than 3 and before any channel with a scan_index larger than 3.
Furthermore the scan indices do not have to be consecutive. E.g. A channel spec array that defines 3 channels with the indices 1, 2 and 3 is just as valid as a channel spec that uses the indices 100, 200, 300. The relative order of the channels will be the same.
Setting scan_index to -1 can be used to indicate that the specific channel does not support buffered capture. In this case no entries will be created for the channel in the scan_elements directory.
Otherwise looks good to me.
- Lars
Re: [PATCH v2] DocBook: Add initial documentation for IIO
<snip>
Quoted 9 lines
Quoted 1 line
+ converters (DACs), that functionality is also supported.
I wouldn't necessarily treat DACs and ADCs differently here. Maybe something like:
The main purpose of the Industrial I/O subsystem (IIO) is to provide support for devices that in some sense perform either analog-to-digital conversion (ADC) or digital-to-analog conversion (DAC) or both.
Ok. Fixed.
Quoted 8 lines
Quoted 6 lines
Documentation/DocBook/iio.tmpl new file +3
-0+ <para> In order to be useful, a buffer needs to have an associated + trigger. Future chapters will add details about triggers and how + drivers use triggers to start data capture, moving samples fromdevice
+ registers to buffer storage and then upward to user space
applications.
Quoted 5 lines
Buffers don't have to have a trigger, only triggered buffers need them. Although admittedly most buffers will be triggered buffers. I think it's better to talk about buffers in general first and then discuss the different types of buffers and when to use them. In this context it should be mentioned that a triggered buffer needs a trigger to function.
I removed this paragraph for the moment, will try to add more info about buffer here with a follow up patch.
<snip>
Quoted 4 lines
Quoted 1 line
+ </itemizedlist>
The scan type gained a repeat field a while ago.
Nice catch. Fixed. Also will send a patch to fix the ABI entry description.
<snip>
Quoted 18 lines
Quoted 3 lines
+ Here <emphasis>
scan_index</emphasis> is used for ordering data
samples
+ (scans) when read from buffer.A bit more:
scan_indexdefines the relative order in which the enabled channels are placed inside the buffer, a channel with a lowerscan_indexwill be placed before a channel with a higher index. Each channels needs to have a uniquescan_index.It is important to realize that the
scan_indexdoes not define the absolution position in the buffer. E.g. a channel with thescan_index= 3 will not be at offset 3 bytes or 3 words, but rather will be placed in the buffer after any channel with ascan_indexlower than 3 and before any channel with ascan_indexlarger than 3.
Quoted 8 lines
Furthermore the scan indices do not have to be consecutive. E.g. A channel spec array that defines 3 channels with the indices 1, 2 and 3 is just as valid as a channel spec that uses the indices 100, 200, 300. The relative order of the channels will be the same.
Setting
scan_indexto -1 can be used to indicate that the specific channel does not support buffered capture. In this case no entries will be created for the channel in thescan_elementsdirectory.
Nice. I've included this in the documentation.
Thanks a lot Lars for your review.
Daniel.