]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/media/IR/ir-keytable.c
V4L/DVB: Don't identify PV SBTVD Hybrid as a DibCom device
[net-next-2.6.git] / drivers / media / IR / ir-keytable.c
CommitLineData
dd3f616d 1/* ir-keytable.c - handle IR scancode->keycode tables
ef53a115
MCC
2 *
3 * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
446e4a64
MCC
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
ef53a115
MCC
13 */
14
ef53a115 15
882ead32 16#include <linux/input.h>
5a0e3ad6 17#include <linux/slab.h>
3f113e36 18#include "ir-core-priv.h"
ef53a115 19
b3074c0a
DH
20/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
21#define IR_TAB_MIN_SIZE 256
22#define IR_TAB_MAX_SIZE 8192
f6fc5049 23
a374fef4
DH
24/* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */
25#define IR_KEYPRESS_TIMEOUT 250
26
7fee03e4 27/**
b3074c0a
DH
28 * ir_resize_table() - resizes a scancode table if necessary
29 * @rc_tab: the ir_scancode_table to resize
30 * @return: zero on success or a negative error code
7fee03e4 31 *
b3074c0a
DH
32 * This routine will shrink the ir_scancode_table if it has lots of
33 * unused entries and grow it if it is full.
7fee03e4 34 */
b3074c0a 35static int ir_resize_table(struct ir_scancode_table *rc_tab)
7fee03e4 36{
b3074c0a
DH
37 unsigned int oldalloc = rc_tab->alloc;
38 unsigned int newalloc = oldalloc;
39 struct ir_scancode *oldscan = rc_tab->scan;
40 struct ir_scancode *newscan;
41
42 if (rc_tab->size == rc_tab->len) {
43 /* All entries in use -> grow keytable */
44 if (rc_tab->alloc >= IR_TAB_MAX_SIZE)
45 return -ENOMEM;
7fee03e4 46
b3074c0a
DH
47 newalloc *= 2;
48 IR_dprintk(1, "Growing table to %u bytes\n", newalloc);
49 }
7fee03e4 50
b3074c0a
DH
51 if ((rc_tab->len * 3 < rc_tab->size) && (oldalloc > IR_TAB_MIN_SIZE)) {
52 /* Less than 1/3 of entries in use -> shrink keytable */
53 newalloc /= 2;
54 IR_dprintk(1, "Shrinking table to %u bytes\n", newalloc);
55 }
7fee03e4 56
b3074c0a
DH
57 if (newalloc == oldalloc)
58 return 0;
7fee03e4 59
b3074c0a
DH
60 newscan = kmalloc(newalloc, GFP_ATOMIC);
61 if (!newscan) {
62 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
63 return -ENOMEM;
64 }
7fee03e4 65
b3074c0a
DH
66 memcpy(newscan, rc_tab->scan, rc_tab->len * sizeof(struct ir_scancode));
67 rc_tab->scan = newscan;
68 rc_tab->alloc = newalloc;
69 rc_tab->size = rc_tab->alloc / sizeof(struct ir_scancode);
70 kfree(oldscan);
71 return 0;
7fee03e4
MCC
72}
73
f6fc5049 74/**
b3074c0a
DH
75 * ir_do_setkeycode() - internal function to set a keycode in the
76 * scancode->keycode table
77 * @dev: the struct input_dev device descriptor
78 * @rc_tab: the struct ir_scancode_table to set the keycode in
79 * @scancode: the scancode for the ir command
80 * @keycode: the keycode for the ir command
42880cd4 81 * @resize: whether the keytable may be shrunk
b3074c0a 82 * @return: -EINVAL if the keycode could not be inserted, otherwise zero.
f6fc5049 83 *
b3074c0a
DH
84 * This routine is used internally to manipulate the scancode->keycode table.
85 * The caller has to hold @rc_tab->lock.
f6fc5049 86 */
b3074c0a
DH
87static int ir_do_setkeycode(struct input_dev *dev,
88 struct ir_scancode_table *rc_tab,
42880cd4
MCC
89 unsigned scancode, unsigned keycode,
90 bool resize)
f6fc5049 91{
b3074c0a
DH
92 unsigned int i;
93 int old_keycode = KEY_RESERVED;
9dfe4e83
MCC
94 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
95
96 /*
97 * Unfortunately, some hardware-based IR decoders don't provide
98 * all bits for the complete IR code. In general, they provide only
99 * the command part of the IR code. Yet, as it is possible to replace
100 * the provided IR with another one, it is needed to allow loading
101 * IR tables from other remotes. So,
102 */
103 if (ir_dev->props && ir_dev->props->scanmask) {
104 scancode &= ir_dev->props->scanmask;
105 }
b3074c0a
DH
106
107 /* First check if we already have a mapping for this ir command */
108 for (i = 0; i < rc_tab->len; i++) {
109 /* Keytable is sorted from lowest to highest scancode */
110 if (rc_tab->scan[i].scancode > scancode)
111 break;
112 else if (rc_tab->scan[i].scancode < scancode)
113 continue;
f6fc5049 114
b3074c0a
DH
115 old_keycode = rc_tab->scan[i].keycode;
116 rc_tab->scan[i].keycode = keycode;
f6fc5049 117
b3074c0a
DH
118 /* Did the user wish to remove the mapping? */
119 if (keycode == KEY_RESERVED || keycode == KEY_UNKNOWN) {
35438946
MCC
120 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
121 i, scancode);
b3074c0a
DH
122 rc_tab->len--;
123 memmove(&rc_tab->scan[i], &rc_tab->scan[i + 1],
124 (rc_tab->len - i) * sizeof(struct ir_scancode));
125 }
f6fc5049 126
b3074c0a
DH
127 /* Possibly shrink the keytable, failure is not a problem */
128 ir_resize_table(rc_tab);
129 break;
130 }
f6fc5049 131
09bd00e7 132 if (old_keycode == KEY_RESERVED && keycode != KEY_RESERVED) {
b3074c0a 133 /* No previous mapping found, we might need to grow the table */
42880cd4 134 if (resize && ir_resize_table(rc_tab))
b3074c0a 135 return -ENOMEM;
7fee03e4 136
35438946
MCC
137 IR_dprintk(1, "#%d: New scan 0x%04x with key 0x%04x\n",
138 i, scancode, keycode);
139
b3074c0a
DH
140 /* i is the proper index to insert our new keycode */
141 memmove(&rc_tab->scan[i + 1], &rc_tab->scan[i],
142 (rc_tab->len - i) * sizeof(struct ir_scancode));
143 rc_tab->scan[i].scancode = scancode;
144 rc_tab->scan[i].keycode = keycode;
145 rc_tab->len++;
146 set_bit(keycode, dev->keybit);
147 } else {
35438946
MCC
148 IR_dprintk(1, "#%d: Replacing scan 0x%04x with key 0x%04x\n",
149 i, scancode, keycode);
b3074c0a
DH
150 /* A previous mapping was updated... */
151 clear_bit(old_keycode, dev->keybit);
152 /* ...but another scancode might use the same keycode */
153 for (i = 0; i < rc_tab->len; i++) {
154 if (rc_tab->scan[i].keycode == old_keycode) {
155 set_bit(old_keycode, dev->keybit);
156 break;
157 }
158 }
f6fc5049 159 }
f6fc5049
MCC
160
161 return 0;
162}
163
ef53a115 164/**
b3074c0a 165 * ir_setkeycode() - set a keycode in the scancode->keycode table
ef53a115
MCC
166 * @dev: the struct input_dev device descriptor
167 * @scancode: the desired scancode
b3074c0a
DH
168 * @keycode: result
169 * @return: -EINVAL if the keycode could not be inserted, otherwise zero.
ef53a115 170 *
b3074c0a 171 * This routine is used to handle evdev EVIOCSKEY ioctl.
ef53a115 172 */
b3074c0a
DH
173static int ir_setkeycode(struct input_dev *dev,
174 unsigned int scancode, unsigned int keycode)
ef53a115 175{
b3074c0a
DH
176 int rc;
177 unsigned long flags;
75543cce
MCC
178 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
179 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
ef53a115 180
b3074c0a 181 spin_lock_irqsave(&rc_tab->lock, flags);
42880cd4 182 rc = ir_do_setkeycode(dev, rc_tab, scancode, keycode, true);
b3074c0a
DH
183 spin_unlock_irqrestore(&rc_tab->lock, flags);
184 return rc;
e97f4677
MCC
185}
186
187/**
b3074c0a
DH
188 * ir_setkeytable() - sets several entries in the scancode->keycode table
189 * @dev: the struct input_dev device descriptor
190 * @to: the struct ir_scancode_table to copy entries to
191 * @from: the struct ir_scancode_table to copy entries from
192 * @return: -EINVAL if all keycodes could not be inserted, otherwise zero.
e97f4677 193 *
b3074c0a 194 * This routine is used to handle table initialization.
e97f4677 195 */
b3074c0a
DH
196static int ir_setkeytable(struct input_dev *dev,
197 struct ir_scancode_table *to,
198 const struct ir_scancode_table *from)
e97f4677 199{
b3074c0a
DH
200 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
201 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
e97f4677 202 unsigned long flags;
b3074c0a
DH
203 unsigned int i;
204 int rc = 0;
e97f4677
MCC
205
206 spin_lock_irqsave(&rc_tab->lock, flags);
b3074c0a
DH
207 for (i = 0; i < from->size; i++) {
208 rc = ir_do_setkeycode(dev, to, from->scan[i].scancode,
42880cd4 209 from->scan[i].keycode, false);
b3074c0a
DH
210 if (rc)
211 break;
e97f4677 212 }
e97f4677 213 spin_unlock_irqrestore(&rc_tab->lock, flags);
b3074c0a 214 return rc;
ef53a115
MCC
215}
216
217/**
b3074c0a 218 * ir_getkeycode() - get a keycode from the scancode->keycode table
ef53a115
MCC
219 * @dev: the struct input_dev device descriptor
220 * @scancode: the desired scancode
b3074c0a
DH
221 * @keycode: used to return the keycode, if found, or KEY_RESERVED
222 * @return: always returns zero.
ef53a115 223 *
b3074c0a 224 * This routine is used to handle evdev EVIOCGKEY ioctl.
ef53a115 225 */
b3074c0a
DH
226static int ir_getkeycode(struct input_dev *dev,
227 unsigned int scancode, unsigned int *keycode)
ef53a115 228{
b3074c0a
DH
229 int start, end, mid;
230 unsigned long flags;
231 int key = KEY_RESERVED;
75543cce
MCC
232 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
233 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
ef53a115 234
b3074c0a
DH
235 spin_lock_irqsave(&rc_tab->lock, flags);
236 start = 0;
237 end = rc_tab->len - 1;
238 while (start <= end) {
239 mid = (start + end) / 2;
240 if (rc_tab->scan[mid].scancode < scancode)
241 start = mid + 1;
242 else if (rc_tab->scan[mid].scancode > scancode)
243 end = mid - 1;
244 else {
245 key = rc_tab->scan[mid].keycode;
246 break;
247 }
e97f4677 248 }
b3074c0a 249 spin_unlock_irqrestore(&rc_tab->lock, flags);
e97f4677 250
35438946
MCC
251 if (key == KEY_RESERVED)
252 IR_dprintk(1, "unknown key for scancode 0x%04x\n",
253 scancode);
254
b3074c0a 255 *keycode = key;
7fee03e4 256 return 0;
ef53a115
MCC
257}
258
259/**
260 * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode
7fee03e4 261 * @input_dev: the struct input_dev descriptor of the device
ef53a115
MCC
262 * @scancode: the scancode that we're seeking
263 *
264 * This routine is used by the input routines when a key is pressed at the
265 * IR. The scancode is received and needs to be converted into a keycode.
6660de56 266 * If the key is not found, it returns KEY_RESERVED. Otherwise, returns the
ef53a115
MCC
267 * corresponding keycode from the table.
268 */
269u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
270{
b3074c0a 271 int keycode;
ef53a115 272
b3074c0a 273 ir_getkeycode(dev, scancode, &keycode);
35438946
MCC
274 if (keycode != KEY_RESERVED)
275 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
276 dev->name, scancode, keycode);
b3074c0a 277 return keycode;
ef53a115 278}
446e4a64 279EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
ef53a115 280
6660de56
MCC
281/**
282 * ir_keyup() - generates input event to cleanup a key press
a374fef4 283 * @ir: the struct ir_input_dev descriptor of the device
6660de56 284 *
a374fef4
DH
285 * This routine is used to signal that a key has been released on the
286 * remote control. It reports a keyup input event via input_report_key().
287 */
288static void ir_keyup(struct ir_input_dev *ir)
289{
290 if (!ir->keypressed)
291 return;
292
293 IR_dprintk(1, "keyup key 0x%04x\n", ir->last_keycode);
294 input_report_key(ir->input_dev, ir->last_keycode, 0);
295 input_sync(ir->input_dev);
296 ir->keypressed = false;
297}
298
299/**
300 * ir_timer_keyup() - generates a keyup event after a timeout
301 * @cookie: a pointer to struct ir_input_dev passed to setup_timer()
302 *
303 * This routine will generate a keyup event some time after a keydown event
304 * is generated when no further activity has been detected.
6660de56 305 */
a374fef4 306static void ir_timer_keyup(unsigned long cookie)
6660de56 307{
a374fef4
DH
308 struct ir_input_dev *ir = (struct ir_input_dev *)cookie;
309 unsigned long flags;
310
311 /*
312 * ir->keyup_jiffies is used to prevent a race condition if a
313 * hardware interrupt occurs at this point and the keyup timer
314 * event is moved further into the future as a result.
315 *
316 * The timer will then be reactivated and this function called
317 * again in the future. We need to exit gracefully in that case
318 * to allow the input subsystem to do its auto-repeat magic or
319 * a keyup event might follow immediately after the keydown.
320 */
321 spin_lock_irqsave(&ir->keylock, flags);
322 if (time_is_after_eq_jiffies(ir->keyup_jiffies))
323 ir_keyup(ir);
324 spin_unlock_irqrestore(&ir->keylock, flags);
325}
326
327/**
328 * ir_repeat() - notifies the IR core that a key is still pressed
329 * @dev: the struct input_dev descriptor of the device
330 *
331 * This routine is used by IR decoders when a repeat message which does
332 * not include the necessary bits to reproduce the scancode has been
333 * received.
334 */
335void ir_repeat(struct input_dev *dev)
336{
337 unsigned long flags;
6660de56
MCC
338 struct ir_input_dev *ir = input_get_drvdata(dev);
339
a374fef4
DH
340 spin_lock_irqsave(&ir->keylock, flags);
341
ed4d3876
ML
342 input_event(dev, EV_MSC, MSC_SCAN, ir->last_scancode);
343
6660de56 344 if (!ir->keypressed)
a374fef4 345 goto out;
6660de56 346
a374fef4
DH
347 ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
348 mod_timer(&ir->timer_keyup, ir->keyup_jiffies);
349
350out:
351 spin_unlock_irqrestore(&ir->keylock, flags);
6660de56 352}
a374fef4 353EXPORT_SYMBOL_GPL(ir_repeat);
6660de56
MCC
354
355/**
356 * ir_keydown() - generates input event for a key press
a374fef4
DH
357 * @dev: the struct input_dev descriptor of the device
358 * @scancode: the scancode that we're seeking
359 * @toggle: the toggle value (protocol dependent, if the protocol doesn't
360 * support toggle values, this should be set to zero)
6660de56
MCC
361 *
362 * This routine is used by the input routines when a key is pressed at the
363 * IR. It gets the keycode for a scancode and reports an input event via
364 * input_report_key().
365 */
a374fef4 366void ir_keydown(struct input_dev *dev, int scancode, u8 toggle)
6660de56 367{
a374fef4 368 unsigned long flags;
6660de56
MCC
369 struct ir_input_dev *ir = input_get_drvdata(dev);
370
371 u32 keycode = ir_g_keycode_from_table(dev, scancode);
372
a374fef4 373 spin_lock_irqsave(&ir->keylock, flags);
6660de56 374
ed4d3876
ML
375 input_event(dev, EV_MSC, MSC_SCAN, scancode);
376
a374fef4
DH
377 /* Repeat event? */
378 if (ir->keypressed &&
379 ir->last_scancode == scancode &&
380 ir->last_toggle == toggle)
381 goto set_timer;
6660de56 382
a374fef4
DH
383 /* Release old keypress */
384 ir_keyup(ir);
6660de56 385
a374fef4
DH
386 ir->last_scancode = scancode;
387 ir->last_toggle = toggle;
388 ir->last_keycode = keycode;
389
ed4d3876 390
a374fef4
DH
391 if (keycode == KEY_RESERVED)
392 goto out;
6660de56 393
ed4d3876 394
a374fef4
DH
395 /* Register a keypress */
396 ir->keypressed = true;
397 IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
398 dev->name, keycode, scancode);
399 input_report_key(dev, ir->last_keycode, 1);
6660de56
MCC
400 input_sync(dev);
401
a374fef4
DH
402set_timer:
403 ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
404 mod_timer(&ir->timer_keyup, ir->keyup_jiffies);
405out:
406 spin_unlock_irqrestore(&ir->keylock, flags);
6660de56
MCC
407}
408EXPORT_SYMBOL_GPL(ir_keydown);
409
716aab44
MCC
410static int ir_open(struct input_dev *input_dev)
411{
412 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
413
414 return ir_dev->props->open(ir_dev->props->priv);
415}
416
417static void ir_close(struct input_dev *input_dev)
418{
419 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
420
421 ir_dev->props->close(ir_dev->props->priv);
422}
6660de56 423
ef53a115 424/**
b2245ba1 425 * __ir_input_register() - sets the IR keycode table and add the handlers
ef53a115
MCC
426 * for keymap table get/set
427 * @input_dev: the struct input_dev descriptor of the device
428 * @rc_tab: the struct ir_scancode_table table of scancode/keymap
429 *
d4b778d3
MCC
430 * This routine is used to initialize the input infrastructure
431 * to work with an IR.
432 * It will register the input/evdev interface for the device and
433 * register the syfs code for IR class
ef53a115 434 */
b2245ba1 435int __ir_input_register(struct input_dev *input_dev,
e93854da 436 const struct ir_scancode_table *rc_tab,
4a702ebf 437 struct ir_dev_props *props,
727e625c 438 const char *driver_name)
ef53a115 439{
75543cce 440 struct ir_input_dev *ir_dev;
b3074c0a 441 int rc;
ef53a115
MCC
442
443 if (rc_tab->scan == NULL || !rc_tab->size)
444 return -EINVAL;
445
75543cce
MCC
446 ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL);
447 if (!ir_dev)
448 return -ENOMEM;
449
b3074c0a
DH
450 ir_dev->driver_name = kasprintf(GFP_KERNEL, "%s", driver_name);
451 if (!ir_dev->driver_name) {
452 rc = -ENOMEM;
453 goto out_dev;
454 }
75543cce 455
b3074c0a
DH
456 input_dev->getkeycode = ir_getkeycode;
457 input_dev->setkeycode = ir_setkeycode;
458 input_set_drvdata(input_dev, ir_dev);
a374fef4 459 ir_dev->input_dev = input_dev;
b3074c0a
DH
460
461 spin_lock_init(&ir_dev->rc_tab.lock);
a374fef4
DH
462 spin_lock_init(&ir_dev->keylock);
463 setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev);
464
9c89a181 465 ir_dev->rc_tab.name = rc_tab->name;
b3074c0a
DH
466 ir_dev->rc_tab.ir_type = rc_tab->ir_type;
467 ir_dev->rc_tab.alloc = roundup_pow_of_two(rc_tab->size *
468 sizeof(struct ir_scancode));
469 ir_dev->rc_tab.scan = kmalloc(ir_dev->rc_tab.alloc, GFP_KERNEL);
470 ir_dev->rc_tab.size = ir_dev->rc_tab.alloc / sizeof(struct ir_scancode);
9dfe4e83
MCC
471 if (props) {
472 ir_dev->props = props;
473 if (props->open)
474 input_dev->open = ir_open;
475 if (props->close)
476 input_dev->close = ir_close;
477 }
b3074c0a 478
8231152f 479 if (!ir_dev->rc_tab.scan) {
b3074c0a
DH
480 rc = -ENOMEM;
481 goto out_name;
8231152f 482 }
75543cce 483
b3074c0a
DH
484 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
485 ir_dev->rc_tab.size, ir_dev->rc_tab.alloc);
486
487 set_bit(EV_KEY, input_dev->evbit);
a374fef4 488 set_bit(EV_REP, input_dev->evbit);
ed4d3876
ML
489 set_bit(EV_MSC, input_dev->evbit);
490 set_bit(MSC_SCAN, input_dev->mscbit);
a374fef4 491
b3074c0a
DH
492 if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
493 rc = -ENOMEM;
494 goto out_table;
495 }
75543cce 496
4714eda8 497 rc = ir_register_class(input_dev);
945cdfa2 498 if (rc < 0)
b3074c0a 499 goto out_table;
579e7d60 500
84b14f18
IL
501 if (ir_dev->props)
502 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) {
503 rc = ir_raw_event_register(input_dev);
504 if (rc < 0)
505 goto out_event;
506 }
626cf697 507
844a9e93
MCC
508 IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
509 driver_name, rc_tab->name,
ede67a30
DC
510 (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ?
511 " in raw mode" : "");
35438946 512
4714eda8
MCC
513 return 0;
514
626cf697
MCC
515out_event:
516 ir_unregister_class(input_dev);
b3074c0a
DH
517out_table:
518 kfree(ir_dev->rc_tab.scan);
519out_name:
520 kfree(ir_dev->driver_name);
521out_dev:
4714eda8 522 kfree(ir_dev);
579e7d60 523 return rc;
ef53a115 524}
b2245ba1 525EXPORT_SYMBOL_GPL(__ir_input_register);
f6fc5049 526
d4b778d3
MCC
527/**
528 * ir_input_unregister() - unregisters IR and frees resources
529 * @input_dev: the struct input_dev descriptor of the device
530
531 * This routine is used to free memory and de-register interfaces.
532 */
626cf697 533void ir_input_unregister(struct input_dev *input_dev)
f6fc5049 534{
626cf697 535 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
579e7d60 536 struct ir_scancode_table *rc_tab;
f6fc5049 537
579e7d60 538 if (!ir_dev)
05395a3d
MCC
539 return;
540
f6fc5049 541 IR_dprintk(1, "Freed keycode table\n");
626cf697 542
a374fef4 543 del_timer_sync(&ir_dev->timer_keyup);
84b14f18
IL
544 if (ir_dev->props)
545 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW)
546 ir_raw_event_unregister(input_dev);
547
579e7d60 548 rc_tab = &ir_dev->rc_tab;
f6fc5049
MCC
549 rc_tab->size = 0;
550 kfree(rc_tab->scan);
551 rc_tab->scan = NULL;
75543cce 552
626cf697 553 ir_unregister_class(input_dev);
4714eda8 554
b3074c0a 555 kfree(ir_dev->driver_name);
75543cce 556 kfree(ir_dev);
f6fc5049 557}
38ef6aa8 558EXPORT_SYMBOL_GPL(ir_input_unregister);
f6fc5049 559
446e4a64
MCC
560int ir_core_debug; /* ir_debug level (0,1,2) */
561EXPORT_SYMBOL_GPL(ir_core_debug);
562module_param_named(debug, ir_core_debug, int, 0644);
563
564MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
565MODULE_LICENSE("GPL");