mac_keyb.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:32k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * drivers/char/mac_keyb.c
  3.  *
  4.  * Keyboard driver for Power Macintosh computers.
  5.  *
  6.  * Adapted from drivers/char/keyboard.c by Paul Mackerras
  7.  * (see that file for its authors and contributors).
  8.  *
  9.  * Copyright (C) 1996 Paul Mackerras.
  10.  *
  11.  * Adapted to ADB changes and support for more devices by
  12.  * Benjamin Herrenschmidt. Adapted from code in MkLinux
  13.  * and reworked.
  14.  *
  15.  * Supported devices:
  16.  *
  17.  * - Standard 1 button mouse
  18.  * - All standard Apple Extended protocol (handler ID 4)
  19.  * - mouseman and trackman mice & trackballs
  20.  * - PowerBook Trackpad (default setup: enable tapping)
  21.  * - MicroSpeed mouse & trackball (needs testing)
  22.  * - CH Products Trackball Pro (needs testing)
  23.  * - Contour Design (Contour Mouse)
  24.  * - Hunter digital (NoHandsMouse)
  25.  * - Kensignton TurboMouse 5 (needs testing)
  26.  * - Mouse Systems A3 mice and trackballs <aidan@kublai.com>
  27.  * - MacAlly 2-buttons mouse (needs testing) <pochini@denise.shiny.it>
  28.  *
  29.  * To do:
  30.  *
  31.  * Improve Kensignton support, add MacX support as a dynamic
  32.  * option (not a compile-time option).
  33.  */
  34. #include <linux/sched.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/tty.h>
  37. #include <linux/mm.h>
  38. #include <linux/signal.h>
  39. #include <linux/ioport.h>
  40. #include <linux/init.h>
  41. #include <linux/tty_flip.h>
  42. #include <linux/config.h>
  43. #include <linux/notifier.h>
  44. #include <asm/bitops.h>
  45. #include <linux/adb.h>
  46. #include <linux/cuda.h>
  47. #include <linux/pmu.h>
  48. #include <linux/kbd_kern.h>
  49. #include <linux/kbd_ll.h>
  50. #ifdef CONFIG_PMAC_BACKLIGHT
  51. #include <asm/backlight.h>
  52. #endif
  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 mackeyb_adb_notifier = {
  58. adb_message_handler,
  59. NULL,
  60. 0
  61. };
  62. /* this map indicates which keys shouldn't autorepeat. */
  63. static unsigned char dont_repeat[128] = {
  64. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  65. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  66. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  67. 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* esc...option */
  68. 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* fn, num lock */
  69. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  70. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, /* scroll lock */
  71. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, /* R modifiers */
  72. };
  73. /* Simple translation table for the SysRq keys */
  74. #ifdef CONFIG_MAGIC_SYSRQ
  75. unsigned char mackbd_sysrq_xlate[128] =
  76. "asdfhgzxcv00bqwer" /* 0x00 - 0x0f */
  77. "yt123465=97-80o]" /* 0x10 - 0x1f */
  78. "u[iprlj'k;\,/nm." /* 0x20 - 0x2f */
  79. "t `177003300000000000000000000"
  80. /* 0x30 - 0x3f */
  81. "000000*00+0000000000/r00-00"
  82. /* 0x40 - 0x4f */
  83. "00000123456789000000" /* 0x50 - 0x5f */
  84. "2052062072032102110021300215000000000021200214";
  85. /* 0x60 - 0x6f */
  86. #endif
  87. static u_short macplain_map[NR_KEYS] __initdata = {
  88. 0xfb61, 0xfb73, 0xfb64, 0xfb66, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
  89. 0xfb63, 0xfb76, 0xf200, 0xfb62, 0xfb71, 0xfb77, 0xfb65, 0xfb72,
  90. 0xfb79, 0xfb74, 0xf031, 0xf032, 0xf033, 0xf034, 0xf036, 0xf035,
  91. 0xf03d, 0xf039, 0xf037, 0xf02d, 0xf038, 0xf030, 0xf05d, 0xfb6f,
  92. 0xfb75, 0xf05b, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf027,
  93. 0xfb6b, 0xf03b, 0xf05c, 0xf02c, 0xf02f, 0xfb6e, 0xfb6d, 0xf02e,
  94. 0xf009, 0xf020, 0xf060, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
  95. 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
  96. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  97. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  98. 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
  99. 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
  100. 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
  101. 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf109, 0xf200, 0xf10b,
  102. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
  103. 0xf101, 0xf119, 0xf100, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
  104. };
  105. static u_short macshift_map[NR_KEYS] __initdata = {
  106. 0xfb41, 0xfb53, 0xfb44, 0xfb46, 0xfb48, 0xfb47, 0xfb5a, 0xfb58,
  107. 0xfb43, 0xfb56, 0xf200, 0xfb42, 0xfb51, 0xfb57, 0xfb45, 0xfb52,
  108. 0xfb59, 0xfb54, 0xf021, 0xf040, 0xf023, 0xf024, 0xf05e, 0xf025,
  109. 0xf02b, 0xf028, 0xf026, 0xf05f, 0xf02a, 0xf029, 0xf07d, 0xfb4f,
  110. 0xfb55, 0xf07b, 0xfb49, 0xfb50, 0xf201, 0xfb4c, 0xfb4a, 0xf022,
  111. 0xfb4b, 0xf03a, 0xf07c, 0xf03c, 0xf03f, 0xfb4e, 0xfb4d, 0xf03e,
  112. 0xf009, 0xf020, 0xf07e, 0xf07f, 0xf200, 0xf01b, 0xf702, 0xf703,
  113. 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
  114. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  115. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  116. 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
  117. 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
  118. 0xf10e, 0xf10f, 0xf110, 0xf10c, 0xf111, 0xf112, 0xf200, 0xf10a,
  119. 0xf200, 0xf10c, 0xf200, 0xf203, 0xf200, 0xf113, 0xf200, 0xf10b,
  120. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf20b, 0xf116, 0xf10d, 0xf117,
  121. 0xf10b, 0xf20a, 0xf10a, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
  122. };
  123. static u_short macaltgr_map[NR_KEYS] __initdata = {
  124. 0xf914, 0xfb73, 0xf917, 0xf919, 0xfb68, 0xfb67, 0xfb7a, 0xfb78,
  125. 0xf916, 0xfb76, 0xf200, 0xf915, 0xfb71, 0xfb77, 0xf918, 0xfb72,
  126. 0xfb79, 0xfb74, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
  127. 0xf200, 0xf05d, 0xf07b, 0xf05c, 0xf05b, 0xf07d, 0xf07e, 0xfb6f,
  128. 0xfb75, 0xf200, 0xfb69, 0xfb70, 0xf201, 0xfb6c, 0xfb6a, 0xf200,
  129. 0xfb6b, 0xf200, 0xf200, 0xf200, 0xf200, 0xfb6e, 0xfb6d, 0xf200,
  130. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
  131. 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
  132. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  133. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  134. 0xf200, 0xf200, 0xf90a, 0xf90b, 0xf90c, 0xf90d, 0xf90e, 0xf90f,
  135. 0xf910, 0xf911, 0xf200, 0xf912, 0xf913, 0xf200, 0xf200, 0xf200,
  136. 0xf510, 0xf511, 0xf512, 0xf50e, 0xf513, 0xf514, 0xf200, 0xf516,
  137. 0xf200, 0xf10c, 0xf200, 0xf202, 0xf200, 0xf515, 0xf200, 0xf517,
  138. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf50f, 0xf117,
  139. 0xf50d, 0xf119, 0xf50c, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
  140. };
  141. static u_short macctrl_map[NR_KEYS] __initdata = {
  142. 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
  143. 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
  144. 0xf019, 0xf014, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01e, 0xf01d,
  145. 0xf200, 0xf200, 0xf01f, 0xf01f, 0xf07f, 0xf200, 0xf01d, 0xf00f,
  146. 0xf015, 0xf01b, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf007,
  147. 0xf00b, 0xf200, 0xf01c, 0xf200, 0xf07f, 0xf00e, 0xf00d, 0xf20e,
  148. 0xf200, 0xf000, 0xf000, 0xf008, 0xf200, 0xf200, 0xf702, 0xf703,
  149. 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
  150. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  151. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  152. 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
  153. 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
  154. 0xf104, 0xf105, 0xf106, 0xf102, 0xf107, 0xf108, 0xf200, 0xf10a,
  155. 0xf200, 0xf10c, 0xf200, 0xf204, 0xf200, 0xf109, 0xf200, 0xf10b,
  156. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf103, 0xf117,
  157. 0xf101, 0xf119, 0xf100, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
  158. };
  159. static u_short macshift_ctrl_map[NR_KEYS] __initdata = {
  160. 0xf001, 0xf013, 0xf004, 0xf006, 0xf008, 0xf007, 0xf01a, 0xf018,
  161. 0xf003, 0xf016, 0xf200, 0xf002, 0xf011, 0xf017, 0xf005, 0xf012,
  162. 0xf019, 0xf014, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
  163. 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200, 0xf00f,
  164. 0xf015, 0xf200, 0xf009, 0xf010, 0xf201, 0xf00c, 0xf00a, 0xf200,
  165. 0xf00b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf00e, 0xf00d, 0xf200,
  166. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
  167. 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
  168. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  169. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  170. 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
  171. 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
  172. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  173. 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  174. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf200, 0xf117,
  175. 0xf200, 0xf119, 0xf200, 0xf700, 0xf701, 0xf702, 0xf200, 0xf20c,
  176. };
  177. static u_short macalt_map[NR_KEYS] __initdata = {
  178. 0xf861, 0xf873, 0xf864, 0xf866, 0xf868, 0xf867, 0xf87a, 0xf878,
  179. 0xf863, 0xf876, 0xf200, 0xf862, 0xf871, 0xf877, 0xf865, 0xf872,
  180. 0xf879, 0xf874, 0xf831, 0xf832, 0xf833, 0xf834, 0xf836, 0xf835,
  181. 0xf83d, 0xf839, 0xf837, 0xf82d, 0xf838, 0xf830, 0xf85d, 0xf86f,
  182. 0xf875, 0xf85b, 0xf869, 0xf870, 0xf80d, 0xf86c, 0xf86a, 0xf827,
  183. 0xf86b, 0xf83b, 0xf85c, 0xf82c, 0xf82f, 0xf86e, 0xf86d, 0xf82e,
  184. 0xf809, 0xf820, 0xf860, 0xf87f, 0xf200, 0xf81b, 0xf702, 0xf703,
  185. 0xf700, 0xf207, 0xf701, 0xf210, 0xf211, 0xf600, 0xf603, 0xf200,
  186. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  187. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  188. 0xf200, 0xf200, 0xf900, 0xf901, 0xf902, 0xf903, 0xf904, 0xf905,
  189. 0xf906, 0xf907, 0xf200, 0xf908, 0xf909, 0xf200, 0xf200, 0xf200,
  190. 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
  191. 0xf200, 0xf10c, 0xf200, 0xf209, 0xf200, 0xf509, 0xf200, 0xf50b,
  192. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
  193. 0xf501, 0xf119, 0xf500, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
  194. };
  195. static u_short macctrl_alt_map[NR_KEYS] __initdata = {
  196. 0xf801, 0xf813, 0xf804, 0xf806, 0xf808, 0xf807, 0xf81a, 0xf818,
  197. 0xf803, 0xf816, 0xf200, 0xf802, 0xf811, 0xf817, 0xf805, 0xf812,
  198. 0xf819, 0xf814, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  199. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80f,
  200. 0xf815, 0xf200, 0xf809, 0xf810, 0xf201, 0xf80c, 0xf80a, 0xf200,
  201. 0xf80b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf80e, 0xf80d, 0xf200,
  202. 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf702, 0xf703,
  203. 0xf700, 0xf207, 0xf701, 0xf601, 0xf602, 0xf600, 0xf603, 0xf200,
  204. 0xf200, 0xf310, 0xf200, 0xf30c, 0xf200, 0xf30a, 0xf200, 0xf208,
  205. 0xf200, 0xf200, 0xf200, 0xf30d, 0xf30e, 0xf200, 0xf30b, 0xf200,
  206. 0xf200, 0xf200, 0xf300, 0xf301, 0xf302, 0xf303, 0xf304, 0xf305,
  207. 0xf306, 0xf307, 0xf200, 0xf308, 0xf309, 0xf200, 0xf200, 0xf200,
  208. 0xf504, 0xf505, 0xf506, 0xf502, 0xf507, 0xf508, 0xf200, 0xf50a,
  209. 0xf200, 0xf10c, 0xf200, 0xf200, 0xf200, 0xf509, 0xf200, 0xf50b,
  210. 0xf200, 0xf11d, 0xf115, 0xf114, 0xf118, 0xf116, 0xf503, 0xf117,
  211. 0xf501, 0xf119, 0xf500, 0xf700, 0xf701, 0xf702, 0xf200, 0xf200,
  212. };
  213. static void kbd_repeat(unsigned long);
  214. static struct timer_list repeat_timer = { function: kbd_repeat };
  215. static int last_keycode;
  216. static void mackeyb_probe(void);
  217. static void keyboard_input(unsigned char *, int, struct pt_regs *, int);
  218. static void input_keycode(int, int);
  219. static void leds_done(struct adb_request *);
  220. static void mac_put_queue(int);
  221. static void buttons_input(unsigned char *, int, struct pt_regs *, int);
  222. static void init_trackpad(int id);
  223. static void init_trackball(int id);
  224. static void init_turbomouse(int id);
  225. static void init_microspeed(int id);
  226. static void init_ms_a3(int id);
  227. #ifdef CONFIG_ADBMOUSE
  228. /* XXX: Hook for mouse driver */
  229. void (*adb_mouse_interrupt_hook)(unsigned char *, int);
  230. int adb_emulate_buttons = 0;
  231. int adb_button2_keycode = 0x7d; /* right control key */
  232. int adb_button3_keycode = 0x7c; /* right option key */
  233. #endif
  234. extern struct kbd_struct kbd_table[];
  235. extern void handle_scancode(unsigned char, int);
  236. static struct adb_ids keyboard_ids;
  237. static struct adb_ids mouse_ids;
  238. static struct adb_ids buttons_ids;
  239. /* Kind of mouse  */
  240. #define ADBMOUSE_STANDARD_100 0 /* Standard 100cpi mouse (handler 1) */
  241. #define ADBMOUSE_STANDARD_200 1 /* Standard 200cpi mouse (handler 2) */
  242. #define ADBMOUSE_EXTENDED 2 /* Apple Extended mouse (handler 4) */
  243. #define ADBMOUSE_TRACKBALL 3 /* TrackBall (handler 4) */
  244. #define ADBMOUSE_TRACKPAD       4 /* Apple's PowerBook trackpad (handler 4) */
  245. #define ADBMOUSE_TURBOMOUSE5    5 /* Turbomouse 5 (previously req. mousehack) */
  246. #define ADBMOUSE_MICROSPEED 6 /* Microspeed mouse (&trackball ?), MacPoint */
  247. #define ADBMOUSE_TRACKBALLPRO 7 /* Trackball Pro (special buttons) */
  248. #define ADBMOUSE_MS_A3 8 /* Mouse systems A3 trackball (handler 3) */
  249. #define ADBMOUSE_MACALLY2 9 /* MacAlly 2-button mouse */
  250. static int adb_mouse_kinds[16];
  251. int mackbd_setkeycode(unsigned int scancode, unsigned int keycode)
  252. {
  253. return -EINVAL;
  254. }
  255. int mackbd_getkeycode(unsigned int scancode)
  256. {
  257. return -EINVAL;
  258. }
  259. int mackbd_translate(unsigned char keycode, unsigned char *keycodep,
  260.      char raw_mode)
  261. {
  262. if (!raw_mode) {
  263. /*
  264.  * Convert R-shift/control/option to L version.
  265.  */
  266. switch (keycode) {
  267. case 0x7b: keycode = 0x38; break; /* R-shift */
  268. case 0x7c: keycode = 0x3a; break; /* R-option */
  269. case 0x7d: keycode = 0x36; break; /* R-control */
  270. }
  271. }
  272. *keycodep = keycode;
  273. return 1;
  274. }
  275. char mackbd_unexpected_up(unsigned char keycode)
  276. {
  277. return 0x80;
  278. }
  279. static void
  280. keyboard_input(unsigned char *data, int nb, struct pt_regs *regs, int apoll)
  281. {
  282. /* first check this is from register 0 */
  283. if (nb != 3 || (data[0] & 3) != KEYB_KEYREG)
  284. return; /* ignore it */
  285. kbd_pt_regs = regs;
  286. input_keycode(data[1], 0);
  287. if (!(data[2] == 0xff || (data[2] == 0x7f && data[1] == 0x7f)))
  288. input_keycode(data[2], 0);
  289. }
  290. static void
  291. input_keycode(int keycode, int repeat)
  292. {
  293. struct kbd_struct *kbd;
  294. int up_flag;
  295.   kbd = kbd_table + fg_console;
  296. up_flag = (keycode & 0x80);
  297. keycode &= 0x7f;
  298. /* on the powerbook 3400, the power key gives code 0x7e */
  299. if (keycode == 0x7e)
  300. keycode = 0x7f;
  301. /* remap the "Fn" key of the PowerBook G3 Series to 0x48
  302.    to avoid conflict with button emulation */
  303. if (keycode == 0x3f)
  304. keycode = 0x48;
  305. if (!repeat)
  306. del_timer(&repeat_timer);
  307. #ifdef CONFIG_ADBMOUSE
  308. /*
  309.  * XXX: Add mouse button 2+3 fake codes here if mouse open.
  310.  * Keep track of 'button' states here as we only send
  311.  * single up/down events!
  312.  * Really messy; might need to check if keyboard is in
  313.  * VC_RAW mode.
  314.  * Might also want to know how many buttons need to be emulated.
  315.  * -> hide this as function in arch/m68k/mac ?
  316.  */
  317. if (adb_emulate_buttons
  318.     && (keycode == adb_button2_keycode
  319. || keycode == adb_button3_keycode)
  320.     && (adb_mouse_interrupt_hook || console_loglevel == 10)) {
  321. int button;
  322. /* faked ADB packet */
  323. static unsigned char data[4] = { 0, 0x80, 0x80, 0x80 };
  324. button = keycode == adb_button2_keycode? 2: 3;
  325. if (data[button] != up_flag) {
  326. /* send a fake mouse packet */
  327. data[button] = up_flag;
  328. if (console_loglevel >= 8)
  329. printk("fake mouse event: %x %x %xn",
  330.        data[1], data[2], data[3]);
  331. if (adb_mouse_interrupt_hook)
  332. adb_mouse_interrupt_hook(data, 4);
  333. }
  334. return;
  335. }
  336. #endif /* CONFIG_ADBMOUSE */
  337. if (kbd->kbdmode != VC_RAW) {
  338. if (!up_flag && !dont_repeat[keycode]) {
  339. last_keycode = keycode;
  340. repeat_timer.expires = jiffies + (repeat? HZ/15: HZ/2);
  341. add_timer(&repeat_timer);
  342. }
  343. /*
  344.  * adb kludge!! Imitate pc caps lock behaviour by
  345.  * generating an up/down event for each time caps
  346.  * is pressed/released. Also, makes sure that the
  347.  * LED are handled.  atong@uiuc.edu
  348.  */
  349.  switch (keycode) {
  350.  /*case 0xb9:*/
  351.  case 0x39:
  352. handle_scancode(0x39, 1);
  353. handle_scancode(0x39, 0);
  354.   tasklet_schedule(&keyboard_tasklet);
  355.   return;
  356.  case 0x47:
  357.  /*case 0xc7:*/
  358.   tasklet_schedule(&keyboard_tasklet);
  359.   break;
  360.  }
  361. }
  362. handle_scancode(keycode, !up_flag);
  363. tasklet_schedule(&keyboard_tasklet);
  364. }
  365. static void
  366. kbd_repeat(unsigned long xxx)
  367. {
  368. unsigned long flags;
  369. save_flags(flags);
  370. cli();
  371. input_keycode(last_keycode, 1);
  372. restore_flags(flags);
  373. }
  374. static void mac_put_queue(int ch)
  375. {
  376. extern struct tty_driver console_driver;
  377. struct tty_struct *tty;
  378. tty = console_driver.table? console_driver.table[fg_console]: NULL;
  379. if (tty) {
  380. tty_insert_flip_char(tty, ch, 0);
  381. con_schedule_flip(tty);
  382. }
  383. }
  384. #ifdef CONFIG_ADBMOUSE
  385. static void
  386. mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
  387. {
  388.   /* [ACA:23-Mar-97] Three button mouse support.  This is designed to
  389.      function with MkLinux DR-2.1 style X servers.  It only works with
  390.      three-button mice that conform to Apple's multi-button mouse
  391.      protocol. */
  392.   /*
  393.     The X server for MkLinux DR2.1 uses the following unused keycodes to
  394.     read the mouse:
  395.     0x7e  This indicates that the next two keycodes should be interpreted
  396.           as mouse information.  The first following byte's high bit
  397.           represents the state of the left button.  The lower seven bits
  398.           represent the x-axis acceleration.  The lower seven bits of the
  399.           second byte represent y-axis acceleration.
  400.     0x3f  The x server interprets this keycode as a middle button
  401.           release.
  402.     0xbf  The x server interprets this keycode as a middle button
  403.           depress.
  404.     0x40  The x server interprets this keycode as a right button
  405.           release.
  406.     0xc0  The x server interprets this keycode as a right button
  407.           depress.
  408.     NOTES: There should be a better way of handling mice in the X server.
  409.     The MOUSE_ESCAPE code (0x7e) should be followed by three bytes instead
  410.     of two.  The three mouse buttons should then, in the X server, be read
  411.     as the high-bits of all three bytes.  The x and y motions can still be
  412.     in the first two bytes.  Maybe I'll do this...
  413.   */
  414.   /*
  415.     Handler 1 -- 100cpi original Apple mouse protocol.
  416.     Handler 2 -- 200cpi original Apple mouse protocol.
  417.     For Apple's standard one-button mouse protocol the data array will
  418.     contain the following values:
  419.                 BITS    COMMENTS
  420.     data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
  421.     data[1] = bxxx xxxx First button and x-axis motion.
  422.     data[2] = byyy yyyy Second button and y-axis motion.
  423.     Handler 4 -- Apple Extended mouse protocol.
  424.     For Apple's 3-button mouse protocol the data array will contain the
  425.     following values:
  426. BITS    COMMENTS
  427.     data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
  428.     data[1] = bxxx xxxx Left button and x-axis motion.
  429.     data[2] = byyy yyyy Second button and y-axis motion.
  430.     data[3] = byyy bxxx Third button and fourth button.  Y is additional
  431.       high bits of y-axis motion.  XY is additional
  432.       high bits of x-axis motion.
  433.     MacAlly 2-button mouse protocol.
  434.     For MacAlly 2-button mouse protocol the data array will contain the
  435.     following values:
  436. BITS    COMMENTS
  437.     data[0] = dddd 1100 ADB command: Talk, register 0, for device dddd.
  438.     data[1] = bxxx xxxx Left button and x-axis motion.
  439.     data[2] = byyy yyyy Right button and y-axis motion.
  440.     data[3] = ???? ???? unknown
  441.     data[4] = ???? ???? unknown
  442.   */
  443. struct kbd_struct *kbd;
  444. /* If it's a trackpad, we alias the second button to the first.
  445.    NOTE: Apple sends an ADB flush command to the trackpad when
  446.          the first (the real) button is released. We could do
  447.  this here using async flush requests.
  448. */
  449. switch (adb_mouse_kinds[(data[0]>>4) & 0xf])
  450. {
  451.     case ADBMOUSE_TRACKPAD:
  452. data[1] = (data[1] & 0x7f) | ((data[1] & data[2]) & 0x80);
  453. data[2] = data[2] | 0x80;
  454. break;
  455.     case ADBMOUSE_MICROSPEED:
  456. data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
  457. data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
  458. data[3] = (data[3] & 0x77) | ((data[3] & 0x04) << 5)
  459. | (data[3] & 0x08);
  460. break;
  461.     case ADBMOUSE_TRACKBALLPRO:
  462. data[1] = (data[1] & 0x7f) | (((data[3] & 0x04) << 5)
  463. & ((data[3] & 0x08) << 4));
  464. data[2] = (data[2] & 0x7f) | ((data[3] & 0x01) << 7);
  465. data[3] = (data[3] & 0x77) | ((data[3] & 0x02) << 6);
  466. break;
  467.     case ADBMOUSE_MS_A3:
  468. data[1] = (data[1] & 0x7f) | ((data[3] & 0x01) << 7);
  469. data[2] = (data[2] & 0x7f) | ((data[3] & 0x02) << 6);
  470. data[3] = ((data[3] & 0x04) << 5);
  471. break;
  472.             case ADBMOUSE_MACALLY2:
  473. data[3] = (data[2] & 0x80) ? 0x80 : 0x00;
  474. data[2] |= 0x80;  /* Right button is mapped as button 3 */
  475. nb=4;
  476.                 break;
  477. }
  478. if (adb_mouse_interrupt_hook)
  479. adb_mouse_interrupt_hook(data, nb);
  480. kbd = kbd_table + fg_console;
  481. /* Only send mouse codes when keyboard is in raw mode. */
  482. if (kbd->kbdmode == VC_RAW) {
  483. static unsigned char uch_ButtonStateSecond = 0x80;
  484. unsigned char uchButtonSecond;
  485. /* Send first button, second button and movement. */
  486. mac_put_queue(0x7e);
  487. mac_put_queue(data[1]);
  488. mac_put_queue(data[2]);
  489. /* [ACA: Are there any two-button ADB mice that use handler 1 or 2?] */
  490. /* Store the button state. */
  491. uchButtonSecond = (data[2] & 0x80);
  492. /* Send second button. */
  493. if (uchButtonSecond != uch_ButtonStateSecond) {
  494. mac_put_queue(0x3f | uchButtonSecond);
  495. uch_ButtonStateSecond = uchButtonSecond;
  496. }
  497. /* Macintosh 3-button mouse (handler 4). */
  498. if (nb >= 4) {
  499. static unsigned char uch_ButtonStateThird = 0x80;
  500. unsigned char uchButtonThird;
  501. /* Store the button state for speed. */
  502. uchButtonThird = (data[3] & 0x80);
  503. /* Send third button. */
  504. if (uchButtonThird != uch_ButtonStateThird) {
  505. mac_put_queue(0x40 | uchButtonThird);
  506. uch_ButtonStateThird = uchButtonThird;
  507. }
  508. }
  509. }
  510. }
  511. #endif /* CONFIG_ADBMOUSE */
  512. static void
  513. buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int autopoll)
  514. {
  515. #ifdef CONFIG_PMAC_BACKLIGHT
  516. int backlight = get_backlight_level();
  517. /*
  518.  * XXX: Where is the contrast control for the passive?
  519.  *  -- Cort
  520.  */
  521. /* Ignore data from register other than 0 */
  522. if ((data[0] & 0x3) || (nb < 2))
  523. return;
  524. switch (data[1]) {
  525. case 0x8: /* mute */
  526. break;
  527. case 0x7: /* contrast decrease */
  528. break;
  529. case 0x6: /* contrast increase */
  530. break;
  531. case 0xa: /* brightness decrease */
  532. if (backlight < 0)
  533. break;
  534. if (backlight > BACKLIGHT_OFF)
  535. set_backlight_level(backlight-1);
  536. else
  537. set_backlight_level(BACKLIGHT_OFF);
  538. break;
  539. case 0x9: /* brightness increase */
  540. if (backlight < 0)
  541. break;
  542. if (backlight < BACKLIGHT_MAX)
  543. set_backlight_level(backlight+1);
  544. else 
  545. set_backlight_level(BACKLIGHT_MAX);
  546. break;
  547. }
  548. #endif /* CONFIG_PMAC_BACKLIGHT */
  549. }
  550. /* Map led flags as defined in kbd_kern.h to bits for Apple keyboard. */
  551. static unsigned char mac_ledmap[8] = {
  552.     0, /* none */
  553.     4, /* scroll lock */
  554.     1, /* num lock */
  555.     5, /* scroll + num lock */
  556.     2, /* caps lock */
  557.     6, /* caps + scroll lock */
  558.     3, /* caps + num lock */
  559.     7, /* caps + num + scroll lock */
  560. };
  561. static struct adb_request led_request;
  562. static int leds_pending[16];
  563. static int pending_devs[16];
  564. static int pending_led_start=0;
  565. static int pending_led_end=0;
  566. static void real_mackbd_leds(unsigned char leds, int device)
  567. {
  568.     if (led_request.complete) {
  569. adb_request(&led_request, leds_done, 0, 3,
  570.     ADB_WRITEREG(device, KEYB_LEDREG), 0xff,
  571.     ~mac_ledmap[leds]);
  572.     } else {
  573. if (!(leds_pending[device] & 0x100)) {
  574.     pending_devs[pending_led_end] = device;
  575.     pending_led_end++;
  576.     pending_led_end = (pending_led_end < 16) ? pending_led_end : 0;
  577. }
  578. leds_pending[device] = leds | 0x100;
  579.     }
  580. }
  581. void mackbd_leds(unsigned char leds)
  582. {
  583.     int i;
  584.     for(i = 0; i < keyboard_ids.nids; i++)
  585. real_mackbd_leds(leds,keyboard_ids.id[i]);
  586. }
  587. static void leds_done(struct adb_request *req)
  588. {
  589.     int leds,device;
  590.     if (pending_led_start != pending_led_end) {
  591. device = pending_devs[pending_led_start];
  592. leds = leds_pending[device] & 0xff;
  593. leds_pending[device] = 0;
  594. pending_led_start++;
  595. pending_led_start = (pending_led_start < 16) ? pending_led_start : 0;
  596. real_mackbd_leds(leds,device);
  597.     }
  598. }
  599. void __init mackbd_init_hw(void)
  600. {
  601. #ifdef CONFIG_PPC
  602. if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) )
  603. return;
  604. #endif
  605. #ifdef CONFIG_MAC
  606. if (!MACH_IS_MAC)
  607. return;
  608. #endif
  609. /* setup key map */
  610. memcpy(key_maps[0], macplain_map, sizeof(plain_map));
  611. memcpy(key_maps[1], macshift_map, sizeof(plain_map));
  612. memcpy(key_maps[2], macaltgr_map, sizeof(plain_map));
  613. memcpy(key_maps[4], macctrl_map, sizeof(plain_map));
  614. memcpy(key_maps[5], macshift_ctrl_map, sizeof(plain_map));
  615. memcpy(key_maps[8], macalt_map, sizeof(plain_map));
  616. memcpy(key_maps[12], macctrl_alt_map, sizeof(plain_map));
  617. #ifdef CONFIG_ADBMOUSE
  618. /* initialize mouse interrupt hook */
  619. adb_mouse_interrupt_hook = NULL;
  620. #endif
  621. led_request.complete = 1;
  622. mackeyb_probe();
  623. notifier_chain_register(&adb_client_list, &mackeyb_adb_notifier);
  624. }
  625. static int
  626. adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
  627. {
  628. unsigned long flags;
  629. switch (code) {
  630. case ADB_MSG_PRE_RESET:
  631. case ADB_MSG_POWERDOWN:
  632. /* Stop the repeat timer. Autopoll is already off at this point */
  633. save_flags(flags);
  634. cli();
  635. del_timer(&repeat_timer);
  636. restore_flags(flags);
  637. /* Stop pending led requests */
  638. while(!led_request.complete)
  639. adb_poll();
  640. break;
  641. case ADB_MSG_POST_RESET:
  642. mackeyb_probe();
  643. break;
  644. }
  645. return NOTIFY_DONE;
  646. }
  647. static void
  648. mackeyb_probe(void)
  649. {
  650. struct adb_request req;
  651. int i;
  652. #ifdef CONFIG_ADBMOUSE
  653. adb_register(ADB_MOUSE, 0, &mouse_ids, mouse_input);
  654. #endif /* CONFIG_ADBMOUSE */
  655. adb_register(ADB_KEYBOARD, 0, &keyboard_ids, keyboard_input);
  656. adb_register(0x07, 0x1F, &buttons_ids, buttons_input);
  657. for (i = 0; i < keyboard_ids.nids; i++) {
  658. int id = keyboard_ids.id[i];
  659. /* turn off all leds */
  660. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  661.     ADB_WRITEREG(id, KEYB_LEDREG), 0xff, 0xff);
  662. /* Enable full feature set of the keyboard
  663.    ->get it to send separate codes for left and right shift,
  664.    control, option keys */
  665. #if 0 /* handler 5 doesn't send separate codes for R modifiers */
  666. if (adb_try_handler_change(id, 5))
  667. printk("ADB keyboard at %d, handler set to 5n", id);
  668. else
  669. #endif
  670. if (adb_try_handler_change(id, 3))
  671. printk("ADB keyboard at %d, handler set to 3n", id);
  672. else
  673. printk("ADB keyboard at %d, handler 1n", id);
  674. }
  675. /* Try to switch all mice to handler 4, or 2 for three-button
  676.    mode and full resolution. */
  677. for (i = 0; i < mouse_ids.nids; i++) {
  678. int id = mouse_ids.id[i];
  679. if (adb_try_handler_change(id, 4)) {
  680. printk("ADB mouse at %d, handler set to 4", id);
  681. adb_mouse_kinds[id] = ADBMOUSE_EXTENDED;
  682. }
  683. else if (adb_try_handler_change(id, 0x2F)) {
  684. printk("ADB mouse at %d, handler set to 0x2F", id);
  685. adb_mouse_kinds[id] = ADBMOUSE_MICROSPEED;
  686. }
  687. else if (adb_try_handler_change(id, 0x42)) {
  688. printk("ADB mouse at %d, handler set to 0x42", id);
  689. adb_mouse_kinds[id] = ADBMOUSE_TRACKBALLPRO;
  690. }
  691. else if (adb_try_handler_change(id, 0x66)) {
  692. printk("ADB mouse at %d, handler set to 0x66", id);
  693. adb_mouse_kinds[id] = ADBMOUSE_MICROSPEED;
  694. }
  695. else if (adb_try_handler_change(id, 0x5F)) {
  696. printk("ADB mouse at %d, handler set to 0x5F", id);
  697. adb_mouse_kinds[id] = ADBMOUSE_MICROSPEED;
  698. }
  699. else if (adb_try_handler_change(id, 3)) {
  700. printk("ADB mouse at %d, handler set to 3", id);
  701. adb_mouse_kinds[id] = ADBMOUSE_MS_A3;
  702. }
  703. else if (adb_try_handler_change(id, 2)) {
  704. printk("ADB mouse at %d, handler set to 2", id);
  705. adb_mouse_kinds[id] = ADBMOUSE_STANDARD_200;
  706. }
  707. else {
  708. printk("ADB mouse at %d, handler 1", id);
  709. adb_mouse_kinds[id] = ADBMOUSE_STANDARD_100;
  710. }
  711. if ((adb_mouse_kinds[id] == ADBMOUSE_TRACKBALLPRO)
  712.     || (adb_mouse_kinds[id] == ADBMOUSE_MICROSPEED)) {
  713. init_microspeed(id);
  714. } else if (adb_mouse_kinds[id] == ADBMOUSE_MS_A3) {
  715. init_ms_a3(id);
  716. }  else if (adb_mouse_kinds[id] ==  ADBMOUSE_EXTENDED) {
  717. /*
  718.  * Register 1 is usually used for device
  719.  * identification.  Here, we try to identify
  720.  * a known device and call the appropriate
  721.  * init function.
  722.  */
  723. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  724.     ADB_READREG(id, 1));
  725. if ((req.reply_len) &&
  726.     (req.reply[1] == 0x9a) && ((req.reply[2] == 0x21)
  727. || (req.reply[2] == 0x20)))
  728. init_trackball(id);
  729. else if ((req.reply_len >= 4) &&
  730.     (req.reply[1] == 0x74) && (req.reply[2] == 0x70) &&
  731.     (req.reply[3] == 0x61) && (req.reply[4] == 0x64))
  732. init_trackpad(id);
  733. else if ((req.reply_len >= 4) &&
  734.     (req.reply[1] == 0x4b) && (req.reply[2] == 0x4d) &&
  735.     (req.reply[3] == 0x4c) && (req.reply[4] == 0x31))
  736. init_turbomouse(id);
  737. else if ((req.reply_len == 9) &&
  738.     (req.reply[1] == 0x4b) && (req.reply[2] == 0x4f) &&
  739.     (req.reply[3] == 0x49) && (req.reply[4] == 0x54)){
  740. if (adb_try_handler_change(id, 0x42)) {
  741. printk("nADB MacAlly 2-button mouse at %d, handler set to 0x42", id);
  742. adb_mouse_kinds[id] = ADBMOUSE_MACALLY2;
  743. }
  744. }
  745. }
  746. printk("n");
  747.         }
  748. }
  749. static void
  750. init_trackpad(int id)
  751. {
  752. struct adb_request req;
  753. unsigned char r1_buffer[8];
  754. printk(" (trackpad)");
  755. adb_mouse_kinds[id] = ADBMOUSE_TRACKPAD;
  756. adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
  757. ADB_READREG(id,1));
  758. if (req.reply_len < 8)
  759.     printk("bad length for reg. 1n");
  760. else
  761. {
  762.     memcpy(r1_buffer, &req.reply[1], 8);
  763.     adb_request(&req, NULL, ADBREQ_SYNC, 9,
  764.         ADB_WRITEREG(id,1),
  765.             r1_buffer[0],
  766.             r1_buffer[1],
  767.             r1_buffer[2],
  768.             r1_buffer[3],
  769.             r1_buffer[4],
  770.             r1_buffer[5],
  771.             0x0d, /*r1_buffer[6],*/
  772.             r1_buffer[7]);
  773.             adb_request(&req, NULL, ADBREQ_SYNC, 9,
  774.         ADB_WRITEREG(id,2),
  775.     0x99,
  776.     0x94,
  777.     0x19,
  778.     0xff,
  779.     0xb2,
  780.     0x8a,
  781.     0x1b,
  782.     0x50);
  783.     adb_request(&req, NULL, ADBREQ_SYNC, 9,
  784.         ADB_WRITEREG(id,1),
  785.             r1_buffer[0],
  786.             r1_buffer[1],
  787.             r1_buffer[2],
  788.             r1_buffer[3],
  789.             r1_buffer[4],
  790.             r1_buffer[5],
  791.             0x03, /*r1_buffer[6],*/
  792.             r1_buffer[7]);
  793.     /* Without this flush, the trackpad may be locked up */     
  794.     adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  795.         }
  796. }
  797. static void
  798. init_trackball(int id)
  799. {
  800. struct adb_request req;
  801. printk(" (trackman/mouseman)");
  802. adb_mouse_kinds[id] = ADBMOUSE_TRACKBALL;
  803. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  804. ADB_WRITEREG(id,1), 00,0x81);
  805. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  806. ADB_WRITEREG(id,1), 01,0x81);
  807. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  808. ADB_WRITEREG(id,1), 02,0x81);
  809. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  810. ADB_WRITEREG(id,1), 03,0x38);
  811. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  812. ADB_WRITEREG(id,1), 00,0x81);
  813. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  814. ADB_WRITEREG(id,1), 01,0x81);
  815. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  816. ADB_WRITEREG(id,1), 02,0x81);
  817. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  818. ADB_WRITEREG(id,1), 03,0x38);
  819. }
  820. static void
  821. init_turbomouse(int id)
  822. {
  823. struct adb_request req;
  824.         printk(" (TurboMouse 5)");
  825. adb_mouse_kinds[id] = ADBMOUSE_TURBOMOUSE5;
  826. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  827. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  828. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  829. ADB_WRITEREG(3,2),
  830.     0xe7,
  831.     0x8c,
  832.     0,
  833.     0,
  834.     0,
  835.     0xff,
  836.     0xff,
  837.     0x94);
  838. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(3));
  839. adb_request(&req, NULL, ADBREQ_SYNC, 9,
  840. ADB_WRITEREG(3,2),
  841.     0xa5,
  842.     0x14,
  843.     0,
  844.     0,
  845.     0x69,
  846.     0xff,
  847.     0xff,
  848.     0x27);
  849. }
  850. static void
  851. init_microspeed(int id)
  852. {
  853. struct adb_request req;
  854.         printk(" (Microspeed/MacPoint or compatible)");
  855. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  856. /* This will initialize mice using the Microspeed, MacPoint and
  857.    other compatible firmware. Bit 12 enables extended protocol.
  858.    Register 1 Listen (4 Bytes)
  859.             0 -  3     Button is mouse (set also for double clicking!!!)
  860.             4 -  7     Button is locking (affects change speed also)
  861.             8 - 11     Button changes speed
  862.            12          1 = Extended mouse mode, 0 = normal mouse mode
  863.            13 - 15     unused 0
  864.            16 - 23     normal speed
  865.            24 - 31     changed speed
  866.        Register 1 talk holds version and product identification information.
  867.        Register 1 Talk (4 Bytes):
  868.             0 -  7     Product code
  869.             8 - 23     undefined, reserved
  870.            24 - 31     Version number
  871.        Speed 0 is max. 1 to 255 set speed in increments of 1/256 of max.
  872.  */
  873. adb_request(&req, NULL, ADBREQ_SYNC, 5,
  874. ADB_WRITEREG(id,1),
  875.     0x20, /* alt speed = 0x20 (rather slow) */
  876.     0x00, /* norm speed = 0x00 (fastest) */
  877.     0x10, /* extended protocol, no speed change */
  878.     0x07); /* all buttons enabled as mouse buttons, no locking */
  879. adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  880. }
  881. static void
  882. init_ms_a3(int id)
  883. {
  884. struct adb_request req;
  885. printk(" (Mouse Systems A3 Mouse, or compatible)");
  886. adb_request(&req, NULL, ADBREQ_SYNC, 3,
  887. ADB_WRITEREG(id, 0x2),
  888.     0x00,
  889.     0x07);
  890.   adb_request(&req, NULL, ADBREQ_SYNC, 1, ADB_FLUSH(id));
  891.  }