aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-07-01 01:45:16 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-07-09 06:22:57 -0400
commit122c94dec7f6909ff6999f6207b124e6db5d2ba8 (patch)
treea955f58f3aaf23e537d3ef1e931e68a0f8f423c6 /drivers/gpio
parent0eb4c6c2671ca05e447811041c838e2a6bc2a1f4 (diff)
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>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/gpiolib-legacy.c111
-rw-r--r--drivers/gpio/gpiolib.c105
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
5obj-$(CONFIG_GPIO_DEVRES) += devres.o 5obj-$(CONFIG_GPIO_DEVRES) += devres.o
6obj-$(CONFIG_GPIOLIB) += gpiolib.o 6obj-$(CONFIG_GPIOLIB) += gpiolib.o
7obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o
7obj-$(CONFIG_OF_GPIO) += gpiolib-of.o 8obj-$(CONFIG_OF_GPIO) += gpiolib-of.o
8obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o 9obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o
9obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o 10obj-$(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
8void gpio_free(unsigned gpio)
9{
10 gpiod_free(gpio_to_desc(gpio));
11}
12EXPORT_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 */
20int 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}
58EXPORT_SYMBOL_GPL(gpio_request_one);
59
60int gpio_request(unsigned gpio, const char *label)
61{
62 return gpiod_request(gpio_to_desc(gpio), label);
63}
64EXPORT_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 */
71int 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
82err_free:
83 while (i--)
84 gpio_free((--array)->gpio);
85 return err;
86}
87EXPORT_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 */
94void gpio_free_array(const struct gpio *array, size_t num)
95{
96 while (num--)
97 gpio_free((array++)->gpio);
98}
99EXPORT_SYMBOL_GPL(gpio_free_array);
100
101int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
102{
103 return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset));
104}
105EXPORT_SYMBOL_GPL(gpio_lock_as_irq);
106
107void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset)
108{
109 return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset));
110}
111EXPORT_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
848int gpio_request(unsigned gpio, const char *label)
849{
850 return gpiod_request(gpio_to_desc(gpio), label);
851}
852EXPORT_SYMBOL_GPL(gpio_request);
853
854static bool __gpiod_free(struct gpio_desc *desc) 848static 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
894void gpio_free(unsigned gpio)
895{
896 gpiod_free(gpio_to_desc(gpio));
897}
898EXPORT_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 */
906int 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}
944EXPORT_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 */
951int 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
962err_free:
963 while (i--)
964 gpio_free((--array)->gpio);
965 return err;
966}
967EXPORT_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 */
974void gpio_free_array(const struct gpio *array, size_t num)
975{
976 while (num--)
977 gpio_free((array++)->gpio);
978}
979EXPORT_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}
1546EXPORT_SYMBOL_GPL(gpiod_lock_as_irq); 1453EXPORT_SYMBOL_GPL(gpiod_lock_as_irq);
1547 1454
1548int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
1549{
1550 return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset));
1551}
1552EXPORT_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}
1568EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq); 1469EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq);
1569 1470
1570void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset)
1571{
1572 return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset));
1573}
1574EXPORT_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