###Enabling ADC (AIN0 - AIN6) on BBB for newer Linux kernels that do not support device tree overlays
The device tree overlay mechanism has been abandoned in newer (3.9+?) linux kernels. Access to GPIO pins via the filesystem-based /sys/class/gpio is still supported, but for some reason the default device tree source (dts) for the Beaglebone Black does not define the 7 ADC ports as accessible (not sure why this is—I don't believe those pins can be used for anything else). If you don't have any devices listed under /sys/bus/iio/devices
, then you too are suffering. Read on.
Thanks to Matti Laakso for pointing me in the right direction here
The fix is to add the definition of the ADC ports to the dtb file that is loaded at boot time. For the Beaglebone Black, the default loaded dtb is am335x-boneblack.dtb
and the boot loader looks for it in directory /boot/dtbs
.
Note: my environment is ArchLinux, kernel 3.19.1 running on a BBB Rev C.
Here's the ADC-specific definition that I added to the am335x-boneblack.dts file:
&tscadc {
status = "okay";
};
&am335x_adc {
ti,adc-channels = <0 1 2 3 4 5 6 7>;
};
Here's how I accomplished updating and installing a dtb that has ADC support:
####1. Download Robert C Nelson's dtb-rebuilder There are two branches here, I used the 3.19 branch.
[root@nodeproto matthew]# git clone https://github.com/RobertCNelson/dtb-rebuilder.git
...
[root@nodeproto matthew]# cd dtb-rebuilder/
[root@nodeproto dtb-rebuilder]# git checkout 3.19.x
####2. To the am335x-boneblack.dts file, add the neccesary ADC definitions
[root@nodeproto dtb-rebuilder]# vi src/arm/am335x-boneblack.dts
Here's the complete file, edited. My insertions begin at line 48.
/*
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/dts-v1/;
#include "am33xx.dtsi"
#include "am335x-bone-common.dtsi"
/ {
model = "TI AM335x BeagleBone Black";
compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
};
/* Max Core Speed */
#include "am335x-boneblack-1ghz.dtsi"
/* #include "am335x-boneblack-800mhz.dtsi" */
&ldo3_reg {
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
};
&mmc1 {
vmmc-supply = <&vmmcsd_fixed>;
};
&am33xx_pinmux {
pinctrl-names = "default";
pinctrl-0 = <&clkout2_pin>;
};
#include "am335x-peripheral-emmc.dtsi"
#include "am335x-bone-pinmux-emmc.dtsi"
/* #include "am335x-bone-emmc-in-reset.dtsi" */
#include "am335x-peripheral-nxp-hdmi.dtsi"
#include "am335x-bone-pinmux-nxp-hdmi.dtsi"
&rtc {
system-power-controller;
};
/* Definitions for ADC */
&tscadc {
status = "okay";
};
&am335x_adc {
ti,adc-channels = <0 1 2 3 4 5 6 7>;
};
/* #include "am335x-peripheral-can0.dtsi" */
/* #include "am335x-bone-pinmux-can0.dtsi" */
/* #include "am335x-peripheral-can1.dtsi" */
/* #include "am335x-bone-pinmux-can1.dtsi" */
/* #include "am335x-peripheral-ttyO1.dtsi" */
/* #include "am335x-bone-pinmux-ttyO1.dtsi" */
/* #include "am335x-peripheral-ttyO2.dtsi" */
/* #include "am335x-bone-pinmux-ttyO2.dtsi" */
/* #include "am335x-peripheral-ttyO4.dtsi" */
/* #include "am335x-bone-pinmux-ttyO4.dtsi" */
/* #include "am335x-peripheral-ttyO5.dtsi" */
/* #include "am335x-bone-pinmux-ttyO5.dtsi" */
####3. Build and install the new dtb (make up a back up first)
[root@nodeproto dtb-rebuilder]# make all
...
[root@nodeproto dtb-rebuilder]# cp /boot/dtbs/am335x-boneblack.dtb /boot/dtbs/am335x-boneblack.dtb.bak
[root@nodeproto dtb-rebuilder]# cp src/arm/am335x-boneblack.dtb /boot/dtbs/
####4. Reboot Once rebooted, listing of /sys/bus/iio should resemble this:
[root@nodeproto ~]# cd /sys/bus/iio/devices/iio\:device0
[root@nodeproto iio:device0]# ls -l
total 0
drwxr-xr-x 2 root root 0 Mar 24 14:40 buffer
-r--r--r-- 1 root root 4096 Mar 24 14:40 dev
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage0_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage1_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage2_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage3_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage4_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage5_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage6_raw
-rw-r--r-- 1 root root 4096 Mar 24 14:40 in_voltage7_raw
-r--r--r-- 1 root root 4096 Mar 24 14:40 name
drwxr-xr-x 2 root root 0 Mar 24 14:40 power
drwxr-xr-x 2 root root 0 Mar 24 14:40 scan_elements
lrwxrwxrwx 1 root root 0 Mar 24 14:40 subsystem -> ../../../../../../bus/iio
-rw-r--r-- 1 root root 4096 Mar 24 13:41 uevent