aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-10-11 15:02:03 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-10-13 08:50:04 +0200
commit370232d096e3fe188e4596f77bc6560636bd40c1 (patch)
treef4897b29c370cde5171981b11bb11aa571a2283c
parentgpiolib: provide gpio_device_to_device() (diff)
downloadwireguard-linux-370232d096e3fe188e4596f77bc6560636bd40c1.tar.xz
wireguard-linux-370232d096e3fe188e4596f77bc6560636bd40c1.zip
gpiolib: provide gpiod_to_gpio_device()
Accessing struct gpio_chip backing a GPIO device is only allowed for the actual providers of that chip. Similarly to how we introduced gpio_device_find() in order to replace the abused gpiochip_find(), let's introduce a counterpart to gpiod_to_chip() that returns a reference to the GPIO device owning the descriptor. This is done in order to later remove gpiod_to_chip() entirely. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Peter Rosin <peda@axentia.se> Acked-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpiolib.c21
-rw-r--r--include/linux/gpio/driver.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 7e297ae35f8c..9febaef6767d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -221,6 +221,27 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
EXPORT_SYMBOL_GPL(gpiod_to_chip);
/**
+ * gpiod_to_gpio_device() - Return the GPIO device to which this descriptor
+ * belongs.
+ * @desc: Descriptor for which to return the GPIO device.
+ *
+ * This *DOES NOT* increase the reference count of the GPIO device as it's
+ * expected that the descriptor is requested and the users already holds a
+ * reference to the device.
+ *
+ * Returns:
+ * Address of the GPIO device owning this descriptor.
+ */
+struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc)
+{
+ if (!desc)
+ return NULL;
+
+ return desc->gdev;
+}
+EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
+
+/**
* gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device
* @gdev: GPIO device
*
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 0e40098aa283..d231c4f31cb4 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -785,6 +785,7 @@ int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset);
void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset);
struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
+struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc);
#else /* CONFIG_GPIOLIB */