Skip to content

Commit c7caf86

Browse files
GnurouLinus Walleij
authored andcommitted
gpio: remove gpio_ensure_requested()
gpio_ensure_requested() has been introduced in Feb. 2008 by commit d2876d0 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>
1 parent 7fd834a commit c7caf86

2 files changed

Lines changed: 12 additions & 109 deletions

File tree

drivers/gpio/gpiolib-legacy.c

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,6 @@
55

66
#include "gpiolib.h"
77

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-
*/
19-
static 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-
44-
end:
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-
668
void gpio_free(unsigned gpio)
679
{
6810
gpiod_free(gpio_to_desc(gpio));
@@ -158,51 +100,3 @@ void gpio_free_array(const struct gpio *array, size_t num)
158100
gpio_free((array++)->gpio);
159101
}
160102
EXPORT_SYMBOL_GPL(gpio_free_array);
161-
162-
int 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-
}
176-
EXPORT_SYMBOL_GPL(gpio_direction_input);
177-
178-
int 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-
}
192-
EXPORT_SYMBOL_GPL(gpio_direction_output);
193-
194-
int 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-
}
208-
EXPORT_SYMBOL_GPL(gpio_set_debounce);

include/asm-generic/gpio.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,19 @@ static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
6363
extern int gpio_request(unsigned gpio, const char *label);
6464
extern void gpio_free(unsigned gpio);
6565

66-
extern int gpio_direction_input(unsigned gpio);
67-
extern int gpio_direction_output(unsigned gpio, int value);
66+
static inline int gpio_direction_input(unsigned gpio)
67+
{
68+
return gpiod_direction_input(gpio_to_desc(gpio));
69+
}
70+
static inline int gpio_direction_output(unsigned gpio, int value)
71+
{
72+
return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
73+
}
6874

69-
extern int gpio_set_debounce(unsigned gpio, unsigned debounce);
75+
static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
76+
{
77+
return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
78+
}
7079

7180
static inline int gpio_get_value_cansleep(unsigned gpio)
7281
{

0 commit comments

Comments
 (0)