[PATCH] input: gpio-keys: initialize the input value with the current gpioval
Sascha Hauer
s.hauer at pengutronix.de
Thu Jul 2 01:17:19 PDT 2026
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 at 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
More information about the barebox
mailing list