* [PATCH v2] gpio: iopoll: implement gpio_poll_timeout_us
@ 2019-09-09 8:14 Ahmad Fatoum
2019-09-09 9:00 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2019-09-09 8:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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>
---
v1 -> v2:
Add comment describing use of macro
---
include/gpio.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/gpio.h b/include/gpio.h
index 38d6ba2df913..867f3d1dbdc6 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
#define ARCH_NR_GPIOS 256
--
2.23.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] gpio: iopoll: implement gpio_poll_timeout_us
2019-09-09 8:14 [PATCH v2] gpio: iopoll: implement gpio_poll_timeout_us Ahmad Fatoum
@ 2019-09-09 9:00 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-09-09 9:00 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Sep 09, 2019 at 10:14:44AM +0200, Ahmad Fatoum wrote:
> 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>
> ---
> v1 -> v2:
> Add comment describing use of macro
> ---
> include/gpio.h | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-09-09 9:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 8:14 [PATCH v2] gpio: iopoll: implement gpio_poll_timeout_us Ahmad Fatoum
2019-09-09 9:00 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox