Wiki

This version is outdated by a newer approved version.DiffThis version (05 Jan 2021 22:17) was approved by Robin Getz.The Previously approved version (11 Feb 2016 20:49) is available.Diff

This is an old revision of the document!


AD7150 IIO Capacitance to Digital Converter Linux Driver

Supported Devices

Evaluation Boards

Description

This is a Linux industrial I/O (IIO) subsystem driver, targeting single and multi channel serial interface Capacitance to Digital Converters. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (i2c, spi, etc). See IIO for more information.

Source Code

Status

Source Mainlined?
git git

Files

Function File
driver drivers/staging/iio/cdc/ad7150.c

Declaring I2C devices

Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.

This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().

So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.

For more information see: Documentation/i2c/instantiating-devices.rst

21 Oct 2010 16:10

Depending on the converter IC used, you may need to set the I2C_BOARD_INFO name accordingly, matching your part name.

ADI part number I2C_BOARD_INFO Name
AD7150 ad7150
AD7151 ad7151
AD7156 ad7156
static struct i2c_board_info __initdata board_i2c_board_info[] = {
#if defined(CONFIG_AD7150) || defined(CONFIG_AD7150_MODULE)
	{
		I2C_BOARD_INFO("ad7150", 0x48),
	},
#endif
};
static int __init board_init(void)
{
	[--snip--]
 
	i2c_register_board_info(0, board_i2c_board_info,
				ARRAY_SIZE(board_i2c_board_info));
	[--snip--]
 
	return 0;
}
arch_initcall(board_init);

Adding Linux driver support

Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)

The driver depends on CONFIG_I2C

Linux Kernel Configuration
	Device Drivers  --->
		[*] Staging drivers  --->
			<*>     Industrial I/O support --->
			    --- Industrial I/O support
			    -*-   Enable ring buffer support within IIO
			    -*-     Industrial I/O lock free software ring
			    -*-   Enable triggered sampling support

			    [--snip--]

				***
 Analog to digital converters ***
			    <*>   Analog Devices AD7150/1/6 capacitive sensor driver

			    [--snip--]

Hardware configuration

Driver testing

Each and every IIO device, typically a hardware chip, has a device folder under /sys/bus/iio/devices/iio:deviceX. Where X is the IIO index of the device. Under every of these directory folders reside a set of files, depending on the characteristics and features of the hardware device in question. These files are consistently generalized and documented in the IIO ABI documentation. In order to determine which IIO deviceX corresponds to which hardware device, the user can read the name file /sys/bus/iio/devices/iio:deviceX/name. In case the sequence in which the iio device drivers are loaded/registered is constant, the numbering is constant and may be known in advance.

02 Mar 2011 15:16

This specifies any shell prompt running on the target

root:/> cd /sys/bus/iio/devices/
root:/sys/bus/iio/devices> ls
iio:device0
root:/sys/bus/iio/devices> cd iio:device0

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> ls -l
-r--r--r--    1 root     root          4096 Jan  3 04:21 dev
drwxr-xr-x    2 root     root             0 Jan  3 04:21 events
-rw-r--r--    1 root     root          4096 Jan  3 04:21 in_capacitance0_mean_raw
-r--r--r--    1 root     root          4096 Jan  3 04:21 in_capacitance0_raw
-rw-r--r--    1 root     root          4096 Jan  3 04:21 in_capacitance1_mean_raw
-r--r--r--    1 root     root          4096 Jan  3 04:21 in_capacitance1_raw
-r--r--r--    1 root     root          4096 Jan  3 04:21 name
drwxr-xr-x    2 root     root             0 Jan  3 04:21 power
lrwxrwxrwx    1 root     root             0 Jan  3 04:21 subsystem -> ../../../../../../bus/iio
-rw-r--r--    1 root     root          4096 Jan  3 04:21 uevent

Show device name

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat name
ad7150

Show channel CIN1(+) measurement

ADC Input Pair Comment Channel name
CIN1(+) actual value in_capacitance0_raw
CIN1(+) average value in_capacitance0_mean_raw
CIN2(+) actual value in_capacitance1_raw
CIN2(+) average value in_capacitance1_mean_raw

Description:
Raw unscaled capacitance measurement on channel in_capacitance0_raw

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance0_raw
26640

Show channel CIN1(+) average measurement

Description:
Raw unscaled capacitance measurement on channel in_capacitance0_mean_raw

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance0_mean_raw
26273

Hardware Events

Event Management

The Industrial I/O subsystem provides support for passing hardware generated events up to userspace.

In IIO events are not used for passing normal readings from the sensing devices to userspace, but rather for out of band information. Normal data reaches userspace through a low overhead character device - typically via either software or hardware buffer. The stream format is pseudo fixed, so is described and controlled via sysfs rather than adding headers to the data describing what is in it.

Pretty much all IIO events correspond to thresholds on some value derived from one or more raw readings from the sensor. They are provided by the underlying hardware.

Examples include:

  • Straight crossing a voltage threshold
  • Moving average crosses a threshold
  • Motion detectors (lots of ways of doing this).
  • Thresholds on sum squared or rms values.
  • Rate of change thresholds.
  • Lots more variants…

Events have timestamps.

The Interface:

  • Single user at a time.
  • Simple chrdev per device (aggregation across devices doesn't really make sense for IIO as you tend to really care which sensor caused the event rather than just that it happened.)

The format is:

/**
 * struct iio_event_data - The actual event being pushed to userspace
 * @id:		event identifier
 * @timestamp:	best estimate of time of event occurrence (often from
 *		the interrupt handler)
 */
struct iio_event_data {
	u64	id;
	s64	timestamp;
};
02 Mar 2011 15:16

Typical event attributes

/sys/bus/iio/devices/iio:deviceX/events
Configuration of which hardware generated events are passed up to user-space.

  • Threshold Events:

<type>Z[_name]_thresh[_rising|falling]_en
Event generated when channel passes a threshold in the specified (_rising|_falling) direction. If the direction is not specified, then either the device will report an event which ever direction a single threshold value is called in (e.g. <type>[Z][_name]_<raw|input>_thresh_value) or <type>[Z][_name]_<raw|input>_thresh_rising_value and <type>[Z][_name]_<raw|input>_thresh_falling_value may take different values, but the device can only enable both thresholds or neither. Note the driver will assume the last p events requested are to be enabled where p is however many it supports (which may vary depending on the exact set requested. So if you want to be sure you have set what you think you have, check the contents of these attributes after everything is configured. Drivers may have to buffer any parameters so that they are consistent when a given event type is enabled a future point (and not those for whatever event was previously enabled).

<type>Z[_name]_thresh[_rising|falling]_value
Specifies the value of threshold that the device is comparing against for the events enabled by <type>Z[_name]_thresh[_rising|falling]_en. If separate attributes exist for the two directions, but direction is not specified for this attribute, then a single threshold value applies to both directions. The raw or input element of the name indicates whether the value is in raw device units or in processed units (as _raw and _input do on sysfs direct channel read attributes).

  • Rate of Change Events:

<type>[Z][_name]_roc[_rising|falling]_en
Event generated when channel passes a threshold on the rate of change (1st differential) in the specified (_rising|_falling) direction. If the direction is not specified, then either the device will report an event which ever direction a single threshold value is called in (e.g. <type>[Z][_name]_<raw|input>_roc_value) or <type>[Z][_name]_<raw|input>_roc_rising_value and <type>[Z][_name]_<raw|input>_roc_falling_value may take different values, but the device can only enable both rate of change thresholds or neither. Note the driver will assume the last p events requested are to be enabled where p is however many it supports (which may vary depending on the exact set requested. So if you want to be sure you have set what you think you have, check the contents of these attributes after everything is configured. Drivers may have to buffer any parameters so that they are consistent when a given event type is enabled a future point (and not those for whatever event was previously enabled).

<type>[Z][_name]_roc[_rising|falling]_value
Specifies the value of rate of change threshold that the device is comparing against for the events enabled by <type>[Z][_name]_roc[_rising|falling]_en. If separate attributes exist for the two directions, but direction is not specified for this attribute, then a single threshold value applies to both directions. The raw or input element of the name indicates whether the value is in raw device units or in processed units (as _raw and _input do on sysfs direct channel read attributes).

  • Magnitude Events:

<type>Z[_name]_mag[_rising|falling]_en
Similar to in_accel_x_thresh[_rising|_falling]_en, but here the magnitude of the channel is compared to the threshold, not its signed value.

<type>Z[_name]_mag[_rising|falling]_value
The value to which the magnitude of the channel is compared. If number or direction is not specified, applies to all channels of this type.

  • Temporal Conditions:

<type>[Z][_name][_thresh|_roc][_rising|falling]_period
Period of time (in seconds) for which the condition must be met before an event is generated. If direction is not specified then this period applies to both directions.

02 Mar 2011 15:16

Supported Events

Event Attributes
Channel 1
in_capacitance0_mag_adaptive_falling_en
in_capacitance0_mag_adaptive_falling_timeout
in_capacitance0_mag_adaptive_falling_value
in_capacitance0_mag_adaptive_rising_en
in_capacitance0_mag_adaptive_rising_timeout
in_capacitance0_mag_adaptive_rising_value
in_capacitance0_thresh_adaptive_falling_en
in_capacitance0_thresh_adaptive_falling_timeout
in_capacitance0_thresh_adaptive_falling_value
in_capacitance0_thresh_adaptive_rising_en
in_capacitance0_thresh_adaptive_rising_timeout
in_capacitance0_thresh_adaptive_rising_value
in_capacitance0_thresh_falling_en
in_capacitance0_thresh_falling_value
in_capacitance0_thresh_rising_en
in_capacitance0_thresh_rising_value
Channel 2
in_capacitance1_mag_adaptive_falling_en
in_capacitance1_mag_adaptive_falling_timeout
in_capacitance1_mag_adaptive_falling_value
in_capacitance1_mag_adaptive_rising_en
in_capacitance1_mag_adaptive_rising_timeout
in_capacitance1_mag_adaptive_rising_value
in_capacitance1_thresh_adaptive_falling_en
in_capacitance1_thresh_adaptive_falling_timeout
in_capacitance1_thresh_adaptive_falling_value
in_capacitance1_thresh_adaptive_rising_en
in_capacitance1_thresh_adaptive_rising_timeout
in_capacitance1_thresh_adaptive_rising_value
in_capacitance1_thresh_falling_en
in_capacitance1_thresh_falling_value
in_capacitance1_thresh_rising_en
in_capacitance1_thresh_rising_value

More Information

resources/tools-software/linux-drivers/iio-cdc/ad7150.1609859400.txt.gz · Last modified: 05 Jan 2021 16:10 by Ioana Chelaru