Input: fix misspelling of Hangeul key
[safe/jmp/linux-2.6] / drivers / macintosh / adbhid.c
1 /*
2  * drivers/input/adbhid.c
3  *
4  * ADB HID driver for Power Macintosh computers.
5  *
6  * Adapted from drivers/macintosh/mac_keyb.c by Franz Sirl.
7  * drivers/macintosh/mac_keyb.c was Copyright (C) 1996 Paul Mackerras
8  * with considerable contributions from Ben Herrenschmidt and others.
9  *
10  * Copyright (C) 2000 Franz Sirl.
11  *
12  * Adapted to ADB changes and support for more devices by
13  * Benjamin Herrenschmidt. Adapted from code in MkLinux
14  * and reworked.
15  * 
16  * Supported devices:
17  *
18  * - Standard 1 button mouse
19  * - All standard Apple Extended protocol (handler ID 4)
20  * - mouseman and trackman mice & trackballs 
21  * - PowerBook Trackpad (default setup: enable tapping)
22  * - MicroSpeed mouse & trackball (needs testing)
23  * - CH Products Trackball Pro (needs testing)
24  * - Contour Design (Contour Mouse)
25  * - Hunter digital (NoHandsMouse)
26  * - Kensignton TurboMouse 5 (needs testing)
27  * - Mouse Systems A3 mice and trackballs <aidan@kublai.com>
28  * - MacAlly 2-buttons mouse (needs testing) <pochini@denise.shiny.it>
29  *
30  * To do:
31  *
32  * Improve Kensington support.
33  * Split mouse/kbd
34  * Move to syfs
35  */
36
37 #include <linux/config.h>
38 #include <linux/module.h>
39 #include <linux/slab.h>
40 #include <linux/init.h>
41 #include <linux/notifier.h>
42 #include <linux/input.h>
43
44 #include <linux/adb.h>
45 #include <linux/cuda.h>
46 #include <linux/pmu.h>
47
48 #include <asm/machdep.h>
49 #ifdef CONFIG_PPC_PMAC
50 #include <asm/pmac_feature.h>
51 #endif
52
53 #ifdef CONFIG_PMAC_BACKLIGHT
54 #include <asm/backlight.h>
55 #endif
56
57 MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>");
58
59 #define KEYB_KEYREG     0       /* register # for key up/down data */
60 #define KEYB_LEDREG     2       /* register # for leds on ADB keyboard */
61 #define MOUSE_DATAREG   0       /* reg# for movement/button codes from mouse */
62
63 static int adb_message_handler(struct notifier_block *, unsigned long, void *);
64 static struct notifier_block adbhid_adb_notifier = {
65         .notifier_call  = adb_message_handler,
66 };
67
68 /* Some special keys */
69 #define ADB_KEY_DEL             0x33
70 #define ADB_KEY_CMD             0x37
71 #define ADB_KEY_CAPSLOCK        0x39
72 #define ADB_KEY_FN              0x3f
73 #define ADB_KEY_FWDEL           0x75
74 #define ADB_KEY_POWER_OLD       0x7e
75 #define ADB_KEY_POWER           0x7f
76
77 u8 adb_to_linux_keycodes[128] = {
78         /* 0x00 */ KEY_A,               /*  30 */
79         /* 0x01 */ KEY_S,               /*  31 */
80         /* 0x02 */ KEY_D,               /*  32 */
81         /* 0x03 */ KEY_F,               /*  33 */
82         /* 0x04 */ KEY_H,               /*  35 */
83         /* 0x05 */ KEY_G,               /*  34 */
84         /* 0x06 */ KEY_Z,               /*  44 */
85         /* 0x07 */ KEY_X,               /*  45 */
86         /* 0x08 */ KEY_C,               /*  46 */
87         /* 0x09 */ KEY_V,               /*  47 */
88         /* 0x0a */ KEY_102ND,           /*  86 */
89         /* 0x0b */ KEY_B,               /*  48 */
90         /* 0x0c */ KEY_Q,               /*  16 */
91         /* 0x0d */ KEY_W,               /*  17 */
92         /* 0x0e */ KEY_E,               /*  18 */
93         /* 0x0f */ KEY_R,               /*  19 */
94         /* 0x10 */ KEY_Y,               /*  21 */
95         /* 0x11 */ KEY_T,               /*  20 */
96         /* 0x12 */ KEY_1,               /*   2 */
97         /* 0x13 */ KEY_2,               /*   3 */
98         /* 0x14 */ KEY_3,               /*   4 */
99         /* 0x15 */ KEY_4,               /*   5 */
100         /* 0x16 */ KEY_6,               /*   7 */
101         /* 0x17 */ KEY_5,               /*   6 */
102         /* 0x18 */ KEY_EQUAL,           /*  13 */
103         /* 0x19 */ KEY_9,               /*  10 */
104         /* 0x1a */ KEY_7,               /*   8 */
105         /* 0x1b */ KEY_MINUS,           /*  12 */
106         /* 0x1c */ KEY_8,               /*   9 */
107         /* 0x1d */ KEY_0,               /*  11 */
108         /* 0x1e */ KEY_RIGHTBRACE,      /*  27 */
109         /* 0x1f */ KEY_O,               /*  24 */
110         /* 0x20 */ KEY_U,               /*  22 */
111         /* 0x21 */ KEY_LEFTBRACE,       /*  26 */
112         /* 0x22 */ KEY_I,               /*  23 */
113         /* 0x23 */ KEY_P,               /*  25 */
114         /* 0x24 */ KEY_ENTER,           /*  28 */
115         /* 0x25 */ KEY_L,               /*  38 */
116         /* 0x26 */ KEY_J,               /*  36 */
117         /* 0x27 */ KEY_APOSTROPHE,      /*  40 */
118         /* 0x28 */ KEY_K,               /*  37 */
119         /* 0x29 */ KEY_SEMICOLON,       /*  39 */
120         /* 0x2a */ KEY_BACKSLASH,       /*  43 */
121         /* 0x2b */ KEY_COMMA,           /*  51 */
122         /* 0x2c */ KEY_SLASH,           /*  53 */
123         /* 0x2d */ KEY_N,               /*  49 */
124         /* 0x2e */ KEY_M,               /*  50 */
125         /* 0x2f */ KEY_DOT,             /*  52 */
126         /* 0x30 */ KEY_TAB,             /*  15 */
127         /* 0x31 */ KEY_SPACE,           /*  57 */
128         /* 0x32 */ KEY_GRAVE,           /*  41 */
129         /* 0x33 */ KEY_BACKSPACE,       /*  14 */
130         /* 0x34 */ KEY_KPENTER,         /*  96 */
131         /* 0x35 */ KEY_ESC,             /*   1 */
132         /* 0x36 */ KEY_LEFTCTRL,        /*  29 */
133         /* 0x37 */ KEY_LEFTMETA,        /* 125 */
134         /* 0x38 */ KEY_LEFTSHIFT,       /*  42 */
135         /* 0x39 */ KEY_CAPSLOCK,        /*  58 */
136         /* 0x3a */ KEY_LEFTALT,         /*  56 */
137         /* 0x3b */ KEY_LEFT,            /* 105 */
138         /* 0x3c */ KEY_RIGHT,           /* 106 */
139         /* 0x3d */ KEY_DOWN,            /* 108 */
140         /* 0x3e */ KEY_UP,              /* 103 */
141         /* 0x3f */ 0,
142         /* 0x40 */ 0,
143         /* 0x41 */ KEY_KPDOT,           /*  83 */
144         /* 0x42 */ 0,
145         /* 0x43 */ KEY_KPASTERISK,      /*  55 */
146         /* 0x44 */ 0,
147         /* 0x45 */ KEY_KPPLUS,          /*  78 */
148         /* 0x46 */ 0,
149         /* 0x47 */ KEY_NUMLOCK,         /*  69 */
150         /* 0x48 */ 0,
151         /* 0x49 */ 0,
152         /* 0x4a */ 0,
153         /* 0x4b */ KEY_KPSLASH,         /*  98 */
154         /* 0x4c */ KEY_KPENTER,         /*  96 */
155         /* 0x4d */ 0,
156         /* 0x4e */ KEY_KPMINUS,         /*  74 */
157         /* 0x4f */ 0,
158         /* 0x50 */ 0,
159         /* 0x51 */ KEY_KPEQUAL,         /* 117 */
160         /* 0x52 */ KEY_KP0,             /*  82 */
161         /* 0x53 */ KEY_KP1,             /*  79 */
162         /* 0x54 */ KEY_KP2,             /*  80 */
163         /* 0x55 */ KEY_KP3,             /*  81 */
164         /* 0x56 */ KEY_KP4,             /*  75 */
165         /* 0x57 */ KEY_KP5,             /*  76 */
166         /* 0x58 */ KEY_KP6,             /*  77 */
167         /* 0x59 */ KEY_KP7,             /*  71 */
168         /* 0x5a */ 0,
169         /* 0x5b */ KEY_KP8,             /*  72 */
170         /* 0x5c */ KEY_KP9,             /*  73 */
171         /* 0x5d */ KEY_YEN,             /* 124 */
172         /* 0x5e */ KEY_RO,              /*  89 */
173         /* 0x5f */ KEY_KPCOMMA,         /* 121 */
174         /* 0x60 */ KEY_F5,              /*  63 */
175         /* 0x61 */ KEY_F6,              /*  64 */
176         /* 0x62 */ KEY_F7,              /*  65 */
177         /* 0x63 */ KEY_F3,              /*  61 */
178         /* 0x64 */ KEY_F8,              /*  66 */
179         /* 0x65 */ KEY_F9,              /*  67 */
180         /* 0x66 */ KEY_HANJA,           /* 123 */
181         /* 0x67 */ KEY_F11,             /*  87 */
182         /* 0x68 */ KEY_HANGEUL,         /* 122 */
183         /* 0x69 */ KEY_SYSRQ,           /*  99 */
184         /* 0x6a */ 0,
185         /* 0x6b */ KEY_SCROLLLOCK,      /*  70 */
186         /* 0x6c */ 0,
187         /* 0x6d */ KEY_F10,             /*  68 */
188         /* 0x6e */ KEY_COMPOSE,         /* 127 */
189         /* 0x6f */ KEY_F12,             /*  88 */
190         /* 0x70 */ 0,
191         /* 0x71 */ KEY_PAUSE,           /* 119 */
192         /* 0x72 */ KEY_INSERT,          /* 110 */
193         /* 0x73 */ KEY_HOME,            /* 102 */
194         /* 0x74 */ KEY_PAGEUP,          /* 104 */
195         /* 0x75 */ KEY_DELETE,          /* 111 */
196         /* 0x76 */ KEY_F4,              /*  62 */
197         /* 0x77 */ KEY_END,             /* 107 */
198         /* 0x78 */ KEY_F2,              /*  60 */
199         /* 0x79 */ KEY_PAGEDOWN,        /* 109 */
200         /* 0x7a */ KEY_F1,              /*  59 */
201         /* 0x7b */ KEY_RIGHTSHIFT,      /*  54 */
202         /* 0x7c */ KEY_RIGHTALT,        /* 100 */
203         /* 0x7d */ KEY_RIGHTCTRL,       /*  97 */
204         /* 0x7e */ KEY_RIGHTMETA,       /* 126 */
205         /* 0x7f */ KEY_POWER,           /* 116 */
206 };
207
208 struct adbhid {
209         struct input_dev *input;
210         int id;
211         int default_id;
212         int original_handler_id;
213         int current_handler_id;
214         int mouse_kind;
215         unsigned char *keycode;
216         char name[64];
217         char phys[32];
218         int flags;
219 };
220
221 #define FLAG_FN_KEY_PRESSED     0x00000001
222 #define FLAG_POWER_FROM_FN      0x00000002
223 #define FLAG_EMU_FWDEL_DOWN     0x00000004
224
225 static struct adbhid *adbhid[16];
226
227 static void adbhid_probe(void);
228
229 static void adbhid_input_keycode(int, int, int, struct pt_regs *);
230
231 static void init_trackpad(int id);
232 static void init_trackball(int id);
233 static void init_turbomouse(int id);
234 static void init_microspeed(int id);
235 static void init_ms_a3(int id);
236
237 static struct adb_ids keyboard_ids;
238 static struct adb_ids mouse_ids;
239 static struct adb_ids buttons_ids;
240
241 #ifdef CONFIG_PMAC_BACKLIGHT
242 /* Exported to via-pmu.c */
243 int disable_kernel_backlight = 0;
244 #endif /* CONFIG_PMAC_BACKLIGHT */
245
246 /* Kind of keyboard, see Apple technote 1152  */
247 #define ADB_KEYBOARD_UNKNOWN    0
248 #define ADB_KEYBOARD_ANSI       0x0100
249 #define ADB_KEYBOARD_ISO        0x0200
250 #define ADB_KEYBOARD_JIS        0x0300
251
252 /* Kind of mouse  */
253 #define ADBMOUSE_STANDARD_100   0       /* Standard 100cpi mouse (handler 1) */
254 #define ADBMOUSE_STANDARD_200   1       /* Standard 200cpi mouse (handler 2) */
255 #define ADBMOUSE_EXTENDED       2       /* Apple Extended mouse (handler 4) */
256 #define ADBMOUSE_TRACKBALL      3       /* TrackBall (handler 4) */
257 #define ADBMOUSE_TRACKPAD       4       /* Apple's PowerBook trackpad (handler 4) */
258 #define ADBMOUSE_TURBOMOUSE5    5       /* Turbomouse 5 (previously req. mousehack) */
259 #define ADBMOUSE_MICROSPEED     6       /* Microspeed mouse (&trackball ?), MacPoint */
260 #define ADBMOUSE_TRACKBALLPRO   7       /* Trackball Pro (special buttons) */
261 #define ADBMOUSE_MS_A3          8       /* Mouse systems A3 trackball (handler 3) */
262 #define ADBMOUSE_MACALLY2       9       /* MacAlly 2-button mouse */
263
264 static void
265 adbhid_keyboard_input(unsigned char *data, int nb, struct pt_regs *regs, int apoll)
266 {
267         int id = (data[0] >> 4) & 0x0f;
268
269         if (!adbhid[id]) {
270                 printk(KERN_ERR "ADB HID on ID %d not yet registered, packet %#02x, %#02x, %#02x, %#02x\n",
271                        id, data[0], data[1], data[2], data[3]);
272                 return;
273         }
274
275         /* first check this is from register 0 */
276         if (nb != 3 || (data[0] & 3) != KEYB_KEYREG)
277                 return;         /* ignore it */
278         adbhid_input_keycode(id, data[1], 0, regs);
279         if (!(data[2] == 0xff || (data[2] == 0x7f && data[1] == 0x7f)))
280                 adbhid_input_keycode(id, data[2], 0, regs);
281 }
282
283 static void
284 adbhid_input_keycode(int id, int keycode, int repeat, struct pt_regs *regs)
285 {
286         struct adbhid *ahid = adbhid[id];
287         int up_flag;
288
289         up_flag = (keycode & 0x80);
290         keycode &= 0x7f;
291
292         switch (keycode) {
293         case ADB_KEY_CAPSLOCK: /* Generate down/up events for CapsLock everytime. */
294                 input_regs(ahid->input, regs);
295                 input_report_key(ahid->input, KEY_CAPSLOCK, 1);
296                 input_report_key(ahid->input, KEY_CAPSLOCK, 0);
297                 input_sync(ahid->input);
298                 return;
299 #ifdef CONFIG_PPC_PMAC
300         case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */
301                 switch(pmac_call_feature(PMAC_FTR_GET_MB_INFO,
302                         NULL, PMAC_MB_INFO_MODEL, 0)) {
303                 case PMAC_TYPE_COMET:
304                 case PMAC_TYPE_HOOPER:
305                 case PMAC_TYPE_KANGA:
306                         keycode = ADB_KEY_POWER;
307                 }
308                 break;
309         case ADB_KEY_POWER: 
310                 /* Fn + Command will produce a bogus "power" keycode */
311                 if (ahid->flags & FLAG_FN_KEY_PRESSED) {
312                         keycode = ADB_KEY_CMD;
313                         if (up_flag)
314                                 ahid->flags &= ~FLAG_POWER_FROM_FN;
315                         else
316                                 ahid->flags |= FLAG_POWER_FROM_FN;
317                 } else if (ahid->flags & FLAG_POWER_FROM_FN) {
318                         keycode = ADB_KEY_CMD;
319                         ahid->flags &= ~FLAG_POWER_FROM_FN;
320                 }
321                 break;
322         case ADB_KEY_FN:
323                 /* Keep track of the Fn key state */
324                 if (up_flag) {
325                         ahid->flags &= ~FLAG_FN_KEY_PRESSED;
326                         /* Emulate Fn+delete = forward delete */
327                         if (ahid->flags & FLAG_EMU_FWDEL_DOWN) {
328                                 ahid->flags &= ~FLAG_EMU_FWDEL_DOWN;
329                                 keycode = ADB_KEY_FWDEL;
330                                 break;
331                         }
332                 } else
333                         ahid->flags |= FLAG_FN_KEY_PRESSED;
334                 /* Swallow the key press */
335                 return;
336         case ADB_KEY_DEL:
337                 /* Emulate Fn+delete = forward delete */
338                 if (ahid->flags & FLAG_FN_KEY_PRESSED) {
339                         keycode = ADB_KEY_FWDEL;
340                         if (up_flag)
341                                 ahid->flags &= ~FLAG_EMU_FWDEL_DOWN;
342                         else
343                                 ahid->flags |= FLAG_EMU_FWDEL_DOWN;
344                 }
345                 break;
346 #endif /* CONFIG_PPC_PMAC */
347         }
348
349         if (adbhid[id]->keycode[keycode]) {
350                 input_regs(adbhid[id]->input, regs);
351                 input_report_key(adbhid[id]->input,
352                                  adbhid[id]->keycode[keycode], !up_flag);
353                 input_sync(adbhid[id]->input);
354         } else
355                 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode,
356                        up_flag ? "released" : "pressed");
357
358 }
359
360 static void
361 adbhid_mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
362 {
363         int id = (data[0] >> 4) & 0x0f;
364
365         if (!adbhid[id]) {
366                 printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
367                 return;
368         }
369
370   /*
371     Handler 1 -- 100cpi original Apple mouse protocol.
372     Handler 2 -- 200cpi original Apple mouse protocol.
373
374     For Apple's standard one-button mouse protocol the data array will
375     contain the following values:
376
377                 BITS    COMMENTS
378     data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
379     data[1] = bxxx xxxx First button and x-axis motion.
380     data[2] = byyy yyyy Second button and y-axis motion.
381
382     Handler 4 -- Apple Extended mouse protocol.
383
384     For Apple's 3-button mouse protocol the data array will contain the
385     following values:
386
387                 BITS    COMMENTS
388     data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
389     data[1] = bxxx xxxx Left button and x-axis motion.
390     data[2] = byyy yyyy Second button and y-axis motion.
391     data[3] = byyy bxxx Third button and fourth button.  Y is additional
392               high bits of y-axis motion.  XY is additional
393               high bits of x-axis motion.
394
395     MacAlly 2-button mouse protocol.
396
397     For MacAlly 2-button mouse protocol the data array will contain the
398     following values:
399
400                 BITS    COMMENTS
401     data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
402     data[1] = bxxx xxxx Left button and x-axis motion.
403     data[2] = byyy yyyy Right button and y-axis motion.
404     data[3] = ???? ???? unknown
405     data[4] = ???? ???? unknown
406
407   */
408
409         /* If it's a trackpad, we alias the second button to the first.
410            NOTE: Apple sends an ADB flush command to the trackpad when
411                  the first (the real) button is released. We could do
412                  this here using async flush requests.
413         */
414         switch (adbhid[id]->mouse_kind)
415         {
416             case ADBMOUSE_TRACKPAD:
417                 data[1] = (data[1] & 0x7f) | ((data[1] & data[2]) & 0x80);
418                 data[2] = data[2] | 0x80;
419                 break;
420             case ADBMOUSE_MICROSPEED:
421                 data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
422                 data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
423                 data[3] = (data[3] & 0x77) | ((data[3] & 0x04) << 5)
424                         | (data[3] & 0x08);
425                 break;
426             case ADBMOUSE_TRACKBALLPRO:
427                 data[1] = (data[1] & 0x7f) | (((data[3] & 0x04) << 5)
428                         & ((data[3] & 0x08) << 4));
429                 data[2] = (data[2] & 0x7f) | ((data[3] & 0x01) << 7);
430                 data[3] = (data[3] & 0x77) | ((data[3] & 0x02) << 6);
431                 break;
432             case ADBMOUSE_MS_A3:
433                 data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
434                 data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
435                 data[3] = ((data[3] & 0x04) << 5);
436                 break;
437             case ADBMOUSE_MACALLY2:
438                 data[3] = (data[2] & 0x80) ? 0x80 : 0x00;
439                 data[2] |= 0x80;  /* Right button is mapped as button 3 */
440                 nb=4;
441                 break;
442         }
443
444         input_regs(adbhid[id]->input, regs);
445
446         input_report_key(adbhid[id]->input, BTN_LEFT,   !((data[1] >> 7) & 1));
447         input_report_key(adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1));
448
449         if (nb >= 4 && adbhid[id]->mouse_kind != ADBMOUSE_TRACKPAD)
450                 input_report_key(adbhid[id]->input, BTN_RIGHT,  !((data[3] >> 7) & 1));
451
452         input_report_rel(adbhid[id]->input, REL_X,
453                          ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ));
454         input_report_rel(adbhid[id]->input, REL_Y,
455                          ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 ));
456
457         input_sync(adbhid[id]->input);
458 }
459
460 static void
461 adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
462 {
463         int id = (data[0] >> 4) & 0x0f;
464
465         if (!adbhid[id]) {
466                 printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
467                 return;
468         }
469
470         input_regs(adbhid[id]->input, regs);
471
472         switch (adbhid[id]->original_handler_id) {
473         default:
474         case 0x02: /* Adjustable keyboard button device */
475           {
476                 int down = (data[1] == (data[1] & 0xf));
477
478                 switch (data[1] & 0x0f) {
479                 case 0x0:       /* microphone */
480                         input_report_key(adbhid[id]->input, KEY_SOUND, down);
481                         break;
482
483                 case 0x1:       /* mute */
484                         input_report_key(adbhid[id]->input, KEY_MUTE, down);
485                         break;
486
487                 case 0x2:       /* volume decrease */
488                         input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
489                         break;
490
491                 case 0x3:       /* volume increase */
492                         input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
493                         break;
494
495                 default:
496                         printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
497                                data[0], data[1], data[2], data[3]);
498                         break;
499                 }
500           }
501           break;
502
503         case 0x1f: /* Powerbook button device */
504           {
505                 int down = (data[1] == (data[1] & 0xf));
506
507                 /*
508                  * XXX: Where is the contrast control for the passive?
509                  *  -- Cort
510                  */
511
512                 switch (data[1] & 0x0f) {
513                 case 0x8:       /* mute */
514                         input_report_key(adbhid[id]->input, KEY_MUTE, down);
515                         break;
516
517                 case 0x7:       /* volume decrease */
518                         input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
519                         break;
520
521                 case 0x6:       /* volume increase */
522                         input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
523                         break;
524
525                 case 0xb:       /* eject */
526                         input_report_key(adbhid[id]->input, KEY_EJECTCD, down);
527                         break;
528
529                 case 0xa:       /* brightness decrease */
530 #ifdef CONFIG_PMAC_BACKLIGHT
531                         if (!disable_kernel_backlight && down)
532                                 pmac_backlight_key_down();
533 #endif
534                         input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
535                         break;
536
537                 case 0x9:       /* brightness increase */
538 #ifdef CONFIG_PMAC_BACKLIGHT
539                         if (!disable_kernel_backlight && down)
540                                 pmac_backlight_key_up();
541 #endif
542                         input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down);
543                         break;
544
545                 case 0xc:       /* videomode switch */
546                         input_report_key(adbhid[id]->input, KEY_SWITCHVIDEOMODE, down);
547                         break;
548
549                 case 0xd:       /* keyboard illumination toggle */
550                         input_report_key(adbhid[id]->input, KEY_KBDILLUMTOGGLE, down);
551                         break;
552
553                 case 0xe:       /* keyboard illumination decrease */
554                         input_report_key(adbhid[id]->input, KEY_KBDILLUMDOWN, down);
555                         break;
556
557                 case 0xf:
558                         switch (data[1]) {
559                         case 0x8f:
560                         case 0x0f:
561                                 /* keyboard illumination increase */
562                                 input_report_key(adbhid[id]->input, KEY_KBDILLUMUP, down);
563                                 break;
564
565                         case 0x7f:
566                         case 0xff:
567                                 /* keypad overlay toogle */
568                                 break;
569
570                         default:
571                                 printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
572                                        data[0], data[1], data[2], data[3]);
573                                 break;
574                         }
575                         break;
576                 default:
577                         printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
578                                data[0], data[1], data[2], data[3]);
579                         break;
580                 }
581           }
582           break;
583         }
584
585         input_sync(adbhid[id]->input);
586 }
587
588 static struct adb_request led_request;
589 static int leds_pending[16];
590 static int leds_req_pending;
591 static int pending_devs[16];
592 static int pending_led_start=0;
593 static int pending_led_end=0;
594 static DEFINE_SPINLOCK(leds_lock);
595
596 static void leds_done(struct adb_request *req)
597 {
598         int leds = 0, device = 0, pending = 0;
599         unsigned long flags;
600
601         spin_lock_irqsave(&leds_lock, flags);
602
603         if (pending_led_start != pending_led_end) {
604                 device = pending_devs[pending_led_start];
605                 leds = leds_pending[device] & 0xff;
606                 leds_pending[device] = 0;
607                 pending_led_start++;
608                 pending_led_start = (pending_led_start < 16) ? pending_led_start : 0;
609                 pending = leds_req_pending;
610         } else
611                 leds_req_pending = 0;
612         spin_unlock_irqrestore(&leds_lock, flags);
613         if (pending)
614                 adb_request(&led_request, leds_done, 0, 3,
615                             ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
616 }
617
618 static void real_leds(unsigned char leds, int device)
619 {
620         unsigned long flags;
621
622         spin_lock_irqsave(&leds_lock, flags);
623         if (!leds_req_pending) {
624                 leds_req_pending = 1;
625                 spin_unlock_irqrestore(&leds_lock, flags);             
626                 adb_request(&led_request, leds_done, 0, 3,
627                             ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
628                 return;
629         } else {
630                 if (!(leds_pending[device] & 0x100)) {
631                         pending_devs[pending_led_end] = device;
632                         pending_led_end++;
633                         pending_led_end = (pending_led_end < 16) ? pending_led_end : 0;
634                 }
635                 leds_pending[device] = leds | 0x100;
636         }
637         spin_unlock_irqrestore(&leds_lock, flags);             
638 }
639
640 /*
641  * Event callback from the input module. Events that change the state of
642  * the hardware are processed here.
643  */
644 static int adbhid_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
645 {
646         struct adbhid *adbhid = dev->private;
647         unsigned char leds;
648
649         switch (type) {
650         case EV_LED:
651           leds = (test_bit(LED_SCROLLL, dev->led) ? 4 : 0)
652                | (test_bit(LED_NUML,    dev->led) ? 1 : 0)
653                | (test_bit(LED_CAPSL,   dev->led) ? 2 : 0);
654           real_leds(leds, adbhid->id);
655           return 0;
656         }
657
658         return -1;
659 }
660
661 static int
662 adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
663 {
664         switch (code) {
665         case ADB_MSG_PRE_RESET:
666         case ADB_MSG_POWERDOWN:
667                 /* Stop the repeat timer. Autopoll is already off at this point */
668                 {
669                         int i;
670                         for (i = 1; i < 16; i++) {
671                                 if (adbhid[i])
672                                         del_timer_sync(&adbhid[i]->input->timer);
673                         }
674                 }
675
676                 /* Stop pending led requests */
677                 while(leds_req_pending)
678                         adb_poll();
679                 break;
680
681         case ADB_MSG_POST_RESET:
682                 adbhid_probe();
683                 break;
684         }
685         return NOTIFY_DONE;
686 }
687
688 static int
689 adbhid_input_register(int id, int default_id, int original_handler_id,
690                       int current_handler_id, int mouse_kind)
691 {
692         struct adbhid *hid;
693         struct input_dev *input_dev;
694         int err;
695         int i;
696
697         if (adbhid[id]) {
698                 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
699                 return -EEXIST;
700         }
701
702         adbhid[id] = hid = kzalloc(sizeof(struct adbhid), GFP_KERNEL);
703         input_dev = input_allocate_device();
704         if (!hid || !input_dev) {
705                 err = -ENOMEM;
706                 goto fail;
707
708         }
709
710         sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
711
712         hid->input = input_dev;
713         hid->id = default_id;
714         hid->original_handler_id = original_handler_id;
715         hid->current_handler_id = current_handler_id;
716         hid->mouse_kind = mouse_kind;
717         hid->flags = 0;
718         input_dev->private = hid;
719         input_dev->name = hid->name;
720         input_dev->phys = hid->phys;
721         input_dev->id.bustype = BUS_ADB;
722         input_dev->id.vendor = 0x0001;
723         input_dev->id.product = (id << 12) | (default_id << 8) | original_handler_id;
724         input_dev->id.version = 0x0100;
725
726         switch (default_id) {
727         case ADB_KEYBOARD:
728                 hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL);
729                 if (!hid->keycode) {
730                         err = -ENOMEM;
731                         goto fail;
732                 }
733
734                 sprintf(hid->name, "ADB keyboard");
735
736                 memcpy(hid->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
737
738                 printk(KERN_INFO "Detected ADB keyboard, type ");
739                 switch (original_handler_id) {
740                 default:
741                         printk("<unknown>.\n");
742                         input_dev->id.version = ADB_KEYBOARD_UNKNOWN;
743                         break;
744
745                 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
746                 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
747                 case 0xC0: case 0xC3: case 0xC6:
748                         printk("ANSI.\n");
749                         input_dev->id.version = ADB_KEYBOARD_ANSI;
750                         break;
751
752                 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
753                 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
754                 case 0xC4: case 0xC7:
755                         printk("ISO, swapping keys.\n");
756                         input_dev->id.version = ADB_KEYBOARD_ISO;
757                         i = hid->keycode[10];
758                         hid->keycode[10] = hid->keycode[50];
759                         hid->keycode[50] = i;
760                         break;
761
762                 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
763                 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
764                         printk("JIS.\n");
765                         input_dev->id.version = ADB_KEYBOARD_JIS;
766                         break;
767                 }
768
769                 for (i = 0; i < 128; i++)
770                         if (hid->keycode[i])
771                                 set_bit(hid->keycode[i], input_dev->keybit);
772
773                 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
774                 input_dev->ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
775                 input_dev->event = adbhid_kbd_event;
776                 input_dev->keycodemax = 127;
777                 input_dev->keycodesize = 1;
778                 break;
779
780         case ADB_MOUSE:
781                 sprintf(hid->name, "ADB mouse");
782
783                 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
784                 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
785                 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
786                 break;
787
788         case ADB_MISC:
789                 switch (original_handler_id) {
790                 case 0x02: /* Adjustable keyboard button device */
791                         sprintf(hid->name, "ADB adjustable keyboard buttons");
792                         input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
793                         set_bit(KEY_SOUND, input_dev->keybit);
794                         set_bit(KEY_MUTE, input_dev->keybit);
795                         set_bit(KEY_VOLUMEUP, input_dev->keybit);
796                         set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
797                         break;
798                 case 0x1f: /* Powerbook button device */
799                         sprintf(hid->name, "ADB Powerbook buttons");
800                         input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
801                         set_bit(KEY_MUTE, input_dev->keybit);
802                         set_bit(KEY_VOLUMEUP, input_dev->keybit);
803                         set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
804                         set_bit(KEY_BRIGHTNESSUP, input_dev->keybit);
805                         set_bit(KEY_BRIGHTNESSDOWN, input_dev->keybit);
806                         set_bit(KEY_EJECTCD, input_dev->keybit);
807                         set_bit(KEY_SWITCHVIDEOMODE, input_dev->keybit);
808                         set_bit(KEY_KBDILLUMTOGGLE, input_dev->keybit);
809                         set_bit(KEY_KBDILLUMDOWN, input_dev->keybit);
810                         set_bit(KEY_KBDILLUMUP, input_dev->keybit);
811                         break;
812                 }
813                 if (hid->name[0])
814                         break;
815                 /* else fall through */
816
817         default:
818                 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
819                 err = -ENODEV;
820                 goto fail;
821         }
822
823         input_dev->keycode = hid->keycode;
824
825         input_register_device(input_dev);
826
827         if (default_id == ADB_KEYBOARD) {
828                 /* HACK WARNING!! This should go away as soon there is an utility
829                  * to control that for event devices.
830                  */
831                 input_dev->rep[REP_DELAY] = 500;   /* input layer default: 250 */
832                 input_dev->rep[REP_PERIOD] = 66; /* input layer default: 33 */
833         }
834
835         return 0;
836
837  fail:  input_free_device(input_dev);
838         kfree(hid);
839         adbhid[id] = NULL;
840         return err;
841 }
842
843 static void adbhid_input_unregister(int id)
844 {
845         input_unregister_device(adbhid[id]->input);
846         kfree(adbhid[id]->keycode);
847         kfree(adbhid[id]);
848         adbhid[id] = NULL;
849 }
850
851
852 static u16
853 adbhid_input_reregister(int id, int default_id, int org_handler_id,
854                         int cur_handler_id, int mk)
855 {
856         if (adbhid[id]) {
857                 if (adbhid[id]->input->id.product !=
858                     ((id << 12)|(default_id << 8)|org_handler_id)) {
859                         adbhid_input_unregister(id);
860                         adbhid_input_register(id, default_id, org_handler_id,
861                                               cur_handler_id, mk);
862                 }
863         } else
864                 adbhid_input_register(id, default_id, org_handler_id,
865                                       cur_handler_id, mk);
866         return 1<<id;
867 }
868
869 static void
870 adbhid_input_devcleanup(u16 exist)
871 {
872         int i;
873         for(i=1; i<16; i++)
874                 if (adbhid[i] && !(exist&(1<<i)))
875                         adbhid_input_unregister(i);
876 }
877
878 static void
879 adbhid_probe(void)
880 {
881         struct adb_request req;
882         int i, default_id, org_handler_id, cur_handler_id;
883         u16 reg = 0;
884
885         adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input);
886         adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input);
887         adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input);
888
889         for (i = 0; i < keyboard_ids.nids; i++) {
890                 int id = keyboard_ids.id[i];
891
892                 adb_get_infos(id, &default_id, &org_handler_id);
893
894                 /* turn off all leds */
895                 adb_request(&req, NULL, ADBREQ_SYNC, 3,
896                             ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
897
898                 /* Enable full feature set of the keyboard
899                    ->get it to send separate codes for left and right shift,
900                    control, option keys */
901 #if 0           /* handler 5 doesn't send separate codes for R modifiers */
902                 if (adb_try_handler_change(id, 5))
903                         printk("ADB keyboard at %d, handler set to 5\n", id);
904                 else
905 #endif
906                 if (adb_try_handler_change(id, 3))
907                         printk("ADB keyboard at %d, handler set to 3\n", id);
908                 else
909                         printk("ADB keyboard at %d, handler 1\n", id);
910
911                 adb_get_infos(id, &default_id, &cur_handler_id);
912                 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
913                                                cur_handler_id, 0);
914         }
915
916         for (i = 0; i < buttons_ids.nids; i++) {
917                 int id = buttons_ids.id[i];
918
919                 adb_get_infos(id, &default_id, &org_handler_id);
920                 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
921                                                org_handler_id, 0);
922         }
923
924         /* Try to switch all mice to handler 4, or 2 for three-button
925            mode and full resolution. */
926         for (i = 0; i < mouse_ids.nids; i++) {
927                 int id = mouse_ids.id[i];
928                 int mouse_kind;
929
930                 adb_get_infos(id, &default_id, &org_handler_id);
931
932                 if (adb_try_handler_change(id, 4)) {
933                         printk("ADB mouse at %d, handler set to 4", id);
934                         mouse_kind = ADBMOUSE_EXTENDED;
935                 }
936                 else if (adb_try_handler_change(id, 0x2F)) {
937                         printk("ADB mouse at %d, handler set to 0x2F", id);
938                         mouse_kind = ADBMOUSE_MICROSPEED;
939                 }
940                 else if (adb_try_handler_change(id, 0x42)) {
941                         printk("ADB mouse at %d, handler set to 0x42", id);
942                         mouse_kind = ADBMOUSE_TRACKBALLPRO;
943                 }
944                 else if (adb_try_handler_change(id, 0x66)) {
945                         printk("ADB mouse at %d, handler set to 0x66", id);
946                         mouse_kind = ADBMOUSE_MICROSPEED;
947                 }
948                 else if (adb_try_handler_change(id, 0x5F)) {
949                         printk("ADB mouse at %d, handler set to 0x5F", id);
950                         mouse_kind = ADBMOUSE_MICROSPEED;
951                 }
952                 else if (adb_try_handler_change(id, 3)) {
953                         printk("ADB mouse at %d, handler set to 3", id);
954                         mouse_kind = ADBMOUSE_MS_A3;
955                 }
956                 else if (adb_try_handler_change(id, 2)) {
957                         printk("ADB mouse at %d, handler set to 2", id);
958                         mouse_kind = ADBMOUSE_STANDARD_200;
959                 }
960                 else {
961                         printk("ADB mouse at %d, handler 1", id);
962                         mouse_kind = ADBMOUSE_STANDARD_100;
963                 }
964
965                 if ((mouse_kind == ADBMOUSE_TRACKBALLPRO)
966                     || (mouse_kind == ADBMOUSE_MICROSPEED)) {
967                         init_microspeed(id);
968                 } else if (mouse_kind == ADBMOUSE_MS_A3) {
969                         init_ms_a3(id);
970                 } else if (mouse_kind ==  ADBMOUSE_EXTENDED) {
971                         /*
972                          * Register 1 is usually used for device
973                          * identification.  Here, we try to identify
974                          * a known device and call the appropriate
975                          * init function.
976                          */
977                         adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
978                                     ADB_READREG(id, 1));
979
980                         if ((req.reply_len) &&
981                             (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
982                                 || (req.reply[2] == 0x20))) {
983                                 mouse_kind = ADBMOUSE_TRACKBALL;
984                                 init_trackball(id);
985                         }
986                         else if ((req.reply_len >= 4) &&
987                             (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
988                             (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) {
989                                 mouse_kind = ADBMOUSE_TRACKPAD;
990                                 init_trackpad(id);
991                         }
992                         else if ((req.reply_len >= 4) &&
993                             (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
994                             (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) {
995                                 mouse_kind = ADBMOUSE_TURBOMOUSE5;
996                                 init_turbomouse(id);
997                         }
998                         else if ((req.reply_len == 9) &&
999                             (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
1000                             (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) {
1001                                 if (adb_try_handler_change(id, 0x42)) {
1002                                         printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
1003                                         mouse_kind = ADBMOUSE_MACALLY2;
1004                                 }
1005                         }
1006                 }
1007                 printk("\n");
1008
1009                 adb_get_infos(id, &default_id, &cur_handler_id);
1010                 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
1011                                                cur_handler_id, mouse_kind);
1012         }
1013         adbhid_input_devcleanup(reg);
1014 }
1015
1016 static void 
1017 init_trackpad(int id)
1018 {
1019         struct adb_request req;
1020         unsigned char r1_buffer[8];
1021
1022         printk(" (trackpad)");
1023
1024         adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
1025                     ADB_READREG(id,1));
1026         if (req.reply_len < 8)
1027             printk("bad length for reg. 1\n");
1028         else
1029         {
1030             memcpy(r1_buffer, &req.reply[1], 8);
1031
1032             adb_request(&req, NULL, ADBREQ_SYNC, 9,
1033                 ADB_WRITEREG(id,1),
1034                     r1_buffer[0],
1035                     r1_buffer[1],
1036                     r1_buffer[2],
1037                     r1_buffer[3],
1038                     r1_buffer[4],
1039                     r1_buffer[5],
1040                     0x0d,
1041                     r1_buffer[7]);
1042
1043             adb_request(&req, NULL, ADBREQ_SYNC, 9,
1044                 ADB_WRITEREG(id,2),
1045                     0x99,
1046                     0x94,
1047                     0x19,
1048                     0xff,
1049                     0xb2,
1050                     0x8a,
1051                     0x1b,
1052                     0x50);
1053
1054             adb_request(&req, NULL, ADBREQ_SYNC, 9,
1055                 ADB_WRITEREG(id,1),
1056                     r1_buffer[0],
1057                     r1_buffer[1],
1058                     r1_buffer[2],
1059                     r1_buffer[3],
1060                     r1_buffer[4],
1061                     r1_buffer[5],
1062                     0x03, /*r1_buffer[6],*/
1063                     r1_buffer[7]);
1064
1065             /* Without this flush, the trackpad may be locked up */
1066             adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1067         }
1068 }
1069
1070 static void 
1071 init_trackball(int id)
1072 {
1073         struct adb_request req;
1074
1075         printk(" (trackman/mouseman)");
1076
1077         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1078         ADB_WRITEREG(id,1), 00,0x81);
1079
1080         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1081         ADB_WRITEREG(id,1), 01,0x81);
1082
1083         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1084         ADB_WRITEREG(id,1), 02,0x81);
1085
1086         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1087         ADB_WRITEREG(id,1), 03,0x38);
1088
1089         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1090         ADB_WRITEREG(id,1), 00,0x81);
1091
1092         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1093         ADB_WRITEREG(id,1), 01,0x81);
1094
1095         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1096         ADB_WRITEREG(id,1), 02,0x81);
1097
1098         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1099         ADB_WRITEREG(id,1), 03,0x38);
1100 }
1101
1102 static void
1103 init_turbomouse(int id)
1104 {
1105         struct adb_request req;
1106
1107         printk(" (TurboMouse 5)");
1108
1109         adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1110
1111         adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
1112
1113         adb_request(&req, NULL, ADBREQ_SYNC, 9,
1114         ADB_WRITEREG(3,2),
1115             0xe7,
1116             0x8c,
1117             0,
1118             0,
1119             0,
1120             0xff,
1121             0xff,
1122             0x94);
1123
1124         adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
1125
1126         adb_request(&req, NULL, ADBREQ_SYNC, 9,
1127         ADB_WRITEREG(3,2),
1128             0xa5,
1129             0x14,
1130             0,
1131             0,
1132             0x69,
1133             0xff,
1134             0xff,
1135             0x27);
1136 }
1137
1138 static void
1139 init_microspeed(int id)
1140 {
1141         struct adb_request req;
1142
1143         printk(" (Microspeed/MacPoint or compatible)");
1144
1145         adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1146
1147         /* This will initialize mice using the Microspeed, MacPoint and
1148            other compatible firmware. Bit 12 enables extended protocol.
1149            
1150            Register 1 Listen (4 Bytes)
1151             0 -  3     Button is mouse (set also for double clicking!!!)
1152             4 -  7     Button is locking (affects change speed also)
1153             8 - 11     Button changes speed
1154            12          1 = Extended mouse mode, 0 = normal mouse mode
1155            13 - 15     unused 0
1156            16 - 23     normal speed
1157            24 - 31     changed speed
1158
1159        Register 1 talk holds version and product identification information.
1160        Register 1 Talk (4 Bytes):
1161             0 -  7     Product code
1162             8 - 23     undefined, reserved
1163            24 - 31     Version number
1164         
1165        Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
1166  */
1167         adb_request(&req, NULL, ADBREQ_SYNC, 5,
1168         ADB_WRITEREG(id,1),
1169             0x20,       /* alt speed = 0x20 (rather slow) */
1170             0x00,       /* norm speed = 0x00 (fastest) */
1171             0x10,       /* extended protocol, no speed change */
1172             0x07);      /* all buttons enabled as mouse buttons, no locking */
1173
1174
1175         adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1176 }
1177
1178 static void
1179 init_ms_a3(int id)
1180 {
1181         struct adb_request req;
1182
1183         printk(" (Mouse Systems A3 Mouse, or compatible)");
1184         adb_request(&req, NULL, ADBREQ_SYNC, 3,
1185         ADB_WRITEREG(id, 0x2),
1186             0x00,
1187             0x07);
1188  
1189         adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1190 }
1191
1192 static int __init adbhid_init(void)
1193 {
1194 #ifndef CONFIG_MAC
1195         if (!machine_is(chrp) && !machine_is(powermac))
1196                 return 0;
1197 #endif
1198
1199         led_request.complete = 1;
1200
1201         adbhid_probe();
1202
1203         blocking_notifier_chain_register(&adb_client_list,
1204                         &adbhid_adb_notifier);
1205
1206         return 0;
1207 }
1208
1209 static void __exit adbhid_exit(void)
1210 {
1211 }
1212  
1213 module_init(adbhid_init);
1214 module_exit(adbhid_exit);