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

gpio: move integer GPIO support to its own file

The old integer GPIO interface is, in effect, a privileged user of the
gpiod interface. Reflect this fact further by moving legacy GPIO support
into its own source file. This makes the code clearer and will allow us
to disable legacy GPIO support in the (far) future.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Alexandre Courbot and committed by
Linus Walleij
122c94de 0eb4c6c2

+112 -105
+1
drivers/gpio/Makefile
··· 4 4 5 5 obj-$(CONFIG_GPIO_DEVRES) += devres.o 6 6 obj-$(CONFIG_GPIOLIB) += gpiolib.o 7 + obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o 7 8 obj-$(CONFIG_OF_GPIO) += gpiolib-of.o 8 9 obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o 9 10 obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o
+111
drivers/gpio/gpiolib-legacy.c
··· 1 + #include <linux/gpio/consumer.h> 2 + #include <linux/gpio/driver.h> 3 + 4 + #include <linux/gpio.h> 5 + 6 + #include "gpiolib.h" 7 + 8 + void gpio_free(unsigned gpio) 9 + { 10 + gpiod_free(gpio_to_desc(gpio)); 11 + } 12 + EXPORT_SYMBOL_GPL(gpio_free); 13 + 14 + /** 15 + * gpio_request_one - request a single GPIO with initial configuration 16 + * @gpio: the GPIO number 17 + * @flags: GPIO configuration as specified by GPIOF_* 18 + * @label: a literal description string of this GPIO 19 + */ 20 + int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) 21 + { 22 + struct gpio_desc *desc; 23 + int err; 24 + 25 + desc = gpio_to_desc(gpio); 26 + 27 + err = gpiod_request(desc, label); 28 + if (err) 29 + return err; 30 + 31 + if (flags & GPIOF_OPEN_DRAIN) 32 + set_bit(FLAG_OPEN_DRAIN, &desc->flags); 33 + 34 + if (flags & GPIOF_OPEN_SOURCE) 35 + set_bit(FLAG_OPEN_SOURCE, &desc->flags); 36 + 37 + if (flags & GPIOF_DIR_IN) 38 + err = gpiod_direction_input(desc); 39 + else 40 + err = gpiod_direction_output_raw(desc, 41 + (flags & GPIOF_INIT_HIGH) ? 1 : 0); 42 + 43 + if (err) 44 + goto free_gpio; 45 + 46 + if (flags & GPIOF_EXPORT) { 47 + err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE); 48 + if (err) 49 + goto free_gpio; 50 + } 51 + 52 + return 0; 53 + 54 + free_gpio: 55 + gpiod_free(desc); 56 + return err; 57 + } 58 + EXPORT_SYMBOL_GPL(gpio_request_one); 59 + 60 + int gpio_request(unsigned gpio, const char *label) 61 + { 62 + return gpiod_request(gpio_to_desc(gpio), label); 63 + } 64 + EXPORT_SYMBOL_GPL(gpio_request); 65 + 66 + /** 67 + * gpio_request_array - request multiple GPIOs in a single call 68 + * @array: array of the 'struct gpio' 69 + * @num: how many GPIOs in the array 70 + */ 71 + int gpio_request_array(const struct gpio *array, size_t num) 72 + { 73 + int i, err; 74 + 75 + for (i = 0; i < num; i++, array++) { 76 + err = gpio_request_one(array->gpio, array->flags, array->label); 77 + if (err) 78 + goto err_free; 79 + } 80 + return 0; 81 + 82 + err_free: 83 + while (i--) 84 + gpio_free((--array)->gpio); 85 + return err; 86 + } 87 + EXPORT_SYMBOL_GPL(gpio_request_array); 88 + 89 + /** 90 + * gpio_free_array - release multiple GPIOs in a single call 91 + * @array: array of the 'struct gpio' 92 + * @num: how many GPIOs in the array 93 + */ 94 + void gpio_free_array(const struct gpio *array, size_t num) 95 + { 96 + while (num--) 97 + gpio_free((array++)->gpio); 98 + } 99 + EXPORT_SYMBOL_GPL(gpio_free_array); 100 + 101 + int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 102 + { 103 + return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset)); 104 + } 105 + EXPORT_SYMBOL_GPL(gpio_lock_as_irq); 106 + 107 + void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 108 + { 109 + return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset)); 110 + } 111 + EXPORT_SYMBOL_GPL(gpio_unlock_as_irq);
-105
drivers/gpio/gpiolib.c
··· 845 845 return status; 846 846 } 847 847 848 - int gpio_request(unsigned gpio, const char *label) 849 - { 850 - return gpiod_request(gpio_to_desc(gpio), label); 851 - } 852 - EXPORT_SYMBOL_GPL(gpio_request); 853 - 854 848 static bool __gpiod_free(struct gpio_desc *desc) 855 849 { 856 850 bool ret = false; ··· 884 890 else 885 891 WARN_ON(extra_checks); 886 892 } 887 - 888 - void gpio_free(unsigned gpio) 889 - { 890 - gpiod_free(gpio_to_desc(gpio)); 891 - } 892 - EXPORT_SYMBOL_GPL(gpio_free); 893 - 894 - /** 895 - * gpio_request_one - request a single GPIO with initial configuration 896 - * @gpio: the GPIO number 897 - * @flags: GPIO configuration as specified by GPIOF_* 898 - * @label: a literal description string of this GPIO 899 - */ 900 - int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) 901 - { 902 - struct gpio_desc *desc; 903 - int err; 904 - 905 - desc = gpio_to_desc(gpio); 906 - 907 - err = gpiod_request(desc, label); 908 - if (err) 909 - return err; 910 - 911 - if (flags & GPIOF_OPEN_DRAIN) 912 - set_bit(FLAG_OPEN_DRAIN, &desc->flags); 913 - 914 - if (flags & GPIOF_OPEN_SOURCE) 915 - set_bit(FLAG_OPEN_SOURCE, &desc->flags); 916 - 917 - if (flags & GPIOF_DIR_IN) 918 - err = gpiod_direction_input(desc); 919 - else 920 - err = gpiod_direction_output_raw(desc, 921 - (flags & GPIOF_INIT_HIGH) ? 1 : 0); 922 - 923 - if (err) 924 - goto free_gpio; 925 - 926 - if (flags & GPIOF_EXPORT) { 927 - err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE); 928 - if (err) 929 - goto free_gpio; 930 - } 931 - 932 - return 0; 933 - 934 - free_gpio: 935 - gpiod_free(desc); 936 - return err; 937 - } 938 - EXPORT_SYMBOL_GPL(gpio_request_one); 939 - 940 - /** 941 - * gpio_request_array - request multiple GPIOs in a single call 942 - * @array: array of the 'struct gpio' 943 - * @num: how many GPIOs in the array 944 - */ 945 - int gpio_request_array(const struct gpio *array, size_t num) 946 - { 947 - int i, err; 948 - 949 - for (i = 0; i < num; i++, array++) { 950 - err = gpio_request_one(array->gpio, array->flags, array->label); 951 - if (err) 952 - goto err_free; 953 - } 954 - return 0; 955 - 956 - err_free: 957 - while (i--) 958 - gpio_free((--array)->gpio); 959 - return err; 960 - } 961 - EXPORT_SYMBOL_GPL(gpio_request_array); 962 - 963 - /** 964 - * gpio_free_array - release multiple GPIOs in a single call 965 - * @array: array of the 'struct gpio' 966 - * @num: how many GPIOs in the array 967 - */ 968 - void gpio_free_array(const struct gpio *array, size_t num) 969 - { 970 - while (num--) 971 - gpio_free((array++)->gpio); 972 - } 973 - EXPORT_SYMBOL_GPL(gpio_free_array); 974 893 975 894 /** 976 895 * gpiochip_is_requested - return string iff signal was requested ··· 1452 1545 } 1453 1546 EXPORT_SYMBOL_GPL(gpiod_lock_as_irq); 1454 1547 1455 - int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 1456 - { 1457 - return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset)); 1458 - } 1459 - EXPORT_SYMBOL_GPL(gpio_lock_as_irq); 1460 - 1461 1548 /** 1462 1549 * gpiod_unlock_as_irq() - unlock a GPIO used as IRQ 1463 1550 * @gpio: the GPIO line to unlock from IRQ usage ··· 1467 1566 clear_bit(FLAG_USED_AS_IRQ, &desc->flags); 1468 1567 } 1469 1568 EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq); 1470 - 1471 - void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 1472 - { 1473 - return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset)); 1474 - } 1475 - EXPORT_SYMBOL_GPL(gpio_unlock_as_irq); 1476 1569 1477 1570 /** 1478 1571 * gpiod_get_raw_value_cansleep() - return a gpio's raw value