From d468bf9ecaabd3bf3a6134e5a369ced82b1d1ca1 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 24 Sep 2013 11:54:38 +0200 Subject: gpio: add API to be strict about GPIO IRQ usage It is currently often possible in many GPIO drivers to request a GPIO line to be used as IRQ after calling gpio_to_irq() and, as the gpiolib is not aware of this, set the same line to output and start driving it, with undesired side effects. As it is a bogus usage scenario to request a line flagged as output to used as IRQ, we introduce APIs to let gpiolib track the use of a line as IRQ, and also set this flag from the userspace ABI. The API is symmetric so that lines can also be flagged from .irq_enable() and unflagged from IRQ by .irq_disable(). The debugfs file is altered so that we see if a line is reserved for IRQ. Cc: Enric Balletbo i Serra Cc: Grant Likely Cc: Jean-Christophe PLAGNIOL-VILLARD Cc: Santosh Shilimkar Acked-by: Alexandre Courbot Reviewed-by: Stephen Warren Reviewed-by: Javier Martinez Canillas Signed-off-by: Linus Walleij --- include/linux/gpio.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/linux/gpio.h') diff --git a/include/linux/gpio.h b/include/linux/gpio.h index 552e3f46e4a3..a06ec3e85ba3 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h @@ -204,6 +204,18 @@ static inline int gpio_to_irq(unsigned gpio) return -EINVAL; } +static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) +{ + WARN_ON(1); + return -EINVAL; +} + +static inline void gpio_unlock_as_irq(struct gpio_chip *chip, + unsigned int offset) +{ + WARN_ON(1); +} + static inline int irq_to_gpio(unsigned irq) { /* irq can never have been returned from gpio_to_irq() */ -- cgit v1.2.3 From 79a9becda8940deb2274b5aa4577c86d52ee7ecb Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Thu, 17 Oct 2013 10:21:36 -0700 Subject: gpiolib: export descriptor-based GPIO interface This patch exports the gpiod_* family of API functions, a safer alternative to the legacy GPIO interface. Differences between the gpiod and legacy gpio APIs are: - gpio works with integers, whereas gpiod operates on opaque handlers which cannot be forged or used before proper acquisition - gpiod get/set functions are aware of the active low state of a GPIO - gpio consumers should now include to access the new interface, whereas chips drivers will use The legacy gpio API is now built as inline functions on top of gpiod. Signed-off-by: Alexandre Courbot Signed-off-by: Linus Walleij --- include/linux/gpio.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include/linux/gpio.h') diff --git a/include/linux/gpio.h b/include/linux/gpio.h index a06ec3e85ba3..c691df044458 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h @@ -16,14 +16,17 @@ #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) +/* Gpio pin is active-low */ +#define GPIOF_ACTIVE_LOW (1 << 2) + /* Gpio pin is open drain */ -#define GPIOF_OPEN_DRAIN (1 << 2) +#define GPIOF_OPEN_DRAIN (1 << 3) /* Gpio pin is open source */ -#define GPIOF_OPEN_SOURCE (1 << 3) +#define GPIOF_OPEN_SOURCE (1 << 4) -#define GPIOF_EXPORT (1 << 4) -#define GPIOF_EXPORT_CHANGEABLE (1 << 5) +#define GPIOF_EXPORT (1 << 5) +#define GPIOF_EXPORT_CHANGEABLE (1 << 6) #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) -- cgit v1.2.3 From 403c1d0be5ccbd750d25c59d8358843a81e52e3b Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Oct 2013 12:59:05 +0200 Subject: gpio: provide stubs for devres gpio functions commit 6b3d8145dcfdbbb43f13544e16f44f4574f941dd "gpiolib: make GPIO_DEVRES depend on GPIOLIB" breaks builds when device drivers are using devm_gpio* devres functions without enabling GPIOLIB, relying on the devres code to be compiled anyway. Provide stubs so that we get these if we're using the devres functions without GPIOLIB. Reported-by: Fengguang Wu Cc: Alexandre Courbot Signed-off-by: Linus Walleij --- include/linux/gpio.h | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'include/linux/gpio.h') diff --git a/include/linux/gpio.h b/include/linux/gpio.h index c691df044458..0c56b9e9c209 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h @@ -77,6 +77,15 @@ static inline int irq_to_gpio(unsigned int irq) #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ +/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */ + +struct device; + +int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); +int devm_gpio_request_one(struct device *dev, unsigned gpio, + unsigned long flags, const char *label); +void devm_gpio_free(struct device *dev, unsigned int gpio); + #else /* ! CONFIG_GPIOLIB */ #include @@ -241,14 +250,25 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) WARN_ON(1); } -#endif /* ! CONFIG_GPIOLIB */ +static inline int devm_gpio_request(struct device *dev, unsigned gpio, + const char *label) +{ + WARN_ON(1); + return -EINVAL; +} -struct device; +static inline int devm_gpio_request_one(struct device *dev, unsigned gpio, + unsigned long flags, const char *label) +{ + WARN_ON(1); + return -EINVAL; +} -/* bindings for managed devices that want to request gpios */ -int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); -int devm_gpio_request_one(struct device *dev, unsigned gpio, - unsigned long flags, const char *label); -void devm_gpio_free(struct device *dev, unsigned int gpio); +static inline void devm_gpio_free(struct device *dev, unsigned int gpio) +{ + WARN_ON(1); +} + +#endif /* ! CONFIG_GPIOLIB */ #endif /* __LINUX_GPIO_H */ -- cgit v1.2.3