diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2019-09-09 10:14:44 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-09-09 10:59:56 +0200 |
commit | fb2e987ee1f54bc9fac26be03e93f839faa9e023 (patch) | |
tree | 5d6d625a3e68bad4dc0290e773032a4712b7b60a /include/gpio.h | |
parent | b330984ac85f9057846b20361dbf083c2d43547c (diff) | |
download | barebox-fb2e987ee1f54bc9fac26be03e93f839faa9e023.tar.gz barebox-fb2e987ee1f54bc9fac26be03e93f839faa9e023.tar.xz |
gpio: iopoll: implement gpio_poll_timeout_us
Sometimes we need to wait for state change on a GPIO, provide a helper
for future code to do this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/gpio.h')
-rw-r--r-- | include/gpio.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/gpio.h b/include/gpio.h index 1926edeca7..4d5f2c25c7 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -3,6 +3,7 @@ #include <linux/types.h> #include <linux/list.h> +#include <linux/iopoll.h> #ifdef CONFIG_GENERIC_GPIO void gpio_set_value(unsigned gpio, int value); @@ -31,6 +32,21 @@ static inline 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); + +/** + * gpio_poll_timeout_us - Poll till GPIO reaches requested active state + * @gpio: gpio to poll + * @active: wait till GPIO is active if true, wait till it's inactive if false + * @timeout_us: timeout in microseconds + * + * During the wait barebox pollers are called, if any. + */ +#define gpio_poll_timeout_us(gpio, active, timeout_us) \ + ({ \ + int __state; \ + readx_poll_timeout(gpio_is_active, gpio, __state, \ + __state == (active), timeout_us); \ + }) #else static inline void gpio_set_active(unsigned gpio, int value) { @@ -43,6 +59,8 @@ static inline int gpio_direction_active(unsigned gpio, int value) { return -EINVAL; } + +#define gpio_poll_timeout_us(gpio, val, timeout_us) (-ENOSYS) #endif #if defined(CONFIG_ARCH_NR_GPIO) && CONFIG_ARCH_NR_GPIO > 0 |