mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/4] gpio: add slice support
Date: Wed, 21 Feb 2024 15:27:57 +0100	[thread overview]
Message-ID: <20240221142800.1958810-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240221142800.1958810-1-s.hauer@pengutronix.de>

GPIOs are not only provided by raw register accesses but also by I2C
devices. Add a slice to a gpio chip so that a gpio user can check if the
slice is acquired before using it in a poller.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 11 +++++++++++
 include/gpio.h         | 15 +++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bcfdd5a0dd..5bc261a010 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -172,6 +172,16 @@ int gpio_request(unsigned gpio, const char *label)
 	return gpiodesc_request(desc, label);
 }
 
+bool gpio_slice_acquired(unsigned gpio)
+{
+	struct gpio_desc *desc = gpio_to_desc(gpio);
+
+	if (!desc)
+		return false;
+
+	return slice_acquired(&desc->chip->slice);
+}
+
 static void gpiodesc_free(struct gpio_desc *desc)
 {
 	if (!desc->requested)
@@ -1013,6 +1023,7 @@ int gpiochip_add(struct gpio_chip *chip)
 			return -ENOSPC;
 	}
 
+	slice_init(&chip->slice, dev_name(chip->dev));
 
 	list_add_tail(&chip->list, &chip_list);
 
diff --git a/include/gpio.h b/include/gpio.h
index 9951532084..adc1eb39ac 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -2,6 +2,7 @@
 #ifndef __GPIO_H
 #define __GPIO_H
 
+#include <slice.h>
 #include <linux/types.h>
 #include <linux/list.h>
 #include <linux/iopoll.h>
@@ -156,6 +157,12 @@ static inline int gpio_array_to_id(const struct gpio *array, size_t num, u32 *va
 {
 	return -EINVAL;
 }
+
+static inline bool gpio_slice_acquired(unsigned gpio)
+{
+	return false;
+}
+
 #else
 int gpio_request(unsigned gpio, const char *label);
 int gpio_find_by_name(const char *name);
@@ -165,6 +172,7 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
 int gpio_request_array(const struct gpio *array, size_t num);
 void gpio_free_array(const struct gpio *array, size_t num);
 int gpio_array_to_id(const struct gpio *array, size_t num, u32 *val);
+bool gpio_slice_acquired(unsigned gpio);
 #endif
 
 struct gpio_chip;
@@ -213,9 +221,16 @@ struct gpio_chip {
 
 	struct gpio_ops *ops;
 
+	struct slice slice;
+
 	struct list_head list;
 };
 
+static inline struct slice *gpiochip_slice(struct gpio_chip *chip)
+{
+	return &chip->slice;
+}
+
 int gpiochip_add(struct gpio_chip *chip);
 void gpiochip_remove(struct gpio_chip *chip);
 
-- 
2.39.2




  reply	other threads:[~2024-02-21 14:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 14:27 [PATCH 0/4] make I2C GPIO expander provided buttons work Sascha Hauer
2024-02-21 14:27 ` Sascha Hauer [this message]
2024-02-21 14:27 ` [PATCH 2/4] gpio: pca953x: depend on i2c slice Sascha Hauer
2024-02-21 14:27 ` [PATCH 3/4] input: gpio_keys: limit poll rate Sascha Hauer
2024-02-21 14:28 ` [PATCH 4/4] input: gpio_keys: only use gpios in poller when not in use Sascha Hauer
2024-02-23  7:32 ` [PATCH 0/4] make I2C GPIO expander provided buttons work Sascha Hauer

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=20240221142800.1958810-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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