aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-07-24 01:51:02 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-07-24 12:18:47 -0400
commitc7caf86823c71fae652cc50c7d8dd0d2b5c41229 (patch)
tree3cb7cf155bf315ffd9b85c641615eb84dfb08150
parent7fd834ad77f79fe0e8e9840238f18bdc088c97b6 (diff)
gpio: remove gpio_ensure_requested()
gpio_ensure_requested() has been introduced in Feb. 2008 by commit d2876d08d86f2 to force users of the GPIO API to explicitly request GPIOs before using them. Hopefully by now all GPIOs are correctly requested and this extra check can be omitted ; in any case the GPIO maintainers won't feel bad if machines start failing after 6 years of warnings. This patch removes that function from the dark ages. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpiolib-legacy.c106
-rw-r--r--include/asm-generic/gpio.h15
2 files changed, 12 insertions, 109 deletions
diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c
index 0f9429b2522a..078ae6c2df79 100644
--- a/drivers/gpio/gpiolib-legacy.c
+++ b/drivers/gpio/gpiolib-legacy.c
@@ -5,64 +5,6 @@
5 5
6#include "gpiolib.h" 6#include "gpiolib.h"
7 7
8/* Warn when drivers omit gpio_request() calls -- legal but ill-advised
9 * when setting direction, and otherwise illegal. Until board setup code
10 * and drivers use explicit requests everywhere (which won't happen when
11 * those calls have no teeth) we can't avoid autorequesting. This nag
12 * message should motivate switching to explicit requests... so should
13 * the weaker cleanup after faults, compared to gpio_request().
14 *
15 * NOTE: the autorequest mechanism is going away; at this point it's
16 * only "legal" in the sense that (old) code using it won't break yet,
17 * but instead only triggers a WARN() stack dump.
18 */
19static int gpio_ensure_requested(struct gpio_desc *desc)
20{
21 struct gpio_chip *chip = desc->chip;
22 unsigned long flags;
23 bool request = false;
24 int err = 0;
25
26 spin_lock_irqsave(&gpio_lock, flags);
27
28 if (WARN(test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0,
29 "autorequest GPIO-%d\n", desc_to_gpio(desc))) {
30 if (!try_module_get(chip->owner)) {
31 gpiod_err(desc, "%s: module can't be gotten\n",
32 __func__);
33 clear_bit(FLAG_REQUESTED, &desc->flags);
34 /* lose */
35 err = -EIO;
36 goto end;
37 }
38 desc->label = "[auto]";
39 /* caller must chip->request() w/o spinlock */
40 if (chip->request)
41 request = true;
42 }
43
44end:
45 spin_unlock_irqrestore(&gpio_lock, flags);
46
47 if (request) {
48 might_sleep_if(chip->can_sleep);
49 err = chip->request(chip, gpio_chip_hwgpio(desc));
50
51 if (err < 0) {
52 gpiod_dbg(desc, "%s: chip request fail, %d\n",
53 __func__, err);
54 spin_lock_irqsave(&gpio_lock, flags);
55
56 desc->label = NULL;
57 clear_bit(FLAG_REQUESTED, &desc->flags);
58
59 spin_unlock_irqrestore(&gpio_lock, flags);
60 }
61 }
62
63 return err;
64}
65
66void gpio_free(unsigned gpio) 8void gpio_free(unsigned gpio)
67{ 9{
68 gpiod_free(gpio_to_desc(gpio)); 10 gpiod_free(gpio_to_desc(gpio));
@@ -158,51 +100,3 @@ void gpio_free_array(const struct gpio *array, size_t num)
158 gpio_free((array++)->gpio); 100 gpio_free((array++)->gpio);
159} 101}
160EXPORT_SYMBOL_GPL(gpio_free_array); 102EXPORT_SYMBOL_GPL(gpio_free_array);
161
162int gpio_direction_input(unsigned gpio)
163{
164 struct gpio_desc *desc = gpio_to_desc(gpio);
165 int err;
166
167 if (!desc)
168 return -EINVAL;
169
170 err = gpio_ensure_requested(desc);
171 if (err < 0)
172 return err;
173
174 return gpiod_direction_input(desc);
175}
176EXPORT_SYMBOL_GPL(gpio_direction_input);
177
178int gpio_direction_output(unsigned gpio, int value)
179{
180 struct gpio_desc *desc = gpio_to_desc(gpio);
181 int err;
182
183 if (!desc)
184 return -EINVAL;
185
186 err = gpio_ensure_requested(desc);
187 if (err < 0)
188 return err;
189
190 return gpiod_direction_output_raw(desc, value);
191}
192EXPORT_SYMBOL_GPL(gpio_direction_output);
193
194int gpio_set_debounce(unsigned gpio, unsigned debounce)
195{
196 struct gpio_desc *desc = gpio_to_desc(gpio);
197 int err;
198
199 if (!desc)
200 return -EINVAL;
201
202 err = gpio_ensure_requested(desc);
203 if (err < 0)
204 return err;
205
206 return gpiod_set_debounce(desc, debounce);
207}
208EXPORT_SYMBOL_GPL(gpio_set_debounce);
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 39a1d06950d9..c1d4105e1c1d 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -63,10 +63,19 @@ static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
63extern int gpio_request(unsigned gpio, const char *label); 63extern int gpio_request(unsigned gpio, const char *label);
64extern void gpio_free(unsigned gpio); 64extern void gpio_free(unsigned gpio);
65 65
66extern int gpio_direction_input(unsigned gpio); 66static inline int gpio_direction_input(unsigned gpio)
67extern int gpio_direction_output(unsigned gpio, int value); 67{
68 return gpiod_direction_input(gpio_to_desc(gpio));
69}
70static inline int gpio_direction_output(unsigned gpio, int value)
71{
72 return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
73}
68 74
69extern int gpio_set_debounce(unsigned gpio, unsigned debounce); 75static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
76{
77 return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
78}
70 79
71static inline int gpio_get_value_cansleep(unsigned gpio) 80static inline int gpio_get_value_cansleep(unsigned gpio)
72{ 81{