All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Linux Input <linux-input@vger.kernel.org>,
	linux-media@vger.kernel.org, Jarod Wilson <jarod@redhat.com>,
	Maxim Levitsky <maximlevitsky@gmail.com>,
	David Hardeman <david@hardeman.nu>, Jiri Kosina <jkosina@suse.cz>,
	Ville Syrjala <syrjala@sci.fi>
Subject: [PATCH 2/6] Input: sparse-keymap - switch to using new keycode interface
Date: Wed, 08 Sep 2010 00:41:49 -0700	[thread overview]
Message-ID: <20100908074149.32365.21481.stgit@hammer.corenet.prv> (raw)
In-Reply-To: <20100908073233.32365.74621.stgit@hammer.corenet.prv>

Switch sparse keymap library to use new style of getkeycode and
setkeycode methods to allow retrieving and setting keycodes not
only by their scancodes but also by index.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/input/sparse-keymap.c |   81 +++++++++++++++++++++++++++++++++--------
 1 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c
index 0142483..a29a7812 100644
--- a/drivers/input/sparse-keymap.c
+++ b/drivers/input/sparse-keymap.c
@@ -22,6 +22,37 @@ MODULE_DESCRIPTION("Generic support for sparse keymaps");
 MODULE_LICENSE("GPL v2");
 MODULE_VERSION("0.1");
 
+static unsigned int sparse_keymap_get_key_index(struct input_dev *dev,
+						const struct key_entry *k)
+{
+	struct key_entry *key;
+	unsigned int idx = 0;
+
+	for (key = dev->keycode; key->type != KE_END; key++) {
+		if (key->type == KE_KEY) {
+			if (key == k)
+				break;
+			idx++;
+		}
+	}
+
+	return idx;
+}
+
+static struct key_entry *sparse_keymap_entry_by_index(struct input_dev *dev,
+						      unsigned int index)
+{
+	struct key_entry *key;
+	unsigned int key_cnt = 0;
+
+	for (key = dev->keycode; key->type != KE_END; key++)
+		if (key->type == KE_KEY)
+			if (key_cnt++ == index)
+				return key;
+
+	return NULL;
+}
+
 /**
  * sparse_keymap_entry_from_scancode - perform sparse keymap lookup
  * @dev: Input device using sparse keymap
@@ -64,16 +95,36 @@ struct key_entry *sparse_keymap_entry_from_keycode(struct input_dev *dev,
 }
 EXPORT_SYMBOL(sparse_keymap_entry_from_keycode);
 
+static struct key_entry *sparse_keymap_locate(struct input_dev *dev,
+					const struct input_keymap_entry *ke)
+{
+	struct key_entry *key;
+	unsigned int scancode;
+
+	if (ke->flags & INPUT_KEYMAP_BY_INDEX)
+		key = sparse_keymap_entry_by_index(dev, ke->index);
+	else if (input_scancode_to_scalar(ke, &scancode) == 0)
+		key = sparse_keymap_entry_from_scancode(dev, scancode);
+	else
+		key = NULL;
+
+	return key;
+}
+
 static int sparse_keymap_getkeycode(struct input_dev *dev,
-				    unsigned int scancode,
-				    unsigned int *keycode)
+				    struct input_keymap_entry *ke)
 {
 	const struct key_entry *key;
 
 	if (dev->keycode) {
-		key = sparse_keymap_entry_from_scancode(dev, scancode);
+		key = sparse_keymap_locate(dev, ke);
 		if (key && key->type == KE_KEY) {
-			*keycode = key->keycode;
+			ke->keycode = key->keycode;
+			if (!(ke->flags & INPUT_KEYMAP_BY_INDEX))
+				ke->index =
+					sparse_keymap_get_key_index(dev, key);
+			ke->len = sizeof(key->code);
+			memcpy(ke->scancode, &key->code, sizeof(key->code));
 			return 0;
 		}
 	}
@@ -82,20 +133,19 @@ static int sparse_keymap_getkeycode(struct input_dev *dev,
 }
 
 static int sparse_keymap_setkeycode(struct input_dev *dev,
-				    unsigned int scancode,
-				    unsigned int keycode)
+				    const struct input_keymap_entry *ke,
+				    unsigned int *old_keycode)
 {
 	struct key_entry *key;
-	int old_keycode;
 
 	if (dev->keycode) {
-		key = sparse_keymap_entry_from_scancode(dev, scancode);
+		key = sparse_keymap_locate(dev, ke);
 		if (key && key->type == KE_KEY) {
-			old_keycode = key->keycode;
-			key->keycode = keycode;
-			set_bit(keycode, dev->keybit);
-			if (!sparse_keymap_entry_from_keycode(dev, old_keycode))
-				clear_bit(old_keycode, dev->keybit);
+			*old_keycode = key->keycode;
+			key->keycode = ke->keycode;
+			set_bit(ke->keycode, dev->keybit);
+			if (!sparse_keymap_entry_from_keycode(dev, *old_keycode))
+				clear_bit(*old_keycode, dev->keybit);
 			return 0;
 		}
 	}
@@ -159,15 +209,14 @@ int sparse_keymap_setup(struct input_dev *dev,
 
 	dev->keycode = map;
 	dev->keycodemax = map_size;
-	dev->getkeycode = sparse_keymap_getkeycode;
-	dev->setkeycode = sparse_keymap_setkeycode;
+	dev->getkeycode_new = sparse_keymap_getkeycode;
+	dev->setkeycode_new = sparse_keymap_setkeycode;
 
 	return 0;
 
  err_out:
 	kfree(map);
 	return error;
-
 }
 EXPORT_SYMBOL(sparse_keymap_setup);
 


  parent reply	other threads:[~2010-09-08  7:41 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-08  7:41 [PATCH 0/6] Large scancode handling Dmitry Torokhov
2010-09-08  7:41 ` [PATCH 1/6] Input: add support for large scancodes Dmitry Torokhov
2010-10-29 21:36   ` James Hogan
2010-10-29 22:34     ` James Hogan
2010-09-08  7:41 ` Dmitry Torokhov [this message]
2010-09-08  7:41 ` [PATCH 3/6] Input: hid-input - switch to using new keycode interface Dmitry Torokhov
2010-09-08  7:42 ` [PATCH 4/6] Input: winbond-cir " Dmitry Torokhov
2010-09-08 21:16   ` David Härdeman
2010-09-08 23:00     ` Dmitry Torokhov
2010-09-08 23:00       ` Dmitry Torokhov
2010-09-08 23:09       ` David Härdeman
2010-09-08 23:09         ` David Härdeman
2010-09-08 23:14         ` Mauro Carvalho Chehab
2010-09-08 23:14           ` Mauro Carvalho Chehab
2010-09-08  7:42 ` [PATCH 5/6] Input: ati-remote2 " Dmitry Torokhov
2010-09-09 12:40   ` Ville Syrjälä
2010-09-13 16:28     ` Dmitry Torokhov
2010-09-13 16:28       ` Dmitry Torokhov
2010-09-15 21:04       ` Ville Syrjälä
2010-09-15 21:04         ` Ville Syrjälä
2010-09-15 21:13         ` Dmitry Torokhov
2010-09-08  7:42 ` [PATCH 6/6] Input: media/IR " Dmitry Torokhov
2010-09-08  9:48 ` [PATCH 0/6] Large scancode handling Jiri Kosina
2010-09-08 14:24   ` Jarod Wilson
2010-09-08 15:15     ` Mauro Carvalho Chehab
2010-09-08 15:22       ` Jarod Wilson
2010-09-08 15:25         ` Jiri Kosina
2010-09-08 15:36           ` Dmitry Torokhov
2010-09-08 16:09           ` Jarod Wilson
2010-09-08 16:56             ` Dmitry Torokhov
2010-09-08 17:29               ` Jarod Wilson
2010-09-13 15:00             ` Jiri Kosina
2010-09-08 15:36   ` Dmitry Torokhov
2010-09-08 14:31 ` Jarod Wilson
2010-09-08 15:34   ` Dmitry Torokhov
2010-09-13 17:48     ` Jarod Wilson
2010-09-14  1:26       ` Dmitry Torokhov
2010-09-08 15:23 ` Mauro Carvalho Chehab

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=20100908074149.32365.21481.stgit@hammer.corenet.prv \
    --to=dmitry.torokhov@gmail.com \
    --cc=david@hardeman.nu \
    --cc=jarod@redhat.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=maximlevitsky@gmail.com \
    --cc=mchehab@redhat.com \
    --cc=syrjala@sci.fi \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.