adbhid.c 33 KB

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