[PATCH 05/12] gpiolib: add support for gpiod_set_consumer_name
Marco Felsch
m.felsch at pengutronix.de
Fri Nov 15 11:57:40 PST 2024
Add support for the Linux gpiod_set_consumer_name() API to make it
easier to port drivers. Compared to Linux the function itself is very
different.
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
drivers/gpio/gpiolib.c | 19 +++++++++++++++++++
include/linux/gpio/consumer.h | 10 ++++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 55beaba6acbc..ec4d8e889bb1 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1223,6 +1223,25 @@ int gpiod_set_array_value(unsigned int array_size,
}
EXPORT_SYMBOL_GPL(gpiod_set_array_value);
+/**
+ * gpiod_set_consumer_name() - set the consumer name for the descriptor
+ * @desc: gpio to set the consumer name on
+ * @name: the new consumer name
+ *
+ * Returns:
+ * 0 on success, or negative errno on failure.
+ */
+int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)
+{
+ VALIDATE_DESC(desc);
+
+ free(desc->label);
+ desc->label = xstrdup(name);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(gpiod_set_consumer_name);
+
int gpiochip_add(struct gpio_chip *chip)
{
int i;
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 34e5795cbc07..d411c3aa3608 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -84,6 +84,8 @@ int gpiod_get_value(const struct gpio_desc *desc);
void gpiod_put(struct gpio_desc *desc);
+int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
+
int gpiod_count(struct device *dev, const char *con_id);
struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
@@ -172,6 +174,14 @@ static inline void gpiod_put(struct gpio_desc *desc)
WARN_ON(desc);
}
+static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
+ const char *name)
+{
+ /* GPIO can never have been requested */
+ WARN_ON(desc);
+ return -EINVAL;
+}
+
static inline int gpiod_count(struct device *dev, const char *con_id)
{
return 0;
--
2.39.5
More information about the barebox
mailing list