Documentation/driver-api/iio/core.rst

Source file repositories/reference/linux-study-clean/Documentation/driver-api/iio/core.rst

File Facts

System
Linux kernel
Corpus path
Documentation/driver-api/iio/core.rst
Extension
.rst
Size
6965 bytes
Lines
183
Domain
Support Tooling And Documentation
Bucket
Documentation
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

=============
Core elements
=============

The Industrial I/O core offers both a unified framework for writing drivers for
many different types of embedded sensors and a standard interface to user space
applications manipulating sensors. The implementation can be found under
:file:`drivers/iio/industrialio-*`

Industrial I/O Devices
----------------------

* struct iio_dev - industrial I/O device
* iio_device_alloc() - allocate an :c:type:`iio_dev` from a driver
* iio_device_free() - free an :c:type:`iio_dev` from a driver
* iio_device_register() - register a device with the IIO subsystem
* iio_device_unregister() - unregister a device from the IIO
  subsystem

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.

There are two ways for a user space application to interact with an IIO driver.

1. :file:`/sys/bus/iio/devices/iio:device{X}/`, this represents a hardware sensor
   and groups together the data channels of the same chip.
2. :file:`/dev/iio:device{X}`, character device node interface used for
   buffered data transfer and for events information retrieval.

A typical IIO driver will register itself as an :doc:`I2C <../i2c>` or
:doc:`SPI <../spi>` driver and will create two routines, probe and remove.

At probe:

1. Call iio_device_alloc(), which allocates memory for an IIO device.
2. Initialize IIO device fields with driver specific information (e.g.
   device name, device channels).
3. Call iio_device_register(), this registers the device with the
   IIO core. After this call the device is ready to accept requests from user
   space applications.

At remove, we free the resources allocated in probe in reverse order:

1. iio_device_unregister(), unregister the device from the IIO core.
2. iio_device_free(), free the memory allocated for the IIO device.

IIO device sysfs interface
==========================

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 /sys/bus/iio/devices/iio:deviceX/
directory.  Common attributes are:

* :file:`name`, description of the physical chip.
* :file:`dev`, shows the major:minor pair associated with
  :file:`/dev/iio:deviceX` node.
* :file:`sampling_frequency_available`, available discrete set of sampling
  frequency values for device.
* Available standard attributes for IIO devices are described in the
  :file:Documentation/ABI/testing/sysfs-bus-iio file in the Linux kernel
  sources.

IIO device channels
===================

struct iio_chan_spec - specification of a single channel

Annotation

Implementation Notes