Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

/sys/class/gpio

FieldValue
SubsystemGPIO sysfs (legacy), drivers/gpio/gpiolib-sysfs.c
Config gateCONFIG_GPIO_SYSFS (obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o in drivers/gpio/Makefile, torvalds/linux master)
ABI documentationDocumentation/ABI/obsolete/sysfs-gpio (obsolete tree); replacement: Documentation/ABI/testing/gpio-cdev
Since2.6.27; the ABI file states it is “obsoleted by Documentation/ABI/testing/gpio-cdev and will be removed after 2020”
Live (5.10.134 host)class absent: no gpiochip exported through the legacy interface in the container
Ledger IDSYSC-gpio

What it represents

The legacy userspace GPIO interface. A flat /sys/class/gpio directory holds export/unexport control files, one gpioN directory per exported GPIO line, and one gpiochipN (or newer chipX) directory per controller. GPIOs are kernel-global integers; nothing is visible until a line is explicitly exported. The documented replacement is the /dev/gpiochipN ioctl character device (KernelVersion 4.4 per gpio-cdev, used via libgpiod).

Relationship to the device model

gpiochipN directories are views over controller devices under /sys/devices/...; exported gpioN directories are synthesized children, not real devices, and persist only while exported. The modern interface maps the same controllers to /dev/gpiochipN char nodes (listed in /sys/dev/char when present). No GPIO bus exists; the class is the only sysfs view.

Attributes

The obsolete ABI file documents the full layout as a tree (single What: entry for /sys/class/gpio/); the ledger’s 1 documented attr reflects that. Every row below comes from that tree.

AttributeR/WUnit/formatConditional?Source
exportWOGPIO integer number; exports a line for userspace usealwaysABI obsolete sysfs-gpio tree
unexportWOGPIO integer number; returns the line to the kernelalwaysABI obsolete tree
gpioN/valueRO/RW0/1; “always readable, writes fail for input GPIOs”exported linesABI obsolete tree
gpioN/directionRWin, out (default low); writes accept high, lowexported linesABI obsolete tree
gpioN/edgeRWnone, falling, rising, both (interrupt source selection)exported linesABI obsolete tree
gpioN/active_lowRW0/1 polarity inversionexported linesABI obsolete tree
gpiochipN/baseROfirst GPIO number of the chip (same as N)gpiochipsABI obsolete tree
gpiochipN/labelROdescriptive chip namegpiochipsABI obsolete tree
gpiochipN/ngpioROline count; chip spans N..N+ngpio-1gpiochipsABI obsolete tree
chipX/{export,unexport,label,ngpio}mixedhardware-offset based variant of the abovenewer kernel formABI obsolete tree

The chipX form addresses lines by hardware offset instead of the global base+number scheme.

Safety and writes

All reads are safe. Writes are the danger zone: export takes a line from whatever kernel driver claimed it (the ABI allows export only for unclaimed lines, and kernel code may also export), and a userspace writer then toggles hardware with no knowledge of board context. value writes on an input line fail. userspace-api/gpio/sysfs.rst documents these hazards (worklog 2-b). The interface is deprecated: new code must use /dev/gpiochipN ioctls (GPIO_GET_LINEHANDLE_IOCTL and friends) or libgpiod; distros compile CONFIG_GPIO_SYSFS mostly for legacy scripts.

References

  • Documentation/ABI/obsolete/sysfs-gpio, Documentation/ABI/testing/gpio-cdev (cached copies)
  • drivers/gpio/gpiolib-sysfs.c, drivers/gpio/Makefile (torvalds/linux master)
  • Documentation/userspace-api/gpio/sysfs.rst, Documentation/userspace-api/gpio/chardev.rst
  • Ledger row SYSC-gpio (Source column notes the obsolete-tree location); worklog Task 2-b