1 /*
2 * drivers/macintosh/mac_hid.c
3 *
4 * HID support stuff for Macintosh computers.
5 *
6 * Copyright (C) 2000 Franz Sirl.
7 *
8 * Stuff inside CONFIG_MAC_ADBKEYCODES should go away during 2.5 when all
9 * major distributions are using the Linux keycodes.
10 * Stuff inside CONFIG_MAC_EMUMOUSEBTN should really be moved to userspace.
11 */
12
13 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/proc_fs.h>
16 #include <linux/sysctl.h>
17 #include <linux/input.h>
18
19 #ifdef CONFIG_MAC_ADBKEYCODES
20 #include <linux/keyboard.h>
21 #include <asm/keyboard.h>
22 #include <asm/machdep.h>
23 #endif
24
25 #ifdef CONFIG_MAC_ADBKEYCODES
26 /* Simple translation table for the SysRq keys */
27
28 #ifdef CONFIG_MAGIC_SYSRQ
29 unsigned char mac_hid_kbd_sysrq_xlate[128] =
30 "asdfhgzxcv\000bqwer" /* 0x00 - 0x0f */
31 "yt123465=97-80o]" /* 0x10 - 0x1f */
32 "u[ip\rlj'k;\\,/nm." /* 0x20 - 0x2f */
33 "\t `\177\000\033\000\000\000\000\000\000\000\000\000\000"
34 /* 0x30 - 0x3f */
35 "\000\000\000*\000+\000\000\000\000\000/\r\000-\000"
36 /* 0x40 - 0x4f */
37 "\000\0000123456789\000\000\000" /* 0x50 - 0x5f */
38 "\205\206\207\203\210\211\000\213\000\215\000\000\000\000\000\212\000\214";
39 /* 0x60 - 0x6f */
40 extern unsigned char pckbd_sysrq_xlate[128];
41 #endif
42
43 static u_short macplain_map[NR_KEYS] = {
44 0xfb61, 0xfb73, 0xfb64, 0xfb66, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
45 0xfb63, 0xfb76, 0xf200, 0xfb62, 0xfb71, 0xfb77, 0xfb65, 0xfb72,
46 0xfb79, 0xfb74, 0xf031, 0xf032, 0xf033, 0xf034, 0xf036, 0xf035,
47 0xf03d, 0xf039, 0xf037, 0xf02d, 0xf038, 0xf030, 0xf05d, 0xfb6f,
48 0xfb75, 0xf05b, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf027,
49 0xfb6b, 0xf03b, 0xf05c, 0xf02c, 0xf02f, 0xfb6e, 0xfb6d, 0xf02e,
50 0xf009, 0xf020, 0xf060, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
51 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
52 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
53 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
54 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
55 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
56 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
57 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf109, 0xf200, 0xf10b,
58 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
59 0xf101, 0xf119, 0xf100, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
60 };
61
62 static u_short macshift_map[NR_KEYS] = {
63 0xfb41, 0xfb53, 0xfb44, 0xfb46, 0xfb48, 0xfb47, 0xfb5a, 0xfb58,
64 0xfb43, 0xfb56, 0xf200, 0xfb42, 0xfb51, 0xfb57, 0xfb45, 0xfb52,
65 0xfb59, 0xfb54, 0xf021, 0xf040, 0xf023, 0xf024, 0xf05e, 0xf025,
66 0xf02b, 0xf028, 0xf026, 0xf05f, 0xf02a, 0xf029, 0xf07d, 0xfb4f,
67 0xfb55, 0xf07b, 0xfb49, 0xfb50, 0xf201, 0xfb4c, 0xfb4a, 0xf022,
68 0xfb4b, 0xf03a, 0xf07c, 0xf03c, 0xf03f, 0xfb4e, 0xfb4d, 0xf03e,
69 0xf009, 0xf020, 0xf07e, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
70 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
71 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
72 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
73 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
74 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
75 0xf10e, 0xf10f, 0xf110, 0xf10c, 0xf111, 0xf112, 0xf200, 0xf10a,
76 0xf200, 0xf10c, 0xf200, 0xf203, 0xf200, 0xf113, 0xf200, 0xf10b,
77 0xf200, 0xf11d, 0xf115, 0xf114, 0xf20b, 0xf116, 0xf10d, 0xf117,
78 0xf10b, 0xf20a, 0xf10a, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
79 };
80
81 static u_short macaltgr_map[NR_KEYS] = {
82 0xf914, 0xfb73, 0xf917, 0xf919, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
83 0xf916, 0xfb76, 0xf200, 0xf915, 0xfb71, 0xfb77, 0xf918, 0xfb72,
84 0xfb79, 0xfb74, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
85 0xf200, 0xf05d, 0xf07b, 0xf05c, 0xf05b, 0xf07d, 0xf07e, 0xfb6f,
86 0xfb75, 0xf200, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf200,
87 0xfb6b, 0xf200, 0xf200, 0xf200, 0xf200, 0xfb6e, 0xfb6d, 0xf200,
88 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
89 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
90 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
91 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
92 0xf200, 0xf200, 0xf90a, 0xf90b, 0xf90c, 0xf90d, 0xf90e, 0xf90f,
93 0xf910, 0xf911, 0xf200, 0xf912, 0xf913, 0xf200, 0xf200, 0xf200,
94 0xf510, 0xf511, 0xf512, 0xf50e, 0xf513, 0xf514, 0xf200, 0xf516,
95 0xf200, 0xf10c, 0xf200, 0xf202, 0xf200, 0xf515, 0xf200, 0xf517,
96 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf50f, 0xf117,
97 0xf50d, 0xf119, 0xf50c, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
98 };
99
100 static u_short macctrl_map[NR_KEYS] = {
101 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
102 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
103 0xf019, 0xf014, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01e, 0xf01d,
104 0xf200, 0xf200, 0xf01f, 0xf01f, 0xf07f, 0xf200, 0xf01d, 0xf00f,
105 0xf015, 0xf01b, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf007,
106 0xf00b, 0xf200, 0xf01c, 0xf200, 0xf07f, 0xf00e, 0xf00d, 0xf20e,
107 0xf200, 0xf000, 0xf000, 0xf008, 0xf200, 0xf200, 0xf702, 0xf703,
108 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
109 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
110 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
111 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
112 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
113 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
114 0xf200, 0xf10c, 0xf200, 0xf204, 0xf200, 0xf109, 0xf200, 0xf10b,
115 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
116 0xf101, 0xf119, 0xf100, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
117 };
118
119 static u_short macshift_ctrl_map[NR_KEYS] = {
120 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
121 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
122 0xf019, 0xf014, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
123 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200, 0xf00f,
124 0xf015, 0xf200, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf200,
125 0xf00b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf00e, 0xf00d, 0xf200,
126 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
127 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
128 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
129 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
130 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
131 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
132 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
133 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
134 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf200, 0xf117,
135 0xf200, 0xf119, 0xf200, 0xf700, 0xf701, 0xf702, 0xf200, 0xf20c,
136 };
137
138 static u_short macalt_map[NR_KEYS] = {
139 0xf861, 0xf873, 0xf864, 0xf866, 0xf868, 0xf867, 0xf87a, 0xf878,
140 0xf863, 0xf876, 0xf200, 0xf862, 0xf871, 0xf877, 0xf865, 0xf872,
141 0xf879, 0xf874, 0xf831, 0xf832, 0xf833, 0xf834, 0xf836, 0xf835,
142 0xf83d, 0xf839, 0xf837, 0xf82d, 0xf838, 0xf830, 0xf85d, 0xf86f,
143 0xf875, 0xf85b, 0xf869, 0xf870, 0xf80d, 0xf86c, 0xf86a, 0xf827,
144 0xf86b, 0xf83b, 0xf85c, 0xf82c, 0xf82f, 0xf86e, 0xf86d, 0xf82e,
145 0xf809, 0xf820, 0xf860, 0xf87f, 0xf200, 0xf81b, 0xf702, 0xf703,
146 0xf700, 0xf207, 0xf701, 0xf210, 0xf211, 0xf600, 0xf603, 0xf200,
147 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
148 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
149 0xf200, 0xf200, 0xf900, 0xf901, 0xf902, 0xf903, 0xf904, 0xf905,
150 0xf906, 0xf907, 0xf200, 0xf908, 0xf909, 0xf200, 0xf200, 0xf200,
151 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
152 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf509, 0xf200, 0xf50b,
153 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
154 0xf501, 0xf119, 0xf500, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
155 };
156
157 static u_short macctrl_alt_map[NR_KEYS] = {
158 0xf801, 0xf813, 0xf804, 0xf806, 0xf808, 0xf807, 0xf81a, 0xf818,
159 0xf803, 0xf816, 0xf200, 0xf802, 0xf811, 0xf817, 0xf805, 0xf812,
160 0xf819, 0xf814, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
161 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80f,
162 0xf815, 0xf200, 0xf809, 0xf810, 0xf201, 0xf80c, 0xf80a, 0xf200,
163 0xf80b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80e, 0xf80d, 0xf200,
164 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
165 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
166 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
167 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
168 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
169 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
170 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
171 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf509, 0xf200, 0xf50b,
172 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
173 0xf501, 0xf119, 0xf500, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
174 };
175
176 static unsigned short *mac_key_maps_save[MAX_NR_KEYMAPS] = {
177 macplain_map, macshift_map, macaltgr_map, 0,
178 macctrl_map, macshift_ctrl_map, 0, 0,
179 macalt_map, 0, 0, 0,
180 macctrl_alt_map, 0
181 };
182
183 static unsigned short *pc_key_maps_save[MAX_NR_KEYMAPS];
184
185 int mac_hid_kbd_translate(unsigned char keycode, unsigned char *keycodep,
186 char raw_mode);
187 static int mac_hid_sysctl_keycodes(ctl_table *ctl, int write, struct file * filp,
188 void *buffer, size_t *lenp);
189 char mac_hid_kbd_unexpected_up(unsigned char keycode);
190
191 static int keyboard_lock_keycodes = 0;
192 int keyboard_sends_linux_keycodes = 0;
193 #else
194 int keyboard_sends_linux_keycodes = 1;
195 #endif
196
197
198 static unsigned char e0_keys[128] = {
199 0, 0, 0, KEY_KPCOMMA, 0, KEY_INTL3, 0, 0, /* 0x00-0x07 */
200 0, 0, 0, 0, KEY_LANG1, KEY_LANG2, 0, 0, /* 0x08-0x0f */
201 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x17 */
202 0, 0, 0, 0, KEY_KPENTER, KEY_RIGHTCTRL, 0, 0, /* 0x18-0x1f */
203 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x27 */
204 0, 0, 0, 0, 0, 0, 0, 0, /* 0x28-0x2f */
205 0, 0, 0, 0, 0, KEY_KPSLASH, 0, KEY_SYSRQ, /* 0x30-0x37 */
206 KEY_RIGHTALT, 0, 0, 0, 0, 0, 0, 0, /* 0x38-0x3f */
207 0, 0, 0, 0, 0, 0, 0, KEY_HOME, /* 0x40-0x47 */
208 KEY_UP, KEY_PAGEUP, 0, KEY_LEFT, 0, KEY_RIGHT, 0, KEY_END, /* 0x48-0x4f */
209 KEY_DOWN, KEY_PAGEDOWN, KEY_INSERT, KEY_DELETE, 0, 0, 0, 0, /* 0x50-0x57 */
210 0, 0, 0, KEY_LEFTMETA, KEY_RIGHTMETA, KEY_COMPOSE, 0, 0, /* 0x58-0x5f */
211 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
212 0, 0, 0, 0, 0, 0, 0, KEY_MACRO, /* 0x68-0x6f */
213 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x77 */
214 0, 0, 0, 0, 0, 0, 0, 0 /* 0x78-0x7f */
215 };
216
217 #ifdef CONFIG_MAC_EMUMOUSEBTN
218 static struct input_dev emumousebtn;
219 static void emumousebtn_input_register(void);
220 static int mouse_emulate_buttons = 0;
221 static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
222 static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
223 static int mouse_last_keycode = 0;
224 #endif
225
226 extern void pckbd_init_hw(void);
227
228 #if defined CONFIG_SYSCTL && (defined(CONFIG_MAC_ADBKEYCODES) || defined(CONFIG_MAC_EMUMOUSEBTN))
229 /* file(s) in /proc/sys/dev/mac_hid */
230 ctl_table mac_hid_files[] =
231 {
232 #ifdef CONFIG_MAC_ADBKEYCODES
233 {
234 DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES,
235 "keyboard_sends_linux_keycodes", &keyboard_sends_linux_keycodes, sizeof(int),
236 0644, NULL, &mac_hid_sysctl_keycodes
237 },
238 {
239 DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES,
240 "keyboard_lock_keycodes", &keyboard_lock_keycodes, sizeof(int),
241 0644, NULL, &proc_dointvec
242 },
243 #endif
244 #ifdef CONFIG_MAC_EMUMOUSEBTN
245 {
246 DEV_MAC_HID_MOUSE_BUTTON_EMULATION,
247 "mouse_button_emulation", &mouse_emulate_buttons, sizeof(int),
248 0644, NULL, &proc_dointvec
249 },
250 {
251 DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,
252 "mouse_button2_keycode", &mouse_button2_keycode, sizeof(int),
253 0644, NULL, &proc_dointvec
254 },
255 {
256 DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,
257 "mouse_button3_keycode", &mouse_button3_keycode, sizeof(int),
258 0644, NULL, &proc_dointvec
259 },
260 #endif
261 { 0 }
262 };
263
264 /* dir in /proc/sys/dev */
265 ctl_table mac_hid_dir[] =
266 {
267 { DEV_MAC_HID, "mac_hid", NULL, 0, 0555, mac_hid_files },
268 { 0 }
269 };
270
271 /* /proc/sys/dev itself, in case that is not there yet */
272 ctl_table mac_hid_root_dir[] =
273 {
274 { CTL_DEV, "dev", NULL, 0, 0555, mac_hid_dir },
275 { 0 }
276 };
277
278 static struct ctl_table_header *mac_hid_sysctl_header;
279
280 #ifdef CONFIG_MAC_ADBKEYCODES
281 static
282 int mac_hid_sysctl_keycodes(ctl_table *ctl, int write, struct file * filp,
283 void *buffer, size_t *lenp)
284 {
285 int val = keyboard_sends_linux_keycodes;
286 int ret = 0;
287
288 if (!write
289 || (write && !keyboard_lock_keycodes))
290 ret = proc_dointvec(ctl, write, filp, buffer, lenp);
291
292 if (write
293 && keyboard_sends_linux_keycodes != val) {
294 if (!keyboard_sends_linux_keycodes) {
295 #ifdef CONFIG_MAGIC_SYSRQ
296 ppc_md.ppc_kbd_sysrq_xlate = mac_hid_kbd_sysrq_xlate;
297 SYSRQ_KEY = 0x69;
298 #endif
299 memcpy(pc_key_maps_save, key_maps, sizeof(key_maps));
300 memcpy(key_maps, mac_key_maps_save, sizeof(key_maps));
301 } else {
302 #ifdef CONFIG_MAGIC_SYSRQ
303 ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
304 SYSRQ_KEY = 0x54;
305 #endif
306 memcpy(mac_key_maps_save, key_maps, sizeof(key_maps));
307 memcpy(key_maps, pc_key_maps_save, sizeof(key_maps));
308 }
309 }
310
311 return ret;
312 }
313 #endif
314 #endif /* endif CONFIG_SYSCTL */
315
316 int mac_hid_kbd_translate(unsigned char scancode, unsigned char *keycode,
317 char raw_mode)
318 {
319 #ifdef CONFIG_MAC_ADBKEYCODES
320 if (!keyboard_sends_linux_keycodes) {
321 if (!raw_mode) {
322 /*
323 * Convert R-shift/control/option to L version.
324 */
325 switch (scancode) {
326 case 0x7b: scancode = 0x38; break; /* R-shift */
327 case 0x7c: scancode = 0x3a; break; /* R-option */
328 case 0x7d: scancode = 0x36; break; /* R-control */
329 }
330 }
331 *keycode = scancode;
332 return 1;
333 } else
334 #endif
335 {
336 /* This code was copied from char/pc_keyb.c and will be
337 * superflous when the input layer is fully integrated.
338 * We don't need the high_keys handling, so this part
339 * has been removed.
340 */
341 static int prev_scancode = 0;
342
343 /* special prefix scancodes.. */
344 if (scancode == 0xe0 || scancode == 0xe1) {
345 prev_scancode = scancode;
346 return 0;
347 }
348
349 scancode &= 0x7f;
350
351 if (prev_scancode) {
352 if (prev_scancode != 0xe0) {
353 if (prev_scancode == 0xe1 && scancode == 0x1d) {
354 prev_scancode = 0x100;
355 return 0;
356 } else if (prev_scancode == 0x100 && scancode == 0x45) {
357 *keycode = KEY_PAUSE;
358 prev_scancode = 0;
359 } else {
360 if (!raw_mode)
361 printk(KERN_INFO "keyboard: unknown e1 escape sequence\n");
362 prev_scancode = 0;
363 return 0;
364 }
365 } else {
366 prev_scancode = 0;
367 if (scancode == 0x2a || scancode == 0x36)
368 return 0;
369 }
370 if (e0_keys[scancode])
371 *keycode = e0_keys[scancode];
372 else {
373 if (!raw_mode)
374 printk(KERN_INFO "keyboard: unknown scancode e0 %02x\n",
375 scancode);
376 return 0;
377 }
378 } else {
379 switch (scancode) {
380 case 91: scancode = KEY_LINEFEED; break;
381 case 92: scancode = KEY_KPEQUAL; break;
382 case 125: scancode = KEY_INTL1; break;
383 }
384 *keycode = scancode;
385 }
386 return 1;
387 }
388 }
389
390 char mac_hid_kbd_unexpected_up(unsigned char keycode)
391 {
392 if (keyboard_sends_linux_keycodes && keycode == KEY_F13)
393 return 0;
394 else
395 return 0x80;
396 }
397
398 #ifdef CONFIG_MAC_ADBKEYCODES
399 int mac_hid_keyboard_sends_linux_keycodes(void)
400 {
401 return keyboard_sends_linux_keycodes;
402 }
403
404 static int __init mac_hid_setup(char *str)
405 {
406 int ints[2];
407
408 str = get_options(str, ARRAY_SIZE(ints), ints);
409 if (ints[0] == 1) {
410 keyboard_sends_linux_keycodes = ints[1] != 0;
411 keyboard_lock_keycodes = 1;
412 }
413 return 1;
414 }
415
416 __setup("keyboard_sends_linux_keycodes=", mac_hid_setup);
417
418 #endif
419
420 #ifdef CONFIG_MAC_EMUMOUSEBTN
421 int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
422 {
423 switch (caller) {
424 case 1:
425 /* Called from keybdev.c */
426 if (mouse_emulate_buttons
427 && (keycode == mouse_button2_keycode
428 || keycode == mouse_button3_keycode)) {
429 if (mouse_emulate_buttons == 1) {
430 input_report_key(&emumousebtn,
431 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
432 down);
433 return 1;
434 }
435 mouse_last_keycode = down ? keycode : 0;
436 }
437 break;
438 case 2:
439 /* Called from mousedev.c */
440 if (mouse_emulate_buttons == 2 && keycode == 0) {
441 if (mouse_last_keycode == mouse_button2_keycode)
442 return 1; /* map to middle button */
443 if (mouse_last_keycode == mouse_button3_keycode)
444 return 2; /* map to right button */
445 }
446 return keycode; /* keep button */
447 }
448 return 0;
449 }
450
451 static void emumousebtn_input_register(void)
452 {
453 emumousebtn.name = "Macintosh mouse button emulation";
454
455 emumousebtn.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
456 emumousebtn.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
457 emumousebtn.relbit[0] = BIT(REL_X) | BIT(REL_Y);
458
459 emumousebtn.idbus = BUS_ADB;
460 emumousebtn.idvendor = 0x0001;
461 emumousebtn.idproduct = 0x0001;
462 emumousebtn.idversion = 0x0100;
463
464 input_register_device(&emumousebtn);
465
466 printk(KERN_INFO "input%d: Macintosh mouse button emulation\n", emumousebtn.number);
467 }
468 #endif
469
470 void __init mac_hid_init_hw(void)
471 {
472
473 #ifdef CONFIG_MAC_ADBKEYCODES
474 memcpy(pc_key_maps_save, key_maps, sizeof(key_maps));
475
476 if (!keyboard_sends_linux_keycodes)
477 memcpy(key_maps, mac_key_maps_save, sizeof(key_maps));
478 #endif
479
480 #ifdef CONFIG_MAC_EMUMOUSEBTN
481 emumousebtn_input_register();
482 #endif
483
484 #if CONFIG_PPC
485 if (_machine != _MACH_Pmac)
486 pckbd_init_hw();
487 #endif
488
489 #if defined(CONFIG_SYSCTL) && (defined(CONFIG_MAC_ADBKEYCODES) || defined(CONFIG_MAC_EMUMOUSEBTN))
490 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1);
491 #endif /* CONFIG_SYSCTL */
492 }
493
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.