Driver architecture and data structures
Drivers for such devices should provide the following:
- Methods to establish GPIO direction (input and output).
- Methods used to access GPIO values (get and set).
- Methods to map a given GPIO to IRQ and return the associated number.
- A flag saying whether calls to its methods may sleep. This is very important.
- An optional
debugfs dump
method (showing extra state such as pullup config). - An optional number called a base number, from which GPIO numbering should start. It will be automatically assigned if omitted.
In the kernel, a GPIO controller is represented as an instance of struct gpio_chip
, defined in linux/gpio/driver.h
:
struct gpio_chip { const char *label; struct device *dev; struct module *owner; int (*request)(struct gpio_chip *chip, unsigned offset); void (*free)(struct gpio_chip *chip, unsigned offset); int (*get_direction)(struct gpio_chip *chip, unsigned offset); int (*direction_input)(struct gpio_chip *chip, unsigned offset)...