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 /drivers/media/IR/ir-keytable.c | |
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>
Diffstat (limited to 'drivers/media/IR/ir-keytable.c')
-rw-r--r-- | drivers/media/IR/ir-keytable.c | 51 |
1 files changed, 39 insertions, 12 deletions
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 | ||