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