From bbc499914739cd51f51cd23ade0a2dca19359804 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sat, 3 Jun 2017 20:11:52 -0700 Subject: gpiolib: Add code to support "active low" GPIOs So far this particular aspect of various DT-bindings has been handled on a per-driver basis. With this change, hopefully, we'll have a single place to handle necessary logic inversions and eventually would be able to migrate existing users as well as avoiding adding redundant code to new drivers. Cc: cphealy@gmail.com Cc: Nikita Yushchenko Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- include/gpio.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include') diff --git a/include/gpio.h b/include/gpio.h index 7b3f512b19..56aae22236 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -6,6 +6,11 @@ void gpio_set_value(unsigned gpio, int value); int gpio_get_value(unsigned gpio); int gpio_direction_output(unsigned gpio, int value); int gpio_direction_input(unsigned gpio); + +void gpio_set_active(unsigned gpio, bool state); +int gpio_is_active(unsigned gpio); +int gpio_direction_active(unsigned gpio, bool state); + #else static inline void gpio_set_value(unsigned gpio, int value) { @@ -22,6 +27,18 @@ static inline int gpio_direction_input(unsigned gpio) { return -EINVAL; } + +static inline void gpio_set_active(unsigned gpio, int value) +{ +} +static inline int gpio_is_active(unsigned gpio) +{ + return 0; +} +static inline int gpio_direction_active(unsigned gpio, int value) +{ + return -EINVAL; +} #endif #define ARCH_NR_GPIOS 256 @@ -45,6 +62,14 @@ static inline int gpio_is_valid(int gpio) #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) +#define GPIOF_LOGICAL BIT(2) +#define GPIOF_ACTIVE_HIGH GPIOF_LOGICAL +#define GPIOF_ACTIVE_LOW (BIT(3) | GPIOF_LOGICAL) +#define GPIOF_INIT_INACTIVE GPIOF_LOGICAL +#define GPIOF_INIT_ACTIVE (GPIOF_LOGICAL | GPIOF_INIT_HIGH) +#define GPIOF_OUT_INIT_ACTIVE (GPIOF_DIR_OUT | GPIOF_INIT_ACTIVE) +#define GPIOF_OUT_INIT_INACTIVE (GPIOF_DIR_OUT | GPIOF_INIT_INACTIVE) + /** * struct gpio - a structure describing a GPIO with configuration * @gpio: the GPIO number -- cgit v1.2.3