diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-21 15:27:57 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-23 08:28:39 +0100 |
commit | cb046503d2c206a324493b292da00228ef945bf8 (patch) | |
tree | ee16ce53743522e4023308ac0cf40337765fb757 | |
parent | d35796c3b19c66baa5c44d00e5d7b9bc035429ea (diff) | |
download | barebox-cb046503d2c206a324493b292da00228ef945bf8.tar.gz barebox-cb046503d2c206a324493b292da00228ef945bf8.tar.xz |
gpio: add slice support
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.
Link: https://lore.barebox.org/20240221142800.1958810-2-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/gpio/gpiolib.c | 11 | ||||
-rw-r--r-- | include/gpio.h | 15 |
2 files changed, 26 insertions, 0 deletions
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); |