mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] input: gpio-keys: initialize the input value with the current gpioval
Date: Thu, 25 Jun 2026 13:51:47 +0200	[thread overview]
Message-ID: <20260625115149.4108394-1-m.felsch@pengutronix.de> (raw)

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




                 reply	other threads:[~2026-06-25 11:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260625115149.4108394-1-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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