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 | { |
| 30 | .ctl_name = DEV_MAC_HID_MOUSE_BUTTON_EMULATION, |
| 31 | .procname = "mouse_button_emulation", |
| 32 | .data = &mouse_emulate_buttons, |
| 33 | .maxlen = sizeof(int), |
| 34 | .mode = 0644, |
| 35 | .proc_handler = &proc_dointvec, |
| 36 | }, |
| 37 | { |
| 38 | .ctl_name = DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE, |
| 39 | .procname = "mouse_button2_keycode", |
| 40 | .data = &mouse_button2_keycode, |
| 41 | .maxlen = sizeof(int), |
| 42 | .mode = 0644, |
| 43 | .proc_handler = &proc_dointvec, |
| 44 | }, |
| 45 | { |
| 46 | .ctl_name = DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE, |
| 47 | .procname = "mouse_button3_keycode", |
| 48 | .data = &mouse_button3_keycode, |
| 49 | .maxlen = sizeof(int), |
| 50 | .mode = 0644, |
| 51 | .proc_handler = &proc_dointvec, |
| 52 | }, |
| 53 | { .ctl_name = 0 } |
| 54 | }; |
| 55 | |
| 56 | /* dir in /proc/sys/dev */ |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 57 | static ctl_table mac_hid_dir[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | .ctl_name = DEV_MAC_HID, |
| 60 | .procname = "mac_hid", |
| 61 | .maxlen = 0, |
| 62 | .mode = 0555, |
| 63 | .child = mac_hid_files, |
| 64 | }, |
| 65 | { .ctl_name = 0 } |
| 66 | }; |
| 67 | |
| 68 | /* /proc/sys/dev itself, in case that is not there yet */ |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 69 | static ctl_table mac_hid_root_dir[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | .ctl_name = CTL_DEV, |
| 72 | .procname = "dev", |
| 73 | .maxlen = 0, |
| 74 | .mode = 0555, |
| 75 | .child = mac_hid_dir, |
| 76 | }, |
| 77 | { .ctl_name = 0 } |
| 78 | }; |
| 79 | |
| 80 | static struct ctl_table_header *mac_hid_sysctl_header; |
| 81 | |
| 82 | #endif /* endif CONFIG_SYSCTL */ |
| 83 | |
| 84 | int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down) |
| 85 | { |
| 86 | switch (caller) { |
| 87 | case 1: |
| 88 | /* Called from keyboard.c */ |
| 89 | if (mouse_emulate_buttons |
| 90 | && (keycode == mouse_button2_keycode |
| 91 | || keycode == mouse_button3_keycode)) { |
| 92 | if (mouse_emulate_buttons == 1) { |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 93 | input_report_key(emumousebtn, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT, |
| 95 | down); |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 96 | input_sync(emumousebtn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | return 1; |
| 98 | } |
| 99 | mouse_last_keycode = down ? keycode : 0; |
| 100 | } |
| 101 | break; |
| 102 | } |
| 103 | return 0; |
| 104 | } |
| 105 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 106 | static int emumousebtn_input_register(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 108 | int ret; |
| 109 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 110 | emumousebtn = input_allocate_device(); |
| 111 | if (!emumousebtn) |
| 112 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 120 | emumousebtn->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 121 | emumousebtn->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | |
| 122 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
| 123 | emumousebtn->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 125 | ret = input_register_device(emumousebtn); |
| 126 | if (ret) |
| 127 | input_free_device(emumousebtn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Dmitry Torokhov | 4bdbd28 | 2006-11-24 00:43:22 -0500 | [diff] [blame] | 129 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Adrian Bunk | f3e5d2b | 2007-03-08 09:41:07 +1100 | [diff] [blame] | 132 | static int __init mac_hid_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 134 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Dmitry Torokhov | c7f7a56 | 2005-09-15 02:01:41 -0500 | [diff] [blame] | 136 | err = emumousebtn_input_register(); |
| 137 | if (err) |
| 138 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | #if defined(CONFIG_SYSCTL) |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 141 | mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #endif /* CONFIG_SYSCTL */ |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | device_initcall(mac_hid_init); |