[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231011130204.52265-2-brgl@bgdev.pl>
Date: Wed, 11 Oct 2023 15:02:02 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Linus Walleij <linus.walleij@...aro.org>,
Andy Shevchenko <andy@...nel.org>,
Peter Korsgaard <peter.korsgaard@...co.com>,
Peter Rosin <peda@...ntia.se>
Cc: linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-i2c@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: [PATCH 1/3] gpiolib: provide gpio_device_to_device()
From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
There are users in the kernel who need to retrieve the address of the
struct device backing the GPIO device. Currently they needlessly poke in
the internals of GPIOLIB. Add a dedicated getter function.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
---
drivers/gpio/gpiolib.c | 17 +++++++++++++++++
include/linux/gpio/driver.h | 2 ++
2 files changed, 19 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 191f9c87b4d0..ca2b5b424284 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1169,6 +1169,23 @@ void gpio_device_put(struct gpio_device *gdev)
}
EXPORT_SYMBOL_GPL(gpio_device_put);
+/**
+ * gpio_device_to_device() - Retrieve the address of the underlying struct
+ * device.
+ * @gdev: GPIO device for which to return the address.
+ *
+ * This does not increase the reference count of the GPIO device nor the
+ * underlying struct device.
+ *
+ * Returns:
+ * Address of struct device backing this GPIO device.
+ */
+struct device *gpio_device_to_device(struct gpio_device *gdev)
+{
+ return &gdev->dev;
+}
+EXPORT_SYMBOL_GPL(gpio_device_to_device);
+
#ifdef CONFIG_GPIOLIB_IRQCHIP
/*
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index f8ad7f40100c..0484bf90b25d 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -618,6 +618,8 @@ void gpio_device_put(struct gpio_device *gdev);
DEFINE_FREE(gpio_device_put, struct gpio_device *,
if (IS_ERR_OR_NULL(_T)) gpio_device_put(_T));
+struct device *gpio_device_to_device(struct gpio_device *gdev);
+
bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset);
int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset);
void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset);
--
2.39.2
Powered by blists - more mailing lists