STRUCT GPIO_DEVICE(9)
π struct gpio_device(9) π
okay bestie, so this is a page from the Kernel API Manual β yes, the Kernel API Manual β and honestly? it's giving backstage-pass energy. pull up a chair, we're going behind the scenes of a GPIO device π
β¨ NAME β¨
struct gpio_device β the internal state container for GPIO devices. like, the little handbag where the kernel keeps all its stuff, iykyk π
πΈ SYNOPSIS πΈ
struct gpio_device {
struct device dev;
struct cdev chrdev;
int id;
struct module *owner;
struct gpio_chip *chip;
struct gpio_desc *descs;
unsigned long *valid_mask;
struct srcu_struct desc_srcu;
unsigned int base;
u16 ngpio;
bool can_sleep;
const char *label;
void *data;
struct list_head list;
struct raw_notifier_head line_state_notifier;
rwlock_t line_state_lock;
struct workqueue_struct *line_state_wq;
struct blocking_notifier_head device_notifier;
struct srcu_struct srcu;
#ifdef CONFIG_PINCTRL;
struct list_head pin_ranges;
#endif;
};
no cap, that #ifdef CONFIG_PINCTRL; is literally how it's written in the original, semicolons and all β do not come for me, I just work here π
π¦ Members π¦
devβ the GPIO device struct. the main character, lowkey π«Άchrdevβ the character device for the GPIO device. userspace says hi through this one.idβ the numerical ID number for the GPIO chip.ownerβ helps prevent removal of modules that are exporting active GPIOs. a bodyguard module fr fr.chipβ pointer to the correspondinggpiochip, which holds the static data for this device. the chill, doesn't-change part.descsβ array ofngpiodescriptors. one entry per line, bestie.valid_maskβ if it's notNULL, it holds a bitmask of the GPIOs which are valid to be used from the chip. think VIP list πdesc_srcuβ ensures consistent state of the GPIO descriptors exposed to users. so nobody catches a descriptor mid-glowup.baseβ the GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned at device creation time. β οΈ deprecated, bestie β noted, respected, moving on.ngpioβ the number of GPIO lines on this GPIO device, equal to the size of thedescsarray. math checks out β¨can_sleepβ tells you whether the GPIO chip driver's callbacks can sleep, which implies they cannot be used from atomic context. important!! do not ignore π¨labelβ a descriptive name for the GPIO device, like the part number or the name of the IP component in a System on Chip. its whole identity, honestly.dataβ per-instance data assigned by the driver. the driver's personal stash.listβ linksgpio_devices together for traversal. a little linked-list friend group π«line_state_notifierβ used to notify subscribers about lines being requested, released or reconfigured. the group chat notif πline_state_lockβ an RW-spinlock protecting the line state notifier. don't touch without it, periodt.line_state_wqβ used to emit line state events from a separate thread in process context. delegation queen πdevice_notifierβ used to notify character device wait queues about the GPIO device being unregistered. the "we're so over" announcement, but polite.srcuβ protects the pointer to the underlying GPIO chip. π‘οΈpin_rangesβ the range of pins served by the GPIO driver.
π Description π
So this state container holds most of the runtime variable data for a GPIO device β like, the live, moving parts. and here's the iconic bit: it can hold references and live on after the GPIO chip has been removed, if it's still being used from userspace. not me surviving the breakup ππ it literally stays booked and busy after the chip is gone.
π§ SEE ALSO π§
- Kernel file
./drivers/gpio/gpiolib.h struct gpio_array(9)struct gpio_desc(9)
go read those if you want the full lore, bestie. iykyk π
okay that's the whole page!! this one came from ./drivers/gpio, dated October 2026, and it's the struct gpio_device(9) page β ily, go touch some GPIOs responsibly πΈβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms