Commit 64921670 authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] dvb_usb_v2: remote controller

* remove old legacy code totally
* move default RC keymap definition the the (struct dvb_usb_driver_info)
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 43402bbd
...@@ -62,24 +62,10 @@ ...@@ -62,24 +62,10 @@
struct dvb_usb_driver_info { struct dvb_usb_driver_info {
const char *name; const char *name;
const char *rc_map;
const struct dvb_usb_device_properties *props; const struct dvb_usb_device_properties *props;
}; };
static inline u8 rc5_custom(struct rc_map_table *key)
{
return (key->scancode >> 8) & 0xff;
}
static inline u8 rc5_data(struct rc_map_table *key)
{
return key->scancode & 0xff;
}
static inline u16 rc5_scan(struct rc_map_table *key)
{
return key->scancode & 0xffff;
}
struct dvb_usb_device; struct dvb_usb_device;
struct dvb_usb_adapter; struct dvb_usb_adapter;
struct usb_data_stream; struct usb_data_stream;
...@@ -160,25 +146,6 @@ struct dvb_usb_adapter_properties { ...@@ -160,25 +146,6 @@ struct dvb_usb_adapter_properties {
struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP]; struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
}; };
/**
* struct dvb_rc_legacy - old properties of remote controller
* @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
* remote control handling).
* @rc_map_size: number of items in @rc_map_table.
* @rc_query: called to query an event event.
* @rc_interval: time in ms between two queries.
*/
struct dvb_rc_legacy {
/* remote control properties */
#define REMOTE_NO_KEY_PRESSED 0x00
#define REMOTE_KEY_PRESSED 0x01
#define REMOTE_KEY_REPEAT 0x02
struct rc_map_table *rc_map_table;
int rc_map_size;
int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
int rc_interval;
};
/** /**
* struct dvb_rc properties of remote controller, using rc-core * struct dvb_rc properties of remote controller, using rc-core
* @rc_codes: name of rc codes table * @rc_codes: name of rc codes table
...@@ -202,17 +169,6 @@ struct dvb_rc { ...@@ -202,17 +169,6 @@ struct dvb_rc {
bool bulk_mode; /* uses bulk mode */ bool bulk_mode; /* uses bulk mode */
}; };
/**
* enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
* based on rc-core
* This is initialized/used only inside dvb-usb-remote.c.
* It shouldn't be set by the drivers.
*/
enum dvb_usb_mode {
DVB_RC_LEGACY,
DVB_RC_CORE,
};
/** /**
* struct dvb_usb_device_properties - properties of a dvb-usb-device * struct dvb_usb_device_properties - properties of a dvb-usb-device
* @owner: owner of the dvb_adapter * @owner: owner of the dvb_adapter
...@@ -283,16 +239,12 @@ struct dvb_usb_device_properties { ...@@ -283,16 +239,12 @@ struct dvb_usb_device_properties {
int (*identify_state) (struct dvb_usb_device *); int (*identify_state) (struct dvb_usb_device *);
int (*init) (struct dvb_usb_device *); int (*init) (struct dvb_usb_device *);
struct {
enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */
struct dvb_rc_legacy legacy;
struct dvb_rc core;
} rc;
struct i2c_algorithm *i2c_algo; struct i2c_algorithm *i2c_algo;
int generic_bulk_ctrl_endpoint; int generic_bulk_ctrl_endpoint;
int generic_bulk_ctrl_endpoint_response; int generic_bulk_ctrl_endpoint_response;
struct dvb_rc rc;
}; };
/** /**
...@@ -419,7 +371,7 @@ struct dvb_usb_adapter { ...@@ -419,7 +371,7 @@ struct dvb_usb_adapter {
struct dvb_usb_device { struct dvb_usb_device {
struct dvb_usb_device_properties props; struct dvb_usb_device_properties props;
const char *name; const char *name;
const char *rc_map;
struct usb_device *udev; struct usb_device *udev;
#define DVB_USB_STATE_INIT 0x000 #define DVB_USB_STATE_INIT 0x000
...@@ -460,10 +412,6 @@ extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, ...@@ -460,10 +412,6 @@ extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,
int); int);
extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16); extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
/* commonly used remote control parsing */
extern int dvb_usbv2_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *,
int *);
/* commonly used firmware download types and function */ /* commonly used firmware download types and function */
struct hexline { struct hexline {
u8 len; u8 len;
......
...@@ -259,6 +259,7 @@ int dvb_usbv2_device_init(struct usb_interface *intf, ...@@ -259,6 +259,7 @@ int dvb_usbv2_device_init(struct usb_interface *intf,
d->udev = udev; d->udev = udev;
d->name = driver_info->name; d->name = driver_info->name;
d->rc_map = driver_info->rc_map;
memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties)); memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties));
if (d->props.size_of_priv > 0) { if (d->props.size_of_priv > 0) {
......
...@@ -9,200 +9,6 @@ ...@@ -9,200 +9,6 @@
#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,
struct input_keymap_entry *ke)
{
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);
if (index >= keymap_size)
return -EINVAL;
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;
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
* scancode table. For it to happen, one possibility
* would be to allocate a table with key_map_size + 1,
* copying data, appending the new key on it, and freeing
* 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 0;
}
/* Remote-control poll function - called every dib->rc_query_interval ms to see
* whether the remote control has received anything.
*
* TODO: Fix the repeat rate of the input device.
*/
static void legacy_dvb_usb_read_remote_control(struct work_struct *work)
{
struct dvb_usb_device *d =
container_of(work, struct dvb_usb_device, rc_query_work.work);
u32 event;
int state;
/* TODO: need a lock here. We can simply skip checking for the remote
control if we're busy. */
/* when the parameter has been set to 1 via sysfs while the driver
was running */
if (dvb_usb_disable_rc_polling)
return;
if (d->props.rc.legacy.rc_query(d, &event, &state)) {
err("error while querying for an remote control event.");
goto schedule;
}
switch (state) {
case REMOTE_NO_KEY_PRESSED:
break;
case REMOTE_KEY_PRESSED:
deb_rc("key pressed\n");
d->last_event = event;
case REMOTE_KEY_REPEAT:
deb_rc("key repeated\n");
input_event(d->input_dev, EV_KEY, event, 1);
input_sync(d->input_dev);
input_event(d->input_dev, EV_KEY, d->last_event, 0);
input_sync(d->input_dev);
break;
default:
break;
}
schedule:
schedule_delayed_work(&d->rc_query_work,
msecs_to_jiffies(d->props.rc.legacy.rc_interval));
}
static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d)
{
int i, err, rc_interval;
struct input_dev *input_dev;
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
input_dev->evbit[0] = BIT_MASK(EV_KEY);
input_dev->name = "IR-receiver inside an USB DVB receiver";
input_dev->phys = d->rc_phys;
usb_to_input_id(d->udev, &input_dev->id);
input_dev->dev.parent = &d->udev->dev;
d->input_dev = input_dev;
d->rc_dev = NULL;
input_dev->getkeycode = legacy_dvb_usb_getkeycode;
input_dev->setkeycode = legacy_dvb_usb_setkeycode;
/* set the bits for the keys */
deb_rc("key map size: %d\n", d->props.rc.legacy.rc_map_size);
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
deb_rc("setting bit for event %d item %d\n",
d->props.rc.legacy.rc_map_table[i].keycode, i);
set_bit(d->props.rc.legacy.rc_map_table[i].keycode,
input_dev->keybit);
}
/* setting these two values to non-zero, we have to manage key
repeats */
input_dev->rep[REP_PERIOD] = d->props.rc.legacy.rc_interval;
input_dev->rep[REP_DELAY] = d->props.rc.legacy.rc_interval + 150;
input_set_drvdata(input_dev, d);
err = input_register_device(input_dev);
if (err)
input_free_device(input_dev);
rc_interval = d->props.rc.legacy.rc_interval;
INIT_DELAYED_WORK(&d->rc_query_work,
legacy_dvb_usb_read_remote_control);
info("schedule remote query interval to %d msecs.", rc_interval);
schedule_delayed_work(&d->rc_query_work,
msecs_to_jiffies(rc_interval));
d->state |= DVB_USB_STATE_REMOTE;
return err;
}
/* 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
* whether the remote control has received anything. * whether the remote control has received anything.
* *
...@@ -220,16 +26,16 @@ static void dvb_usb_read_remote_control(struct work_struct *work) ...@@ -220,16 +26,16 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
/* when the parameter has been set to 1 via sysfs while the /* when the parameter has been set to 1 via sysfs while the
* driver was running, or when bulk mode is enabled after IR init * driver was running, or when bulk mode is enabled after IR init
*/ */
if (dvb_usb_disable_rc_polling || d->props.rc.core.bulk_mode) if (dvb_usb_disable_rc_polling || d->props.rc.bulk_mode)
return; return;
err = d->props.rc.core.rc_query(d); err = d->props.rc.rc_query(d);
if (err) if (err)
err("error %d while querying for an remote control event.", err("error %d while querying for an remote control event.",
err); err);
schedule_delayed_work(&d->rc_query_work, schedule_delayed_work(&d->rc_query_work,
msecs_to_jiffies(d->props.rc.core.rc_interval)); msecs_to_jiffies(d->props.rc.rc_interval));
} }
static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d) static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d)
...@@ -241,17 +47,21 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d) ...@@ -241,17 +47,21 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d)
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
dev->driver_name = d->props.rc.core.module_name; dev->driver_name = d->props.rc.module_name;
dev->map_name = d->props.rc.core.rc_codes; dev->map_name = d->rc_map;
dev->change_protocol = d->props.rc.core.change_protocol; dev->change_protocol = d->props.rc.change_protocol;
dev->allowed_protos = d->props.rc.core.allowed_protos; dev->allowed_protos = d->props.rc.allowed_protos;
dev->driver_type = d->props.rc.core.driver_type; dev->driver_type = d->props.rc.driver_type;
usb_to_input_id(d->udev, &dev->input_id); usb_to_input_id(d->udev, &dev->input_id);
dev->input_name = "IR-receiver inside an USB DVB receiver"; dev->input_name = "IR-receiver inside an USB DVB receiver";
dev->input_phys = d->rc_phys; dev->input_phys = d->rc_phys;
dev->dev.parent = &d->udev->dev; dev->dev.parent = &d->udev->dev;
dev->priv = d; dev->priv = d;
/* leave remote controller enabled even there is no default map */
if (dev->map_name == NULL)
dev->map_name = RC_MAP_EMPTY;
err = rc_register_device(dev); err = rc_register_device(dev);
if (err < 0) { if (err < 0) {
rc_free_device(dev); rc_free_device(dev);
...@@ -261,13 +71,13 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d) ...@@ -261,13 +71,13 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d)
d->input_dev = NULL; d->input_dev = NULL;
d->rc_dev = dev; d->rc_dev = dev;
if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode) if (!d->props.rc.rc_query || d->props.rc.bulk_mode)
return 0; return 0;
/* Polling mode - initialize a work queue for handling it */ /* Polling mode - initialize a work queue for handling it */
INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control); INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control);
rc_interval = d->props.rc.core.rc_interval; rc_interval = d->props.rc.rc_interval;
info("schedule remote query interval to %d msecs.", rc_interval); info("schedule remote query interval to %d msecs.", rc_interval);
schedule_delayed_work(&d->rc_query_work, schedule_delayed_work(&d->rc_query_work,
...@@ -283,24 +93,14 @@ int dvb_usb_remote_init(struct dvb_usb_device *d) ...@@ -283,24 +93,14 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
if (dvb_usb_disable_rc_polling) if (dvb_usb_disable_rc_polling)
return 0; return 0;
if (d->props.rc.legacy.rc_map_table && d->props.rc.legacy.rc_query) if (d->props.rc.module_name == NULL)
d->props.rc.mode = DVB_RC_LEGACY;
else if (d->props.rc.core.rc_codes)
d->props.rc.mode = DVB_RC_CORE;
else
return 0; return 0;
usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
/* Start the remote-control polling. */ /* Start the remote-control polling. */
if (d->props.rc.legacy.rc_interval < 40) err = rc_core_dvb_usb_remote_init(d);
d->props.rc.legacy.rc_interval = 100; /* default */
if (d->props.rc.mode == DVB_RC_LEGACY)
err = legacy_dvb_usb_remote_init(d);
else
err = rc_core_dvb_usb_remote_init(d);
if (err) if (err)
return err; return err;
...@@ -313,52 +113,8 @@ int dvb_usb_remote_exit(struct dvb_usb_device *d) ...@@ -313,52 +113,8 @@ int dvb_usb_remote_exit(struct dvb_usb_device *d)
{ {
if (d->state & DVB_USB_STATE_REMOTE) { if (d->state & DVB_USB_STATE_REMOTE) {
cancel_delayed_work_sync(&d->rc_query_work); cancel_delayed_work_sync(&d->rc_query_work);
if (d->props.rc.mode == DVB_RC_LEGACY) rc_unregister_device(d->rc_dev);
input_unregister_device(d->input_dev);
else
rc_unregister_device(d->rc_dev);
} }
d->state &= ~DVB_USB_STATE_REMOTE; d->state &= ~DVB_USB_STATE_REMOTE;
return 0; return 0;
} }
#define DVB_USB_RC_NEC_EMPTY 0x00
#define DVB_USB_RC_NEC_KEY_PRESSED 0x01
#define DVB_USB_RC_NEC_KEY_REPEATED 0x02
int dvb_usbv2_nec_rc_key_to_event(struct dvb_usb_device *d,
u8 keybuf[5], u32 *event, int *state)
{
int i;
struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
*event = 0;
*state = REMOTE_NO_KEY_PRESSED;
switch (keybuf[0]) {
case DVB_USB_RC_NEC_EMPTY:
break;
case DVB_USB_RC_NEC_KEY_PRESSED:
if ((u8) ~keybuf[1] != keybuf[2] ||
(u8) ~keybuf[3] != keybuf[4]) {
deb_err("remote control checksum failed.\n");
break;
}
/* See if we can match the raw key code. */
for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
if (rc5_custom(&keymap[i]) == keybuf[1] &&
rc5_data(&keymap[i]) == keybuf[3]) {
*event = keymap[i].keycode;
*state = REMOTE_KEY_PRESSED;
return 0;
}
deb_err("key mapping failed - no appropriate key found in" \
" keymapping\n");
break;
case DVB_USB_RC_NEC_KEY_REPEATED:
*state = REMOTE_KEY_REPEAT;
break;
default:
deb_err("unknown type of remote status: %d\n", keybuf[0]);
break;
}
return 0;
}
EXPORT_SYMBOL(dvb_usbv2_nec_rc_key_to_event);
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