Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PS/2 mouse driver |
| 3 | * |
| 4 | * Copyright (c) 1999-2002 Vojtech Pavlik |
| 5 | * Copyright (c) 2003-2004 Dmitry Torokhov |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as published by |
| 11 | * the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/input.h> |
| 20 | #include <linux/serio.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/libps2.h> |
| 23 | #include "psmouse.h" |
| 24 | #include "synaptics.h" |
| 25 | #include "logips2pp.h" |
| 26 | #include "alps.h" |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 27 | #include "lifebook.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #define DRIVER_DESC "PS/2 mouse driver" |
| 30 | |
| 31 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); |
| 32 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 33 | MODULE_LICENSE("GPL"); |
| 34 | |
| 35 | static unsigned int psmouse_max_proto = -1U; |
| 36 | static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); |
| 37 | static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 38 | static char *psmouse_proto_abbrev[] = { NULL, "bare", NULL, NULL, NULL, "imps", "exps", NULL, NULL, "lifebook" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) |
| 40 | #define param_set_proto_abbrev psmouse_set_maxproto |
| 41 | #define param_get_proto_abbrev psmouse_get_maxproto |
| 42 | module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644); |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 43 | MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, lifebook, any). Useful for KVM switches."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | static unsigned int psmouse_resolution = 200; |
| 46 | module_param_named(resolution, psmouse_resolution, uint, 0644); |
| 47 | MODULE_PARM_DESC(resolution, "Resolution, in dpi."); |
| 48 | |
| 49 | static unsigned int psmouse_rate = 100; |
| 50 | module_param_named(rate, psmouse_rate, uint, 0644); |
| 51 | MODULE_PARM_DESC(rate, "Report rate, in reports per second."); |
| 52 | |
| 53 | static unsigned int psmouse_smartscroll = 1; |
| 54 | module_param_named(smartscroll, psmouse_smartscroll, bool, 0644); |
| 55 | MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled."); |
| 56 | |
| 57 | static unsigned int psmouse_resetafter; |
| 58 | module_param_named(resetafter, psmouse_resetafter, uint, 0644); |
| 59 | MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); |
| 60 | |
| 61 | PSMOUSE_DEFINE_ATTR(rate); |
| 62 | PSMOUSE_DEFINE_ATTR(resolution); |
| 63 | PSMOUSE_DEFINE_ATTR(resetafter); |
| 64 | |
| 65 | __obsolete_setup("psmouse_noext"); |
| 66 | __obsolete_setup("psmouse_resolution="); |
| 67 | __obsolete_setup("psmouse_smartscroll="); |
| 68 | __obsolete_setup("psmouse_resetafter="); |
| 69 | __obsolete_setup("psmouse_rate="); |
| 70 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 71 | /* |
| 72 | * psmouse_sem protects all operations changing state of mouse |
| 73 | * (connecting, disconnecting, changing rate or resolution via |
| 74 | * sysfs). We could use a per-device semaphore but since there |
| 75 | * rarely more than one PS/2 mouse connected and since semaphore |
| 76 | * is taken in "slow" paths it is not worth it. |
| 77 | */ |
| 78 | static DECLARE_MUTEX(psmouse_sem); |
| 79 | |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 80 | static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2", "LBPS/2" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * psmouse_process_byte() analyzes the PS/2 data stream and reports |
| 84 | * relevant events to the input module once full packet has arrived. |
| 85 | */ |
| 86 | |
| 87 | static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_regs *regs) |
| 88 | { |
| 89 | struct input_dev *dev = &psmouse->dev; |
| 90 | unsigned char *packet = psmouse->packet; |
| 91 | |
| 92 | if (psmouse->pktcnt < psmouse->pktsize) |
| 93 | return PSMOUSE_GOOD_DATA; |
| 94 | |
| 95 | /* |
| 96 | * Full packet accumulated, process it |
| 97 | */ |
| 98 | |
| 99 | input_regs(dev, regs); |
| 100 | |
| 101 | /* |
| 102 | * Scroll wheel on IntelliMice, scroll buttons on NetMice |
| 103 | */ |
| 104 | |
| 105 | if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS) |
| 106 | input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); |
| 107 | |
| 108 | /* |
| 109 | * Scroll wheel and buttons on IntelliMouse Explorer |
| 110 | */ |
| 111 | |
| 112 | if (psmouse->type == PSMOUSE_IMEX) { |
| 113 | input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7)); |
| 114 | input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1); |
| 115 | input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * Extra buttons on Genius NewNet 3D |
| 120 | */ |
| 121 | |
| 122 | if (psmouse->type == PSMOUSE_GENPS) { |
| 123 | input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); |
| 124 | input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Extra button on ThinkingMouse |
| 129 | */ |
| 130 | if (psmouse->type == PSMOUSE_THINKPS) { |
| 131 | input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); |
| 132 | /* Without this bit of weirdness moving up gives wildly high Y changes. */ |
| 133 | packet[1] |= (packet[0] & 0x40) << 1; |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Generic PS/2 Mouse |
| 138 | */ |
| 139 | |
| 140 | input_report_key(dev, BTN_LEFT, packet[0] & 1); |
| 141 | input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); |
| 142 | input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); |
| 143 | |
| 144 | input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); |
| 145 | input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); |
| 146 | |
| 147 | input_sync(dev); |
| 148 | |
| 149 | return PSMOUSE_FULL_PACKET; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * psmouse_interrupt() handles incoming characters, either gathering them into |
| 154 | * packets or passing them to the command routine as command output. |
| 155 | */ |
| 156 | |
| 157 | static irqreturn_t psmouse_interrupt(struct serio *serio, |
| 158 | unsigned char data, unsigned int flags, struct pt_regs *regs) |
| 159 | { |
| 160 | struct psmouse *psmouse = serio_get_drvdata(serio); |
| 161 | psmouse_ret_t rc; |
| 162 | |
| 163 | if (psmouse->state == PSMOUSE_IGNORE) |
| 164 | goto out; |
| 165 | |
| 166 | if (flags & (SERIO_PARITY|SERIO_TIMEOUT)) { |
| 167 | if (psmouse->state == PSMOUSE_ACTIVATED) |
| 168 | printk(KERN_WARNING "psmouse.c: bad data from KBC -%s%s\n", |
| 169 | flags & SERIO_TIMEOUT ? " timeout" : "", |
| 170 | flags & SERIO_PARITY ? " bad parity" : ""); |
| 171 | ps2_cmd_aborted(&psmouse->ps2dev); |
| 172 | goto out; |
| 173 | } |
| 174 | |
| 175 | if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK)) |
| 176 | if (ps2_handle_ack(&psmouse->ps2dev, data)) |
| 177 | goto out; |
| 178 | |
| 179 | if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_CMD)) |
| 180 | if (ps2_handle_response(&psmouse->ps2dev, data)) |
| 181 | goto out; |
| 182 | |
| 183 | if (psmouse->state == PSMOUSE_INITIALIZING) |
| 184 | goto out; |
| 185 | |
| 186 | if (psmouse->state == PSMOUSE_ACTIVATED && |
| 187 | psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) { |
| 188 | printk(KERN_WARNING "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n", |
| 189 | psmouse->name, psmouse->phys, psmouse->pktcnt); |
| 190 | psmouse->pktcnt = 0; |
| 191 | } |
| 192 | |
| 193 | psmouse->last = jiffies; |
| 194 | psmouse->packet[psmouse->pktcnt++] = data; |
| 195 | |
| 196 | if (psmouse->packet[0] == PSMOUSE_RET_BAT) { |
| 197 | if (psmouse->pktcnt == 1) |
| 198 | goto out; |
| 199 | |
| 200 | if (psmouse->pktcnt == 2) { |
| 201 | if (psmouse->packet[1] == PSMOUSE_RET_ID) { |
| 202 | psmouse->state = PSMOUSE_IGNORE; |
| 203 | serio_reconnect(serio); |
| 204 | goto out; |
| 205 | } |
| 206 | if (psmouse->type == PSMOUSE_SYNAPTICS) { |
| 207 | /* neither 0xAA nor 0x00 are valid first bytes |
| 208 | * for a packet in absolute mode |
| 209 | */ |
| 210 | psmouse->pktcnt = 0; |
| 211 | goto out; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | rc = psmouse->protocol_handler(psmouse, regs); |
| 217 | |
| 218 | switch (rc) { |
| 219 | case PSMOUSE_BAD_DATA: |
| 220 | printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n", |
| 221 | psmouse->name, psmouse->phys, psmouse->pktcnt); |
| 222 | psmouse->pktcnt = 0; |
| 223 | |
| 224 | if (++psmouse->out_of_sync == psmouse->resetafter) { |
| 225 | psmouse->state = PSMOUSE_IGNORE; |
| 226 | printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n"); |
| 227 | serio_reconnect(psmouse->ps2dev.serio); |
| 228 | } |
| 229 | break; |
| 230 | |
| 231 | case PSMOUSE_FULL_PACKET: |
| 232 | psmouse->pktcnt = 0; |
| 233 | if (psmouse->out_of_sync) { |
| 234 | psmouse->out_of_sync = 0; |
| 235 | printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n", |
| 236 | psmouse->name, psmouse->phys); |
| 237 | } |
| 238 | break; |
| 239 | |
| 240 | case PSMOUSE_GOOD_DATA: |
| 241 | break; |
| 242 | } |
| 243 | out: |
| 244 | return IRQ_HANDLED; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | /* |
| 249 | * psmouse_sliced_command() sends an extended PS/2 command to the mouse |
| 250 | * using sliced syntax, understood by advanced devices, such as Logitech |
| 251 | * or Synaptics touchpads. The command is encoded as: |
| 252 | * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu |
| 253 | * is the command. |
| 254 | */ |
| 255 | int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command) |
| 256 | { |
| 257 | int i; |
| 258 | |
| 259 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) |
| 260 | return -1; |
| 261 | |
| 262 | for (i = 6; i >= 0; i -= 2) { |
| 263 | unsigned char d = (command >> i) & 3; |
| 264 | if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES)) |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | |
| 272 | /* |
| 273 | * psmouse_reset() resets the mouse into power-on state. |
| 274 | */ |
| 275 | int psmouse_reset(struct psmouse *psmouse) |
| 276 | { |
| 277 | unsigned char param[2]; |
| 278 | |
| 279 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT)) |
| 280 | return -1; |
| 281 | |
| 282 | if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID) |
| 283 | return -1; |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /* |
| 290 | * Genius NetMouse magic init. |
| 291 | */ |
| 292 | static int genius_detect(struct psmouse *psmouse, int set_properties) |
| 293 | { |
| 294 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 295 | unsigned char param[4]; |
| 296 | |
| 297 | param[0] = 3; |
| 298 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 299 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 300 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 301 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 302 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); |
| 303 | |
| 304 | if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55) |
| 305 | return -1; |
| 306 | |
| 307 | if (set_properties) { |
| 308 | set_bit(BTN_EXTRA, psmouse->dev.keybit); |
| 309 | set_bit(BTN_SIDE, psmouse->dev.keybit); |
| 310 | set_bit(REL_WHEEL, psmouse->dev.relbit); |
| 311 | |
| 312 | psmouse->vendor = "Genius"; |
| 313 | psmouse->name = "Wheel Mouse"; |
| 314 | psmouse->pktsize = 4; |
| 315 | } |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * IntelliMouse magic init. |
| 322 | */ |
| 323 | static int intellimouse_detect(struct psmouse *psmouse, int set_properties) |
| 324 | { |
| 325 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 326 | unsigned char param[2]; |
| 327 | |
| 328 | param[0] = 200; |
| 329 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 330 | param[0] = 100; |
| 331 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 332 | param[0] = 80; |
| 333 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 334 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); |
| 335 | |
| 336 | if (param[0] != 3) |
| 337 | return -1; |
| 338 | |
| 339 | if (set_properties) { |
| 340 | set_bit(REL_WHEEL, psmouse->dev.relbit); |
| 341 | |
| 342 | if (!psmouse->vendor) psmouse->vendor = "Generic"; |
| 343 | if (!psmouse->name) psmouse->name = "Wheel Mouse"; |
| 344 | psmouse->pktsize = 4; |
| 345 | } |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Try IntelliMouse/Explorer magic init. |
| 352 | */ |
| 353 | static int im_explorer_detect(struct psmouse *psmouse, int set_properties) |
| 354 | { |
| 355 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 356 | unsigned char param[2]; |
| 357 | |
| 358 | intellimouse_detect(psmouse, 0); |
| 359 | |
| 360 | param[0] = 200; |
| 361 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 362 | param[0] = 200; |
| 363 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 364 | param[0] = 80; |
| 365 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 366 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); |
| 367 | |
| 368 | if (param[0] != 4) |
| 369 | return -1; |
| 370 | |
| 371 | if (set_properties) { |
| 372 | set_bit(REL_WHEEL, psmouse->dev.relbit); |
| 373 | set_bit(BTN_SIDE, psmouse->dev.keybit); |
| 374 | set_bit(BTN_EXTRA, psmouse->dev.keybit); |
| 375 | |
| 376 | if (!psmouse->vendor) psmouse->vendor = "Generic"; |
| 377 | if (!psmouse->name) psmouse->name = "Explorer Mouse"; |
| 378 | psmouse->pktsize = 4; |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Kensington ThinkingMouse / ExpertMouse magic init. |
| 386 | */ |
| 387 | static int thinking_detect(struct psmouse *psmouse, int set_properties) |
| 388 | { |
| 389 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 390 | unsigned char param[2]; |
| 391 | unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20, 0 }; |
| 392 | int i; |
| 393 | |
| 394 | param[0] = 10; |
| 395 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 396 | param[0] = 0; |
| 397 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 398 | for (i = 0; seq[i]; i++) |
| 399 | ps2_command(ps2dev, seq + i, PSMOUSE_CMD_SETRATE); |
| 400 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); |
| 401 | |
| 402 | if (param[0] != 2) |
| 403 | return -1; |
| 404 | |
| 405 | if (set_properties) { |
| 406 | set_bit(BTN_EXTRA, psmouse->dev.keybit); |
| 407 | |
| 408 | psmouse->vendor = "Kensington"; |
| 409 | psmouse->name = "ThinkingMouse"; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * Bare PS/2 protocol "detection". Always succeeds. |
| 417 | */ |
| 418 | static int ps2bare_detect(struct psmouse *psmouse, int set_properties) |
| 419 | { |
| 420 | if (!psmouse->vendor) psmouse->vendor = "Generic"; |
| 421 | if (!psmouse->name) psmouse->name = "Mouse"; |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * psmouse_extensions() probes for any extensions to the basic PS/2 protocol |
| 428 | * the mouse may have. |
| 429 | */ |
| 430 | |
| 431 | static int psmouse_extensions(struct psmouse *psmouse, |
| 432 | unsigned int max_proto, int set_properties) |
| 433 | { |
| 434 | int synaptics_hardware = 0; |
| 435 | |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 436 | /* |
| 437 | * We always check for lifebook because it does not disturb mouse |
| 438 | * (it only checks DMI information). |
| 439 | */ |
| 440 | if (lifebook_detect(psmouse, set_properties) == 0 || |
| 441 | max_proto == PSMOUSE_LIFEBOOK) { |
| 442 | |
| 443 | if (max_proto > PSMOUSE_IMEX) { |
| 444 | if (!set_properties || lifebook_init(psmouse) == 0) |
| 445 | return PSMOUSE_LIFEBOOK; |
| 446 | } |
| 447 | } |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* |
| 450 | * Try Kensington ThinkingMouse (we try first, because synaptics probe |
| 451 | * upsets the thinkingmouse). |
| 452 | */ |
| 453 | |
| 454 | if (max_proto > PSMOUSE_IMEX && thinking_detect(psmouse, set_properties) == 0) |
| 455 | return PSMOUSE_THINKPS; |
| 456 | |
| 457 | /* |
| 458 | * Try Synaptics TouchPad |
| 459 | */ |
| 460 | if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) { |
| 461 | synaptics_hardware = 1; |
| 462 | |
| 463 | if (max_proto > PSMOUSE_IMEX) { |
| 464 | if (!set_properties || synaptics_init(psmouse) == 0) |
| 465 | return PSMOUSE_SYNAPTICS; |
| 466 | /* |
| 467 | * Some Synaptics touchpads can emulate extended protocols (like IMPS/2). |
| 468 | * Unfortunately Logitech/Genius probes confuse some firmware versions so |
| 469 | * we'll have to skip them. |
| 470 | */ |
| 471 | max_proto = PSMOUSE_IMEX; |
| 472 | } |
| 473 | /* |
| 474 | * Make sure that touchpad is in relative mode, gestures (taps) are enabled |
| 475 | */ |
| 476 | synaptics_reset(psmouse); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Try ALPS TouchPad |
| 481 | */ |
| 482 | if (max_proto > PSMOUSE_IMEX) { |
| 483 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); |
| 484 | if (alps_detect(psmouse, set_properties) == 0) { |
| 485 | if (!set_properties || alps_init(psmouse) == 0) |
| 486 | return PSMOUSE_ALPS; |
| 487 | /* |
| 488 | * Init failed, try basic relative protocols |
| 489 | */ |
| 490 | max_proto = PSMOUSE_IMEX; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse, set_properties) == 0) |
| 495 | return PSMOUSE_GENPS; |
| 496 | |
| 497 | if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties) == 0) |
| 498 | return PSMOUSE_PS2PP; |
| 499 | |
| 500 | /* |
| 501 | * Reset to defaults in case the device got confused by extended |
| 502 | * protocol probes. |
| 503 | */ |
| 504 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); |
| 505 | |
| 506 | if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0) |
| 507 | return PSMOUSE_IMEX; |
| 508 | |
| 509 | if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0) |
| 510 | return PSMOUSE_IMPS; |
| 511 | |
| 512 | /* |
| 513 | * Okay, all failed, we have a standard mouse here. The number of the buttons |
| 514 | * is still a question, though. We assume 3. |
| 515 | */ |
| 516 | ps2bare_detect(psmouse, set_properties); |
| 517 | |
| 518 | if (synaptics_hardware) { |
| 519 | /* |
| 520 | * We detected Synaptics hardware but it did not respond to IMPS/2 probes. |
| 521 | * We need to reset the touchpad because if there is a track point on the |
| 522 | * pass through port it could get disabled while probing for protocol |
| 523 | * extensions. |
| 524 | */ |
| 525 | psmouse_reset(psmouse); |
| 526 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); |
| 527 | } |
| 528 | |
| 529 | return PSMOUSE_PS2; |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | * psmouse_probe() probes for a PS/2 mouse. |
| 534 | */ |
| 535 | |
| 536 | static int psmouse_probe(struct psmouse *psmouse) |
| 537 | { |
| 538 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 539 | unsigned char param[2]; |
| 540 | |
| 541 | /* |
| 542 | * First, we check if it's a mouse. It should send 0x00 or 0x03 |
| 543 | * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer. |
Vojtech Pavlik | 7741e93 | 2005-05-28 02:11:42 -0500 | [diff] [blame] | 544 | * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent |
| 545 | * ID queries, probably due to a firmware bug. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | */ |
| 547 | |
| 548 | param[0] = 0xa5; |
| 549 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) |
| 550 | return -1; |
| 551 | |
Vojtech Pavlik | 7741e93 | 2005-05-28 02:11:42 -0500 | [diff] [blame] | 552 | if (param[0] != 0x00 && param[0] != 0x03 && |
| 553 | param[0] != 0x04 && param[0] != 0xff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | return -1; |
| 555 | |
| 556 | /* |
| 557 | * Then we reset and disable the mouse so that it doesn't generate events. |
| 558 | */ |
| 559 | |
| 560 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS)) |
| 561 | printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", ps2dev->serio->phys); |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | /* |
| 567 | * Here we set the mouse resolution. |
| 568 | */ |
| 569 | |
| 570 | void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution) |
| 571 | { |
| 572 | unsigned char params[] = { 0, 1, 2, 2, 3 }; |
| 573 | |
| 574 | if (resolution == 0 || resolution > 200) |
| 575 | resolution = 200; |
| 576 | |
| 577 | ps2_command(&psmouse->ps2dev, ¶ms[resolution / 50], PSMOUSE_CMD_SETRES); |
| 578 | psmouse->resolution = 25 << params[resolution / 50]; |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * Here we set the mouse report rate. |
| 583 | */ |
| 584 | |
| 585 | static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate) |
| 586 | { |
| 587 | unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; |
| 588 | int i = 0; |
| 589 | |
| 590 | while (rates[i] > rate) i++; |
| 591 | ps2_command(&psmouse->ps2dev, &rates[i], PSMOUSE_CMD_SETRATE); |
| 592 | psmouse->rate = rates[i]; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * psmouse_initialize() initializes the mouse to a sane state. |
| 597 | */ |
| 598 | |
| 599 | static void psmouse_initialize(struct psmouse *psmouse) |
| 600 | { |
| 601 | /* |
| 602 | * We set the mouse into streaming mode. |
| 603 | */ |
| 604 | |
| 605 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM); |
| 606 | |
| 607 | /* |
| 608 | * We set the mouse report rate, resolution and scaling. |
| 609 | */ |
| 610 | |
| 611 | if (psmouse_max_proto != PSMOUSE_PS2) { |
| 612 | psmouse->set_rate(psmouse, psmouse->rate); |
| 613 | psmouse->set_resolution(psmouse, psmouse->resolution); |
| 614 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * psmouse_set_state() sets new psmouse state and resets all flags and |
| 620 | * counters while holding serio lock so fighting with interrupt handler |
| 621 | * is not a concern. |
| 622 | */ |
| 623 | |
| 624 | static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) |
| 625 | { |
| 626 | serio_pause_rx(psmouse->ps2dev.serio); |
| 627 | psmouse->state = new_state; |
| 628 | psmouse->pktcnt = psmouse->out_of_sync = 0; |
| 629 | psmouse->ps2dev.flags = 0; |
| 630 | serio_continue_rx(psmouse->ps2dev.serio); |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | * psmouse_activate() enables the mouse so that we get motion reports from it. |
| 635 | */ |
| 636 | |
| 637 | static void psmouse_activate(struct psmouse *psmouse) |
| 638 | { |
| 639 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) |
| 640 | printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n", |
| 641 | psmouse->ps2dev.serio->phys); |
| 642 | |
| 643 | psmouse_set_state(psmouse, PSMOUSE_ACTIVATED); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | /* |
| 648 | * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion |
| 649 | * reports from it unless we explicitely request it. |
| 650 | */ |
| 651 | |
| 652 | static void psmouse_deactivate(struct psmouse *psmouse) |
| 653 | { |
| 654 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 655 | printk(KERN_WARNING "psmouse.c: Failed to deactivate mouse on %s\n", |
| 656 | psmouse->ps2dev.serio->phys); |
| 657 | |
| 658 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 659 | } |
| 660 | |
| 661 | |
| 662 | /* |
| 663 | * psmouse_cleanup() resets the mouse into power-on state. |
| 664 | */ |
| 665 | |
| 666 | static void psmouse_cleanup(struct serio *serio) |
| 667 | { |
| 668 | struct psmouse *psmouse = serio_get_drvdata(serio); |
| 669 | |
| 670 | psmouse_reset(psmouse); |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * psmouse_disconnect() closes and frees. |
| 675 | */ |
| 676 | |
| 677 | static void psmouse_disconnect(struct serio *serio) |
| 678 | { |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 679 | struct psmouse *psmouse, *parent = NULL; |
| 680 | |
| 681 | psmouse = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | device_remove_file(&serio->dev, &psmouse_attr_rate); |
| 684 | device_remove_file(&serio->dev, &psmouse_attr_resolution); |
| 685 | device_remove_file(&serio->dev, &psmouse_attr_resetafter); |
| 686 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 687 | down(&psmouse_sem); |
| 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 690 | |
| 691 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 692 | parent = serio_get_drvdata(serio->parent); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 693 | psmouse_deactivate(parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | if (psmouse->disconnect) |
| 697 | psmouse->disconnect(psmouse); |
| 698 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 699 | if (parent && parent->pt_deactivate) |
| 700 | parent->pt_deactivate(parent); |
| 701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 703 | |
| 704 | input_unregister_device(&psmouse->dev); |
| 705 | serio_close(serio); |
| 706 | serio_set_drvdata(serio, NULL); |
| 707 | kfree(psmouse); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 708 | |
| 709 | if (parent) |
| 710 | psmouse_activate(parent); |
| 711 | |
| 712 | up(&psmouse_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /* |
| 716 | * psmouse_connect() is a callback from the serio module when |
| 717 | * an unhandled serio port is found. |
| 718 | */ |
| 719 | static int psmouse_connect(struct serio *serio, struct serio_driver *drv) |
| 720 | { |
| 721 | struct psmouse *psmouse, *parent = NULL; |
| 722 | int retval; |
| 723 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 724 | down(&psmouse_sem); |
| 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | /* |
| 727 | * If this is a pass-through port deactivate parent so the device |
| 728 | * connected to this port can be successfully identified |
| 729 | */ |
| 730 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 731 | parent = serio_get_drvdata(serio->parent); |
| 732 | psmouse_deactivate(parent); |
| 733 | } |
| 734 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 735 | if (!(psmouse = kcalloc(1, sizeof(struct psmouse), GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | retval = -ENOMEM; |
| 737 | goto out; |
| 738 | } |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | ps2_init(&psmouse->ps2dev, serio); |
| 741 | sprintf(psmouse->phys, "%s/input0", serio->phys); |
| 742 | psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); |
| 743 | psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); |
| 744 | psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); |
| 745 | psmouse->dev.private = psmouse; |
| 746 | psmouse->dev.dev = &serio->dev; |
| 747 | psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); |
| 748 | |
| 749 | serio_set_drvdata(serio, psmouse); |
| 750 | |
| 751 | retval = serio_open(serio, drv); |
| 752 | if (retval) { |
| 753 | serio_set_drvdata(serio, NULL); |
| 754 | kfree(psmouse); |
| 755 | goto out; |
| 756 | } |
| 757 | |
| 758 | if (psmouse_probe(psmouse) < 0) { |
| 759 | serio_close(serio); |
| 760 | serio_set_drvdata(serio, NULL); |
| 761 | kfree(psmouse); |
| 762 | retval = -ENODEV; |
| 763 | goto out; |
| 764 | } |
| 765 | |
| 766 | psmouse->rate = psmouse_rate; |
| 767 | psmouse->resolution = psmouse_resolution; |
| 768 | psmouse->resetafter = psmouse_resetafter; |
| 769 | psmouse->smartscroll = psmouse_smartscroll; |
| 770 | psmouse->set_rate = psmouse_set_rate; |
| 771 | psmouse->set_resolution = psmouse_set_resolution; |
| 772 | psmouse->protocol_handler = psmouse_process_byte; |
| 773 | psmouse->pktsize = 3; |
| 774 | |
| 775 | psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1); |
| 776 | |
| 777 | sprintf(psmouse->devname, "%s %s %s", |
| 778 | psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name); |
| 779 | |
| 780 | psmouse->dev.name = psmouse->devname; |
| 781 | psmouse->dev.phys = psmouse->phys; |
| 782 | psmouse->dev.id.bustype = BUS_I8042; |
| 783 | psmouse->dev.id.vendor = 0x0002; |
| 784 | psmouse->dev.id.product = psmouse->type; |
| 785 | psmouse->dev.id.version = psmouse->model; |
| 786 | |
| 787 | input_register_device(&psmouse->dev); |
| 788 | |
| 789 | printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys); |
| 790 | |
| 791 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 792 | |
| 793 | psmouse_initialize(psmouse); |
| 794 | |
| 795 | if (parent && parent->pt_activate) |
| 796 | parent->pt_activate(parent); |
| 797 | |
| 798 | device_create_file(&serio->dev, &psmouse_attr_rate); |
| 799 | device_create_file(&serio->dev, &psmouse_attr_resolution); |
| 800 | device_create_file(&serio->dev, &psmouse_attr_resetafter); |
| 801 | |
| 802 | psmouse_activate(psmouse); |
| 803 | |
| 804 | retval = 0; |
| 805 | |
| 806 | out: |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 807 | /* If this is a pass-through port the parent needs to be re-activated */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (parent) |
| 809 | psmouse_activate(parent); |
| 810 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 811 | up(&psmouse_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | return retval; |
| 813 | } |
| 814 | |
| 815 | |
| 816 | static int psmouse_reconnect(struct serio *serio) |
| 817 | { |
| 818 | struct psmouse *psmouse = serio_get_drvdata(serio); |
| 819 | struct psmouse *parent = NULL; |
| 820 | struct serio_driver *drv = serio->drv; |
| 821 | int rc = -1; |
| 822 | |
| 823 | if (!drv || !psmouse) { |
| 824 | printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n"); |
| 825 | return -1; |
| 826 | } |
| 827 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 828 | down(&psmouse_sem); |
| 829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 831 | parent = serio_get_drvdata(serio->parent); |
| 832 | psmouse_deactivate(parent); |
| 833 | } |
| 834 | |
| 835 | psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); |
| 836 | |
| 837 | if (psmouse->reconnect) { |
| 838 | if (psmouse->reconnect(psmouse)) |
| 839 | goto out; |
| 840 | } else if (psmouse_probe(psmouse) < 0 || |
| 841 | psmouse->type != psmouse_extensions(psmouse, psmouse_max_proto, 0)) |
| 842 | goto out; |
| 843 | |
| 844 | /* ok, the device type (and capabilities) match the old one, |
| 845 | * we can continue using it, complete intialization |
| 846 | */ |
| 847 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 848 | |
| 849 | psmouse_initialize(psmouse); |
| 850 | |
| 851 | if (parent && parent->pt_activate) |
| 852 | parent->pt_activate(parent); |
| 853 | |
| 854 | psmouse_activate(psmouse); |
| 855 | rc = 0; |
| 856 | |
| 857 | out: |
| 858 | /* If this is a pass-through port the parent waits to be activated */ |
| 859 | if (parent) |
| 860 | psmouse_activate(parent); |
| 861 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 862 | up(&psmouse_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | return rc; |
| 864 | } |
| 865 | |
| 866 | static struct serio_device_id psmouse_serio_ids[] = { |
| 867 | { |
| 868 | .type = SERIO_8042, |
| 869 | .proto = SERIO_ANY, |
| 870 | .id = SERIO_ANY, |
| 871 | .extra = SERIO_ANY, |
| 872 | }, |
| 873 | { |
| 874 | .type = SERIO_PS_PSTHRU, |
| 875 | .proto = SERIO_ANY, |
| 876 | .id = SERIO_ANY, |
| 877 | .extra = SERIO_ANY, |
| 878 | }, |
| 879 | { 0 } |
| 880 | }; |
| 881 | |
| 882 | MODULE_DEVICE_TABLE(serio, psmouse_serio_ids); |
| 883 | |
| 884 | static struct serio_driver psmouse_drv = { |
| 885 | .driver = { |
| 886 | .name = "psmouse", |
| 887 | }, |
| 888 | .description = DRIVER_DESC, |
| 889 | .id_table = psmouse_serio_ids, |
| 890 | .interrupt = psmouse_interrupt, |
| 891 | .connect = psmouse_connect, |
| 892 | .reconnect = psmouse_reconnect, |
| 893 | .disconnect = psmouse_disconnect, |
| 894 | .cleanup = psmouse_cleanup, |
| 895 | }; |
| 896 | |
| 897 | ssize_t psmouse_attr_show_helper(struct device *dev, char *buf, |
| 898 | ssize_t (*handler)(struct psmouse *, char *)) |
| 899 | { |
| 900 | struct serio *serio = to_serio_port(dev); |
| 901 | int retval; |
| 902 | |
| 903 | retval = serio_pin_driver(serio); |
| 904 | if (retval) |
| 905 | return retval; |
| 906 | |
| 907 | if (serio->drv != &psmouse_drv) { |
| 908 | retval = -ENODEV; |
| 909 | goto out; |
| 910 | } |
| 911 | |
| 912 | retval = handler(serio_get_drvdata(serio), buf); |
| 913 | |
| 914 | out: |
| 915 | serio_unpin_driver(serio); |
| 916 | return retval; |
| 917 | } |
| 918 | |
| 919 | ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count, |
| 920 | ssize_t (*handler)(struct psmouse *, const char *, size_t)) |
| 921 | { |
| 922 | struct serio *serio = to_serio_port(dev); |
| 923 | struct psmouse *psmouse = serio_get_drvdata(serio); |
| 924 | struct psmouse *parent = NULL; |
| 925 | int retval; |
| 926 | |
| 927 | retval = serio_pin_driver(serio); |
| 928 | if (retval) |
| 929 | return retval; |
| 930 | |
| 931 | if (serio->drv != &psmouse_drv) { |
| 932 | retval = -ENODEV; |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 933 | goto out_unpin; |
| 934 | } |
| 935 | |
| 936 | retval = down_interruptible(&psmouse_sem); |
| 937 | if (retval) |
| 938 | goto out_unpin; |
| 939 | |
| 940 | if (psmouse->state == PSMOUSE_IGNORE) { |
| 941 | retval = -ENODEV; |
| 942 | goto out_up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 946 | parent = serio_get_drvdata(serio->parent); |
| 947 | psmouse_deactivate(parent); |
| 948 | } |
| 949 | psmouse_deactivate(psmouse); |
| 950 | |
| 951 | retval = handler(psmouse, buf, count); |
| 952 | |
| 953 | psmouse_activate(psmouse); |
| 954 | if (parent) |
| 955 | psmouse_activate(parent); |
| 956 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame^] | 957 | out_up: |
| 958 | up(&psmouse_sem); |
| 959 | out_unpin: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | serio_unpin_driver(serio); |
| 961 | return retval; |
| 962 | } |
| 963 | |
| 964 | static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf) |
| 965 | { |
| 966 | return sprintf(buf, "%d\n", psmouse->rate); |
| 967 | } |
| 968 | |
| 969 | static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, size_t count) |
| 970 | { |
| 971 | unsigned long value; |
| 972 | char *rest; |
| 973 | |
| 974 | value = simple_strtoul(buf, &rest, 10); |
| 975 | if (*rest) |
| 976 | return -EINVAL; |
| 977 | |
| 978 | psmouse->set_rate(psmouse, value); |
| 979 | return count; |
| 980 | } |
| 981 | |
| 982 | static ssize_t psmouse_attr_show_resolution(struct psmouse *psmouse, char *buf) |
| 983 | { |
| 984 | return sprintf(buf, "%d\n", psmouse->resolution); |
| 985 | } |
| 986 | |
| 987 | static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *buf, size_t count) |
| 988 | { |
| 989 | unsigned long value; |
| 990 | char *rest; |
| 991 | |
| 992 | value = simple_strtoul(buf, &rest, 10); |
| 993 | if (*rest) |
| 994 | return -EINVAL; |
| 995 | |
| 996 | psmouse->set_resolution(psmouse, value); |
| 997 | return count; |
| 998 | } |
| 999 | |
| 1000 | static ssize_t psmouse_attr_show_resetafter(struct psmouse *psmouse, char *buf) |
| 1001 | { |
| 1002 | return sprintf(buf, "%d\n", psmouse->resetafter); |
| 1003 | } |
| 1004 | |
| 1005 | static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *buf, size_t count) |
| 1006 | { |
| 1007 | unsigned long value; |
| 1008 | char *rest; |
| 1009 | |
| 1010 | value = simple_strtoul(buf, &rest, 10); |
| 1011 | if (*rest) |
| 1012 | return -EINVAL; |
| 1013 | |
| 1014 | psmouse->resetafter = value; |
| 1015 | return count; |
| 1016 | } |
| 1017 | |
| 1018 | static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) |
| 1019 | { |
| 1020 | int i; |
| 1021 | |
| 1022 | if (!val) |
| 1023 | return -EINVAL; |
| 1024 | |
| 1025 | if (!strncmp(val, "any", 3)) { |
Andrew Morton | 271b74d | 2005-05-28 02:11:06 -0500 | [diff] [blame] | 1026 | *((unsigned int *)kp->arg) = -1U; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | for (i = 0; i < ARRAY_SIZE(psmouse_proto_abbrev); i++) { |
| 1031 | if (!psmouse_proto_abbrev[i]) |
| 1032 | continue; |
| 1033 | |
| 1034 | if (!strncmp(val, psmouse_proto_abbrev[i], strlen(psmouse_proto_abbrev[i]))) { |
| 1035 | *((unsigned int *)kp->arg) = i; |
| 1036 | return 0; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | return -EINVAL; \ |
| 1041 | } |
| 1042 | |
| 1043 | static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) |
| 1044 | { |
| 1045 | return sprintf(buffer, "%s\n", |
| 1046 | psmouse_max_proto < ARRAY_SIZE(psmouse_proto_abbrev) ? |
| 1047 | psmouse_proto_abbrev[psmouse_max_proto] : "any"); |
| 1048 | } |
| 1049 | |
| 1050 | static int __init psmouse_init(void) |
| 1051 | { |
| 1052 | serio_register_driver(&psmouse_drv); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | static void __exit psmouse_exit(void) |
| 1057 | { |
| 1058 | serio_unregister_driver(&psmouse_drv); |
| 1059 | } |
| 1060 | |
| 1061 | module_init(psmouse_init); |
| 1062 | module_exit(psmouse_exit); |