[PATCH] gpiochip: expose gpiochip set data to be able to use it with a an usb gpio expander for example.

From: chalianis1
Date: Mon May 19 2025 - 00:19:10 EST


From: Anis Chali <chalianis1@xxxxxxxxx>

Signed-off-by: Anis Chali <chalianis1@xxxxxxxxx>
---
drivers/gpio/gpiolib.c | 8 +++++++-
include/linux/gpio/driver.h | 3 +++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cd4fecbb41f2..58d051141f53 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -900,10 +900,16 @@ static void gpiochip_setup_devs(void)
}
}

-static void gpiochip_set_data(struct gpio_chip *gc, void *data)
+/**
+ * gpiochip_set_data() - set per-subdriver data for the chip
+ * @gc: GPIO chip
+ * @data: Data for GPIO chip
+ */
+void gpiochip_set_data(struct gpio_chip *gc, void *data)
{
gc->gpiodev->data = data;
}
+EXPORT_SYMBOL_GPL(gpiochip_set_data);

/**
* gpiochip_get_data() - get per-subdriver data for the chip
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 4c0294a9104d..b1206fe42c26 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -717,6 +717,9 @@ const unsigned long *gpiochip_query_valid_mask(const struct gpio_chip *gc);
/* get driver data */
void *gpiochip_get_data(struct gpio_chip *gc);

+/* gpiochip set data */
+void gpiochip_set_data(struct gpio_chip *gc, void *data);
+
struct bgpio_pdata {
const char *label;
int base;
--
2.49.0