Skip to content

devm_gpiod_get()

Purpose

Gets a GPIO descriptor by function name from firmware data such as Device Tree.

#include <linux/gpio/consumer.h>

Prototype

struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id, enum gpiod_flags flags);

Parameters

  • dev: device used for lookup and managed cleanup.
  • con_id: GPIO function name, mapped to <con_id>-gpios.
  • flags: initial direction/value flags.

Return Value

  • Success: returns a GPIO descriptor.
  • Failure: returns an error pointer; check with IS_ERR().

Minimal Example

priv->led = devm_gpiod_get(dev, "led", GPIOD_OUT_LOW);
if (IS_ERR(priv->led))
    return PTR_ERR(priv->led);

Common Pitfalls

  • "led" maps to the led-gpios Device Tree property.
  • Do not hardcode GPIO numbers in portable drivers.
  • Use descriptor-based GPIO APIs such as gpiod_set_value().