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 int legacy_dvb_usb_getkeycode(struct input_dev *dev, static unsigned int
unsigned int scancode, unsigned int *keycode) legacy_dvb_usb_get_keymap_index(const struct input_keymap_entry *ke,
struct rc_map_table *keymap,
unsigned int keymap_size)
{ {
struct dvb_usb_device *d = input_get_drvdata(dev); unsigned int index;
unsigned int scancode;
struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table; if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
int i; index = ke->index;
} else {
if (input_scancode_to_scalar(ke, &scancode))
return keymap_size;
/* See if we can match the raw key code. */ /* See if we can match the raw key code. */
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) for (index = 0; index < keymap_size; index++)
if (keymap[i].scancode == scancode) { if (keymap[index].scancode == scancode)
*keycode = keymap[i].keycode; break;
return 0;
}
/* /* See if there is an unused hole in the map */
* If is there extra space, returns KEY_RESERVED, if (index >= keymap_size) {
* otherwise, input core won't let legacy_dvb_usb_setkeycode for (index = 0; index < keymap_size; index++) {
* to work if (keymap[index].keycode == KEY_RESERVED ||
*/ keymap[index].keycode == KEY_UNKNOWN) {
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) break;
if (keymap[i].keycode == KEY_RESERVED || }
keymap[i].keycode == KEY_UNKNOWN) { }
*keycode = KEY_RESERVED; }
return 0;
} }
return -EINVAL; return index;
} }
static int legacy_dvb_usb_setkeycode(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;
/* Search if it is replacing an existing keycode */ 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;
keymap[i].keycode = keycode;
return 0; ke->keycode = keymap[index].keycode;
} if (ke->keycode == KEY_UNKNOWN)
ke->keycode = KEY_RESERVED;
ke->len = sizeof(keymap[index].scancode);
memcpy(&ke->scancode, &keymap[index].scancode, ke->len);
ke->index = index;
/* 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; return 0;
} }
static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
const struct input_keymap_entry *ke,
unsigned int *old_keycode)
{
struct dvb_usb_device *d = input_get_drvdata(dev);
struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
unsigned int index;
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; 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 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