ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / input / mouse / psmouse-base.c
1 /*
2  * PS/2 mouse driver
3  *
4  * Copyright (c) 1999-2002 Vojtech Pavlik
5  */
6
7 /*
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  */
12
13 #include <linux/delay.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/slab.h>
17 #include <linux/interrupt.h>
18 #include <linux/input.h>
19 #include <linux/serio.h>
20 #include <linux/init.h>
21 #include "psmouse.h"
22 #include "synaptics.h"
23 #include "logips2pp.h"
24
25 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
26 MODULE_DESCRIPTION("PS/2 mouse driver");
27 MODULE_LICENSE("GPL");
28
29 static char *psmouse_proto;
30 static unsigned int psmouse_max_proto = -1U;
31 module_param_named(proto, psmouse_proto, charp, 0);
32 MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps). Useful for KVM switches.");
33
34 int psmouse_resolution = 200;
35 module_param_named(resolution, psmouse_resolution, uint, 0);
36 MODULE_PARM_DESC(resolution, "Resolution, in dpi.");
37
38 unsigned int psmouse_rate = 100;
39 module_param_named(rate, psmouse_rate, uint, 0);
40 MODULE_PARM_DESC(rate, "Report rate, in reports per second.");
41
42 int psmouse_smartscroll = 1;
43 module_param_named(smartscroll, psmouse_smartscroll, bool, 0);
44 MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
45
46 unsigned int psmouse_resetafter;
47 module_param_named(resetafter, psmouse_resetafter, uint, 0);
48 MODULE_PARM_DESC(resetafter, "Reset Synaptics Touchpad after so many bad packets (0 = never).");
49
50 __obsolete_setup("psmouse_noext");
51 __obsolete_setup("psmouse_resolution=");
52 __obsolete_setup("psmouse_smartscroll=");
53 __obsolete_setup("psmouse_resetafter=");
54 __obsolete_setup("psmouse_rate=");
55
56 static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "PS2T++", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2"};
57
58 /*
59  * psmouse_process_packet() analyzes the PS/2 mouse packet contents and
60  * reports relevant events to the input module.
61  */
62
63 static void psmouse_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
64 {
65         struct input_dev *dev = &psmouse->dev;
66         unsigned char *packet = psmouse->packet;
67
68         input_regs(dev, regs);
69
70 /*
71  * The PS2++ protocol is a little bit complex
72  */
73
74         if (psmouse->type == PSMOUSE_PS2PP || psmouse->type == PSMOUSE_PS2TPP)
75                 ps2pp_process_packet(psmouse);
76
77 /*
78  * Scroll wheel on IntelliMice, scroll buttons on NetMice
79  */
80
81         if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS)
82                 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
83
84 /*
85  * Scroll wheel and buttons on IntelliMouse Explorer
86  */
87
88         if (psmouse->type == PSMOUSE_IMEX) {
89                 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7));
90                 input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1);
91                 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1);
92         }
93
94 /*
95  * Extra buttons on Genius NewNet 3D
96  */
97
98         if (psmouse->type == PSMOUSE_GENPS) {
99                 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
100                 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
101         }
102
103 /*
104  * Generic PS/2 Mouse
105  */
106
107         input_report_key(dev, BTN_LEFT,    packet[0]       & 1);
108         input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
109         input_report_key(dev, BTN_RIGHT,  (packet[0] >> 1) & 1);
110
111         input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
112         input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
113
114         input_sync(dev);
115 }
116
117 /*
118  * psmouse_interrupt() handles incoming characters, either gathering them into
119  * packets or passing them to the command routine as command output.
120  */
121
122 static irqreturn_t psmouse_interrupt(struct serio *serio,
123                 unsigned char data, unsigned int flags, struct pt_regs *regs)
124 {
125         struct psmouse *psmouse = serio->private;
126
127         if (psmouse->state == PSMOUSE_IGNORE)
128                 goto out;
129
130         if (flags & (SERIO_PARITY|SERIO_TIMEOUT)) {
131                 if (psmouse->state == PSMOUSE_ACTIVATED)
132                         printk(KERN_WARNING "psmouse.c: bad data from KBC -%s%s\n",
133                                 flags & SERIO_TIMEOUT ? " timeout" : "",
134                                 flags & SERIO_PARITY ? " bad parity" : "");
135                 if (psmouse->acking) {
136                         psmouse->ack = -1;
137                         psmouse->acking = 0;
138                 }
139                 psmouse->pktcnt = 0;
140                 goto out;
141         }
142
143         if (psmouse->acking) {
144                 switch (data) {
145                         case PSMOUSE_RET_ACK:
146                                 psmouse->ack = 1;
147                                 break;
148                         case PSMOUSE_RET_NAK:
149                                 psmouse->ack = -1;
150                                 break;
151                         default:
152                                 psmouse->ack = 1;       /* Workaround for mice which don't ACK the Get ID command */
153                                 if (psmouse->cmdcnt)
154                                         psmouse->cmdbuf[--psmouse->cmdcnt] = data;
155                                 break;
156                 }
157                 psmouse->acking = 0;
158                 goto out;
159         }
160
161         if (psmouse->cmdcnt) {
162                 psmouse->cmdbuf[--psmouse->cmdcnt] = data;
163                 goto out;
164         }
165
166         if (psmouse->state == PSMOUSE_ACTIVATED &&
167             psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
168                 printk(KERN_WARNING "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n",
169                        psmouse->name, psmouse->phys, psmouse->pktcnt);
170                 psmouse->pktcnt = 0;
171         }
172
173         psmouse->last = jiffies;
174         psmouse->packet[psmouse->pktcnt++] = data;
175
176         if (psmouse->packet[0] == PSMOUSE_RET_BAT) {
177                 if (psmouse->pktcnt == 1)
178                         goto out;
179
180                 if (psmouse->pktcnt == 2) {
181                         if (psmouse->packet[1] == PSMOUSE_RET_ID) {
182                                 psmouse->state = PSMOUSE_IGNORE;
183                                 serio_rescan(serio);
184                                 goto out;
185                         }
186                         if (psmouse->type == PSMOUSE_SYNAPTICS) {
187                                 /* neither 0xAA nor 0x00 are valid first bytes
188                                  * for a packet in absolute mode
189                                  */
190                                 psmouse->pktcnt = 0;
191                                 goto out;
192                         }
193                 }
194         }
195
196         if (psmouse->type == PSMOUSE_SYNAPTICS) {
197                 /*
198                  * The synaptics driver has its own resync logic,
199                  * so it needs to receive all bytes one at a time.
200                  */
201                 synaptics_process_byte(psmouse, regs);
202                 goto out;
203         }
204
205         if (psmouse->pktcnt == 3 + (psmouse->type >= PSMOUSE_GENPS)) {
206                 psmouse_process_packet(psmouse, regs);
207                 psmouse->pktcnt = 0;
208                 goto out;
209         }
210 out:
211         return IRQ_HANDLED;
212 }
213
214 /*
215  * psmouse_sendbyte() sends a byte to the mouse, and waits for acknowledge.
216  * It doesn't handle retransmission, though it could - because when there would
217  * be need for retransmissions, the mouse has to be replaced anyway.
218  */
219
220 static int psmouse_sendbyte(struct psmouse *psmouse, unsigned char byte)
221 {
222         int timeout = 10000; /* 100 msec */
223         psmouse->ack = 0;
224         psmouse->acking = 1;
225
226         if (serio_write(psmouse->serio, byte)) {
227                 psmouse->acking = 0;
228                 return -1;
229         }
230
231         while (!psmouse->ack && timeout--) udelay(10);
232
233         return -(psmouse->ack <= 0);
234 }
235
236 /*
237  * psmouse_command() sends a command and its parameters to the mouse,
238  * then waits for the response and puts it in the param array.
239  */
240
241 int psmouse_command(struct psmouse *psmouse, unsigned char *param, int command)
242 {
243         int timeout = 500000; /* 500 msec */
244         int send = (command >> 12) & 0xf;
245         int receive = (command >> 8) & 0xf;
246         int i;
247
248         psmouse->cmdcnt = receive;
249
250         if (command == PSMOUSE_CMD_RESET_BAT)
251                 timeout = 4000000; /* 4 sec */
252
253         /* initialize cmdbuf with preset values from param */
254         if (receive)
255            for (i = 0; i < receive; i++)
256                 psmouse->cmdbuf[(receive - 1) - i] = param[i];
257
258         if (command & 0xff)
259                 if (psmouse_sendbyte(psmouse, command & 0xff))
260                         return (psmouse->cmdcnt = 0) - 1;
261
262         for (i = 0; i < send; i++)
263                 if (psmouse_sendbyte(psmouse, param[i]))
264                         return (psmouse->cmdcnt = 0) - 1;
265
266         while (psmouse->cmdcnt && timeout--) {
267
268                 if (psmouse->cmdcnt == 1 && command == PSMOUSE_CMD_RESET_BAT &&
269                                 timeout > 100000) /* do not run in a endless loop */
270                         timeout = 100000; /* 1 sec */
271
272                 if (psmouse->cmdcnt == 1 && command == PSMOUSE_CMD_GETID &&
273                     psmouse->cmdbuf[1] != 0xab && psmouse->cmdbuf[1] != 0xac) {
274                         psmouse->cmdcnt = 0;
275                         break;
276                 }
277
278                 udelay(1);
279         }
280
281         for (i = 0; i < receive; i++)
282                 param[i] = psmouse->cmdbuf[(receive - 1) - i];
283
284         if (psmouse->cmdcnt)
285                 return (psmouse->cmdcnt = 0) - 1;
286
287         return 0;
288 }
289
290
291 /*
292  * psmouse_reset() resets the mouse into power-on state.
293  */
294 int psmouse_reset(struct psmouse *psmouse)
295 {
296         unsigned char param[2];
297
298         if (psmouse_command(psmouse, param, PSMOUSE_CMD_RESET_BAT))
299                 return -1;
300
301         if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID)
302                 return -1;
303
304         return 0;
305 }
306
307
308 /*
309  * Genius NetMouse magic init.
310  */
311 static int genius_detect(struct psmouse *psmouse)
312 {
313         unsigned char param[4];
314
315         param[0] = 3;
316         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
317         psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
318         psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
319         psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
320         psmouse_command(psmouse, param, PSMOUSE_CMD_GETINFO);
321
322         return param[0] == 0x00 && param[1] == 0x33 && param[2] == 0x55;
323 }
324
325 /*
326  * IntelliMouse magic init.
327  */
328 static int intellimouse_detect(struct psmouse *psmouse)
329 {
330         unsigned char param[2];
331
332         param[0] = 200;
333         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE);
334         param[0] = 100;
335         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE);
336         param[0] =  80;
337         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE);
338         psmouse_command(psmouse, param, PSMOUSE_CMD_GETID);
339
340         return param[0] == 3;
341 }
342
343 /*
344  * Try IntelliMouse/Explorer magic init.
345  */
346 static int im_explorer_detect(struct psmouse *psmouse)
347 {
348         unsigned char param[2];
349
350         param[0] = 200;
351         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE);
352         param[0] = 200;
353         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE);
354         param[0] =  80;
355         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRATE);
356         psmouse_command(psmouse, param, PSMOUSE_CMD_GETID);
357
358         return param[0] == 4;
359 }
360
361 /*
362  * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
363  * the mouse may have.
364  */
365
366 static int psmouse_extensions(struct psmouse *psmouse)
367 {
368         int synaptics_hardware = 0;
369
370         psmouse->vendor = "Generic";
371         psmouse->name = "Mouse";
372         psmouse->model = 0;
373
374 /*
375  * Try Synaptics TouchPad
376  */
377         if (psmouse_max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse)) {
378                 synaptics_hardware = 1;
379                 psmouse->vendor = "Synaptics";
380                 psmouse->name = "TouchPad";
381
382                 if (psmouse_max_proto > PSMOUSE_IMEX) {
383                         if (synaptics_init(psmouse) == 0)
384                                 return PSMOUSE_SYNAPTICS;
385 /*
386  * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
387  * Unfortunately Logitech/Genius probes confuse some firmware versions so
388  * we'll have to skip them.
389  */
390                         psmouse_max_proto = PSMOUSE_IMEX;
391                 }
392 /*
393  * Make sure that touchpad is in relative mode, gestures (taps) are enabled
394  */
395                 synaptics_reset(psmouse);
396         }
397
398         if (psmouse_max_proto > PSMOUSE_IMEX && genius_detect(psmouse)) {
399                 set_bit(BTN_EXTRA, psmouse->dev.keybit);
400                 set_bit(BTN_SIDE, psmouse->dev.keybit);
401                 set_bit(REL_WHEEL, psmouse->dev.relbit);
402
403                 psmouse->vendor = "Genius";
404                 psmouse->name = "Wheel Mouse";
405                 return PSMOUSE_GENPS;
406         }
407
408         if (psmouse_max_proto > PSMOUSE_IMEX) {
409                 int type = ps2pp_detect(psmouse);
410                 if (type)
411                         return type;
412         }
413
414         if (psmouse_max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse)) {
415                 set_bit(REL_WHEEL, psmouse->dev.relbit);
416
417                 if (psmouse_max_proto >= PSMOUSE_IMEX &&
418                                         im_explorer_detect(psmouse)) {
419                         set_bit(BTN_SIDE, psmouse->dev.keybit);
420                         set_bit(BTN_EXTRA, psmouse->dev.keybit);
421
422                         psmouse->name = "Explorer Mouse";
423                         return PSMOUSE_IMEX;
424                 }
425
426                 psmouse->name = "Wheel Mouse";
427                 return PSMOUSE_IMPS;
428         }
429
430 /*
431  * Okay, all failed, we have a standard mouse here. The number of the buttons
432  * is still a question, though. We assume 3.
433  */
434         if (synaptics_hardware) {
435 /*
436  * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
437  * We need to reset the touchpad because if there is a track point on the
438  * pass through port it could get disabled while probing for protocol
439  * extensions.
440  */
441                 psmouse_reset(psmouse);
442                 psmouse_command(psmouse, NULL, PSMOUSE_CMD_RESET_DIS);
443         }
444
445         return PSMOUSE_PS2;
446 }
447
448 /*
449  * psmouse_probe() probes for a PS/2 mouse.
450  */
451
452 static int psmouse_probe(struct psmouse *psmouse)
453 {
454         unsigned char param[2];
455
456 /*
457  * First, we check if it's a mouse. It should send 0x00 or 0x03
458  * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
459  */
460
461         param[0] = 0xa5;
462
463         if (psmouse_command(psmouse, param, PSMOUSE_CMD_GETID))
464                 return -1;
465
466         if (param[0] != 0x00 && param[0] != 0x03 && param[0] != 0x04)
467                 return -1;
468
469 /*
470  * Then we reset and disable the mouse so that it doesn't generate events.
471  */
472
473         if (psmouse_command(psmouse, NULL, PSMOUSE_CMD_RESET_DIS))
474                 printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", psmouse->serio->phys);
475
476 /*
477  * And here we try to determine if it has any extensions over the
478  * basic PS/2 3-button mouse.
479  */
480
481         return psmouse->type = psmouse_extensions(psmouse);
482 }
483
484 /*
485  * Here we set the mouse resolution.
486  */
487
488 static void psmouse_set_resolution(struct psmouse *psmouse)
489 {
490         unsigned char param[1];
491
492         if (psmouse->type == PSMOUSE_PS2PP && psmouse_resolution > 400) {
493                 ps2pp_set_800dpi(psmouse);
494                 return;
495         }
496
497         if (!psmouse_resolution || psmouse_resolution >= 200)
498                 param[0] = 3;
499         else if (psmouse_resolution >= 100)
500                 param[0] = 2;
501         else if (psmouse_resolution >= 50)
502                 param[0] = 1;
503         else if (psmouse_resolution)
504                 param[0] = 0;
505
506         psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
507 }
508
509 /*
510  * Here we set the mouse report rate.
511  */
512
513 static void psmouse_set_rate(struct psmouse *psmouse)
514 {
515         unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
516         int i = 0;
517
518         while (rates[i] > psmouse_rate) i++;
519         psmouse_command(psmouse, rates + i, PSMOUSE_CMD_SETRATE);
520 }
521
522 /*
523  * psmouse_initialize() initializes the mouse to a sane state.
524  */
525
526 static void psmouse_initialize(struct psmouse *psmouse)
527 {
528         unsigned char param[2];
529
530 /*
531  * We set the mouse report rate, resolution and scaling.
532  */
533
534         if (psmouse_max_proto != PSMOUSE_PS2) {
535                 psmouse_set_rate(psmouse);
536                 psmouse_set_resolution(psmouse);
537                 psmouse_command(psmouse,  NULL, PSMOUSE_CMD_SETSCALE11);
538         }
539
540 /*
541  * We set the mouse into streaming mode.
542  */
543
544         psmouse_command(psmouse, param, PSMOUSE_CMD_SETSTREAM);
545 }
546
547 /*
548  * psmouse_activate() enables the mouse so that we get motion reports from it.
549  */
550
551 static void psmouse_activate(struct psmouse *psmouse)
552 {
553         if (psmouse_command(psmouse, NULL, PSMOUSE_CMD_ENABLE))
554                 printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n", psmouse->serio->phys);
555
556         psmouse->state = PSMOUSE_ACTIVATED;
557 }
558
559 /*
560  * psmouse_cleanup() resets the mouse into power-on state.
561  */
562
563 static void psmouse_cleanup(struct serio *serio)
564 {
565         struct psmouse *psmouse = serio->private;
566
567         psmouse_reset(psmouse);
568 }
569
570 /*
571  * psmouse_disconnect() closes and frees.
572  */
573
574 static void psmouse_disconnect(struct serio *serio)
575 {
576         struct psmouse *psmouse = serio->private;
577
578         psmouse->state = PSMOUSE_CMD_MODE;
579
580         if (psmouse->ptport) {
581                 if (psmouse->ptport->deactivate)
582                         psmouse->ptport->deactivate(psmouse);
583                 __serio_unregister_port(&psmouse->ptport->serio); /* we have serio_sem */
584                 kfree(psmouse->ptport);
585                 psmouse->ptport = NULL;
586         }
587
588         if (psmouse->disconnect)
589                 psmouse->disconnect(psmouse);
590
591         psmouse->state = PSMOUSE_IGNORE;
592
593         input_unregister_device(&psmouse->dev);
594         serio_close(serio);
595         kfree(psmouse);
596 }
597
598 /*
599  * psmouse_connect() is a callback from the serio module when
600  * an unhandled serio port is found.
601  */
602 static void psmouse_connect(struct serio *serio, struct serio_dev *dev)
603 {
604         struct psmouse *psmouse;
605
606         if ((serio->type & SERIO_TYPE) != SERIO_8042 &&
607             (serio->type & SERIO_TYPE) != SERIO_PS_PSTHRU)
608                 return;
609
610         if (!(psmouse = kmalloc(sizeof(struct psmouse), GFP_KERNEL)))
611                 return;
612
613         memset(psmouse, 0, sizeof(struct psmouse));
614
615         init_input_dev(&psmouse->dev);
616         psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
617         psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
618         psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
619
620         psmouse->state = PSMOUSE_CMD_MODE;
621         psmouse->serio = serio;
622         psmouse->dev.private = psmouse;
623
624         serio->private = psmouse;
625         if (serio_open(serio, dev)) {
626                 kfree(psmouse);
627                 serio->private = NULL;
628                 return;
629         }
630
631         if (psmouse_probe(psmouse) <= 0) {
632                 serio_close(serio);
633                 kfree(psmouse);
634                 serio->private = NULL;
635                 return;
636         }
637
638         sprintf(psmouse->devname, "%s %s %s",
639                 psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
640         sprintf(psmouse->phys, "%s/input0",
641                 serio->phys);
642
643         psmouse->dev.name = psmouse->devname;
644         psmouse->dev.phys = psmouse->phys;
645         psmouse->dev.id.bustype = BUS_I8042;
646         psmouse->dev.id.vendor = 0x0002;
647         psmouse->dev.id.product = psmouse->type;
648         psmouse->dev.id.version = psmouse->model;
649
650         input_register_device(&psmouse->dev);
651
652         printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
653
654         psmouse_initialize(psmouse);
655
656         if (psmouse->ptport) {
657                 printk(KERN_INFO "serio: %s port at %s\n", psmouse->ptport->serio.name, psmouse->phys);
658                 __serio_register_port(&psmouse->ptport->serio); /* we have serio_sem */
659                 if (psmouse->ptport->activate)
660                         psmouse->ptport->activate(psmouse);
661         }
662
663         psmouse_activate(psmouse);
664 }
665
666
667 static int psmouse_reconnect(struct serio *serio)
668 {
669         struct psmouse *psmouse = serio->private;
670         struct serio_dev *dev = serio->dev;
671         int old_type;
672
673         if (!dev || !psmouse) {
674                 printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n");
675                 return -1;
676         }
677
678         old_type = psmouse->type;
679
680         psmouse->state = PSMOUSE_CMD_MODE;
681         psmouse->type = psmouse->acking = psmouse->cmdcnt = psmouse->pktcnt = 0;
682         if (psmouse->reconnect) {
683                if (psmouse->reconnect(psmouse))
684                         return -1;
685         } else if (psmouse_probe(psmouse) != old_type)
686                 return -1;
687
688         /* ok, the device type (and capabilities) match the old one,
689          * we can continue using it, complete intialization
690          */
691         psmouse->type = old_type;
692         psmouse_initialize(psmouse);
693
694         if (psmouse->ptport) {
695                 if (psmouse_reconnect(&psmouse->ptport->serio)) {
696                         __serio_unregister_port(&psmouse->ptport->serio);
697                         __serio_register_port(&psmouse->ptport->serio);
698                         if (psmouse->ptport->activate)
699                                 psmouse->ptport->activate(psmouse);
700                 }
701         }
702
703         psmouse_activate(psmouse);
704         return 0;
705 }
706
707
708 static struct serio_dev psmouse_dev = {
709         .interrupt =    psmouse_interrupt,
710         .connect =      psmouse_connect,
711         .reconnect =    psmouse_reconnect,
712         .disconnect =   psmouse_disconnect,
713         .cleanup =      psmouse_cleanup,
714 };
715
716 static inline void psmouse_parse_proto(void)
717 {
718         if (psmouse_proto) {
719                 if (!strcmp(psmouse_proto, "bare"))
720                         psmouse_max_proto = PSMOUSE_PS2;
721                 else if (!strcmp(psmouse_proto, "imps"))
722                         psmouse_max_proto = PSMOUSE_IMPS;
723                 else if (!strcmp(psmouse_proto, "exps"))
724                         psmouse_max_proto = PSMOUSE_IMEX;
725                 else
726                         printk(KERN_ERR "psmouse: unknown protocol type '%s'\n", psmouse_proto);
727         }
728 }
729
730 int __init psmouse_init(void)
731 {
732         psmouse_parse_proto();
733         serio_register_device(&psmouse_dev);
734         return 0;
735 }
736
737 void __exit psmouse_exit(void)
738 {
739         serio_unregister_device(&psmouse_dev);
740 }
741
742 module_init(psmouse_init);
743 module_exit(psmouse_exit);