adbhid.c 33 KB

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