[PATCH] gpiolib: implement gpiod_slice_acquired

Ahmad Fatoum a.fatoum at pengutronix.de
Sun Apr 14 22:28:50 PDT 2024


For use by poller code that makes use of GPIO descriptors instead of the
unstable indices, add a gpiod variant of the existing
gpiod_slice_acquird.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/gpio/gpiolib.c        | 11 ++++++++---
 include/linux/gpio/consumer.h |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5bc261a0105c..a70e13eafca2 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -172,16 +172,21 @@ int gpio_request(unsigned gpio, const char *label)
 	return gpiodesc_request(desc, label);
 }
 
-bool gpio_slice_acquired(unsigned gpio)
+bool gpiod_slice_acquired(struct gpio_desc *desc)
 {
-	struct gpio_desc *desc = gpio_to_desc(gpio);
-
 	if (!desc)
 		return false;
 
 	return slice_acquired(&desc->chip->slice);
 }
 
+bool gpio_slice_acquired(unsigned gpio)
+{
+	struct gpio_desc *desc = gpio_to_desc(gpio);
+
+	return gpiod_slice_acquired(desc);
+}
+
 static void gpiodesc_free(struct gpio_desc *desc)
 {
 	if (!desc->requested)
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 531ed1472546..e04f516b3155 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -45,6 +45,8 @@ struct gpio_descs {
 	DECLARE_FLEX_ARRAY(struct gpio_desc *, desc);
 };
 
+bool gpiod_slice_acquired(struct gpio_desc *);
+
 #if defined(CONFIG_OFDEVICE) && defined(CONFIG_GPIOLIB)
 
 /* returned gpio descriptor can be passed to any normal gpio_* function */
-- 
2.39.2




More information about the barebox mailing list