devm_fwnode_...get_optional(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– devm_fwnode_gpiod_get_optional β€” obtain an optional GPIO from firmware node πŸ’–

okay so bestie, welcome to the devm_fwnode_...get_optional(9) page from the Kernel API Manual ✨ (yes the title is a whole abbreviation situation, the full name is devm_fwnode_gpiod_get_optional, and like… it's a mouthful but we move πŸ’…).


✨ SYNOPSIS ✨

struct gpio_desc * devm_fwnode_gpiod_get_optional (struct device *dev ,
struct fwnode_handle *fwnode , const char *con_id , enum gpiod_flags
flags , const char *label );

like just look at that signature, she's got five arguments and she's serving πŸ’…


🫢 ARGUMENTS 🫢

  • dev β€” the GPIO consumer. the main character, basically πŸ‘‘
  • fwnode β€” handle of the firmware node πŸ¦‹
  • con_id β€” the function within the GPIO consumer 🌸
  • flags β€” GPIO initialization flags, the little settings gremlins βš™οΈβœ¨
  • label β€” the label you attach to the requested GPIO πŸŽ€

🌈 DESCRIPTION 🌈

so this function is lowkey made for drivers that get their configuration from opaque firmware πŸ‘€ β€” like, the driver doesn't know the details, it just asks the firmware and the firmware knows. iykyk.

and here's the iconic part: the GPIO descriptors you get back from this function are automatically disposed on driver detach 🧚✨ like bestie it cleans up after itself, no manual freeing, we love a self-sufficient queen πŸ’…


πŸ”₯ RETURN πŸ”₯

so what do you get back? it's giving multiple possibilities, keep up:

  • the GPIO descriptor corresponding to the optional function con_id of device dev πŸ’–
  • NULL if no GPIO has been assigned to the requested function πŸ™ˆ
  • or another IS_ERR code if an error occurred while trying to acquire the GPIO πŸ’€
fr fr check for errors, don't just assume it worked 😭

πŸ¦‹ SEE ALSO πŸ¦‹

  • Kernel file ./include/linux/gpio/consumer.h
  • struct gpio_descs(9)
  • enum gpiod_flags(9)

and that's the whole vibe bestie, go forth and get those optional GPIOs πŸ“πŸ’œ

sign-off szn: this lil masterpiece comes from the ./include/linux/gpio source, dated October 2026, and it's filed under devm_fwnode_...get_optional(9) β€” periodt πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from