adbhid.c 32 KB

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