STRUCT GPIO_DEVICE(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 corresponding gpiochip, which holds the static data for this device. the chill, doesn't-change part.
  • descs β€” array of ngpio descriptors. one entry per line, bestie.
  • valid_mask β€” if it's not NULL, 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 the descs array. 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 β€” links gpio_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