GPIO framework for FreeBSD
GPIO stands for General Purpose Input/Output. This interface may be thought of as a set of pins which could serve as input or output having logical 0 and logical 1 as their values (some other options are applicable, but they're not crucial for this explanation). Most common usage of GPIO interface is LED and button control for various SoCs.
All the HW-independent stuff resides in sys/dev/gpio directory. It consists of gpioc (GPIO controller device), gpiobus (bus that manages devices attached to GPIO controller) and gpioled (implementation of LED driver that illustrates usage pattern of gpiobus, utilizes led(4) interface).
HW-dependent part might be a part of SoC, I2C extender, whatever. It should implement interface defined in sys/dev/gpio/gpio_if.m:
gpio_pin_max - get maximum pin available gpio_pin_getcaps - get capabilities for given pin gpio_pin_getflags - get flags for given pin gpio_pin_setflags - set flags for given pin gpio_pin_getname - get pin name (if any) gpio_pin_set - set pin value gpio_pin_get - get pin value gpio_pin_toggle - toggle (invert) pin value
And on attaching HW driver should add gpioc and gpiobus as its children.
gpioc creates /dev/gpiocX entry that is used by gpioctl application for managing GPIO pins using following ioctls:
GPIOMAXPIN - get maximum pin available GPIOGETCONFIG - get flags/capabilities/name for given pin GPIOSETCONFIG - set flags for given pin GPIOGET - get pin value GPIOSET - set pin value GPIOTOGGLE - toggle (invert) pin value
gpioctl -f ctldev -l [-v] gpioctl -f ctldev -t pin gpioctl -f ctldev -c pin flag ... gpioctl -f ctldev pin [0|1]
gpiobus manages devices attached to gpio controller. Its interface is a subset of of gpio_if.m interface and allows child devices talk to GPIO controller. At the moment children could be set only by hints file and pin space is limited to 32. Example:
# RF led hint.gpioled.0.at="gpiobus0" hint.gpioled.0.name="rf" # pin 2 hint.gpioled.0.pins=0x0004
gpiobus_pin_getcaps - get capabilities for given pin gpiobus_pin_getflags - get flags for given pin gpiobus_pin_setflags - set flags for given pin gpiobus_pin_set - set pin value gpiobus_pin_get - get pin value gpiobus_pin_toggle - toggle (invert) pin value
gpioled. Reference implementation of child device. Provides on/off function for led(4) API
gpioiic. I2C bus over GPIO. (Author: Luiz Otavio O Souza <email@example.com>)
Code has been committed to HEAD
Using GPIO pins, examples of use. FreeBSD/GPIO-hardware
GPIO C examples
libgpio. Provides all the GPIO low level routines for a C program: https://bitbucket.org/rpaulo/libgpio/src
interrupts. Allow GPIO controllers to act as interrupt controllers
runtime attach/detach. Allow GPIO devices to be attached and detached at runtime
pin groups. Allow the read/write of a group of pins (8/16/32/64 pins at time ?)
pin features. Implement pin value inversion, in a generic way.