Skip to content

Commit 6a89a31

Browse files
Shawn GuoLinus Walleij
authored andcommitted
gpio: devm_gpio_* support should not depend on GPIOLIB
Some architectures (e.g. blackfin) provide gpio API without requiring GPIOLIB support (ARCH_WANT_OPTIONAL_GPIOLIB). devm_gpio_* functions should also work for these architectures, since they do not really depend on GPIOLIB. Add a new option GPIO_DEVRES (enabled by default) to control the build of devres.c. It also removes the empty version of devm_gpio_* functions for !GENERIC_GPIO build from linux/gpio.h, and moves the function declarations from asm-generic/gpio.h into linux/gpio.h. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent d59b4ea commit 6a89a31

4 files changed

Lines changed: 13 additions & 27 deletions

File tree

drivers/gpio/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ config ARCH_REQUIRE_GPIOLIB
3030
Selecting this from the architecture code will cause the gpiolib
3131
code to always get built in.
3232

33+
config GPIO_DEVRES
34+
def_bool y
35+
depends on HAS_IOMEM
3336

3437

3538
menuconfig GPIOLIB

drivers/gpio/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
44

5-
obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o
5+
obj-$(CONFIG_GPIO_DEVRES) += devres.o
6+
obj-$(CONFIG_GPIOLIB) += gpiolib.o
67
obj-$(CONFIG_OF_GPIO) += gpiolib-of.o
78
obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o
89

include/asm-generic/gpio.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *labe
192192
extern int gpio_request_array(const struct gpio *array, size_t num);
193193
extern void gpio_free_array(const struct gpio *array, size_t num);
194194

195-
/* bindings for managed devices that want to request gpios */
196-
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
197-
int devm_gpio_request_one(struct device *dev, unsigned gpio,
198-
unsigned long flags, const char *label);
199-
void devm_gpio_free(struct device *dev, unsigned int gpio);
200-
201195
#ifdef CONFIG_GPIO_SYSFS
202196

203197
/*

include/linux/gpio.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,12 @@ static inline int gpio_request(unsigned gpio, const char *label)
9494
return -ENOSYS;
9595
}
9696

97-
static inline int devm_gpio_request(struct device *dev, unsigned gpio,
98-
const char *label)
99-
{
100-
return -ENOSYS;
101-
}
102-
10397
static inline int gpio_request_one(unsigned gpio,
10498
unsigned long flags, const char *label)
10599
{
106100
return -ENOSYS;
107101
}
108102

109-
static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
110-
unsigned long flags, const char *label)
111-
{
112-
return -ENOSYS;
113-
}
114-
115103
static inline int gpio_request_array(const struct gpio *array, size_t num)
116104
{
117105
return -ENOSYS;
@@ -125,14 +113,6 @@ static inline void gpio_free(unsigned gpio)
125113
WARN_ON(1);
126114
}
127115

128-
static inline void devm_gpio_free(struct device *dev, unsigned gpio)
129-
{
130-
might_sleep();
131-
132-
/* GPIO can never have been requested */
133-
WARN_ON(1);
134-
}
135-
136116
static inline void gpio_free_array(const struct gpio *array, size_t num)
137117
{
138118
might_sleep();
@@ -248,4 +228,12 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip)
248228

249229
#endif /* ! CONFIG_GENERIC_GPIO */
250230

231+
struct device;
232+
233+
/* bindings for managed devices that want to request gpios */
234+
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
235+
int devm_gpio_request_one(struct device *dev, unsigned gpio,
236+
unsigned long flags, const char *label);
237+
void devm_gpio_free(struct device *dev, unsigned int gpio);
238+
251239
#endif /* __LINUX_GPIO_H */

0 commit comments

Comments
 (0)