Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / macintosh / mac_hid.c
bloba66636116f0b4f047f1071cf54b2c5cf334e2165
1 /*
2 * drivers/macintosh/mac_hid.c
4 * HID support stuff for Macintosh computers.
6 * Copyright (C) 2000 Franz Sirl.
8 * This file will soon be removed in favor of an uinput userspace tool.
9 */
11 #include <linux/config.h>
12 #include <linux/init.h>
13 #include <linux/proc_fs.h>
14 #include <linux/sysctl.h>
15 #include <linux/input.h>
16 #include <linux/module.h>
19 static struct input_dev *emumousebtn;
20 static int emumousebtn_input_register(void);
21 static int mouse_emulate_buttons = 0;
22 static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
23 static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
24 static int mouse_last_keycode = 0;
26 #if defined(CONFIG_SYSCTL)
27 /* file(s) in /proc/sys/dev/mac_hid */
28 ctl_table mac_hid_files[] = {
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,
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,
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,
53 { .ctl_name = 0 }
56 /* dir in /proc/sys/dev */
57 ctl_table mac_hid_dir[] = {
59 .ctl_name = DEV_MAC_HID,
60 .procname = "mac_hid",
61 .maxlen = 0,
62 .mode = 0555,
63 .child = mac_hid_files,
65 { .ctl_name = 0 }
68 /* /proc/sys/dev itself, in case that is not there yet */
69 ctl_table mac_hid_root_dir[] = {
71 .ctl_name = CTL_DEV,
72 .procname = "dev",
73 .maxlen = 0,
74 .mode = 0555,
75 .child = mac_hid_dir,
77 { .ctl_name = 0 }
80 static struct ctl_table_header *mac_hid_sysctl_header;
82 #endif /* endif CONFIG_SYSCTL */
84 int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
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) {
93 input_report_key(emumousebtn,
94 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
95 down);
96 input_sync(emumousebtn);
97 return 1;
99 mouse_last_keycode = down ? keycode : 0;
101 break;
103 return 0;
106 EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons);
108 static int emumousebtn_input_register(void)
110 emumousebtn = input_allocate_device();
111 if (!emumousebtn)
112 return -ENOMEM;
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;
120 emumousebtn->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
121 emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
122 emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y);
124 input_register_device(emumousebtn);
126 return 0;
129 int __init mac_hid_init(void)
131 int err;
133 err = emumousebtn_input_register();
134 if (err)
135 return err;
137 #if defined(CONFIG_SYSCTL)
138 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1);
139 #endif /* CONFIG_SYSCTL */
141 return 0;
144 device_initcall(mac_hid_init);