adbhid.c 33 KB

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