From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [PATCH 11/15 v3] gpio: Add devm_gpiod_unhinge()
Date: Wed, 5 Dec 2018 15:34:01 +0100 [thread overview]
Message-ID: <0179c784-137d-b37a-1b93-cf2f957730a8@samsung.com> (raw)
In-Reply-To: <20181205124721.26624-12-linus.walleij@linaro.org>
Hi Linus,
On 2018-12-05 13:47, Linus Walleij wrote:
> 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.
>
> Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v2->v3:
> - Make sure to bail out of gpiod_unhinge() if the descritor
> passed in is NULL or an error pointer.
> - Accept of devres_destroy() returns -ENOENT: if we have
> nonexclusive GPIOs, we may attempt to remove resource
> management from the same descriptor multiple times.
> ChangeLog v1->v2:
> - New patch to be able to hand over GPIO descriptors to
> the regulator core.
> - Mark: feel free to apply this to the regulator tree with
> the regulator tree with the rest.
> ---
> Documentation/driver-model/devres.txt | 1 +
> drivers/gpio/gpiolib-devres.c | 30 +++++++++++++++++++++++++++
> include/linux/gpio/consumer.h | 10 +++++++++
> 3 files changed, 41 insertions(+)
>
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index 43681ca0837f..fc4cc24dfb97 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -254,6 +254,7 @@ GPIO
> devm_gpiod_get_index_optional()
> devm_gpiod_get_optional()
> devm_gpiod_put()
> + devm_gpiod_unhinge()
> devm_gpiochip_add_data()
> devm_gpiochip_remove()
> devm_gpio_request()
> diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
> index a57e968025a8..e9a17ec4de02 100644
> --- a/drivers/gpio/gpiolib-devres.c
> +++ b/drivers/gpio/gpiolib-devres.c
> @@ -346,6 +346,36 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
> }
> 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);
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()
> * @dev: GPIO consumer
> diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> index 348885f2f3d3..8aebcf822082 100644
> --- a/include/linux/gpio/consumer.h
> +++ b/include/linux/gpio/consumer.h
> @@ -104,6 +104,7 @@ struct gpio_descs *__must_check
> devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
> enum gpiod_flags flags);
> 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);
>
> int gpiod_get_direction(struct gpio_desc *desc);
> @@ -249,6 +250,15 @@ static inline void gpiod_put(struct gpio_desc *desc)
> 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)
> {
> might_sleep();
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
next prev parent reply other threads:[~2018-12-05 14:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 12:47 [PATCH 00/15 v3] Regulator ena_gpiod fixups Linus Walleij
2018-12-05 12:47 ` [PATCH 01/15 v3] regulator: core: Track dangling GPIO descriptors Linus Walleij
2018-12-05 12:47 ` [PATCH 02/15 v3] regulator: fixed: Let core handle GPIO descriptor Linus Walleij
2018-12-05 12:47 ` [PATCH 03/15 v3] regulator: lm363x: " Linus Walleij
2018-12-05 12:47 ` [PATCH 04/15 v3] regulator: lp8788-ldo: " Linus Walleij
2018-12-05 12:47 ` [PATCH 05/15 v3] regulator: max8952: " Linus Walleij
2018-12-05 12:47 ` [PATCH 06/15 v3] regulator: max8973: " Linus Walleij
2018-12-05 13:43 ` Charles Keepax
2018-12-05 14:42 ` Linus Walleij
2018-12-05 15:33 ` Charles Keepax
2018-12-06 8:58 ` Linus Walleij
2018-12-06 10:34 ` Charles Keepax
2018-12-06 11:47 ` Linus Walleij
2018-12-06 11:53 ` Charles Keepax
2018-12-05 12:47 ` [PATCH 07/15 v3] gpio: Export gpiod_get_from_of_node() Linus Walleij
2018-12-05 12:47 ` [PATCH 08/15 v3] regulator: max77686: Let core handle GPIO descriptor Linus Walleij
2018-12-05 12:47 ` [PATCH 09/15 v3] gpio: Enable nonexclusive gpiods from DT nodes Linus Walleij
2018-12-05 12:47 ` [PATCH 10/15 v3] gpio: devres: Handle nonexclusive GPIOs Linus Walleij
2018-12-05 14:34 ` Marek Szyprowski
2018-12-05 12:47 ` [PATCH 11/15 v3] gpio: Add devm_gpiod_unhinge() Linus Walleij
2018-12-05 14:34 ` Marek Szyprowski [this message]
2018-12-05 12:47 ` [PATCH 12/15 v3] regulator: da9211: Hand over GPIO to regulator core Linus Walleij
2018-12-05 12:47 ` [PATCH 13/15 v3] regulator: s5m8767: " Linus Walleij
2018-12-05 12:47 ` [PATCH 14/15 v3] regulator: tps65090: " Linus Walleij
2018-12-05 12:47 ` [PATCH 15/15 v3] regulator: s2mps11: " Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0179c784-137d-b37a-1b93-cf2f957730a8@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=bgolaszewski@baylibre.com \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®