Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 1 | /* dvb-usb-remote.c is part of the DVB USB library. |
| 2 | * |
Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 3 | * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 4 | * see dvb-usb-init.c for copyright information. |
| 5 | * |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 6 | * This file contains functions for initializing the input-device and for handling remote-control-queries. |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 7 | */ |
| 8 | #include "dvb-usb-common.h" |
Unai Uribarri | 4fcd7d8 | 2006-08-27 23:01:24 -0300 | [diff] [blame] | 9 | #include <linux/usb/input.h> |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 10 | |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 11 | static int legacy_dvb_usb_getkeycode(struct input_dev *dev, |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 12 | unsigned int scancode, unsigned int *keycode) |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 13 | { |
| 14 | struct dvb_usb_device *d = input_get_drvdata(dev); |
| 15 | |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 16 | struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 17 | int i; |
| 18 | |
| 19 | /* See if we can match the raw key code. */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 20 | for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) |
Mauro Carvalho Chehab | 34abf21 | 2010-07-31 11:24:57 -0300 | [diff] [blame] | 21 | if (keymap[i].scancode == scancode) { |
| 22 | *keycode = keymap[i].keycode; |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 23 | return 0; |
| 24 | } |
Mauro Carvalho Chehab | a4c1cbc | 2009-08-29 22:03:47 -0300 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * If is there extra space, returns KEY_RESERVED, |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 28 | * otherwise, input core won't let legacy_dvb_usb_setkeycode |
Mauro Carvalho Chehab | a4c1cbc | 2009-08-29 22:03:47 -0300 | [diff] [blame] | 29 | * to work |
| 30 | */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 31 | for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) |
Mauro Carvalho Chehab | 34abf21 | 2010-07-31 11:24:57 -0300 | [diff] [blame] | 32 | if (keymap[i].keycode == KEY_RESERVED || |
| 33 | keymap[i].keycode == KEY_UNKNOWN) { |
Mauro Carvalho Chehab | a4c1cbc | 2009-08-29 22:03:47 -0300 | [diff] [blame] | 34 | *keycode = KEY_RESERVED; |
| 35 | return 0; |
| 36 | } |
| 37 | |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 38 | return -EINVAL; |
| 39 | } |
| 40 | |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 41 | static int legacy_dvb_usb_setkeycode(struct input_dev *dev, |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 42 | unsigned int scancode, unsigned int keycode) |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 43 | { |
| 44 | struct dvb_usb_device *d = input_get_drvdata(dev); |
| 45 | |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 46 | struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 47 | int i; |
| 48 | |
| 49 | /* Search if it is replacing an existing keycode */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 50 | for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) |
Mauro Carvalho Chehab | 34abf21 | 2010-07-31 11:24:57 -0300 | [diff] [blame] | 51 | if (keymap[i].scancode == scancode) { |
| 52 | keymap[i].keycode = keycode; |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | /* Search if is there a clean entry. If so, use it */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 57 | for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) |
Mauro Carvalho Chehab | 34abf21 | 2010-07-31 11:24:57 -0300 | [diff] [blame] | 58 | if (keymap[i].keycode == KEY_RESERVED || |
| 59 | keymap[i].keycode == KEY_UNKNOWN) { |
| 60 | keymap[i].scancode = scancode; |
| 61 | keymap[i].keycode = keycode; |
Mauro Carvalho Chehab | b77f0a7 | 2009-08-29 15:27:29 -0300 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * FIXME: Currently, it is not possible to increase the size of |
| 67 | * scancode table. For it to happen, one possibility |
| 68 | * would be to allocate a table with key_map_size + 1, |
| 69 | * copying data, appending the new key on it, and freeing |
| 70 | * the old one - or maybe just allocating some spare space |
| 71 | */ |
| 72 | |
| 73 | return -EINVAL; |
| 74 | } |
| 75 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 76 | /* Remote-control poll function - called every dib->rc_query_interval ms to see |
| 77 | * whether the remote control has received anything. |
| 78 | * |
| 79 | * TODO: Fix the repeat rate of the input device. |
| 80 | */ |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 81 | static void legacy_dvb_usb_read_remote_control(struct work_struct *work) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 82 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 83 | struct dvb_usb_device *d = |
| 84 | container_of(work, struct dvb_usb_device, rc_query_work.work); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 85 | u32 event; |
| 86 | int state; |
| 87 | |
| 88 | /* TODO: need a lock here. We can simply skip checking for the remote control |
| 89 | if we're busy. */ |
| 90 | |
Patrick Boettcher | c9b06fa | 2005-07-07 17:58:11 -0700 | [diff] [blame] | 91 | /* when the parameter has been set to 1 via sysfs while the driver was running */ |
| 92 | if (dvb_usb_disable_rc_polling) |
| 93 | return; |
| 94 | |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 95 | if (d->props.rc.legacy.rc_query(d,&event,&state)) { |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 96 | err("error while querying for an remote control event."); |
| 97 | goto schedule; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | switch (state) { |
| 102 | case REMOTE_NO_KEY_PRESSED: |
| 103 | break; |
| 104 | case REMOTE_KEY_PRESSED: |
| 105 | deb_rc("key pressed\n"); |
| 106 | d->last_event = event; |
| 107 | case REMOTE_KEY_REPEAT: |
| 108 | deb_rc("key repeated\n"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 109 | input_event(d->input_dev, EV_KEY, event, 1); |
| 110 | input_sync(d->input_dev); |
| 111 | input_event(d->input_dev, EV_KEY, d->last_event, 0); |
| 112 | input_sync(d->input_dev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 113 | break; |
| 114 | default: |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | /* improved repeat handling ??? |
| 119 | switch (state) { |
| 120 | case REMOTE_NO_KEY_PRESSED: |
| 121 | deb_rc("NO KEY PRESSED\n"); |
| 122 | if (d->last_state != REMOTE_NO_KEY_PRESSED) { |
| 123 | deb_rc("releasing event %d\n",d->last_event); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 124 | input_event(d->rc_input_dev, EV_KEY, d->last_event, 0); |
| 125 | input_sync(d->rc_input_dev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 126 | } |
| 127 | d->last_state = REMOTE_NO_KEY_PRESSED; |
| 128 | d->last_event = 0; |
| 129 | break; |
| 130 | case REMOTE_KEY_PRESSED: |
| 131 | deb_rc("KEY PRESSED\n"); |
| 132 | deb_rc("pressing event %d\n",event); |
| 133 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 134 | input_event(d->rc_input_dev, EV_KEY, event, 1); |
| 135 | input_sync(d->rc_input_dev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 136 | |
| 137 | d->last_event = event; |
| 138 | d->last_state = REMOTE_KEY_PRESSED; |
| 139 | break; |
| 140 | case REMOTE_KEY_REPEAT: |
| 141 | deb_rc("KEY_REPEAT\n"); |
| 142 | if (d->last_state != REMOTE_NO_KEY_PRESSED) { |
| 143 | deb_rc("repeating event %d\n",d->last_event); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 144 | input_event(d->rc_input_dev, EV_KEY, d->last_event, 2); |
| 145 | input_sync(d->rc_input_dev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 146 | d->last_state = REMOTE_KEY_REPEAT; |
| 147 | } |
| 148 | default: |
| 149 | break; |
| 150 | } |
| 151 | */ |
| 152 | |
| 153 | schedule: |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 154 | schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc.legacy.rc_interval)); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 155 | } |
| 156 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 157 | static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d) |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 158 | { |
| 159 | int i, err, rc_interval; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 160 | struct input_dev *input_dev; |
| 161 | |
| 162 | input_dev = input_allocate_device(); |
| 163 | if (!input_dev) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | input_dev->evbit[0] = BIT_MASK(EV_KEY); |
| 167 | input_dev->name = "IR-receiver inside an USB DVB receiver"; |
| 168 | input_dev->phys = d->rc_phys; |
| 169 | usb_to_input_id(d->udev, &input_dev->id); |
| 170 | input_dev->dev.parent = &d->udev->dev; |
| 171 | d->input_dev = input_dev; |
| 172 | d->rc_dev = NULL; |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 173 | |
| 174 | input_dev->getkeycode = legacy_dvb_usb_getkeycode; |
| 175 | input_dev->setkeycode = legacy_dvb_usb_setkeycode; |
| 176 | |
| 177 | /* set the bits for the keys */ |
| 178 | deb_rc("key map size: %d\n", d->props.rc.legacy.rc_key_map_size); |
| 179 | for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { |
| 180 | deb_rc("setting bit for event %d item %d\n", |
| 181 | d->props.rc.legacy.rc_key_map[i].keycode, i); |
| 182 | set_bit(d->props.rc.legacy.rc_key_map[i].keycode, input_dev->keybit); |
| 183 | } |
| 184 | |
| 185 | /* setting these two values to non-zero, we have to manage key repeats */ |
| 186 | input_dev->rep[REP_PERIOD] = d->props.rc.legacy.rc_interval; |
| 187 | input_dev->rep[REP_DELAY] = d->props.rc.legacy.rc_interval + 150; |
| 188 | |
| 189 | input_set_drvdata(input_dev, d); |
| 190 | |
| 191 | err = input_register_device(input_dev); |
| 192 | if (err) |
| 193 | input_free_device(input_dev); |
| 194 | |
| 195 | rc_interval = d->props.rc.legacy.rc_interval; |
| 196 | |
| 197 | INIT_DELAYED_WORK(&d->rc_query_work, legacy_dvb_usb_read_remote_control); |
| 198 | |
| 199 | info("schedule remote query interval to %d msecs.", rc_interval); |
| 200 | schedule_delayed_work(&d->rc_query_work, |
| 201 | msecs_to_jiffies(rc_interval)); |
| 202 | |
| 203 | d->state |= DVB_USB_STATE_REMOTE; |
| 204 | |
| 205 | return err; |
| 206 | } |
| 207 | |
| 208 | /* Remote-control poll function - called every dib->rc_query_interval ms to see |
| 209 | * whether the remote control has received anything. |
| 210 | * |
| 211 | * TODO: Fix the repeat rate of the input device. |
| 212 | */ |
| 213 | static void dvb_usb_read_remote_control(struct work_struct *work) |
| 214 | { |
| 215 | struct dvb_usb_device *d = |
| 216 | container_of(work, struct dvb_usb_device, rc_query_work.work); |
| 217 | int err; |
| 218 | |
| 219 | /* TODO: need a lock here. We can simply skip checking for the remote control |
| 220 | if we're busy. */ |
| 221 | |
| 222 | /* when the parameter has been set to 1 via sysfs while the |
| 223 | * driver was running, or when bulk mode is enabled after IR init |
| 224 | */ |
| 225 | if (dvb_usb_disable_rc_polling || d->props.rc.core.bulk_mode) |
| 226 | return; |
| 227 | |
| 228 | err = d->props.rc.core.rc_query(d); |
| 229 | if (err) |
| 230 | err("error %d while querying for an remote control event.", err); |
| 231 | |
| 232 | schedule_delayed_work(&d->rc_query_work, |
| 233 | msecs_to_jiffies(d->props.rc.core.rc_interval)); |
| 234 | } |
| 235 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 236 | static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d) |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 237 | { |
| 238 | int err, rc_interval; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 239 | struct rc_dev *dev; |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 240 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 241 | dev = rc_allocate_device(); |
| 242 | if (!dev) |
| 243 | return -ENOMEM; |
| 244 | |
| 245 | dev->driver_name = d->props.rc.core.module_name; |
| 246 | dev->map_name = d->props.rc.core.rc_codes; |
| 247 | dev->change_protocol = d->props.rc.core.change_protocol; |
| 248 | dev->allowed_protos = d->props.rc.core.allowed_protos; |
| 249 | dev->driver_type = RC_DRIVER_SCANCODE; |
| 250 | usb_to_input_id(d->udev, &dev->input_id); |
| 251 | dev->input_name = "IR-receiver inside an USB DVB receiver"; |
| 252 | dev->input_phys = d->rc_phys; |
| 253 | dev->dev.parent = &d->udev->dev; |
| 254 | dev->priv = d; |
| 255 | |
| 256 | err = rc_register_device(dev); |
| 257 | if (err < 0) { |
| 258 | rc_free_device(dev); |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 259 | return err; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | d->input_dev = NULL; |
| 263 | d->rc_dev = dev; |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 264 | |
| 265 | if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode) |
| 266 | return 0; |
| 267 | |
| 268 | /* Polling mode - initialize a work queue for handling it */ |
| 269 | INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control); |
| 270 | |
| 271 | rc_interval = d->props.rc.core.rc_interval; |
| 272 | |
| 273 | info("schedule remote query interval to %d msecs.", rc_interval); |
| 274 | schedule_delayed_work(&d->rc_query_work, |
| 275 | msecs_to_jiffies(rc_interval)); |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 280 | int dvb_usb_remote_init(struct dvb_usb_device *d) |
| 281 | { |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 282 | int err; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 283 | |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 284 | if (dvb_usb_disable_rc_polling) |
| 285 | return 0; |
| 286 | |
| 287 | if (d->props.rc.legacy.rc_key_map && d->props.rc.legacy.rc_query) |
| 288 | d->props.rc.mode = DVB_RC_LEGACY; |
| 289 | else if (d->props.rc.core.rc_codes) |
| 290 | d->props.rc.mode = DVB_RC_CORE; |
| 291 | else |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 292 | return 0; |
| 293 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 294 | usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); |
Unai Uribarri | 4fcd7d8 | 2006-08-27 23:01:24 -0300 | [diff] [blame] | 295 | strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 296 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 297 | /* Start the remote-control polling. */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 298 | if (d->props.rc.legacy.rc_interval < 40) |
| 299 | d->props.rc.legacy.rc_interval = 100; /* default */ |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 300 | |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 301 | if (d->props.rc.mode == DVB_RC_LEGACY) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 302 | err = legacy_dvb_usb_remote_init(d); |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 303 | else |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 304 | err = rc_core_dvb_usb_remote_init(d); |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 305 | if (err) |
| 306 | return err; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 307 | |
| 308 | d->state |= DVB_USB_STATE_REMOTE; |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int dvb_usb_remote_exit(struct dvb_usb_device *d) |
| 314 | { |
| 315 | if (d->state & DVB_USB_STATE_REMOTE) { |
Chris Rankin | e1af498 | 2007-02-06 20:29:07 -0300 | [diff] [blame] | 316 | cancel_rearming_delayed_work(&d->rc_query_work); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 317 | flush_scheduled_work(); |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 318 | if (d->props.rc.mode == DVB_RC_LEGACY) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 319 | input_unregister_device(d->input_dev); |
Mauro Carvalho Chehab | 6520342 | 2010-07-31 19:07:55 -0300 | [diff] [blame] | 320 | else |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 321 | rc_unregister_device(d->rc_dev); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 322 | } |
| 323 | d->state &= ~DVB_USB_STATE_REMOTE; |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | #define DVB_USB_RC_NEC_EMPTY 0x00 |
| 328 | #define DVB_USB_RC_NEC_KEY_PRESSED 0x01 |
| 329 | #define DVB_USB_RC_NEC_KEY_REPEATED 0x02 |
| 330 | int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d, |
| 331 | u8 keybuf[5], u32 *event, int *state) |
| 332 | { |
| 333 | int i; |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 334 | struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 335 | *event = 0; |
| 336 | *state = REMOTE_NO_KEY_PRESSED; |
| 337 | switch (keybuf[0]) { |
| 338 | case DVB_USB_RC_NEC_EMPTY: |
| 339 | break; |
| 340 | case DVB_USB_RC_NEC_KEY_PRESSED: |
| 341 | if ((u8) ~keybuf[1] != keybuf[2] || |
| 342 | (u8) ~keybuf[3] != keybuf[4]) { |
| 343 | deb_err("remote control checksum failed.\n"); |
| 344 | break; |
| 345 | } |
| 346 | /* See if we can match the raw key code. */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 347 | for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) |
Mauro Carvalho Chehab | 2e36588 | 2009-08-29 15:19:31 -0300 | [diff] [blame] | 348 | if (rc5_custom(&keymap[i]) == keybuf[1] && |
| 349 | rc5_data(&keymap[i]) == keybuf[3]) { |
Mauro Carvalho Chehab | 34abf21 | 2010-07-31 11:24:57 -0300 | [diff] [blame] | 350 | *event = keymap[i].keycode; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 351 | *state = REMOTE_KEY_PRESSED; |
Patrick Boettcher | 1df896a | 2005-07-07 17:58:24 -0700 | [diff] [blame] | 352 | return 0; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 353 | } |
| 354 | deb_err("key mapping failed - no appropriate key found in keymapping\n"); |
| 355 | break; |
| 356 | case DVB_USB_RC_NEC_KEY_REPEATED: |
| 357 | *state = REMOTE_KEY_REPEAT; |
| 358 | break; |
| 359 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 360 | deb_err("unknown type of remote status: %d\n",keybuf[0]); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 361 | break; |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | EXPORT_SYMBOL(dvb_usb_nec_rc_key_to_event); |