The analog inputs on the AM335x processor are supported by the Linux kernel, so using Linux is one way to use them. They can be tied into the Industrial IO (IIO) subsystem in the Linux kernel. This requires some declarations in the device tree to initialize the device drivers Linux will use to read the analog inputs. Depending on the kernel configuration, it may also require loading some kernel modules on startup to enable the drivers. Once all of this is in place, Linux will create some nodes in the filesystem that can be used to read the analog inputs.
The following device tree declarations should be enough to enable the analog input drivers:
status = “okay”;
ti,adc–channels = <0 1 2 3 4 5 6 7>;
These declarations build on existing declarations in the am33xx.dtsi device tree include file that comes with the Linux kernel source code. The first declaration enables the analog input module, and the second declares that all 8 input channels will be used. The next step is loading the kernel modules at startup, if required. There are a number of kernel modules required to make the analog inputs work, but they are all dependencies of ti_am335x_adc. Running the command ‘modprobe ti_am335x_adc’ should load all of them.
If the IIO device driver is loaded and configured correctly, then Linux should create a folder for it in ‘/sys/bus/iio/devices’. The folder will have a name like ‘iio:device0’, and will contain files and folders for interacting with the device. If multiple IIO devices are present, then the ‘name’ file can be used to distinguish them. The device for the analog inputs should have a name like ‘TI-am335x-adc.0.auto’. The device folder should also contain eight files called ‘in_voltage0_raw through in_voltage7_raw’. Reading these files will give the current reading on the corresponding analog input.