Merge branch 'pcmcia' of git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia
[linux-2.6-microblaze.git] / drivers / gpio / devres.c
index afbff15..e82cc76 100644 (file)
@@ -124,6 +124,48 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
 }
 EXPORT_SYMBOL(devm_gpiod_get_index);
 
+/**
+ * devm_gpiod_get_from_of_node() - obtain a GPIO from an OF node
+ * @dev:       device for lifecycle management
+ * @node:      handle of the OF node
+ * @propname:  name of the DT property representing the GPIO
+ * @index:     index of the GPIO to obtain for the consumer
+ * @dflags:    GPIO initialization flags
+ * @label:     label to attach to the requested GPIO
+ *
+ * Returns:
+ * On successful request the GPIO pin is configured in accordance with
+ * provided @dflags.
+ *
+ * In case of error an ERR_PTR() is returned.
+ */
+struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
+                                             struct device_node *node,
+                                             const char *propname, int index,
+                                             enum gpiod_flags dflags,
+                                             const char *label)
+{
+       struct gpio_desc **dr;
+       struct gpio_desc *desc;
+
+       dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
+                         GFP_KERNEL);
+       if (!dr)
+               return ERR_PTR(-ENOMEM);
+
+       desc = gpiod_get_from_of_node(node, propname, index, dflags, label);
+       if (IS_ERR(desc)) {
+               devres_free(dr);
+               return desc;
+       }
+
+       *dr = desc;
+       devres_add(dev, dr);
+
+       return desc;
+}
+EXPORT_SYMBOL(devm_gpiod_get_from_of_node);
+
 /**
  * devm_fwnode_get_index_gpiod_from_child - get a GPIO descriptor from a
  *                                         device's child node