adbhid.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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 void
  622. adbhid_input_register(int id, int default_id, int original_handler_id,
  623. int current_handler_id, int mouse_kind)
  624. {
  625. int i;
  626. if (adbhid[id]) {
  627. printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
  628. return;
  629. }
  630. if (!(adbhid[id] = kmalloc(sizeof(struct adbhid), GFP_KERNEL)))
  631. return;
  632. memset(adbhid[id], 0, sizeof(struct adbhid));
  633. sprintf(adbhid[id]->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
  634. init_input_dev(&adbhid[id]->input);
  635. adbhid[id]->id = default_id;
  636. adbhid[id]->original_handler_id = original_handler_id;
  637. adbhid[id]->current_handler_id = current_handler_id;
  638. adbhid[id]->mouse_kind = mouse_kind;
  639. adbhid[id]->flags = 0;
  640. adbhid[id]->input.private = adbhid[id];
  641. adbhid[id]->input.name = adbhid[id]->name;
  642. adbhid[id]->input.phys = adbhid[id]->phys;
  643. adbhid[id]->input.id.bustype = BUS_ADB;
  644. adbhid[id]->input.id.vendor = 0x0001;
  645. adbhid[id]->input.id.product = (id << 12) | (default_id << 8) | original_handler_id;
  646. adbhid[id]->input.id.version = 0x0100;
  647. switch (default_id) {
  648. case ADB_KEYBOARD:
  649. if (!(adbhid[id]->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL))) {
  650. kfree(adbhid[id]);
  651. return;
  652. }
  653. sprintf(adbhid[id]->name, "ADB keyboard");
  654. memcpy(adbhid[id]->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
  655. printk(KERN_INFO "Detected ADB keyboard, type ");
  656. switch (original_handler_id) {
  657. default:
  658. printk("<unknown>.\n");
  659. adbhid[id]->input.id.version = ADB_KEYBOARD_UNKNOWN;
  660. break;
  661. case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
  662. case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
  663. case 0xC0: case 0xC3: case 0xC6:
  664. printk("ANSI.\n");
  665. adbhid[id]->input.id.version = ADB_KEYBOARD_ANSI;
  666. break;
  667. case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
  668. case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
  669. case 0xC4: case 0xC7:
  670. printk("ISO, swapping keys.\n");
  671. adbhid[id]->input.id.version = ADB_KEYBOARD_ISO;
  672. i = adbhid[id]->keycode[10];
  673. adbhid[id]->keycode[10] = adbhid[id]->keycode[50];
  674. adbhid[id]->keycode[50] = i;
  675. break;
  676. case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
  677. case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
  678. printk("JIS.\n");
  679. adbhid[id]->input.id.version = ADB_KEYBOARD_JIS;
  680. break;
  681. }
  682. for (i = 0; i < 128; i++)
  683. if (adbhid[id]->keycode[i])
  684. set_bit(adbhid[id]->keycode[i], adbhid[id]->input.keybit);
  685. adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
  686. adbhid[id]->input.ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
  687. adbhid[id]->input.event = adbhid_kbd_event;
  688. adbhid[id]->input.keycodemax = 127;
  689. adbhid[id]->input.keycodesize = 1;
  690. break;
  691. case ADB_MOUSE:
  692. sprintf(adbhid[id]->name, "ADB mouse");
  693. adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  694. adbhid[id]->input.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  695. adbhid[id]->input.relbit[0] = BIT(REL_X) | BIT(REL_Y);
  696. break;
  697. case ADB_MISC:
  698. switch (original_handler_id) {
  699. case 0x02: /* Adjustable keyboard button device */
  700. sprintf(adbhid[id]->name, "ADB adjustable keyboard buttons");
  701. adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  702. set_bit(KEY_SOUND, adbhid[id]->input.keybit);
  703. set_bit(KEY_MUTE, adbhid[id]->input.keybit);
  704. set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit);
  705. set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit);
  706. break;
  707. case 0x1f: /* Powerbook button device */
  708. sprintf(adbhid[id]->name, "ADB Powerbook buttons");
  709. adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  710. set_bit(KEY_MUTE, adbhid[id]->input.keybit);
  711. set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit);
  712. set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit);
  713. set_bit(KEY_BRIGHTNESSUP, adbhid[id]->input.keybit);
  714. set_bit(KEY_BRIGHTNESSDOWN, adbhid[id]->input.keybit);
  715. set_bit(KEY_EJECTCD, adbhid[id]->input.keybit);
  716. set_bit(KEY_SWITCHVIDEOMODE, adbhid[id]->input.keybit);
  717. set_bit(KEY_KBDILLUMTOGGLE, adbhid[id]->input.keybit);
  718. set_bit(KEY_KBDILLUMDOWN, adbhid[id]->input.keybit);
  719. set_bit(KEY_KBDILLUMUP, adbhid[id]->input.keybit);
  720. break;
  721. }
  722. if (adbhid[id]->name[0])
  723. break;
  724. /* else fall through */
  725. default:
  726. printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
  727. kfree(adbhid[id]);
  728. return;
  729. }
  730. adbhid[id]->input.keycode = adbhid[id]->keycode;
  731. input_register_device(&adbhid[id]->input);
  732. printk(KERN_INFO "input: %s on %s\n",
  733. adbhid[id]->name, adbhid[id]->phys);
  734. if (default_id == ADB_KEYBOARD) {
  735. /* HACK WARNING!! This should go away as soon there is an utility
  736. * to control that for event devices.
  737. */
  738. adbhid[id]->input.rep[REP_DELAY] = 500; /* input layer default: 250 */
  739. adbhid[id]->input.rep[REP_PERIOD] = 66; /* input layer default: 33 */
  740. }
  741. }
  742. static void adbhid_input_unregister(int id)
  743. {
  744. input_unregister_device(&adbhid[id]->input);
  745. if (adbhid[id]->keycode)
  746. kfree(adbhid[id]->keycode);
  747. kfree(adbhid[id]);
  748. adbhid[id] = NULL;
  749. }
  750. static u16
  751. adbhid_input_reregister(int id, int default_id, int org_handler_id,
  752. int cur_handler_id, int mk)
  753. {
  754. if (adbhid[id]) {
  755. if (adbhid[id]->input.id.product !=
  756. ((id << 12)|(default_id << 8)|org_handler_id)) {
  757. adbhid_input_unregister(id);
  758. adbhid_input_register(id, default_id, org_handler_id,
  759. cur_handler_id, mk);
  760. }
  761. } else
  762. adbhid_input_register(id, default_id, org_handler_id,
  763. cur_handler_id, mk);
  764. return 1<<id;
  765. }
  766. static void
  767. adbhid_input_devcleanup(u16 exist)
  768. {
  769. int i;
  770. for(i=1; i<16; i++)
  771. if (adbhid[i] && !(exist&(1<<i)))
  772. adbhid_input_unregister(i);
  773. }
  774. static void
  775. adbhid_probe(void)
  776. {
  777. struct adb_request req;
  778. int i, default_id, org_handler_id, cur_handler_id;
  779. u16 reg = 0;
  780. adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input);
  781. adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input);
  782. adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input);
  783. for (i = 0; i < keyboard_ids.nids; i++) {
  784. int id = keyboard_ids.id[i];
  785. adb_get_infos(id, &default_id, &org_handler_id);
  786. /* turn off all leds */
  787. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  788. ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
  789. /* Enable full feature set of the keyboard
  790. ->get it to send separate codes for left and right shift,
  791. control, option keys */
  792. #if 0 /* handler 5 doesn't send separate codes for R modifiers */
  793. if (adb_try_handler_change(id, 5))
  794. printk("ADB keyboard at %d, handler set to 5\n", id);
  795. else
  796. #endif
  797. if (adb_try_handler_change(id, 3))
  798. printk("ADB keyboard at %d, handler set to 3\n", id);
  799. else
  800. printk("ADB keyboard at %d, handler 1\n", id);
  801. adb_get_infos(id, &default_id, &cur_handler_id);
  802. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  803. cur_handler_id, 0);
  804. }
  805. for (i = 0; i < buttons_ids.nids; i++) {
  806. int id = buttons_ids.id[i];
  807. adb_get_infos(id, &default_id, &org_handler_id);
  808. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  809. org_handler_id, 0);
  810. }
  811. /* Try to switch all mice to handler 4, or 2 for three-button
  812. mode and full resolution. */
  813. for (i = 0; i < mouse_ids.nids; i++) {
  814. int id = mouse_ids.id[i];
  815. int mouse_kind;
  816. adb_get_infos(id, &default_id, &org_handler_id);
  817. if (adb_try_handler_change(id, 4)) {
  818. printk("ADB mouse at %d, handler set to 4", id);
  819. mouse_kind = ADBMOUSE_EXTENDED;
  820. }
  821. else if (adb_try_handler_change(id, 0x2F)) {
  822. printk("ADB mouse at %d, handler set to 0x2F", id);
  823. mouse_kind = ADBMOUSE_MICROSPEED;
  824. }
  825. else if (adb_try_handler_change(id, 0x42)) {
  826. printk("ADB mouse at %d, handler set to 0x42", id);
  827. mouse_kind = ADBMOUSE_TRACKBALLPRO;
  828. }
  829. else if (adb_try_handler_change(id, 0x66)) {
  830. printk("ADB mouse at %d, handler set to 0x66", id);
  831. mouse_kind = ADBMOUSE_MICROSPEED;
  832. }
  833. else if (adb_try_handler_change(id, 0x5F)) {
  834. printk("ADB mouse at %d, handler set to 0x5F", id);
  835. mouse_kind = ADBMOUSE_MICROSPEED;
  836. }
  837. else if (adb_try_handler_change(id, 3)) {
  838. printk("ADB mouse at %d, handler set to 3", id);
  839. mouse_kind = ADBMOUSE_MS_A3;
  840. }
  841. else if (adb_try_handler_change(id, 2)) {
  842. printk("ADB mouse at %d, handler set to 2", id);
  843. mouse_kind = ADBMOUSE_STANDARD_200;
  844. }
  845. else {
  846. printk("ADB mouse at %d, handler 1", id);
  847. mouse_kind = ADBMOUSE_STANDARD_100;
  848. }
  849. if ((mouse_kind == ADBMOUSE_TRACKBALLPRO)
  850. || (mouse_kind == ADBMOUSE_MICROSPEED)) {
  851. init_microspeed(id);
  852. } else if (mouse_kind == ADBMOUSE_MS_A3) {
  853. init_ms_a3(id);
  854. } else if (mouse_kind == ADBMOUSE_EXTENDED) {
  855. /*
  856. * Register 1 is usually used for device
  857. * identification. Here, we try to identify
  858. * a known device and call the appropriate
  859. * init function.
  860. */
  861. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  862. ADB_READREG(id, 1));
  863. if ((req.reply_len) &&
  864. (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
  865. || (req.reply[2] == 0x20))) {
  866. mouse_kind = ADBMOUSE_TRACKBALL;
  867. init_trackball(id);
  868. }
  869. else if ((req.reply_len >= 4) &&
  870. (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
  871. (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) {
  872. mouse_kind = ADBMOUSE_TRACKPAD;
  873. init_trackpad(id);
  874. }
  875. else if ((req.reply_len >= 4) &&
  876. (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
  877. (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) {
  878. mouse_kind = ADBMOUSE_TURBOMOUSE5;
  879. init_turbomouse(id);
  880. }
  881. else if ((req.reply_len == 9) &&
  882. (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
  883. (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) {
  884. if (adb_try_handler_change(id, 0x42)) {
  885. printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
  886. mouse_kind = ADBMOUSE_MACALLY2;
  887. }
  888. }
  889. }
  890. printk("\n");
  891. adb_get_infos(id, &default_id, &cur_handler_id);
  892. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  893. cur_handler_id, mouse_kind);
  894. }
  895. adbhid_input_devcleanup(reg);
  896. }
  897. static void
  898. init_trackpad(int id)
  899. {
  900. struct adb_request req;
  901. unsigned char r1_buffer[8];
  902. printk(" (trackpad)");
  903. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  904. ADB_READREG(id,1));
  905. if (req.reply_len < 8)
  906. printk("bad length for reg. 1\n");
  907. else
  908. {
  909. memcpy(r1_buffer, &req.reply[1], 8);
  910. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  911. ADB_WRITEREG(id,1),
  912. r1_buffer[0],
  913. r1_buffer[1],
  914. r1_buffer[2],
  915. r1_buffer[3],
  916. r1_buffer[4],
  917. r1_buffer[5],
  918. 0x0d,
  919. r1_buffer[7]);
  920. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  921. ADB_WRITEREG(id,2),
  922. 0x99,
  923. 0x94,
  924. 0x19,
  925. 0xff,
  926. 0xb2,
  927. 0x8a,
  928. 0x1b,
  929. 0x50);
  930. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  931. ADB_WRITEREG(id,1),
  932. r1_buffer[0],
  933. r1_buffer[1],
  934. r1_buffer[2],
  935. r1_buffer[3],
  936. r1_buffer[4],
  937. r1_buffer[5],
  938. 0x03, /*r1_buffer[6],*/
  939. r1_buffer[7]);
  940. /* Without this flush, the trackpad may be locked up */
  941. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  942. }
  943. }
  944. static void
  945. init_trackball(int id)
  946. {
  947. struct adb_request req;
  948. printk(" (trackman/mouseman)");
  949. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  950. ADB_WRITEREG(id,1), 00,0x81);
  951. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  952. ADB_WRITEREG(id,1), 01,0x81);
  953. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  954. ADB_WRITEREG(id,1), 02,0x81);
  955. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  956. ADB_WRITEREG(id,1), 03,0x38);
  957. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  958. ADB_WRITEREG(id,1), 00,0x81);
  959. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  960. ADB_WRITEREG(id,1), 01,0x81);
  961. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  962. ADB_WRITEREG(id,1), 02,0x81);
  963. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  964. ADB_WRITEREG(id,1), 03,0x38);
  965. }
  966. static void
  967. init_turbomouse(int id)
  968. {
  969. struct adb_request req;
  970. printk(" (TurboMouse 5)");
  971. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  972. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  973. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  974. ADB_WRITEREG(3,2),
  975. 0xe7,
  976. 0x8c,
  977. 0,
  978. 0,
  979. 0,
  980. 0xff,
  981. 0xff,
  982. 0x94);
  983. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  984. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  985. ADB_WRITEREG(3,2),
  986. 0xa5,
  987. 0x14,
  988. 0,
  989. 0,
  990. 0x69,
  991. 0xff,
  992. 0xff,
  993. 0x27);
  994. }
  995. static void
  996. init_microspeed(int id)
  997. {
  998. struct adb_request req;
  999. printk(" (Microspeed/MacPoint or compatible)");
  1000. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1001. /* This will initialize mice using the Microspeed, MacPoint and
  1002. other compatible firmware. Bit 12 enables extended protocol.
  1003. Register 1 Listen (4 Bytes)
  1004. 0 - 3 Button is mouse (set also for double clicking!!!)
  1005. 4 - 7 Button is locking (affects change speed also)
  1006. 8 - 11 Button changes speed
  1007. 12 1 = Extended mouse mode, 0 = normal mouse mode
  1008. 13 - 15 unused 0
  1009. 16 - 23 normal speed
  1010. 24 - 31 changed speed
  1011. Register 1 talk holds version and product identification information.
  1012. Register 1 Talk (4 Bytes):
  1013. 0 - 7 Product code
  1014. 8 - 23 undefined, reserved
  1015. 24 - 31 Version number
  1016. Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
  1017. */
  1018. adb_request(&req, NULL, ADBREQ_SYNC, 5,
  1019. ADB_WRITEREG(id,1),
  1020. 0x20, /* alt speed = 0x20 (rather slow) */
  1021. 0x00, /* norm speed = 0x00 (fastest) */
  1022. 0x10, /* extended protocol, no speed change */
  1023. 0x07); /* all buttons enabled as mouse buttons, no locking */
  1024. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1025. }
  1026. static void
  1027. init_ms_a3(int id)
  1028. {
  1029. struct adb_request req;
  1030. printk(" (Mouse Systems A3 Mouse, or compatible)");
  1031. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  1032. ADB_WRITEREG(id, 0x2),
  1033. 0x00,
  1034. 0x07);
  1035. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1036. }
  1037. static int __init adbhid_init(void)
  1038. {
  1039. #ifndef CONFIG_MAC
  1040. if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) )
  1041. return 0;
  1042. #endif
  1043. led_request.complete = 1;
  1044. adbhid_probe();
  1045. notifier_chain_register(&adb_client_list, &adbhid_adb_notifier);
  1046. return 0;
  1047. }
  1048. static void __exit adbhid_exit(void)
  1049. {
  1050. }
  1051. module_init(adbhid_init);
  1052. module_exit(adbhid_exit);