mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 15/15] input: gpio-keys: convert to input framework
Date: Wed, 13 Jan 2016 16:37:36 +0100	[thread overview]
Message-ID: <1452699456-1025-16-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1452699456-1025-1-git-send-email-s.hauer@pengutronix.de>

To allow asking for the button states.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/input/gpio_keys.c | 64 +++++++++++++----------------------------------
 1 file changed, 17 insertions(+), 47 deletions(-)

diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index acb9e07..38c0f11 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -12,7 +12,7 @@
 #include <poller.h>
 #include <gpio.h>
 #include <of_gpio.h>
-#include <input/keyboard.h>
+#include <input/input.h>
 
 struct gpio_key {
 	int code;
@@ -30,12 +30,9 @@ struct gpio_keys {
 	struct gpio_key *buttons;
 	int nbuttons;
 
-	/* optional */
-	int fifo_size;
-
-	struct kfifo *recv_fifo;
 	struct poller_struct poller;
-	struct console_device cdev;
+	struct input_device input;
+	struct device_d *dev;
 };
 
 static inline struct gpio_keys *
@@ -44,12 +41,6 @@ poller_to_gk_pdata(struct poller_struct *poller)
 	return container_of(poller, struct gpio_keys, poller);
 }
 
-static inline struct gpio_keys *
-cdev_to_gk_pdata(struct console_device *cdev)
-{
-	return container_of(cdev, struct gpio_keys, cdev);
-}
-
 static void gpio_key_poller(struct poller_struct *poller)
 {
 	struct gpio_keys *gk = poller_to_gk_pdata(poller);
@@ -65,33 +56,17 @@ static void gpio_key_poller(struct poller_struct *poller)
 			continue;
 
 		if (val != gb->previous_state) {
+			int pressed = val != gb->active_low;
+
 			gb->debounce_start = get_time_ns();
-			if (val != gb->active_low) {
-				kfifo_put(gk->recv_fifo, (u_char*)&gb->code, sizeof(int));
-				debug("pressed gpio(%d) as %d\n", gb->gpio, gb->code);
-			}
+			input_report_key_event(&gk->input, gb->code, pressed);
+			dev_dbg(gk->dev, "%s gpio(%d) as %d\n",
+				pressed ? "pressed" : "released", gb->gpio, gb->code);
 			gb->previous_state = val;
 		}
 	}
 }
 
-static int gpio_keys_tstc(struct console_device *cdev)
-{
-	struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
-
-	return (kfifo_len(gk->recv_fifo) == 0) ? 0 : 1;
-}
-
-static int gpio_keys_getc(struct console_device *cdev)
-{
-	int code = 0;
-	struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
-
-	kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int));
-
-	return keycode_bb_keys[code];
-}
-
 static int gpio_keys_probe_pdata(struct gpio_keys *gk, struct device_d *dev)
 {
 	struct gpio_keys_platform_data *pdata;
@@ -105,9 +80,6 @@ static int gpio_keys_probe_pdata(struct gpio_keys *gk, struct device_d *dev)
 		return -ENODEV;
 	}
 
-	if (pdata->fifo_size)
-		gk->fifo_size = pdata->fifo_size;
-
 	gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons));
 	gk->nbuttons = pdata->nbuttons;
 
@@ -163,11 +135,11 @@ static int gpio_keys_probe_dt(struct gpio_keys *gk, struct device_d *dev)
 static int __init gpio_keys_probe(struct device_d *dev)
 {
 	int ret, i, gpio;
-	struct console_device *cdev;
 	struct gpio_keys *gk;
 
 	gk = xzalloc(sizeof(*gk));
-	gk->fifo_size = 50;
+
+	gk->dev = dev;
 
 	if (dev->device_node)
 		ret = gpio_keys_probe_dt(gk, dev);
@@ -177,8 +149,6 @@ static int __init gpio_keys_probe(struct device_d *dev)
 	if (ret)
 		return ret;
 
-	gk->recv_fifo = kfifo_alloc(gk->fifo_size);
-
 	for (i = 0; i < gk->nbuttons; i++) {
 		gpio = gk->buttons[i].gpio;
 		ret = gpio_request(gpio, "gpio_keys");
@@ -192,15 +162,15 @@ static int __init gpio_keys_probe(struct device_d *dev)
 
 	gk->poller.func = gpio_key_poller;
 
-	cdev = &gk->cdev;
-	dev->type_data = cdev;
-	cdev->dev = dev;
-	cdev->tstc = gpio_keys_tstc;
-	cdev->getc = gpio_keys_getc;
+	ret = input_device_register(&gk->input);
+	if (ret)
+		return ret;
 
-	console_register(&gk->cdev);
+	ret = poller_register(&gk->poller);
+	if (ret)
+		return ret;
 
-	return poller_register(&gk->poller);
+	return 0;
 }
 
 static struct of_device_id key_gpio_of_ids[] = {
-- 
2.6.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2016-01-13 15:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 15:37 [PATCH] input core Sascha Hauer
2016-01-13 15:37 ` [PATCH 01/15] poller: Fix async poller Sascha Hauer
2016-01-13 15:37 ` [PATCH 02/15] keymap: Fix braces Sascha Hauer
2016-01-13 15:37 ` [PATCH 03/15] keymap: remove exotic and nonprintable keys Sascha Hauer
2016-01-13 15:37 ` [PATCH 04/15] keymap: Add keypad keys Sascha Hauer
2016-01-13 15:37 ` [PATCH 05/15] keymap: Add apostrophe, backslash and home Sascha Hauer
2016-01-13 15:37 ` [PATCH 06/15] keymap: Add keymap for keys with shift pressed Sascha Hauer
2016-01-13 15:37 ` [PATCH 07/15] input: Add input core Sascha Hauer
2017-05-05 10:05   ` Antony Pavlov
2017-05-05 11:10     ` Sascha Hauer
2016-01-13 15:37 ` [PATCH 08/15] input: usb keyboard: convert to input framework Sascha Hauer
2016-01-13 15:37 ` [PATCH 09/15] input: imx-keypad: Use dev_* functions Sascha Hauer
2016-01-13 15:37 ` [PATCH 10/15] input: move matrix_keypad_build_keymap() to C file Sascha Hauer
2016-01-13 15:37 ` [PATCH 11/15] input: imx-keypad: convert to input framework Sascha Hauer
2016-01-13 15:37 ` [PATCH 12/15] input: Add device tree parsing support for matrix keymap Sascha Hauer
2016-01-13 15:37 ` [PATCH 13/15] input: imx-keypad: Add device tree support Sascha Hauer
2016-01-13 15:37 ` [PATCH 14/15] input: gpio-keys: Use KEY_* keycodes Sascha Hauer
2016-01-13 15:37 ` Sascha Hauer [this message]

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=1452699456-1025-16-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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