diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-12-11 07:44:23 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-12-15 21:18:44 -0500 |
commit | 75543cce0c1f46be495b981d8d3eda0882721d07 (patch) | |
tree | a9ce0d8919329369b174c63afadc372f82526e54 | |
parent | 865fbf20bed00d456556ecd4b4c9dadc45cba759 (diff) |
V4L/DVB (13615): ir-core: create ir_input_register
Move non-V4L specific stuff from ir-functions ir_input_init() into
a new function to register ir devices: ir_input_register().
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/IR/ir-functions.c | 17 | ||||
-rw-r--r-- | drivers/media/IR/ir-keytable.c | 51 | ||||
-rw-r--r-- | include/media/ir-common.h | 2 | ||||
-rw-r--r-- | include/media/ir-core.h | 9 |
4 files changed, 48 insertions, 31 deletions
diff --git a/drivers/media/IR/ir-functions.c b/drivers/media/IR/ir-functions.c index 2db22948a310..7401a7989719 100644 --- a/drivers/media/IR/ir-functions.c +++ b/drivers/media/IR/ir-functions.c | |||
@@ -56,24 +56,11 @@ int ir_input_init(struct input_dev *dev, struct ir_input_state *ir, | |||
56 | { | 56 | { |
57 | ir->ir_type = ir_type; | 57 | ir->ir_type = ir_type; |
58 | 58 | ||
59 | ir->keytable.size = ir_roundup_tablesize(ir_codes->size); | ||
60 | ir->keytable.scan = kzalloc(ir->keytable.size * | ||
61 | sizeof(struct ir_scancode), GFP_KERNEL); | ||
62 | if (!ir->keytable.scan) | ||
63 | return -ENOMEM; | ||
64 | |||
65 | IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n", | ||
66 | ir->keytable.size, | ||
67 | ir->keytable.size * sizeof(ir->keytable.scan)); | ||
68 | |||
69 | ir_copy_table(&ir->keytable, ir_codes); | ||
70 | ir_set_keycode_table(dev, &ir->keytable); | ||
71 | |||
72 | clear_bit(0, dev->keybit); | ||
73 | set_bit(EV_KEY, dev->evbit); | ||
74 | if (repeat) | 59 | if (repeat) |
75 | set_bit(EV_REP, dev->evbit); | 60 | set_bit(EV_REP, dev->evbit); |
76 | 61 | ||
62 | ir_input_register(dev, ir_codes); | ||
63 | |||
77 | return 0; | 64 | return 0; |
78 | } | 65 | } |
79 | EXPORT_SYMBOL_GPL(ir_input_init); | 66 | EXPORT_SYMBOL_GPL(ir_input_init); |
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 20d642dbab49..ddb8a0f8af4d 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c | |||
@@ -125,7 +125,8 @@ static int ir_getkeycode(struct input_dev *dev, | |||
125 | int scancode, int *keycode) | 125 | int scancode, int *keycode) |
126 | { | 126 | { |
127 | int elem; | 127 | int elem; |
128 | struct ir_scancode_table *rc_tab = input_get_drvdata(dev); | 128 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); |
129 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | ||
129 | 130 | ||
130 | elem = ir_seek_table(rc_tab, scancode); | 131 | elem = ir_seek_table(rc_tab, scancode); |
131 | if (elem >= 0) { | 132 | if (elem >= 0) { |
@@ -296,7 +297,8 @@ static int ir_setkeycode(struct input_dev *dev, | |||
296 | int scancode, int keycode) | 297 | int scancode, int keycode) |
297 | { | 298 | { |
298 | int rc = 0; | 299 | int rc = 0; |
299 | struct ir_scancode_table *rc_tab = input_get_drvdata(dev); | 300 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); |
301 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | ||
300 | struct ir_scancode *keymap = rc_tab->scan; | 302 | struct ir_scancode *keymap = rc_tab->scan; |
301 | unsigned long flags; | 303 | unsigned long flags; |
302 | 304 | ||
@@ -370,7 +372,8 @@ static int ir_setkeycode(struct input_dev *dev, | |||
370 | */ | 372 | */ |
371 | u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) | 373 | u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) |
372 | { | 374 | { |
373 | struct ir_scancode_table *rc_tab = input_get_drvdata(dev); | 375 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); |
376 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | ||
374 | struct ir_scancode *keymap = rc_tab->scan; | 377 | struct ir_scancode *keymap = rc_tab->scan; |
375 | int elem; | 378 | int elem; |
376 | 379 | ||
@@ -391,7 +394,7 @@ u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) | |||
391 | EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); | 394 | EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); |
392 | 395 | ||
393 | /** | 396 | /** |
394 | * ir_set_keycode_table() - sets the IR keycode table and add the handlers | 397 | * ir_input_register() - sets the IR keycode table and add the handlers |
395 | * for keymap table get/set | 398 | * for keymap table get/set |
396 | * @input_dev: the struct input_dev descriptor of the device | 399 | * @input_dev: the struct input_dev descriptor of the device |
397 | * @rc_tab: the struct ir_scancode_table table of scancode/keymap | 400 | * @rc_tab: the struct ir_scancode_table table of scancode/keymap |
@@ -400,17 +403,34 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); | |||
400 | * an IR. | 403 | * an IR. |
401 | * It should be called before registering the IR device. | 404 | * It should be called before registering the IR device. |
402 | */ | 405 | */ |
403 | int ir_set_keycode_table(struct input_dev *input_dev, | 406 | int ir_input_register(struct input_dev *input_dev, |
404 | struct ir_scancode_table *rc_tab) | 407 | struct ir_scancode_table *rc_tab) |
405 | { | 408 | { |
406 | struct ir_scancode *keymap = rc_tab->scan; | 409 | struct ir_input_dev *ir_dev; |
410 | struct ir_scancode *keymap = rc_tab->scan; | ||
407 | int i; | 411 | int i; |
408 | 412 | ||
409 | spin_lock_init(&rc_tab->lock); | ||
410 | |||
411 | if (rc_tab->scan == NULL || !rc_tab->size) | 413 | if (rc_tab->scan == NULL || !rc_tab->size) |
412 | return -EINVAL; | 414 | return -EINVAL; |
413 | 415 | ||
416 | ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL); | ||
417 | if (!ir_dev) | ||
418 | return -ENOMEM; | ||
419 | |||
420 | spin_lock_init(&rc_tab->lock); | ||
421 | |||
422 | ir_dev->rc_tab.size = ir_roundup_tablesize(rc_tab->size); | ||
423 | ir_dev->rc_tab.scan = kzalloc(ir_dev->rc_tab.size * | ||
424 | sizeof(struct ir_scancode), GFP_KERNEL); | ||
425 | if (!ir_dev->rc_tab.scan) | ||
426 | return -ENOMEM; | ||
427 | |||
428 | IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n", | ||
429 | ir_dev->rc_tab.size, | ||
430 | ir_dev->rc_tab.size * sizeof(ir_dev->rc_tab.scan)); | ||
431 | |||
432 | ir_copy_table(&ir_dev->rc_tab, rc_tab); | ||
433 | |||
414 | /* set the bits for the keys */ | 434 | /* set the bits for the keys */ |
415 | IR_dprintk(1, "key map size: %d\n", rc_tab->size); | 435 | IR_dprintk(1, "key map size: %d\n", rc_tab->size); |
416 | for (i = 0; i < rc_tab->size; i++) { | 436 | for (i = 0; i < rc_tab->size; i++) { |
@@ -418,18 +438,22 @@ int ir_set_keycode_table(struct input_dev *input_dev, | |||
418 | i, keymap[i].keycode); | 438 | i, keymap[i].keycode); |
419 | set_bit(keymap[i].keycode, input_dev->keybit); | 439 | set_bit(keymap[i].keycode, input_dev->keybit); |
420 | } | 440 | } |
441 | clear_bit(0, input_dev->keybit); | ||
442 | |||
443 | set_bit(EV_KEY, input_dev->evbit); | ||
421 | 444 | ||
422 | input_dev->getkeycode = ir_getkeycode; | 445 | input_dev->getkeycode = ir_getkeycode; |
423 | input_dev->setkeycode = ir_setkeycode; | 446 | input_dev->setkeycode = ir_setkeycode; |
424 | input_set_drvdata(input_dev, rc_tab); | 447 | input_set_drvdata(input_dev, ir_dev); |
425 | 448 | ||
426 | return 0; | 449 | return 0; |
427 | } | 450 | } |
428 | EXPORT_SYMBOL_GPL(ir_set_keycode_table); | 451 | EXPORT_SYMBOL_GPL(ir_input_register); |
429 | 452 | ||
430 | void ir_input_free(struct input_dev *dev) | 453 | void ir_input_free(struct input_dev *dev) |
431 | { | 454 | { |
432 | struct ir_scancode_table *rc_tab = input_get_drvdata(dev); | 455 | struct ir_input_dev *ir_dev = input_get_drvdata(dev); |
456 | struct ir_scancode_table *rc_tab = &ir_dev->rc_tab; | ||
433 | 457 | ||
434 | if (!rc_tab) | 458 | if (!rc_tab) |
435 | return; | 459 | return; |
@@ -439,6 +463,9 @@ void ir_input_free(struct input_dev *dev) | |||
439 | rc_tab->size = 0; | 463 | rc_tab->size = 0; |
440 | kfree(rc_tab->scan); | 464 | kfree(rc_tab->scan); |
441 | rc_tab->scan = NULL; | 465 | rc_tab->scan = NULL; |
466 | |||
467 | kfree(ir_dev); | ||
468 | input_set_drvdata(dev, NULL); | ||
442 | } | 469 | } |
443 | EXPORT_SYMBOL_GPL(ir_input_free); | 470 | EXPORT_SYMBOL_GPL(ir_input_free); |
444 | 471 | ||
diff --git a/include/media/ir-common.h b/include/media/ir-common.h index 18d300414fa2..ac8ced6bf3e2 100644 --- a/include/media/ir-common.h +++ b/include/media/ir-common.h | |||
@@ -37,8 +37,6 @@ struct ir_input_state { | |||
37 | /* configuration */ | 37 | /* configuration */ |
38 | int ir_type; | 38 | int ir_type; |
39 | 39 | ||
40 | struct ir_scancode_table keytable; | ||
41 | |||
42 | /* key info */ | 40 | /* key info */ |
43 | u32 ir_key; /* ir scancode */ | 41 | u32 ir_key; /* ir scancode */ |
44 | u32 keycode; /* linux key code */ | 42 | u32 keycode; /* linux key code */ |
diff --git a/include/media/ir-core.h b/include/media/ir-core.h index 825d04a4e77b..ea76c199b67d 100644 --- a/include/media/ir-core.h +++ b/include/media/ir-core.h | |||
@@ -41,6 +41,11 @@ struct ir_scancode_table { | |||
41 | spinlock_t lock; | 41 | spinlock_t lock; |
42 | }; | 42 | }; |
43 | 43 | ||
44 | struct ir_input_dev { | ||
45 | struct input_dev *dev; | ||
46 | struct ir_scancode_table rc_tab; | ||
47 | }; | ||
48 | |||
44 | /* Routines from ir-keytable.c */ | 49 | /* Routines from ir-keytable.c */ |
45 | 50 | ||
46 | u32 ir_g_keycode_from_table(struct input_dev *input_dev, | 51 | u32 ir_g_keycode_from_table(struct input_dev *input_dev, |
@@ -50,8 +55,8 @@ int ir_set_keycode_table(struct input_dev *input_dev, | |||
50 | struct ir_scancode_table *rc_tab); | 55 | struct ir_scancode_table *rc_tab); |
51 | 56 | ||
52 | int ir_roundup_tablesize(int n_elems); | 57 | int ir_roundup_tablesize(int n_elems); |
53 | int ir_copy_table(struct ir_scancode_table *destin, | 58 | int ir_input_register(struct input_dev *dev, |
54 | const struct ir_scancode_table *origin); | 59 | struct ir_scancode_table *ir_codes); |
55 | void ir_input_free(struct input_dev *input_dev); | 60 | void ir_input_free(struct input_dev *input_dev); |
56 | 61 | ||
57 | #endif | 62 | #endif |