summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2017-06-03 20:11:52 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2017-06-06 08:27:15 +0200
commitbbc499914739cd51f51cd23ade0a2dca19359804 (patch)
tree6b36fb0e96430f15657283e200ec810be16d0158 /include
parent08dd7b2bf240c262ff585546115e8a96ca5b52d7 (diff)
downloadbarebox-bbc499914739cd51f51cd23ade0a2dca19359804.tar.gz
barebox-bbc499914739cd51f51cd23ade0a2dca19359804.tar.xz
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 <nikita.yoush@cogentembedded.com> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/gpio.h25
1 files changed, 25 insertions, 0 deletions
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