* [PATCH] gpio: iopoll: implement gpio_poll_timeout_us
@ 2019-08-29 12:43 Ahmad Fatoum
2019-08-30 4:18 ` Oleksij Rempel
2019-09-02 7:16 ` Sascha Hauer
0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2019-08-29 12:43 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Sometimes we need to wait for state change on a GPIO,
provide a helper to do this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/gpio.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/gpio.h b/include/gpio.h
index 1926edeca757..89cb306a195c 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,13 @@ 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);
+
+#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 +51,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
--
2.23.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: iopoll: implement gpio_poll_timeout_us
2019-08-29 12:43 [PATCH] gpio: iopoll: implement gpio_poll_timeout_us Ahmad Fatoum
@ 2019-08-30 4:18 ` Oleksij Rempel
2019-08-30 8:55 ` Ahmad Fatoum
2019-09-02 7:16 ` Sascha Hauer
1 sibling, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2019-08-30 4:18 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Thu, Aug 29, 2019 at 02:43:18PM +0200, Ahmad Fatoum wrote:
> Sometimes we need to wait for state change on a GPIO,
> provide a helper to do this.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/gpio.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/gpio.h b/include/gpio.h
> index 1926edeca757..89cb306a195c 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,13 @@ 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);
> +
> +#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 +51,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
Do we already have some thing using this function?
--
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] 4+ messages in thread
* Re: [PATCH] gpio: iopoll: implement gpio_poll_timeout_us
2019-08-30 4:18 ` Oleksij Rempel
@ 2019-08-30 8:55 ` Ahmad Fatoum
0 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2019-08-30 8:55 UTC (permalink / raw)
To: Oleksij Rempel; +Cc: barebox
Hello Oleksij,
On 8/30/19 6:18 AM, Oleksij Rempel wrote:
> On Thu, Aug 29, 2019 at 02:43:18PM +0200, Ahmad Fatoum wrote:
>> Sometimes we need to wait for state change on a GPIO,
>> provide a helper to do this.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> include/gpio.h | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/include/gpio.h b/include/gpio.h
>> index 1926edeca757..89cb306a195c 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,13 @@ 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);
>> +
>> +#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 +51,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
>
> Do we already have some thing using this function?
Just stuff sitting on my own branches, but I figured it's useful
enough to have in the header.
>
--
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] 4+ messages in thread
* Re: [PATCH] gpio: iopoll: implement gpio_poll_timeout_us
2019-08-29 12:43 [PATCH] gpio: iopoll: implement gpio_poll_timeout_us Ahmad Fatoum
2019-08-30 4:18 ` Oleksij Rempel
@ 2019-09-02 7:16 ` Sascha Hauer
1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2019-09-02 7:16 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Thu, Aug 29, 2019 at 02:43:18PM +0200, Ahmad Fatoum wrote:
> Sometimes we need to wait for state change on a GPIO,
> provide a helper to do this.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/gpio.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/gpio.h b/include/gpio.h
> index 1926edeca757..89cb306a195c 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,13 @@ 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);
> +
> +#define gpio_poll_timeout_us(gpio, active, timeout_us) \
Please add a comment what this macro does. Specificall it's interesting
to know if this function polls as long as the gpio is active or if it
polls until it's active.
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] 4+ messages in thread
end of thread, other threads:[~2019-09-02 7:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 12:43 [PATCH] gpio: iopoll: implement gpio_poll_timeout_us Ahmad Fatoum
2019-08-30 4:18 ` Oleksij Rempel
2019-08-30 8:55 ` Ahmad Fatoum
2019-09-02 7:16 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox