allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / macintosh / mac_hid.c
blob1fee8d0deab99f059ffb5a8be59011557d594c3b
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/init.h>
12 #include <linux/proc_fs.h>
13 #include <linux/sysctl.h>
14 #include <linux/input.h>
15 #include <linux/module.h>
18 static struct input_dev *emumousebtn;
19 static int emumousebtn_input_register(void);
20 static int mouse_emulate_buttons;
21 static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
22 static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
23 static int mouse_last_keycode;
25 #if defined(CONFIG_SYSCTL)
26 /* file(s) in /proc/sys/dev/mac_hid */
27 static ctl_table mac_hid_files[] = {
29 .ctl_name = DEV_MAC_HID_MOUSE_BUTTON_EMULATION,
30 .procname = "mouse_button_emulation",
31 .data = &mouse_emulate_buttons,
32 .maxlen = sizeof(int),
33 .mode = 0644,
34 .proc_handler = &proc_dointvec,
37 .ctl_name = DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,
38 .procname = "mouse_button2_keycode",
39 .data = &mouse_button2_keycode,
40 .maxlen = sizeof(int),
41 .mode = 0644,
42 .proc_handler = &proc_dointvec,
45 .ctl_name = DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,
46 .procname = "mouse_button3_keycode",
47 .data = &mouse_button3_keycode,
48 .maxlen = sizeof(int),
49 .mode = 0644,
50 .proc_handler = &proc_dointvec,
52 { .ctl_name = 0 }
55 /* dir in /proc/sys/dev */
56 static ctl_table mac_hid_dir[] = {
58 .ctl_name = DEV_MAC_HID,
59 .procname = "mac_hid",
60 .maxlen = 0,
61 .mode = 0555,
62 .child = mac_hid_files,
64 { .ctl_name = 0 }
67 /* /proc/sys/dev itself, in case that is not there yet */
68 static ctl_table mac_hid_root_dir[] = {
70 .ctl_name = CTL_DEV,
71 .procname = "dev",
72 .maxlen = 0,
73 .mode = 0555,
74 .child = mac_hid_dir,
76 { .ctl_name = 0 }
79 static struct ctl_table_header *mac_hid_sysctl_header;
81 #endif /* endif CONFIG_SYSCTL */
83 int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
85 switch (caller) {
86 case 1:
87 /* Called from keyboard.c */
88 if (mouse_emulate_buttons
89 && (keycode == mouse_button2_keycode
90 || keycode == mouse_button3_keycode)) {
91 if (mouse_emulate_buttons == 1) {
92 input_report_key(emumousebtn,
93 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
94 down);
95 input_sync(emumousebtn);
96 return 1;
98 mouse_last_keycode = down ? keycode : 0;
100 break;
102 return 0;
105 static int emumousebtn_input_register(void)
107 int ret;
109 emumousebtn = input_allocate_device();
110 if (!emumousebtn)
111 return -ENOMEM;
113 emumousebtn->name = "Macintosh mouse button emulation";
114 emumousebtn->id.bustype = BUS_ADB;
115 emumousebtn->id.vendor = 0x0001;
116 emumousebtn->id.product = 0x0001;
117 emumousebtn->id.version = 0x0100;
119 emumousebtn->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
120 emumousebtn->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
121 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
122 emumousebtn->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
124 ret = input_register_device(emumousebtn);
125 if (ret)
126 input_free_device(emumousebtn);
128 return ret;
131 static int __init mac_hid_init(void)
133 int err;
135 err = emumousebtn_input_register();
136 if (err)
137 return err;
139 #if defined(CONFIG_SYSCTL)
140 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir);
141 #endif /* CONFIG_SYSCTL */
143 return 0;
146 device_initcall(mac_hid_init);