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