diff options
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpiolib-legacy.c | 111 | ||||
-rw-r--r-- | drivers/gpio/gpiolib.c | 105 |
3 files changed, 112 insertions, 105 deletions
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 9d3df07290f3..09c5b5643bff 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG | |||
4 | 4 | ||
5 | obj-$(CONFIG_GPIO_DEVRES) += devres.o | 5 | obj-$(CONFIG_GPIO_DEVRES) += devres.o |
6 | obj-$(CONFIG_GPIOLIB) += gpiolib.o | 6 | obj-$(CONFIG_GPIOLIB) += gpiolib.o |
7 | obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o | ||
7 | obj-$(CONFIG_OF_GPIO) += gpiolib-of.o | 8 | obj-$(CONFIG_OF_GPIO) += gpiolib-of.o |
8 | obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o | 9 | obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o |
9 | obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o | 10 | obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o |
diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c new file mode 100644 index 000000000000..eb5a4e2cee85 --- /dev/null +++ b/drivers/gpio/gpiolib-legacy.c | |||
@@ -0,0 +1,111 @@ | |||
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); | ||
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7b35e5093ef5..c5509359ba88 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -845,12 +845,6 @@ done: | |||
845 | return status; | 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 | static bool __gpiod_free(struct gpio_desc *desc) | 848 | static bool __gpiod_free(struct gpio_desc *desc) |
855 | { | 849 | { |
856 | bool ret = false; | 850 | bool ret = false; |
@@ -891,93 +885,6 @@ void gpiod_free(struct gpio_desc *desc) | |||
891 | WARN_ON(extra_checks); | 885 | WARN_ON(extra_checks); |
892 | } | 886 | } |
893 | 887 | ||
894 | void gpio_free(unsigned gpio) | ||
895 | { | ||
896 | gpiod_free(gpio_to_desc(gpio)); | ||
897 | } | ||
898 | EXPORT_SYMBOL_GPL(gpio_free); | ||
899 | |||
900 | /** | ||
901 | * gpio_request_one - request a single GPIO with initial configuration | ||
902 | * @gpio: the GPIO number | ||
903 | * @flags: GPIO configuration as specified by GPIOF_* | ||
904 | * @label: a literal description string of this GPIO | ||
905 | */ | ||
906 | int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) | ||
907 | { | ||
908 | struct gpio_desc *desc; | ||
909 | int err; | ||
910 | |||
911 | desc = gpio_to_desc(gpio); | ||
912 | |||
913 | err = gpiod_request(desc, label); | ||
914 | if (err) | ||
915 | return err; | ||
916 | |||
917 | if (flags & GPIOF_OPEN_DRAIN) | ||
918 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | ||
919 | |||
920 | if (flags & GPIOF_OPEN_SOURCE) | ||
921 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | ||
922 | |||
923 | if (flags & GPIOF_DIR_IN) | ||
924 | err = gpiod_direction_input(desc); | ||
925 | else | ||
926 | err = gpiod_direction_output_raw(desc, | ||
927 | (flags & GPIOF_INIT_HIGH) ? 1 : 0); | ||
928 | |||
929 | if (err) | ||
930 | goto free_gpio; | ||
931 | |||
932 | if (flags & GPIOF_EXPORT) { | ||
933 | err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE); | ||
934 | if (err) | ||
935 | goto free_gpio; | ||
936 | } | ||
937 | |||
938 | return 0; | ||
939 | |||
940 | free_gpio: | ||
941 | gpiod_free(desc); | ||
942 | return err; | ||
943 | } | ||
944 | EXPORT_SYMBOL_GPL(gpio_request_one); | ||
945 | |||
946 | /** | ||
947 | * gpio_request_array - request multiple GPIOs in a single call | ||
948 | * @array: array of the 'struct gpio' | ||
949 | * @num: how many GPIOs in the array | ||
950 | */ | ||
951 | int gpio_request_array(const struct gpio *array, size_t num) | ||
952 | { | ||
953 | int i, err; | ||
954 | |||
955 | for (i = 0; i < num; i++, array++) { | ||
956 | err = gpio_request_one(array->gpio, array->flags, array->label); | ||
957 | if (err) | ||
958 | goto err_free; | ||
959 | } | ||
960 | return 0; | ||
961 | |||
962 | err_free: | ||
963 | while (i--) | ||
964 | gpio_free((--array)->gpio); | ||
965 | return err; | ||
966 | } | ||
967 | EXPORT_SYMBOL_GPL(gpio_request_array); | ||
968 | |||
969 | /** | ||
970 | * gpio_free_array - release multiple GPIOs in a single call | ||
971 | * @array: array of the 'struct gpio' | ||
972 | * @num: how many GPIOs in the array | ||
973 | */ | ||
974 | void gpio_free_array(const struct gpio *array, size_t num) | ||
975 | { | ||
976 | while (num--) | ||
977 | gpio_free((array++)->gpio); | ||
978 | } | ||
979 | EXPORT_SYMBOL_GPL(gpio_free_array); | ||
980 | |||
981 | /** | 888 | /** |
982 | * gpiochip_is_requested - return string iff signal was requested | 889 | * gpiochip_is_requested - return string iff signal was requested |
983 | * @chip: controller managing the signal | 890 | * @chip: controller managing the signal |
@@ -1545,12 +1452,6 @@ int gpiod_lock_as_irq(struct gpio_desc *desc) | |||
1545 | } | 1452 | } |
1546 | EXPORT_SYMBOL_GPL(gpiod_lock_as_irq); | 1453 | EXPORT_SYMBOL_GPL(gpiod_lock_as_irq); |
1547 | 1454 | ||
1548 | int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) | ||
1549 | { | ||
1550 | return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset)); | ||
1551 | } | ||
1552 | EXPORT_SYMBOL_GPL(gpio_lock_as_irq); | ||
1553 | |||
1554 | /** | 1455 | /** |
1555 | * gpiod_unlock_as_irq() - unlock a GPIO used as IRQ | 1456 | * gpiod_unlock_as_irq() - unlock a GPIO used as IRQ |
1556 | * @gpio: the GPIO line to unlock from IRQ usage | 1457 | * @gpio: the GPIO line to unlock from IRQ usage |
@@ -1567,12 +1468,6 @@ void gpiod_unlock_as_irq(struct gpio_desc *desc) | |||
1567 | } | 1468 | } |
1568 | EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq); | 1469 | EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq); |
1569 | 1470 | ||
1570 | void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) | ||
1571 | { | ||
1572 | return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset)); | ||
1573 | } | ||
1574 | EXPORT_SYMBOL_GPL(gpio_unlock_as_irq); | ||
1575 | |||
1576 | /** | 1471 | /** |
1577 | * gpiod_get_raw_value_cansleep() - return a gpio's raw value | 1472 | * gpiod_get_raw_value_cansleep() - return a gpio's raw value |
1578 | * @desc: gpio whose value will be returned | 1473 | * @desc: gpio whose value will be returned |