adbhid.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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_HANGEUL, /* 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. /*
  452. * XXX: Where is the contrast control for the passive?
  453. * -- Cort
  454. */
  455. switch (data[1] & 0x0f) {
  456. case 0x8: /* mute */
  457. input_report_key(adbhid[id]->input, KEY_MUTE, down);
  458. break;
  459. case 0x7: /* volume decrease */
  460. input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
  461. break;
  462. case 0x6: /* volume increase */
  463. input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
  464. break;
  465. case 0xb: /* eject */
  466. input_report_key(adbhid[id]->input, KEY_EJECTCD, down);
  467. break;
  468. case 0xa: /* brightness decrease */
  469. #ifdef CONFIG_PMAC_BACKLIGHT
  470. if (!disable_kernel_backlight && down)
  471. pmac_backlight_key_down();
  472. #endif
  473. input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
  474. break;
  475. case 0x9: /* brightness increase */
  476. #ifdef CONFIG_PMAC_BACKLIGHT
  477. if (!disable_kernel_backlight && down)
  478. pmac_backlight_key_up();
  479. #endif
  480. input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down);
  481. break;
  482. case 0xc: /* videomode switch */
  483. input_report_key(adbhid[id]->input, KEY_SWITCHVIDEOMODE, down);
  484. break;
  485. case 0xd: /* keyboard illumination toggle */
  486. input_report_key(adbhid[id]->input, KEY_KBDILLUMTOGGLE, down);
  487. break;
  488. case 0xe: /* keyboard illumination decrease */
  489. input_report_key(adbhid[id]->input, KEY_KBDILLUMDOWN, down);
  490. break;
  491. case 0xf:
  492. switch (data[1]) {
  493. case 0x8f:
  494. case 0x0f:
  495. /* keyboard illumination increase */
  496. input_report_key(adbhid[id]->input, KEY_KBDILLUMUP, down);
  497. break;
  498. case 0x7f:
  499. case 0xff:
  500. /* keypad overlay toogle */
  501. break;
  502. default:
  503. printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
  504. data[0], data[1], data[2], data[3]);
  505. break;
  506. }
  507. break;
  508. default:
  509. printk(KERN_INFO "Unhandled ADB_MISC event %02x, %02x, %02x, %02x\n",
  510. data[0], data[1], data[2], data[3]);
  511. break;
  512. }
  513. }
  514. break;
  515. }
  516. input_sync(adbhid[id]->input);
  517. }
  518. static struct adb_request led_request;
  519. static int leds_pending[16];
  520. static int leds_req_pending;
  521. static int pending_devs[16];
  522. static int pending_led_start=0;
  523. static int pending_led_end=0;
  524. static DEFINE_SPINLOCK(leds_lock);
  525. static void leds_done(struct adb_request *req)
  526. {
  527. int leds = 0, device = 0, pending = 0;
  528. unsigned long flags;
  529. spin_lock_irqsave(&leds_lock, flags);
  530. if (pending_led_start != pending_led_end) {
  531. device = pending_devs[pending_led_start];
  532. leds = leds_pending[device] & 0xff;
  533. leds_pending[device] = 0;
  534. pending_led_start++;
  535. pending_led_start = (pending_led_start < 16) ? pending_led_start : 0;
  536. pending = leds_req_pending;
  537. } else
  538. leds_req_pending = 0;
  539. spin_unlock_irqrestore(&leds_lock, flags);
  540. if (pending)
  541. adb_request(&led_request, leds_done, 0, 3,
  542. ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
  543. }
  544. static void real_leds(unsigned char leds, int device)
  545. {
  546. unsigned long flags;
  547. spin_lock_irqsave(&leds_lock, flags);
  548. if (!leds_req_pending) {
  549. leds_req_pending = 1;
  550. spin_unlock_irqrestore(&leds_lock, flags);
  551. adb_request(&led_request, leds_done, 0, 3,
  552. ADB_WRITEREG(device, KEYB_LEDREG), 0xff, ~leds);
  553. return;
  554. } else {
  555. if (!(leds_pending[device] & 0x100)) {
  556. pending_devs[pending_led_end] = device;
  557. pending_led_end++;
  558. pending_led_end = (pending_led_end < 16) ? pending_led_end : 0;
  559. }
  560. leds_pending[device] = leds | 0x100;
  561. }
  562. spin_unlock_irqrestore(&leds_lock, flags);
  563. }
  564. /*
  565. * Event callback from the input module. Events that change the state of
  566. * the hardware are processed here.
  567. */
  568. static int adbhid_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
  569. {
  570. struct adbhid *adbhid = dev->private;
  571. unsigned char leds;
  572. switch (type) {
  573. case EV_LED:
  574. leds = (test_bit(LED_SCROLLL, dev->led) ? 4 : 0)
  575. | (test_bit(LED_NUML, dev->led) ? 1 : 0)
  576. | (test_bit(LED_CAPSL, dev->led) ? 2 : 0);
  577. real_leds(leds, adbhid->id);
  578. return 0;
  579. }
  580. return -1;
  581. }
  582. static int
  583. adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
  584. {
  585. switch (code) {
  586. case ADB_MSG_PRE_RESET:
  587. case ADB_MSG_POWERDOWN:
  588. /* Stop the repeat timer. Autopoll is already off at this point */
  589. {
  590. int i;
  591. for (i = 1; i < 16; i++) {
  592. if (adbhid[i])
  593. del_timer_sync(&adbhid[i]->input->timer);
  594. }
  595. }
  596. /* Stop pending led requests */
  597. while(leds_req_pending)
  598. adb_poll();
  599. break;
  600. case ADB_MSG_POST_RESET:
  601. adbhid_probe();
  602. break;
  603. }
  604. return NOTIFY_DONE;
  605. }
  606. static int
  607. adbhid_input_register(int id, int default_id, int original_handler_id,
  608. int current_handler_id, int mouse_kind)
  609. {
  610. struct adbhid *hid;
  611. struct input_dev *input_dev;
  612. int err;
  613. int i;
  614. if (adbhid[id]) {
  615. printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
  616. return -EEXIST;
  617. }
  618. adbhid[id] = hid = kzalloc(sizeof(struct adbhid), GFP_KERNEL);
  619. input_dev = input_allocate_device();
  620. if (!hid || !input_dev) {
  621. err = -ENOMEM;
  622. goto fail;
  623. }
  624. sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
  625. hid->input = input_dev;
  626. hid->id = default_id;
  627. hid->original_handler_id = original_handler_id;
  628. hid->current_handler_id = current_handler_id;
  629. hid->mouse_kind = mouse_kind;
  630. hid->flags = 0;
  631. input_dev->private = hid;
  632. input_dev->name = hid->name;
  633. input_dev->phys = hid->phys;
  634. input_dev->id.bustype = BUS_ADB;
  635. input_dev->id.vendor = 0x0001;
  636. input_dev->id.product = (id << 12) | (default_id << 8) | original_handler_id;
  637. input_dev->id.version = 0x0100;
  638. switch (default_id) {
  639. case ADB_KEYBOARD:
  640. hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL);
  641. if (!hid->keycode) {
  642. err = -ENOMEM;
  643. goto fail;
  644. }
  645. sprintf(hid->name, "ADB keyboard");
  646. memcpy(hid->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
  647. printk(KERN_INFO "Detected ADB keyboard, type ");
  648. switch (original_handler_id) {
  649. default:
  650. printk("<unknown>.\n");
  651. input_dev->id.version = ADB_KEYBOARD_UNKNOWN;
  652. break;
  653. case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
  654. case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
  655. case 0xC0: case 0xC3: case 0xC6:
  656. printk("ANSI.\n");
  657. input_dev->id.version = ADB_KEYBOARD_ANSI;
  658. break;
  659. case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
  660. case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
  661. case 0xC4: case 0xC7:
  662. printk("ISO, swapping keys.\n");
  663. input_dev->id.version = ADB_KEYBOARD_ISO;
  664. i = hid->keycode[10];
  665. hid->keycode[10] = hid->keycode[50];
  666. hid->keycode[50] = i;
  667. break;
  668. case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
  669. case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
  670. printk("JIS.\n");
  671. input_dev->id.version = ADB_KEYBOARD_JIS;
  672. break;
  673. }
  674. for (i = 0; i < 128; i++)
  675. if (hid->keycode[i])
  676. set_bit(hid->keycode[i], input_dev->keybit);
  677. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
  678. input_dev->ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
  679. input_dev->event = adbhid_kbd_event;
  680. input_dev->keycodemax = 127;
  681. input_dev->keycodesize = 1;
  682. break;
  683. case ADB_MOUSE:
  684. sprintf(hid->name, "ADB mouse");
  685. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  686. input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
  687. input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
  688. break;
  689. case ADB_MISC:
  690. switch (original_handler_id) {
  691. case 0x02: /* Adjustable keyboard button device */
  692. sprintf(hid->name, "ADB adjustable keyboard buttons");
  693. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  694. set_bit(KEY_SOUND, input_dev->keybit);
  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. break;
  699. case 0x1f: /* Powerbook button device */
  700. sprintf(hid->name, "ADB Powerbook buttons");
  701. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  702. set_bit(KEY_MUTE, input_dev->keybit);
  703. set_bit(KEY_VOLUMEUP, input_dev->keybit);
  704. set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
  705. set_bit(KEY_BRIGHTNESSUP, input_dev->keybit);
  706. set_bit(KEY_BRIGHTNESSDOWN, input_dev->keybit);
  707. set_bit(KEY_EJECTCD, input_dev->keybit);
  708. set_bit(KEY_SWITCHVIDEOMODE, input_dev->keybit);
  709. set_bit(KEY_KBDILLUMTOGGLE, input_dev->keybit);
  710. set_bit(KEY_KBDILLUMDOWN, input_dev->keybit);
  711. set_bit(KEY_KBDILLUMUP, input_dev->keybit);
  712. break;
  713. }
  714. if (hid->name[0])
  715. break;
  716. /* else fall through */
  717. default:
  718. printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
  719. err = -ENODEV;
  720. goto fail;
  721. }
  722. input_dev->keycode = hid->keycode;
  723. input_register_device(input_dev);
  724. if (default_id == ADB_KEYBOARD) {
  725. /* HACK WARNING!! This should go away as soon there is an utility
  726. * to control that for event devices.
  727. */
  728. input_dev->rep[REP_DELAY] = 500; /* input layer default: 250 */
  729. input_dev->rep[REP_PERIOD] = 66; /* input layer default: 33 */
  730. }
  731. return 0;
  732. fail: input_free_device(input_dev);
  733. kfree(hid);
  734. adbhid[id] = NULL;
  735. return err;
  736. }
  737. static void adbhid_input_unregister(int id)
  738. {
  739. input_unregister_device(adbhid[id]->input);
  740. kfree(adbhid[id]->keycode);
  741. kfree(adbhid[id]);
  742. adbhid[id] = NULL;
  743. }
  744. static u16
  745. adbhid_input_reregister(int id, int default_id, int org_handler_id,
  746. int cur_handler_id, int mk)
  747. {
  748. if (adbhid[id]) {
  749. if (adbhid[id]->input->id.product !=
  750. ((id << 12)|(default_id << 8)|org_handler_id)) {
  751. adbhid_input_unregister(id);
  752. adbhid_input_register(id, default_id, org_handler_id,
  753. cur_handler_id, mk);
  754. }
  755. } else
  756. adbhid_input_register(id, default_id, org_handler_id,
  757. cur_handler_id, mk);
  758. return 1<<id;
  759. }
  760. static void
  761. adbhid_input_devcleanup(u16 exist)
  762. {
  763. int i;
  764. for(i=1; i<16; i++)
  765. if (adbhid[i] && !(exist&(1<<i)))
  766. adbhid_input_unregister(i);
  767. }
  768. static void
  769. adbhid_probe(void)
  770. {
  771. struct adb_request req;
  772. int i, default_id, org_handler_id, cur_handler_id;
  773. u16 reg = 0;
  774. adb_register(ADB_MOUSE, 0, &mouse_ids, adbhid_mouse_input);
  775. adb_register(ADB_KEYBOARD, 0, &keyboard_ids, adbhid_keyboard_input);
  776. adb_register(ADB_MISC, 0, &buttons_ids, adbhid_buttons_input);
  777. for (i = 0; i < keyboard_ids.nids; i++) {
  778. int id = keyboard_ids.id[i];
  779. adb_get_infos(id, &default_id, &org_handler_id);
  780. /* turn off all leds */
  781. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  782. ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
  783. /* Enable full feature set of the keyboard
  784. ->get it to send separate codes for left and right shift,
  785. control, option keys */
  786. #if 0 /* handler 5 doesn't send separate codes for R modifiers */
  787. if (adb_try_handler_change(id, 5))
  788. printk("ADB keyboard at %d, handler set to 5\n", id);
  789. else
  790. #endif
  791. if (adb_try_handler_change(id, 3))
  792. printk("ADB keyboard at %d, handler set to 3\n", id);
  793. else
  794. printk("ADB keyboard at %d, handler 1\n", id);
  795. adb_get_infos(id, &default_id, &cur_handler_id);
  796. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  797. cur_handler_id, 0);
  798. }
  799. for (i = 0; i < buttons_ids.nids; i++) {
  800. int id = buttons_ids.id[i];
  801. adb_get_infos(id, &default_id, &org_handler_id);
  802. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  803. org_handler_id, 0);
  804. }
  805. /* Try to switch all mice to handler 4, or 2 for three-button
  806. mode and full resolution. */
  807. for (i = 0; i < mouse_ids.nids; i++) {
  808. int id = mouse_ids.id[i];
  809. int mouse_kind;
  810. adb_get_infos(id, &default_id, &org_handler_id);
  811. if (adb_try_handler_change(id, 4)) {
  812. printk("ADB mouse at %d, handler set to 4", id);
  813. mouse_kind = ADBMOUSE_EXTENDED;
  814. }
  815. else if (adb_try_handler_change(id, 0x2F)) {
  816. printk("ADB mouse at %d, handler set to 0x2F", id);
  817. mouse_kind = ADBMOUSE_MICROSPEED;
  818. }
  819. else if (adb_try_handler_change(id, 0x42)) {
  820. printk("ADB mouse at %d, handler set to 0x42", id);
  821. mouse_kind = ADBMOUSE_TRACKBALLPRO;
  822. }
  823. else if (adb_try_handler_change(id, 0x66)) {
  824. printk("ADB mouse at %d, handler set to 0x66", id);
  825. mouse_kind = ADBMOUSE_MICROSPEED;
  826. }
  827. else if (adb_try_handler_change(id, 0x5F)) {
  828. printk("ADB mouse at %d, handler set to 0x5F", id);
  829. mouse_kind = ADBMOUSE_MICROSPEED;
  830. }
  831. else if (adb_try_handler_change(id, 3)) {
  832. printk("ADB mouse at %d, handler set to 3", id);
  833. mouse_kind = ADBMOUSE_MS_A3;
  834. }
  835. else if (adb_try_handler_change(id, 2)) {
  836. printk("ADB mouse at %d, handler set to 2", id);
  837. mouse_kind = ADBMOUSE_STANDARD_200;
  838. }
  839. else {
  840. printk("ADB mouse at %d, handler 1", id);
  841. mouse_kind = ADBMOUSE_STANDARD_100;
  842. }
  843. if ((mouse_kind == ADBMOUSE_TRACKBALLPRO)
  844. || (mouse_kind == ADBMOUSE_MICROSPEED)) {
  845. init_microspeed(id);
  846. } else if (mouse_kind == ADBMOUSE_MS_A3) {
  847. init_ms_a3(id);
  848. } else if (mouse_kind == ADBMOUSE_EXTENDED) {
  849. /*
  850. * Register 1 is usually used for device
  851. * identification. Here, we try to identify
  852. * a known device and call the appropriate
  853. * init function.
  854. */
  855. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  856. ADB_READREG(id, 1));
  857. if ((req.reply_len) &&
  858. (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
  859. || (req.reply[2] == 0x20))) {
  860. mouse_kind = ADBMOUSE_TRACKBALL;
  861. init_trackball(id);
  862. }
  863. else if ((req.reply_len >= 4) &&
  864. (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
  865. (req.reply[3] == 0x61) && (req.reply[4] == 0x64)) {
  866. mouse_kind = ADBMOUSE_TRACKPAD;
  867. init_trackpad(id);
  868. }
  869. else if ((req.reply_len >= 4) &&
  870. (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
  871. (req.reply[3] == 0x4c) && (req.reply[4] == 0x31)) {
  872. mouse_kind = ADBMOUSE_TURBOMOUSE5;
  873. init_turbomouse(id);
  874. }
  875. else if ((req.reply_len == 9) &&
  876. (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
  877. (req.reply[3] == 0x49) && (req.reply[4] == 0x54)) {
  878. if (adb_try_handler_change(id, 0x42)) {
  879. printk("\nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
  880. mouse_kind = ADBMOUSE_MACALLY2;
  881. }
  882. }
  883. }
  884. printk("\n");
  885. adb_get_infos(id, &default_id, &cur_handler_id);
  886. reg |= adbhid_input_reregister(id, default_id, org_handler_id,
  887. cur_handler_id, mouse_kind);
  888. }
  889. adbhid_input_devcleanup(reg);
  890. }
  891. static void
  892. init_trackpad(int id)
  893. {
  894. struct adb_request req;
  895. unsigned char r1_buffer[8];
  896. printk(" (trackpad)");
  897. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  898. ADB_READREG(id,1));
  899. if (req.reply_len < 8)
  900. printk("bad length for reg. 1\n");
  901. else
  902. {
  903. memcpy(r1_buffer, &req.reply[1], 8);
  904. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  905. ADB_WRITEREG(id,1),
  906. r1_buffer[0],
  907. r1_buffer[1],
  908. r1_buffer[2],
  909. r1_buffer[3],
  910. r1_buffer[4],
  911. r1_buffer[5],
  912. 0x0d,
  913. r1_buffer[7]);
  914. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  915. ADB_WRITEREG(id,2),
  916. 0x99,
  917. 0x94,
  918. 0x19,
  919. 0xff,
  920. 0xb2,
  921. 0x8a,
  922. 0x1b,
  923. 0x50);
  924. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  925. ADB_WRITEREG(id,1),
  926. r1_buffer[0],
  927. r1_buffer[1],
  928. r1_buffer[2],
  929. r1_buffer[3],
  930. r1_buffer[4],
  931. r1_buffer[5],
  932. 0x03, /*r1_buffer[6],*/
  933. r1_buffer[7]);
  934. /* Without this flush, the trackpad may be locked up */
  935. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  936. }
  937. }
  938. static void
  939. init_trackball(int id)
  940. {
  941. struct adb_request req;
  942. printk(" (trackman/mouseman)");
  943. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  944. ADB_WRITEREG(id,1), 00,0x81);
  945. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  946. ADB_WRITEREG(id,1), 01,0x81);
  947. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  948. ADB_WRITEREG(id,1), 02,0x81);
  949. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  950. ADB_WRITEREG(id,1), 03,0x38);
  951. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  952. ADB_WRITEREG(id,1), 00,0x81);
  953. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  954. ADB_WRITEREG(id,1), 01,0x81);
  955. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  956. ADB_WRITEREG(id,1), 02,0x81);
  957. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  958. ADB_WRITEREG(id,1), 03,0x38);
  959. }
  960. static void
  961. init_turbomouse(int id)
  962. {
  963. struct adb_request req;
  964. printk(" (TurboMouse 5)");
  965. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  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. 0xe7,
  970. 0x8c,
  971. 0,
  972. 0,
  973. 0,
  974. 0xff,
  975. 0xff,
  976. 0x94);
  977. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  978. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  979. ADB_WRITEREG(3,2),
  980. 0xa5,
  981. 0x14,
  982. 0,
  983. 0,
  984. 0x69,
  985. 0xff,
  986. 0xff,
  987. 0x27);
  988. }
  989. static void
  990. init_microspeed(int id)
  991. {
  992. struct adb_request req;
  993. printk(" (Microspeed/MacPoint or compatible)");
  994. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  995. /* This will initialize mice using the Microspeed, MacPoint and
  996. other compatible firmware. Bit 12 enables extended protocol.
  997. Register 1 Listen (4 Bytes)
  998. 0 - 3 Button is mouse (set also for double clicking!!!)
  999. 4 - 7 Button is locking (affects change speed also)
  1000. 8 - 11 Button changes speed
  1001. 12 1 = Extended mouse mode, 0 = normal mouse mode
  1002. 13 - 15 unused 0
  1003. 16 - 23 normal speed
  1004. 24 - 31 changed speed
  1005. Register 1 talk holds version and product identification information.
  1006. Register 1 Talk (4 Bytes):
  1007. 0 - 7 Product code
  1008. 8 - 23 undefined, reserved
  1009. 24 - 31 Version number
  1010. Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
  1011. */
  1012. adb_request(&req, NULL, ADBREQ_SYNC, 5,
  1013. ADB_WRITEREG(id,1),
  1014. 0x20, /* alt speed = 0x20 (rather slow) */
  1015. 0x00, /* norm speed = 0x00 (fastest) */
  1016. 0x10, /* extended protocol, no speed change */
  1017. 0x07); /* all buttons enabled as mouse buttons, no locking */
  1018. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1019. }
  1020. static void
  1021. init_ms_a3(int id)
  1022. {
  1023. struct adb_request req;
  1024. printk(" (Mouse Systems A3 Mouse, or compatible)");
  1025. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  1026. ADB_WRITEREG(id, 0x2),
  1027. 0x00,
  1028. 0x07);
  1029. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  1030. }
  1031. static int __init adbhid_init(void)
  1032. {
  1033. #ifndef CONFIG_MAC
  1034. if (!machine_is(chrp) && !machine_is(powermac))
  1035. return 0;
  1036. #endif
  1037. led_request.complete = 1;
  1038. adbhid_probe();
  1039. blocking_notifier_chain_register(&adb_client_list,
  1040. &adbhid_adb_notifier);
  1041. return 0;
  1042. }
  1043. static void __exit adbhid_exit(void)
  1044. {
  1045. }
  1046. module_init(adbhid_init);
  1047. module_exit(adbhid_exit);