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 11/15] input: imx-keypad: convert to input framework
Date: Wed, 13 Jan 2016 16:37:32 +0100	[thread overview]
Message-ID: <1452699456-1025-12-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1452699456-1025-1-git-send-email-s.hauer@pengutronix.de>

To make it possible to ask for the button state.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/input/Kconfig      |  1 +
 drivers/input/imx_keypad.c | 55 ++++++++++------------------------------------
 2 files changed, 13 insertions(+), 43 deletions(-)

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 24c3bd7..7cc98f2 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -29,6 +29,7 @@ config KEYBOARD_IMX_KEYPAD
 	depends on ARCH_IMX
 	select INPUT_MATRIXKMAP
 	select POLLER
+	select INPUT
 	help
 	  This driver implements support for buttons connected
 	  to the IMX keypad matrix.
diff --git a/drivers/input/imx_keypad.c b/drivers/input/imx_keypad.c
index b0282f2..bc74d7d 100644
--- a/drivers/input/imx_keypad.c
+++ b/drivers/input/imx_keypad.c
@@ -48,6 +48,7 @@
 #include <malloc.h>
 #include <input/matrix_keypad.h>
 #include <linux/err.h>
+#include <input/input.h>
 
 /*
  * Keypad Controller registers (halfword)
@@ -73,15 +74,11 @@
 #define MAX_MATRIX_KEY_NUM	(MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS)
 
 struct imx_keypad {
+	struct input_device input;
 	struct clk *clk;
 	struct device_d *dev;
-	struct console_device cdev;
 	void __iomem *mmio_base;
 
-	/* optional */
-	int fifo_size;
-
-	struct kfifo *recv_fifo;
 	struct poller_struct poller;
 
 	/*
@@ -112,28 +109,6 @@ poller_to_imx_kp_pdata(struct poller_struct *poller)
 	return container_of(poller, struct imx_keypad, poller);
 }
 
-static inline struct imx_keypad *
-cdev_to_imx_kp_pdata(struct console_device *cdev)
-{
-	return container_of(cdev, struct imx_keypad, cdev);
-}
-
-static int imx_keypad_tstc(struct console_device *cdev)
-{
-	struct imx_keypad *kp = cdev_to_imx_kp_pdata(cdev);
-
-	return (kfifo_len(kp->recv_fifo) == 0) ? 0 : 1;
-}
-
-static int imx_keypad_getc(struct console_device *cdev)
-{
-	int code = 0;
-	struct imx_keypad *kp = cdev_to_imx_kp_pdata(cdev);
-
-	kfifo_get(kp->recv_fifo, (u_char*)&code, sizeof(int));
-	return code;
-}
-
 /* Scan the matrix and return the new state in *matrix_volatile_state. */
 static void imx_keypad_scan_matrix(struct imx_keypad *keypad,
 				  unsigned short *matrix_volatile_state)
@@ -226,7 +201,8 @@ static void imx_keypad_fire_events(struct imx_keypad *keypad,
 
 			code = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT);
 
-			kfifo_put(keypad->recv_fifo, (u_char*)(&keypad->keycodes[code]), sizeof(int));
+			input_report_key_event(&keypad->input, keypad->keycodes[code],
+					       matrix_volatile_state[col] & (1 << row));
 
 			dev_dbg(keypad->dev, "Event code: %d, val: %d",
 				keypad->keycodes[code],
@@ -390,8 +366,7 @@ static int __init imx_keypad_probe(struct device_d *dev)
 {
 	struct imx_keypad *keypad;
 	const struct matrix_keymap_data *keymap_data = dev->platform_data;
-	struct console_device *cdev;
-	int i;
+	int i, ret;
 
 	if (!keymap_data) {
 		dev_err(dev, "no keymap defined\n");
@@ -405,11 +380,6 @@ static int __init imx_keypad_probe(struct device_d *dev)
 	if (IS_ERR(keypad->mmio_base))
 		return PTR_ERR(keypad->mmio_base);
 
-	if(!keypad->fifo_size)
-		keypad->fifo_size = 50;
-
-	keypad->recv_fifo = kfifo_alloc(keypad->fifo_size);
-
 	/* Search for rows and cols enabled */
 	for (i = 0; i < keymap_data->keymap_size; i++) {
 		keypad->rows_en_mask |= 1 << KEY_ROW(keymap_data->keymap[i]);
@@ -436,16 +406,15 @@ static int __init imx_keypad_probe(struct device_d *dev)
 
 	keypad->poller.func = imx_keypad_check_for_events;
 
-	cdev = &keypad->cdev;
-	dev->type_data = cdev;
-	cdev->dev = dev;
-	cdev->tstc = imx_keypad_tstc;
-	cdev->getc = imx_keypad_getc;
-	cdev->f_active = CONSOLE_STDIN;
+	ret = poller_register(&keypad->poller);
+	if (ret)
+		return ret;
 
-	console_register(&keypad->cdev);
+	ret = input_device_register(&keypad->input);
+	if (ret)
+		return ret;
 
-	return poller_register(&keypad->poller);
+	return 0;
 }
 
 static struct driver_d imx_keypad_driver = {
-- 
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 ` Sascha Hauer [this message]
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 ` [PATCH 15/15] input: gpio-keys: convert to input framework 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=1452699456-1025-12-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