gpiolib: provide gpio_device_get_base()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 5 Sep 2023 18:52:55 +0000 (20:52 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 13 Oct 2023 07:05:57 +0000 (09:05 +0200)
Let's start adding getters for the opaque struct gpio_device. Start with
a function allowing to retrieve the base GPIO number.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c
include/linux/gpio/driver.h

index 9febaef6767d113d1ef53eafa11878bd592a6edd..cbafcd95243e8fcb2c29912a9073afb350d8203a 100644 (file)
@@ -241,6 +241,19 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc)
 }
 EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
 
+/**
+ * gpio_device_get_base() - Get the base GPIO number allocated by this device
+ * @gdev: GPIO device
+ *
+ * Returns:
+ * First GPIO number in the global GPIO numberspace for this device.
+ */
+int gpio_device_get_base(struct gpio_device *gdev)
+{
+       return gdev->base;
+}
+EXPORT_SYMBOL_GPL(gpio_device_get_base);
+
 /**
  * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device
  * @gdev: GPIO device
index d231c4f31cb43e1047b109e10acb35eee41a4c04..1d454dc944b37fa379c3a1dd7af266281cd2e4cb 100644 (file)
@@ -787,6 +787,9 @@ 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);
 
+/* struct gpio_device getters */
+int gpio_device_get_base(struct gpio_device *gdev);
+
 #else /* CONFIG_GPIOLIB */
 
 #include <linux/err.h>