* [PATCH] input: gpio-keys: initialize the input value with the current gpioval
@ 2026-07-02 8:17 Sascha Hauer
0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-07-02 8:17 UTC (permalink / raw)
To: Barebox List; +Cc: Marco Felsch
This is required for deep-probe systems which probe the "gpio-keys"
device on demand. In such case the input value is not yet accessible
once the probe finished because the first gpio reads happen
asynchronously to the probe function. However, board code queries the
input device value directly after the of.*ensure.*probed().
Therefore provide a sane default by reading the gpio value during probe
and init the input device value.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/input/gpio_keys.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index b52738f5cc..0fb09007a9 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -30,25 +30,18 @@ struct gpio_keys {
struct input_device input;
};
-static void gpio_key_poller(void *data)
+static void gpio_keys_read(struct gpio_keys *gk, bool force)
{
- struct gpio_keys *gk = data;
struct gpio_key *gb;
int i, pressed;
- for (i = 0; i < gk->nbuttons; i++) {
- gb = &gk->buttons[i];
-
- if (gpiod_slice_acquired(gb->gpio))
- goto out;
- }
-
for (i = 0; i < gk->nbuttons; i++) {
gb = &gk->buttons[i];
pressed = gpiod_get_value(gb->gpio);
- if (!is_timeout(gb->debounce_start, gb->debounce_interval * MSECOND))
+ if (!force && !is_timeout(gb->debounce_start,
+ gb->debounce_interval * MSECOND))
continue;
if (pressed != gb->previous_state) {
@@ -59,6 +52,22 @@ static void gpio_key_poller(void *data)
gb->previous_state = pressed;
}
}
+}
+
+static void gpio_key_poller(void *data)
+{
+ struct gpio_keys *gk = data;
+ struct gpio_key *gb;
+ int i;
+
+ for (i = 0; i < gk->nbuttons; i++) {
+ gb = &gk->buttons[i];
+
+ if (gpiod_slice_acquired(gb->gpio))
+ goto out;
+ }
+
+ gpio_keys_read(gk, false);
out:
poller_call_async(&gk->poller, 10 * MSECOND, gpio_key_poller, gk);
}
@@ -167,6 +176,8 @@ static int __init gpio_keys_probe(struct device *dev)
if (ret)
return ret;
+ gpio_keys_read(gk, true);
+
poller_call_async(&gk->poller, 10 * MSECOND, gpio_key_poller, gk);
return 0;
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] input: gpio-keys: initialize the input value with the current gpioval
2026-06-25 11:51 Marco Felsch
@ 2026-07-02 8:18 ` Sascha Hauer
0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-07-02 8:18 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
Hi Marco,
I just sent an alternative patch which avoids some code duplication.
It's untested, maybe you could spin a test for your case.
Sascha
On 2026-06-25 13:51, Marco Felsch wrote:
> This is required for deep-probe systems which prove the "gpio-keys"
> device on demand. In such case the input value is not yet accessible
> once the probe finished. However, board code queries the input device
> value directly after the of.*ensure.*probed().
>
> Therefore provide a sane default by reading the gpio value during probe
> and init the input device value.
>
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> drivers/input/gpio_keys.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
> index b52738f5ccb2..316ed73ddfd1 100644
> --- a/drivers/input/gpio_keys.c
> +++ b/drivers/input/gpio_keys.c
> @@ -143,6 +143,26 @@ static int gpio_keys_probe_dt(struct gpio_keys *gk, struct device *dev)
> return 0;
> }
>
> +static int gpio_keys_set_initialval(struct gpio_keys *gk)
> +{
> + struct gpio_key *gb;
> + int i, pressed;
> +
> + for (i = 0; i < gk->nbuttons; i++) {
> +
> + gb = &gk->buttons[i];
> + pressed = gpiod_get_value(gb->gpio);
> +
> + if (pressed != gb->previous_state) {
> + gb->debounce_start = get_time_ns();
> + input_report_key_event(&gk->input, gb->code, pressed);
> + dev_dbg(gk->input.parent, "%s gpio #%d as %d\n",
> + pressed ? "pressed" : "released", i, gb->code);
> + gb->previous_state = pressed;
> + }
> + }
> +}
> +
> static int __init gpio_keys_probe(struct device *dev)
> {
> int ret;
> @@ -163,6 +183,8 @@ static int __init gpio_keys_probe(struct device *dev)
> if (ret)
> return ret;
>
> + gpio_keys_set_initialval(gk);
> +
> ret = poller_async_register(&gk->poller, dev_name(dev));
> if (ret)
> return ret;
> --
> 2.47.3
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] input: gpio-keys: initialize the input value with the current gpioval
@ 2026-06-25 11:51 Marco Felsch
2026-07-02 8:18 ` Sascha Hauer
0 siblings, 1 reply; 3+ messages in thread
From: Marco Felsch @ 2026-06-25 11:51 UTC (permalink / raw)
To: barebox
This is required for deep-probe systems which prove the "gpio-keys"
device on demand. In such case the input value is not yet accessible
once the probe finished. However, board code queries the input device
value directly after the of.*ensure.*probed().
Therefore provide a sane default by reading the gpio value during probe
and init the input device value.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/input/gpio_keys.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index b52738f5ccb2..316ed73ddfd1 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -143,6 +143,26 @@ static int gpio_keys_probe_dt(struct gpio_keys *gk, struct device *dev)
return 0;
}
+static int gpio_keys_set_initialval(struct gpio_keys *gk)
+{
+ struct gpio_key *gb;
+ int i, pressed;
+
+ for (i = 0; i < gk->nbuttons; i++) {
+
+ gb = &gk->buttons[i];
+ pressed = gpiod_get_value(gb->gpio);
+
+ if (pressed != gb->previous_state) {
+ gb->debounce_start = get_time_ns();
+ input_report_key_event(&gk->input, gb->code, pressed);
+ dev_dbg(gk->input.parent, "%s gpio #%d as %d\n",
+ pressed ? "pressed" : "released", i, gb->code);
+ gb->previous_state = pressed;
+ }
+ }
+}
+
static int __init gpio_keys_probe(struct device *dev)
{
int ret;
@@ -163,6 +183,8 @@ static int __init gpio_keys_probe(struct device *dev)
if (ret)
return ret;
+ gpio_keys_set_initialval(gk);
+
ret = poller_async_register(&gk->poller, dev_name(dev));
if (ret)
return ret;
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-02 8:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-02 8:17 [PATCH] input: gpio-keys: initialize the input value with the current gpioval Sascha Hauer
-- strict thread matches above, loose matches on Subject: below --
2026-06-25 11:51 Marco Felsch
2026-07-02 8:18 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox