This is an old revision of the document!
This is a Linux industrial I/O (IIO) subsystem driver, targeting dual or quad channel serial interface ADCs. 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.
Function | File |
---|---|
core driver | drivers/iio/accel/adxl372.c |
spi driver | drivers/iio/accel/adxl372_spi.c |
i2c driver | drivers/iio/accel/adxl372_i2c.c |
header | drivers/iio/accel/adxl372.h |
Required devicetree properties:
Required properties for SPI bus usage:
Optional properties:
Example for a SPI device node:
#address-cells = <1>; #size-cells = <0>; status = "okay"; adxl372@0 { compatible = "adi,adxl372"; reg = <0>; spi-max-frequency = <1000000>; interrupts = <25 2>; interrupt-parent = <&gpio>; };
Example for a I2C device node:
#address-cells = <1>; #size-cells = <0>; status = "okay"; adxl372@53 { compatible = "adi,adxl372"; reg = <0x53>; interrupts = <25 2>; interrupt-parent = <&gpio>; };
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/bus/iio/devices/iio:device0> ls -l drwxr-xr-x 2 root root 0 Oct 25 04:25 buffer -rw-r--r-- 1 root root 4096 Oct 25 04:25 current_timestamp_clock -r--r--r-- 1 root root 4096 Oct 25 04:25 dev -rw-r--r-- 1 root root 4096 Oct 25 04:28 in_accel_filter_low_pass_3db_frequency -r--r--r-- 1 root root 4096 Oct 25 04:25 in_accel_filter_low_pass_3db_frequency_available -rw-r--r-- 1 root root 4096 Oct 25 04:27 in_accel_sampling_frequency -rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_scale -rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_x_raw -rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_y_raw -rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_z_raw -r--r--r-- 1 root root 4096 Oct 25 04:25 name lrwxrwxrwx 1 root root 0 Oct 25 04:25 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/adxl372@0 drwxr-xr-x 2 root root 0 Oct 25 04:25 power -r--r--r-- 1 root root 4096 Oct 25 04:25 sampling_frequency_available drwxr-xr-x 2 root root 0 Oct 25 04:25 scan_elements lrwxrwxrwx 1 root root 0 Oct 25 04:25 subsystem -> ../../../../../../../../bus/iio drwxr-xr-x 2 root root 0 Oct 25 04:25 trigger -rw-r--r-- 1 root root 4096 Oct 25 04:25 uevent
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat name adxl372
Description:
scale to be applied to in_accel_*_raw in order to obtain the acceleration.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat in_accel_scale 0.958241
Description:
Raw unscaled acceleration measurement on x axis
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw -5
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency_available 400 800 1600 3200 6400 root:/sys/bus/iio/devices/iio:device0> cat in_accel_sampling_frequency 6400 root:/sys/bus/iio/devices/iio:device0> echo 3200 > in_accel_sampling_frequency root:/sys/bus/iio/devices/iio:device0> cat in_accel_sampling_frequency 3200
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat in_accel_sampling_frequency 256000 root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency_available 200 400 800 1600 3200 root:/sys/bus/iio/devices/iio:device0>
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency_available 200 400 800 1600 3200 root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency 3200 root:/sys/bus/iio/devices/iio:device0> echo 1600 > in_accel_filter_low_pass_3db_frequency root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency 1600 root:/sys/bus/iio/devices/iio:device0> echo 3200 > in_accel_sampling_frequency root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency_available 200 400 800 1600 root:/sys/bus/iio/devices/iio:device0> echo 1600 > in_accel_sampling_frequency root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency 800
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0> cat trigger/current_trigger adxl372-dev-*
Description:
The scan_elements directory contains interfaces for elements that will be captured for a single triggered sample set in the buffer
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/scan_elements> ls -l -rw-r--r-- 1 root root 4096 Oct 25 08:08 in_accel_x_en -r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_x_index -r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_x_type -rw-r--r-- 1 root root 4096 Oct 25 08:08 in_accel_y_en -r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_y_index -r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_y_type -rw-r--r-- 1 root root 4096 Oct 25 08:08 in_accel_z_en -r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_z_index -r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_z_type -rw-r--r-- 1 root root 4096 Oct 25 08:08 in_timestamp_en -r--r--r-- 1 root root 4096 Oct 25 08:08 in_timestamp_index -r--r--r-- 1 root root 4096 Oct 25 08:08 in_timestamp_type root:/sys/bus/iio/devices/iio:device0/scan_elements>
Before enabling the buffer, a few steps need to be completed.
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_x_en root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_y_en root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_z_en
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/buffer> ls enable hwfifo_enabled hwfifo_watermark hwfifo_watermark_max hwfifo_watermark_min length watermark root:/sys/bus/iio/devices/iio:device0/buffer>
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/buffer> echo 1024 > length
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/buffer> echo 170 > watermark
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/buffer> echo 1 > enable
To read samples:
This specifies any shell prompt running on the target
root:/sys/bus/iio/devices/iio:device0/buffer> cat /dev/iio:device0
Some IIO drivers feature an optional debug facility, allowing users to read or write registers directly. Special care needs to be taken when using this feature, since you can modify registers on the back of the driver. Accessing debugfs requires root privileges.
In order to identify if the IIO device in question feature this option you first need to identify the IIO device number.
Therefore read the name attribute of each IIO device
This specifies any shell prompt running on the target
root@analog:~# grep "" /sys/bus/iio/devices/iio\:device*/name adxl372 root@analog:~#
Change directory to /sys/kernel/debug/iio/iio:deviceX and check if the direct_reg_access file exists.
This specifies any shell prompt running on the target
root@analog:~# cd /sys/kernel/debug/iio/iio\:device0/ root@analog:/sys/kernel/debug/iio/iio:device0# ls direct_reg_access ls direct_reg_access root@analog:/sys/kernel/debug/iio/iio:device0#
Reading
This specifies any shell prompt running on the target
root@analog:/sys/kernel/debug/iio/iio:device0# echo 0x0 > direct_reg_access root@analog:/sys/kernel/debug/iio/iio:device0# cat direct_reg_access 0xAD root@analog:/sys/kernel/debug/iio/iio:device0#
Writing
Write ADDRESS VALUE
This specifies any shell prompt running on the target
root@analog:/sys/kernel/debug/iio/iio:device0# echo 0x3D 0x80 > direct_reg_access root@analog:/sys/kernel/debug/iio/iio:device0# cat direct_reg_access 0x80 root@analog:/sys/kernel/debug/iio/iio:device0#