Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpiolib: remove legacy gpio_export()

There are only a handful of users of gpio_export() and
related functions.

As these are just wrappers around the modern gpiod_export()
helper, remove the wrappers and open-code the gpio_to_desc
in all callers to shrink the legacy API.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

authored by

Arnd Bergmann and committed by
Andy Shevchenko
d74e3166 0e685c3e

+21 -99
+1 -1
Documentation/admin-guide/gpio/sysfs.rst
··· 145 145 /* export the GPIO to userspace */ 146 146 int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 147 147 148 - /* reverse gpio_export() */ 148 + /* reverse gpiod_export() */ 149 149 void gpiod_unexport(struct gpio_desc *desc); 150 150 151 151 /* create a sysfs link to an exported GPIO node */
-21
Documentation/driver-api/gpio/legacy.rst
··· 714 714 the correct GPIO number to use for a given signal. 715 715 716 716 717 - Exporting from Kernel code 718 - -------------------------- 719 - Kernel code can explicitly manage exports of GPIOs which have already been 720 - requested using gpio_request():: 721 - 722 - /* export the GPIO to userspace */ 723 - int gpio_export(unsigned gpio, bool direction_may_change); 724 - 725 - /* reverse gpio_export() */ 726 - void gpio_unexport(); 727 - 728 - After a kernel driver requests a GPIO, it may only be made available in 729 - the sysfs interface by gpio_export(). The driver can control whether the 730 - signal direction may change. This helps drivers prevent userspace code 731 - from accidentally clobbering important system state. 732 - 733 - This explicit exporting can help with debugging (by making some kinds 734 - of experiments easier), or can provide an always-there interface that's 735 - suitable for documenting as part of a board support package. 736 - 737 - 738 717 API Reference 739 718 ============= 740 719
-19
Documentation/translations/zh_CN/driver-api/gpio/legacy.rst
··· 653 653 确定给定信号所用的 GPIO 编号。 654 654 655 655 656 - 从内核代码中导出 657 - ---------------- 658 - 659 - 内核代码可以明确地管理那些已通过 gpio_request()申请的 GPIO 的导出:: 660 - 661 - /* 导出 GPIO 到用户空间 */ 662 - int gpio_export(unsigned gpio, bool direction_may_change); 663 - 664 - /* gpio_export()的逆操作 */ 665 - void gpio_unexport(); 666 - 667 - 在一个内核驱动申请一个 GPIO 之后,它可以通过 gpio_export()使其在 sysfs 668 - 接口中可见。该驱动可以控制信号方向是否可修改。这有助于防止用户空间代码无意间 669 - 破坏重要的系统状态。 670 - 671 - 这个明确的导出有助于(通过使某些实验更容易来)调试,也可以提供一个始终存在的接口, 672 - 与文档配合作为板级支持包的一部分。 673 - 674 - 675 656 API参考 676 657 ======= 677 658
-18
Documentation/translations/zh_TW/gpio.txt
··· 614 614 固定的,例如在擴展卡上的 GPIO會根據所使用的主板或所在堆疊架構中其他的板子而 615 615 有所不同。在這種情況下,你可能需要使用 gpiochip 節點(儘可能地結合電路圖)來 616 616 確定給定信號所用的 GPIO 編號。 617 - 618 - 619 - 從內核代碼中導出 620 - ------------- 621 - 內核代碼可以明確地管理那些已通過 gpio_request()申請的 GPIO 的導出: 622 - 623 - /* 導出 GPIO 到用戶空間 */ 624 - int gpio_export(unsigned gpio, bool direction_may_change); 625 - 626 - /* gpio_export()的逆操作 */ 627 - void gpio_unexport(); 628 - 629 - 在一個內核驅動申請一個 GPIO 之後,它可以通過 gpio_export()使其在 sysfs 630 - 接口中可見。該驅動可以控制信號方向是否可修改。這有助於防止用戶空間代碼無意間 631 - 破壞重要的系統狀態。 632 - 633 - 這個明確的導出有助於(通過使某些實驗更容易來)調試,也可以提供一個始終存在的接口, 634 - 與文檔配合作爲板級支持包的一部分。
+5 -4
arch/arm/mach-omap2/pdata-quirks.c
··· 6 6 */ 7 7 #include <linux/clk.h> 8 8 #include <linux/davinci_emac.h> 9 + #include <linux/gpio/consumer.h> 9 10 #include <linux/gpio.h> 10 11 #include <linux/init.h> 11 12 #include <linux/kernel.h> ··· 109 108 if (res) 110 109 return res; 111 110 112 - gpio_export(gpio, 0); 111 + gpiod_export(gpio_to_desc(gpio), 0); 113 112 114 113 return 0; 115 114 } ··· 124 123 return; 125 124 } 126 125 127 - gpio_export(gpio, 0); 126 + gpiod_export(gpio_to_desc(gpio), 0); 128 127 129 128 udelay(10); 130 129 gpio_set_value(gpio, 1); ··· 201 200 return; 202 201 } 203 202 204 - gpio_export(cm_t3517_wlan_gpios[0].gpio, 0); 205 - gpio_export(cm_t3517_wlan_gpios[1].gpio, 0); 203 + gpiod_export(gpio_to_desc(cm_t3517_wlan_gpios[0].gpio), 0); 204 + gpiod_export(gpio_to_desc(cm_t3517_wlan_gpios[1].gpio), 0); 206 205 207 206 msleep(100); 208 207 gpio_set_value(cm_t3517_wlan_gpios[1].gpio, 0);
+4 -3
arch/sh/boards/mach-ap325rxa/setup.c
··· 18 18 #include <linux/delay.h> 19 19 #include <linux/device.h> 20 20 #include <linux/gpio.h> 21 + #include <linux/gpio/consumer.h> 21 22 #include <linux/gpio/machine.h> 22 23 #include <linux/i2c.h> 23 24 #include <linux/init.h> ··· 412 411 /* LD3 and LD4 LEDs */ 413 412 gpio_request(GPIO_PTX5, NULL); /* RUN */ 414 413 gpio_direction_output(GPIO_PTX5, 1); 415 - gpio_export(GPIO_PTX5, 0); 414 + gpiod_export(gpio_to_desc(GPIO_PTX5), 0); 416 415 417 416 gpio_request(GPIO_PTX4, NULL); /* INDICATOR */ 418 417 gpio_direction_output(GPIO_PTX4, 0); 419 - gpio_export(GPIO_PTX4, 0); 418 + gpiod_export(gpio_to_desc(GPIO_PTX4), 0); 420 419 421 420 /* SW1 input */ 422 421 gpio_request(GPIO_PTF7, NULL); /* MODE */ 423 422 gpio_direction_input(GPIO_PTF7); 424 - gpio_export(GPIO_PTF7, 0); 423 + gpiod_export(gpio_to_desc(GPIO_PTF7), 0); 425 424 426 425 /* LCDC */ 427 426 gpio_request(GPIO_FN_LCDD15, NULL);
+2 -2
drivers/gpio/gpiolib-sysfs.c
··· 491 491 goto done; 492 492 493 493 desc = gpio_to_desc(gpio); 494 - /* reject bogus commands (gpio_unexport ignores them) */ 494 + /* reject bogus commands (gpiod_unexport() ignores them) */ 495 495 if (!desc) { 496 496 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); 497 497 return -EINVAL; ··· 790 790 * early (e.g. before the class_register above was called). 791 791 * 792 792 * We run before arch_initcall() so chip->dev nodes can have 793 - * registered, and so arch_initcall() can always gpio_export(). 793 + * registered, and so arch_initcall() can always gpiod_export(). 794 794 */ 795 795 spin_lock_irqsave(&gpio_lock, flags); 796 796 list_for_each_entry(gdev, &gpio_devices, list) {
+7 -3
drivers/media/pci/sta2x11/sta2x11_vip.c
··· 18 18 #include <linux/pci.h> 19 19 #include <linux/interrupt.h> 20 20 #include <linux/io.h> 21 + #include <linux/gpio/consumer.h> 21 22 #include <linux/gpio.h> 22 23 #include <linux/i2c.h> 23 24 #include <linux/delay.h> ··· 890 889 static int vip_gpio_reserve(struct device *dev, int pin, int dir, 891 890 const char *name) 892 891 { 892 + struct gpio_desc *desc = gpio_to_desc(pin); 893 893 int ret = -ENODEV; 894 894 895 895 if (!gpio_is_valid(pin)) ··· 902 900 return ret; 903 901 } 904 902 905 - ret = gpio_direction_output(pin, dir); 903 + ret = gpiod_direction_output(desc, dir); 906 904 if (ret) { 907 905 dev_err(dev, "Failed to set direction for pin %d (%s)\n", 908 906 pin, name); ··· 910 908 return ret; 911 909 } 912 910 913 - ret = gpio_export(pin, false); 911 + ret = gpiod_export(desc, false); 914 912 if (ret) { 915 913 dev_err(dev, "Failed to export pin %d (%s)\n", pin, name); 916 914 gpio_free(pin); ··· 930 928 static void vip_gpio_release(struct device *dev, int pin, const char *name) 931 929 { 932 930 if (gpio_is_valid(pin)) { 931 + struct gpio_desc *desc = gpio_to_desc(pin); 932 + 933 933 dev_dbg(dev, "releasing pin %d (%s)\n", pin, name); 934 - gpio_unexport(pin); 934 + gpiod_unexport(desc); 935 935 gpio_free(pin); 936 936 } 937 937 }
+2 -1
drivers/net/ieee802154/ca8210.c
··· 51 51 #include <linux/clk-provider.h> 52 52 #include <linux/debugfs.h> 53 53 #include <linux/delay.h> 54 + #include <linux/gpio/consumer.h> 54 55 #include <linux/gpio.h> 55 56 #include <linux/ieee802154.h> 56 57 #include <linux/io.h> ··· 2854 2853 ); 2855 2854 if (ret) { 2856 2855 dev_crit(&spi->dev, "request_irq %d failed\n", pdata->irq_id); 2857 - gpio_unexport(pdata->gpio_irq); 2856 + gpiod_unexport(gpio_to_desc(pdata->gpio_irq)); 2858 2857 gpio_free(pdata->gpio_irq); 2859 2858 } 2860 2859
-27
include/linux/gpio.h
··· 132 132 int gpio_request_array(const struct gpio *array, size_t num); 133 133 void gpio_free_array(const struct gpio *array, size_t num); 134 134 135 - /* 136 - * A sysfs interface can be exported by individual drivers if they want, 137 - * but more typically is configured entirely from userspace. 138 - */ 139 - static inline int gpio_export(unsigned gpio, bool direction_may_change) 140 - { 141 - return gpiod_export(gpio_to_desc(gpio), direction_may_change); 142 - } 143 - 144 - static inline void gpio_unexport(unsigned gpio) 145 - { 146 - gpiod_unexport(gpio_to_desc(gpio)); 147 - } 148 - 149 135 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */ 150 136 151 137 struct device; ··· 225 239 static inline void gpio_set_value_cansleep(unsigned gpio, int value) 226 240 { 227 241 /* GPIO can never have been requested or set as output */ 228 - WARN_ON(1); 229 - } 230 - 231 - static inline int gpio_export(unsigned gpio, bool direction_may_change) 232 - { 233 - /* GPIO can never have been requested or set as {in,out}put */ 234 - WARN_ON(1); 235 - return -EINVAL; 236 - } 237 - 238 - static inline void gpio_unexport(unsigned gpio) 239 - { 240 - /* GPIO can never have been exported */ 241 242 WARN_ON(1); 242 243 } 243 244