blob: 161d70b57965d16680dee46b0823ddc6fed10264 [file] [log] [blame]
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -03001/* ir-register.c - handle IR scancode->keycode tables
2 *
3 * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -03004 *
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.
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -030013 */
14
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -030015
Mauro Carvalho Chehab882ead32009-12-29 10:37:38 -030016#include <linux/input.h>
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -030017#include <media/ir-common.h>
18
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030019#define IR_TAB_MIN_SIZE 32
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -030020#define IR_TAB_MAX_SIZE 1024
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030021
22/**
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -030023 * ir_seek_table() - returns the element order on the table
24 * @rc_tab: the ir_scancode_table with the keymap to be used
25 * @scancode: the scancode that we're seeking
26 *
27 * This routine is used by the input routines when a key is pressed at the
28 * IR. The scancode is received and needs to be converted into a keycode.
29 * If the key is not found, it returns KEY_UNKNOWN. Otherwise, returns the
30 * corresponding keycode from the table.
31 */
32static int ir_seek_table(struct ir_scancode_table *rc_tab, u32 scancode)
33{
34 int rc;
35 unsigned long flags;
36 struct ir_scancode *keymap = rc_tab->scan;
37
38 spin_lock_irqsave(&rc_tab->lock, flags);
39
40 /* FIXME: replace it by a binary search */
41
42 for (rc = 0; rc < rc_tab->size; rc++)
43 if (keymap[rc].scancode == scancode)
44 goto exit;
45
46 /* Not found */
47 rc = -EINVAL;
48
49exit:
50 spin_unlock_irqrestore(&rc_tab->lock, flags);
51 return rc;
52}
53
54/**
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030055 * ir_roundup_tablesize() - gets an optimum value for the table size
56 * @n_elems: minimum number of entries to store keycodes
57 *
58 * This routine is used to choose the keycode table size.
59 *
60 * In order to have some empty space for new keycodes,
61 * and knowing in advance that kmalloc allocates only power of two
62 * segments, it optimizes the allocated space to have some spare space
63 * for those new keycodes by using the maximum number of entries that
64 * will be effectively be allocated by kmalloc.
65 * In order to reduce the quantity of table resizes, it has a minimum
66 * table size of IR_TAB_MIN_SIZE.
67 */
Mauro Carvalho Chehab8719cfd2009-12-17 09:24:37 -030068static int ir_roundup_tablesize(int n_elems)
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030069{
70 size_t size;
71
72 if (n_elems < IR_TAB_MIN_SIZE)
73 n_elems = IR_TAB_MIN_SIZE;
74
75 /*
76 * As kmalloc only allocates sizes of power of two, get as
77 * much entries as possible for the allocated memory segment
78 */
79 size = roundup_pow_of_two(n_elems * sizeof(struct ir_scancode));
80 n_elems = size / sizeof(struct ir_scancode);
81
82 return n_elems;
83}
84
85/**
86 * ir_copy_table() - copies a keytable, discarding the unused entries
87 * @destin: destin table
88 * @origin: origin table
89 *
90 * Copies all entries where the keycode is not KEY_UNKNOWN/KEY_RESERVED
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -030091 * Also copies table size and table protocol.
92 * NOTE: It shouldn't copy the lock field
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030093 */
94
Mauro Carvalho Chehab8719cfd2009-12-17 09:24:37 -030095static int ir_copy_table(struct ir_scancode_table *destin,
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030096 const struct ir_scancode_table *origin)
97{
98 int i, j = 0;
99
100 for (i = 0; i < origin->size; i++) {
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300101 if (origin->scan[i].keycode == KEY_UNKNOWN ||
102 origin->scan[i].keycode == KEY_RESERVED)
103 continue;
104
105 memcpy(&destin->scan[j], &origin->scan[i], sizeof(struct ir_scancode));
106 j++;
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300107 }
108 destin->size = j;
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -0300109 destin->ir_type = origin->ir_type;
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300110
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300111 IR_dprintk(1, "Copied %d scancodes to the new keycode table\n", destin->size);
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300112
113 return 0;
114}
115
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300116/**
117 * ir_getkeycode() - get a keycode at the evdev scancode ->keycode table
118 * @dev: the struct input_dev device descriptor
119 * @scancode: the desired scancode
120 * @keycode: the keycode to be retorned.
121 *
122 * This routine is used to handle evdev EVIOCGKEY ioctl.
123 * If the key is not found, returns -EINVAL, otherwise, returns 0.
124 */
125static int ir_getkeycode(struct input_dev *dev,
126 int scancode, int *keycode)
127{
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300128 int elem;
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300129 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
130 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300131
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300132 elem = ir_seek_table(rc_tab, scancode);
133 if (elem >= 0) {
134 *keycode = rc_tab->scan[elem].keycode;
135 return 0;
136 }
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300137
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300138 /*
139 * Scancode not found and table can't be expanded
140 */
141 if (elem < 0 && rc_tab->size == IR_TAB_MAX_SIZE)
142 return -EINVAL;
143
144 /*
145 * If is there extra space, returns KEY_RESERVED,
146 * otherwise, input core won't let ir_setkeycode to work
147 */
148 *keycode = KEY_RESERVED;
149 return 0;
150}
151
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300152/**
153 * ir_is_resize_needed() - Check if the table needs rezise
154 * @table: keycode table that may need to resize
155 * @n_elems: minimum number of entries to store keycodes
156 *
157 * Considering that kmalloc uses power of two storage areas, this
158 * routine detects if the real alloced size will change. If not, it
159 * just returns without doing nothing. Otherwise, it will extend or
160 * reduce the table size to meet the new needs.
161 *
162 * It returns 0 if no resize is needed, 1 otherwise.
163 */
164static int ir_is_resize_needed(struct ir_scancode_table *table, int n_elems)
165{
166 int cur_size = ir_roundup_tablesize(table->size);
167 int new_size = ir_roundup_tablesize(n_elems);
168
169 if (cur_size == new_size)
170 return 0;
171
172 /* Resize is needed */
173 return 1;
174}
175
176/**
177 * ir_delete_key() - remove a keycode from the table
178 * @rc_tab: keycode table
179 * @elem: element to be removed
180 *
181 */
182static void ir_delete_key(struct ir_scancode_table *rc_tab, int elem)
183{
184 unsigned long flags = 0;
185 int newsize = rc_tab->size - 1;
186 int resize = ir_is_resize_needed(rc_tab, newsize);
187 struct ir_scancode *oldkeymap = rc_tab->scan;
Mauro Carvalho Chehab3205e4f2009-12-29 08:25:13 -0300188 struct ir_scancode *newkeymap = NULL;
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300189
Mauro Carvalho Chehab3205e4f2009-12-29 08:25:13 -0300190 if (resize)
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300191 newkeymap = kzalloc(ir_roundup_tablesize(newsize) *
192 sizeof(*newkeymap), GFP_ATOMIC);
193
Mauro Carvalho Chehab3205e4f2009-12-29 08:25:13 -0300194 /* There's no memory for resize. Keep the old table */
195 if (!resize || !newkeymap) {
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300196 newkeymap = oldkeymap;
197
198 /* We'll modify the live table. Lock it */
199 spin_lock_irqsave(&rc_tab->lock, flags);
200 }
201
202 /*
203 * Copy the elements before the one that will be deleted
204 * if (!resize), both oldkeymap and newkeymap points
205 * to the same place, so, there's no need to copy
206 */
207 if (resize && elem > 0)
208 memcpy(newkeymap, oldkeymap,
209 elem * sizeof(*newkeymap));
210
211 /*
212 * Copy the other elements overwriting the element to be removed
213 * This operation applies to both resize and non-resize case
214 */
215 if (elem < newsize)
216 memcpy(&newkeymap[elem], &oldkeymap[elem + 1],
217 (newsize - elem) * sizeof(*newkeymap));
218
219 if (resize) {
220 /*
221 * As the copy happened to a temporary table, only here
222 * it needs to lock while replacing the table pointers
223 * to use the new table
224 */
225 spin_lock_irqsave(&rc_tab->lock, flags);
226 rc_tab->size = newsize;
227 rc_tab->scan = newkeymap;
228 spin_unlock_irqrestore(&rc_tab->lock, flags);
229
230 /* Frees the old keytable */
231 kfree(oldkeymap);
232 } else {
233 rc_tab->size = newsize;
234 spin_unlock_irqrestore(&rc_tab->lock, flags);
235 }
236}
237
238/**
239 * ir_insert_key() - insert a keycode at the table
240 * @rc_tab: keycode table
241 * @scancode: the desired scancode
242 * @keycode: the keycode to be retorned.
243 *
244 */
245static int ir_insert_key(struct ir_scancode_table *rc_tab,
246 int scancode, int keycode)
247{
248 unsigned long flags;
249 int elem = rc_tab->size;
250 int newsize = rc_tab->size + 1;
251 int resize = ir_is_resize_needed(rc_tab, newsize);
252 struct ir_scancode *oldkeymap = rc_tab->scan;
253 struct ir_scancode *newkeymap;
254
255 if (resize) {
256 newkeymap = kzalloc(ir_roundup_tablesize(newsize) *
257 sizeof(*newkeymap), GFP_ATOMIC);
258 if (!newkeymap)
259 return -ENOMEM;
260
261 memcpy(newkeymap, oldkeymap,
262 rc_tab->size * sizeof(*newkeymap));
263 } else
264 newkeymap = oldkeymap;
265
266 /* Stores the new code at the table */
267 IR_dprintk(1, "#%d: New scan 0x%04x with key 0x%04x\n",
268 rc_tab->size, scancode, keycode);
269
270 spin_lock_irqsave(&rc_tab->lock, flags);
271 rc_tab->size = newsize;
272 if (resize) {
273 rc_tab->scan = newkeymap;
274 kfree(oldkeymap);
275 }
276 newkeymap[elem].scancode = scancode;
277 newkeymap[elem].keycode = keycode;
278 spin_unlock_irqrestore(&rc_tab->lock, flags);
279
280 return 0;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300281}
282
283/**
284 * ir_setkeycode() - set a keycode at the evdev scancode ->keycode table
285 * @dev: the struct input_dev device descriptor
286 * @scancode: the desired scancode
287 * @keycode: the keycode to be retorned.
288 *
289 * This routine is used to handle evdev EVIOCSKEY ioctl.
290 * There's one caveat here: how can we increase the size of the table?
291 * If the key is not found, returns -EINVAL, otherwise, returns 0.
292 */
293static int ir_setkeycode(struct input_dev *dev,
294 int scancode, int keycode)
295{
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300296 int rc = 0;
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300297 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
298 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300299 struct ir_scancode *keymap = rc_tab->scan;
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300300 unsigned long flags;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300301
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300302 /*
303 * Handle keycode table deletions
304 *
305 * If userspace is adding a KEY_UNKNOWN or KEY_RESERVED,
306 * deal as a trial to remove an existing scancode attribution
307 * if table become too big, reduce it to save space
308 */
309 if (keycode == KEY_UNKNOWN || keycode == KEY_RESERVED) {
310 rc = ir_seek_table(rc_tab, scancode);
311 if (rc < 0)
312 return 0;
313
314 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n", rc, scancode);
315 clear_bit(keymap[rc].keycode, dev->keybit);
316 ir_delete_key(rc_tab, rc);
317
318 return 0;
319 }
320
321 /*
322 * Handle keycode replacements
323 *
324 * If the scancode exists, just replace by the new value
325 */
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300326 rc = ir_seek_table(rc_tab, scancode);
Mauro Carvalho Chehabe97f4672009-12-04 17:17:47 -0300327 if (rc >= 0) {
328 IR_dprintk(1, "#%d: Replacing scan 0x%04x with key 0x%04x\n",
329 rc, scancode, keycode);
330
331 clear_bit(keymap[rc].keycode, dev->keybit);
332
333 spin_lock_irqsave(&rc_tab->lock, flags);
334 keymap[rc].keycode = keycode;
335 spin_unlock_irqrestore(&rc_tab->lock, flags);
336
337 set_bit(keycode, dev->keybit);
338
339 return 0;
340 }
341
342 /*
343 * Handle new scancode inserts
344 *
345 * reallocate table if needed and insert a new keycode
346 */
347
348 /* Avoid growing the table indefinitely */
349 if (rc_tab->size + 1 > IR_TAB_MAX_SIZE)
350 return -EINVAL;
351
352 rc = ir_insert_key(rc_tab, scancode, keycode);
353 if (rc < 0)
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300354 return rc;
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300355 set_bit(keycode, dev->keybit);
356
357 return 0;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300358}
359
360/**
361 * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300362 * @input_dev: the struct input_dev descriptor of the device
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300363 * @scancode: the scancode that we're seeking
364 *
365 * This routine is used by the input routines when a key is pressed at the
366 * IR. The scancode is received and needs to be converted into a keycode.
367 * If the key is not found, it returns KEY_UNKNOWN. Otherwise, returns the
368 * corresponding keycode from the table.
369 */
370u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
371{
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300372 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
373 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300374 struct ir_scancode *keymap = rc_tab->scan;
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300375 int elem;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300376
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300377 elem = ir_seek_table(rc_tab, scancode);
378 if (elem >= 0) {
379 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
380 dev->name, scancode, keymap[elem].keycode);
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300381
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300382 return rc_tab->scan[elem].keycode;
383 }
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300384
385 printk(KERN_INFO "%s: unknown key for scancode 0x%04x\n",
386 dev->name, scancode);
387
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -0300388 /* Reports userspace that an unknown keycode were got */
389 return KEY_RESERVED;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300390}
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -0300391EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300392
393/**
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300394 * ir_input_register() - sets the IR keycode table and add the handlers
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300395 * for keymap table get/set
396 * @input_dev: the struct input_dev descriptor of the device
397 * @rc_tab: the struct ir_scancode_table table of scancode/keymap
398 *
Mauro Carvalho Chehabd4b778d2009-12-14 02:55:03 -0300399 * This routine is used to initialize the input infrastructure
400 * to work with an IR.
401 * It will register the input/evdev interface for the device and
402 * register the syfs code for IR class
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300403 */
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300404int ir_input_register(struct input_dev *input_dev,
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -0300405 const struct ir_scancode_table *rc_tab,
406 const struct ir_dev_props *props)
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300407{
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300408 struct ir_input_dev *ir_dev;
409 struct ir_scancode *keymap = rc_tab->scan;
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300410 int i, rc;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300411
412 if (rc_tab->scan == NULL || !rc_tab->size)
413 return -EINVAL;
414
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300415 ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL);
416 if (!ir_dev)
417 return -ENOMEM;
418
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -0300419 spin_lock_init(&ir_dev->rc_tab.lock);
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300420
421 ir_dev->rc_tab.size = ir_roundup_tablesize(rc_tab->size);
422 ir_dev->rc_tab.scan = kzalloc(ir_dev->rc_tab.size *
423 sizeof(struct ir_scancode), GFP_KERNEL);
424 if (!ir_dev->rc_tab.scan)
425 return -ENOMEM;
426
427 IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n",
428 ir_dev->rc_tab.size,
429 ir_dev->rc_tab.size * sizeof(ir_dev->rc_tab.scan));
430
431 ir_copy_table(&ir_dev->rc_tab, rc_tab);
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -0300432 ir_dev->props = props;
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300433
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300434 /* set the bits for the keys */
435 IR_dprintk(1, "key map size: %d\n", rc_tab->size);
436 for (i = 0; i < rc_tab->size; i++) {
437 IR_dprintk(1, "#%d: setting bit for keycode 0x%04x\n",
438 i, keymap[i].keycode);
439 set_bit(keymap[i].keycode, input_dev->keybit);
440 }
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300441 clear_bit(0, input_dev->keybit);
442
443 set_bit(EV_KEY, input_dev->evbit);
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300444
445 input_dev->getkeycode = ir_getkeycode;
446 input_dev->setkeycode = ir_setkeycode;
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300447 input_set_drvdata(input_dev, ir_dev);
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300448
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300449 rc = input_register_device(input_dev);
Mauro Carvalho Chehab4714eda2009-12-13 16:00:08 -0300450 if (rc < 0)
451 goto err;
452
453 rc = ir_register_class(input_dev);
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300454 if (rc < 0) {
Mauro Carvalho Chehab4714eda2009-12-13 16:00:08 -0300455 input_unregister_device(input_dev);
456 goto err;
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300457 }
458
Mauro Carvalho Chehab4714eda2009-12-13 16:00:08 -0300459 return 0;
460
461err:
462 kfree(rc_tab->scan);
463 kfree(ir_dev);
464 input_set_drvdata(input_dev, NULL);
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300465 return rc;
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300466}
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300467EXPORT_SYMBOL_GPL(ir_input_register);
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300468
Mauro Carvalho Chehabd4b778d2009-12-14 02:55:03 -0300469/**
470 * ir_input_unregister() - unregisters IR and frees resources
471 * @input_dev: the struct input_dev descriptor of the device
472
473 * This routine is used to free memory and de-register interfaces.
474 */
Mauro Carvalho Chehab38ef6aa2009-12-11 09:47:42 -0300475void ir_input_unregister(struct input_dev *dev)
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300476{
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300477 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300478 struct ir_scancode_table *rc_tab;
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300479
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300480 if (!ir_dev)
Mauro Carvalho Chehab05395a32009-12-06 08:32:49 -0300481 return;
482
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300483 IR_dprintk(1, "Freed keycode table\n");
484
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300485 rc_tab = &ir_dev->rc_tab;
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300486 rc_tab->size = 0;
487 kfree(rc_tab->scan);
488 rc_tab->scan = NULL;
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300489
Mauro Carvalho Chehab4714eda2009-12-13 16:00:08 -0300490 ir_unregister_class(dev);
491
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -0300492 kfree(ir_dev);
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300493 input_unregister_device(dev);
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300494}
Mauro Carvalho Chehab38ef6aa2009-12-11 09:47:42 -0300495EXPORT_SYMBOL_GPL(ir_input_unregister);
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300496
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -0300497int ir_core_debug; /* ir_debug level (0,1,2) */
498EXPORT_SYMBOL_GPL(ir_core_debug);
499module_param_named(debug, ir_core_debug, int, 0644);
500
501MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
502MODULE_LICENSE("GPL");