Commit 891ddbc7 authored by Linus Walleij's avatar Linus Walleij Committed by Mark Brown

gpio: Add devm_gpiod_unhinge()

This adds a function named devm_gpiod_unhinge() that removes
the resource management from a GPIO descriptor.

I am not sure if this is the best anglosaxon name for the
function, no other managed resources have an equivalent
currently, but I chose "unhinge" as the closest intuitive
thing I could imagine that fits Rusty Russell's API design
criterions "the obvious use is the correct one" and
"the name tells you how to use it".

The idea came out of a remark from Mark Brown that it should
be possible to handle over management of a resource from
devres to the regulator core, and indeed we can do that.
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Reviewed-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Tested-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent cb28ee38
...@@ -254,6 +254,7 @@ GPIO ...@@ -254,6 +254,7 @@ GPIO
devm_gpiod_get_index_optional() devm_gpiod_get_index_optional()
devm_gpiod_get_optional() devm_gpiod_get_optional()
devm_gpiod_put() devm_gpiod_put()
devm_gpiod_unhinge()
devm_gpiochip_add_data() devm_gpiochip_add_data()
devm_gpiochip_remove() devm_gpiochip_remove()
devm_gpio_request() devm_gpio_request()
......
...@@ -346,6 +346,36 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) ...@@ -346,6 +346,36 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
} }
EXPORT_SYMBOL(devm_gpiod_put); EXPORT_SYMBOL(devm_gpiod_put);
/**
* devm_gpiod_unhinge - Remove resource management from a gpio descriptor
* @dev: GPIO consumer
* @desc: GPIO descriptor to remove resource management from
*
* Remove resource management from a GPIO descriptor. This is needed when
* you want to hand over lifecycle management of a descriptor to another
* mechanism.
*/
void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc)
{
int ret;
if (IS_ERR_OR_NULL(desc))
return;
ret = devres_destroy(dev, devm_gpiod_release,
devm_gpiod_match, &desc);
/*
* If the GPIO descriptor is requested as nonexclusive, we
* may call this function several times on the same descriptor
* so it is OK if devres_destroy() returns -ENOENT.
*/
if (ret == -ENOENT)
return;
/* Anything else we should warn about */
WARN_ON(ret);
}
EXPORT_SYMBOL(devm_gpiod_unhinge);
/** /**
* devm_gpiod_put_array - Resource-managed gpiod_put_array() * devm_gpiod_put_array - Resource-managed gpiod_put_array()
* @dev: GPIO consumer * @dev: GPIO consumer
......
...@@ -104,6 +104,7 @@ struct gpio_descs *__must_check ...@@ -104,6 +104,7 @@ struct gpio_descs *__must_check
devm_gpiod_get_array_optional(struct device *dev, const char *con_id, devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags); enum gpiod_flags flags);
void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
int gpiod_get_direction(struct gpio_desc *desc); int gpiod_get_direction(struct gpio_desc *desc);
...@@ -249,6 +250,15 @@ static inline void gpiod_put(struct gpio_desc *desc) ...@@ -249,6 +250,15 @@ static inline void gpiod_put(struct gpio_desc *desc)
WARN_ON(1); WARN_ON(1);
} }
static inline void devm_gpiod_unhinge(struct device *dev,
struct gpio_desc *desc)
{
might_sleep();
/* GPIO can never have been requested */
WARN_ON(1);
}
static inline void gpiod_put_array(struct gpio_descs *descs) static inline void gpiod_put_array(struct gpio_descs *descs)
{ {
might_sleep(); might_sleep();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment