aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc/ati_remote2.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2010-09-15 22:36:34 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-09-16 02:10:53 -0400
commit1f7930c55e1c1a2b6d5793a1002b31590356558c (patch)
treef9991e00643f2d7eb9744142a8f529a8388d46e0 /drivers/input/misc/ati_remote2.c
parent528487081aad32da85bf99802bdb7af32f4922b9 (diff)
Input: ati_remote2 - switch to using new keycode interface
Switch the code to use new style of getkeycode and setkeycode methods to allow retrieving and setting keycodes not only by their scancodes but also by index. Acked-by: Ville Syrjälä <syrjala@sci.fi> Tested-by: Jarod Wilson <jarod@wilsonet.com> Tested-by: Ville Syrjälä <syrjala@sci.fi> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/misc/ati_remote2.c')
-rw-r--r--drivers/input/misc/ati_remote2.c93
1 files changed, 65 insertions, 28 deletions
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 23257652b8e8..0b0e9be63542 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -483,51 +483,88 @@ static void ati_remote2_complete_key(struct urb *urb)
483} 483}
484 484
485static int ati_remote2_getkeycode(struct input_dev *idev, 485static int ati_remote2_getkeycode(struct input_dev *idev,
486 unsigned int scancode, unsigned int *keycode) 486 struct input_keymap_entry *ke)
487{ 487{
488 struct ati_remote2 *ar2 = input_get_drvdata(idev); 488 struct ati_remote2 *ar2 = input_get_drvdata(idev);
489 unsigned int mode; 489 unsigned int mode;
490 int index; 490 int offset;
491 unsigned int index;
492 unsigned int scancode;
493
494 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
495 index = ke->index;
496 if (index >= ATI_REMOTE2_MODES *
497 ARRAY_SIZE(ati_remote2_key_table))
498 return -EINVAL;
499
500 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
501 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
502 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
503 } else {
504 if (input_scancode_to_scalar(ke, &scancode))
505 return -EINVAL;
506
507 mode = scancode >> 8;
508 if (mode > ATI_REMOTE2_PC)
509 return -EINVAL;
510
511 offset = ati_remote2_lookup(scancode & 0xff);
512 if (offset < 0)
513 return -EINVAL;
514
515 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
516 }
491 517
492 mode = scancode >> 8; 518 ke->keycode = ar2->keycode[mode][offset];
493 if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) 519 ke->len = sizeof(scancode);
494 return -EINVAL; 520 memcpy(&ke->scancode, &scancode, sizeof(scancode));
521 ke->index = index;
495 522
496 index = ati_remote2_lookup(scancode & 0xFF);
497 if (index < 0)
498 return -EINVAL;
499
500 *keycode = ar2->keycode[mode][index];
501 return 0; 523 return 0;
502} 524}
503 525
504static int ati_remote2_setkeycode(struct input_dev *idev, 526static int ati_remote2_setkeycode(struct input_dev *idev,
505 unsigned int scancode, unsigned int keycode) 527 const struct input_keymap_entry *ke,
528 unsigned int *old_keycode)
506{ 529{
507 struct ati_remote2 *ar2 = input_get_drvdata(idev); 530 struct ati_remote2 *ar2 = input_get_drvdata(idev);
508 unsigned int mode, old_keycode; 531 unsigned int mode;
509 int index; 532 int offset;
510 533 unsigned int index;
511 mode = scancode >> 8; 534 unsigned int scancode;
512 if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) 535
513 return -EINVAL; 536 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
514 537 if (ke->index >= ATI_REMOTE2_MODES *
515 index = ati_remote2_lookup(scancode & 0xFF); 538 ARRAY_SIZE(ati_remote2_key_table))
516 if (index < 0) 539 return -EINVAL;
517 return -EINVAL; 540
541 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
542 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
543 } else {
544 if (input_scancode_to_scalar(ke, &scancode))
545 return -EINVAL;
546
547 mode = scancode >> 8;
548 if (mode > ATI_REMOTE2_PC)
549 return -EINVAL;
550
551 offset = ati_remote2_lookup(scancode & 0xff);
552 if (offset < 0)
553 return -EINVAL;
554 }
518 555
519 old_keycode = ar2->keycode[mode][index]; 556 *old_keycode = ar2->keycode[mode][offset];
520 ar2->keycode[mode][index] = keycode; 557 ar2->keycode[mode][offset] = ke->keycode;
521 __set_bit(keycode, idev->keybit); 558 __set_bit(ke->keycode, idev->keybit);
522 559
523 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { 560 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
524 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) { 561 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
525 if (ar2->keycode[mode][index] == old_keycode) 562 if (ar2->keycode[mode][index] == *old_keycode)
526 return 0; 563 return 0;
527 } 564 }
528 } 565 }
529 566
530 __clear_bit(old_keycode, idev->keybit); 567 __clear_bit(*old_keycode, idev->keybit);
531 568
532 return 0; 569 return 0;
533} 570}
@@ -575,8 +612,8 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
575 idev->open = ati_remote2_open; 612 idev->open = ati_remote2_open;
576 idev->close = ati_remote2_close; 613 idev->close = ati_remote2_close;
577 614
578 idev->getkeycode = ati_remote2_getkeycode; 615 idev->getkeycode_new = ati_remote2_getkeycode;
579 idev->setkeycode = ati_remote2_setkeycode; 616 idev->setkeycode_new = ati_remote2_setkeycode;
580 617
581 idev->name = ar2->name; 618 idev->name = ar2->name;
582 idev->phys = ar2->phys; 619 idev->phys = ar2->phys;