@@ -390,3 +390,19 @@ void devm_gpio_free(struct device *dev, unsigned int gpio)
&gpio));
}
EXPORT_SYMBOL(devm_gpio_free);
+
+int devm_acquire_gpio_named(struct device *dev,
+ const struct devm_resource *resource)
+{
+ struct gpio_desc *desc, **descp;
+
+ desc = devm_get_gpiod_from_child(dev, resource->name, dev->fwnode);
+ if (IS_ERR(desc))
+ return PTR_ERR(desc);
+
+ descp = dev_get_drvdata(dev) + resource->offset;
+ *descp = desc;
+
+ return 0;
+}
+EXPORT_SYMBOL(devm_acquire_gpio_named);
@@ -6,6 +6,7 @@
#include <linux/kernel.h>
struct device;
+struct devm_resource;
/**
* Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
@@ -139,6 +140,16 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
const char *con_id,
struct fwnode_handle *child);
+
+int devm_acquire_gpio_named(struct device *dev,
+ const struct devm_resource *resource);
+
+#define DEVM_GPIO_NAMED(_struct, _member, _name) { \
+ .initfunc = devm_acquire_gpio_named, \
+ .offset = offsetof_t(struct _struct, _member, struct gpio_desc *),\
+ .name = _name, \
+}
+
#else /* CONFIG_GPIOLIB */
static inline int gpiod_count(struct device *dev, const char *con_id)
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> --- drivers/gpio/devres.c | 16 ++++++++++++++++ include/linux/gpio/consumer.h | 11 +++++++++++ 2 files changed, 27 insertions(+)