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 3/6] Input: hid-input - switch to using new keycode interface
Date: Wed, 08 Sep 2010 00:41:55 -0700 [thread overview]
Message-ID: <20100908074155.32365.15268.stgit@hammer.corenet.prv> (raw)
In-Reply-To: <20100908073233.32365.74621.stgit@hammer.corenet.prv>
Switch HID code 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/hid/hid-input.c | 103 ++++++++++++++++++++++++++++++++---------------
1 files changed, 70 insertions(+), 33 deletions(-)
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 6c03dcc..b12c07e 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -68,39 +68,49 @@ static const struct {
#define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \
&max, EV_KEY, (c))
-static inline int match_scancode(unsigned int code, unsigned int scancode)
+static bool match_scancode(struct hid_usage *usage,
+ unsigned int cur_idx, unsigned int scancode)
{
- if (scancode == 0)
- return 1;
-
- return (code & (HID_USAGE_PAGE | HID_USAGE)) == scancode;
+ return (usage->hid & (HID_USAGE_PAGE | HID_USAGE)) == scancode;
}
-static inline int match_keycode(unsigned int code, unsigned int keycode)
+static bool match_keycode(struct hid_usage *usage,
+ unsigned int cur_idx, unsigned int keycode)
{
- if (keycode == 0)
- return 1;
+ return usage->code == keycode;
+}
- return code == keycode;
+static bool match_index(struct hid_usage *usage,
+ unsigned int cur_idx, unsigned int idx)
+{
+ return cur_idx == idx;
}
+typedef bool (*hid_usage_cmp_t)(struct hid_usage *usage,
+ unsigned int cur_idx, unsigned int val);
+
static struct hid_usage *hidinput_find_key(struct hid_device *hid,
- unsigned int scancode,
- unsigned int keycode)
+ hid_usage_cmp_t match,
+ unsigned int value,
+ unsigned int *usage_idx)
{
- int i, j, k;
+ unsigned int i, j, k, cur_idx = 0;
struct hid_report *report;
struct hid_usage *usage;
for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
for (i = 0; i < report->maxfield; i++) {
- for ( j = 0; j < report->field[i]->maxusage; j++) {
+ for (j = 0; j < report->field[i]->maxusage; j++) {
usage = report->field[i]->usage + j;
- if (usage->type == EV_KEY &&
- match_scancode(usage->hid, scancode) &&
- match_keycode(usage->code, keycode))
- return usage;
+ if (usage->type == EV_KEY) {
+ if (match(usage, cur_idx, value)) {
+ if (usage_idx)
+ *usage_idx = cur_idx;
+ return usage;
+ }
+ cur_idx++;
+ }
}
}
}
@@ -108,39 +118,66 @@ static struct hid_usage *hidinput_find_key(struct hid_device *hid,
return NULL;
}
+static struct hid_usage *hidinput_locate_usage(struct hid_device *hid,
+ const struct input_keymap_entry *ke,
+ unsigned int *index)
+{
+ struct hid_usage *usage;
+ unsigned int scancode;
+
+ if (ke->flags & INPUT_KEYMAP_BY_INDEX)
+ usage = hidinput_find_key(hid, match_index, ke->index, index);
+ else if (input_scancode_to_scalar(ke, &scancode) == 0)
+ usage = hidinput_find_key(hid, match_scancode, scancode, index);
+ else
+ usage = NULL;
+
+ return usage;
+}
+
static int hidinput_getkeycode(struct input_dev *dev,
- unsigned int scancode, unsigned int *keycode)
+ struct input_keymap_entry *ke)
{
struct hid_device *hid = input_get_drvdata(dev);
struct hid_usage *usage;
+ unsigned int scancode, index;
- usage = hidinput_find_key(hid, scancode, 0);
+ usage = hidinput_locate_usage(hid, ke, &index);
if (usage) {
- *keycode = usage->code;
+ ke->keycode = usage->code;
+ ke->index = index;
+ scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE);
+ ke->len = sizeof(scancode);
+ memcpy(ke->scancode, &scancode, sizeof(scancode));
return 0;
}
+
return -EINVAL;
}
static int hidinput_setkeycode(struct input_dev *dev,
- unsigned int scancode, unsigned int keycode)
+ const struct input_keymap_entry *ke,
+ unsigned int *old_keycode)
{
struct hid_device *hid = input_get_drvdata(dev);
struct hid_usage *usage;
- int old_keycode;
- usage = hidinput_find_key(hid, scancode, 0);
+ usage = hidinput_locate_usage(hid, ke, NULL);
if (usage) {
- old_keycode = usage->code;
- usage->code = keycode;
+ *old_keycode = usage->code;
+ usage->code = ke->keycode;
- clear_bit(old_keycode, dev->keybit);
+ clear_bit(*old_keycode, dev->keybit);
set_bit(usage->code, dev->keybit);
- dbg_hid(KERN_DEBUG "Assigned keycode %d to HID usage code %x\n", keycode, scancode);
- /* Set the keybit for the old keycode if the old keycode is used
- * by another key */
- if (hidinput_find_key (hid, 0, old_keycode))
- set_bit(old_keycode, dev->keybit);
+ dbg_hid(KERN_DEBUG "Assigned keycode %d to HID usage code %x\n",
+ usage->code, usage->hid);
+
+ /*
+ * Set the keybit for the old keycode if the old keycode is used
+ * by another key
+ */
+ if (hidinput_find_key(hid, match_keycode, *old_keycode, NULL))
+ set_bit(*old_keycode, dev->keybit);
return 0;
}
@@ -748,8 +785,8 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
hid->ll_driver->hidinput_input_event;
input_dev->open = hidinput_open;
input_dev->close = hidinput_close;
- input_dev->setkeycode = hidinput_setkeycode;
- input_dev->getkeycode = hidinput_getkeycode;
+ input_dev->setkeycode_new = hidinput_setkeycode;
+ input_dev->getkeycode_new = hidinput_getkeycode;
input_dev->name = hid->name;
input_dev->phys = hid->phys;
next prev 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 ` [PATCH 2/6] Input: sparse-keymap - switch to using new keycode interface Dmitry Torokhov
2010-09-08 7:41 ` Dmitry Torokhov [this message]
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=20100908074155.32365.15268.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.