Using GPIO with SysFs

Linux Drivers

Release Date
2023-07-22

The GPIO driver fits in the Linux GPIO framework. It does provide access to the GPIO by user space through the sysfs filesystem. For details please refer to - the above-mentioned - documentation. The following text is aimed to augment, not replace the existing documentation. For the examples below, there are some important points with sysfs.

  1. The GPIO controllers are visible in /sys/class/gpio . Each controller controls a number of GPIO signals.
  2. The GPIO signals must be exported into the sysfs before they can be manipulated. The number of the GPIO signal must be written to the GPIO export file to cause this to happen.
  3. After exporting the GPIO signal a new directory based on the GPIO signal number will appear in /sys/class/gpio . Under that directory are direction and value files that can be read and written.