Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/macintosh/mac_hid.c |
| 3 | * |
| 4 | * HID support stuff for Macintosh computers. |
| 5 | * |
| 6 | * Copyright (C) 2000 Franz Sirl. |
| 7 | * |
| 8 | * This file will soon be removed in favor of an uinput userspace tool. |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/proc_fs.h> |
| 13 | #include <linux/sysctl.h> |
| 14 | #include <linux/input.h> |
| 15 | #include <linux/module.h> |
Geert Uytterhoeven | 2301060 | 2007-08-22 14:01:35 -0700 | [diff] [blame] | 16 | #include <linux/kbd_kern.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 19 | static struct input_dev *emumousebtn; |
| 20 | static int emumousebtn_input_register(void); |
Olaf Hering | 8727585 | 2007-02-10 21:35:12 +0100 | [diff] [blame] | 21 | static int mouse_emulate_buttons; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */ |
| 23 | static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */ |
Olaf Hering | 8727585 | 2007-02-10 21:35:12 +0100 | [diff] [blame] | 24 | static int mouse_last_keycode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #if defined(CONFIG_SYSCTL) |
| 27 | /* file(s) in /proc/sys/dev/mac_hid */ |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 28 | static ctl_table mac_hid_files[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | .procname = "mouse_button_emulation", |
| 31 | .data = &mouse_emulate_buttons, |
| 32 | .maxlen = sizeof(int), |
| 33 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 34 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | }, |
| 36 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | .procname = "mouse_button2_keycode", |
| 38 | .data = &mouse_button2_keycode, |
| 39 | .maxlen = sizeof(int), |
| 40 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 41 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | }, |
| 43 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .procname = "mouse_button3_keycode", |
| 45 | .data = &mouse_button3_keycode, |
| 46 | .maxlen = sizeof(int), |
| 47 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 48 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 50 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /* dir in /proc/sys/dev */ |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 54 | static ctl_table mac_hid_dir[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .procname = "mac_hid", |
| 57 | .maxlen = 0, |
| 58 | .mode = 0555, |
| 59 | .child = mac_hid_files, |
| 60 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 61 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* /proc/sys/dev itself, in case that is not there yet */ |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 65 | static ctl_table mac_hid_root_dir[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | .procname = "dev", |
| 68 | .maxlen = 0, |
| 69 | .mode = 0555, |
| 70 | .child = mac_hid_dir, |
| 71 | }, |
Eric W. Biederman | 894d249 | 2009-11-05 14:34:02 -0800 | [diff] [blame] | 72 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static struct ctl_table_header *mac_hid_sysctl_header; |
| 76 | |
| 77 | #endif /* endif CONFIG_SYSCTL */ |
| 78 | |
| 79 | int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down) |
| 80 | { |
| 81 | switch (caller) { |
| 82 | case 1: |
| 83 | /* Called from keyboard.c */ |
| 84 | if (mouse_emulate_buttons |
| 85 | && (keycode == mouse_button2_keycode |
| 86 | || keycode == mouse_button3_keycode)) { |
| 87 | if (mouse_emulate_buttons == 1) { |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 88 | input_report_key(emumousebtn, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT, |
| 90 | down); |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 91 | input_sync(emumousebtn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return 1; |
| 93 | } |
| 94 | mouse_last_keycode = down ? keycode : 0; |
| 95 | } |
| 96 | break; |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
Peter Zijlstra | 8fd76c4 | 2008-04-18 00:25:38 -0400 | [diff] [blame] | 101 | static struct lock_class_key emumousebtn_event_class; |
| 102 | static struct lock_class_key emumousebtn_mutex_class; |
| 103 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 104 | static int emumousebtn_input_register(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 106 | int ret; |
| 107 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 108 | emumousebtn = input_allocate_device(); |
| 109 | if (!emumousebtn) |
| 110 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Harvey Harrison | a929107 | 2008-04-25 18:40:01 -0700 | [diff] [blame] | 112 | lockdep_set_class(&emumousebtn->event_lock, &emumousebtn_event_class); |
| 113 | lockdep_set_class(&emumousebtn->mutex, &emumousebtn_mutex_class); |
Peter Zijlstra | 8fd76c4 | 2008-04-18 00:25:38 -0400 | [diff] [blame] | 114 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 115 | emumousebtn->name = "Macintosh mouse button emulation"; |
| 116 | emumousebtn->id.bustype = BUS_ADB; |
| 117 | emumousebtn->id.vendor = 0x0001; |
| 118 | emumousebtn->id.product = 0x0001; |
| 119 | emumousebtn->id.version = 0x0100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 121 | emumousebtn->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 122 | emumousebtn->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | |
| 123 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
| 124 | emumousebtn->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 126 | ret = input_register_device(emumousebtn); |
| 127 | if (ret) |
| 128 | input_free_device(emumousebtn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 130 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 133 | static int __init mac_hid_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 135 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 137 | err = emumousebtn_input_register(); |
| 138 | if (err) |
| 139 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | #if defined(CONFIG_SYSCTL) |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 142 | mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | #endif /* CONFIG_SYSCTL */ |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | device_initcall(mac_hid_init); |