adbhid.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. /*
  2. * drivers/macintosh/adbhid.c
  3. *
  4. * ADB HID driver for Power Macintosh computers.
  5. *
  6. * Adapted from drivers/macintosh/mac_keyb.c by Franz Sirl.
  7. * drivers/macintosh/mac_keyb.c was Copyright (C) 1996 Paul Mackerras
  8. * with considerable contributions from Ben Herrenschmidt and others.
  9. *
  10. * Copyright (C) 2000 Franz Sirl.
  11. *
  12. * Adapted to ADB changes and support for more devices by
  13. * Benjamin Herrenschmidt. Adapted from code in MkLinux
  14. * and reworked.
  15. *
  16. * Supported devices:
  17. *
  18. * - Standard 1 button mouse
  19. * - All standard Apple Extended protocol (handler ID 4)
  20. * - mouseman and trackman mice & trackballs
  21. * - PowerBook Trackpad (default setup: enable tapping)
  22. * - MicroSpeed mouse & trackball (needs testing)
  23. * - CH Products Trackball Pro (needs testing)
  24. * - Contour Design (Contour Mouse)
  25. * - Hunter digital (NoHandsMouse)
  26. * - Kensignton TurboMouse 5 (needs testing)
  27. * - Mouse Systems A3 mice and trackballs <aidan@kublai.com>
  28. * - MacAlly 2-buttons mouse (needs testing) <pochini@denise.shiny.it>
  29. *
  30. * To do:
  31. *
  32. * Improve Kensington support.
  33. * Split mouse/kbd
  34. * Move to syfs
  35. */
  36. #include <linux/module.h>
  37. #include <linux/slab.h>
  38. #include <linux/init.h>
  39. #include <linux/notifier.h>
  40. #include <linux/input.h>
  41. #include <linux/adb.h>
  42. #include <linux/cuda.h>
  43. #include <linux/pmu.h>
  44. #include <asm/machdep.h>
  45. #ifdef CONFIG_PPC_PMAC
  46. #include <asm/backlight.h>
  47. #include <asm/pmac_feature.h>
  48. #endif
  49. MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>");
  50. #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);
  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, 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);
  250. if (!(data[2] == 0xff || (data[2] == 0x7f && data[1] == 0x7f)))
  251. adbhid_input_keycode(id, data[2], 0);
  252. }
  253. static void
  254. adbhid_input_keycode(int id, int keycode, int repeat)
  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_report_key(ahid->input, KEY_CAPSLOCK, 1);
  263. input_report_key(ahid->input, KEY_CAPSLOCK, 0);
  264. input_sync(ahid->input);
  265. return;
  266. #ifdef CONFIG_PPC_PMAC
  267. case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */
  268. switch(pmac_call_feature(PMAC_FTR_GET_MB_INFO,
  269. NULL, PMAC_MB_INFO_MODEL, 0)) {
  270. case PMAC_TYPE_COMET:
  271. case PMAC_TYPE_HOOPER:
  272. case PMAC_TYPE_KANGA:
  273. keycode = ADB_KEY_POWER;
  274. }
  275. break;
  276. case ADB_KEY_POWER:
  277. /* Fn + Command will produce a bogus "power" keycode */
  278. if (ahid->flags & FLAG_FN_KEY_PRESSED) {
  279. keycode = ADB_KEY_CMD;
  280. if (up_flag)
  281. ahid->flags &= ~FLAG_POWER_FROM_FN;
  282. else
  283. ahid->flags |= FLAG_POWER_FROM_FN;
  284. } else if (ahid->flags & FLAG_POWER_FROM_FN) {
  285. keycode = ADB_KEY_CMD;
  286. ahid->flags &= ~FLAG_POWER_FROM_FN;
  287. }
  288. break;
  289. case ADB_KEY_FN:
  290. /* Keep track of the Fn key state */
  291. if (up_flag) {
  292. ahid->flags &= ~FLAG_FN_KEY_PRESSED;
  293. /* Emulate Fn+delete = forward delete */
  294. if (ahid->flags & FLAG_EMU_FWDEL_DOWN) {
  295. ahid->flags &= ~FLAG_EMU_FWDEL_DOWN;
  296. keycode = ADB_KEY_FWDEL;
  297. break;
  298. }
  299. } else
  300. ahid->flags |= FLAG_FN_KEY_PRESSED;
  301. /* Swallow the key press */
  302. return;
  303. case ADB_KEY_DEL:
  304. /* Emulate Fn+delete = forward delete */
  305. if (ahid->flags & FLAG_FN_KEY_PRESSED) {
  306. keycode = ADB_KEY_FWDEL;
  307. if (up_flag)
  308. ahid->flags &= ~FLAG_EMU_FWDEL_DOWN;
  309. else
  310. ahid->flags |= FLAG_EMU_FWDEL_DOWN;
  311. }
  312. break;
  313. #endif /* CONFIG_PPC_PMAC */
  314. }
  315. if (adbhid[id]->keycode[keycode]) {
  316. input_report_key(adbhid[id]->input,
  317. adbhid[id]->keycode[keycode], !up_flag);
  318. input_sync(adbhid[id]->input);
  319. } else
  320. printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode,
  321. up_flag ? "released" : "pressed");
  322. }
  323. static void
  324. adbhid_mouse_input(unsigned char *data, int nb, int autopoll)
  325. {
  326. int id = (data[0] >> 4) & 0x0f;
  327. if (!adbhid[id]) {
  328. printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
  329. return;
  330. }
  331. /*
  332. Handler 1 -- 100cpi original Apple mouse protocol.
  333. Handler 2 -- 200cpi original Apple mouse protocol.
  334. For Apple's standard one-button mouse protocol the data array will
  335. contain the following values:
  336. BITS COMMENTS
  337. data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
  338. data[1] = bxxx xxxx First button and x-axis motion.
  339. data[2] = byyy yyyy Second button and y-axis motion.
  340. Handler 4 -- Apple Extended mouse protocol.
  341. For Apple's 3-button mouse protocol the data array will contain the
  342. following values:
  343. BITS COMMENTS
  344. data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
  345. data[1] = bxxx xxxx Left button and x-axis motion.
  346. data[2] = byyy yyyy Second button and y-axis motion.
  347. data[3] = byyy bxxx Third button and fourth button. Y is additional
  348. high bits of y-axis motion. XY is additional
  349. high bits of x-axis motion.
  350. MacAlly 2-button mouse protocol.
  351. For MacAlly 2-button mouse protocol the data array will contain the
  352. following values:
  353. BITS COMMENTS
  354. data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
  355. data[1] = bxxx xxxx Left button and x-axis motion.
  356. data[2] = byyy yyyy Right button and y-axis motion.
  357. data[3] = ???? ???? unknown
  358. data[4] = ???? ???? unknown
  359. */
  360. /* If it's a trackpad, we alias the second button to the first.
  361. NOTE: Apple sends an ADB flush command to the trackpad when
  362. the first (the real) button is released. We could do
  363. this here using async flush requests.
  364. */
  365. switch (adbhid[id]->mouse_kind)
  366. {
  367. case ADBMOUSE_TRACKPAD:
  368. data[1] = (data[1] & 0x7f) | ((data[1] & data[2]) & 0x80);
  369. data[2] = data[2] | 0x80;
  370. break;
  371. case ADBMOUSE_MICROSPEED:
  372. data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
  373. data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
  374. data[3] = (data[3] & 0x77) | ((data[3] & 0x04) << 5)
  375. | (data[3] & 0x08);
  376. break;
  377. case ADBMOUSE_TRACKBALLPRO:
  378. data[1] = (data[1] & 0x7f) | (((data[3] & 0x04) << 5)
  379. & ((data[3] & 0x08) << 4));
  380. data[2] = (data[2] & 0x7f) | ((data[3] & 0x01) << 7);
  381. data[3] = (data[3] & 0x77) | ((data[3] & 0x02) << 6);
  382. break;
  383. case ADBMOUSE_MS_A3:
  384. data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
  385. data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
  386. data[3] = ((data[3] & 0x04) << 5);
  387. break;
  388. case ADBMOUSE_MACALLY2:
  389. data[3] = (data[2] & 0x80) ? 0x80 : 0x00;
  390. data[2] |= 0x80; /* Right button is mapped as button 3 */
  391. nb=4;
  392. break;
  393. }
  394. input_report_key(adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1));
  395. input_report_key(adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1));
  396. if (nb >= 4 && adbhid[id]->mouse_kind != ADBMOUSE_TRACKPAD)
  397. input_report_key(adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1));
  398. input_report_rel(adbhid[id]->input, REL_X,
  399. ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ));
  400. input_report_rel(adbhid[id]->input, REL_Y,
  401. ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 ));
  402. input_sync(adbhid[id]->input);
  403. }
  404. static void
  405. adbhid_buttons_input(unsigned char *data, int nb, int autopoll)
  406. {
  407. int id = (data[0] >> 4) & 0x0f;
  408. if (!adbhid[id]) {
  409. printk(KERN_ERR "ADB HID on ID %d not yet registered\n", id);
  410. return;
  411. }
  412. switch (adbhid[id]->original_handler_id) {
  413. default:
  414. case 0x02: /* Adjustable keyboard button device */
  415. {
  416. int down = (data[1] == (data[1] & 0xf));
  417. switch (data[1] & 0x0f) {
  418. case 0x0: /* microphone */
  419. input_report_key(adbhid[id]->input, KEY_SOUND, down);
  420. break;
  421. case 0x1: /* mute */
  422. input_report_key(adbhid[id]->input, KEY_MUTE, down);
  423. break;
  424. case 0x2: /* volume decrease */
  425. input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
  426. break;
  427. case 0x3: /* volume increase */
  428. input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
  429. break;
  430. default:
  431. printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
  432. data[0], data[1], data[2], data[3]);
  433. break;
  434. }
  435. }
  436. break;
  437. case 0x1f: /* Powerbook button device */
  438. {
  439. int down = (data[1] == (data[1] & 0xf));
  440. /*
  441. * XXX: Where is the contrast control for the passive?
  442. * -- Cort
  443. */
  444. switch (data[1] & 0x0f) {
  445. case 0x8: /* mute */
  446. input_report_key(adbhid[id]->input, KEY_MUTE, down);
  447. break;
  448. case 0x7: /* volume decrease */
  449. input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
  450. break;
  451. case 0x6: /* volume increase */
  452. input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
  453. break;
  454. case 0xb: /* eject */
  455. input_report_key(adbhid[id]->input, KEY_EJECTCD, down);
  456. break;
  457. case 0xa: /* brightness decrease */
  458. #ifdef CONFIG_PMAC_BACKLIGHT
  459. if (down)
  460. pmac_backlight_key_down();
  461. #endif
  462. input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
  463. break;
  464. case 0x9: /* brightness increase */
  465. #ifdef CONFIG_PMAC_BACKLIGHT
  466. if (down)
  467. pmac_backlight_key_up();
  468. #endif
  469. input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down);
  470. break;
  471. case 0xc: /* videomode switch */
  472. input_report_key(adbhid[id]->input, KEY_SWITCHVIDEOMODE, down);
  473. break;
  474. case 0xd: /* keyboard illumination toggle */
  475. input_report_key(adbhid[id]->input, KEY_KBDILLUMTOGGLE, down);
  476. break;
  477. case 0xe: /* keyboard illumination decrease */
  478. input_report_key(adbhid[id]->input, KEY_KBDILLUMDOWN, down);
  479. break;
  480. case 0xf:
  481. switch (data[1]) {
  482. case 0x8f:
  483. case 0x0f:
  484. /* keyboard illumination increase */
  485. input_report_key(adbhid[id]->input, KEY_KBDILLUMUP, down);
  486. break;
  487. case 0x7f:
  488. case 0xff:
  489. /* keypad overlay toogle */
  490. break;
  491. default:
  492. printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
  493. data[0], data[1], data[2], data[3]);
  494. break;
  495. }
  496. break;
  497. default:
  498. printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
  499. data[0], data[1], data[2], data[3]);
  500. break;
  501. }
  502. }
  503. break;
  504. }
  505. input_sync(adbhid[id]->input);
  506. }
  507. static struct adb_request led_request;
  508. static int leds_pending[16];
  509. static int leds_req_pending;
  510. static int pending_devs[16];
  511. static int pending_led_start=0;
  512. static int pending_led_end=0;
  513. static DEFINE_SPINLOCK(leds_lock);
  514. static void leds_done(struct adb_request *req)
  515. {
  516. int leds = 0, device = 0, pending = 0;
  517. unsigned long flags;
  518. spin_lock_irqsave(&leds_lock, flags);
  519. if (pending_led_start != pending_led_end) {
  520. device = pending_devs[pending_led_start];
  521. leds = leds_pending[device] & 0xff;
  522. leds_pending[device] = 0;
  523. pending_led_start++;
  524. pending_led_start = (pending_led_start < 16) ? pending_led_start : 0;
  525. pending = leds_req_pending;
  526. } else
  527. leds_req_pending = 0;
  528. spin_unlock_irqrestore(&leds_lock, flags);
  529. if (pending)
  530. adb_request(&led_request, leds_done, 0, 3,
  531. ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
  532. }
  533. static void real_leds(unsigned char leds, int device)
  534. {
  535. unsigned long flags;
  536. spin_lock_irqsave(&leds_lock, flags);
  537. if (!leds_req_pending) {
  538. leds_req_pending = 1;
  539. spin_unlock_irqrestore(&leds_lock, flags);
  540. adb_request(&led_request, leds_done, 0, 3,
  541. ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
  542. return;
  543. } else {
  544. if (!(leds_pending[device] & 0x100)) {
  545. pending_devs[pending_led_end] = device;
  546. pending_led_end++;
  547. pending_led_end = (pending_led_end < 16) ? pending_led_end : 0;
  548. }
  549. leds_pending[device] = leds | 0x100;
  550. }
  551. spin_unlock_irqrestore(&leds_lock, flags);
  552. }
  553. /*
  554. * Event callback from the input module. Events that change the state of
  555. * the hardware are processed here.
  556. */
  557. static int adbhid_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
  558. {
  559. struct adbhid *adbhid = dev->private;
  560. unsigned char leds;
  561. switch (type) {
  562. case EV_LED:
  563. leds = (test_bit(LED_SCROLLL, dev->led) ? 4 : 0)
  564. | (test_bit(LED_NUML, dev->led) ? 1 : 0)
  565. | (test_bit(LED_CAPSL, dev->led) ? 2 : 0);
  566. real_leds(leds, adbhid->id);
  567. return 0;
  568. }
  569. return -1;
  570. }
  571. static int
  572. adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
  573. {
  574. switch (code) {
  575. case ADB_MSG_PRE_RESET:
  576. case ADB_MSG_POWERDOWN:
  577. /* Stop the repeat timer. Autopoll is already off at this point */
  578. {
  579. int i;
  580. for (i = 1; i < 16; i++) {
  581. if (adbhid[i])
  582. del_timer_sync(&adbhid[i]->input->timer);
  583. }
  584. }
  585. /* Stop pending led requests */
  586. while(leds_req_pending)
  587. adb_poll();
  588. break;
  589. case ADB_MSG_POST_RESET:
  590. adbhid_probe();
  591. break;
  592. }
  593. return NOTIFY_DONE;
  594. }
  595. static int
  596. adbhid_input_register(int id, int default_id, int original_handler_id,
  597. int current_handler_id, int mouse_kind)
  598. {
  599. struct adbhid *hid;
  600. struct input_dev *input_dev;
  601. int err;
  602. int i;
  603. if (adbhid[id]) {
  604. printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
  605. return -EEXIST;
  606. }
  607. adbhid[id] = hid = kzalloc(sizeof(struct adbhid), GFP_KERNEL);
  608. input_dev = input_allocate_device();
  609. if (!hid || !input_dev) {
  610. err = -ENOMEM;
  611. goto fail;
  612. }
  613. sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
  614. hid->input = input_dev;
  615. hid->id = default_id;
  616. hid->original_handler_id = original_handler_id;
  617. hid->current_handler_id = current_handler_id;
  618. hid->mouse_kind = mouse_kind;
  619. hid->flags = 0;
  620. input_dev->private = hid;
  621. input_dev->name = hid->name;
  622. input_dev->phys = hid->phys;
  623. input_dev->id.bustype = BUS_ADB;
  624. input_dev->id.vendor = 0x0001;
  625. input_dev->id.product = (id << 12) | (default_id << 8) | original_handler_id;
  626. input_dev->id.version = 0x0100;
  627. switch (default_id) {
  628. case ADB_KEYBOARD:
  629. hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL);
  630. if (!hid->keycode) {
  631. err = -ENOMEM;
  632. goto fail;
  633. }
  634. sprintf(hid->name, "ADB keyboard");
  635. memcpy(hid->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
  636. printk(KERN_INFO "Detected ADB keyboard, type ");
  637. switch (original_handler_id) {
  638. default:
  639. printk("<unknown>.\n");
  640. input_dev->id.version = ADB_KEYBOARD_UNKNOWN;
  641. break;
  642. case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
  643. case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
  644. case 0xC0: case 0xC3: case 0xC6:
  645. printk("ANSI.\n");
  646. input_dev->id.version = ADB_KEYBOARD_ANSI;
  647. break;
  648. case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
  649. case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
  650. case 0xC4: case 0xC7:
  651. printk("ISO, swapping keys.\n");
  652. input_dev->id.version = ADB_KEYBOARD_ISO;
  653. i = hid->keycode[10];
  654. hid->keycode[10] = hid->keycode[50];
  655. hid->keycode[50] = i;
  656. break;
  657. case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
  658. case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
  659. printk("JIS.\n");
  660. input_dev->id.version = ADB_KEYBOARD_JIS;
  661. break;
  662. }
  663. for (i = 0; i < 128; i++)
  664. if (hid->keycode[i])
  665. set_bit(hid->keycode[i], input_dev->keybit);
  666. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
  667. input_dev->ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
  668. input_dev->event = adbhid_kbd_event;
  669. input_dev->keycodemax = 127;
  670. input_dev->keycodesize = 1;
  671. break;
  672. case ADB_MOUSE:
  673. sprintf(hid->name, "ADB mouse");
  674. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  675. input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  676. input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  677. break;
  678. case ADB_MISC:
  679. switch (original_handler_id) {
  680. case 0x02: /* Adjustable keyboard button device */
  681. sprintf(hid->name, "ADB adjustable keyboard buttons");
  682. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  683. set_bit(KEY_SOUND, input_dev->keybit);
  684. set_bit(KEY_MUTE, input_dev->keybit);
  685. set_bit(KEY_VOLUMEUP, input_dev->keybit);
  686. set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
  687. break;
  688. case 0x1f: /* Powerbook button device */
  689. sprintf(hid->name, "ADB Powerbook buttons");
  690. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  691. set_bit(KEY_MUTE, input_dev->keybit);
  692. set_bit(KEY_VOLUMEUP, input_dev->keybit);
  693. set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
  694. set_bit(KEY_BRIGHTNESSUP, input_dev->keybit);
  695. set_bit(KEY_BRIGHTNESSDOWN, input_dev->keybit);
  696. set_bit(KEY_EJECTCD, input_dev->keybit);
  697. set_bit(KEY_SWITCHVIDEOMODE, input_dev->keybit);
  698. set_bit(KEY_KBDILLUMTOGGLE, input_dev->keybit);
  699. set_bit(KEY_KBDILLUMDOWN, input_dev->keybit);
  700. set_bit(KEY_KBDILLUMUP, input_dev->keybit);
  701. break;
  702. }
  703. if (hid->name[0])
  704. break;
  705. /* else fall through */
  706. default:
  707. printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
  708. err = -ENODEV;
  709. goto fail;
  710. }
  711. input_dev->keycode = hid->keycode;
  712. input_register_device(input_dev);
  713. if (default_id == ADB_KEYBOARD) {
  714. /* HACK WARNING!! This should go away as soon there is an utility
  715. * to control that for event devices.
  716. */
  717. input_dev->rep[REP_DELAY] = 500; /* input layer default: 250 */
  718. input_dev->rep[REP_PERIOD] = 66; /* input layer default: 33 */
  719. }
  720. return 0;
  721. fail: input_free_device(input_dev);
  722. kfree(hid);
  723. adbhid[id] = NULL;
  724. return err;
  725. }
  726. static void adbhid_input_unregister(int id)
  727. {
  728. input_unregister_device(adbhid[id]->input);
  729. kfree(adbhid[id]->keycode);
  730. kfree(adbhid[id]);
  731. adbhid[id] = NULL;
  732. }
  733. static u16
  734. adbhid_input_reregister(int id, int default_id, int org_handler_id,
  735. int cur_handler_id, int mk)
  736. {
  737. if (adbhid[id]) {
  738. if (adbhid[id]->input->id.product !=
  739. ((id << 12)|(default_id << 8)|org_handler_id)) {
  740. adbhid_input_unregister(id);
  741. adbhid_input_register(id, default_id, org_handler_id,
  742. cur_handler_id, mk);
  743. }
  744. } else
  745. adbhid_input_register(id, default_id, org_handler_id,
  746. cur_handler_id, mk);
  747. return 1<<id;
  748. }
  749. static void
  750. adbhid_input_devcleanup(u16 exist)
  751. {
  752. int i;
  753. for(i=1; i<16; i++)
  754. if (adbhid[i] && !(exist&(1<<i)))
  755. adbhid_input_unregister(i);
  756. }
  757. static void
  758. adbhid_probe(void)
  759. {
  760. struct adb_request req;
  761. int i, default_id, org_handler_id, cur_handler_id;
  762. u16 reg = 0;
  763. adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input);
  764. adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input);
  765. adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input);
  766. for (i = 0; i < keyboard_ids.nids; i++) {
  767. int id = keyboard_ids.id[i];
  768. adb_get_infos(id, &default_id, &org_handler_id);
  769. /* turn off all leds */
  770. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  771. ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
  772. /* Enable full feature set of the keyboard
  773. ->get it to send separate codes for left and right shift,
  774. control, option keys */
  775. #if 0 /* handler 5 doesn't send separate codes for R modifiers */
  776. if (adb_try_handler_change(id, 5))
  777. printk("ADB keyboard at %d, handler set to 5\n", id);
  778. else
  779. #endif
  780. if (adb_try_handler_change(id, 3))
  781. printk("ADB keyboard at %d, handler set to 3\n", id);
  782. else
  783. printk("ADB keyboard at %d, handler 1\n", id);
  784. adb_get_infos(id, &default_id, &cur_handler_id);
  785. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  786. cur_handler_id, 0);
  787. }
  788. for (i = 0; i < buttons_ids.nids; i++) {
  789. int id = buttons_ids.id[i];
  790. adb_get_infos(id, &default_id, &org_handler_id);
  791. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  792. org_handler_id, 0);
  793. }
  794. /* Try to switch all mice to handler 4, or 2 for three-button
  795. mode and full resolution. */
  796. for (i = 0; i < mouse_ids.nids; i++) {
  797. int id = mouse_ids.id[i];
  798. int mouse_kind;
  799. adb_get_infos(id, &default_id, &org_handler_id);
  800. if (adb_try_handler_change(id, 4)) {
  801. printk("ADB mouse at %d, handler set to 4", id);
  802. mouse_kind = ADBMOUSE_EXTENDED;
  803. }
  804. else if (adb_try_handler_change(id, 0x2F)) {
  805. printk("ADB mouse at %d, handler set to 0x2F", id);
  806. mouse_kind = ADBMOUSE_MICROSPEED;
  807. }
  808. else if (adb_try_handler_change(id, 0x42)) {
  809. printk("ADB mouse at %d, handler set to 0x42", id);
  810. mouse_kind = ADBMOUSE_TRACKBALLPRO;
  811. }
  812. else if (adb_try_handler_change(id, 0x66)) {
  813. printk("ADB mouse at %d, handler set to 0x66", id);
  814. mouse_kind = ADBMOUSE_MICROSPEED;
  815. }
  816. else if (adb_try_handler_change(id, 0x5F)) {
  817. printk("ADB mouse at %d, handler set to 0x5F", id);
  818. mouse_kind = ADBMOUSE_MICROSPEED;
  819. }
  820. else if (adb_try_handler_change(id, 3)) {
  821. printk("ADB mouse at %d, handler set to 3", id);
  822. mouse_kind = ADBMOUSE_MS_A3;
  823. }
  824. else if (adb_try_handler_change(id, 2)) {
  825. printk("ADB mouse at %d, handler set to 2", id);
  826. mouse_kind = ADBMOUSE_STANDARD_200;
  827. }
  828. else {
  829. printk("ADB mouse at %d, handler 1", id);
  830. mouse_kind = ADBMOUSE_STANDARD_100;
  831. }
  832. if ((mouse_kind == ADBMOUSE_TRACKBALLPRO)
  833. || (mouse_kind == ADBMOUSE_MICROSPEED)) {
  834. init_microspeed(id);
  835. } else if (mouse_kind == ADBMOUSE_MS_A3) {
  836. init_ms_a3(id);
  837. } else if (mouse_kind == ADBMOUSE_EXTENDED) {
  838. /*
  839. * Register 1 is usually used for device
  840. * identification. Here, we try to identify
  841. * a known device and call the appropriate
  842. * init function.
  843. */
  844. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  845. ADB_READREG(id, 1));
  846. if ((req.reply_len) &&
  847. (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
  848. || (req.reply[2] == 0x20))) {
  849. mouse_kind = ADBMOUSE_TRACKBALL;
  850. init_trackball(id);
  851. }
  852. else if ((req.reply_len >= 4) &&
  853. (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
  854. (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) {
  855. mouse_kind = ADBMOUSE_TRACKPAD;
  856. init_trackpad(id);
  857. }
  858. else if ((req.reply_len >= 4) &&
  859. (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
  860. (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) {
  861. mouse_kind = ADBMOUSE_TURBOMOUSE5;
  862. init_turbomouse(id);
  863. }
  864. else if ((req.reply_len == 9) &&
  865. (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
  866. (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) {
  867. if (adb_try_handler_change(id, 0x42)) {
  868. printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
  869. mouse_kind = ADBMOUSE_MACALLY2;
  870. }
  871. }
  872. }
  873. printk("\n");
  874. adb_get_infos(id, &default_id, &cur_handler_id);
  875. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  876. cur_handler_id, mouse_kind);
  877. }
  878. adbhid_input_devcleanup(reg);
  879. }
  880. static void
  881. init_trackpad(int id)
  882. {
  883. struct adb_request req;
  884. unsigned char r1_buffer[8];
  885. printk(" (trackpad)");
  886. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  887. ADB_READREG(id,1));
  888. if (req.reply_len < 8)
  889. printk("bad length for reg. 1\n");
  890. else
  891. {
  892. memcpy(r1_buffer, &req.reply[1], 8);
  893. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  894. ADB_WRITEREG(id,1),
  895. r1_buffer[0],
  896. r1_buffer[1],
  897. r1_buffer[2],
  898. r1_buffer[3],
  899. r1_buffer[4],
  900. r1_buffer[5],
  901. 0x0d,
  902. r1_buffer[7]);
  903. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  904. ADB_WRITEREG(id,2),
  905. 0x99,
  906. 0x94,
  907. 0x19,
  908. 0xff,
  909. 0xb2,
  910. 0x8a,
  911. 0x1b,
  912. 0x50);
  913. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  914. ADB_WRITEREG(id,1),
  915. r1_buffer[0],
  916. r1_buffer[1],
  917. r1_buffer[2],
  918. r1_buffer[3],
  919. r1_buffer[4],
  920. r1_buffer[5],
  921. 0x03, /*r1_buffer[6],*/
  922. r1_buffer[7]);
  923. /* Without this flush, the trackpad may be locked up */
  924. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  925. }
  926. }
  927. static void
  928. init_trackball(int id)
  929. {
  930. struct adb_request req;
  931. printk(" (trackman/mouseman)");
  932. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  933. ADB_WRITEREG(id,1), 00,0x81);
  934. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  935. ADB_WRITEREG(id,1), 01,0x81);
  936. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  937. ADB_WRITEREG(id,1), 02,0x81);
  938. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  939. ADB_WRITEREG(id,1), 03,0x38);
  940. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  941. ADB_WRITEREG(id,1), 00,0x81);
  942. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  943. ADB_WRITEREG(id,1), 01,0x81);
  944. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  945. ADB_WRITEREG(id,1), 02,0x81);
  946. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  947. ADB_WRITEREG(id,1), 03,0x38);
  948. }
  949. static void
  950. init_turbomouse(int id)
  951. {
  952. struct adb_request req;
  953. printk(" (TurboMouse 5)");
  954. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  955. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  956. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  957. ADB_WRITEREG(3,2),
  958. 0xe7,
  959. 0x8c,
  960. 0,
  961. 0,
  962. 0,
  963. 0xff,
  964. 0xff,
  965. 0x94);
  966. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  967. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  968. ADB_WRITEREG(3,2),
  969. 0xa5,
  970. 0x14,
  971. 0,
  972. 0,
  973. 0x69,
  974. 0xff,
  975. 0xff,
  976. 0x27);
  977. }
  978. static void
  979. init_microspeed(int id)
  980. {
  981. struct adb_request req;
  982. printk(" (Microspeed/MacPoint or compatible)");
  983. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  984. /* This will initialize mice using the Microspeed, MacPoint and
  985. other compatible firmware. Bit 12 enables extended protocol.
  986. Register 1 Listen (4 Bytes)
  987. 0 - 3 Button is mouse (set also for double clicking!!!)
  988. 4 - 7 Button is locking (affects change speed also)
  989. 8 - 11 Button changes speed
  990. 12 1 = Extended mouse mode, 0 = normal mouse mode
  991. 13 - 15 unused 0
  992. 16 - 23 normal speed
  993. 24 - 31 changed speed
  994. Register 1 talk holds version and product identification information.
  995. Register 1 Talk (4 Bytes):
  996. 0 - 7 Product code
  997. 8 - 23 undefined, reserved
  998. 24 - 31 Version number
  999. Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
  1000. */
  1001. adb_request(&req, NULL, ADBREQ_SYNC, 5,
  1002. ADB_WRITEREG(id,1),
  1003. 0x20, /* alt speed = 0x20 (rather slow) */
  1004. 0x00, /* norm speed = 0x00 (fastest) */
  1005. 0x10, /* extended protocol, no speed change */
  1006. 0x07); /* all buttons enabled as mouse buttons, no locking */
  1007. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1008. }
  1009. static void
  1010. init_ms_a3(int id)
  1011. {
  1012. struct adb_request req;
  1013. printk(" (Mouse Systems A3 Mouse, or compatible)");
  1014. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  1015. ADB_WRITEREG(id, 0x2),
  1016. 0x00,
  1017. 0x07);
  1018. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1019. }
  1020. static int __init adbhid_init(void)
  1021. {
  1022. #ifndef CONFIG_MAC
  1023. if (!machine_is(chrp) && !machine_is(powermac))
  1024. return 0;
  1025. #endif
  1026. led_request.complete = 1;
  1027. adbhid_probe();
  1028. blocking_notifier_chain_register(&adb_client_list,
  1029. &adbhid_adb_notifier);
  1030. return 0;
  1031. }
  1032. static void __exit adbhid_exit(void)
  1033. {
  1034. }
  1035. module_init(adbhid_init);
  1036. module_exit(adbhid_exit);