Skip to content

Day75 - GPIO Controller Architecture

Date

2026-06-11

Topics

  • GPIO controller hardware architecture
  • GPIO register blocks
  • Direction register
  • Input register
  • Output register
  • Set/Clear registers
  • GPIO line vs GPIO controller
  • GPIO numbering
  • GPIO consumer model
  • GPIO controller abstraction
  • gpio_chip fundamentals

Summary

Today focused on understanding how Linux GPIO controllers are implemented on top of MMIO register blocks.

The learning began from the hardware perspective by analyzing the common GPIO register layout found in MCU and SoC designs, including direction, input, output, set, and clear registers.

Using Raspberry Pi 5 as a reference platform, GPIO controller Device Tree nodes were inspected and mapped through:

Device Tree
platform device
platform driver
gpiochip
GPIO lines

GPIO controller resources were examined through Device Tree, sysfs, and debugfs. Multiple GPIO controllers and gpiochips were identified, including both internal BCM2712 GPIO controllers and the RP1 GPIO controller used by the external header pins.

The relationship between GPIO controller, GPIO line, GPIO numbering, consumer ownership, and hardware register bits was investigated.

A userspace GPIO controller simulator was implemented to model:

Direction Register
Input Register
Output Register
SET Register
CLR Register

A second abstraction layer based on a simplified gpio_chip model was then added. Callback operations were introduced to demonstrate how Linux separates GPIO hardware implementation from higher-level GPIO APIs.

Labs Completed

Lab 1 - GPIO Controller Register Model

Implemented a simulated GPIO controller containing:

  • Direction register
  • Input register
  • Output register
  • SET register behavior
  • CLR register behavior

Implemented APIs:

  • gpio_direction_input()
  • gpio_direction_output()
  • gpio_get_value()
  • gpio_set_value()
  • gpio_simulate_input()

Lab 2 - gpio_chip Abstraction Model

Implemented a simplified gpio_chip layer containing:

  • Callback table
  • Private context
  • Direction callbacks
  • Get/Set callbacks

Architecture:

main
gpio_chip
gpio_controller
register model

This demonstrated how Linux GPIO abstractions are built on top of hardware-specific controller implementations.

Key Takeaways

  • GPIO controller is fundamentally a MMIO register block.
  • GPIO line corresponds to a hardware register bit.
  • GPIO controller and GPIO line are different concepts.
  • GPIO numbering is an abstraction and does not necessarily correspond to external pins.
  • GPIO consumers represent ownership of GPIO lines.
  • gpio_chip acts as a callback-based abstraction layer between gpiolib and hardware drivers.
  • Linux GPIO design follows the same callback-table pattern used throughout the Linux driver model.

Next

Day76 - gpiolib and GPIO Descriptor

Topics:

  • gpiolib architecture
  • struct gpio_chip
  • gpio_desc
  • devm_gpiod_get()
  • gpiod_set_value()
  • GPIO_ACTIVE_LOW
  • Device Tree GPIO bindings
  • reset-gpios
  • interrupt-gpios
  • GPIO consumer model