ADC
Warning
The maximum acquisition voltage for SARADC on Rockchip platforms is 1.8V. Overvoltage use is strictly prohibited! The maximum acquisition voltage for GPADC on Allwinner platforms is 1.8 V, and for LRADC it is 1.266V. Overvoltage use is strictly prohibited!
The expansion pin ADC pin information for Rockchip platforms is as follows:
| Board | SoC | Platform | Expansion Pins |
|---|---|---|---|
| K1 | RK3568 | Rockchip | SARADC X1 |
| K1B | RK3568 | Rockchip | SARADC X1 |
| K3 | RK3562 | Rockchip | SARADC X1 |
| K7 | RK3576 | Rockchip | SARADC X3 |
| K7C | RK3576 | Rockchip | SARADC X3 |
| K8 | RK3588 | Rockchip | SARADC X1 |
The expansion pin ADC pin information for Allwinner platforms is as follows:
| Board | SoC | Platform | Expansion Pins |
|---|---|---|---|
| K2B | H618 | Allwinner | None |
| K2C | H618 | Allwinner | None |
| K4B | T113 | Allwinner | GPADC X1 |
| K5C | A133 | Allwinner | LRADC X1 |
Terminology
| Term | Description |
|---|---|
| ADC | Analog-to-Digital Converter |
| SARADC | Successive Approximation ADC |
| GPADC | General Purpose ADC |
| LRADC | Low Rate ADC |
Specifications
| ADC | Resolution | Max Sample Rate | Voltage Range |
|---|---|---|---|
| SARADC | 12-bit | 1MHz | 0~1.8V |
| GPADC | 12-bit | 1MHz | 0~1.8V |
| LRADC | 6-bit | 2KHz | 0~1.266 V |
DTS Configuration
DTS configurations vary across platforms. Please check the corresponding DTS node configuration based on the motherboard's platform.
An example node configuration for SARADC on Rockchip platforms is as follows:
saradc: adc@ff280000 {
compatible = "rockchip,saradc";
reg = <0xff280000 0x1000>;
clocks = <&cru SCLK_SARADC>;
clock-names = "saradc";
resets = <&cru SRST_SARADC>;
reset-names = "saradc";
#io-channel-cells = <1>;
status = "okay";
};
An example node configuration for GPADC on Allwinner platforms is as follows:
/*
* channel_num: Maxinum number of channels supported on the platform.
* channel_select: channel enable slection. channel0:0x01 channel1:0x02 channel2:0x04 channel3:0x08
* channel_data_select: channel data enable. channel0:0x01 channel1:0x02 channel2:0x04 channel3:0x08.
* channel_compare_select: compare function enable channel0:0x01 channel1:0x02 channel2:0x04 channel3:0x08.
* channel_cld_select: compare function low data enable setection: channel0:0x01 channel1:0x02 channel2:0x04 channel3:0x08.
* channel_chd_select: compare function hig data enable setection: channel0:0x01 channel1:0x02 channel2:0x04 channel3:0x08.
*/
gpadc:gpadc{
compatible = "allwinner,sunxi-gpadc"; // Identifies the specific device for driver binding;
reg = <0x0 0x05070000 0x0 0x400>; // Register address used by the device;
interrupts = <GIC_SPI 0 IRQ_TYPE_NONE>; // Interrupt configuration used by the device;
clocks = <&clk_gpadc>; // Clock configuration used by the device
channel_num = <2>; // Channels used
channel_select = <0x05>; // Channel selection
channel_data_select = <0>; // Enable channel data
channel_compare_select = <0x05>; // Use channel compare function
channel_cld_select = <0x05>; // Use data less than compare function
channel_chd_select = <0>; // Use data greater than compare function
channel0_compare_lowdata = <1700000>; // Trigger interrupt if data is less than this value
channel0_compare_higdata = <1200000>; // Trigger interrupt if data is greater than this value
channel1_compare_lowdata = <460000>;
channel1_compare_higdata = <1200000>;
channel0_compare_lowdata = <1500000>; // Trigger interrupt if data is less than this value
channel0_compare_higdata = <1200000>; // Trigger interrupt if data is greater than this value
key_cnt = <5>; // Number of keys, Note: The following parts are only used if GPADC0 is used for keys
key0_vol = <210>; // Key voltage
key0_val = <115>; // Key reported value
key1_vol = <410>;
key1_val = <114>;
key2_vol = <590>;
key2_val = <139>;
key3_vol = <750>;
key3_val = <28>;
key4_vol = <880>;
key4_val = <102>;
status = "okay";
};
An example node configuration for LRADC on Allwinner platforms is as follows:
sunxi_keyboard:keyboard{
compatible = "allwinner,keyboard";
reg = <0x0 0x01c21800 0x0 0x400>; /* Register address */
interrupts = <GIC_SPI 30 IRQ_TYPE_NONE>; /* Interrupt */
status = "okay"; /* Enable this node */
key_cnt = <5>;
key0 = <115 115>; /* According to the actual situation, the left 115 is the voltage in mV, the right 115 is the key value corresponding to that voltage */
key1 = <235 114>;
key2 = <330 139>;
key3 = <420 28>;
key4 = <520 102>;
};
Driver Paths
The Rockchip platform saradc driver is located under the IIO (Industrial I/O) subsystem framework, responsible for converting analog signals to digital signals for user space or application reading.
The Allwinner platform GPADC and LRADC drivers are located under the Input subsystem framework. They convert analog signals to digital signals and then report them through the Input subsystem for user space or application reading.
ADC Pin Identification
- ADC Pins
Note
The △ symbol on the motherboard expansion pin marking corresponds to pin 1 in the pinout diagram. Combine this with the pin number silkscreen to confirm the actual pin number.
K7 Pinout Diagram: The K7 motherboard is equipped with 3 ADC channels, corresponding to pins 36 (SARADC_VIN4), 38 (SARADC_VIN5), and 40 (SARADC_VIN6).

GPADC/LRADC Test
View the event node of the ADC module:
Read input device 0 data using hexdump:
getevent is a command used in Android systems to view input device events:
evtest is an open-source input device event testing tool in Linux systems:
SARADC Test
The SARADC on Rockchip platforms is registered as an IIO subsystem device. ADC data can be read using the following methods.
IIO Read
List registered IIO devices in the system:
View all operable interfaces for target IIO device 0:
Note
Key nodes under the interface
in_voltageX_raw: X is the ADC channel number (e.g., 0, 6), stores the raw ADC sample value for the corresponding channel.
in_voltage_scale: Voltage conversion scale factor (unit: V/LSB), used to convert the raw sample value to the actual voltage.
Voltage calculation formula:
Read the voltage scale factor (used to calculate the actual voltage):
Read the raw ADC sample value for the IN6 channel:
Shell Script
Read the voltage of the IN6 channel via a script. After running the script, it outputs the ADC raw sample value, voltage scale factor, and voltage value every second.
#!/bin/bash
echo "Press Ctrl+C to quit"
VOL_RAW="/sys/bus/iio/devices/iio:device0/in_voltage6_raw"
VOL_SCALE="/sys/bus/iio/devices/iio:device0/in_voltage_scale"
# Check required files accessibility
for file in "$VOL_RAW" "$VOL_SCALE"; do
[ ! -f "$file" ] || [ ! -r "$file" ] && { echo "Error: Cannot access $file" >&2; exit 1; }
done
while true; do
raw=$(cat "$VOL_RAW" | tr -d '\n\r ')
scale=$(cat "$VOL_SCALE" | tr -d '\n\r ')
voltage=$(awk -v r="$raw" -v s="$scale" 'BEGIN { printf "%.4f", (r * s) / 1000 }')
echo "vol_raw:$raw, vol_scale:$scale, vol:$voltage V"
sleep 1
done
Execution method:
C Program
Read the voltage of the IN6 channel via a C program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#define VOL_RAW "/sys/bus/iio/devices/iio:device0/in_voltage6_raw"
#define VOL_SCALE "/sys/bus/iio/devices/iio:device0/in_voltage_scale"
// Handle Ctrl+C exit
void sigint_handler(int sig) {
(void)sig;
printf("\nExiting...\n");
exit(EXIT_SUCCESS);
}
// Read int from file
static int read_int(const char *path) {
FILE *fp = fopen(path, "r");
int val;
if (!fp || fscanf(fp, "%d", &val) != 1) {
perror("Read int failed");
exit(EXIT_FAILURE);
}
fclose(fp);
return val;
}
// Read float from file
static float read_float(const char *path) {
FILE *fp = fopen(path, "r");
float val;
if (!fp || fscanf(fp, "%f", &val) != 1) {
perror("Read float failed");
exit(EXIT_FAILURE);
}
fclose(fp);
return val;
}
int main() {
signal(SIGINT, sigint_handler);
printf("Press Ctrl+C to quit\n");
while (1) {
int raw = read_int(VOL_RAW);
float scale = read_float(VOL_SCALE);
printf("vol_raw:%d, vol_scale:%.6f, vol:%.4f V\n",
raw, scale, (raw * scale) / 1000.0f);
sleep(1);
}
}
Execution method: