adbhid.c
来自「linux 内核源代码」· C语言 代码 · 共 1,247 行 · 第 1/3 页
C
1,247 行
set_bit(KEY_EJECTCD, input_dev->keybit); set_bit(KEY_SWITCHVIDEOMODE, input_dev->keybit); set_bit(KEY_KBDILLUMTOGGLE, input_dev->keybit); set_bit(KEY_KBDILLUMDOWN, input_dev->keybit); set_bit(KEY_KBDILLUMUP, input_dev->keybit); break; } if (hid->name[0]) break; /* else fall through */ default: printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n"); err = -ENODEV; goto fail; } input_dev->keycode = hid->keycode; err = input_register_device(input_dev); if (err) goto fail; if (default_id == ADB_KEYBOARD) { /* HACK WARNING!! This should go away as soon there is an utility * to control that for event devices. */ input_dev->rep[REP_DELAY] = 500; /* input layer default: 250 */ input_dev->rep[REP_PERIOD] = 66; /* input layer default: 33 */ } return 0; fail: input_free_device(input_dev); if (hid) { kfree(hid->keycode); kfree(hid); } adbhid[id] = NULL; return err;}static void adbhid_input_unregister(int id){ input_unregister_device(adbhid[id]->input); kfree(adbhid[id]->keycode); kfree(adbhid[id]); adbhid[id] = NULL;}static u16adbhid_input_reregister(int id, int default_id, int org_handler_id, int cur_handler_id, int mk){ if (adbhid[id]) { if (adbhid[id]->input->id.product != ((id << 12)|(default_id << 8)|org_handler_id)) { adbhid_input_unregister(id); adbhid_input_register(id, default_id, org_handler_id, cur_handler_id, mk); } } else adbhid_input_register(id, default_id, org_handler_id, cur_handler_id, mk); return 1<<id;}static voidadbhid_input_devcleanup(u16 exist){ int i; for(i=1; i<16; i++) if (adbhid[i] && !(exist&(1<<i))) adbhid_input_unregister(i);}static voidadbhid_probe(void){ struct adb_request req; int i, default_id, org_handler_id, cur_handler_id; u16 reg = 0; adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input); adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input); adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input); for (i = 0; i < keyboard_ids.nids; i++) { int id = keyboard_ids.id[i]; adb_get_infos(id, &default_id, &org_handler_id); /* turn off all leds */ adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff); /* Enable full feature set of the keyboard ->get it to send separate codes for left and right shift, control, option keys */#if 0 /* handler 5 doesn't send separate codes for R modifiers */ if (adb_try_handler_change(id, 5)) printk("ADB keyboard at %d, handler set to 5\n", id); else#endif if (adb_try_handler_change(id, 3)) printk("ADB keyboard at %d, handler set to 3\n", id); else printk("ADB keyboard at %d, handler 1\n", id); adb_get_infos(id, &default_id, &cur_handler_id); reg |= adbhid_input_reregister(id, default_id, org_handler_id, cur_handler_id, 0); } for (i = 0; i < buttons_ids.nids; i++) { int id = buttons_ids.id[i]; adb_get_infos(id, &default_id, &org_handler_id); reg |= adbhid_input_reregister(id, default_id, org_handler_id, org_handler_id, 0); } /* Try to switch all mice to handler 4, or 2 for three-button mode and full resolution. */ for (i = 0; i < mouse_ids.nids; i++) { int id = mouse_ids.id[i]; int mouse_kind; adb_get_infos(id, &default_id, &org_handler_id); if (adb_try_handler_change(id, 4)) { printk("ADB mouse at %d, handler set to 4", id); mouse_kind = ADBMOUSE_EXTENDED; } else if (adb_try_handler_change(id, 0x2F)) { printk("ADB mouse at %d, handler set to 0x2F", id); mouse_kind = ADBMOUSE_MICROSPEED; } else if (adb_try_handler_change(id, 0x42)) { printk("ADB mouse at %d, handler set to 0x42", id); mouse_kind = ADBMOUSE_TRACKBALLPRO; } else if (adb_try_handler_change(id, 0x66)) { printk("ADB mouse at %d, handler set to 0x66", id); mouse_kind = ADBMOUSE_MICROSPEED; } else if (adb_try_handler_change(id, 0x5F)) { printk("ADB mouse at %d, handler set to 0x5F", id); mouse_kind = ADBMOUSE_MICROSPEED; } else if (adb_try_handler_change(id, 3)) { printk("ADB mouse at %d, handler set to 3", id); mouse_kind = ADBMOUSE_MS_A3; } else if (adb_try_handler_change(id, 2)) { printk("ADB mouse at %d, handler set to 2", id); mouse_kind = ADBMOUSE_STANDARD_200; } else { printk("ADB mouse at %d, handler 1", id); mouse_kind = ADBMOUSE_STANDARD_100; } if ((mouse_kind == ADBMOUSE_TRACKBALLPRO) || (mouse_kind == ADBMOUSE_MICROSPEED)) { init_microspeed(id); } else if (mouse_kind == ADBMOUSE_MS_A3) { init_ms_a3(id); } else if (mouse_kind == ADBMOUSE_EXTENDED) { /* * Register 1 is usually used for device * identification. Here, we try to identify * a known device and call the appropriate * init function. */ adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, ADB_READREG(id, 1)); if ((req.reply_len) && (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21) || (req.reply[2] == 0x20))) { mouse_kind = ADBMOUSE_TRACKBALL; init_trackball(id); } else if ((req.reply_len >= 4) && (req.reply[1] == 0x74) && (req.reply[2] == 0x70) && (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) { mouse_kind = ADBMOUSE_TRACKPAD; init_trackpad(id); } else if ((req.reply_len >= 4) && (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) && (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) { mouse_kind = ADBMOUSE_TURBOMOUSE5; init_turbomouse(id); } else if ((req.reply_len == 9) && (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) && (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) { if (adb_try_handler_change(id, 0x42)) { printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id); mouse_kind = ADBMOUSE_MACALLY2; } } } printk("\n"); adb_get_infos(id, &default_id, &cur_handler_id); reg |= adbhid_input_reregister(id, default_id, org_handler_id, cur_handler_id, mouse_kind); } adbhid_input_devcleanup(reg);}static void init_trackpad(int id){ struct adb_request req; unsigned char r1_buffer[8]; printk(" (trackpad)"); adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1, ADB_READREG(id,1)); if (req.reply_len < 8) printk("bad length for reg. 1\n"); else { memcpy(r1_buffer, &req.reply[1], 8); adb_request(&req, NULL, ADBREQ_SYNC, 9, ADB_WRITEREG(id,1), r1_buffer[0], r1_buffer[1], r1_buffer[2], r1_buffer[3], r1_buffer[4], r1_buffer[5], 0x0d, r1_buffer[7]); adb_request(&req, NULL, ADBREQ_SYNC, 9, ADB_WRITEREG(id,2), 0x99, 0x94, 0x19, 0xff, 0xb2, 0x8a, 0x1b, 0x50); adb_request(&req, NULL, ADBREQ_SYNC, 9, ADB_WRITEREG(id,1), r1_buffer[0], r1_buffer[1], r1_buffer[2], r1_buffer[3], r1_buffer[4], r1_buffer[5], 0x03, /*r1_buffer[6],*/ r1_buffer[7]); /* Without this flush, the trackpad may be locked up */ adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id)); }}static void init_trackball(int id){ struct adb_request req; printk(" (trackman/mouseman)"); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 00,0x81); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 01,0x81); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 02,0x81); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 03,0x38); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 00,0x81); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 01,0x81); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 02,0x81); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id,1), 03,0x38);}static voidinit_turbomouse(int id){ struct adb_request req; printk(" (TurboMouse 5)"); adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id)); adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3)); adb_request(&req, NULL, ADBREQ_SYNC, 9, ADB_WRITEREG(3,2), 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94); adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3)); adb_request(&req, NULL, ADBREQ_SYNC, 9, ADB_WRITEREG(3,2), 0xa5, 0x14, 0, 0, 0x69, 0xff, 0xff, 0x27);}static voidinit_microspeed(int id){ struct adb_request req; printk(" (Microspeed/MacPoint or compatible)"); adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id)); /* This will initialize mice using the Microspeed, MacPoint and other compatible firmware. Bit 12 enables extended protocol. Register 1 Listen (4 Bytes) 0 - 3 Button is mouse (set also for double clicking!!!) 4 - 7 Button is locking (affects change speed also) 8 - 11 Button changes speed 12 1 = Extended mouse mode, 0 = normal mouse mode 13 - 15 unused 0 16 - 23 normal speed 24 - 31 changed speed Register 1 talk holds version and product identification information. Register 1 Talk (4 Bytes): 0 - 7 Product code 8 - 23 undefined, reserved 24 - 31 Version number Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max. */ adb_request(&req, NULL, ADBREQ_SYNC, 5, ADB_WRITEREG(id,1), 0x20, /* alt speed = 0x20 (rather slow) */ 0x00, /* norm speed = 0x00 (fastest) */ 0x10, /* extended protocol, no speed change */ 0x07); /* all buttons enabled as mouse buttons, no locking */ adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));}static voidinit_ms_a3(int id){ struct adb_request req; printk(" (Mouse Systems A3 Mouse, or compatible)"); adb_request(&req, NULL, ADBREQ_SYNC, 3, ADB_WRITEREG(id, 0x2), 0x00, 0x07); adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));}static int __init adbhid_init(void){#ifndef CONFIG_MAC if (!machine_is(chrp) && !machine_is(powermac)) return 0;#endif led_request.complete = 1; adbhid_probe(); blocking_notifier_chain_register(&adb_client_list, &adbhid_adb_notifier); return 0;}static void __exit adbhid_exit(void){} module_init(adbhid_init);module_exit(adbhid_exit);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?