aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor_core@ameritech.net>2005-09-15 03:01:41 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-10-28 12:52:53 -0400
commitc7f7a569d9b4ea7c53ab6fcd1377895312d8372b (patch)
tree554febf346b80a93c8dad5dff57fa60c4ea675b8 /drivers/macintosh
parentb7df3910c1298fee8ed7b9dfd2da74b85df5539c (diff)
[PATCH] Input: convert drivers/macintosh to dynamic input_dev allocation
Input: convert drivers/macntosh to dynamic input_dev allocation This is required for input_dev sysfs integration Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r--drivers/macintosh/adbhid.c222
-rw-r--r--drivers/macintosh/mac_hid.c40
2 files changed, 138 insertions, 124 deletions
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index db654e8bd67e..cdb6d0283195 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -206,7 +206,7 @@ u8 adb_to_linux_keycodes[128] = {
206}; 206};
207 207
208struct adbhid { 208struct adbhid {
209 struct input_dev input; 209 struct input_dev *input;
210 int id; 210 int id;
211 int default_id; 211 int default_id;
212 int original_handler_id; 212 int original_handler_id;
@@ -291,10 +291,10 @@ adbhid_input_keycode(int id, int keycode, int repeat, struct pt_regs *regs)
291 291
292 switch (keycode) { 292 switch (keycode) {
293 case ADB_KEY_CAPSLOCK: /* Generate down/up events for CapsLock everytime. */ 293 case ADB_KEY_CAPSLOCK: /* Generate down/up events for CapsLock everytime. */
294 input_regs(&ahid->input, regs); 294 input_regs(ahid->input, regs);
295 input_report_key(&ahid->input, KEY_CAPSLOCK, 1); 295 input_report_key(ahid->input, KEY_CAPSLOCK, 1);
296 input_report_key(&ahid->input, KEY_CAPSLOCK, 0); 296 input_report_key(ahid->input, KEY_CAPSLOCK, 0);
297 input_sync(&ahid->input); 297 input_sync(ahid->input);
298 return; 298 return;
299#ifdef CONFIG_PPC_PMAC 299#ifdef CONFIG_PPC_PMAC
300 case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */ 300 case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */
@@ -347,10 +347,10 @@ adbhid_input_keycode(int id, int keycode, int repeat, struct pt_regs *regs)
347 } 347 }
348 348
349 if (adbhid[id]->keycode[keycode]) { 349 if (adbhid[id]->keycode[keycode]) {
350 input_regs(&adbhid[id]->input, regs); 350 input_regs(adbhid[id]->input, regs);
351 input_report_key(&adbhid[id]->input, 351 input_report_key(adbhid[id]->input,
352 adbhid[id]->keycode[keycode], !up_flag); 352 adbhid[id]->keycode[keycode], !up_flag);
353 input_sync(&adbhid[id]->input); 353 input_sync(adbhid[id]->input);
354 } else 354 } else
355 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode, 355 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode,
356 up_flag ? "released" : "pressed"); 356 up_flag ? "released" : "pressed");
@@ -441,20 +441,20 @@ adbhid_mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopo
441 break; 441 break;
442 } 442 }
443 443
444 input_regs(&adbhid[id]->input, regs); 444 input_regs(adbhid[id]->input, regs);
445 445
446 input_report_key(&adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1)); 446 input_report_key(adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1));
447 input_report_key(&adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1)); 447 input_report_key(adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1));
448 448
449 if (nb >= 4 && adbhid[id]->mouse_kind != ADBMOUSE_TRACKPAD) 449 if (nb >= 4 && adbhid[id]->mouse_kind != ADBMOUSE_TRACKPAD)
450 input_report_key(&adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1)); 450 input_report_key(adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1));
451 451
452 input_report_rel(&adbhid[id]->input, REL_X, 452 input_report_rel(adbhid[id]->input, REL_X,
453 ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 )); 453 ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ));
454 input_report_rel(&adbhid[id]->input, REL_Y, 454 input_report_rel(adbhid[id]->input, REL_Y,
455 ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 )); 455 ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 ));
456 456
457 input_sync(&adbhid[id]->input); 457 input_sync(adbhid[id]->input);
458} 458}
459 459
460static void 460static void
@@ -467,7 +467,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
467 return; 467 return;
468 } 468 }
469 469
470 input_regs(&adbhid[id]->input, regs); 470 input_regs(adbhid[id]->input, regs);
471 471
472 switch (adbhid[id]->original_handler_id) { 472 switch (adbhid[id]->original_handler_id) {
473 default: 473 default:
@@ -477,19 +477,19 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
477 477
478 switch (data[1] & 0x0f) { 478 switch (data[1] & 0x0f) {
479 case 0x0: /* microphone */ 479 case 0x0: /* microphone */
480 input_report_key(&adbhid[id]->input, KEY_SOUND, down); 480 input_report_key(adbhid[id]->input, KEY_SOUND, down);
481 break; 481 break;
482 482
483 case 0x1: /* mute */ 483 case 0x1: /* mute */
484 input_report_key(&adbhid[id]->input, KEY_MUTE, down); 484 input_report_key(adbhid[id]->input, KEY_MUTE, down);
485 break; 485 break;
486 486
487 case 0x2: /* volume decrease */ 487 case 0x2: /* volume decrease */
488 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down); 488 input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
489 break; 489 break;
490 490
491 case 0x3: /* volume increase */ 491 case 0x3: /* volume increase */
492 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down); 492 input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
493 break; 493 break;
494 494
495 default: 495 default:
@@ -513,19 +513,19 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
513 513
514 switch (data[1] & 0x0f) { 514 switch (data[1] & 0x0f) {
515 case 0x8: /* mute */ 515 case 0x8: /* mute */
516 input_report_key(&adbhid[id]->input, KEY_MUTE, down); 516 input_report_key(adbhid[id]->input, KEY_MUTE, down);
517 break; 517 break;
518 518
519 case 0x7: /* volume decrease */ 519 case 0x7: /* volume decrease */
520 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down); 520 input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
521 break; 521 break;
522 522
523 case 0x6: /* volume increase */ 523 case 0x6: /* volume increase */
524 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down); 524 input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
525 break; 525 break;
526 526
527 case 0xb: /* eject */ 527 case 0xb: /* eject */
528 input_report_key(&adbhid[id]->input, KEY_EJECTCD, down); 528 input_report_key(adbhid[id]->input, KEY_EJECTCD, down);
529 break; 529 break;
530 530
531 case 0xa: /* brightness decrease */ 531 case 0xa: /* brightness decrease */
@@ -539,7 +539,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
539 } 539 }
540 } 540 }
541#endif /* CONFIG_PMAC_BACKLIGHT */ 541#endif /* CONFIG_PMAC_BACKLIGHT */
542 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSDOWN, down); 542 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
543 break; 543 break;
544 544
545 case 0x9: /* brightness increase */ 545 case 0x9: /* brightness increase */
@@ -553,19 +553,19 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
553 } 553 }
554 } 554 }
555#endif /* CONFIG_PMAC_BACKLIGHT */ 555#endif /* CONFIG_PMAC_BACKLIGHT */
556 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSUP, down); 556 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down);
557 break; 557 break;
558 558
559 case 0xc: /* videomode switch */ 559 case 0xc: /* videomode switch */
560 input_report_key(&adbhid[id]->input, KEY_SWITCHVIDEOMODE, down); 560 input_report_key(adbhid[id]->input, KEY_SWITCHVIDEOMODE, down);
561 break; 561 break;
562 562
563 case 0xd: /* keyboard illumination toggle */ 563 case 0xd: /* keyboard illumination toggle */
564 input_report_key(&adbhid[id]->input, KEY_KBDILLUMTOGGLE, down); 564 input_report_key(adbhid[id]->input, KEY_KBDILLUMTOGGLE, down);
565 break; 565 break;
566 566
567 case 0xe: /* keyboard illumination decrease */ 567 case 0xe: /* keyboard illumination decrease */
568 input_report_key(&adbhid[id]->input, KEY_KBDILLUMDOWN, down); 568 input_report_key(adbhid[id]->input, KEY_KBDILLUMDOWN, down);
569 break; 569 break;
570 570
571 case 0xf: 571 case 0xf:
@@ -573,7 +573,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
573 case 0x8f: 573 case 0x8f:
574 case 0x0f: 574 case 0x0f:
575 /* keyboard illumination increase */ 575 /* keyboard illumination increase */
576 input_report_key(&adbhid[id]->input, KEY_KBDILLUMUP, down); 576 input_report_key(adbhid[id]->input, KEY_KBDILLUMUP, down);
577 break; 577 break;
578 578
579 case 0x7f: 579 case 0x7f:
@@ -596,7 +596,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
596 break; 596 break;
597 } 597 }
598 598
599 input_sync(&adbhid[id]->input); 599 input_sync(adbhid[id]->input);
600} 600}
601 601
602static struct adb_request led_request; 602static struct adb_request led_request;
@@ -683,7 +683,7 @@ adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
683 int i; 683 int i;
684 for (i = 1; i < 16; i++) { 684 for (i = 1; i < 16; i++) {
685 if (adbhid[i]) 685 if (adbhid[i])
686 del_timer_sync(&adbhid[i]->input.timer); 686 del_timer_sync(&adbhid[i]->input->timer);
687 } 687 }
688 } 688 }
689 689
@@ -699,153 +699,163 @@ adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
699 return NOTIFY_DONE; 699 return NOTIFY_DONE;
700} 700}
701 701
702static void 702static int
703adbhid_input_register(int id, int default_id, int original_handler_id, 703adbhid_input_register(int id, int default_id, int original_handler_id,
704 int current_handler_id, int mouse_kind) 704 int current_handler_id, int mouse_kind)
705{ 705{
706 struct adbhid *hid;
707 struct input_dev *input_dev;
708 int err;
706 int i; 709 int i;
707 710
708 if (adbhid[id]) { 711 if (adbhid[id]) {
709 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id); 712 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
710 return; 713 return -EEXIST;
711 } 714 }
712 715
713 if (!(adbhid[id] = kmalloc(sizeof(struct adbhid), GFP_KERNEL))) 716 adbhid[id] = hid = kzalloc(sizeof(struct adbhid), GFP_KERNEL);
714 return; 717 input_dev = input_allocate_device();
715 718 if (!hid || !input_dev) {
716 memset(adbhid[id], 0, sizeof(struct adbhid)); 719 err = -ENOMEM;
717 sprintf(adbhid[id]->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id); 720 goto fail;
718 721
719 init_input_dev(&adbhid[id]->input); 722 }
720 723
721 adbhid[id]->id = default_id; 724 sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
722 adbhid[id]->original_handler_id = original_handler_id; 725
723 adbhid[id]->current_handler_id = current_handler_id; 726 hid->id = default_id;
724 adbhid[id]->mouse_kind = mouse_kind; 727 hid->original_handler_id = original_handler_id;
725 adbhid[id]->flags = 0; 728 hid->current_handler_id = current_handler_id;
726 adbhid[id]->input.private = adbhid[id]; 729 hid->mouse_kind = mouse_kind;
727 adbhid[id]->input.name = adbhid[id]->name; 730 hid->flags = 0;
728 adbhid[id]->input.phys = adbhid[id]->phys; 731 input_dev->private = hid;
729 adbhid[id]->input.id.bustype = BUS_ADB; 732 input_dev->name = hid->name;
730 adbhid[id]->input.id.vendor = 0x0001; 733 input_dev->phys = hid->phys;
731 adbhid[id]->input.id.product = (id << 12) | (default_id << 8) | original_handler_id; 734 input_dev->id.bustype = BUS_ADB;
732 adbhid[id]->input.id.version = 0x0100; 735 input_dev->id.vendor = 0x0001;
736 input_dev->id.product = (id << 12) | (default_id << 8) | original_handler_id;
737 input_dev->id.version = 0x0100;
733 738
734 switch (default_id) { 739 switch (default_id) {
735 case ADB_KEYBOARD: 740 case ADB_KEYBOARD:
736 if (!(adbhid[id]->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL))) { 741 hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL);
737 kfree(adbhid[id]); 742 if (!hid->keycode) {
738 return; 743 err = -ENOMEM;
744 goto fail;
739 } 745 }
740 746
741 sprintf(adbhid[id]->name, "ADB keyboard"); 747 sprintf(hid->name, "ADB keyboard");
742 748
743 memcpy(adbhid[id]->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes)); 749 memcpy(hid->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
744 750
745 printk(KERN_INFO "Detected ADB keyboard, type "); 751 printk(KERN_INFO "Detected ADB keyboard, type ");
746 switch (original_handler_id) { 752 switch (original_handler_id) {
747 default: 753 default:
748 printk("<unknown>.\n"); 754 printk("<unknown>.\n");
749 adbhid[id]->input.id.version = ADB_KEYBOARD_UNKNOWN; 755 input_dev->id.version = ADB_KEYBOARD_UNKNOWN;
750 break; 756 break;
751 757
752 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08: 758 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
753 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C: 759 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
754 case 0xC0: case 0xC3: case 0xC6: 760 case 0xC0: case 0xC3: case 0xC6:
755 printk("ANSI.\n"); 761 printk("ANSI.\n");
756 adbhid[id]->input.id.version = ADB_KEYBOARD_ANSI; 762 input_dev->id.version = ADB_KEYBOARD_ANSI;
757 break; 763 break;
758 764
759 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D: 765 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
760 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1: 766 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
761 case 0xC4: case 0xC7: 767 case 0xC4: case 0xC7:
762 printk("ISO, swapping keys.\n"); 768 printk("ISO, swapping keys.\n");
763 adbhid[id]->input.id.version = ADB_KEYBOARD_ISO; 769 input_dev->id.version = ADB_KEYBOARD_ISO;
764 i = adbhid[id]->keycode[10]; 770 i = hid->keycode[10];
765 adbhid[id]->keycode[10] = adbhid[id]->keycode[50]; 771 hid->keycode[10] = hid->keycode[50];
766 adbhid[id]->keycode[50] = i; 772 hid->keycode[50] = i;
767 break; 773 break;
768 774
769 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A: 775 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
770 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9: 776 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
771 printk("JIS.\n"); 777 printk("JIS.\n");
772 adbhid[id]->input.id.version = ADB_KEYBOARD_JIS; 778 input_dev->id.version = ADB_KEYBOARD_JIS;
773 break; 779 break;
774 } 780 }
775 781
776 for (i = 0; i < 128; i++) 782 for (i = 0; i < 128; i++)
777 if (adbhid[id]->keycode[i]) 783 if (hid->keycode[i])
778 set_bit(adbhid[id]->keycode[i], adbhid[id]->input.keybit); 784 set_bit(hid->keycode[i], input_dev->keybit);
779 785
780 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 786 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
781 adbhid[id]->input.ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML); 787 input_dev->ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
782 adbhid[id]->input.event = adbhid_kbd_event; 788 input_dev->event = adbhid_kbd_event;
783 adbhid[id]->input.keycodemax = 127; 789 input_dev->keycodemax = 127;
784 adbhid[id]->input.keycodesize = 1; 790 input_dev->keycodesize = 1;
785 break; 791 break;
786 792
787 case ADB_MOUSE: 793 case ADB_MOUSE:
788 sprintf(adbhid[id]->name, "ADB mouse"); 794 sprintf(hid->name, "ADB mouse");
789 795
790 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 796 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
791 adbhid[id]->input.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 797 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
792 adbhid[id]->input.relbit[0] = BIT(REL_X) | BIT(REL_Y); 798 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
793 break; 799 break;
794 800
795 case ADB_MISC: 801 case ADB_MISC:
796 switch (original_handler_id) { 802 switch (original_handler_id) {
797 case 0x02: /* Adjustable keyboard button device */ 803 case 0x02: /* Adjustable keyboard button device */
798 sprintf(adbhid[id]->name, "ADB adjustable keyboard buttons"); 804 sprintf(hid->name, "ADB adjustable keyboard buttons");
799 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 805 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
800 set_bit(KEY_SOUND, adbhid[id]->input.keybit); 806 set_bit(KEY_SOUND, input_dev->keybit);
801 set_bit(KEY_MUTE, adbhid[id]->input.keybit); 807 set_bit(KEY_MUTE, input_dev->keybit);
802 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit); 808 set_bit(KEY_VOLUMEUP, input_dev->keybit);
803 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit); 809 set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
804 break; 810 break;
805 case 0x1f: /* Powerbook button device */ 811 case 0x1f: /* Powerbook button device */
806 sprintf(adbhid[id]->name, "ADB Powerbook buttons"); 812 sprintf(hid->name, "ADB Powerbook buttons");
807 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 813 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
808 set_bit(KEY_MUTE, adbhid[id]->input.keybit); 814 set_bit(KEY_MUTE, input_dev->keybit);
809 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit); 815 set_bit(KEY_VOLUMEUP, input_dev->keybit);
810 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit); 816 set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
811 set_bit(KEY_BRIGHTNESSUP, adbhid[id]->input.keybit); 817 set_bit(KEY_BRIGHTNESSUP, input_dev->keybit);
812 set_bit(KEY_BRIGHTNESSDOWN, adbhid[id]->input.keybit); 818 set_bit(KEY_BRIGHTNESSDOWN, input_dev->keybit);
813 set_bit(KEY_EJECTCD, adbhid[id]->input.keybit); 819 set_bit(KEY_EJECTCD, input_dev->keybit);
814 set_bit(KEY_SWITCHVIDEOMODE, adbhid[id]->input.keybit); 820 set_bit(KEY_SWITCHVIDEOMODE, input_dev->keybit);
815 set_bit(KEY_KBDILLUMTOGGLE, adbhid[id]->input.keybit); 821 set_bit(KEY_KBDILLUMTOGGLE, input_dev->keybit);
816 set_bit(KEY_KBDILLUMDOWN, adbhid[id]->input.keybit); 822 set_bit(KEY_KBDILLUMDOWN, input_dev->keybit);
817 set_bit(KEY_KBDILLUMUP, adbhid[id]->input.keybit); 823 set_bit(KEY_KBDILLUMUP, input_dev->keybit);
818 break; 824 break;
819 } 825 }
820 if (adbhid[id]->name[0]) 826 if (hid->name[0])
821 break; 827 break;
822 /* else fall through */ 828 /* else fall through */
823 829
824 default: 830 default:
825 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n"); 831 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
826 kfree(adbhid[id]); 832 err = -ENODEV;
827 return; 833 goto fail;
828 } 834 }
829 835
830 adbhid[id]->input.keycode = adbhid[id]->keycode; 836 input_dev->keycode = hid->keycode;
831
832 input_register_device(&adbhid[id]->input);
833 837
834 printk(KERN_INFO "input: %s on %s\n", 838 input_register_device(input_dev);
835 adbhid[id]->name, adbhid[id]->phys);
836 839
837 if (default_id == ADB_KEYBOARD) { 840 if (default_id == ADB_KEYBOARD) {
838 /* HACK WARNING!! This should go away as soon there is an utility 841 /* HACK WARNING!! This should go away as soon there is an utility
839 * to control that for event devices. 842 * to control that for event devices.
840 */ 843 */
841 adbhid[id]->input.rep[REP_DELAY] = 500; /* input layer default: 250 */ 844 input_dev->rep[REP_DELAY] = 500; /* input layer default: 250 */
842 adbhid[id]->input.rep[REP_PERIOD] = 66; /* input layer default: 33 */ 845 input_dev->rep[REP_PERIOD] = 66; /* input layer default: 33 */
843 } 846 }
847
848 return 0;
849
850 fail: input_free_device(input_dev);
851 kfree(hid);
852 adbhid[id] = NULL;
853 return err;
844} 854}
845 855
846static void adbhid_input_unregister(int id) 856static void adbhid_input_unregister(int id)
847{ 857{
848 input_unregister_device(&adbhid[id]->input); 858 input_unregister_device(adbhid[id]->input);
849 if (adbhid[id]->keycode) 859 if (adbhid[id]->keycode)
850 kfree(adbhid[id]->keycode); 860 kfree(adbhid[id]->keycode);
851 kfree(adbhid[id]); 861 kfree(adbhid[id]);
@@ -858,7 +868,7 @@ adbhid_input_reregister(int id, int default_id, int org_handler_id,
858 int cur_handler_id, int mk) 868 int cur_handler_id, int mk)
859{ 869{
860 if (adbhid[id]) { 870 if (adbhid[id]) {
861 if (adbhid[id]->input.id.product != 871 if (adbhid[id]->input->id.product !=
862 ((id << 12)|(default_id << 8)|org_handler_id)) { 872 ((id << 12)|(default_id << 8)|org_handler_id)) {
863 adbhid_input_unregister(id); 873 adbhid_input_unregister(id);
864 adbhid_input_register(id, default_id, org_handler_id, 874 adbhid_input_register(id, default_id, org_handler_id,
diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index 5ad3a5a9eb7f..a66636116f0b 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -16,8 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18 18
19static struct input_dev emumousebtn; 19static struct input_dev *emumousebtn;
20static void emumousebtn_input_register(void); 20static int emumousebtn_input_register(void);
21static int mouse_emulate_buttons = 0; 21static int mouse_emulate_buttons = 0;
22static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */ 22static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
23static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */ 23static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
@@ -90,10 +90,10 @@ int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
90 && (keycode == mouse_button2_keycode 90 && (keycode == mouse_button2_keycode
91 || keycode == mouse_button3_keycode)) { 91 || keycode == mouse_button3_keycode)) {
92 if (mouse_emulate_buttons == 1) { 92 if (mouse_emulate_buttons == 1) {
93 input_report_key(&emumousebtn, 93 input_report_key(emumousebtn,
94 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT, 94 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
95 down); 95 down);
96 input_sync(&emumousebtn); 96 input_sync(emumousebtn);
97 return 1; 97 return 1;
98 } 98 }
99 mouse_last_keycode = down ? keycode : 0; 99 mouse_last_keycode = down ? keycode : 0;
@@ -105,30 +105,34 @@ int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
105 105
106EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons); 106EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons);
107 107
108static void emumousebtn_input_register(void) 108static int emumousebtn_input_register(void)
109{ 109{
110 emumousebtn.name = "Macintosh mouse button emulation"; 110 emumousebtn = input_allocate_device();
111 if (!emumousebtn)
112 return -ENOMEM;
111 113
112 init_input_dev(&emumousebtn); 114 emumousebtn->name = "Macintosh mouse button emulation";
115 emumousebtn->id.bustype = BUS_ADB;
116 emumousebtn->id.vendor = 0x0001;
117 emumousebtn->id.product = 0x0001;
118 emumousebtn->id.version = 0x0100;
113 119
114 emumousebtn.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 120 emumousebtn->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
115 emumousebtn.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 121 emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
116 emumousebtn.relbit[0] = BIT(REL_X) | BIT(REL_Y); 122 emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y);
117 123
118 emumousebtn.id.bustype = BUS_ADB; 124 input_register_device(emumousebtn);
119 emumousebtn.id.vendor = 0x0001;
120 emumousebtn.id.product = 0x0001;
121 emumousebtn.id.version = 0x0100;
122 125
123 input_register_device(&emumousebtn); 126 return 0;
124
125 printk(KERN_INFO "input: Macintosh mouse button emulation\n");
126} 127}
127 128
128int __init mac_hid_init(void) 129int __init mac_hid_init(void)
129{ 130{
131 int err;
130 132
131 emumousebtn_input_register(); 133 err = emumousebtn_input_register();
134 if (err)
135 return err;
132 136
133#if defined(CONFIG_SYSCTL) 137#if defined(CONFIG_SYSCTL)
134 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1); 138 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1);