Import 2.1.116pre2
[davej-history.git] / arch / m68k / mac / mackeyb.c
blob5946a9e8b178f52351c2788520ea431449d4ff1d
1 /*
2 * linux/arch/m68k/mac/mackeyb.c
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
6 * for more details.
7 */
9 /*
10 * misc. keyboard stuff (everything not in adb-bus.c or keyb_m68k.c)
13 #include <linux/types.h>
14 #include <linux/mm.h>
15 #include <linux/kd.h>
16 #include <linux/tty.h>
17 #include <linux/console.h>
18 #include <linux/interrupt.h>
19 #include <linux/init.h>
20 /* keyb */
21 #include <linux/keyboard.h>
22 #include <linux/random.h>
23 #include <linux/delay.h>
24 /* keyb */
26 #include <asm/setup.h>
28 #include <asm/system.h>
29 #include <asm/io.h>
30 #include <asm/irq.h>
31 #include <asm/pgtable.h>
32 #include <asm/machdep.h>
34 #include <asm/macintosh.h>
35 #include <asm/macints.h>
36 /* for keyboard_input stuff */
37 #include <asm/adb.h>
38 #define KEYB_KEYREG 0 /* register # for key up/down data */
39 #define KEYB_LEDREG 2 /* register # for leds on ADB keyboard */
40 #define MOUSE_DATAREG 0 /* reg# for movement/button codes from mouse */
41 /* end keyboard_input stuff */
43 #include <linux/kbd_kern.h>
44 #include <linux/kbd_ll.h>
46 static void kbd_repeat(unsigned long);
47 static struct timer_list repeat_timer = { NULL, NULL, 0, 0, kbd_repeat };
48 static int last_keycode;
50 static void input_keycode(int, int);
52 extern struct kbd_struct kbd_table[];
54 extern void handle_scancode(unsigned char);
55 extern void put_queue(int);
57 /* keyb */
58 static void mac_leds_done(struct adb_request *);
59 static void keyboard_input(unsigned char *, int, struct pt_regs *);
60 static void mouse_input(unsigned char *, int, struct pt_regs *);
61 /* Hook for mouse driver */
62 void (*mac_mouse_interrupt_hook) (char *);
63 int mac_emulate_button2;
64 int mac_emulate_button3;
65 /* The mouse driver - for debugging */
66 extern void mac_mouse_interrupt(char *);
67 /* end keyb */
69 /* this map indicates which keys shouldn't autorepeat. */
70 static unsigned char dont_repeat[128] = {
71 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* esc...option */
75 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, /* num lock */
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, /* scroll lock */
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82 * Mac private key maps
84 u_short mac_plain_map[NR_KEYS] __initdata = {
85 0xfb61, 0xfb73, 0xfb64, 0xfb66, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
86 0xfb63, 0xfb76, 0xf200, 0xfb62, 0xfb71, 0xfb77, 0xfb65, 0xfb72,
87 0xfb79, 0xfb74, 0xf031, 0xf032, 0xf033, 0xf034, 0xf036, 0xf035,
88 0xf03d, 0xf039, 0xf037, 0xf02d, 0xf038, 0xf030, 0xf05d, 0xfb6f,
89 0xfb75, 0xf05b, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf027,
90 0xfb6b, 0xf03b, 0xf05c, 0xf02c, 0xf02f, 0xfb6e, 0xfb6d, 0xf02e,
91 0xf009, 0xf020, 0xf060, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
92 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
93 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
94 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
95 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
96 0xf306, 0xf307, 0xfb61, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
97 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
98 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf109, 0xf200, 0xf10b,
99 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
100 0xf101, 0xf119, 0xf100, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
103 u_short mac_shift_map[NR_KEYS] __initdata = {
104 0xfb41, 0xfb53, 0xfb44, 0xfb46, 0xfb48, 0xfb47, 0xfb5a, 0xfb58,
105 0xfb43, 0xfb56, 0xf200, 0xfb42, 0xfb51, 0xfb57, 0xfb45, 0xfb52,
106 0xfb59, 0xfb54, 0xf021, 0xf040, 0xf023, 0xf024, 0xf05e, 0xf025,
107 0xf02b, 0xf028, 0xf026, 0xf05f, 0xf02a, 0xf029, 0xf07d, 0xfb4f,
108 0xfb55, 0xf07b, 0xfb49, 0xfb50, 0xf201, 0xfb4c, 0xfb4a, 0xf022,
109 0xfb4b, 0xf03a, 0xf07c, 0xf03c, 0xf03f, 0xfb4e, 0xfb4d, 0xf03e,
110 0xf009, 0xf020, 0xf07e, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
111 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
112 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
113 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
114 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
115 0xf306, 0xf307, 0xfb41, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
116 0xf10e, 0xf10f, 0xf110, 0xf10c, 0xf111, 0xf112, 0xf200, 0xf10a,
117 0xf200, 0xf10c, 0xf200, 0xf203, 0xf200, 0xf113, 0xf200, 0xf10b,
118 0xf200, 0xf11d, 0xf115, 0xf114, 0xf20b, 0xf116, 0xf10d, 0xf117,
119 0xf10b, 0xf20a, 0xf10a, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
122 u_short mac_altgr_map[NR_KEYS] __initdata = {
123 0xf914, 0xfb73, 0xf917, 0xf919, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
124 0xf916, 0xfb76, 0xf200, 0xf915, 0xfb71, 0xfb77, 0xf918, 0xfb72,
125 0xfb79, 0xfb74, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
126 0xf200, 0xf05d, 0xf07b, 0xf05c, 0xf05b, 0xf07d, 0xf07e, 0xfb6f,
127 0xfb75, 0xf200, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf200,
128 0xfb6b, 0xf200, 0xf200, 0xf200, 0xf200, 0xfb6e, 0xfb6d, 0xf200,
129 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
130 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
131 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
132 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
133 0xf200, 0xf200, 0xf90a, 0xf90b, 0xf90c, 0xf90d, 0xf90e, 0xf90f,
134 0xf910, 0xf911, 0xf914, 0xf912, 0xf913, 0xf200, 0xf200, 0xf200,
135 0xf510, 0xf511, 0xf512, 0xf50e, 0xf513, 0xf514, 0xf200, 0xf516,
136 0xf200, 0xf10c, 0xf200, 0xf202, 0xf200, 0xf515, 0xf200, 0xf517,
137 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf50f, 0xf117,
138 0xf50d, 0xf119, 0xf50c, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
141 u_short mac_ctrl_map[NR_KEYS] __initdata = {
142 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
143 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
144 0xf019, 0xf014, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01e, 0xf01d,
145 0xf200, 0xf200, 0xf01f, 0xf01f, 0xf07f, 0xf200, 0xf01d, 0xf00f,
146 0xf015, 0xf01b, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf007,
147 0xf00b, 0xf200, 0xf01c, 0xf200, 0xf07f, 0xf00e, 0xf00d, 0xf20e,
148 0xf200, 0xf000, 0xf000, 0xf008, 0xf200, 0xf200, 0xf702, 0xf703,
149 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
150 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
151 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
152 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
153 0xf306, 0xf307, 0xf001, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
154 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
155 0xf200, 0xf10c, 0xf200, 0xf204, 0xf200, 0xf109, 0xf200, 0xf10b,
156 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
157 0xf101, 0xf119, 0xf100, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
160 u_short mac_shift_ctrl_map[NR_KEYS] __initdata = {
161 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
162 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
163 0xf019, 0xf014, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
164 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200, 0xf00f,
165 0xf015, 0xf200, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf200,
166 0xf00b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf00e, 0xf00d, 0xf200,
167 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
168 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
169 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
170 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
171 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
172 0xf306, 0xf307, 0xf001, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
173 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
174 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
175 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf200, 0xf117,
176 0xf200, 0xf119, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf20c,
179 u_short mac_alt_map[NR_KEYS] __initdata = {
180 0xf861, 0xf873, 0xf864, 0xf866, 0xf868, 0xf867, 0xf87a, 0xf878,
181 0xf863, 0xf876, 0xf200, 0xf862, 0xf871, 0xf877, 0xf865, 0xf872,
182 0xf879, 0xf874, 0xf831, 0xf832, 0xf833, 0xf834, 0xf836, 0xf835,
183 0xf83d, 0xf839, 0xf837, 0xf82d, 0xf838, 0xf830, 0xf85d, 0xf86f,
184 0xf875, 0xf85b, 0xf869, 0xf870, 0xf80d, 0xf86c, 0xf86a, 0xf827,
185 0xf86b, 0xf83b, 0xf85c, 0xf82c, 0xf82f, 0xf86e, 0xf86d, 0xf82e,
186 0xf809, 0xf820, 0xf860, 0xf87f, 0xf200, 0xf81b, 0xf702, 0xf703,
187 0xf700, 0xf207, 0xf701, 0xf210, 0xf211, 0xf600, 0xf603, 0xf200,
188 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
189 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
190 0xf200, 0xf200, 0xf900, 0xf901, 0xf902, 0xf903, 0xf904, 0xf905,
191 0xf906, 0xf907, 0xf861, 0xf908, 0xf909, 0xf200, 0xf200, 0xf200,
192 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
193 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf509, 0xf200, 0xf50b,
194 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
195 0xf501, 0xf119, 0xf500, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
198 u_short mac_ctrl_alt_map[NR_KEYS] __initdata = {
199 0xf801, 0xf813, 0xf804, 0xf806, 0xf808, 0xf807, 0xf81a, 0xf818,
200 0xf803, 0xf816, 0xf200, 0xf802, 0xf811, 0xf817, 0xf805, 0xf812,
201 0xf819, 0xf814, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
202 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80f,
203 0xf815, 0xf200, 0xf809, 0xf810, 0xf201, 0xf80c, 0xf80a, 0xf200,
204 0xf80b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80e, 0xf80d, 0xf200,
205 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
206 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
207 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
208 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
209 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
210 0xf306, 0xf307, 0xf801, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
211 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
212 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf509, 0xf200, 0xf50b,
213 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
214 0xf501, 0xf119, 0xf500, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
217 extern unsigned int keymap_count;
220 * Misc. defines for testing
223 extern int console_loglevel;
225 static struct adb_request led_request;
226 extern int in_keybinit;
229 * machdep keyboard routines, interface and key repeat method modeled after
230 * drivers/macintosh/keyb_mac.c
233 int mac_kbd_translate(unsigned char keycode, unsigned char *keycodep,
234 char raw_mode)
236 if (!raw_mode) {
238 * Convert R-shift/control/option to L version.
239 * Remap keycode 0 (A) to the unused keycode 0x5a.
240 * Other parts of the system assume 0 is not a valid keycode.
242 switch (keycode) {
243 case 0x7b: keycode = 0x38; break; /* R-shift */
244 case 0x7c: keycode = 0x3a; break; /* R-option */
245 case 0x7d: keycode = 0x36; break; /* R-control */
246 case 0: keycode = 0x5a; break; /* A */
249 *keycodep = keycode;
250 return 1;
253 int mac_kbd_unexpected_up(unsigned char keycode)
255 return 0x80;
258 static void
259 keyboard_input(unsigned char *data, int nb, struct pt_regs *regs)
261 /* first check this is from register 0 */
262 if (nb != 5 || (data[2] & 3) != KEYB_KEYREG)
263 return; /* ignore it */
264 kbd_pt_regs = regs;
265 input_keycode(data[3], 0);
266 if (!(data[4] == 0xff || (data[4] == 0x7f && data[3] == 0x7f)))
267 input_keycode(data[4], 0);
270 static void
271 input_keycode(int keycode, int repeat)
273 struct kbd_struct *kbd;
274 int up_flag;
276 kbd = kbd_table + fg_console;
277 up_flag = (keycode & 0x80);
278 keycode &= 0x7f;
279 if (!repeat)
280 del_timer(&repeat_timer);
283 * XXX: Add mouse button 2+3 fake codes here if mouse open.
284 * As we only report up/down events, keep track of faked buttons.
285 * Really messy; might need to check if keyboard is in
286 * VC_RAW mode for X?.
287 * Might also want to know how many buttons need to be emulated.
288 * -> hide this as function in arch/m68k/mac ?
289 * Current emulation buttons: right alt/option and control
290 * (wanted: command and alt/option, or KP= and KP( ...)
291 * Debug version; might be rewritten to be faster on normal keys.
293 if (mac_mouse_interrupt_hook || console_loglevel >= 8) {
294 unsigned char button, button2, button3, fake_event;
295 static unsigned char button2state=0, button3state=0; /* up */
296 /* faked ADB packet: device type ff, handler 4 ! */
297 static char data[6] = { 0xff, 0x40, 0x3c, 0x80, 0x80, 0x80 };
299 button = 0;
300 fake_event = 0;
301 switch (keycode) { /* which 'button' ? */
302 case 0x7c: /* R-option */
303 button2 = (!up_flag); /* new state */
304 if (button2 != button2state) /* change ? */
305 button = 2;
306 button2state = button2; /* save state */
307 fake_event = 2;
308 break;
309 case 0x7d: /* R-control */
310 button3 = (!up_flag); /* new state */
311 if (button3 != button3state) /* change ? */
312 button = 3;
313 button3state = button3; /* save state */
314 fake_event = 3;
315 break;
317 #ifdef DEBUG_ADBMOUSE
318 if (fake_event && console_loglevel >= 8)
319 printk("fake event: button2 %d button3 %d button %d\n",
320 button2state, button3state, button);
321 #endif
322 if (button) { /* there's been a button state change */
323 /* fake a mouse packet : send all bytes, change one! */
324 data[button+2] = (up_flag ? 0x80 : 0);
325 if (mac_mouse_interrupt_hook)
326 mac_mouse_interrupt_hook(data);
327 #ifdef DEBUG_ADBMOUSE
328 else
329 printk("mouse_fake: data %2x %2x %2x buttons %2x \n",
330 data[3], data[4], data[5],
331 ~( (data[3] & 0x80 ? 0 : 4)
332 | (data[4] & 0x80 ? 0 : 1)
333 | (data[5] & 0x80 ? 0 : 2) )&7 );
334 #endif
337 * for mouse 3-button emulation: don't process 'fake' keys!
338 * Keys might autorepeat, and console state gets generally messed
339 * up enough so that selection stops working.
341 if (fake_event)
342 return;
346 * Convert R-shift/control/option to L version.
348 switch (keycode) {
349 case 0x7b: keycode = 0x38; break; /* R-shift */
350 case 0x7c: keycode = 0x3a; break; /* R-option */
351 case 0x7d: keycode = 0x36; break; /* R-control */
352 case 0x0: if (kbd->kbdmode != VC_RAW)
353 keycode = 0x5a; /* A; keycode 0 deprecated */
354 break;
357 if (kbd->kbdmode != VC_RAW) {
358 if (!up_flag && !dont_repeat[keycode]) {
359 last_keycode = keycode;
360 repeat_timer.expires = jiffies + (repeat? HZ/15: HZ/2);
361 add_timer(&repeat_timer);
365 * XXX fix caps-lock behaviour by turning the key-up
366 * transition into a key-down transition.
367 * MSch: need to turn each caps-lock event into a down-up
368 * double event (keyboard code assumes caps-lock is a toggle)
370 #if 0
371 if (keycode == 0x39 && up_flag && vc_kbd_led(kbd, VC_CAPSLOCK))
372 up_flag = 0;
373 #else
374 if (keycode == 0x39) {
375 handle_scancode(keycode); /* down */
376 up_flag = 0x80; /* see below ... */
378 #endif
381 handle_scancode(keycode + up_flag);
384 static void
385 kbd_repeat(unsigned long xxx)
387 unsigned long flags;
389 save_flags(flags);
390 cli();
391 input_keycode(last_keycode, 1);
392 restore_flags(flags);
395 /* [ACA:23-Mar-97] Three button mouse support. This is designed to
396 function with MkLinux DR-2.1 style X servers. It only works with
397 three-button mice that conform to Apple's multi-button mouse
398 protocol. */
401 The X server for MkLinux DR2.1 uses the following unused keycodes to
402 read the mouse:
404 0x7e This indicates that the next two keycodes should be interpreted
405 as mouse information. The first following byte's high bit
406 represents the state of the left button. The lower seven bits
407 represent the x-axis acceleration. The lower seven bits of the
408 second byte represent y-axis acceleration.
410 0x3f The x server interprets this keycode as a middle button
411 release.
413 0xbf The x server interprets this keycode as a middle button
414 depress.
416 0x40 The x server interprets this keycode as a right button
417 release.
419 0xc0 The x server interprets this keycode as a right button
420 depress.
422 NOTES: There should be a better way of handling mice in the X server.
423 The MOUSE_ESCAPE code (0x7e) should be followed by three bytes instead
424 of two. The three mouse buttons should then, in the X server, be read
425 as the high-bits of all three bytes. The x and y motions can still be
426 in the first two bytes. Maybe I'll do this...
430 Handler 4 -- Apple Extended mouse protocol.
432 For Apple's 3-button mouse protocol the data array will contain the
433 following values:
435 BITS COMMENTS
436 data[0] = 0000 0000 ADB packet identifer.
437 data[1] = 0100 0000 Extended protocol register.
438 Bits 6-7 are the device id, which should be 1.
439 Bits 4-5 are resolution which is in "units/inch".
440 The Logitech MouseMan returns these bits clear but it has
441 200/300cpi resolution.
442 Bits 0-3 are unique vendor id.
443 data[2] = 0011 1100 Bits 0-1 should be zero for a mouse device.
444 Bits 2-3 should be 8 + 4.
445 Bits 4-7 should be 3 for a mouse device.
446 data[3] = bxxx xxxx Left button and x-axis motion.
447 data[4] = byyy yyyy Second button and y-axis motion.
448 data[5] = byyy bxxx Third button and fourth button. Y is additional
449 high bits of y-axis motion. XY is additional
450 high bits of x-axis motion.
452 NOTE: data[0] and data[2] are confirmed by the parent function and
453 need not be checked here.
457 Handler 1 -- 100cpi original Apple mouse protocol.
458 Handler 2 -- 200cpi original Apple mouse protocol.
460 For Apple's standard one-button mouse protocol the data array will
461 contain the following values:
463 BITS COMMENTS
464 data[0] = 0000 0000 ADB packet identifer.
465 data[1] = ???? ???? (?)
466 data[2] = ???? ??00 Bits 0-1 should be zero for a mouse device.
467 data[3] = bxxx xxxx First button and x-axis motion.
468 data[4] = byyy yyyy Second button and y-axis motion.
470 NOTE: data[0] is confirmed by the parent function and need not be
471 checked here.
474 static void
475 mouse_input(unsigned char *data, int nb, struct pt_regs *regs)
477 struct kbd_struct *kbd;
478 int i;
480 if (nb < 5 || nb > 6 || (data[2] & 3) != MOUSE_DATAREG) {
481 printk("data from mouse:");
482 for (i = 0; i < nb; ++i)
483 printk(" %x", data[i]);
484 printk("\n");
485 return;
488 if (mac_mouse_interrupt_hook) {
489 mac_mouse_interrupt_hook(data);
491 * passing the mouse data to i.e. the X server as done for
492 * Xpmac will confuse applications on a sane X server :-)
494 return;
496 #ifdef DEBUG_ADBMOUSE
497 else
498 if (console_loglevel >= 8)
499 printk("mouse_input: data %x %x %x buttons %x dx %d dy %d \n",
500 data[3], data[4], data[5],
501 ~((data[3] & 0x80 ? 0 : 4)
502 | (data[4] & 0x80 ? 0 : 1)
503 | (data[5] & 0x80 ? 0 : 2))&7,
504 ((data[4]&0x7f) < 64 ? (data[4]&0x7f) : (data[4]&0x7f)-128 ),
505 ((data[3]&0x7f) < 64 ? -(data[3]&0x7f) : 128-(data[3]&0x7f) ) );
506 #endif
509 kbd = kbd_table + fg_console;
511 #if 0 /* The entirely insane way of MkLinux handling mouse input */
512 /* Requires put_queue which is static in keyboard.c :-( */
513 /* Only send mouse codes when keyboard is in raw mode. */
514 if (kbd->kbdmode == VC_RAW) {
515 static unsigned char uch_ButtonStateSecond = 0;
516 unsigned char uchButtonSecond;
518 /* Send first button, second button and movement. */
519 put_queue( 0x7e );
520 put_queue( data[3] );
521 put_queue( data[4] );
523 /* [ACA: Are there any two-button ADB mice that use handler 1 or 2?] */
525 /* Store the button state. */
526 uchButtonSecond = (data[4] & 0x80);
528 /* Send second button. */
529 if (uchButtonSecond != uch_ButtonStateSecond) {
530 put_queue( 0x3f | uchButtonSecond );
531 uch_ButtonStateSecond = uchButtonSecond;
534 /* Macintosh 3-button mouse (handler 4). */
535 if ((nb == 6) && (data[1] & 0x40)) {
536 static unsigned char uch_ButtonStateThird = 0;
537 unsigned char uchButtonThird;
539 /* Store the button state for speed. */
540 uchButtonThird = (data[5] & 0x80);
542 /* Send third button. */
543 if (uchButtonThird != uch_ButtonStateThird) {
544 put_queue( 0x40 | uchButtonThird );
545 uch_ButtonStateThird = uchButtonThird;
549 #endif /* insane MkLinux mouse hack */
552 /* Map led flags as defined in kbd_kern.h to bits for Apple keyboard. */
553 static unsigned char mac_ledmap[8] = {
554 0, /* none */
555 4, /* scroll lock */
556 1, /* num lock */
557 5, /* scroll + num lock */
558 2, /* caps lock */
559 6, /* caps + scroll lock */
560 3, /* caps + num lock */
561 7, /* caps + num + scroll lock */
564 static int leds_pending;
566 void mac_kbd_leds(unsigned int leds)
568 if (led_request.got_reply) {
569 #ifdef DEBUG_ADB
570 if (console_loglevel == 10)
571 printk("mac_kbd_leds: got reply, sending request!\n");
572 #endif
573 adb_request(&led_request, mac_leds_done, 4, ADB_PACKET,
574 ADB_WRITEREG(ADB_KEYBOARD, KEYB_LEDREG),
575 0xff, ~mac_ledmap[leds]);
576 } else
577 leds_pending = leds | 0x100;
580 static void mac_leds_done(struct adb_request *req)
582 int leds;
584 if (leds_pending) {
585 leds = leds_pending & 0xff;
586 leds_pending = 0;
587 mac_kbd_leds(leds);
589 mark_bh(KEYBOARD_BH);
592 int mac_kbdrate(struct kbd_repeat *k)
594 return 0;
597 __initfunc(int mac_keyb_init(void))
599 static struct adb_request autopoll_req, confcod_req, mouse_req, readkey_req;
600 volatile int ct;
602 /* setup key map */
603 memcpy(key_maps[0], mac_plain_map, sizeof(plain_map));
604 memcpy(key_maps[1], mac_shift_map, sizeof(plain_map));
605 memcpy(key_maps[2], mac_altgr_map, sizeof(plain_map));
606 memcpy(key_maps[4], mac_ctrl_map, sizeof(plain_map));
607 memcpy(key_maps[5], mac_shift_ctrl_map, sizeof(plain_map));
608 memcpy(key_maps[8], mac_alt_map, sizeof(plain_map));
609 memcpy(key_maps[12], mac_ctrl_alt_map, sizeof(plain_map));
611 /* initialize mouse interrupt hook */
612 mac_mouse_interrupt_hook = NULL;
613 /* assume broken mouse :-) */
614 mac_emulate_button2 = 1;
615 mac_emulate_button3 = 1;
618 * Might put that someplace else, possibly ....
620 adb_bus_init();
622 /* the input functions ... */
623 adb_register(ADB_KEYBOARD, keyboard_input);
624 adb_register(ADB_MOUSE, mouse_input);
626 /* turn on ADB auto-polling in the CUDA */
629 * Older boxes don't support CUDA_* targets and CUDA commands
630 * instead we emulate them in the adb_request hook to make
631 * the code interfaces saner.
633 * Note XXX: the Linux PMac and this code both assume the
634 * devices are at their primary ids and do not do device
635 * assignment. This isn't ideal. We should fix it to follow
636 * the reassignment specs.
639 if (macintosh_config->adb_type == MAC_ADB_CUDA) {
640 printk("CUDA autopoll on ...\n");
641 adb_request(&autopoll_req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1);
642 ct=0;
643 while (!autopoll_req.got_reply && ++ct<1000)
645 udelay(10);
647 if(ct==1000) {
648 printk("Keyboard timed out.\n");
649 autopoll_req.got_reply = 1;
654 * XXX: all ADB requests now in CUDA format; adb_request takes
655 * care of that for other Macs.
658 printk("Configuring keyboard:\n");
661 * turn on all leds - the keyboard driver will turn them back off
662 * via mac_kbd_leds if everything works ok!
664 printk("leds on ...\n");
665 adb_request(&led_request, NULL, 4, ADB_PACKET,
666 ADB_WRITEREG(ADB_KEYBOARD, KEYB_LEDREG), 0xff, ~7);
669 * The polling stuff should go away as soon as the ADB driver is stable
671 ct = 0;
672 while (!led_request.got_reply && ++ct<1000)
674 udelay(10);
676 if(ct==1000) {
677 printk("keyboard timed out.\n");
678 led_request.got_reply = 1;
681 #if 1
682 printk("configuring coding mode ...\n");
685 * get the keyboard to send separate codes for
686 * left and right shift, control, option keys.
688 adb_request(&confcod_req, NULL, 4, ADB_PACKET,
689 ADB_WRITEREG(ADB_KEYBOARD, 3), 0, 3);
691 ct=0;
692 while (!confcod_req.got_reply && ++ct<1000)
694 udelay(10);
696 if(ct==1000) {
697 printk("keyboard timed out.\n");
698 confcod_req.got_reply = 1;
700 #endif
702 #if 0 /* seems to hurt, at least Geert's Mac */
703 printk("Configuring mouse (3-button mode) ...\n");
706 * XXX: taken from the PPC driver again ...
707 * Try to switch the mouse (id 3) to handler 4, for three-button
708 * mode. (0x20 is Service Request Enable, 0x03 is Device ID).
710 adb_request(&mouse_req, NULL, 4, ADB_PACKET,
711 ADB_WRITEREG(ADB_MOUSE, 3), 0x23, 4 );
713 ct=0;
714 while (!mouse_req.got_reply && ++ct<1000)
716 udelay(10);
718 if(ct==1000)
719 printk("Mouse timed out.\n");
720 #endif
722 #if 0
723 printk("Start polling keyboard ...\n");
726 * get the keyboard to send data back, via the adb_input hook
727 * XXX: was never used properly, and the driver takes care
728 * of polling and timeout retransmits now.
729 * Might be of use if we want to start talking to a specific
730 * device here...
732 adb_request(&readkey_req, NULL, 2, ADB_PACKET,
733 ADB_READREG(ADB_KEYBOARD, KEYB_KEYREG));
734 #endif
736 in_keybinit = 0;
737 printk("keyboard init done\n");
739 return 0;
742 /* for "kbd-reset" cmdline param */
743 __initfunc(void mac_kbd_reset_setup(char *str, int *ints))
747 /* for "kbd-reset" cmdline param */
748 __initfunc(void mac_kbd_reset_setup(char *str, int *ints))