2.2.0-final
[davej-history.git] / arch / m68k / mac / mackeyb.c
blob5a6ae7c75af09ededcb4841fe175b1a0575d7c6d
1 /*
2 * linux/arch/m68k/mac/mackeyb.c
4 * Keyboard driver for Macintosh computers.
6 * Adapted from drivers/macintosh/key_mac.c and arch/m68k/atari/akakeyb.c
7 * (see that file for its authors and contributors).
9 * Copyright (C) 1997 Michael Schmitz.
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive
13 * for more details.
17 * misc. keyboard stuff (everything not in adb-bus.c or keyb_m68k.c)
20 #include <linux/config.h>
21 #include <linux/types.h>
22 #include <linux/mm.h>
23 #include <linux/kd.h>
24 #include <linux/tty.h>
25 #include <linux/console.h>
26 #include <linux/interrupt.h>
27 #include <linux/init.h>
28 /* keyb */
29 #include <linux/keyboard.h>
30 #include <linux/random.h>
31 #include <linux/delay.h>
32 /* keyb */
34 #include <asm/setup.h>
36 #include <asm/system.h>
37 #include <asm/io.h>
38 #include <asm/irq.h>
39 #include <asm/pgtable.h>
40 #include <asm/machdep.h>
42 #include <asm/macintosh.h>
43 #include <asm/macints.h>
44 /* for keyboard_input stuff */
45 #include <asm/adb.h>
46 #define KEYB_KEYREG 0 /* register # for key up/down data */
47 #define KEYB_LEDREG 2 /* register # for leds on ADB keyboard */
48 #define MOUSE_DATAREG 0 /* reg# for movement/button codes from mouse */
49 /* end keyboard_input stuff */
51 #include <linux/kbd_kern.h>
52 #include <linux/kbd_ll.h>
54 static void kbd_repeat(unsigned long);
55 static struct timer_list repeat_timer = { NULL, NULL, 0, 0, kbd_repeat };
56 static int last_keycode;
58 static void input_keycode(int, int);
60 extern struct kbd_struct kbd_table[];
62 extern void adb_bus_init(void);
63 extern void handle_scancode(unsigned char);
64 extern void put_queue(int);
66 /* keyb */
67 static void mac_leds_done(struct adb_request *);
68 static void keyboard_input(unsigned char *, int, struct pt_regs *);
69 static void mouse_input(unsigned char *, int, struct pt_regs *);
71 #ifdef CONFIG_ADBMOUSE
72 /* XXX: Hook for mouse driver */
73 void (*adb_mouse_interrupt_hook)(unsigned char *, int);
74 int adb_emulate_buttons = 0;
75 int adb_button2_keycode = 0x7d; /* right control key */
76 int adb_button3_keycode = 0x7c; /* right option key */
77 #endif
79 /* The mouse driver - for debugging */
80 extern void adb_mouse_interrupt(char *, int);
81 /* end keyb */
83 /* this map indicates which keys shouldn't autorepeat. */
84 static unsigned char dont_repeat[128] = {
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* esc...option */
89 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, /* num lock */
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, /* scroll lock */
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 * Mac private key maps
98 u_short mac_plain_map[NR_KEYS] __initdata = {
99 0xfb61, 0xfb73, 0xfb64, 0xfb66, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
100 0xfb63, 0xfb76, 0xf200, 0xfb62, 0xfb71, 0xfb77, 0xfb65, 0xfb72,
101 0xfb79, 0xfb74, 0xf031, 0xf032, 0xf033, 0xf034, 0xf036, 0xf035,
102 0xf03d, 0xf039, 0xf037, 0xf02d, 0xf038, 0xf030, 0xf05d, 0xfb6f,
103 0xfb75, 0xf05b, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf027,
104 0xfb6b, 0xf03b, 0xf05c, 0xf02c, 0xf02f, 0xfb6e, 0xfb6d, 0xf02e,
105 0xf009, 0xf020, 0xf060, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
106 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
107 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
108 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
109 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
110 0xf306, 0xf307, 0xfb61, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
111 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
112 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf109, 0xf200, 0xf10b,
113 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
114 0xf101, 0xf119, 0xf100, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
117 u_short mac_shift_map[NR_KEYS] __initdata = {
118 0xfb41, 0xfb53, 0xfb44, 0xfb46, 0xfb48, 0xfb47, 0xfb5a, 0xfb58,
119 0xfb43, 0xfb56, 0xf200, 0xfb42, 0xfb51, 0xfb57, 0xfb45, 0xfb52,
120 0xfb59, 0xfb54, 0xf021, 0xf040, 0xf023, 0xf024, 0xf05e, 0xf025,
121 0xf02b, 0xf028, 0xf026, 0xf05f, 0xf02a, 0xf029, 0xf07d, 0xfb4f,
122 0xfb55, 0xf07b, 0xfb49, 0xfb50, 0xf201, 0xfb4c, 0xfb4a, 0xf022,
123 0xfb4b, 0xf03a, 0xf07c, 0xf03c, 0xf03f, 0xfb4e, 0xfb4d, 0xf03e,
124 0xf009, 0xf020, 0xf07e, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
125 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
126 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
127 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
128 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
129 0xf306, 0xf307, 0xfb41, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
130 0xf10e, 0xf10f, 0xf110, 0xf10c, 0xf111, 0xf112, 0xf200, 0xf10a,
131 0xf200, 0xf10c, 0xf200, 0xf203, 0xf200, 0xf113, 0xf200, 0xf10b,
132 0xf200, 0xf11d, 0xf115, 0xf114, 0xf20b, 0xf116, 0xf10d, 0xf117,
133 0xf10b, 0xf20a, 0xf10a, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
136 u_short mac_altgr_map[NR_KEYS] __initdata = {
137 0xf914, 0xfb73, 0xf917, 0xf919, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
138 0xf916, 0xfb76, 0xf200, 0xf915, 0xfb71, 0xfb77, 0xf918, 0xfb72,
139 0xfb79, 0xfb74, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
140 0xf200, 0xf05d, 0xf07b, 0xf05c, 0xf05b, 0xf07d, 0xf07e, 0xfb6f,
141 0xfb75, 0xf200, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf200,
142 0xfb6b, 0xf200, 0xf200, 0xf200, 0xf200, 0xfb6e, 0xfb6d, 0xf200,
143 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
144 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
145 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
146 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
147 0xf200, 0xf200, 0xf90a, 0xf90b, 0xf90c, 0xf90d, 0xf90e, 0xf90f,
148 0xf910, 0xf911, 0xf914, 0xf912, 0xf913, 0xf200, 0xf200, 0xf200,
149 0xf510, 0xf511, 0xf512, 0xf50e, 0xf513, 0xf514, 0xf200, 0xf516,
150 0xf200, 0xf10c, 0xf200, 0xf202, 0xf200, 0xf515, 0xf200, 0xf517,
151 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf50f, 0xf117,
152 0xf50d, 0xf119, 0xf50c, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
155 u_short mac_ctrl_map[NR_KEYS] __initdata = {
156 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
157 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
158 0xf019, 0xf014, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01e, 0xf01d,
159 0xf200, 0xf200, 0xf01f, 0xf01f, 0xf07f, 0xf200, 0xf01d, 0xf00f,
160 0xf015, 0xf01b, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf007,
161 0xf00b, 0xf200, 0xf01c, 0xf200, 0xf07f, 0xf00e, 0xf00d, 0xf20e,
162 0xf200, 0xf000, 0xf000, 0xf008, 0xf200, 0xf200, 0xf702, 0xf703,
163 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
164 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
165 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
166 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
167 0xf306, 0xf307, 0xf001, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
168 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
169 0xf200, 0xf10c, 0xf200, 0xf204, 0xf200, 0xf109, 0xf200, 0xf10b,
170 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
171 0xf101, 0xf119, 0xf100, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
174 u_short mac_shift_ctrl_map[NR_KEYS] __initdata = {
175 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
176 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
177 0xf019, 0xf014, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
178 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200, 0xf00f,
179 0xf015, 0xf200, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf200,
180 0xf00b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf00e, 0xf00d, 0xf200,
181 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
182 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
183 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
184 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
185 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
186 0xf306, 0xf307, 0xf001, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
187 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
188 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
189 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf200, 0xf117,
190 0xf200, 0xf119, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf20c,
193 u_short mac_alt_map[NR_KEYS] __initdata = {
194 0xf861, 0xf873, 0xf864, 0xf866, 0xf868, 0xf867, 0xf87a, 0xf878,
195 0xf863, 0xf876, 0xf200, 0xf862, 0xf871, 0xf877, 0xf865, 0xf872,
196 0xf879, 0xf874, 0xf831, 0xf832, 0xf833, 0xf834, 0xf836, 0xf835,
197 0xf83d, 0xf839, 0xf837, 0xf82d, 0xf838, 0xf830, 0xf85d, 0xf86f,
198 0xf875, 0xf85b, 0xf869, 0xf870, 0xf80d, 0xf86c, 0xf86a, 0xf827,
199 0xf86b, 0xf83b, 0xf85c, 0xf82c, 0xf82f, 0xf86e, 0xf86d, 0xf82e,
200 0xf809, 0xf820, 0xf860, 0xf87f, 0xf200, 0xf81b, 0xf702, 0xf703,
201 0xf700, 0xf207, 0xf701, 0xf210, 0xf211, 0xf600, 0xf603, 0xf200,
202 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
203 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
204 0xf200, 0xf200, 0xf900, 0xf901, 0xf902, 0xf903, 0xf904, 0xf905,
205 0xf906, 0xf907, 0xf861, 0xf908, 0xf909, 0xf200, 0xf200, 0xf200,
206 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
207 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf509, 0xf200, 0xf50b,
208 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
209 0xf501, 0xf119, 0xf500, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
212 u_short mac_ctrl_alt_map[NR_KEYS] __initdata = {
213 0xf801, 0xf813, 0xf804, 0xf806, 0xf808, 0xf807, 0xf81a, 0xf818,
214 0xf803, 0xf816, 0xf200, 0xf802, 0xf811, 0xf817, 0xf805, 0xf812,
215 0xf819, 0xf814, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
216 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80f,
217 0xf815, 0xf200, 0xf809, 0xf810, 0xf201, 0xf80c, 0xf80a, 0xf200,
218 0xf80b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80e, 0xf80d, 0xf200,
219 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
220 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
221 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
222 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
223 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
224 0xf306, 0xf307, 0xf801, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
225 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
226 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf509, 0xf200, 0xf50b,
227 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
228 0xf501, 0xf119, 0xf500, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
231 extern unsigned int keymap_count;
234 * Misc. defines for testing
237 extern int console_loglevel;
239 static struct adb_request led_request;
240 extern int in_keybinit;
243 * machdep keyboard routines, interface and key repeat method modeled after
244 * drivers/macintosh/keyb_mac.c
247 int mac_kbd_translate(unsigned char keycode, unsigned char *keycodep,
248 char raw_mode)
250 if (!raw_mode) {
252 * Convert R-shift/control/option to L version.
253 * Remap keycode 0 (A) to the unused keycode 0x5a.
254 * Other parts of the system assume 0 is not a valid keycode.
256 switch (keycode) {
257 case 0x7b: keycode = 0x38; break; /* R-shift */
258 case 0x7c: keycode = 0x3a; break; /* R-option */
259 case 0x7d: keycode = 0x36; break; /* R-control */
260 case 0: keycode = 0x5a; break; /* A */
263 *keycodep = keycode;
264 return 1;
267 int mac_kbd_unexpected_up(unsigned char keycode)
269 return 0x80;
272 static void
273 keyboard_input(unsigned char *data, int nb, struct pt_regs *regs)
275 /* first check this is from register 0 */
276 if (nb != 5 || (data[2] & 3) != KEYB_KEYREG)
277 return; /* ignore it */
278 kbd_pt_regs = regs;
279 input_keycode(data[3], 0);
280 if (!(data[4] == 0xff || (data[4] == 0x7f && data[3] == 0x7f)))
281 input_keycode(data[4], 0);
284 static void
285 input_keycode(int keycode, int repeat)
287 struct kbd_struct *kbd;
288 int up_flag;
290 kbd = kbd_table + fg_console;
291 up_flag = (keycode & 0x80);
292 keycode &= 0x7f;
294 if (!repeat)
295 del_timer(&repeat_timer);
297 #ifdef CONFIG_ADBMOUSE
299 * XXX: Add mouse button 2+3 fake codes here if mouse open.
300 * As we only report up/down events, keep track of faked buttons.
301 * Really messy; might need to check if keyboard is in
302 * VC_RAW mode for X?.
303 * Might also want to know how many buttons need to be emulated.
304 * -> hide this as function in arch/m68k/mac ?
305 * Current emulation buttons: right alt/option and control
306 * (wanted: command and alt/option, or KP= and KP( ...)
307 * Debug version; might be rewritten to be faster on normal keys.
309 if (adb_emulate_buttons
310 && (adb_mouse_interrupt_hook || console_loglevel >= 8)) {
311 unsigned char button, button2, button3, fake_event;
312 static unsigned char button2state=0, button3state=0; /* up */
313 /* faked ADB packet */
314 static unsigned char data[4] = { 0, 0x80, 0x80, 0x80 };
316 button = 0;
317 fake_event = 0;
318 if (keycode == adb_button2_keycode) { /* which 'button' ? */
319 /* R-option */
320 button2 = (!up_flag); /* new state */
321 if (button2 != button2state) /* change ? */
322 button = 2;
323 button2state = button2; /* save state */
324 fake_event = 2;
325 } else if (keycode == adb_button3_keycode) {
326 /* R-control */
327 button3 = (!up_flag); /* new state */
328 if (button3 != button3state) /* change ? */
329 button = 3;
330 button3state = button3; /* save state */
331 fake_event = 3;
333 #ifdef DEBUG_ADBMOUSE
334 if (fake_event && console_loglevel >= 8)
335 printk("fake event: button2 %d button3 %d button %d\n",
336 button2state, button3state, button);
337 #endif
338 if (button) { /* there's been a button state change */
339 /* fake a mouse packet : send all bytes, change one! */
340 data[button] = (up_flag ? 0x80 : 0);
341 if (adb_mouse_interrupt_hook)
342 adb_mouse_interrupt_hook(data, 4);
343 #ifdef DEBUG_ADBMOUSE
344 else
345 printk("mouse_fake: data %2x %2x %2x buttons %2x \n",
346 data[1], data[2], data[3],
347 ~( (data[1] & 0x80 ? 0 : 4)
348 | (data[2] & 0x80 ? 0 : 1)
349 | (data[3] & 0x80 ? 0 : 2) )&7 );
350 #endif
353 * for mouse 3-button emulation: don't process 'fake' keys!
354 * Keys might autorepeat, and console state gets generally messed
355 * up enough so that selection stops working.
357 if (fake_event)
358 return;
360 #endif /* CONFIG_ADBMOUSE */
363 * Convert R-shift/control/option to L version.
365 switch (keycode) {
366 case 0x7b: keycode = 0x38; break; /* R-shift */
367 case 0x7c: keycode = 0x3a; break; /* R-option */
368 case 0x7d: keycode = 0x36; break; /* R-control */
369 case 0x0: if (kbd->kbdmode != VC_RAW)
370 keycode = 0x5a; /* A; keycode 0 deprecated */
371 break;
374 if (kbd->kbdmode != VC_RAW) {
375 if (!up_flag && !dont_repeat[keycode]) {
376 last_keycode = keycode;
377 repeat_timer.expires = jiffies + (repeat? HZ/15: HZ/2);
378 add_timer(&repeat_timer);
382 * XXX fix caps-lock behaviour by turning the key-up
383 * transition into a key-down transition.
384 * MSch: need to turn each caps-lock event into a down-up
385 * double event (keyboard code assumes caps-lock is a toggle)
386 * 981127: fix LED behavior (kudos atong!)
388 switch (keycode) {
389 case 0x39:
390 handle_scancode(keycode); /* down */
391 up_flag = 0x80; /* see below ... */
392 mark_bh(KEYBOARD_BH);
393 break;
394 case 0x47:
395 mark_bh(KEYBOARD_BH);
396 break;
400 handle_scancode(keycode + up_flag);
403 static void
404 kbd_repeat(unsigned long xxx)
406 unsigned long flags;
408 save_flags(flags);
409 cli();
410 input_keycode(last_keycode, 1);
411 restore_flags(flags);
414 /* [ACA:23-Mar-97] Three button mouse support. This is designed to
415 function with MkLinux DR-2.1 style X servers. It only works with
416 three-button mice that conform to Apple's multi-button mouse
417 protocol. */
420 The X server for MkLinux DR2.1 uses the following unused keycodes to
421 read the mouse:
423 0x7e This indicates that the next two keycodes should be interpreted
424 as mouse information. The first following byte's high bit
425 represents the state of the left button. The lower seven bits
426 represent the x-axis acceleration. The lower seven bits of the
427 second byte represent y-axis acceleration.
429 0x3f The x server interprets this keycode as a middle button
430 release.
432 0xbf The x server interprets this keycode as a middle button
433 depress.
435 0x40 The x server interprets this keycode as a right button
436 release.
438 0xc0 The x server interprets this keycode as a right button
439 depress.
441 NOTES: There should be a better way of handling mice in the X server.
442 The MOUSE_ESCAPE code (0x7e) should be followed by three bytes instead
443 of two. The three mouse buttons should then, in the X server, be read
444 as the high-bits of all three bytes. The x and y motions can still be
445 in the first two bytes. Maybe I'll do this...
449 Handler 4 -- Apple Extended mouse protocol.
451 For Apple's 3-button mouse protocol the data array will contain the
452 following values:
454 BITS COMMENTS
455 data[0] = 0000 0000 ADB packet identifer.
456 data[1] = 0100 0000 Extended protocol register.
457 Bits 6-7 are the device id, which should be 1.
458 Bits 4-5 are resolution which is in "units/inch".
459 The Logitech MouseMan returns these bits clear but it has
460 200/300cpi resolution.
461 Bits 0-3 are unique vendor id.
462 data[2] = 0011 1100 Bits 0-1 should be zero for a mouse device.
463 Bits 2-3 should be 8 + 4.
464 Bits 4-7 should be 3 for a mouse device.
465 data[3] = bxxx xxxx Left button and x-axis motion.
466 data[4] = byyy yyyy Second button and y-axis motion.
467 data[5] = byyy bxxx Third button and fourth button. Y is additional
468 high bits of y-axis motion. XY is additional
469 high bits of x-axis motion.
471 NOTE: data[0] and data[2] are confirmed by the parent function and
472 need not be checked here.
476 Handler 1 -- 100cpi original Apple mouse protocol.
477 Handler 2 -- 200cpi original Apple mouse protocol.
479 For Apple's standard one-button mouse protocol the data array will
480 contain the following values:
482 BITS COMMENTS
483 data[0] = 0000 0000 ADB packet identifer.
484 data[1] = ???? ???? (?)
485 data[2] = ???? ??00 Bits 0-1 should be zero for a mouse device.
486 data[3] = bxxx xxxx First button and x-axis motion.
487 data[4] = byyy yyyy Second button and y-axis motion.
489 NOTE: data[0] is confirmed by the parent function and need not be
490 checked here.
493 static void
494 mouse_input(unsigned char *data, int nb, struct pt_regs *regs)
496 struct kbd_struct *kbd;
497 int i;
499 if (nb < 5 || nb > 6 || (data[2] & 3) != MOUSE_DATAREG) {
500 printk("data from mouse:");
501 for (i = 0; i < nb; ++i)
502 printk(" %x", data[i]);
503 printk("\n");
504 return;
507 if (adb_mouse_interrupt_hook) {
508 adb_mouse_interrupt_hook(data+2, nb-2);
510 * passing the mouse data to i.e. the X server as done for
511 * Xpmac will confuse applications on a sane X server :-)
513 return;
515 #ifdef DEBUG_ADBMOUSE
516 else
517 if (console_loglevel >= 8)
518 printk("mouse_input: data %x %x %x buttons %x dx %d dy %d \n",
519 data[3], data[4], data[5],
520 ~((data[3] & 0x80 ? 0 : 4)
521 | (data[4] & 0x80 ? 0 : 1)
522 | (data[5] & 0x80 ? 0 : 2))&7,
523 ((data[4]&0x7f) < 64 ? (data[4]&0x7f) : (data[4]&0x7f)-128 ),
524 ((data[3]&0x7f) < 64 ? -(data[3]&0x7f) : 128-(data[3]&0x7f) ) );
525 #endif
528 kbd = kbd_table + fg_console;
530 #if 0 /* The entirely insane way of MkLinux handling mouse input */
531 /* Requires put_queue which is static in keyboard.c :-( */
532 /* Only send mouse codes when keyboard is in raw mode. */
533 if (kbd->kbdmode == VC_RAW) {
534 static unsigned char uch_ButtonStateSecond = 0;
535 unsigned char uchButtonSecond;
537 /* Send first button, second button and movement. */
538 put_queue( 0x7e );
539 put_queue( data[3] );
540 put_queue( data[4] );
542 /* [ACA: Are there any two-button ADB mice that use handler 1 or 2?] */
544 /* Store the button state. */
545 uchButtonSecond = (data[4] & 0x80);
547 /* Send second button. */
548 if (uchButtonSecond != uch_ButtonStateSecond) {
549 put_queue( 0x3f | uchButtonSecond );
550 uch_ButtonStateSecond = uchButtonSecond;
553 /* Macintosh 3-button mouse (handler 4). */
554 if ((nb == 6) && (data[1] & 0x40)) {
555 static unsigned char uch_ButtonStateThird = 0;
556 unsigned char uchButtonThird;
558 /* Store the button state for speed. */
559 uchButtonThird = (data[5] & 0x80);
561 /* Send third button. */
562 if (uchButtonThird != uch_ButtonStateThird) {
563 put_queue( 0x40 | uchButtonThird );
564 uch_ButtonStateThird = uchButtonThird;
568 #endif /* insane MkLinux mouse hack */
571 /* Map led flags as defined in kbd_kern.h to bits for Apple keyboard. */
572 static unsigned char mac_ledmap[8] = {
573 0, /* none */
574 4, /* scroll lock */
575 1, /* num lock */
576 5, /* scroll + num lock */
577 2, /* caps lock */
578 6, /* caps + scroll lock */
579 3, /* caps + num lock */
580 7, /* caps + num + scroll lock */
583 static int leds_pending;
585 void mac_kbd_leds(unsigned int leds)
587 if (led_request.got_reply) {
588 #ifdef DEBUG_ADB
589 if (console_loglevel == 10)
590 printk("mac_kbd_leds: got reply, sending request!\n");
591 #endif
592 adb_request(&led_request, mac_leds_done, 4, ADB_PACKET,
593 ADB_WRITEREG(ADB_KEYBOARD, KEYB_LEDREG),
594 0xff, ~mac_ledmap[leds]);
595 } else
596 leds_pending = leds | 0x100;
599 static void mac_leds_done(struct adb_request *req)
601 int leds;
603 if (leds_pending) {
604 leds = leds_pending & 0xff;
605 leds_pending = 0;
606 mac_kbd_leds(leds);
608 mark_bh(KEYBOARD_BH);
611 int mac_kbdrate(struct kbd_repeat *k)
613 return 0;
616 __initfunc(int mac_keyb_init(void))
618 static struct adb_request autopoll_req, confcod_req, mouse_req, readkey_req;
619 volatile int ct;
621 /* setup key map */
622 memcpy(key_maps[0], mac_plain_map, sizeof(plain_map));
623 memcpy(key_maps[1], mac_shift_map, sizeof(plain_map));
624 memcpy(key_maps[2], mac_altgr_map, sizeof(plain_map));
625 memcpy(key_maps[4], mac_ctrl_map, sizeof(plain_map));
626 memcpy(key_maps[5], mac_shift_ctrl_map, sizeof(plain_map));
627 memcpy(key_maps[8], mac_alt_map, sizeof(plain_map));
628 memcpy(key_maps[12], mac_ctrl_alt_map, sizeof(plain_map));
630 /* initialize mouse interrupt hook */
631 adb_mouse_interrupt_hook = NULL;
634 * Might put that someplace else, possibly ....
636 adb_bus_init();
638 /* the input functions ... */
639 adb_register(ADB_KEYBOARD, keyboard_input);
640 adb_register(ADB_MOUSE, mouse_input);
642 /* turn on ADB auto-polling in the CUDA */
645 * Older boxes don't support CUDA_* targets and CUDA commands
646 * instead we emulate them in the adb_request hook to make
647 * the code interfaces saner.
649 * Note XXX: the Linux PMac and this code both assume the
650 * devices are at their primary ids and do not do device
651 * assignment. This isn't ideal. We should fix it to follow
652 * the reassignment specs.
655 if (macintosh_config->adb_type == MAC_ADB_CUDA) {
656 printk("CUDA autopoll on ...\n");
657 adb_request(&autopoll_req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1);
658 ct=0;
659 while (!autopoll_req.got_reply && ++ct<1000)
661 udelay(10);
663 if(ct==1000) {
664 printk("Keyboard timed out.\n");
665 autopoll_req.got_reply = 1;
670 * XXX: all ADB requests now in CUDA format; adb_request takes
671 * care of that for other Macs.
674 printk("Configuring keyboard:\n");
676 udelay(3000);
679 * turn on all leds - the keyboard driver will turn them back off
680 * via mac_kbd_leds if everything works ok!
682 printk("leds on ...\n");
683 adb_request(&led_request, NULL, 4, ADB_PACKET,
684 ADB_WRITEREG(ADB_KEYBOARD, KEYB_LEDREG), 0xff, ~7);
687 * The polling stuff should go away as soon as the ADB driver is stable
689 ct = 0;
690 while (!led_request.got_reply && ++ct<1000)
692 udelay(10);
694 if(ct==1000) {
695 printk("keyboard timed out.\n");
696 led_request.got_reply = 1;
699 #if 1
700 printk("configuring coding mode ...\n");
702 udelay(3000);
705 * get the keyboard to send separate codes for
706 * left and right shift, control, option keys.
708 adb_request(&confcod_req, NULL, 4, ADB_PACKET,
709 ADB_WRITEREG(ADB_KEYBOARD, 3), 0, 3);
711 ct=0;
712 while (!confcod_req.got_reply && ++ct<1000)
714 udelay(10);
716 if(ct==1000) {
717 printk("keyboard timed out.\n");
718 confcod_req.got_reply = 1;
720 #endif
722 #if 0 /* seems to hurt, at least Geert's Mac */
723 printk("Configuring mouse (3-button mode) ...\n");
725 udelay(3000);
728 * XXX: taken from the PPC driver again ...
729 * Try to switch the mouse (id 3) to handler 4, for three-button
730 * mode. (0x20 is Service Request Enable, 0x03 is Device ID).
732 adb_request(&mouse_req, NULL, 4, ADB_PACKET,
733 ADB_WRITEREG(ADB_MOUSE, 3), 0x23, 4 );
735 ct=0;
736 while (!mouse_req.got_reply && ++ct<1000)
738 udelay(10);
740 if(ct==1000)
741 printk("Mouse timed out.\n");
742 #endif
744 #if 0
745 printk("Start polling keyboard ...\n");
748 * get the keyboard to send data back, via the adb_input hook
749 * XXX: was never used properly, and the driver takes care
750 * of polling and timeout retransmits now.
751 * Might be of use if we want to start talking to a specific
752 * device here...
754 adb_request(&readkey_req, NULL, 2, ADB_PACKET,
755 ADB_READREG(ADB_KEYBOARD, KEYB_KEYREG));
756 #endif
758 in_keybinit = 0;
759 printk("keyboard init done\n");
761 return 0;