diff options
| author | Linus Walleij <linus.walleij@linaro.org> | 2016-02-09 07:21:06 -0500 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2016-02-11 12:16:54 -0500 |
| commit | afbc4f312b5e6e87fcd383eb6764e09f1324c78e (patch) | |
| tree | 5428e0fe100c576dd158bba68df183010cee2009 | |
| parent | 9efd9e6956adf479eb85beb74bb975f702dc01a9 (diff) | |
gpio: move sysfs mock device to the gpio_device
Since gpio_device is the struct that survives if the backing
gpio_chip is removed, move the sysfs mock device to this state
container so it becomes part of the dangling state of the
GPIO device on removal.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
| -rw-r--r-- | drivers/gpio/gpiolib-sysfs.c | 23 | ||||
| -rw-r--r-- | drivers/gpio/gpiolib.c | 4 | ||||
| -rw-r--r-- | drivers/gpio/gpiolib.h | 11 | ||||
| -rw-r--r-- | include/linux/gpio/driver.h | 2 |
4 files changed, 21 insertions, 19 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 28d3bf2328aa..94ba4bb8b4f8 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c | |||
| @@ -572,7 +572,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) | |||
| 572 | mutex_lock(&sysfs_lock); | 572 | mutex_lock(&sysfs_lock); |
| 573 | 573 | ||
| 574 | /* check if chip is being removed */ | 574 | /* check if chip is being removed */ |
| 575 | if (!chip || !chip->cdev) { | 575 | if (!chip || !gdev->mockdev) { |
| 576 | status = -ENODEV; | 576 | status = -ENODEV; |
| 577 | goto err_unlock; | 577 | goto err_unlock; |
| 578 | } | 578 | } |
| @@ -718,9 +718,10 @@ err_unlock: | |||
| 718 | } | 718 | } |
| 719 | EXPORT_SYMBOL_GPL(gpiod_unexport); | 719 | EXPORT_SYMBOL_GPL(gpiod_unexport); |
| 720 | 720 | ||
| 721 | int gpiochip_sysfs_register(struct gpio_chip *chip) | 721 | int gpiochip_sysfs_register(struct gpio_device *gdev) |
| 722 | { | 722 | { |
| 723 | struct device *dev; | 723 | struct device *dev; |
| 724 | struct gpio_chip *chip = gdev->chip; | ||
| 724 | 725 | ||
| 725 | /* | 726 | /* |
| 726 | * Many systems add gpio chips for SOC support very early, | 727 | * Many systems add gpio chips for SOC support very early, |
| @@ -732,7 +733,7 @@ int gpiochip_sysfs_register(struct gpio_chip *chip) | |||
| 732 | return 0; | 733 | return 0; |
| 733 | 734 | ||
| 734 | /* use chip->base for the ID; it's already known to be unique */ | 735 | /* use chip->base for the ID; it's already known to be unique */ |
| 735 | dev = device_create_with_groups(&gpio_class, chip->parent, | 736 | dev = device_create_with_groups(&gpio_class, &gdev->dev, |
| 736 | MKDEV(0, 0), | 737 | MKDEV(0, 0), |
| 737 | chip, gpiochip_groups, | 738 | chip, gpiochip_groups, |
| 738 | "gpiochip%d", chip->base); | 739 | "gpiochip%d", chip->base); |
| @@ -740,25 +741,26 @@ int gpiochip_sysfs_register(struct gpio_chip *chip) | |||
| 740 | return PTR_ERR(dev); | 741 | return PTR_ERR(dev); |
| 741 | 742 | ||
| 742 | mutex_lock(&sysfs_lock); | 743 | mutex_lock(&sysfs_lock); |
| 743 | chip->cdev = dev; | 744 | gdev->mockdev = dev; |
| 744 | mutex_unlock(&sysfs_lock); | 745 | mutex_unlock(&sysfs_lock); |
| 745 | 746 | ||
| 746 | return 0; | 747 | return 0; |
| 747 | } | 748 | } |
| 748 | 749 | ||
| 749 | void gpiochip_sysfs_unregister(struct gpio_chip *chip) | 750 | void gpiochip_sysfs_unregister(struct gpio_device *gdev) |
| 750 | { | 751 | { |
| 751 | struct gpio_desc *desc; | 752 | struct gpio_desc *desc; |
| 753 | struct gpio_chip *chip = gdev->chip; | ||
| 752 | unsigned int i; | 754 | unsigned int i; |
| 753 | 755 | ||
| 754 | if (!chip->cdev) | 756 | if (!gdev->mockdev) |
| 755 | return; | 757 | return; |
| 756 | 758 | ||
| 757 | device_unregister(chip->cdev); | 759 | device_unregister(gdev->mockdev); |
| 758 | 760 | ||
| 759 | /* prevent further gpiod exports */ | 761 | /* prevent further gpiod exports */ |
| 760 | mutex_lock(&sysfs_lock); | 762 | mutex_lock(&sysfs_lock); |
| 761 | chip->cdev = NULL; | 763 | gdev->mockdev = NULL; |
| 762 | mutex_unlock(&sysfs_lock); | 764 | mutex_unlock(&sysfs_lock); |
| 763 | 765 | ||
| 764 | /* unregister gpiod class devices owned by sysfs */ | 766 | /* unregister gpiod class devices owned by sysfs */ |
| @@ -787,7 +789,7 @@ static int __init gpiolib_sysfs_init(void) | |||
| 787 | */ | 789 | */ |
| 788 | spin_lock_irqsave(&gpio_lock, flags); | 790 | spin_lock_irqsave(&gpio_lock, flags); |
| 789 | list_for_each_entry(gdev, &gpio_devices, list) { | 791 | list_for_each_entry(gdev, &gpio_devices, list) { |
| 790 | if (gdev->chip->cdev) | 792 | if (gdev->mockdev) |
| 791 | continue; | 793 | continue; |
| 792 | 794 | ||
| 793 | /* | 795 | /* |
| @@ -800,12 +802,11 @@ static int __init gpiolib_sysfs_init(void) | |||
| 800 | * gpio_lock prevents us from doing this. | 802 | * gpio_lock prevents us from doing this. |
| 801 | */ | 803 | */ |
| 802 | spin_unlock_irqrestore(&gpio_lock, flags); | 804 | spin_unlock_irqrestore(&gpio_lock, flags); |
| 803 | status = gpiochip_sysfs_register(gdev->chip); | 805 | status = gpiochip_sysfs_register(gdev); |
| 804 | spin_lock_irqsave(&gpio_lock, flags); | 806 | spin_lock_irqsave(&gpio_lock, flags); |
| 805 | } | 807 | } |
| 806 | spin_unlock_irqrestore(&gpio_lock, flags); | 808 | spin_unlock_irqrestore(&gpio_lock, flags); |
| 807 | 809 | ||
| 808 | |||
| 809 | return status; | 810 | return status; |
| 810 | } | 811 | } |
| 811 | postcore_initcall(gpiolib_sysfs_init); | 812 | postcore_initcall(gpiolib_sysfs_init); |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 36f8be3f910b..5763290f777c 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
| @@ -558,7 +558,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) | |||
| 558 | if (status) | 558 | if (status) |
| 559 | goto err_remove_chardev; | 559 | goto err_remove_chardev; |
| 560 | 560 | ||
| 561 | status = gpiochip_sysfs_register(chip); | 561 | status = gpiochip_sysfs_register(gdev); |
| 562 | if (status) | 562 | if (status) |
| 563 | goto err_remove_device; | 563 | goto err_remove_device; |
| 564 | 564 | ||
| @@ -615,7 +615,7 @@ void gpiochip_remove(struct gpio_chip *chip) | |||
| 615 | gdev->chip = NULL; | 615 | gdev->chip = NULL; |
| 616 | 616 | ||
| 617 | /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ | 617 | /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ |
| 618 | gpiochip_sysfs_unregister(chip); | 618 | gpiochip_sysfs_unregister(gdev); |
| 619 | gpiochip_irqchip_remove(chip); | 619 | gpiochip_irqchip_remove(chip); |
| 620 | acpi_gpiochip_remove(chip); | 620 | acpi_gpiochip_remove(chip); |
| 621 | gpiochip_remove_pin_ranges(chip); | 621 | gpiochip_remove_pin_ranges(chip); |
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 1524ba0ca99d..c5a5b57463c7 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h | |||
| @@ -27,6 +27,8 @@ struct acpi_device; | |||
| 27 | * @id: numerical ID number for the GPIO chip | 27 | * @id: numerical ID number for the GPIO chip |
| 28 | * @dev: the GPIO device struct | 28 | * @dev: the GPIO device struct |
| 29 | * @chrdev: character device for the GPIO device | 29 | * @chrdev: character device for the GPIO device |
| 30 | * @mockdev: class device used by the deprecated sysfs interface (may be | ||
| 31 | * NULL) | ||
| 30 | * @owner: helps prevent removal of modules exporting active GPIOs | 32 | * @owner: helps prevent removal of modules exporting active GPIOs |
| 31 | * @chip: pointer to the corresponding gpiochip, holding static | 33 | * @chip: pointer to the corresponding gpiochip, holding static |
| 32 | * data for this device | 34 | * data for this device |
| @@ -41,6 +43,7 @@ struct gpio_device { | |||
| 41 | int id; | 43 | int id; |
| 42 | struct device dev; | 44 | struct device dev; |
| 43 | struct cdev chrdev; | 45 | struct cdev chrdev; |
| 46 | struct device *mockdev; | ||
| 44 | struct module *owner; | 47 | struct module *owner; |
| 45 | struct gpio_chip *chip; | 48 | struct gpio_chip *chip; |
| 46 | struct list_head list; | 49 | struct list_head list; |
| @@ -190,17 +193,17 @@ static int __maybe_unused gpio_chip_hwgpio(const struct gpio_desc *desc) | |||
| 190 | 193 | ||
| 191 | #ifdef CONFIG_GPIO_SYSFS | 194 | #ifdef CONFIG_GPIO_SYSFS |
| 192 | 195 | ||
| 193 | int gpiochip_sysfs_register(struct gpio_chip *chip); | 196 | int gpiochip_sysfs_register(struct gpio_device *gdev); |
| 194 | void gpiochip_sysfs_unregister(struct gpio_chip *chip); | 197 | void gpiochip_sysfs_unregister(struct gpio_device *gdev); |
| 195 | 198 | ||
| 196 | #else | 199 | #else |
| 197 | 200 | ||
| 198 | static inline int gpiochip_sysfs_register(struct gpio_chip *chip) | 201 | static inline int gpiochip_sysfs_register(struct gpio_device *gdev) |
| 199 | { | 202 | { |
| 200 | return 0; | 203 | return 0; |
| 201 | } | 204 | } |
| 202 | 205 | ||
| 203 | static inline void gpiochip_sysfs_unregister(struct gpio_chip *chip) | 206 | static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev) |
| 204 | { | 207 | { |
| 205 | } | 208 | } |
| 206 | 209 | ||
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index f3f1dbd43c9b..4db64ab534ef 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h | |||
| @@ -24,7 +24,6 @@ struct gpio_device; | |||
| 24 | * @label: for diagnostics | 24 | * @label: for diagnostics |
| 25 | * @gpiodev: the internal state holder, opaque struct | 25 | * @gpiodev: the internal state holder, opaque struct |
| 26 | * @parent: optional parent device providing the GPIOs | 26 | * @parent: optional parent device providing the GPIOs |
| 27 | * @cdev: class device used by sysfs interface (may be NULL) | ||
| 28 | * @owner: helps prevent removal of modules exporting active GPIOs | 27 | * @owner: helps prevent removal of modules exporting active GPIOs |
| 29 | * @data: per-instance data assigned by the driver | 28 | * @data: per-instance data assigned by the driver |
| 30 | * @request: optional hook for chip-specific activation, such as | 29 | * @request: optional hook for chip-specific activation, such as |
| @@ -110,7 +109,6 @@ struct gpio_chip { | |||
| 110 | const char *label; | 109 | const char *label; |
| 111 | struct gpio_device *gpiodev; | 110 | struct gpio_device *gpiodev; |
