Commit f06e6a52 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: dvb-usb-remote - convert to new style of get/setkeycode

Acked-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent a1f3d4bb
...@@ -8,60 +8,71 @@ ...@@ -8,60 +8,71 @@
#include "dvb-usb-common.h" #include "dvb-usb-common.h"
#include <linux/usb/input.h> #include <linux/usb/input.h>
static unsigned int
legacy_dvb_usb_get_keymap_index(const struct input_keymap_entry *ke,
struct rc_map_table *keymap,
unsigned int keymap_size)
{
unsigned int index;
unsigned int scancode;
if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
index = ke->index;
} else {
if (input_scancode_to_scalar(ke, &scancode))
return keymap_size;
/* See if we can match the raw key code. */
for (index = 0; index < keymap_size; index++)
if (keymap[index].scancode == scancode)
break;
/* See if there is an unused hole in the map */
if (index >= keymap_size) {
for (index = 0; index < keymap_size; index++) {
if (keymap[index].keycode == KEY_RESERVED ||
keymap[index].keycode == KEY_UNKNOWN) {
break;
}
}
}
}
return index;
}
static int legacy_dvb_usb_getkeycode(struct input_dev *dev, static int legacy_dvb_usb_getkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int *keycode) struct input_keymap_entry *ke)
{ {
struct dvb_usb_device *d = input_get_drvdata(dev); struct dvb_usb_device *d = input_get_drvdata(dev);
struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
int i; unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
unsigned int index;
/* See if we can match the raw key code. */ index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size);
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) if (index >= keymap_size)
if (keymap[i].scancode == scancode) { return -EINVAL;
*keycode = keymap[i].keycode;
return 0;
}
/* ke->keycode = keymap[index].keycode;
* If is there extra space, returns KEY_RESERVED, if (ke->keycode == KEY_UNKNOWN)
* otherwise, input core won't let legacy_dvb_usb_setkeycode ke->keycode = KEY_RESERVED;
* to work ke->len = sizeof(keymap[index].scancode);
*/ memcpy(&ke->scancode, &keymap[index].scancode, ke->len);
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) ke->index = index;
if (keymap[i].keycode == KEY_RESERVED ||
keymap[i].keycode == KEY_UNKNOWN) {
*keycode = KEY_RESERVED;
return 0;
}
return -EINVAL; return 0;
} }
static int legacy_dvb_usb_setkeycode(struct input_dev *dev, static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int keycode) const struct input_keymap_entry *ke,
unsigned int *old_keycode)
{ {
struct dvb_usb_device *d = input_get_drvdata(dev); struct dvb_usb_device *d = input_get_drvdata(dev);
struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
int i; unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
unsigned int index;
/* Search if it is replacing an existing keycode */
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
if (keymap[i].scancode == scancode) {
keymap[i].keycode = keycode;
return 0;
}
/* Search if is there a clean entry. If so, use it */
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
if (keymap[i].keycode == KEY_RESERVED ||
keymap[i].keycode == KEY_UNKNOWN) {
keymap[i].scancode = scancode;
keymap[i].keycode = keycode;
return 0;
}
index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size);
/* /*
* FIXME: Currently, it is not possible to increase the size of * FIXME: Currently, it is not possible to increase the size of
* scancode table. For it to happen, one possibility * scancode table. For it to happen, one possibility
...@@ -69,8 +80,24 @@ static int legacy_dvb_usb_setkeycode(struct input_dev *dev, ...@@ -69,8 +80,24 @@ static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
* copying data, appending the new key on it, and freeing * copying data, appending the new key on it, and freeing
* the old one - or maybe just allocating some spare space * the old one - or maybe just allocating some spare space
*/ */
if (index >= keymap_size)
return -EINVAL;
*old_keycode = keymap[index].keycode;
keymap->keycode = ke->keycode;
__set_bit(ke->keycode, dev->keybit);
if (*old_keycode != KEY_RESERVED) {
__clear_bit(*old_keycode, dev->keybit);
for (index = 0; index < keymap_size; index++) {
if (keymap[index].keycode == *old_keycode) {
__set_bit(*old_keycode, dev->keybit);
break;
}
}
}
return -EINVAL; return 0;
} }
/* Remote-control poll function - called every dib->rc_query_interval ms to see /* Remote-control poll function - called every dib->rc_query_interval ms to see
...@@ -171,8 +198,8 @@ static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d) ...@@ -171,8 +198,8 @@ static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d)
d->input_dev = input_dev; d->input_dev = input_dev;
d->rc_dev = NULL; d->rc_dev = NULL;
input_dev->getkeycode = legacy_dvb_usb_getkeycode; input_dev->getkeycode_new = legacy_dvb_usb_getkeycode;
input_dev->setkeycode = legacy_dvb_usb_setkeycode; input_dev->setkeycode_new = legacy_dvb_usb_setkeycode;
/* set the bits for the keys */ /* set the bits for the keys */
deb_rc("key map size: %d\n", d->props.rc.legacy.rc_map_size); deb_rc("key map size: %d\n", d->props.rc.legacy.rc_map_size);
......
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