diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c index 3dd29399cef52530ff3fa60f04e1a777d079b684..d21a9ff38551fa6a485c8805eb1cafd337cf92de 100644 --- a/drivers/gpio/devres.c +++ b/drivers/gpio/devres.c @@ -70,6 +70,35 @@ int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) } EXPORT_SYMBOL(devm_gpio_request); +/** + * devm_gpio_request_one - request a single GPIO with initial setup + * @dev: device to request for + * @gpio: the GPIO number + * @flags: GPIO configuration as specified by GPIOF_* + * @label: a literal description string of this GPIO + */ +int devm_gpio_request_one(struct device *dev, unsigned gpio, + unsigned long flags, const char *label) +{ + unsigned *dr; + int rc; + + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rc = gpio_request_one(gpio, flags, label); + if (rc) { + devres_free(dr); + return rc; + } + + *dr = gpio; + devres_add(dev, dr); + + return 0; +} + /** * devm_gpio_free - free an interrupt * @dev: device to free gpio for diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 5f52690c3c8f3a632350d14b1511908299887efb..4ead12332c66f043c49b834b7ddbbfe9b5bdad2b 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -179,6 +179,8 @@ extern void gpio_free_array(const struct gpio *array, size_t num); /* bindings for managed devices that want to request gpios */ int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); +int devm_gpio_request_one(struct device *dev, unsigned gpio, + unsigned long flags, const char *label); void devm_gpio_free(struct device *dev, unsigned int gpio); #ifdef CONFIG_GPIO_SYSFS diff --git a/include/linux/gpio.h b/include/linux/gpio.h index 7a8816a1a0d8a29e79656dc7db3979844110deb2..f07fc2d081598ba7c2432a2306081473d3e0bbe1 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h @@ -106,6 +106,12 @@ static inline int gpio_request_one(unsigned gpio, return -ENOSYS; } +static inline int devm_gpio_request_one(struct device *dev, unsigned gpio, + unsigned long flags, const char *label) +{ + return -ENOSYS; +} + static inline int gpio_request_array(const struct gpio *array, size_t num) { return -ENOSYS;