Generic Use Cases and Common Interfaces

This section describes some generic, platform-independent APIs/ABIs to be used on the embedded Linux targets. For more specific details, please also check the information in the platform-specific part of the documentation.

CPU-Frequency Scaling

Usually the devicetree contains a set of operating points, that define voltage and frequency values for the CPU cores. The cpufreq driver is able to switch between these operating points depending on the load or temperature. To define the behavior of the switching, a "governor" is specified in the driver.


On multicore systems you can access the cpufreq sysfs attributes for each core through /sys/devices/system/cpu/cpuX/cpufreq, but usually these paths all link to a single policy, that controls the parameters for all cores at the same time.

# Read the current CPU frequency in kHz
cat /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq

# Get the available governors
cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_governors
conservative ondemand userspace powersave performance schedutil

# Get the governor currently in use:
cat /sys/devices/system/cpu/cpufreq/policy0/scaling_governor

# Save power and always set the CPU to a low frequency:
echo powersave > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor

# Gain best performance and always set the CPU to a high frequency:
echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor

# Scale the frequency depending on the load:
echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor

For further information also see the Kernel Docs.


Access through sysfs

Deprecated since Linux 4.8

This interface is deprecated in favor of the libgpiod interface. It still can be enabled in later kernel versions through CONFIG_GPIO_SYSFS.

# list all GPIOs bound to a driver
cat /sys/kernel/debug/gpio

# export GPIO
echo <index> > /sys/class/gpio/export

# set as input
echo input > /sys/class/gpio/gpio<index>/direction

# set as output
echo output > /sys/class/gpio/gpio<index>/direction

# set gpio state
echo 1 > /sys/class/gpio/gpio<index>/value

# get gpio state 
cat /sys/class/gpio/gpio<index>/value

Access through libgpiod

# list GPIO controllers

# list all available GPIO lines

# read the value of a single line
gpioget gpiochip1 23

# set the value of a single line
gpioset gpiochip1 23=1

You can also use libgpiod to access the GPIOs from your application's code or use some of the other available tools. For more information see the official documentation here.