adbhid.c 34 KB

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