2 * drivers/input/adbhid.c
4 * ADB HID driver for Power Macintosh computers.
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.
10 * Copyright (C) 2000 Franz Sirl.
12 * Adapted to ADB changes and support for more devices by
13 * Benjamin Herrenschmidt. Adapted from code in MkLinux
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>
32 * Improve Kensington support.
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>
44 #include <linux/adb.h>
45 #include <linux/cuda.h>
46 #include <linux/pmu.h>
48 #include <asm/machdep.h>
49 #ifdef CONFIG_PPC_PMAC
50 #include <asm/pmac_feature.h>
53 #ifdef CONFIG_PMAC_BACKLIGHT
54 #include <asm/backlight.h>
57 MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>");
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 */
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,
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
77 unsigned char adb_to_linux_keycodes[128] = {
78 30, 31, 32, 33, 35, 34, 44, 45, 46, 47, 86, 48, 16, 17, 18, 19,
79 21, 20, 2, 3, 4, 5, 7, 6, 13, 10, 8, 12, 9, 11, 27, 24,
80 22, 26, 23, 25, 28, 38, 36, 40, 37, 39, 43, 51, 53, 49, 50, 52,
81 15, 57, 41, 14, 96, 1, 29,125, 42, 58, 56,105,106,108,103, 0,
82 0, 83, 0, 55, 0, 78, 0, 69, 0, 0, 0, 98, 96, 0, 74, 0,
83 0,117, 82, 79, 80, 81, 75, 76, 77, 71, 0, 72, 73,124, 89,121,
84 63, 64, 65, 61, 66, 67,123, 87,122, 99, 0, 70, 0, 68,101, 88,
85 0,119,110,102,104,111, 62,107, 60,109, 59, 54,100, 97,126,116
89 struct input_dev input;
92 int original_handler_id;
93 int current_handler_id;
95 unsigned char *keycode;
101 #define FLAG_FN_KEY_PRESSED 0x00000001
102 #define FLAG_POWER_FROM_FN 0x00000002
103 #define FLAG_EMU_FWDEL_DOWN 0x00000004
105 static struct adbhid *adbhid[16];
107 static void adbhid_probe(void);
109 static void adbhid_input_keycode(int, int, int, struct pt_regs *);
111 static void init_trackpad(int id);
112 static void init_trackball(int id);
113 static void init_turbomouse(int id);
114 static void init_microspeed(int id);
115 static void init_ms_a3(int id);
117 static struct adb_ids keyboard_ids;
118 static struct adb_ids mouse_ids;
119 static struct adb_ids buttons_ids;
121 #ifdef CONFIG_PMAC_BACKLIGHT
122 /* Exported to via-pmu.c */
123 int disable_kernel_backlight = 0;
124 #endif /* CONFIG_PMAC_BACKLIGHT */
126 /* Kind of keyboard, see Apple technote 1152 */
127 #define ADB_KEYBOARD_UNKNOWN 0
128 #define ADB_KEYBOARD_ANSI 0x0100
129 #define ADB_KEYBOARD_ISO 0x0200
130 #define ADB_KEYBOARD_JIS 0x0300
133 #define ADBMOUSE_STANDARD_100 0 /* Standard 100cpi mouse (handler 1) */
134 #define ADBMOUSE_STANDARD_200 1 /* Standard 200cpi mouse (handler 2) */
135 #define ADBMOUSE_EXTENDED 2 /* Apple Extended mouse (handler 4) */
136 #define ADBMOUSE_TRACKBALL 3 /* TrackBall (handler 4) */
137 #define ADBMOUSE_TRACKPAD 4 /* Apple's PowerBook trackpad (handler 4) */
138 #define ADBMOUSE_TURBOMOUSE5 5 /* Turbomouse 5 (previously req. mousehack) */
139 #define ADBMOUSE_MICROSPEED 6 /* Microspeed mouse (&trackball ?), MacPoint */
140 #define ADBMOUSE_TRACKBALLPRO 7 /* Trackball Pro (special buttons) */
141 #define ADBMOUSE_MS_A3 8 /* Mouse systems A3 trackball (handler 3) */
142 #define ADBMOUSE_MACALLY2 9 /* MacAlly 2-button mouse */
145 adbhid_keyboard_input(unsigned char *data, int nb, struct pt_regs *regs, int apoll)
147 int id = (data[0] >> 4) & 0x0f;
150 printk(KERN_ERR "ADB HID on ID %d not yet registered, packet %#02x, %#02x, %#02x, %#02x\n",
151 id, data[0], data[1], data[2], data[3]);
155 /* first check this is from register 0 */
156 if (nb != 3 || (data[0] & 3) != KEYB_KEYREG)
157 return; /* ignore it */
158 adbhid_input_keycode(id, data[1], 0, regs);
159 if (!(data[2] == 0xff || (data[2] == 0x7f && data[1] == 0x7f)))
160 adbhid_input_keycode(id, data[2], 0, regs);
164 adbhid_input_keycode(int id, int keycode, int repeat, struct pt_regs *regs)
166 struct adbhid *ahid = adbhid[id];
169 up_flag = (keycode & 0x80);
173 case ADB_KEY_CAPSLOCK: /* Generate down/up events for CapsLock everytime. */
174 input_regs(&ahid->input, regs);
175 input_report_key(&ahid->input, KEY_CAPSLOCK, 1);
176 input_report_key(&ahid->input, KEY_CAPSLOCK, 0);
177 input_sync(&ahid->input);
179 #ifdef CONFIG_PPC_PMAC
180 case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */
181 switch(pmac_call_feature(PMAC_FTR_GET_MB_INFO,
182 NULL, PMAC_MB_INFO_MODEL, 0)) {
183 case PMAC_TYPE_COMET:
184 case PMAC_TYPE_HOOPER:
185 case PMAC_TYPE_KANGA:
186 keycode = ADB_KEY_POWER;
190 /* Fn + Command will produce a bogus "power" keycode */
191 if (ahid->flags & FLAG_FN_KEY_PRESSED) {
192 keycode = ADB_KEY_CMD;
194 ahid->flags &= ~FLAG_POWER_FROM_FN;
196 ahid->flags |= FLAG_POWER_FROM_FN;
197 } else if (ahid->flags & FLAG_POWER_FROM_FN) {
198 keycode = ADB_KEY_CMD;
199 ahid->flags &= ~FLAG_POWER_FROM_FN;
203 /* Keep track of the Fn key state */
205 ahid->flags &= ~FLAG_FN_KEY_PRESSED;
206 /* Emulate Fn+delete = forward delete */
207 if (ahid->flags & FLAG_EMU_FWDEL_DOWN) {
208 ahid->flags &= ~FLAG_EMU_FWDEL_DOWN;
209 keycode = ADB_KEY_FWDEL;
213 ahid->flags |= FLAG_FN_KEY_PRESSED;
214 /* Swallow the key press */
217 /* Emulate Fn+delete = forward delete */
218 if (ahid->flags & FLAG_FN_KEY_PRESSED) {
219 keycode = ADB_KEY_FWDEL;
221 ahid->flags &= ~FLAG_EMU_FWDEL_DOWN;
223 ahid->flags |= FLAG_EMU_FWDEL_DOWN;
226 #endif /* CONFIG_PPC_PMAC */
229 if (adbhid[id]->keycode[keycode]) {
230 input_regs(&adbhid[id]->input, regs);
231 input_report_key(&adbhid[id]->input,
232 adbhid[id]->keycode[keycode], !up_flag);
233 input_sync(&adbhid[id]->input);
235 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode,
236 up_flag ? "released" : "pressed");
241 adbhid_mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
243 int id = (data[0] >> 4) & 0x0f;
246 printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
251 Handler 1 -- 100cpi original Apple mouse protocol.
252 Handler 2 -- 200cpi original Apple mouse protocol.
254 For Apple's standard one-button mouse protocol the data array will
255 contain the following values:
258 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
259 data[1] = bxxx xxxx First button and x-axis motion.
260 data[2] = byyy yyyy Second button and y-axis motion.
262 Handler 4 -- Apple Extended mouse protocol.
264 For Apple's 3-button mouse protocol the data array will contain the
268 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
269 data[1] = bxxx xxxx Left button and x-axis motion.
270 data[2] = byyy yyyy Second button and y-axis motion.
271 data[3] = byyy bxxx Third button and fourth button. Y is additional
272 high bits of y-axis motion. XY is additional
273 high bits of x-axis motion.
275 MacAlly 2-button mouse protocol.
277 For MacAlly 2-button mouse protocol the data array will contain the
281 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
282 data[1] = bxxx xxxx Left button and x-axis motion.
283 data[2] = byyy yyyy Right button and y-axis motion.
284 data[3] = ???? ???? unknown
285 data[4] = ???? ???? unknown
289 /* If it's a trackpad, we alias the second button to the first.
290 NOTE: Apple sends an ADB flush command to the trackpad when
291 the first (the real) button is released. We could do
292 this here using async flush requests.
294 switch (adbhid[id]->mouse_kind)
296 case ADBMOUSE_TRACKPAD:
297 data[1] = (data[1] & 0x7f) | ((data[1] & data[2]) & 0x80);
298 data[2] = data[2] | 0x80;
300 case ADBMOUSE_MICROSPEED:
301 data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
302 data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
303 data[3] = (data[3] & 0x77) | ((data[3] & 0x04) << 5)
306 case ADBMOUSE_TRACKBALLPRO:
307 data[1] = (data[1] & 0x7f) | (((data[3] & 0x04) << 5)
308 & ((data[3] & 0x08) << 4));
309 data[2] = (data[2] & 0x7f) | ((data[3] & 0x01) << 7);
310 data[3] = (data[3] & 0x77) | ((data[3] & 0x02) << 6);
313 data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
314 data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
315 data[3] = ((data[3] & 0x04) << 5);
317 case ADBMOUSE_MACALLY2:
318 data[3] = (data[2] & 0x80) ? 0x80 : 0x00;
319 data[2] |= 0x80; /* Right button is mapped as button 3 */
324 input_regs(&adbhid[id]->input, regs);
326 input_report_key(&adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1));
327 input_report_key(&adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1));
330 input_report_key(&adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1));
332 input_report_rel(&adbhid[id]->input, REL_X,
333 ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ));
334 input_report_rel(&adbhid[id]->input, REL_Y,
335 ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 ));
337 input_sync(&adbhid[id]->input);
341 adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
343 int id = (data[0] >> 4) & 0x0f;
346 printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
350 input_regs(&adbhid[id]->input, regs);
352 switch (adbhid[id]->original_handler_id) {
354 case 0x02: /* Adjustable keyboard button device */
356 int down = (data[1] == (data[1] & 0xf));
358 switch (data[1] & 0x0f) {
359 case 0x0: /* microphone */
360 input_report_key(&adbhid[id]->input, KEY_SOUND, down);
364 input_report_key(&adbhid[id]->input, KEY_MUTE, down);
367 case 0x2: /* volume decrease */
368 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down);
371 case 0x3: /* volume increase */
372 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down);
376 printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
377 data[0], data[1], data[2], data[3]);
383 case 0x1f: /* Powerbook button device */
385 int down = (data[1] == (data[1] & 0xf));
386 #ifdef CONFIG_PMAC_BACKLIGHT
387 int backlight = get_backlight_level();
390 * XXX: Where is the contrast control for the passive?
394 switch (data[1] & 0x0f) {
396 input_report_key(&adbhid[id]->input, KEY_MUTE, down);
399 case 0x7: /* volume decrease */
400 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down);
403 case 0x6: /* volume increase */
404 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down);
407 case 0xb: /* eject */
408 input_report_key(&adbhid[id]->input, KEY_EJECTCD, down);
411 case 0xa: /* brightness decrease */
412 #ifdef CONFIG_PMAC_BACKLIGHT
413 if (!disable_kernel_backlight) {
414 if (down && backlight >= 0) {
415 if (backlight > BACKLIGHT_OFF)
416 set_backlight_level(backlight-1);
418 set_backlight_level(BACKLIGHT_OFF);
421 #endif /* CONFIG_PMAC_BACKLIGHT */
422 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
425 case 0x9: /* brightness increase */
426 #ifdef CONFIG_PMAC_BACKLIGHT
427 if (!disable_kernel_backlight) {
428 if (down && backlight >= 0) {
429 if (backlight < BACKLIGHT_MAX)
430 set_backlight_level(backlight+1);
432 set_backlight_level(BACKLIGHT_MAX);
435 #endif /* CONFIG_PMAC_BACKLIGHT */
436 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSUP, down);
443 input_sync(&adbhid[id]->input);
446 static struct adb_request led_request;
447 static int leds_pending[16];
448 static int leds_req_pending;
449 static int pending_devs[16];
450 static int pending_led_start=0;
451 static int pending_led_end=0;
452 static spinlock_t leds_lock = SPIN_LOCK_UNLOCKED;
454 static void leds_done(struct adb_request *req)
459 spin_lock_irqsave(&leds_lock, flags);
461 if (pending_led_start != pending_led_end) {
462 device = pending_devs[pending_led_start];
463 leds = leds_pending[device] & 0xff;
464 leds_pending[device] = 0;
466 pending_led_start = (pending_led_start < 16) ? pending_led_start : 0;
468 leds_req_pending = 0;
470 spin_unlock_irqrestore(&leds_lock, flags);
471 if (leds_req_pending)
472 adb_request(&led_request, leds_done, 0, 3,
473 ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
476 static void real_leds(unsigned char leds, int device)
480 spin_lock_irqsave(&leds_lock, flags);
481 if (!leds_req_pending) {
482 leds_req_pending = 1;
483 spin_unlock_irqrestore(&leds_lock, flags);
484 adb_request(&led_request, leds_done, 0, 3,
485 ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
488 if (!(leds_pending[device] & 0x100)) {
489 pending_devs[pending_led_end] = device;
491 pending_led_end = (pending_led_end < 16) ? pending_led_end : 0;
493 leds_pending[device] = leds | 0x100;
495 spin_unlock_irqrestore(&leds_lock, flags);
499 * Event callback from the input module. Events that change the state of
500 * the hardware are processed here.
502 static int adbhid_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
504 struct adbhid *adbhid = dev->private;
509 leds = (test_bit(LED_SCROLLL, dev->led) ? 4 : 0)
510 | (test_bit(LED_NUML, dev->led) ? 1 : 0)
511 | (test_bit(LED_CAPSL, dev->led) ? 2 : 0);
512 real_leds(leds, adbhid->id);
520 adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
523 case ADB_MSG_PRE_RESET:
524 case ADB_MSG_POWERDOWN:
525 /* Stop the repeat timer. Autopoll is already off at this point */
528 for (i = 1; i < 16; i++) {
530 del_timer_sync(&adbhid[i]->input.timer);
534 /* Stop pending led requests */
535 while(leds_req_pending)
539 case ADB_MSG_POST_RESET:
547 adbhid_input_register(int id, int default_id, int original_handler_id,
548 int current_handler_id, int mouse_kind)
553 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
557 if (!(adbhid[id] = kmalloc(sizeof(struct adbhid), GFP_KERNEL)))
560 memset(adbhid[id], 0, sizeof(struct adbhid));
561 sprintf(adbhid[id]->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
563 init_input_dev(&adbhid[id]->input);
565 adbhid[id]->id = default_id;
566 adbhid[id]->original_handler_id = original_handler_id;
567 adbhid[id]->current_handler_id = current_handler_id;
568 adbhid[id]->mouse_kind = mouse_kind;
569 adbhid[id]->flags = 0;
570 adbhid[id]->input.private = adbhid[id];
571 adbhid[id]->input.name = adbhid[id]->name;
572 adbhid[id]->input.phys = adbhid[id]->phys;
573 adbhid[id]->input.id.bustype = BUS_ADB;
574 adbhid[id]->input.id.vendor = 0x0001;
575 adbhid[id]->input.id.product = (id << 12) | (default_id << 8) | original_handler_id;
576 adbhid[id]->input.id.version = 0x0100;
578 switch (default_id) {
580 if (!(adbhid[id]->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL))) {
585 sprintf(adbhid[id]->name, "ADB keyboard");
587 memcpy(adbhid[id]->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
589 printk(KERN_INFO "Detected ADB keyboard, type ");
590 switch (original_handler_id) {
592 printk("<unknown>.\n");
593 adbhid[id]->input.id.version = ADB_KEYBOARD_UNKNOWN;
596 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
597 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
598 case 0xC0: case 0xC3: case 0xC6:
600 adbhid[id]->input.id.version = ADB_KEYBOARD_ANSI;
603 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
604 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
605 case 0xC4: case 0xC7:
606 printk("ISO, swapping keys.\n");
607 adbhid[id]->input.id.version = ADB_KEYBOARD_ISO;
608 i = adbhid[id]->keycode[10];
609 adbhid[id]->keycode[10] = adbhid[id]->keycode[50];
610 adbhid[id]->keycode[50] = i;
613 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
614 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
616 adbhid[id]->input.id.version = ADB_KEYBOARD_JIS;
620 for (i = 0; i < 128; i++)
621 if (adbhid[id]->keycode[i])
622 set_bit(adbhid[id]->keycode[i], adbhid[id]->input.keybit);
624 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
625 adbhid[id]->input.ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
626 adbhid[id]->input.event = adbhid_kbd_event;
627 adbhid[id]->input.keycodemax = 127;
628 adbhid[id]->input.keycodesize = 1;
632 sprintf(adbhid[id]->name, "ADB mouse");
634 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
635 adbhid[id]->input.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
636 adbhid[id]->input.relbit[0] = BIT(REL_X) | BIT(REL_Y);
640 switch (original_handler_id) {
641 case 0x02: /* Adjustable keyboard button device */
642 sprintf(adbhid[id]->name, "ADB adjustable keyboard buttons");
643 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
644 set_bit(KEY_SOUND, adbhid[id]->input.keybit);
645 set_bit(KEY_MUTE, adbhid[id]->input.keybit);
646 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit);
647 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit);
649 case 0x1f: /* Powerbook button device */
650 sprintf(adbhid[id]->name, "ADB Powerbook buttons");
651 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
652 set_bit(KEY_MUTE, adbhid[id]->input.keybit);
653 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit);
654 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit);
655 set_bit(KEY_BRIGHTNESSUP, adbhid[id]->input.keybit);
656 set_bit(KEY_BRIGHTNESSDOWN, adbhid[id]->input.keybit);
657 set_bit(KEY_EJECTCD, adbhid[id]->input.keybit);
660 if (adbhid[id]->name[0])
662 /* else fall through */
665 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
670 adbhid[id]->input.keycode = adbhid[id]->keycode;
672 input_register_device(&adbhid[id]->input);
674 printk(KERN_INFO "input: %s on %s\n",
675 adbhid[id]->name, adbhid[id]->phys);
677 if (default_id == ADB_KEYBOARD) {
678 /* HACK WARNING!! This should go away as soon there is an utility
679 * to control that for event devices.
681 adbhid[id]->input.rep[REP_DELAY] = 500; /* input layer default: 250 */
682 adbhid[id]->input.rep[REP_PERIOD] = 66; /* input layer default: 33 */
686 static void adbhid_input_unregister(int id)
688 input_unregister_device(&adbhid[id]->input);
689 if (adbhid[id]->keycode)
690 kfree(adbhid[id]->keycode);
697 adbhid_input_reregister(int id, int default_id, int org_handler_id,
698 int cur_handler_id, int mk)
701 if (adbhid[id]->input.id.product !=
702 ((id << 12)|(default_id << 8)|org_handler_id)) {
703 adbhid_input_unregister(id);
704 adbhid_input_register(id, default_id, org_handler_id,
708 adbhid_input_register(id, default_id, org_handler_id,
714 adbhid_input_devcleanup(u16 exist)
718 if (adbhid[i] && !(exist&(1<<i)))
719 adbhid_input_unregister(i);
725 struct adb_request req;
726 int i, default_id, org_handler_id, cur_handler_id;
729 adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input);
730 adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input);
731 adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input);
733 for (i = 0; i < keyboard_ids.nids; i++) {
734 int id = keyboard_ids.id[i];
736 adb_get_infos(id, &default_id, &org_handler_id);
738 /* turn off all leds */
739 adb_request(&req, NULL, ADBREQ_SYNC, 3,
740 ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
742 /* Enable full feature set of the keyboard
743 ->get it to send separate codes for left and right shift,
744 control, option keys */
745 #if 0 /* handler 5 doesn't send separate codes for R modifiers */
746 if (adb_try_handler_change(id, 5))
747 printk("ADB keyboard at %d, handler set to 5\n", id);
750 if (adb_try_handler_change(id, 3))
751 printk("ADB keyboard at %d, handler set to 3\n", id);
753 printk("ADB keyboard at %d, handler 1\n", id);
755 adb_get_infos(id, &default_id, &cur_handler_id);
756 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
760 for (i = 0; i < buttons_ids.nids; i++) {
761 int id = buttons_ids.id[i];
763 adb_get_infos(id, &default_id, &org_handler_id);
764 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
768 /* Try to switch all mice to handler 4, or 2 for three-button
769 mode and full resolution. */
770 for (i = 0; i < mouse_ids.nids; i++) {
771 int id = mouse_ids.id[i];
774 adb_get_infos(id, &default_id, &org_handler_id);
776 if (adb_try_handler_change(id, 4)) {
777 printk("ADB mouse at %d, handler set to 4", id);
778 mouse_kind = ADBMOUSE_EXTENDED;
780 else if (adb_try_handler_change(id, 0x2F)) {
781 printk("ADB mouse at %d, handler set to 0x2F", id);
782 mouse_kind = ADBMOUSE_MICROSPEED;
784 else if (adb_try_handler_change(id, 0x42)) {
785 printk("ADB mouse at %d, handler set to 0x42", id);
786 mouse_kind = ADBMOUSE_TRACKBALLPRO;
788 else if (adb_try_handler_change(id, 0x66)) {
789 printk("ADB mouse at %d, handler set to 0x66", id);
790 mouse_kind = ADBMOUSE_MICROSPEED;
792 else if (adb_try_handler_change(id, 0x5F)) {
793 printk("ADB mouse at %d, handler set to 0x5F", id);
794 mouse_kind = ADBMOUSE_MICROSPEED;
796 else if (adb_try_handler_change(id, 3)) {
797 printk("ADB mouse at %d, handler set to 3", id);
798 mouse_kind = ADBMOUSE_MS_A3;
800 else if (adb_try_handler_change(id, 2)) {
801 printk("ADB mouse at %d, handler set to 2", id);
802 mouse_kind = ADBMOUSE_STANDARD_200;
805 printk("ADB mouse at %d, handler 1", id);
806 mouse_kind = ADBMOUSE_STANDARD_100;
809 if ((mouse_kind == ADBMOUSE_TRACKBALLPRO)
810 || (mouse_kind == ADBMOUSE_MICROSPEED)) {
812 } else if (mouse_kind == ADBMOUSE_MS_A3) {
814 } else if (mouse_kind == ADBMOUSE_EXTENDED) {
816 * Register 1 is usually used for device
817 * identification. Here, we try to identify
818 * a known device and call the appropriate
821 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
824 if ((req.reply_len) &&
825 (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
826 || (req.reply[2] == 0x20))) {
827 mouse_kind = ADBMOUSE_TRACKBALL;
830 else if ((req.reply_len >= 4) &&
831 (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
832 (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) {
833 mouse_kind = ADBMOUSE_TRACKPAD;
836 else if ((req.reply_len >= 4) &&
837 (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
838 (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) {
839 mouse_kind = ADBMOUSE_TURBOMOUSE5;
842 else if ((req.reply_len == 9) &&
843 (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
844 (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) {
845 if (adb_try_handler_change(id, 0x42)) {
846 printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
847 mouse_kind = ADBMOUSE_MACALLY2;
853 adb_get_infos(id, &default_id, &cur_handler_id);
854 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
855 cur_handler_id, mouse_kind);
857 adbhid_input_devcleanup(reg);
861 init_trackpad(int id)
863 struct adb_request req;
864 unsigned char r1_buffer[8];
866 printk(" (trackpad)");
868 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
870 if (req.reply_len < 8)
871 printk("bad length for reg. 1\n");
874 memcpy(r1_buffer, &req.reply[1], 8);
876 adb_request(&req, NULL, ADBREQ_SYNC, 9,
887 adb_request(&req, NULL, ADBREQ_SYNC, 9,
898 adb_request(&req, NULL, ADBREQ_SYNC, 9,
906 0x03, /*r1_buffer[6],*/
909 /* Without this flush, the trackpad may be locked up */
910 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
915 init_trackball(int id)
917 struct adb_request req;
919 printk(" (trackman/mouseman)");
921 adb_request(&req, NULL, ADBREQ_SYNC, 3,
922 ADB_WRITEREG(id,1), 00,0x81);
924 adb_request(&req, NULL, ADBREQ_SYNC, 3,
925 ADB_WRITEREG(id,1), 01,0x81);
927 adb_request(&req, NULL, ADBREQ_SYNC, 3,
928 ADB_WRITEREG(id,1), 02,0x81);
930 adb_request(&req, NULL, ADBREQ_SYNC, 3,
931 ADB_WRITEREG(id,1), 03,0x38);
933 adb_request(&req, NULL, ADBREQ_SYNC, 3,
934 ADB_WRITEREG(id,1), 00,0x81);
936 adb_request(&req, NULL, ADBREQ_SYNC, 3,
937 ADB_WRITEREG(id,1), 01,0x81);
939 adb_request(&req, NULL, ADBREQ_SYNC, 3,
940 ADB_WRITEREG(id,1), 02,0x81);
942 adb_request(&req, NULL, ADBREQ_SYNC, 3,
943 ADB_WRITEREG(id,1), 03,0x38);
947 init_turbomouse(int id)
949 struct adb_request req;
951 printk(" (TurboMouse 5)");
953 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
955 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
957 adb_request(&req, NULL, ADBREQ_SYNC, 9,
968 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
970 adb_request(&req, NULL, ADBREQ_SYNC, 9,
983 init_microspeed(int id)
985 struct adb_request req;
987 printk(" (Microspeed/MacPoint or compatible)");
989 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
991 /* This will initialize mice using the Microspeed, MacPoint and
992 other compatible firmware. Bit 12 enables extended protocol.
994 Register 1 Listen (4 Bytes)
995 0 - 3 Button is mouse (set also for double clicking!!!)
996 4 - 7 Button is locking (affects change speed also)
997 8 - 11 Button changes speed
998 12 1 = Extended mouse mode, 0 = normal mouse mode
1000 16 - 23 normal speed
1001 24 - 31 changed speed
1003 Register 1 talk holds version and product identification information.
1004 Register 1 Talk (4 Bytes):
1006 8 - 23 undefined, reserved
1007 24 - 31 Version number
1009 Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
1011 adb_request(&req, NULL, ADBREQ_SYNC, 5,
1013 0x20, /* alt speed = 0x20 (rather slow) */
1014 0x00, /* norm speed = 0x00 (fastest) */
1015 0x10, /* extended protocol, no speed change */
1016 0x07); /* all buttons enabled as mouse buttons, no locking */
1019 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1025 struct adb_request req;
1027 printk(" (Mouse Systems A3 Mouse, or compatible)");
1028 adb_request(&req, NULL, ADBREQ_SYNC, 3,
1029 ADB_WRITEREG(id, 0x2),
1033 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
1036 static int __init adbhid_init(void)
1039 if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) )
1043 led_request.complete = 1;
1047 notifier_chain_register(&adb_client_list, &adbhid_adb_notifier);
1052 static void __exit adbhid_exit(void)
1056 module_init(adbhid_init);
1057 module_exit(adbhid_exit);