gpiod_count(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… gpiod_count β€” bestie's guide to counting GPIOs

okay so this is a page from the Kernel API Manual (that's the manual name, we're not copying the header line, we're being cute about it ✨), and it's about gpiod_count, which is genuinely one of the most "wait, how many??" functions in the whole GPIO library. Let's get into it 🫢


✨ NAME ✨

gpiod_count β€” it returns the number of GPIOs associated with a device or a function. that's it, that's the whole job, and honestly? iconic for it πŸ’…


🌸 SYNOPSIS 🌸

int gpiod_count (struct device *dev , const char *con_id );

that's the whole signature, no cap. two arguments, both pointers, and it hands you back an int.


πŸŽ€ ARGUMENTS πŸŽ€

  • dev β€” this is the GPIO consumer, fr fr. it's a struct device * and yes, it can be NULL β€” and if you do that, you get the system-global GPIOs instead. so like, no device? no problem, you're just playing on hard mode globally 🌍
  • con_id β€” the function within the GPIO consumer. a const char * holding the name of the function you're asking about. it's the "which one tho" of the operation πŸ’–

πŸ”₯ RETURN πŸ”₯

it returns the number of GPIOs associated with that device / function β€” a plain, satisfying int ✨

BUT if no GPIO has been assigned to the function you asked about, you get -ENOENT 😭 so like, always vibe check your return value, because it's not always a happy little count. it could be a negative errno. check it. please. i'm begging 🫢


πŸ¦‹ SEE ALSO πŸ¦‹

okay bestie this list is long, but every single one of these is a real friend of the family and i'm not skipping a single one, periodt. they all live in the kernel file ./drivers/gpio/gpiolib.c:

like i said. long list. every name there though, not one dropped, i would never πŸ™ˆ


ok tiny note that this whole page is sourced from ./drivers/gpio, and it's dated October 2026 🌈 β€” and the manual we've been living in is gpiod_count(9). mwah, stan, go count some GPIOs bestie πŸ‘‘πŸ’œ
πŸ“¦ where this page comes from