This is an old revision of the document!
The AD5593R have eight I/Ox pins (I/O0 to I/O7) that can be independently configured as digital-to-analog converter (DAC) outputs, analog-to-digital converter (ADC) inputs, digital outputs, or digital inputs.
When an I/Ox pin is configured as an analog output, it is driven by a 12-bit DAC. The output range of the DAC is 0 V to VREF or 0 V to 2 × VREF.
When an I/Ox pin is configured as an analog input, it is connected to a 12-bit ADC via an analog multiplexer. The input range of the ADC is 0 V to VREF or 0 V to 2 × VREF. The ADC has a total throughput rate of 400 kSPS.
The I/Ox pins can also be configured as digital, general-purpose input or output (GPIO) pins. The state of the GPIO pins can be set or read back by accessing the GPIO write data register or the GPIO read configuration register, respectively, via an I2C write or read operation.
The AD5593R have an integrated 2.5 V, 25 ppm/°C reference, which is turned off by default, and an integrated temperature indicator, which gives an indication of the die temperature. The temperature value is read back as part of an ADC read sequence.
Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)
The AD5593R Driver depends on CONFIG_I2C
Linux Kernel Configuration Device Drivers ---> ... <*> Industrial I/O support ---> --- Industrial I/O support ... Digital to analog converters ---> ... <*> Analog Devices AD5593R ADC/DAC driver ... ... ...
The following example instanciates the ad5593r driver for a AD5593R device connected on a I2C bus. It sets the I/O0 port as a DAC, the I/O1 port as ADC. I/O2 and I/O3 are configured for primary function DAC the additional ADC can measure the voltage being provided by the DAC. This feature can monitor the output voltage to detect short circuits or overload conditions. I/O4 is connected to the ground with a pull-down resistor. The other I/Os are registered with the Linux GPIO subsystem.
#include <dt-bindings/iio/adi,ad5592r.h> vref: regulator-vref { compatible = "regulator-fixed"; regulator-name = "vref-ad559x"; regulator-min-microvolt = <3300000>; regulator-max-microvolt = <3300000>; regulator-always-on; }; &i2c0 { status = "okay"; clock-frequency = <400000>; ad5593r@10 { compatible = "adi,ad5593r"; reg = <0x10>; channel-modes = /bits/ 8 < CH_MODE_DAC CH_MODE_ADC CH_MODE_DAC_AND_ADC CH_MODE_DAC_AND_ADC CH_MODE_UNUSED_PULL_DOWN CH_MODE_GPIO CH_MODE_GPIO CH_MODE_GPIO >; vref-supply = <&vref>; /* optional */ reset-gpios = <&gpio0 86 0>; /* optional */ }; };
If the driver correctly detected the device, the “iio_info” program should inform us about the available channels:
root@linaro-ubuntu-desktop:~# iio_info IIO context created: local IIO context has 3 devices: iio:device2: ad5593r 7 channels found: voltage0: (output) 3 channel-specific attributes found: attr 0: raw value: 0 attr 1: scale_available value: 0.732421875 1.464843750 attr 2: scale value: 0.732421875 voltage2: (output) 3 channel-specific attributes found: attr 0: raw value: 0 attr 1: scale_available value: 0.732421875 1.464843750 attr 2: scale value: 0.732421875 voltage3: (output) 3 channel-specific attributes found: attr 0: raw value: 0 attr 1: scale_available value: 0.732421875 1.464843750 attr 2: scale value: 0.732421875 voltage1: (input) 3 channel-specific attributes found: attr 0: raw value: 0 attr 1: scale value: 0.732421875 attr 2: scale_available value: 0.732421875 1.464843750 voltage2: (input) 3 channel-specific attributes found: attr 0: raw value: 1 attr 1: scale value: 0.732421875 attr 2: scale_available value: 0.732421875 1.464843750 voltage3: (input) 3 channel-specific attributes found: attr 0: raw value: 0 attr 1: scale value: 0.732421875 attr 2: scale_available value: 0.732421875 1.464843750 temp: (input) 3 channel-specific attributes found: attr 0: offset value: -628 attr 1: raw value: 680 attr 2: scale value: 452.147700000
The GPIO sysfs interface allows users to manipulate any GPIO from userspace. Userspace utilizes a sysfs control interface to dynamically request and release individual GPIOs. Once a GPIO has been requested, writing to the newly created path allows you to control the direction and the data while reading from it returns the GPIO data (which usually corresponds to a 0 or 1 which represents the signal level).
For more information see also here: GPIO Kernel Documentation
root@linaro-ubuntu-desktop:~# cd /sys/class/gpio/ root@linaro-ubuntu-desktop:/sys/class/gpio# ls export gpiochip890 gpiochip898 gpiochip906 unexport root@linaro-ubuntu-desktop:/sys/class/gpio# cd gpiochip890 root@linaro-ubuntu-desktop:/sys/class/gpio/gpiochip890# ls -al total 0 drwxr-xr-x 3 root root 0 Jan 1 1970 . drwxr-xr-x 3 root root 0 Jan 1 1970 .. -r--r--r-- 1 root root 4096 Feb 23 08:06 base lrwxrwxrwx 1 root root 0 Feb 23 08:06 device -> ../../../0-0010 -r--r--r-- 1 root root 4096 Feb 23 08:06 label -r--r--r-- 1 root root 4096 Feb 23 08:06 ngpio drwxr-xr-x 2 root root 0 Feb 23 08:06 power lrwxrwxrwx 1 root root 0 Jan 1 1970 subsystem -> ../../../../../../../../class/gpio -rw-r--r-- 1 root root 4096 Jan 1 1970 uevent root@linaro-ubuntu-desktop:/sys/class/gpio/gpiochip890# grep "" * base:890 label:0-0010 ngpio:8 root@linaro-ubuntu-desktop:/sys/class/gpio/gpiochip890# cd .. root@linaro-ubuntu-desktop:/sys/class/gpio# echo 897 > export root@linaro-ubuntu-desktop:/sys/class/gpio# cd gpio897/ root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# ls -al total 0 drwxr-xr-x 3 root root 0 Feb 23 08:06 . drwxr-xr-x 4 root root 0 Feb 23 08:06 .. -rw-r--r-- 1 root root 4096 Feb 23 08:06 active_low lrwxrwxrwx 1 root root 0 Feb 23 08:06 device -> ../../../0-0010 -rw-r--r-- 1 root root 4096 Feb 23 08:06 direction drwxr-xr-x 2 root root 0 Feb 23 08:06 power lrwxrwxrwx 1 root root 0 Feb 23 08:06 subsystem -> ../../../../../../../../class/gpio -rw-r--r-- 1 root root 4096 Feb 23 08:06 uevent -rw-r--r-- 1 root root 4096 Feb 23 08:06 value root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# cat direction in root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# cat value 0 root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# echo low > direction root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# cat direction out root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# cat value 0 root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# echo high > direction root@linaro-ubuntu-desktop:/sys/class/gpio/gpio897# cat value 1