4 * Copyright (c) 1999-2002 Vojtech Pavlik
5 * Copyright (c) 2003-2004 Dmitry Torokhov
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.
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>
24 #include "synaptics.h"
25 #include "logips2pp.h"
28 #define DRIVER_DESC "PS/2 mouse driver"
30 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
31 MODULE_DESCRIPTION(DRIVER_DESC
);
32 MODULE_LICENSE("GPL");
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.");
44 static unsigned int psmouse_resolution
= 200;
45 module_param_named(resolution
, psmouse_resolution
, uint
, 0644);
46 MODULE_PARM_DESC(resolution
, "Resolution, in dpi.");
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.");
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.");
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).");
60 PSMOUSE_DEFINE_ATTR(rate
);
61 PSMOUSE_DEFINE_ATTR(resolution
);
62 PSMOUSE_DEFINE_ATTR(resetafter
);
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=");
70 static char *psmouse_protocols
[] = { "None", "PS/2", "PS2++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2" };
73 * psmouse_process_byte() analyzes the PS/2 data stream and reports
74 * relevant events to the input module once full packet has arrived.
77 static psmouse_ret_t
psmouse_process_byte(struct psmouse
*psmouse
, struct pt_regs
*regs
)
79 struct input_dev
*dev
= &psmouse
->dev
;
80 unsigned char *packet
= psmouse
->packet
;
82 if (psmouse
->pktcnt
< psmouse
->pktsize
)
83 return PSMOUSE_GOOD_DATA
;
86 * Full packet accumulated, process it
89 input_regs(dev
, regs
);
92 * Scroll wheel on IntelliMice, scroll buttons on NetMice
95 if (psmouse
->type
== PSMOUSE_IMPS
|| psmouse
->type
== PSMOUSE_GENPS
)
96 input_report_rel(dev
, REL_WHEEL
, -(signed char) packet
[3]);
99 * Scroll wheel and buttons on IntelliMouse Explorer
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);
109 * Extra buttons on Genius NewNet 3D
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);
118 * Extra button on ThinkingMouse
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;
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);
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);
139 return PSMOUSE_FULL_PACKET
;
143 * psmouse_interrupt() handles incoming characters, either gathering them into
144 * packets or passing them to the command routine as command output.
147 static irqreturn_t
psmouse_interrupt(struct serio
*serio
,
148 unsigned char data
, unsigned int flags
, struct pt_regs
*regs
)
150 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
153 if (psmouse
->state
== PSMOUSE_IGNORE
)
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
);
165 if (unlikely(psmouse
->ps2dev
.flags
& PS2_FLAG_ACK
))
166 if (ps2_handle_ack(&psmouse
->ps2dev
, data
))
169 if (unlikely(psmouse
->ps2dev
.flags
& PS2_FLAG_CMD
))
170 if (ps2_handle_response(&psmouse
->ps2dev
, data
))
173 if (psmouse
->state
== PSMOUSE_INITIALIZING
)
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
);
183 psmouse
->last
= jiffies
;
184 psmouse
->packet
[psmouse
->pktcnt
++] = data
;
186 if (psmouse
->packet
[0] == PSMOUSE_RET_BAT
) {
187 if (psmouse
->pktcnt
== 1)
190 if (psmouse
->pktcnt
== 2) {
191 if (psmouse
->packet
[1] == PSMOUSE_RET_ID
) {
192 psmouse
->state
= PSMOUSE_IGNORE
;
193 serio_reconnect(serio
);
196 if (psmouse
->type
== PSMOUSE_SYNAPTICS
) {
197 /* neither 0xAA nor 0x00 are valid first bytes
198 * for a packet in absolute mode
206 rc
= psmouse
->protocol_handler(psmouse
, regs
);
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
);
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
);
221 case PSMOUSE_FULL_PACKET
:
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
);
230 case PSMOUSE_GOOD_DATA
:
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
245 int psmouse_sliced_command(struct psmouse
*psmouse
, unsigned char command
)
249 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
))
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
))
263 * psmouse_reset() resets the mouse into power-on state.
265 int psmouse_reset(struct psmouse
*psmouse
)
267 unsigned char param
[2];
269 if (ps2_command(&psmouse
->ps2dev
, param
, PSMOUSE_CMD_RESET_BAT
))
272 if (param
[0] != PSMOUSE_RET_BAT
&& param
[1] != PSMOUSE_RET_ID
)
280 * Genius NetMouse magic init.
282 static int genius_detect(struct psmouse
*psmouse
, int set_properties
)
284 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
285 unsigned char param
[4];
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
);
294 if (param
[0] != 0x00 || param
[1] != 0x33 || param
[2] != 0x55)
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
);
302 psmouse
->vendor
= "Genius";
303 psmouse
->name
= "Wheel Mouse";
304 psmouse
->pktsize
= 4;
311 * IntelliMouse magic init.
313 static int intellimouse_detect(struct psmouse
*psmouse
, int set_properties
)
315 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
316 unsigned char param
[2];
319 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
321 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
323 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
324 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
329 if (set_properties
) {
330 set_bit(REL_WHEEL
, psmouse
->dev
.relbit
);
332 if (!psmouse
->vendor
) psmouse
->vendor
= "Generic";
333 if (!psmouse
->name
) psmouse
->name
= "Wheel Mouse";
334 psmouse
->pktsize
= 4;
341 * Try IntelliMouse/Explorer magic init.
343 static int im_explorer_detect(struct psmouse
*psmouse
, int set_properties
)
345 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
346 unsigned char param
[2];
348 intellimouse_detect(psmouse
, 0);
351 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
353 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
355 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
356 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
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
);
366 if (!psmouse
->vendor
) psmouse
->vendor
= "Generic";
367 if (!psmouse
->name
) psmouse
->name
= "Explorer Mouse";
368 psmouse
->pktsize
= 4;
375 * Kensington ThinkingMouse / ExpertMouse magic init.
377 static int thinking_detect(struct psmouse
*psmouse
, int set_properties
)
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 };
385 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
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
);
395 if (set_properties
) {
396 set_bit(BTN_EXTRA
, psmouse
->dev
.keybit
);
398 psmouse
->vendor
= "Kensington";
399 psmouse
->name
= "ThinkingMouse";
406 * Bare PS/2 protocol "detection". Always succeeds.
408 static int ps2bare_detect(struct psmouse
*psmouse
, int set_properties
)
410 if (!psmouse
->vendor
) psmouse
->vendor
= "Generic";
411 if (!psmouse
->name
) psmouse
->name
= "Mouse";
417 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
418 * the mouse may have.
421 static int psmouse_extensions(struct psmouse
*psmouse
,
422 unsigned int max_proto
, int set_properties
)
424 int synaptics_hardware
= 0;
427 * Try Kensington ThinkingMouse (we try first, because synaptics probe
428 * upsets the thinkingmouse).
431 if (max_proto
> PSMOUSE_IMEX
&& thinking_detect(psmouse
, set_properties
) == 0)
432 return PSMOUSE_THINKPS
;
435 * Try Synaptics TouchPad
437 if (max_proto
> PSMOUSE_PS2
&& synaptics_detect(psmouse
, set_properties
) == 0) {
438 synaptics_hardware
= 1;
440 if (max_proto
> PSMOUSE_IMEX
) {
441 if (!set_properties
|| synaptics_init(psmouse
) == 0)
442 return PSMOUSE_SYNAPTICS
;
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.
448 max_proto
= PSMOUSE_IMEX
;
451 * Make sure that touchpad is in relative mode, gestures (taps) are enabled
453 synaptics_reset(psmouse
);
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)
465 * Init failed, try basic relative protocols
467 max_proto
= PSMOUSE_IMEX
;
471 if (max_proto
> PSMOUSE_IMEX
&& genius_detect(psmouse
, set_properties
) == 0)
472 return PSMOUSE_GENPS
;
474 if (max_proto
> PSMOUSE_IMEX
&& ps2pp_init(psmouse
, set_properties
) == 0)
475 return PSMOUSE_PS2PP
;
478 * Reset to defaults in case the device got confused by extended
481 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_RESET_DIS
);
483 if (max_proto
>= PSMOUSE_IMEX
&& im_explorer_detect(psmouse
, set_properties
) == 0)
486 if (max_proto
>= PSMOUSE_IMPS
&& intellimouse_detect(psmouse
, set_properties
) == 0)
490 * Okay, all failed, we have a standard mouse here. The number of the buttons
491 * is still a question, though. We assume 3.
493 ps2bare_detect(psmouse
, set_properties
);
495 if (synaptics_hardware
) {
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
502 psmouse_reset(psmouse
);
503 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_RESET_DIS
);
510 * psmouse_probe() probes for a PS/2 mouse.
513 static int psmouse_probe(struct psmouse
*psmouse
)
515 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
516 unsigned char param
[2];
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.
524 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
))
527 if (param
[0] != 0x00 && param
[0] != 0x03 && param
[0] != 0x04)
531 * Then we reset and disable the mouse so that it doesn't generate events.
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
);
541 * Here we set the mouse resolution.
544 void psmouse_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
)
546 unsigned char params
[] = { 0, 1, 2, 2, 3 };
548 if (resolution
== 0 || resolution
> 200)
551 ps2_command(&psmouse
->ps2dev
, ¶ms
[resolution
/ 50], PSMOUSE_CMD_SETRES
);
552 psmouse
->resolution
= 25 << params
[resolution
/ 50];
556 * Here we set the mouse report rate.
559 static void psmouse_set_rate(struct psmouse
*psmouse
, unsigned int rate
)
561 unsigned char rates
[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
564 while (rates
[i
] > rate
) i
++;
565 ps2_command(&psmouse
->ps2dev
, &rates
[i
], PSMOUSE_CMD_SETRATE
);
566 psmouse
->rate
= rates
[i
];
570 * psmouse_initialize() initializes the mouse to a sane state.
573 static void psmouse_initialize(struct psmouse
*psmouse
)
576 * We set the mouse into streaming mode.
579 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
);
582 * We set the mouse report rate, resolution and scaling.
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
);
593 * psmouse_set_state() sets new psmouse state and resets all flags and
594 * counters while holding serio lock so fighting with interrupt handler
598 static void psmouse_set_state(struct psmouse
*psmouse
, enum psmouse_state new_state
)
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
);
608 * psmouse_activate() enables the mouse so that we get motion reports from it.
611 static void psmouse_activate(struct psmouse
*psmouse
)
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
);
617 psmouse_set_state(psmouse
, PSMOUSE_ACTIVATED
);
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.
626 static void psmouse_deactivate(struct psmouse
*psmouse
)
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
);
632 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
637 * psmouse_cleanup() resets the mouse into power-on state.
640 static void psmouse_cleanup(struct serio
*serio
)
642 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
644 psmouse_reset(psmouse
);
648 * psmouse_disconnect() closes and frees.
651 static void psmouse_disconnect(struct serio
*serio
)
653 struct psmouse
*psmouse
, *parent
;
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
);
659 psmouse
= serio_get_drvdata(serio
);
660 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
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
);
668 if (psmouse
->disconnect
)
669 psmouse
->disconnect(psmouse
);
671 psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
673 input_unregister_device(&psmouse
->dev
);
675 serio_set_drvdata(serio
, NULL
);
680 * psmouse_connect() is a callback from the serio module when
681 * an unhandled serio port is found.
683 static int psmouse_connect(struct serio
*serio
, struct serio_driver
*drv
)
685 struct psmouse
*psmouse
, *parent
= NULL
;
689 * If this is a pass-through port deactivate parent so the device
690 * connected to this port can be successfully identified
692 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
693 parent
= serio_get_drvdata(serio
->parent
);
694 psmouse_deactivate(parent
);
697 if (!(psmouse
= kmalloc(sizeof(struct psmouse
), GFP_KERNEL
))) {
702 memset(psmouse
, 0, sizeof(struct psmouse
));
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
);
713 serio_set_drvdata(serio
, psmouse
);
715 retval
= serio_open(serio
, drv
);
717 serio_set_drvdata(serio
, NULL
);
722 if (psmouse_probe(psmouse
) < 0) {
724 serio_set_drvdata(serio
, NULL
);
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;
739 psmouse
->type
= psmouse_extensions(psmouse
, psmouse_max_proto
, 1);
741 sprintf(psmouse
->devname
, "%s %s %s",
742 psmouse_protocols
[psmouse
->type
], psmouse
->vendor
, psmouse
->name
);
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
;
751 input_register_device(&psmouse
->dev
);
753 printk(KERN_INFO
"input: %s on %s\n", psmouse
->devname
, serio
->phys
);
755 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
757 psmouse_initialize(psmouse
);
759 if (parent
&& parent
->pt_activate
)
760 parent
->pt_activate(parent
);
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
);
766 psmouse_activate(psmouse
);
771 /* If this is a pass-through port the parent awaits to be activated */
773 psmouse_activate(parent
);
779 static int psmouse_reconnect(struct serio
*serio
)
781 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
782 struct psmouse
*parent
= NULL
;
783 struct serio_driver
*drv
= serio
->drv
;
786 if (!drv
|| !psmouse
) {
787 printk(KERN_DEBUG
"psmouse: reconnect request, but serio is disconnected, ignoring...\n");
791 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
792 parent
= serio_get_drvdata(serio
->parent
);
793 psmouse_deactivate(parent
);
796 psmouse_set_state(psmouse
, PSMOUSE_INITIALIZING
);
798 if (psmouse
->reconnect
) {
799 if (psmouse
->reconnect(psmouse
))
801 } else if (psmouse_probe(psmouse
) < 0 ||
802 psmouse
->type
!= psmouse_extensions(psmouse
, psmouse_max_proto
, 0))
805 /* ok, the device type (and capabilities) match the old one,
806 * we can continue using it, complete intialization
808 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
810 psmouse_initialize(psmouse
);
812 if (parent
&& parent
->pt_activate
)
813 parent
->pt_activate(parent
);
815 psmouse_activate(psmouse
);
819 /* If this is a pass-through port the parent waits to be activated */
821 psmouse_activate(parent
);
826 static struct serio_device_id psmouse_serio_ids
[] = {
834 .type
= SERIO_PS_PSTHRU
,
842 MODULE_DEVICE_TABLE(serio
, psmouse_serio_ids
);
844 static struct serio_driver psmouse_drv
= {
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
,
857 ssize_t
psmouse_attr_show_helper(struct device
*dev
, char *buf
,
858 ssize_t (*handler
)(struct psmouse
*, char *))
860 struct serio
*serio
= to_serio_port(dev
);
863 retval
= serio_pin_driver(serio
);
867 if (serio
->drv
!= &psmouse_drv
) {
872 retval
= handler(serio_get_drvdata(serio
), buf
);
875 serio_unpin_driver(serio
);
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))
882 struct serio
*serio
= to_serio_port(dev
);
883 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
884 struct psmouse
*parent
= NULL
;
887 retval
= serio_pin_driver(serio
);
891 if (serio
->drv
!= &psmouse_drv
) {
896 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
897 parent
= serio_get_drvdata(serio
->parent
);
898 psmouse_deactivate(parent
);
900 psmouse_deactivate(psmouse
);
902 retval
= handler(psmouse
, buf
, count
);
904 psmouse_activate(psmouse
);
906 psmouse_activate(parent
);
909 serio_unpin_driver(serio
);
913 static ssize_t
psmouse_attr_show_rate(struct psmouse
*psmouse
, char *buf
)
915 return sprintf(buf
, "%d\n", psmouse
->rate
);
918 static ssize_t
psmouse_attr_set_rate(struct psmouse
*psmouse
, const char *buf
, size_t count
)
923 value
= simple_strtoul(buf
, &rest
, 10);
927 psmouse
->set_rate(psmouse
, value
);
931 static ssize_t
psmouse_attr_show_resolution(struct psmouse
*psmouse
, char *buf
)
933 return sprintf(buf
, "%d\n", psmouse
->resolution
);
936 static ssize_t
psmouse_attr_set_resolution(struct psmouse
*psmouse
, const char *buf
, size_t count
)
941 value
= simple_strtoul(buf
, &rest
, 10);
945 psmouse
->set_resolution(psmouse
, value
);
949 static ssize_t
psmouse_attr_show_resetafter(struct psmouse
*psmouse
, char *buf
)
951 return sprintf(buf
, "%d\n", psmouse
->resetafter
);
954 static ssize_t
psmouse_attr_set_resetafter(struct psmouse
*psmouse
, const char *buf
, size_t count
)
959 value
= simple_strtoul(buf
, &rest
, 10);
963 psmouse
->resetafter
= value
;
967 static int psmouse_set_maxproto(const char *val
, struct kernel_param
*kp
)
974 if (!strncmp(val
, "any", 3)) {
975 *((unsigned int *)kp
->arg
) = -1UL;
979 for (i
= 0; i
< ARRAY_SIZE(psmouse_proto_abbrev
); i
++) {
980 if (!psmouse_proto_abbrev
[i
])
983 if (!strncmp(val
, psmouse_proto_abbrev
[i
], strlen(psmouse_proto_abbrev
[i
]))) {
984 *((unsigned int *)kp
->arg
) = i
;
992 static int psmouse_get_maxproto(char *buffer
, struct kernel_param
*kp
)
994 return sprintf(buffer
, "%s\n",
995 psmouse_max_proto
< ARRAY_SIZE(psmouse_proto_abbrev
) ?
996 psmouse_proto_abbrev
[psmouse_max_proto
] : "any");
999 static int __init
psmouse_init(void)
1001 serio_register_driver(&psmouse_drv
);
1005 static void __exit
psmouse_exit(void)
1007 serio_unregister_driver(&psmouse_drv
);
1010 module_init(psmouse_init
);
1011 module_exit(psmouse_exit
);