Commit f5854fad authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: hid-input - allow mapping unknown usages

Currently HID layer only allows to remap keycodes for known usages,
and responds with -EINVAL when user tries to map new usage code.
This precludes us form relying on udev/keymap for establishing correct
mappings and forces us to write dummy HID drivers responsible only for
setting up keymaps.

Let's allow remapping not only usages that have been set up as keys
(usage->type == EV_KEY) but also yet-unmapped usages (usage->type == 0).
Acked-by: default avatarJarod Wilson <jarod@redhat.com>
Acked-by: default avatarJiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 1f7930c5
...@@ -77,7 +77,10 @@ static bool match_scancode(struct hid_usage *usage, ...@@ -77,7 +77,10 @@ static bool match_scancode(struct hid_usage *usage,
static bool match_keycode(struct hid_usage *usage, static bool match_keycode(struct hid_usage *usage,
unsigned int cur_idx, unsigned int keycode) unsigned int cur_idx, unsigned int keycode)
{ {
return usage->code == keycode; /*
* We should exclude unmapped usages when doing lookup by keycode.
*/
return (usage->type == EV_KEY && usage->code == keycode);
} }
static bool match_index(struct hid_usage *usage, static bool match_index(struct hid_usage *usage,
...@@ -103,7 +106,7 @@ static struct hid_usage *hidinput_find_key(struct hid_device *hid, ...@@ -103,7 +106,7 @@ static struct hid_usage *hidinput_find_key(struct hid_device *hid,
for (i = 0; i < report->maxfield; i++) { 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; usage = report->field[i]->usage + j;
if (usage->type == EV_KEY) { if (usage->type == EV_KEY || usage->type == 0) {
if (match(usage, cur_idx, value)) { if (match(usage, cur_idx, value)) {
if (usage_idx) if (usage_idx)
*usage_idx = cur_idx; *usage_idx = cur_idx;
...@@ -144,7 +147,8 @@ static int hidinput_getkeycode(struct input_dev *dev, ...@@ -144,7 +147,8 @@ static int hidinput_getkeycode(struct input_dev *dev,
usage = hidinput_locate_usage(hid, ke, &index); usage = hidinput_locate_usage(hid, ke, &index);
if (usage) { if (usage) {
ke->keycode = usage->code; ke->keycode = usage->type == EV_KEY ?
usage->code : KEY_RESERVED;
ke->index = index; ke->index = index;
scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE); scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE);
ke->len = sizeof(scancode); ke->len = sizeof(scancode);
...@@ -164,7 +168,8 @@ static int hidinput_setkeycode(struct input_dev *dev, ...@@ -164,7 +168,8 @@ static int hidinput_setkeycode(struct input_dev *dev,
usage = hidinput_locate_usage(hid, ke, NULL); usage = hidinput_locate_usage(hid, ke, NULL);
if (usage) { if (usage) {
*old_keycode = usage->code; *old_keycode = usage->type == EV_KEY ?
usage->code : KEY_RESERVED;
usage->code = ke->keycode; usage->code = ke->keycode;
clear_bit(*old_keycode, dev->keybit); clear_bit(*old_keycode, dev->keybit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment