Skip to content

Commit 9b41878

Browse files
author
Bartosz Golaszewski
committed
gpiolib: reluctantly provide gpio_device_get_chip()
The process of converting all unauthorized users of struct gpio_chip to using dedicated struct gpio_device function will be long so in the meantime we must provide a way of retrieving the pointer to struct gpio_chip from a GPIO device. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]>
1 parent 93548f8 commit 9b41878

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
220220
}
221221
EXPORT_SYMBOL_GPL(gpiod_to_chip);
222222

223+
/**
224+
* gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device
225+
* @gdev: GPIO device
226+
*
227+
* Returns:
228+
* Address of the GPIO chip backing this device.
229+
*
230+
* Until we can get rid of all non-driver users of struct gpio_chip, we must
231+
* provide a way of retrieving the pointer to it from struct gpio_device. This
232+
* is *NOT* safe as the GPIO API is considered to be hot-unpluggable and the
233+
* chip can dissapear at any moment (unlike reference-counted struct
234+
* gpio_device).
235+
*
236+
* Use at your own risk.
237+
*/
238+
struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev)
239+
{
240+
return gdev->chip;
241+
}
242+
EXPORT_SYMBOL_GPL(gpio_device_get_chip);
243+
223244
/* dynamic allocation of GPIOs, e.g. on a hotplugged device */
224245
static int gpiochip_find_base(int ngpio)
225246
{

include/linux/gpio/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum);
773773
struct gpio_desc *
774774
gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum);
775775

776+
struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev);
777+
776778
#ifdef CONFIG_GPIOLIB
777779

778780
/* lock/unlock as IRQ */

0 commit comments

Comments
 (0)