Wiki

This version (18 Apr 2023 09:56) was approved by Nuno Sá.The Previously approved version (17 Aug 2022 11:17) is available.Diff

AD74413R/AD74412R Quad-Channel, Software Configurable, Input and Output Circuit Linux Driver

Supported Devices

Evaluation Boards

Source Code

Status

Source Mainlined?
git Yes

Files

Function File
core driver ad74413r.c
Documentation adi,ad74413r.yaml

Example device tree

Function File
dts rpi-ad74413r-overlay.dts

Driver testing

When configured with channel 0 as voltage output, channel 1 as current output, channel 2 as voltage input and channel 3 as current input, the following structure is created under the corresponding IIO device.

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 Aug 17 09:56 buffer
-r--r--r-- 1 root root 4096 Aug 17 09:56 dev
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current0_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current3_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_scale
-r--r--r-- 1 root root 4096 Aug 17 09:56 name
lrwxrwxrwx 1 root root    0 Aug 17 09:56 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/ad74413r@0
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_current1_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_current1_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_voltage0_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_voltage0_scale
drwxr-xr-x 2 root root    0 Aug 17 09:56 power
drwxr-xr-x 2 root root    0 Aug 17 09:56 scan_elements
lrwxrwxrwx 1 root root    0 Aug 17 09:56 subsystem -> ../../../../../../../../bus/iio
drwxr-xr-x 2 root root    0 Aug 17 09:56 trigger
-rw-r--r-- 1 root root 4096 Aug 17 09:56 uevent

Show device name

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat name
ad74413r

Show raw measurement

Description:
Raw measurement of current on channel 0.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_current0_raw
4608

Show scale

Description:
Scale to be applied to the raw measurement of current on channel 0 in order to obtain the actual current.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_current0_scale
0.001525902

Set sampling frequency

Description:
Show available sampling frequencies and select one for channel 0.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_current0_sampling_frequency_available
10 20 1200 4800
root:/sys/bus/iio/devices/iio:device0> cat in_current0_sampling_frequency
20
root:/sys/bus/iio/devices/iio:device0> echo 4800 > in_current0_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_current0_sampling_frequency
4800

Buffer management

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> cd scan_elements/
root:/sys/bus/iio/devices/iio:device0/scan_elements> ls -l
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current0_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current0_type
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current3_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current3_type
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_type
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_type

Before enabling the buffer, a few steps need to be completed.

  • For example, if we want to capture all input channels, we need to enable the scan elements:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_current0_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_voltage1_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_voltage2_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_current3_en

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/scan_elements> cd ../buffer/
root:/sys/bus/iio/devices/iio:device0/buffer> ls -l
-r--r--r-- 1 root root 4096 Aug 17 09:56 data_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 enable
-rw-r--r-- 1 root root 4096 Aug 17 09:56 length
-rw-r--r-- 1 root root 4096 Aug 17 09:56 watermark

  • Set the buffer length:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1024 > length

  • Set the watermak:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 512 > watermark

  • Enable the buffer:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1 > enable

  • Read the samples:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> cat /dev/iio:device0

Low level register access via debugfs (direct_reg_access)

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.

This specifies any shell prompt running on the target

root:/> /sys/kernel/debug/iio/iio:device0/
root:/sys/kernel/debug/iio/iio:device0> ls direct_reg_access  
direct_reg_access

Reading

This specifies any shell prompt running on the target

root:/sys/kernel/debug/iio/iio:device0> echo 0x45 > direct_reg_access
root:/sys/kernel/debug/iio/iio:device0> cat direct_reg_access 
0x00

Writing

Write ADDRESS VALUE

This specifies any shell prompt running on the target

root@analog:/sys/kernel/debug/iio/iio:device0> echo 0x45 0xADAD > direct_reg_access   
root@analog:/sys/kernel/debug/iio/iio:device0> cat direct_reg_access 
0xADAD

More Information

resources/tools-software/linux-drivers/iio-addac/ad74413r.txt · Last modified: 18 Apr 2023 09:56 by Nuno Sá