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 * (see that file for its authors and contributors).
9 * Copyright (C) 2000 Franz Sirl.
11 * Adapted to ADB changes and support for more devices by
12 * Benjamin Herrenschmidt. Adapted from code in MkLinux
17 * - Standard 1 button mouse
18 * - All standard Apple Extended protocol (handler ID 4)
19 * - mouseman and trackman mice & trackballs
20 * - PowerBook Trackpad (default setup: enable tapping)
21 * - MicroSpeed mouse & trackball (needs testing)
22 * - CH Products Trackball Pro (needs testing)
23 * - Contour Design (Contour Mouse)
24 * - Hunter digital (NoHandsMouse)
25 * - Kensignton TurboMouse 5 (needs testing)
26 * - Mouse Systems A3 mice and trackballs <aidan@kublai.com>
27 * - MacAlly 2-buttons mouse (needs testing) <pochini@denise.shiny.it>
31 * Improve Kensington support.
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/init.h>
38 #include <linux/notifier.h>
39 #include <linux/input.h>
40 #include <linux/kbd_ll.h>
42 #include <linux/adb.h>
43 #include <linux/cuda.h>
44 #include <linux/pmu.h>
46 #include <asm/machdep.h>
48 #include <asm/pmac_feature.h>
51 #ifdef CONFIG_PMAC_BACKLIGHT
52 #include <asm/backlight.h>
55 MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>");
57 #define KEYB_KEYREG 0 /* register # for key up/down data */
58 #define KEYB_LEDREG 2 /* register # for leds on ADB keyboard */
59 #define MOUSE_DATAREG 0 /* reg# for movement/button codes from mouse */
61 static int adb_message_handler(struct notifier_block *, unsigned long, void *);
62 static struct notifier_block adbhid_adb_notifier = {
63 notifier_call: adb_message_handler,
66 unsigned char adb_to_linux_keycodes[128] = {
67 30, 31, 32, 33, 35, 34, 44, 45, 46, 47, 86, 48, 16, 17, 18, 19,
68 21, 20, 2, 3, 4, 5, 7, 6, 13, 10, 8, 12, 9, 11, 27, 24,
69 22, 26, 23, 25, 28, 38, 36, 40, 37, 39, 43, 51, 53, 49, 50, 52,
70 15, 57, 41, 14, 96, 1, 29,125, 42, 58, 56,105,106,108,103, 0,
71 0, 83, 0, 55, 0, 78, 0, 69, 0, 0, 0, 98, 96, 0, 74, 0,
72 0,117, 82, 79, 80, 81, 75, 76, 77, 71, 0, 72, 73,183,181,124,
73 63, 64, 65, 61, 66, 67,191, 87,190, 99, 0, 70, 0, 68,101, 88,
74 0,119,110,102,104,111, 62,107, 60,109, 59, 54,100, 97,126,116
78 struct input_dev input;
81 int original_handler_id;
82 int current_handler_id;
84 unsigned char *keycode;
88 static struct adbhid *adbhid[16] = { 0 };
90 static void adbhid_probe(void);
92 static void adbhid_input_keycode(int, int, int);
93 static void leds_done(struct adb_request *);
95 static void init_trackpad(int id);
96 static void init_trackball(int id);
97 static void init_turbomouse(int id);
98 static void init_microspeed(int id);
99 static void init_ms_a3(int id);
101 static struct adb_ids keyboard_ids;
102 static struct adb_ids mouse_ids;
103 static struct adb_ids buttons_ids;
105 #ifdef CONFIG_PMAC_BACKLIGHT
106 /* Exported to via-pmu.c */
107 int disable_kernel_backlight = 0;
108 #endif /* CONFIG_PMAC_BACKLIGHT */
110 /* Kind of keyboard, see Apple technote 1152 */
111 #define ADB_KEYBOARD_UNKNOWN 0
112 #define ADB_KEYBOARD_ANSI 0x0100
113 #define ADB_KEYBOARD_ISO 0x0200
114 #define ADB_KEYBOARD_JIS 0x0300
117 #define ADBMOUSE_STANDARD_100 0 /* Standard 100cpi mouse (handler 1) */
118 #define ADBMOUSE_STANDARD_200 1 /* Standard 200cpi mouse (handler 2) */
119 #define ADBMOUSE_EXTENDED 2 /* Apple Extended mouse (handler 4) */
120 #define ADBMOUSE_TRACKBALL 3 /* TrackBall (handler 4) */
121 #define ADBMOUSE_TRACKPAD 4 /* Apple's PowerBook trackpad (handler 4) */
122 #define ADBMOUSE_TURBOMOUSE5 5 /* Turbomouse 5 (previously req. mousehack) */
123 #define ADBMOUSE_MICROSPEED 6 /* Microspeed mouse (&trackball ?), MacPoint */
124 #define ADBMOUSE_TRACKBALLPRO 7 /* Trackball Pro (special buttons) */
125 #define ADBMOUSE_MS_A3 8 /* Mouse systems A3 trackball (handler 3) */
126 #define ADBMOUSE_MACALLY2 9 /* MacAlly 2-button mouse */
129 adbhid_keyboard_input(unsigned char *data, int nb, struct pt_regs *regs, int apoll)
131 int id = (data[0] >> 4) & 0x0f;
134 printk(KERN_ERR "ADB HID on ID %d not yet registered, packet %#02x, %#02x, %#02x, %#02x\n",
135 id, data[0], data[1], data[2], data[3]);
139 /* first check this is from register 0 */
140 if (nb != 3 || (data[0] & 3) != KEYB_KEYREG)
141 return; /* ignore it */
143 adbhid_input_keycode(id, data[1], 0);
144 if (!(data[2] == 0xff || (data[2] == 0x7f && data[1] == 0x7f)))
145 adbhid_input_keycode(id, data[2], 0);
149 adbhid_input_keycode(int id, int keycode, int repeat)
153 up_flag = (keycode & 0x80);
157 case 0x39: /* Generate down/up events for CapsLock everytime. */
158 input_report_key(&adbhid[id]->input, KEY_CAPSLOCK, 1);
159 input_report_key(&adbhid[id]->input, KEY_CAPSLOCK, 0);
161 case 0x3f: /* ignore Powerbook Fn key */
163 #ifdef CONFIG_ALL_PPC
164 case 0x7e: /* Power key on PBook 3400 needs remapping */
165 switch(pmac_call_feature(PMAC_FTR_GET_MB_INFO,
166 NULL, PMAC_MB_INFO_MODEL, 0)) {
167 case PMAC_TYPE_COMET:
168 case PMAC_TYPE_HOOPER:
169 case PMAC_TYPE_KANGA:
173 #endif /* CONFIG_ALL_PPC */
176 if (adbhid[id]->keycode[keycode])
177 input_report_key(&adbhid[id]->input,
178 adbhid[id]->keycode[keycode], !up_flag);
180 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode,
181 up_flag ? "released" : "pressed");
185 adbhid_mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
187 int id = (data[0] >> 4) & 0x0f;
190 printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
195 Handler 1 -- 100cpi original Apple mouse protocol.
196 Handler 2 -- 200cpi original Apple mouse protocol.
198 For Apple's standard one-button mouse protocol the data array will
199 contain the following values:
202 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
203 data[1] = bxxx xxxx First button and x-axis motion.
204 data[2] = byyy yyyy Second button and y-axis motion.
206 Handler 4 -- Apple Extended mouse protocol.
208 For Apple's 3-button mouse protocol the data array will contain the
212 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
213 data[1] = bxxx xxxx Left button and x-axis motion.
214 data[2] = byyy yyyy Second button and y-axis motion.
215 data[3] = byyy bxxx Third button and fourth button. Y is additional
216 high bits of y-axis motion. XY is additional
217 high bits of x-axis motion.
219 MacAlly 2-button mouse protocol.
221 For MacAlly 2-button mouse protocol the data array will contain the
225 data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
226 data[1] = bxxx xxxx Left button and x-axis motion.
227 data[2] = byyy yyyy Right button and y-axis motion.
228 data[3] = ???? ???? unknown
229 data[4] = ???? ???? unknown
233 /* If it's a trackpad, we alias the second button to the first.
234 NOTE: Apple sends an ADB flush command to the trackpad when
235 the first (the real) button is released. We could do
236 this here using async flush requests.
238 switch (adbhid[id]->mouse_kind)
240 case ADBMOUSE_TRACKPAD:
241 data[1] = (data[1] & 0x7f) | ((data[1] & data[2]) & 0x80);
242 data[2] = data[2] | 0x80;
244 case ADBMOUSE_MICROSPEED:
245 data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
246 data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
247 data[3] = (data[3] & 0x77) | ((data[3] & 0x04) << 5)
250 case ADBMOUSE_TRACKBALLPRO:
251 data[1] = (data[1] & 0x7f) | (((data[3] & 0x04) << 5)
252 & ((data[3] & 0x08) << 4));
253 data[2] = (data[2] & 0x7f) | ((data[3] & 0x01) << 7);
254 data[3] = (data[3] & 0x77) | ((data[3] & 0x02) << 6);
257 data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
258 data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
259 data[3] = ((data[3] & 0x04) << 5);
261 case ADBMOUSE_MACALLY2:
262 data[3] = (data[2] & 0x80) ? 0x80 : 0x00;
263 data[2] |= 0x80; /* Right button is mapped as button 3 */
268 input_report_key(&adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1));
269 input_report_key(&adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1));
272 input_report_key(&adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1));
274 input_report_rel(&adbhid[id]->input, REL_X,
275 ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ));
276 input_report_rel(&adbhid[id]->input, REL_Y,
277 ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 ));
281 adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
283 int id = (data[0] >> 4) & 0x0f;
286 printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
290 switch (adbhid[id]->original_handler_id) {
292 case 0x02: /* Adjustable keyboard button device */
293 printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
294 data[0], data[1], data[2], data[3]);
296 case 0x1f: /* Powerbook button device */
298 int down = (data[1] == (data[1] & 0xf));
299 #ifdef CONFIG_PMAC_BACKLIGHT
300 int backlight = get_backlight_level();
303 * XXX: Where is the contrast control for the passive?
307 switch (data[1] & 0x0f) {
309 input_report_key(&adbhid[id]->input, KEY_MUTE, down);
312 case 0x7: /* volume decrease */
313 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down);
316 case 0x6: /* volume increase */
317 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down);
320 case 0xb: /* eject */
321 input_report_key(&adbhid[id]->input, KEY_EJECTCD, down);
323 case 0xa: /* brightness decrease */
324 #ifdef CONFIG_PMAC_BACKLIGHT
325 if (!disable_kernel_backlight) {
326 if (down && backlight >= 0) {
327 if (backlight > BACKLIGHT_OFF)
328 set_backlight_level(backlight-1);
330 set_backlight_level(BACKLIGHT_OFF);
333 #endif /* CONFIG_PMAC_BACKLIGHT */
334 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
336 case 0x9: /* brightness increase */
337 #ifdef CONFIG_PMAC_BACKLIGHT
338 if (!disable_kernel_backlight) {
339 if (down && backlight >= 0) {
340 if (backlight < BACKLIGHT_MAX)
341 set_backlight_level(backlight+1);
343 set_backlight_level(BACKLIGHT_MAX);
346 #endif /* CONFIG_PMAC_BACKLIGHT */
347 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSUP, down);
355 static struct adb_request led_request;
356 static int leds_pending[16];
357 static int pending_devs[16];
358 static int pending_led_start=0;
359 static int pending_led_end=0;
361 static void real_leds(unsigned char leds, int device)
363 if (led_request.complete) {
364 adb_request(&led_request, leds_done, 0, 3,
365 ADB_WRITEREG(device, KEYB_LEDREG), 0xff,
368 if (!(leds_pending[device] & 0x100)) {
369 pending_devs[pending_led_end] = device;
371 pending_led_end = (pending_led_end < 16) ? pending_led_end : 0;
373 leds_pending[device] = leds | 0x100;
378 * Event callback from the input module. Events that change the state of
379 * the hardware are processed here.
381 static int adbhid_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
383 struct adbhid *adbhid = dev->private;
388 leds = (test_bit(LED_SCROLLL, dev->led) ? 4 : 0)
389 | (test_bit(LED_NUML, dev->led) ? 1 : 0)
390 | (test_bit(LED_CAPSL, dev->led) ? 2 : 0);
391 real_leds(leds, adbhid->id);
398 static void leds_done(struct adb_request *req)
402 if (pending_led_start != pending_led_end) {
403 device = pending_devs[pending_led_start];
404 leds = leds_pending[device] & 0xff;
405 leds_pending[device] = 0;
407 pending_led_start = (pending_led_start < 16) ? pending_led_start : 0;
408 real_leds(leds,device);
414 adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
419 case ADB_MSG_PRE_RESET:
420 case ADB_MSG_POWERDOWN:
421 /* Stop the repeat timer. Autopoll is already off at this point */
426 for (i = 1; i < 16; i++) {
428 del_timer(&adbhid[i]->input.timer);
431 restore_flags(flags);
433 /* Stop pending led requests */
434 while(!led_request.complete)
438 case ADB_MSG_POST_RESET:
446 adbhid_input_register(int id, int default_id, int original_handler_id,
447 int current_handler_id, int mouse_kind)
452 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
456 if (!(adbhid[id] = kmalloc(sizeof(struct adbhid), GFP_KERNEL)))
459 memset(adbhid[id], 0, sizeof(struct adbhid));
461 adbhid[id]->id = default_id;
462 adbhid[id]->original_handler_id = original_handler_id;
463 adbhid[id]->current_handler_id = current_handler_id;
464 adbhid[id]->mouse_kind = mouse_kind;
465 adbhid[id]->input.private = adbhid[id];
466 adbhid[id]->input.name = adbhid[id]->name;
467 adbhid[id]->input.idbus = BUS_ADB;
468 adbhid[id]->input.idvendor = 0x0001;
469 adbhid[id]->input.idproduct = (id << 12) | (default_id << 8) | original_handler_id;
470 adbhid[id]->input.idversion = 0x0100;
472 switch (default_id) {
474 if (!(adbhid[id]->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL))) {
479 sprintf(adbhid[id]->name, "ADB keyboard on ID %d:%d.%02x",
480 id, default_id, original_handler_id);
482 memcpy(adbhid[id]->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
484 printk(KERN_INFO "Detected ADB keyboard, type ");
485 switch (original_handler_id) {
487 printk("<unknown>.\n");
488 adbhid[id]->input.idversion = ADB_KEYBOARD_UNKNOWN;
491 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
492 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
493 case 0xC0: case 0xC3: case 0xC6:
495 adbhid[id]->input.idversion = ADB_KEYBOARD_ANSI;
498 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
499 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
500 case 0xC4: case 0xC7:
501 printk("ISO, swapping keys.\n");
502 adbhid[id]->input.idversion = ADB_KEYBOARD_ISO;
503 i = adbhid[id]->keycode[10];
504 adbhid[id]->keycode[10] = adbhid[id]->keycode[50];
505 adbhid[id]->keycode[50] = i;
508 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
509 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
511 adbhid[id]->input.idversion = ADB_KEYBOARD_JIS;
515 for (i = 0; i < 128; i++)
516 if (adbhid[id]->keycode[i])
517 set_bit(adbhid[id]->keycode[i], adbhid[id]->input.keybit);
519 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
520 adbhid[id]->input.ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
521 adbhid[id]->input.event = adbhid_kbd_event;
522 adbhid[id]->input.keycodemax = 127;
523 adbhid[id]->input.keycodesize = 1;
527 sprintf(adbhid[id]->name, "ADB mouse on ID %d:%d.%02x",
528 id, default_id, original_handler_id);
530 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
531 adbhid[id]->input.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
532 adbhid[id]->input.relbit[0] = BIT(REL_X) | BIT(REL_Y);
536 switch (original_handler_id) {
537 case 0x02: /* Adjustable keyboard button device */
538 sprintf(adbhid[id]->name, "ADB adjustable keyboard buttons on ID %d:%d.%02x",
539 id, default_id, original_handler_id);
541 case 0x1f: /* Powerbook button device */
542 sprintf(adbhid[id]->name, "ADB Powerbook buttons on ID %d:%d.%02x",
543 id, default_id, original_handler_id);
544 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
545 set_bit(KEY_MUTE, adbhid[id]->input.keybit);
546 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit);
547 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit);
548 set_bit(KEY_BRIGHTNESSUP, adbhid[id]->input.keybit);
549 set_bit(KEY_BRIGHTNESSDOWN, adbhid[id]->input.keybit);
550 set_bit(KEY_EJECTCD, adbhid[id]->input.keybit);
553 if (adbhid[id]->name[0])
555 /* else fall through */
558 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
563 adbhid[id]->input.keycode = adbhid[id]->keycode;
565 input_register_device(&adbhid[id]->input);
567 printk(KERN_INFO "input%d: ADB HID on ID %d:%d.%02x\n",
568 adbhid[id]->input.number, id, default_id, original_handler_id);
570 if (default_id == ADB_KEYBOARD) {
571 /* HACK WARNING!! This should go away as soon there is an utility
572 * to control that for event devices.
574 adbhid[id]->input.rep[REP_DELAY] = HZ/2; /* input layer default: HZ/4 */
575 adbhid[id]->input.rep[REP_PERIOD] = HZ/15; /* input layer default: HZ/33 */
579 static void adbhid_input_unregister(int id)
581 input_unregister_device(&adbhid[id]->input);
582 if (adbhid[id]->keycode)
583 kfree(adbhid[id]->keycode);
590 adbhid_input_reregister(int id, int default_id, int org_handler_id,
591 int cur_handler_id, int mk)
594 if (adbhid[id]->input.idproduct !=
595 ((id << 12)|(default_id << 8)|org_handler_id)) {
596 adbhid_input_unregister(id);
597 adbhid_input_register(id, default_id, org_handler_id,
601 adbhid_input_register(id, default_id, org_handler_id,
607 adbhid_input_devcleanup(u16 exist)
611 if (adbhid[i] && !(exist&(1<<i)))
612 adbhid_input_unregister(i);
618 struct adb_request req;
619 int i, default_id, org_handler_id, cur_handler_id;
622 adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input);
623 adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input);
624 adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input);
626 for (i = 0; i < keyboard_ids.nids; i++) {
627 int id = keyboard_ids.id[i];
629 adb_get_infos(id, &default_id, &org_handler_id);
631 /* turn off all leds */
632 adb_request(&req, NULL, ADBREQ_SYNC, 3,
633 ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
635 /* Enable full feature set of the keyboard
636 ->get it to send separate codes for left and right shift,
637 control, option keys */
638 #if 0 /* handler 5 doesn't send separate codes for R modifiers */
639 if (adb_try_handler_change(id, 5))
640 printk("ADB keyboard at %d, handler set to 5\n", id);
643 if (adb_try_handler_change(id, 3))
644 printk("ADB keyboard at %d, handler set to 3\n", id);
646 printk("ADB keyboard at %d, handler 1\n", id);
648 adb_get_infos(id, &default_id, &cur_handler_id);
649 reg |= adbhid_input_reregister(id, default_id, org_handler_id, cur_handler_id, 0);
652 for (i = 0; i < buttons_ids.nids; i++) {
653 int id = buttons_ids.id[i];
655 adb_get_infos(id, &default_id, &org_handler_id);
656 reg |= adbhid_input_reregister(id, default_id, org_handler_id, org_handler_id, 0);
659 /* Try to switch all mice to handler 4, or 2 for three-button
660 mode and full resolution. */
661 for (i = 0; i < mouse_ids.nids; i++) {
662 int id = mouse_ids.id[i];
665 adb_get_infos(id, &default_id, &org_handler_id);
667 if (adb_try_handler_change(id, 4)) {
668 printk("ADB mouse at %d, handler set to 4", id);
669 mouse_kind = ADBMOUSE_EXTENDED;
671 else if (adb_try_handler_change(id, 0x2F)) {
672 printk("ADB mouse at %d, handler set to 0x2F", id);
673 mouse_kind = ADBMOUSE_MICROSPEED;
675 else if (adb_try_handler_change(id, 0x42)) {
676 printk("ADB mouse at %d, handler set to 0x42", id);
677 mouse_kind = ADBMOUSE_TRACKBALLPRO;
679 else if (adb_try_handler_change(id, 0x66)) {
680 printk("ADB mouse at %d, handler set to 0x66", id);
681 mouse_kind = ADBMOUSE_MICROSPEED;
683 else if (adb_try_handler_change(id, 0x5F)) {
684 printk("ADB mouse at %d, handler set to 0x5F", id);
685 mouse_kind = ADBMOUSE_MICROSPEED;
687 else if (adb_try_handler_change(id, 3)) {
688 printk("ADB mouse at %d, handler set to 3", id);
689 mouse_kind = ADBMOUSE_MS_A3;
691 else if (adb_try_handler_change(id, 2)) {
692 printk("ADB mouse at %d, handler set to 2", id);
693 mouse_kind = ADBMOUSE_STANDARD_200;
696 printk("ADB mouse at %d, handler 1", id);
697 mouse_kind = ADBMOUSE_STANDARD_100;
700 if ((mouse_kind == ADBMOUSE_TRACKBALLPRO)
701 || (mouse_kind == ADBMOUSE_MICROSPEED)) {
703 } else if (mouse_kind == ADBMOUSE_MS_A3) {
705 } else if (mouse_kind == ADBMOUSE_EXTENDED) {
707 * Register 1 is usually used for device
708 * identification. Here, we try to identify
709 * a known device and call the appropriate
712 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
715 if ((req.reply_len) &&
716 (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
717 || (req.reply[2] == 0x20))) {
718 mouse_kind = ADBMOUSE_TRACKBALL;
721 else if ((req.reply_len >= 4) &&
722 (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
723 (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) {
724 mouse_kind = ADBMOUSE_TRACKPAD;
727 else if ((req.reply_len >= 4) &&
728 (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
729 (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) {
730 mouse_kind = ADBMOUSE_TURBOMOUSE5;
733 else if ((req.reply_len == 9) &&
734 (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
735 (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) {
736 if (adb_try_handler_change(id, 0x42)) {
737 printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
738 mouse_kind = ADBMOUSE_MACALLY2;
744 adb_get_infos(id, &default_id, &cur_handler_id);
745 reg |= adbhid_input_reregister(id, default_id, org_handler_id,
746 cur_handler_id, mouse_kind);
748 adbhid_input_devcleanup(reg);
752 init_trackpad(int id)
754 struct adb_request req;
755 unsigned char r1_buffer[8];
757 printk(" (trackpad)");
759 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
761 if (req.reply_len < 8)
762 printk("bad length for reg. 1\n");
765 memcpy(r1_buffer, &req.reply[1], 8);
767 adb_request(&req, NULL, ADBREQ_SYNC, 9,
778 adb_request(&req, NULL, ADBREQ_SYNC, 9,
789 adb_request(&req, NULL, ADBREQ_SYNC, 9,
797 0x03, /*r1_buffer[6],*/
800 /* Without this flush, the trackpad may be locked up */
801 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
806 init_trackball(int id)
808 struct adb_request req;
810 printk(" (trackman/mouseman)");
812 adb_request(&req, NULL, ADBREQ_SYNC, 3,
813 ADB_WRITEREG(id,1), 00,0x81);
815 adb_request(&req, NULL, ADBREQ_SYNC, 3,
816 ADB_WRITEREG(id,1), 01,0x81);
818 adb_request(&req, NULL, ADBREQ_SYNC, 3,
819 ADB_WRITEREG(id,1), 02,0x81);
821 adb_request(&req, NULL, ADBREQ_SYNC, 3,
822 ADB_WRITEREG(id,1), 03,0x38);
824 adb_request(&req, NULL, ADBREQ_SYNC, 3,
825 ADB_WRITEREG(id,1), 00,0x81);
827 adb_request(&req, NULL, ADBREQ_SYNC, 3,
828 ADB_WRITEREG(id,1), 01,0x81);
830 adb_request(&req, NULL, ADBREQ_SYNC, 3,
831 ADB_WRITEREG(id,1), 02,0x81);
833 adb_request(&req, NULL, ADBREQ_SYNC, 3,
834 ADB_WRITEREG(id,1), 03,0x38);
838 init_turbomouse(int id)
840 struct adb_request req;
842 printk(" (TurboMouse 5)");
844 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
846 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
848 adb_request(&req, NULL, ADBREQ_SYNC, 9,
859 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
861 adb_request(&req, NULL, ADBREQ_SYNC, 9,
874 init_microspeed(int id)
876 struct adb_request req;
878 printk(" (Microspeed/MacPoint or compatible)");
880 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
882 /* This will initialize mice using the Microspeed, MacPoint and
883 other compatible firmware. Bit 12 enables extended protocol.
885 Register 1 Listen (4 Bytes)
886 0 - 3 Button is mouse (set also for double clicking!!!)
887 4 - 7 Button is locking (affects change speed also)
888 8 - 11 Button changes speed
889 12 1 = Extended mouse mode, 0 = normal mouse mode
892 24 - 31 changed speed
894 Register 1 talk holds version and product identification information.
895 Register 1 Talk (4 Bytes):
897 8 - 23 undefined, reserved
898 24 - 31 Version number
900 Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
902 adb_request(&req, NULL, ADBREQ_SYNC, 5,
904 0x20, /* alt speed = 0x20 (rather slow) */
905 0x00, /* norm speed = 0x00 (fastest) */
906 0x10, /* extended protocol, no speed change */
907 0x07); /* all buttons enabled as mouse buttons, no locking */
910 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
916 struct adb_request req;
918 printk(" (Mouse Systems A3 Mouse, or compatible)");
919 adb_request(&req, NULL, ADBREQ_SYNC, 3,
920 ADB_WRITEREG(id, 0x2),
924 adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
927 static int __init adbhid_init(void)
930 if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) )
934 led_request.complete = 1;
938 notifier_chain_register(&adb_client_list, &adbhid_adb_notifier);
943 static void __exit adbhid_exit(void)
947 module_init(adbhid_init);
948 module_exit(adbhid_exit);