Commit 43c54eca authored by Linus Walleij's avatar Linus Walleij

gpio: move the subdriver data pointer into gpio_device

We move to manage this pointer under gpiolib control rather than
leave it in the subdevice's gpio_chip. We can not NULL it after
gpiochip_remove so at to keep things tight.
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 20ec3e39
...@@ -480,8 +480,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) ...@@ -480,8 +480,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
goto err_free_gdev; goto err_free_gdev;
} }
gdev->ngpio = chip->ngpio; gdev->ngpio = chip->ngpio;
/* FIXME: move driver data into gpio_device dev_set_drvdata() */ gdev->data = data;
chip->data = data;
spin_lock_irqsave(&gpio_lock, flags); spin_lock_irqsave(&gpio_lock, flags);
...@@ -602,6 +601,15 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) ...@@ -602,6 +601,15 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
} }
EXPORT_SYMBOL_GPL(gpiochip_add_data); EXPORT_SYMBOL_GPL(gpiochip_add_data);
/**
* gpiochip_get_data() - get per-subdriver data for the chip
*/
void *gpiochip_get_data(struct gpio_chip *chip)
{
return chip->gpiodev->data;
}
EXPORT_SYMBOL_GPL(gpiochip_get_data);
/** /**
* gpiochip_remove() - unregister a gpio_chip * gpiochip_remove() - unregister a gpio_chip
* @chip: the chip to unregister * @chip: the chip to unregister
...@@ -626,6 +634,11 @@ void gpiochip_remove(struct gpio_chip *chip) ...@@ -626,6 +634,11 @@ void gpiochip_remove(struct gpio_chip *chip)
gpiochip_remove_pin_ranges(chip); gpiochip_remove_pin_ranges(chip);
gpiochip_free_hogs(chip); gpiochip_free_hogs(chip);
of_gpiochip_remove(chip); of_gpiochip_remove(chip);
/*
* We accept no more calls into the driver from this point, so
* NULL the driver data pointer
*/
gdev->data = NULL;
spin_lock_irqsave(&gpio_lock, flags); spin_lock_irqsave(&gpio_lock, flags);
for (i = 0; i < gdev->ngpio; i++) { for (i = 0; i < gdev->ngpio; i++) {
......
...@@ -37,6 +37,7 @@ struct acpi_device; ...@@ -37,6 +37,7 @@ struct acpi_device;
* of the @descs array. * of the @descs array.
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
* at device creation time. * at device creation time.
* @data: per-instance data assigned by the driver
* @list: links gpio_device:s together for traversal * @list: links gpio_device:s together for traversal
* *
* This state container holds most of the runtime variable data * This state container holds most of the runtime variable data
...@@ -54,6 +55,7 @@ struct gpio_device { ...@@ -54,6 +55,7 @@ struct gpio_device {
struct gpio_desc *descs; struct gpio_desc *descs;
int base; int base;
u16 ngpio; u16 ngpio;
void *data;
struct list_head list; struct list_head list;
#ifdef CONFIG_PINCTRL #ifdef CONFIG_PINCTRL
......
...@@ -25,7 +25,6 @@ struct gpio_device; ...@@ -25,7 +25,6 @@ struct gpio_device;
* @gpiodev: the internal state holder, opaque struct * @gpiodev: the internal state holder, opaque struct
* @parent: optional parent device providing the GPIOs * @parent: optional parent device providing the GPIOs
* @owner: helps prevent removal of modules exporting active GPIOs * @owner: helps prevent removal of modules exporting active GPIOs
* @data: per-instance data assigned by the driver
* @request: optional hook for chip-specific activation, such as * @request: optional hook for chip-specific activation, such as
* enabling module power and clock; may sleep * enabling module power and clock; may sleep
* @free: optional hook for chip-specific deactivation, such as * @free: optional hook for chip-specific deactivation, such as
...@@ -109,7 +108,6 @@ struct gpio_chip { ...@@ -109,7 +108,6 @@ struct gpio_chip {
struct gpio_device *gpiodev; struct gpio_device *gpiodev;
struct device *parent; struct device *parent;
struct module *owner; struct module *owner;
void *data;
int (*request)(struct gpio_chip *chip, int (*request)(struct gpio_chip *chip,
unsigned offset); unsigned offset);
...@@ -202,10 +200,7 @@ void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); ...@@ -202,10 +200,7 @@ void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset); bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset);
/* get driver data */ /* get driver data */
static inline void *gpiochip_get_data(struct gpio_chip *chip) void *gpiochip_get_data(struct gpio_chip *chip);
{
return chip->data;
}
struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment