From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH] input: gpio-keys: initialize the input value with the current gpioval
Date: Thu, 2 Jul 2026 10:17:19 +0200 [thread overview]
Message-ID: <20260702081719.2065068-1-s.hauer@pengutronix.de> (raw)
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
next reply other threads:[~2026-07-02 8:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 8:17 Sascha Hauer [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-06-25 11:51 Marco Felsch
2026-07-02 8:18 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260702081719.2065068-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.felsch@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox