diff options
author | Johan Hovold <johan@kernel.org> | 2015-05-04 11:10:33 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-05-12 04:46:53 -0400 |
commit | 166a85e44245d771bd7042f3ad72aa0e12bb53bd (patch) | |
tree | a9fd0409715c50ff15d2314b2314b4358c754ffb | |
parent | 426577bd8846d67b735b3a4e8926ef00abb15297 (diff) |
gpio: remove gpiod_sysfs_set_active_low
Remove gpiod_sysfs_set_active_low (and gpio_sysfs_set_active_low) which
allowed code to change the polarity of a gpio line even after it had
been exported through sysfs.
Drivers should not care, and generally does not know, about gpio-line
polarity which is a hardware feature that needs to be described by
firmware.
It is currently possible to define gpio-line polarity in device-tree and
acpi firmware or using platform data. Userspace can also change the
polarity through sysfs.
Note that drivers using the legacy gpio interface could still use
GPIOF_ACTIVE_LOW to change the polarity before exporting the gpio.
There are no in-kernel users of this interface.
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Harry Wei <harryxiyou@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@zh-kernel.org
Cc: linux-arch@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | Documentation/gpio/gpio-legacy.txt | 9 | ||||
-rw-r--r-- | Documentation/gpio/sysfs.txt | 8 | ||||
-rw-r--r-- | Documentation/zh_CN/gpio.txt | 8 | ||||
-rw-r--r-- | drivers/gpio/gpiolib-sysfs.c | 48 | ||||
-rw-r--r-- | include/asm-generic/gpio.h | 5 | ||||
-rw-r--r-- | include/linux/gpio.h | 7 | ||||
-rw-r--r-- | include/linux/gpio/consumer.h | 6 |
7 files changed, 2 insertions, 89 deletions
diff --git a/Documentation/gpio/gpio-legacy.txt b/Documentation/gpio/gpio-legacy.txt index 6f83fa965b4b..79ab5648d69b 100644 --- a/Documentation/gpio/gpio-legacy.txt +++ b/Documentation/gpio/gpio-legacy.txt | |||
@@ -751,9 +751,6 @@ requested using gpio_request(): | |||
751 | int gpio_export_link(struct device *dev, const char *name, | 751 | int gpio_export_link(struct device *dev, const char *name, |
752 | unsigned gpio) | 752 | unsigned gpio) |
753 | 753 | ||
754 | /* change the polarity of a GPIO node in sysfs */ | ||
755 | int gpio_sysfs_set_active_low(unsigned gpio, int value); | ||
756 | |||
757 | After a kernel driver requests a GPIO, it may only be made available in | 754 | After a kernel driver requests a GPIO, it may only be made available in |
758 | the sysfs interface by gpio_export(). The driver can control whether the | 755 | the sysfs interface by gpio_export(). The driver can control whether the |
759 | signal direction may change. This helps drivers prevent userspace code | 756 | signal direction may change. This helps drivers prevent userspace code |
@@ -767,9 +764,3 @@ After the GPIO has been exported, gpio_export_link() allows creating | |||
767 | symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can | 764 | symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can |
768 | use this to provide the interface under their own device in sysfs with | 765 | use this to provide the interface under their own device in sysfs with |
769 | a descriptive name. | 766 | a descriptive name. |
770 | |||
771 | Drivers can use gpio_sysfs_set_active_low() to hide GPIO line polarity | ||
772 | differences between boards from user space. This only affects the | ||
773 | sysfs interface. Polarity change can be done both before and after | ||
774 | gpio_export(), and previously enabled poll(2) support for either | ||
775 | rising or falling edge will be reconfigured to follow this setting. | ||
diff --git a/Documentation/gpio/sysfs.txt b/Documentation/gpio/sysfs.txt index c2c3a97f8ff7..535b6a8a7a7c 100644 --- a/Documentation/gpio/sysfs.txt +++ b/Documentation/gpio/sysfs.txt | |||
@@ -132,9 +132,6 @@ requested using gpio_request(): | |||
132 | int gpiod_export_link(struct device *dev, const char *name, | 132 | int gpiod_export_link(struct device *dev, const char *name, |
133 | struct gpio_desc *desc); | 133 | struct gpio_desc *desc); |
134 | 134 | ||
135 | /* change the polarity of a GPIO node in sysfs */ | ||
136 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); | ||
137 | |||
138 | After a kernel driver requests a GPIO, it may only be made available in | 135 | After a kernel driver requests a GPIO, it may only be made available in |
139 | the sysfs interface by gpiod_export(). The driver can control whether the | 136 | the sysfs interface by gpiod_export(). The driver can control whether the |
140 | signal direction may change. This helps drivers prevent userspace code | 137 | signal direction may change. This helps drivers prevent userspace code |
@@ -148,8 +145,3 @@ After the GPIO has been exported, gpiod_export_link() allows creating | |||
148 | symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can | 145 | symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can |
149 | use this to provide the interface under their own device in sysfs with | 146 | use this to provide the interface under their own device in sysfs with |
150 | a descriptive name. | 147 | a descriptive name. |
151 | |||
152 | Drivers can use gpiod_sysfs_set_active_low() to hide GPIO line polarity | ||
153 | differences between boards from user space. Polarity change can be done both | ||
154 | before and after gpiod_export(), and previously enabled poll(2) support for | ||
155 | either rising or falling edge will be reconfigured to follow this setting. | ||
diff --git a/Documentation/zh_CN/gpio.txt b/Documentation/zh_CN/gpio.txt index d5b8f01833f4..bce972521065 100644 --- a/Documentation/zh_CN/gpio.txt +++ b/Documentation/zh_CN/gpio.txt | |||
@@ -638,9 +638,6 @@ GPIO 控制器的路径类似 /sys/class/gpio/gpiochip42/ (对于从#42 GPIO | |||
638 | int gpio_export_link(struct device *dev, const char *name, | 638 | int gpio_export_link(struct device *dev, const char *name, |
639 | unsigned gpio) | 639 | unsigned gpio) |
640 | 640 | ||
641 | /* 改变 sysfs 中的一个 GPIO 节点的极性 */ | ||
642 | int gpio_sysfs_set_active_low(unsigned gpio, int value); | ||
643 | |||
644 | 在一个内核驱动申请一个 GPIO 之后,它可以通过 gpio_export()使其在 sysfs | 641 | 在一个内核驱动申请一个 GPIO 之后,它可以通过 gpio_export()使其在 sysfs |
645 | 接口中可见。该驱动可以控制信号方向是否可修改。这有助于防止用户空间代码无意间 | 642 | 接口中可见。该驱动可以控制信号方向是否可修改。这有助于防止用户空间代码无意间 |
646 | 破坏重要的系统状态。 | 643 | 破坏重要的系统状态。 |
@@ -651,8 +648,3 @@ GPIO 控制器的路径类似 /sys/class/gpio/gpiochip42/ (对于从#42 GPIO | |||
651 | 在 GPIO 被导出之后,gpio_export_link()允许在 sysfs 文件系统的任何地方 | 648 | 在 GPIO 被导出之后,gpio_export_link()允许在 sysfs 文件系统的任何地方 |
652 | 创建一个到这个 GPIO sysfs 节点的符号链接。这样驱动就可以通过一个描述性的 | 649 | 创建一个到这个 GPIO sysfs 节点的符号链接。这样驱动就可以通过一个描述性的 |
653 | 名字,在 sysfs 中他们所拥有的设备下提供一个(到这个 GPIO sysfs 节点的)接口。 | 650 | 名字,在 sysfs 中他们所拥有的设备下提供一个(到这个 GPIO sysfs 节点的)接口。 |
654 | |||
655 | 驱动可以使用 gpio_sysfs_set_active_low() 来在用户空间隐藏电路板之间 | ||
656 | GPIO 线的极性差异。这个仅对 sysfs 接口起作用。极性的改变可以在 gpio_export() | ||
657 | 前后进行,且之前使能的轮询操作(poll(2))支持(上升或下降沿)将会被重新配置来遵循 | ||
658 | 这个设置。 | ||
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index aeb73ef2955e..9dcd346a20fb 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c | |||
@@ -308,8 +308,8 @@ static int sysfs_set_active_low(struct gpio_desc *desc, struct device *dev, | |||
308 | clear_bit(FLAG_ACTIVE_LOW, &desc->flags); | 308 | clear_bit(FLAG_ACTIVE_LOW, &desc->flags); |
309 | 309 | ||
310 | /* reconfigure poll(2) support if enabled on one edge only */ | 310 | /* reconfigure poll(2) support if enabled on one edge only */ |
311 | if (dev != NULL && (!!test_bit(FLAG_TRIG_RISE, &desc->flags) ^ | 311 | if (!!test_bit(FLAG_TRIG_RISE, &desc->flags) ^ |
312 | !!test_bit(FLAG_TRIG_FALL, &desc->flags))) { | 312 | !!test_bit(FLAG_TRIG_FALL, &desc->flags)) { |
313 | unsigned long trigger_flags = desc->flags & GPIO_TRIGGER_MASK; | 313 | unsigned long trigger_flags = desc->flags & GPIO_TRIGGER_MASK; |
314 | 314 | ||
315 | gpio_setup_irq(desc, dev, 0); | 315 | gpio_setup_irq(desc, dev, 0); |
@@ -681,50 +681,6 @@ int gpiod_export_link(struct device *dev, const char *name, | |||
681 | EXPORT_SYMBOL_GPL(gpiod_export_link); | 681 | EXPORT_SYMBOL_GPL(gpiod_export_link); |
682 | 682 | ||
683 | /** | 683 | /** |
684 | * gpiod_sysfs_set_active_low - set the polarity of gpio sysfs value | ||
685 | * @gpio: gpio to change | ||
686 | * @value: non-zero to use active low, i.e. inverted values | ||
687 | * | ||
688 | * Set the polarity of /sys/class/gpio/gpioN/value sysfs attribute. | ||
689 | * The GPIO does not have to be exported yet. If poll(2) support has | ||
690 | * been enabled for either rising or falling edge, it will be | ||
691 | * reconfigured to follow the new polarity. | ||
692 | * | ||
693 | * Returns zero on success, else an error. | ||
694 | */ | ||
695 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) | ||
696 | { | ||
697 | struct device *dev = NULL; | ||
698 | int status = -EINVAL; | ||
699 | |||
700 | if (!desc) { | ||
701 | pr_warn("%s: invalid GPIO\n", __func__); | ||
702 | return -EINVAL; | ||
703 | } | ||
704 | |||
705 | mutex_lock(&sysfs_lock); | ||
706 | |||
707 | if (test_bit(FLAG_EXPORT, &desc->flags)) { | ||
708 | dev = class_find_device(&gpio_class, NULL, desc, match_export); | ||
709 | if (dev == NULL) { | ||
710 | status = -ENODEV; | ||
711 | goto unlock; | ||
712 | } | ||
713 | } | ||
714 | |||
715 | status = sysfs_set_active_low(desc, dev, value); | ||
716 | put_device(dev); | ||
717 | unlock: | ||
718 | mutex_unlock(&sysfs_lock); | ||
719 | |||
720 | if (status) | ||
721 | gpiod_dbg(desc, "%s: status %d\n", __func__, status); | ||
722 | |||
723 | return status; | ||
724 | } | ||
725 | EXPORT_SYMBOL_GPL(gpiod_sysfs_set_active_low); | ||
726 | |||
727 | /** | ||
728 | * gpiod_unexport - reverse effect of gpio_export() | 684 | * gpiod_unexport - reverse effect of gpio_export() |
729 | * @gpio: gpio to make unavailable | 685 | * @gpio: gpio to make unavailable |
730 | * | 686 | * |
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 9bb0d11729c9..40ec1433f05d 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h | |||
@@ -128,11 +128,6 @@ static inline int gpio_export_link(struct device *dev, const char *name, | |||
128 | return gpiod_export_link(dev, name, gpio_to_desc(gpio)); | 128 | return gpiod_export_link(dev, name, gpio_to_desc(gpio)); |
129 | } | 129 | } |
130 | 130 | ||
131 | static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) | ||
132 | { | ||
133 | return gpiod_sysfs_set_active_low(gpio_to_desc(gpio), value); | ||
134 | } | ||
135 | |||
136 | static inline void gpio_unexport(unsigned gpio) | 131 | static inline void gpio_unexport(unsigned gpio) |
137 | { | 132 | { |
138 | gpiod_unexport(gpio_to_desc(gpio)); | 133 | gpiod_unexport(gpio_to_desc(gpio)); |
diff --git a/include/linux/gpio.h b/include/linux/gpio.h index ab81339a8590..d12b5d566e4b 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h | |||
@@ -196,13 +196,6 @@ static inline int gpio_export_link(struct device *dev, const char *name, | |||
196 | return -EINVAL; | 196 | return -EINVAL; |
197 | } | 197 | } |
198 | 198 | ||
199 | static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) | ||
200 | { | ||
201 | /* GPIO can never have been requested */ | ||
202 | WARN_ON(1); | ||
203 | return -EINVAL; | ||
204 | } | ||
205 | |||
206 | static inline void gpio_unexport(unsigned gpio) | 199 | static inline void gpio_unexport(unsigned gpio) |
207 | { | 200 | { |
208 | /* GPIO can never have been exported */ | 201 | /* GPIO can never have been exported */ |
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 3a7c9ffd5ab9..09a7fb0062a6 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
@@ -449,7 +449,6 @@ static inline int desc_to_gpio(const struct gpio_desc *desc) | |||
449 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); | 449 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); |
450 | int gpiod_export_link(struct device *dev, const char *name, | 450 | int gpiod_export_link(struct device *dev, const char *name, |
451 | struct gpio_desc *desc); | 451 | struct gpio_desc *desc); |
452 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); | ||
453 | void gpiod_unexport(struct gpio_desc *desc); | 452 | void gpiod_unexport(struct gpio_desc *desc); |
454 | 453 | ||
455 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ | 454 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ |
@@ -466,11 +465,6 @@ static inline int gpiod_export_link(struct device *dev, const char *name, | |||
466 | return -ENOSYS; | 465 | return -ENOSYS; |
467 | } | 466 | } |
468 | 467 | ||
469 | static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) | ||
470 | { | ||
471 | return -ENOSYS; | ||
472 | } | ||
473 | |||
474 | static inline void gpiod_unexport(struct gpio_desc *desc) | 468 | static inline void gpiod_unexport(struct gpio_desc *desc) |
475 | { | 469 | { |
476 | } | 470 | } |