gpiochip_add_data(9)
π gpiochip_add_data(9) β the Kernel API Manual, bestie edition π
okay so this one is from the Kernel API Manual (yes, the 9 section, we love a kernel-dev moment) and it's literally the page about registering a gpio_chip. grab a strawberry drink π, we're doing this.
β¨ SYNOPSIS β¨
gpiochip_add_data (gc , data );
that's it. two args. iconic.
π«Ά ARGUMENTS π«Ά
gcβ the chip you're registering, and heads up: it needsgc->basealready initialized before you hand it over. no showing up unprepared πdataβ the driver-private data that goes with this chip. it's giving "your stuff, your business" π
π CONTEXT π
potentially before irqs will work π like, yes, it can happen that early. read the description, i'm begging you.
π DESCRIPTION π
so here's the tea β. when gpiochip_add_data gets called very early during boot β like, early enough that GPIOs can be freely used β then the gc->parent device must be registered before the gpio framework's arch_initcall. otherwise sysfs initialization for GPIOs will fail rudely π and nobody wants that energy in their dmesg.
also,gpiochip_add_datamust only be called after gpiolib initialization β i.e. aftercore_initcall. that's the vibe check you cannot skip, fr fr.
and if gc->base is negative? that's the signal to request dynamic assignment of a range of valid GPIOs. you're not picking the number, the kernel is picking the number. main character energy only for the framework π§β¨
β RETURN β
- a negative errno if the chip can't be registered β for example because
gc->baseis invalid, or it's already associated with a different chip π - otherwise it returns zero as a success code. slay. that zero ate π
π¦ SEE ALSO π¦
- Kernel file
./include/linux/gpio/driver.h struct gpio_irq_chip(9)struct gpio_chip(9)for_each_hwgpio_in_range(9)for_each_hwgpio(9)for_each_requested_gpio_in_range(9)struct gpio_pin_range(9)
and that's the whole page, no cap π this one lives in ./include/linux/gpio, dated October 2026 β go read the source bestie, it's lowkey all there πΈπ«Ά
π¦ 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