Depending on the module type the analogue inputs are connected via different ADCs (see ADC) therefore ADC read-out is supported by various drivers. Most drivers provide file access through sysfs. Access through sysfs is easy to implement since it only involves reading a regular file. Keep in mind that opening and closing a file for every ADC read-out is relatively slow and rather resource intensive. However the internal ADCs are anyway not meant to be used for high speed applications.
On the Colibri T20 the WM9715 supports ADC read-out through the battery driver. Currently only AD0 and AD1 are supported.
root@colibri_t20:~# cat /sys/class/power_supply/colibri_t20-analog_inputs/voltage_now 4095
root@colibri_t20:~# cat /sys/class/power_supply/colibri_t20-analog_inputs/temp 1044
The STMPE-ADC driver makes use of the Industrial Input/Output (IIO) framework. The driver will be included in BSP V2.1 beta 2.
The STMPE811 supports up to 8 analogue inputs, however, input 1-4 are used for the resistive touchscreen interface. The inputs are 0 indexed, so the usable inputs are 4-7.
|SODIMM/MXM3||STMPE811 Input||IIO device||IIO channel|
Note that the STMPE811 pin name IN0 goes to the ADC channel 4.
The IIO framework exposes those inputs through the sysfs interface:
# cd /sys/bus/iio/devices/device0/ # ls in* in4_raw in5_raw in6_raw in7_raw in_scale # cat /sys/bus/iio/devices/device0/in4_raw 755
Note: On newer kernels the IIO framework changed its file naming scheme slightly:
root@colibri-imx6:~# cd /sys/bus/iio/devices/iio\:device0/ root@colibri-imx6:/sys/bus/iio/devices/iio:device0# ls in* in_temp8_raw in_voltage4_raw in_voltage5_raw in_voltage6_raw in_voltage7_raw in_voltage_scale root@colibri-imx6:/sys/bus/iio/devices/iio:device0# cat /sys/bus/iio/devices/iio\:device0/in_voltage4_raw 1089
Note: Since the ADC is shared with the touchscreen its not recommended to change the ADC characteristics such as sample time.
More information about the IIO framework:
On the Colibri VFxx modules the AD functionality is making use of the two integrated 12-Bit ADC peripherals of the Vybrid SoC.
|SODIMM||Vybrid ADC||IIO device||IIO channel|
|AD0||ADC0, Channel 8||iio:device0||in_voltage8_raw|
|AD1||ADC1, Channel 8||iio:device1||in_voltage8_raw|
|AD2||ADC0, Channel 9||iio:device0||in_voltage9_raw|
|AD3||ADC1, Channel 9||iio:device1||in_voltage9_raw|
These four analogue inputs are compatible within the Colibri family and are dedicated ADC inputs. Additional some of the GPIO capable pins on the SODIMM connector feature with alternative function ADC capability. The ADC function of these pins are not compatible with other Colibri modules. It should be noted, that the noise level on these pins might be higher than on the dedicated ADC input signals, as these are routed as digital signals on the module.
For BSP versions 2.3 Beta3 and earlier, the driver is called mvf-adc and supports access through a character device only. We created a test program to show how the driver can be used, see adc-test.c.
Starting with BSP versions 2.3 Beta5, the vf610_adc driver makes use of the Industrial Input/Output (IIO) framework. The IIO framework exposes the ADC channels through the sysfs interface. The inputs are indexed through 0 to 15 with the channels 8 and 9 for ADC0 and ADC1 being usable by default. The ADC peripherals also include an internal temperature sensor. The readout of them is given by in_temp_input in degree celsius times 1000.
root@colibri-vf:~# cd /sys/bus/iio/devices/iio\:device0 root@colibri-vf:/sys/bus/iio/devices/iio:device0# ls dev in_voltage5_raw in_temp_input in_voltage6_raw in_voltage0_raw in_voltage7_raw in_voltage10_raw in_voltage8_raw in_voltage11_raw in_voltage9_raw in_voltage12_raw in_voltage_sampling_frequency in_voltage13_raw in_voltage_scale in_voltage14_raw name in_voltage15_raw power in_voltage1_raw sampling_frequency_available in_voltage2_raw subsystem in_voltage3_raw uevent in_voltage4_raw root@colibri-vf:/sys/bus/iio/devices/iio:device0# cat in_temp_input 41304 root@colibri-vf:/sys/bus/iio/devices/iio:device0# cat in_voltage8_raw 1377 root@colibri-vf:~# cd /sys/bus/iio/devices/iio\:device1 root@colibri-vf:/sys/bus/iio/devices/iio:device1# cat in_temp_input 40760 root@colibri-vf:/sys/bus/iio/devices/iio:device1# cat in_voltage9_raw 4035
Vybrid provides support for continuous sampling with its ADC peripheral. Currently only software triggers are supported, they are accessible through sysfs. The necessary driver support is available with version 2.6 Beta1 and above. The 2.6 Beta1 release image is missing the sysfs trigger configuration option (CONFIG_IIO_SYSFS_TRIGGER) and hence requires a custom kernel build.
root@colibri-vf:~# cd /sys/bus/iio/devices/ root@colibri-vf:/sys/bus/iio/devices# ls iio:device0 iio:device1 iio_sysfs_trigger root@colibri-vf:/sys/bus/iio/devices# cd iio:device0 root@colibri-vf:/sys/bus/iio/devices/iio:device0# ls buffer in_voltage13_raw in_voltage6_raw power dev in_voltage14_raw in_voltage7_raw sampling_frequency_available in_conversion_mode in_voltage15_raw in_voltage8_raw scan_elements in_temp_input in_voltage1_raw in_voltage9_raw subsystem in_voltage0_raw in_voltage2_raw in_voltage_sampling_frequency trigger in_voltage10_raw in_voltage3_raw in_voltage_scale uevent in_voltage11_raw in_voltage4_raw name in_voltage12_raw in_voltage5_raw of_node
The generic buffer code present in Linux kernel source tree can be used to test the continuous sampling functionality.
root@colibri-vf:~# echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_temp_en root@colibri-vf:~# echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_timestamp_en root@colibri-vf:~# echo 0 > /sys/bus/iio/devices/iio_sysfs_trigger/add_trigger root@colibri-vf:~# ./generic_buffer -n 4003b000.adc -t sysfstrig0 -l 512 -c 1 iio device number being used is 0 iio trigger number being used is 0 /sys/bus/iio/devices/iio:device0 sysfstrig0 835.000000 1463058211407519734 835.000000 1463058211407532489 834.000000 1463058211407542708 835.000000 1463058211407556933 835.000000 1463058211407572004 835.000000 1463058211407587044 836.000000 1463058211407601449 835.000000 1463058211407615464 835.000000 1463058211407629923 835.000000 1463058211407644663 835.000000 1463058211407659362 835.000000 1463058211407674031 836.000000 1463058211407688639 835.000000 1463058211407703164 835.000000 1463058211407717683 834.000000 1463058211407731968 root@colibri-vf:~# echo 0 > /sys/bus/iio/devices/iio:device0/scan_elements/in_timestamp_en root@colibri-vf:~# echo 0 > /sys/bus/iio/devices/iio:device0/scan_elements/in_temp_en root@colibri-vf:~# echo 0 > /sys/bus/iio/devices/iio_sysfs_trigger/remove_trigger
On the Colibri iMX7 modules the AD functionality is making use of the integrated 12-Bit ADC peripheral of the i.MX 7 SoC.
|SODIMM||i.MX 7 ADC||IIO device||IIO channel|
Note: The ADC channels are only 1.8V capable! This is a limitation of the i.MX 7 SoC.
The Linux IIO driver for the i.MX 7 ADC is called AD2802A and by default enabled. The IIO framework exposes the ADC channels through the sysfs interface.
root@colibri-imx7:~# cd /sys/bus/iio/devices/iio\:device0/ root@colibriimx7:/sys/bus/iio/devices/iio:device0# ls dev in_voltage12_raw in_voltage1_raw in_voltage5_raw in_voltage9_raw of_node in_voltage0_raw in_voltage13_raw in_voltage2_raw in_voltage6_raw in_voltage_sampling_frequency power in_voltage10_raw in_voltage14_raw in_voltage3_raw in_voltage7_raw in_voltage_scale subsystem in_voltage11_raw in_voltage15_raw in_voltage4_raw in_voltage8_raw name uevent root@colibriimx7:/sys/bus/iio/devices/iio:device0# cat in_voltage[0-3]_raw 1860 3057 3050 3735