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>
23 #include <linux/mutex.h>
26 #include "synaptics.h"
27 #include "logips2pp.h"
30 #include "trackpoint.h"
31 #include "touchkit_ps2.h"
33 #define DRIVER_DESC "PS/2 mouse driver"
35 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
36 MODULE_DESCRIPTION(DRIVER_DESC
);
37 MODULE_LICENSE("GPL");
39 static unsigned int psmouse_max_proto
= PSMOUSE_AUTO
;
40 static int psmouse_set_maxproto(const char *val
, struct kernel_param
*kp
);
41 static int psmouse_get_maxproto(char *buffer
, struct kernel_param
*kp
);
42 #define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
43 #define param_set_proto_abbrev psmouse_set_maxproto
44 #define param_get_proto_abbrev psmouse_get_maxproto
45 module_param_named(proto
, psmouse_max_proto
, proto_abbrev
, 0644);
46 MODULE_PARM_DESC(proto
, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
48 static unsigned int psmouse_resolution
= 200;
49 module_param_named(resolution
, psmouse_resolution
, uint
, 0644);
50 MODULE_PARM_DESC(resolution
, "Resolution, in dpi.");
52 static unsigned int psmouse_rate
= 100;
53 module_param_named(rate
, psmouse_rate
, uint
, 0644);
54 MODULE_PARM_DESC(rate
, "Report rate, in reports per second.");
56 static unsigned int psmouse_smartscroll
= 1;
57 module_param_named(smartscroll
, psmouse_smartscroll
, bool, 0644);
58 MODULE_PARM_DESC(smartscroll
, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
60 static unsigned int psmouse_resetafter
= 5;
61 module_param_named(resetafter
, psmouse_resetafter
, uint
, 0644);
62 MODULE_PARM_DESC(resetafter
, "Reset device after so many bad packets (0 = never).");
64 static unsigned int psmouse_resync_time
;
65 module_param_named(resync_time
, psmouse_resync_time
, uint
, 0644);
66 MODULE_PARM_DESC(resync_time
, "How long can mouse stay idle before forcing resync (in seconds, 0 = never).");
68 PSMOUSE_DEFINE_ATTR(protocol
, S_IWUSR
| S_IRUGO
,
70 psmouse_attr_show_protocol
, psmouse_attr_set_protocol
);
71 PSMOUSE_DEFINE_ATTR(rate
, S_IWUSR
| S_IRUGO
,
72 (void *) offsetof(struct psmouse
, rate
),
73 psmouse_show_int_attr
, psmouse_attr_set_rate
);
74 PSMOUSE_DEFINE_ATTR(resolution
, S_IWUSR
| S_IRUGO
,
75 (void *) offsetof(struct psmouse
, resolution
),
76 psmouse_show_int_attr
, psmouse_attr_set_resolution
);
77 PSMOUSE_DEFINE_ATTR(resetafter
, S_IWUSR
| S_IRUGO
,
78 (void *) offsetof(struct psmouse
, resetafter
),
79 psmouse_show_int_attr
, psmouse_set_int_attr
);
80 PSMOUSE_DEFINE_ATTR(resync_time
, S_IWUSR
| S_IRUGO
,
81 (void *) offsetof(struct psmouse
, resync_time
),
82 psmouse_show_int_attr
, psmouse_set_int_attr
);
84 static struct attribute
*psmouse_attributes
[] = {
85 &psmouse_attr_protocol
.dattr
.attr
,
86 &psmouse_attr_rate
.dattr
.attr
,
87 &psmouse_attr_resolution
.dattr
.attr
,
88 &psmouse_attr_resetafter
.dattr
.attr
,
89 &psmouse_attr_resync_time
.dattr
.attr
,
93 static struct attribute_group psmouse_attribute_group
= {
94 .attrs
= psmouse_attributes
,
98 * psmouse_mutex protects all operations changing state of mouse
99 * (connecting, disconnecting, changing rate or resolution via
100 * sysfs). We could use a per-device semaphore but since there
101 * rarely more than one PS/2 mouse connected and since semaphore
102 * is taken in "slow" paths it is not worth it.
104 static DEFINE_MUTEX(psmouse_mutex
);
106 static struct workqueue_struct
*kpsmoused_wq
;
108 struct psmouse_protocol
{
109 enum psmouse_type type
;
113 int (*detect
)(struct psmouse
*, int);
114 int (*init
)(struct psmouse
*);
118 * psmouse_process_byte() analyzes the PS/2 data stream and reports
119 * relevant events to the input module once full packet has arrived.
122 static psmouse_ret_t
psmouse_process_byte(struct psmouse
*psmouse
)
124 struct input_dev
*dev
= psmouse
->dev
;
125 unsigned char *packet
= psmouse
->packet
;
127 if (psmouse
->pktcnt
< psmouse
->pktsize
)
128 return PSMOUSE_GOOD_DATA
;
131 * Full packet accumulated, process it
135 * Scroll wheel on IntelliMice, scroll buttons on NetMice
138 if (psmouse
->type
== PSMOUSE_IMPS
|| psmouse
->type
== PSMOUSE_GENPS
)
139 input_report_rel(dev
, REL_WHEEL
, -(signed char) packet
[3]);
142 * Scroll wheel and buttons on IntelliMouse Explorer
145 if (psmouse
->type
== PSMOUSE_IMEX
) {
146 switch (packet
[3] & 0xC0) {
147 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
148 input_report_rel(dev
, REL_WHEEL
, (int) (packet
[3] & 32) - (int) (packet
[3] & 31));
150 case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */
151 input_report_rel(dev
, REL_HWHEEL
, (int) (packet
[3] & 32) - (int) (packet
[3] & 31));
155 input_report_rel(dev
, REL_WHEEL
, (int) (packet
[3] & 8) - (int) (packet
[3] & 7));
156 input_report_key(dev
, BTN_SIDE
, (packet
[3] >> 4) & 1);
157 input_report_key(dev
, BTN_EXTRA
, (packet
[3] >> 5) & 1);
163 * Extra buttons on Genius NewNet 3D
166 if (psmouse
->type
== PSMOUSE_GENPS
) {
167 input_report_key(dev
, BTN_SIDE
, (packet
[0] >> 6) & 1);
168 input_report_key(dev
, BTN_EXTRA
, (packet
[0] >> 7) & 1);
172 * Extra button on ThinkingMouse
174 if (psmouse
->type
== PSMOUSE_THINKPS
) {
175 input_report_key(dev
, BTN_EXTRA
, (packet
[0] >> 3) & 1);
176 /* Without this bit of weirdness moving up gives wildly high Y changes. */
177 packet
[1] |= (packet
[0] & 0x40) << 1;
184 input_report_key(dev
, BTN_LEFT
, packet
[0] & 1);
185 input_report_key(dev
, BTN_MIDDLE
, (packet
[0] >> 2) & 1);
186 input_report_key(dev
, BTN_RIGHT
, (packet
[0] >> 1) & 1);
188 input_report_rel(dev
, REL_X
, packet
[1] ? (int) packet
[1] - (int) ((packet
[0] << 4) & 0x100) : 0);
189 input_report_rel(dev
, REL_Y
, packet
[2] ? (int) ((packet
[0] << 3) & 0x100) - (int) packet
[2] : 0);
193 return PSMOUSE_FULL_PACKET
;
197 * __psmouse_set_state() sets new psmouse state and resets all flags.
200 static inline void __psmouse_set_state(struct psmouse
*psmouse
, enum psmouse_state new_state
)
202 psmouse
->state
= new_state
;
203 psmouse
->pktcnt
= psmouse
->out_of_sync
= 0;
204 psmouse
->ps2dev
.flags
= 0;
205 psmouse
->last
= jiffies
;
210 * psmouse_set_state() sets new psmouse state and resets all flags and
211 * counters while holding serio lock so fighting with interrupt handler
215 static void psmouse_set_state(struct psmouse
*psmouse
, enum psmouse_state new_state
)
217 serio_pause_rx(psmouse
->ps2dev
.serio
);
218 __psmouse_set_state(psmouse
, new_state
);
219 serio_continue_rx(psmouse
->ps2dev
.serio
);
223 * psmouse_handle_byte() processes one byte of the input data stream
224 * by calling corresponding protocol handler.
227 static int psmouse_handle_byte(struct psmouse
*psmouse
)
229 psmouse_ret_t rc
= psmouse
->protocol_handler(psmouse
);
232 case PSMOUSE_BAD_DATA
:
233 if (psmouse
->state
== PSMOUSE_ACTIVATED
) {
234 printk(KERN_WARNING
"psmouse.c: %s at %s lost sync at byte %d\n",
235 psmouse
->name
, psmouse
->phys
, psmouse
->pktcnt
);
236 if (++psmouse
->out_of_sync
== psmouse
->resetafter
) {
237 __psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
238 printk(KERN_NOTICE
"psmouse.c: issuing reconnect request\n");
239 serio_reconnect(psmouse
->ps2dev
.serio
);
246 case PSMOUSE_FULL_PACKET
:
248 if (psmouse
->out_of_sync
) {
249 psmouse
->out_of_sync
= 0;
250 printk(KERN_NOTICE
"psmouse.c: %s at %s - driver resynched.\n",
251 psmouse
->name
, psmouse
->phys
);
255 case PSMOUSE_GOOD_DATA
:
262 * psmouse_interrupt() handles incoming characters, either passing them
263 * for normal processing or gathering them as command response.
266 static irqreturn_t
psmouse_interrupt(struct serio
*serio
,
267 unsigned char data
, unsigned int flags
)
269 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
271 if (psmouse
->state
== PSMOUSE_IGNORE
)
274 if (flags
& (SERIO_PARITY
|SERIO_TIMEOUT
)) {
275 if (psmouse
->state
== PSMOUSE_ACTIVATED
)
276 printk(KERN_WARNING
"psmouse.c: bad data from KBC -%s%s\n",
277 flags
& SERIO_TIMEOUT
? " timeout" : "",
278 flags
& SERIO_PARITY
? " bad parity" : "");
279 ps2_cmd_aborted(&psmouse
->ps2dev
);
283 if (unlikely(psmouse
->ps2dev
.flags
& PS2_FLAG_ACK
))
284 if (ps2_handle_ack(&psmouse
->ps2dev
, data
))
287 if (unlikely(psmouse
->ps2dev
.flags
& PS2_FLAG_CMD
))
288 if (ps2_handle_response(&psmouse
->ps2dev
, data
))
291 if (psmouse
->state
<= PSMOUSE_RESYNCING
)
294 if (psmouse
->state
== PSMOUSE_ACTIVATED
&&
295 psmouse
->pktcnt
&& time_after(jiffies
, psmouse
->last
+ HZ
/2)) {
296 printk(KERN_INFO
"psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n",
297 psmouse
->name
, psmouse
->phys
, psmouse
->pktcnt
);
298 psmouse
->badbyte
= psmouse
->packet
[0];
299 __psmouse_set_state(psmouse
, PSMOUSE_RESYNCING
);
300 queue_work(kpsmoused_wq
, &psmouse
->resync_work
);
304 psmouse
->packet
[psmouse
->pktcnt
++] = data
;
306 * Check if this is a new device announcement (0xAA 0x00)
308 if (unlikely(psmouse
->packet
[0] == PSMOUSE_RET_BAT
&& psmouse
->pktcnt
<= 2)) {
309 if (psmouse
->pktcnt
== 1) {
310 psmouse
->last
= jiffies
;
314 if (psmouse
->packet
[1] == PSMOUSE_RET_ID
) {
315 __psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
316 serio_reconnect(serio
);
320 * Not a new device, try processing first byte normally
323 if (psmouse_handle_byte(psmouse
))
326 psmouse
->packet
[psmouse
->pktcnt
++] = data
;
330 * See if we need to force resync because mouse was idle for too long
332 if (psmouse
->state
== PSMOUSE_ACTIVATED
&&
333 psmouse
->pktcnt
== 1 && psmouse
->resync_time
&&
334 time_after(jiffies
, psmouse
->last
+ psmouse
->resync_time
* HZ
)) {
335 psmouse
->badbyte
= psmouse
->packet
[0];
336 __psmouse_set_state(psmouse
, PSMOUSE_RESYNCING
);
337 queue_work(kpsmoused_wq
, &psmouse
->resync_work
);
341 psmouse
->last
= jiffies
;
342 psmouse_handle_byte(psmouse
);
350 * psmouse_sliced_command() sends an extended PS/2 command to the mouse
351 * using sliced syntax, understood by advanced devices, such as Logitech
352 * or Synaptics touchpads. The command is encoded as:
353 * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
356 int psmouse_sliced_command(struct psmouse
*psmouse
, unsigned char command
)
360 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
))
363 for (i
= 6; i
>= 0; i
-= 2) {
364 unsigned char d
= (command
>> i
) & 3;
365 if (ps2_command(&psmouse
->ps2dev
, &d
, PSMOUSE_CMD_SETRES
))
374 * psmouse_reset() resets the mouse into power-on state.
376 int psmouse_reset(struct psmouse
*psmouse
)
378 unsigned char param
[2];
380 if (ps2_command(&psmouse
->ps2dev
, param
, PSMOUSE_CMD_RESET_BAT
))
383 if (param
[0] != PSMOUSE_RET_BAT
&& param
[1] != PSMOUSE_RET_ID
)
391 * Genius NetMouse magic init.
393 static int genius_detect(struct psmouse
*psmouse
, int set_properties
)
395 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
396 unsigned char param
[4];
399 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRES
);
400 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
);
401 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
);
402 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
);
403 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
);
405 if (param
[0] != 0x00 || param
[1] != 0x33 || param
[2] != 0x55)
408 if (set_properties
) {
409 set_bit(BTN_EXTRA
, psmouse
->dev
->keybit
);
410 set_bit(BTN_SIDE
, psmouse
->dev
->keybit
);
411 set_bit(REL_WHEEL
, psmouse
->dev
->relbit
);
413 psmouse
->vendor
= "Genius";
414 psmouse
->name
= "Mouse";
415 psmouse
->pktsize
= 4;
422 * IntelliMouse magic init.
424 static int intellimouse_detect(struct psmouse
*psmouse
, int set_properties
)
426 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
427 unsigned char param
[2];
430 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
432 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
434 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
435 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
440 if (set_properties
) {
441 set_bit(BTN_MIDDLE
, psmouse
->dev
->keybit
);
442 set_bit(REL_WHEEL
, psmouse
->dev
->relbit
);
444 if (!psmouse
->vendor
) psmouse
->vendor
= "Generic";
445 if (!psmouse
->name
) psmouse
->name
= "Wheel Mouse";
446 psmouse
->pktsize
= 4;
453 * Try IntelliMouse/Explorer magic init.
455 static int im_explorer_detect(struct psmouse
*psmouse
, int set_properties
)
457 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
458 unsigned char param
[2];
460 intellimouse_detect(psmouse
, 0);
463 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
465 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
467 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
468 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
473 /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
475 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
477 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
479 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
481 if (set_properties
) {
482 set_bit(BTN_MIDDLE
, psmouse
->dev
->keybit
);
483 set_bit(REL_WHEEL
, psmouse
->dev
->relbit
);
484 set_bit(REL_HWHEEL
, psmouse
->dev
->relbit
);
485 set_bit(BTN_SIDE
, psmouse
->dev
->keybit
);
486 set_bit(BTN_EXTRA
, psmouse
->dev
->keybit
);
488 if (!psmouse
->vendor
) psmouse
->vendor
= "Generic";
489 if (!psmouse
->name
) psmouse
->name
= "Explorer Mouse";
490 psmouse
->pktsize
= 4;
497 * Kensington ThinkingMouse / ExpertMouse magic init.
499 static int thinking_detect(struct psmouse
*psmouse
, int set_properties
)
501 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
502 unsigned char param
[2];
503 static const unsigned char seq
[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
507 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
509 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRES
);
510 for (i
= 0; i
< ARRAY_SIZE(seq
); i
++) {
512 ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
);
514 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
);
519 if (set_properties
) {
520 set_bit(BTN_EXTRA
, psmouse
->dev
->keybit
);
522 psmouse
->vendor
= "Kensington";
523 psmouse
->name
= "ThinkingMouse";
530 * Bare PS/2 protocol "detection". Always succeeds.
532 static int ps2bare_detect(struct psmouse
*psmouse
, int set_properties
)
534 if (set_properties
) {
535 if (!psmouse
->vendor
) psmouse
->vendor
= "Generic";
536 if (!psmouse
->name
) psmouse
->name
= "Mouse";
544 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
545 * the mouse may have.
548 static int psmouse_extensions(struct psmouse
*psmouse
,
549 unsigned int max_proto
, int set_properties
)
551 int synaptics_hardware
= 0;
554 * We always check for lifebook because it does not disturb mouse
555 * (it only checks DMI information).
557 if (lifebook_detect(psmouse
, set_properties
) == 0) {
558 if (max_proto
> PSMOUSE_IMEX
) {
559 if (!set_properties
|| lifebook_init(psmouse
) == 0)
560 return PSMOUSE_LIFEBOOK
;
565 * Try Kensington ThinkingMouse (we try first, because synaptics probe
566 * upsets the thinkingmouse).
569 if (max_proto
> PSMOUSE_IMEX
&& thinking_detect(psmouse
, set_properties
) == 0)
570 return PSMOUSE_THINKPS
;
573 * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol
574 * support is disabled in config - we need to know if it is synaptics so we
575 * can reset it properly after probing for intellimouse.
577 if (max_proto
> PSMOUSE_PS2
&& synaptics_detect(psmouse
, set_properties
) == 0) {
578 synaptics_hardware
= 1;
580 if (max_proto
> PSMOUSE_IMEX
) {
581 if (!set_properties
|| synaptics_init(psmouse
) == 0)
582 return PSMOUSE_SYNAPTICS
;
584 * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
585 * Unfortunately Logitech/Genius probes confuse some firmware versions so
586 * we'll have to skip them.
588 max_proto
= PSMOUSE_IMEX
;
591 * Make sure that touchpad is in relative mode, gestures (taps) are enabled
593 synaptics_reset(psmouse
);
599 if (max_proto
> PSMOUSE_IMEX
) {
600 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_RESET_DIS
);
601 if (alps_detect(psmouse
, set_properties
) == 0) {
602 if (!set_properties
|| alps_init(psmouse
) == 0)
605 * Init failed, try basic relative protocols
607 max_proto
= PSMOUSE_IMEX
;
611 if (max_proto
> PSMOUSE_IMEX
) {
613 if (genius_detect(psmouse
, set_properties
) == 0)
614 return PSMOUSE_GENPS
;
616 if (ps2pp_init(psmouse
, set_properties
) == 0)
617 return PSMOUSE_PS2PP
;
619 if (trackpoint_detect(psmouse
, set_properties
) == 0)
620 return PSMOUSE_TRACKPOINT
;
622 if (touchkit_ps2_detect(psmouse
, set_properties
) == 0)
623 return PSMOUSE_TOUCHKIT_PS2
;
627 * Reset to defaults in case the device got confused by extended
628 * protocol probes. Note that we do full reset becuase some mice
629 * put themselves to sleep when see PSMOUSE_RESET_DIS.
631 psmouse_reset(psmouse
);
633 if (max_proto
>= PSMOUSE_IMEX
&& im_explorer_detect(psmouse
, set_properties
) == 0)
636 if (max_proto
>= PSMOUSE_IMPS
&& intellimouse_detect(psmouse
, set_properties
) == 0)
640 * Okay, all failed, we have a standard mouse here. The number of the buttons
641 * is still a question, though. We assume 3.
643 ps2bare_detect(psmouse
, set_properties
);
645 if (synaptics_hardware
) {
647 * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
648 * We need to reset the touchpad because if there is a track point on the
649 * pass through port it could get disabled while probing for protocol
652 psmouse_reset(psmouse
);
658 static const struct psmouse_protocol psmouse_protocols
[] = {
664 .detect
= ps2bare_detect
,
666 #ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
668 .type
= PSMOUSE_PS2PP
,
671 .detect
= ps2pp_init
,
675 .type
= PSMOUSE_THINKPS
,
678 .detect
= thinking_detect
,
681 .type
= PSMOUSE_GENPS
,
684 .detect
= genius_detect
,
687 .type
= PSMOUSE_IMPS
,
691 .detect
= intellimouse_detect
,
694 .type
= PSMOUSE_IMEX
,
698 .detect
= im_explorer_detect
,
700 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
702 .type
= PSMOUSE_SYNAPTICS
,
704 .alias
= "synaptics",
705 .detect
= synaptics_detect
,
706 .init
= synaptics_init
,
709 #ifdef CONFIG_MOUSE_PS2_ALPS
711 .type
= PSMOUSE_ALPS
,
714 .detect
= alps_detect
,
718 #ifdef CONFIG_MOUSE_PS2_LIFEBOOK
720 .type
= PSMOUSE_LIFEBOOK
,
723 .init
= lifebook_init
,
726 #ifdef CONFIG_MOUSE_PS2_TRACKPOINT
728 .type
= PSMOUSE_TRACKPOINT
,
730 .alias
= "trackpoint",
731 .detect
= trackpoint_detect
,
734 #ifdef CONFIG_MOUSE_PS2_TOUCHKIT
736 .type
= PSMOUSE_TOUCHKIT_PS2
,
737 .name
= "touchkitPS/2",
739 .detect
= touchkit_ps2_detect
,
743 .type
= PSMOUSE_AUTO
,
750 static const struct psmouse_protocol
*psmouse_protocol_by_type(enum psmouse_type type
)
754 for (i
= 0; i
< ARRAY_SIZE(psmouse_protocols
); i
++)
755 if (psmouse_protocols
[i
].type
== type
)
756 return &psmouse_protocols
[i
];
759 return &psmouse_protocols
[0];
762 static const struct psmouse_protocol
*psmouse_protocol_by_name(const char *name
, size_t len
)
764 const struct psmouse_protocol
*p
;
767 for (i
= 0; i
< ARRAY_SIZE(psmouse_protocols
); i
++) {
768 p
= &psmouse_protocols
[i
];
770 if ((strlen(p
->name
) == len
&& !strncmp(p
->name
, name
, len
)) ||
771 (strlen(p
->alias
) == len
&& !strncmp(p
->alias
, name
, len
)))
772 return &psmouse_protocols
[i
];
780 * psmouse_probe() probes for a PS/2 mouse.
783 static int psmouse_probe(struct psmouse
*psmouse
)
785 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
786 unsigned char param
[2];
789 * First, we check if it's a mouse. It should send 0x00 or 0x03
790 * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
791 * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent
792 * ID queries, probably due to a firmware bug.
796 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
))
799 if (param
[0] != 0x00 && param
[0] != 0x03 &&
800 param
[0] != 0x04 && param
[0] != 0xff)
804 * Then we reset and disable the mouse so that it doesn't generate events.
807 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_DIS
))
808 printk(KERN_WARNING
"psmouse.c: Failed to reset mouse on %s\n", ps2dev
->serio
->phys
);
814 * Here we set the mouse resolution.
817 void psmouse_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
)
819 static const unsigned char params
[] = { 0, 1, 2, 2, 3 };
822 if (resolution
== 0 || resolution
> 200)
825 p
= params
[resolution
/ 50];
826 ps2_command(&psmouse
->ps2dev
, &p
, PSMOUSE_CMD_SETRES
);
827 psmouse
->resolution
= 25 << p
;
831 * Here we set the mouse report rate.
834 static void psmouse_set_rate(struct psmouse
*psmouse
, unsigned int rate
)
836 static const unsigned char rates
[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
840 while (rates
[i
] > rate
) i
++;
842 ps2_command(&psmouse
->ps2dev
, &r
, PSMOUSE_CMD_SETRATE
);
847 * psmouse_initialize() initializes the mouse to a sane state.
850 static void psmouse_initialize(struct psmouse
*psmouse
)
853 * We set the mouse report rate, resolution and scaling.
856 if (psmouse_max_proto
!= PSMOUSE_PS2
) {
857 psmouse
->set_rate(psmouse
, psmouse
->rate
);
858 psmouse
->set_resolution(psmouse
, psmouse
->resolution
);
859 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
);
864 * psmouse_activate() enables the mouse so that we get motion reports from it.
867 static void psmouse_activate(struct psmouse
*psmouse
)
869 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
))
870 printk(KERN_WARNING
"psmouse.c: Failed to enable mouse on %s\n",
871 psmouse
->ps2dev
.serio
->phys
);
873 psmouse_set_state(psmouse
, PSMOUSE_ACTIVATED
);
878 * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion
879 * reports from it unless we explicitely request it.
882 static void psmouse_deactivate(struct psmouse
*psmouse
)
884 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
))
885 printk(KERN_WARNING
"psmouse.c: Failed to deactivate mouse on %s\n",
886 psmouse
->ps2dev
.serio
->phys
);
888 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
892 * psmouse_poll() - default poll hanlder. Everyone except for ALPS uses it.
895 static int psmouse_poll(struct psmouse
*psmouse
)
897 return ps2_command(&psmouse
->ps2dev
, psmouse
->packet
,
898 PSMOUSE_CMD_POLL
| (psmouse
->pktsize
<< 8));
903 * psmouse_resync() attempts to re-validate current protocol.
906 static void psmouse_resync(struct work_struct
*work
)
908 struct psmouse
*parent
= NULL
, *psmouse
=
909 container_of(work
, struct psmouse
, resync_work
);
910 struct serio
*serio
= psmouse
->ps2dev
.serio
;
911 psmouse_ret_t rc
= PSMOUSE_GOOD_DATA
;
912 int failed
= 0, enabled
= 0;
915 mutex_lock(&psmouse_mutex
);
917 if (psmouse
->state
!= PSMOUSE_RESYNCING
)
920 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
921 parent
= serio_get_drvdata(serio
->parent
);
922 psmouse_deactivate(parent
);
926 * Some mice don't ACK commands sent while they are in the middle of
927 * transmitting motion packet. To avoid delay we use ps2_sendbyte()
928 * instead of ps2_command() which would wait for 200ms for an ACK
929 * that may never come.
930 * As an additional quirk ALPS touchpads may not only forget to ACK
931 * disable command but will stop reporting taps, so if we see that
932 * mouse at least once ACKs disable we will do full reconnect if ACK
935 psmouse
->num_resyncs
++;
937 if (ps2_sendbyte(&psmouse
->ps2dev
, PSMOUSE_CMD_DISABLE
, 20)) {
938 if (psmouse
->num_resyncs
< 3 || psmouse
->acks_disable_command
)
941 psmouse
->acks_disable_command
= 1;
944 * Poll the mouse. If it was reset the packet will be shorter than
945 * psmouse->pktsize and ps2_command will fail. We do not expect and
946 * do not handle scenario when mouse "upgrades" its protocol while
947 * disconnected since it would require additional delay. If we ever
948 * see a mouse that does it we'll adjust the code.
951 if (psmouse
->poll(psmouse
))
954 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
955 for (i
= 0; i
< psmouse
->pktsize
; i
++) {
957 rc
= psmouse
->protocol_handler(psmouse
);
958 if (rc
!= PSMOUSE_GOOD_DATA
)
961 if (rc
!= PSMOUSE_FULL_PACKET
)
963 psmouse_set_state(psmouse
, PSMOUSE_RESYNCING
);
967 * Now try to enable mouse. We try to do that even if poll failed and also
968 * repeat our attempts 5 times, otherwise we may be left out with disabled
971 for (i
= 0; i
< 5; i
++) {
972 if (!ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
)) {
980 printk(KERN_WARNING
"psmouse.c: failed to re-enable mouse on %s\n",
981 psmouse
->ps2dev
.serio
->phys
);
986 psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
987 printk(KERN_INFO
"psmouse.c: resync failed, issuing reconnect request\n");
988 serio_reconnect(serio
);
990 psmouse_set_state(psmouse
, PSMOUSE_ACTIVATED
);
993 psmouse_activate(parent
);
995 mutex_unlock(&psmouse_mutex
);
999 * psmouse_cleanup() resets the mouse into power-on state.
1002 static void psmouse_cleanup(struct serio
*serio
)
1004 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
1005 struct psmouse
*parent
= NULL
;
1007 mutex_lock(&psmouse_mutex
);
1009 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
1010 parent
= serio_get_drvdata(serio
->parent
);
1011 psmouse_deactivate(parent
);
1014 psmouse_deactivate(psmouse
);
1016 if (psmouse
->cleanup
)
1017 psmouse
->cleanup(psmouse
);
1019 psmouse_reset(psmouse
);
1022 * Some boxes, such as HP nx7400, get terribly confused if mouse
1023 * is not fully enabled before suspending/shutting down.
1025 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
1028 if (parent
->pt_deactivate
)
1029 parent
->pt_deactivate(parent
);
1031 psmouse_activate(parent
);
1034 mutex_unlock(&psmouse_mutex
);
1038 * psmouse_disconnect() closes and frees.
1041 static void psmouse_disconnect(struct serio
*serio
)
1043 struct psmouse
*psmouse
, *parent
= NULL
;
1045 psmouse
= serio_get_drvdata(serio
);
1047 sysfs_remove_group(&serio
->dev
.kobj
, &psmouse_attribute_group
);
1049 mutex_lock(&psmouse_mutex
);
1051 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
1053 /* make sure we don't have a resync in progress */
1054 mutex_unlock(&psmouse_mutex
);
1055 flush_workqueue(kpsmoused_wq
);
1056 mutex_lock(&psmouse_mutex
);
1058 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
1059 parent
= serio_get_drvdata(serio
->parent
);
1060 psmouse_deactivate(parent
);
1063 if (psmouse
->disconnect
)
1064 psmouse
->disconnect(psmouse
);
1066 if (parent
&& parent
->pt_deactivate
)
1067 parent
->pt_deactivate(parent
);
1069 psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
1072 serio_set_drvdata(serio
, NULL
);
1073 input_unregister_device(psmouse
->dev
);
1077 psmouse_activate(parent
);
1079 mutex_unlock(&psmouse_mutex
);
1082 static int psmouse_switch_protocol(struct psmouse
*psmouse
, const struct psmouse_protocol
*proto
)
1084 struct input_dev
*input_dev
= psmouse
->dev
;
1086 input_dev
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
1088 input_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_REL
);
1089 input_dev
->keybit
[LONG(BTN_MOUSE
)] = BIT(BTN_LEFT
) | BIT(BTN_MIDDLE
) | BIT(BTN_RIGHT
);
1090 input_dev
->relbit
[0] = BIT(REL_X
) | BIT(REL_Y
);
1092 psmouse
->set_rate
= psmouse_set_rate
;
1093 psmouse
->set_resolution
= psmouse_set_resolution
;
1094 psmouse
->poll
= psmouse_poll
;
1095 psmouse
->protocol_handler
= psmouse_process_byte
;
1096 psmouse
->pktsize
= 3;
1098 if (proto
&& (proto
->detect
|| proto
->init
)) {
1099 if (proto
->detect
&& proto
->detect(psmouse
, 1) < 0)
1102 if (proto
->init
&& proto
->init(psmouse
) < 0)
1105 psmouse
->type
= proto
->type
;
1108 psmouse
->type
= psmouse_extensions(psmouse
, psmouse_max_proto
, 1);
1111 * If mouse's packet size is 3 there is no point in polling the
1112 * device in hopes to detect protocol reset - we won't get less
1113 * than 3 bytes response anyhow.
1115 if (psmouse
->pktsize
== 3)
1116 psmouse
->resync_time
= 0;
1119 * Some smart KVMs fake response to POLL command returning just
1120 * 3 bytes and messing up our resync logic, so if initial poll
1121 * fails we won't try polling the device anymore. Hopefully
1122 * such KVM will maintain initially selected protocol.
1124 if (psmouse
->resync_time
&& psmouse
->poll(psmouse
))
1125 psmouse
->resync_time
= 0;
1127 snprintf(psmouse
->devname
, sizeof(psmouse
->devname
), "%s %s %s",
1128 psmouse_protocol_by_type(psmouse
->type
)->name
, psmouse
->vendor
, psmouse
->name
);
1130 input_dev
->name
= psmouse
->devname
;
1131 input_dev
->phys
= psmouse
->phys
;
1132 input_dev
->id
.bustype
= BUS_I8042
;
1133 input_dev
->id
.vendor
= 0x0002;
1134 input_dev
->id
.product
= psmouse
->type
;
1135 input_dev
->id
.version
= psmouse
->model
;
1141 * psmouse_connect() is a callback from the serio module when
1142 * an unhandled serio port is found.
1144 static int psmouse_connect(struct serio
*serio
, struct serio_driver
*drv
)
1146 struct psmouse
*psmouse
, *parent
= NULL
;
1147 struct input_dev
*input_dev
;
1148 int retval
= 0, error
= -ENOMEM
;
1150 mutex_lock(&psmouse_mutex
);
1153 * If this is a pass-through port deactivate parent so the device
1154 * connected to this port can be successfully identified
1156 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
1157 parent
= serio_get_drvdata(serio
->parent
);
1158 psmouse_deactivate(parent
);
1161 psmouse
= kzalloc(sizeof(struct psmouse
), GFP_KERNEL
);
1162 input_dev
= input_allocate_device();
1163 if (!psmouse
|| !input_dev
)
1166 ps2_init(&psmouse
->ps2dev
, serio
);
1167 INIT_WORK(&psmouse
->resync_work
, psmouse_resync
);
1168 psmouse
->dev
= input_dev
;
1169 snprintf(psmouse
->phys
, sizeof(psmouse
->phys
), "%s/input0", serio
->phys
);
1171 psmouse_set_state(psmouse
, PSMOUSE_INITIALIZING
);
1173 serio_set_drvdata(serio
, psmouse
);
1175 error
= serio_open(serio
, drv
);
1177 goto err_clear_drvdata
;
1179 if (psmouse_probe(psmouse
) < 0) {
1181 goto err_close_serio
;
1184 psmouse
->rate
= psmouse_rate
;
1185 psmouse
->resolution
= psmouse_resolution
;
1186 psmouse
->resetafter
= psmouse_resetafter
;
1187 psmouse
->resync_time
= parent
? 0 : psmouse_resync_time
;
1188 psmouse
->smartscroll
= psmouse_smartscroll
;
1190 psmouse_switch_protocol(psmouse
, NULL
);
1192 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
1193 psmouse_initialize(psmouse
);
1195 error
= input_register_device(psmouse
->dev
);
1197 goto err_protocol_disconnect
;
1199 if (parent
&& parent
->pt_activate
)
1200 parent
->pt_activate(parent
);
1202 error
= sysfs_create_group(&serio
->dev
.kobj
, &psmouse_attribute_group
);
1204 goto err_pt_deactivate
;
1206 psmouse_activate(psmouse
);
1209 /* If this is a pass-through port the parent needs to be re-activated */
1211 psmouse_activate(parent
);
1213 mutex_unlock(&psmouse_mutex
);
1217 if (parent
&& parent
->pt_deactivate
)
1218 parent
->pt_deactivate(parent
);
1219 err_protocol_disconnect
:
1220 if (psmouse
->disconnect
)
1221 psmouse
->disconnect(psmouse
);
1222 psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
1226 serio_set_drvdata(serio
, NULL
);
1228 input_free_device(input_dev
);
1236 static int psmouse_reconnect(struct serio
*serio
)
1238 struct psmouse
*psmouse
= serio_get_drvdata(serio
);
1239 struct psmouse
*parent
= NULL
;
1240 struct serio_driver
*drv
= serio
->drv
;
1243 if (!drv
|| !psmouse
) {
1244 printk(KERN_DEBUG
"psmouse: reconnect request, but serio is disconnected, ignoring...\n");
1248 mutex_lock(&psmouse_mutex
);
1250 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
1251 parent
= serio_get_drvdata(serio
->parent
);
1252 psmouse_deactivate(parent
);
1255 psmouse_set_state(psmouse
, PSMOUSE_INITIALIZING
);
1257 if (psmouse
->reconnect
) {
1258 if (psmouse
->reconnect(psmouse
))
1260 } else if (psmouse_probe(psmouse
) < 0 ||
1261 psmouse
->type
!= psmouse_extensions(psmouse
, psmouse_max_proto
, 0))
1264 /* ok, the device type (and capabilities) match the old one,
1265 * we can continue using it, complete intialization
1267 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
1269 psmouse_initialize(psmouse
);
1271 if (parent
&& parent
->pt_activate
)
1272 parent
->pt_activate(parent
);
1274 psmouse_activate(psmouse
);
1278 /* If this is a pass-through port the parent waits to be activated */
1280 psmouse_activate(parent
);
1282 mutex_unlock(&psmouse_mutex
);
1286 static struct serio_device_id psmouse_serio_ids
[] = {
1294 .type
= SERIO_PS_PSTHRU
,
1302 MODULE_DEVICE_TABLE(serio
, psmouse_serio_ids
);
1304 static struct serio_driver psmouse_drv
= {
1308 .description
= DRIVER_DESC
,
1309 .id_table
= psmouse_serio_ids
,
1310 .interrupt
= psmouse_interrupt
,
1311 .connect
= psmouse_connect
,
1312 .reconnect
= psmouse_reconnect
,
1313 .disconnect
= psmouse_disconnect
,
1314 .cleanup
= psmouse_cleanup
,
1317 ssize_t
psmouse_attr_show_helper(struct device
*dev
, struct device_attribute
*devattr
,
1320 struct serio
*serio
= to_serio_port(dev
);
1321 struct psmouse_attribute
*attr
= to_psmouse_attr(devattr
);
1322 struct psmouse
*psmouse
;
1325 retval
= serio_pin_driver(serio
);
1329 if (serio
->drv
!= &psmouse_drv
) {
1334 psmouse
= serio_get_drvdata(serio
);
1336 retval
= attr
->show(psmouse
, attr
->data
, buf
);
1339 serio_unpin_driver(serio
);
1343 ssize_t
psmouse_attr_set_helper(struct device
*dev
, struct device_attribute
*devattr
,
1344 const char *buf
, size_t count
)
1346 struct serio
*serio
= to_serio_port(dev
);
1347 struct psmouse_attribute
*attr
= to_psmouse_attr(devattr
);
1348 struct psmouse
*psmouse
, *parent
= NULL
;
1351 retval
= serio_pin_driver(serio
);
1355 if (serio
->drv
!= &psmouse_drv
) {
1360 retval
= mutex_lock_interruptible(&psmouse_mutex
);
1364 psmouse
= serio_get_drvdata(serio
);
1366 if (psmouse
->state
== PSMOUSE_IGNORE
) {
1371 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
1372 parent
= serio_get_drvdata(serio
->parent
);
1373 psmouse_deactivate(parent
);
1376 psmouse_deactivate(psmouse
);
1378 retval
= attr
->set(psmouse
, attr
->data
, buf
, count
);
1380 if (retval
!= -ENODEV
)
1381 psmouse_activate(psmouse
);
1384 psmouse_activate(parent
);
1387 mutex_unlock(&psmouse_mutex
);
1389 serio_unpin_driver(serio
);
1393 static ssize_t
psmouse_show_int_attr(struct psmouse
*psmouse
, void *offset
, char *buf
)
1395 unsigned int *field
= (unsigned int *)((char *)psmouse
+ (size_t)offset
);
1397 return sprintf(buf
, "%u\n", *field
);
1400 static ssize_t
psmouse_set_int_attr(struct psmouse
*psmouse
, void *offset
, const char *buf
, size_t count
)
1402 unsigned int *field
= (unsigned int *)((char *)psmouse
+ (size_t)offset
);
1403 unsigned long value
;
1406 value
= simple_strtoul(buf
, &rest
, 10);
1410 if ((unsigned int)value
!= value
)
1418 static ssize_t
psmouse_attr_show_protocol(struct psmouse
*psmouse
, void *data
, char *buf
)
1420 return sprintf(buf
, "%s\n", psmouse_protocol_by_type(psmouse
->type
)->name
);
1423 static ssize_t
psmouse_attr_set_protocol(struct psmouse
*psmouse
, void *data
, const char *buf
, size_t count
)
1425 struct serio
*serio
= psmouse
->ps2dev
.serio
;
1426 struct psmouse
*parent
= NULL
;
1427 struct input_dev
*old_dev
, *new_dev
;
1428 const struct psmouse_protocol
*proto
, *old_proto
;
1432 proto
= psmouse_protocol_by_name(buf
, count
);
1436 if (psmouse
->type
== proto
->type
)
1439 new_dev
= input_allocate_device();
1443 while (serio
->child
) {
1445 printk(KERN_WARNING
"psmouse: failed to destroy child port, protocol change aborted.\n");
1446 input_free_device(new_dev
);
1450 mutex_unlock(&psmouse_mutex
);
1451 serio_unpin_driver(serio
);
1452 serio_unregister_child_port(serio
);
1453 serio_pin_driver_uninterruptible(serio
);
1454 mutex_lock(&psmouse_mutex
);
1456 if (serio
->drv
!= &psmouse_drv
) {
1457 input_free_device(new_dev
);
1461 if (psmouse
->type
== proto
->type
) {
1462 input_free_device(new_dev
);
1463 return count
; /* switched by other thread */
1467 if (serio
->parent
&& serio
->id
.type
== SERIO_PS_PSTHRU
) {
1468 parent
= serio_get_drvdata(serio
->parent
);
1469 if (parent
->pt_deactivate
)
1470 parent
->pt_deactivate(parent
);
1473 old_dev
= psmouse
->dev
;
1474 old_proto
= psmouse_protocol_by_type(psmouse
->type
);
1476 if (psmouse
->disconnect
)
1477 psmouse
->disconnect(psmouse
);
1479 psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
1481 psmouse
->dev
= new_dev
;
1482 psmouse_set_state(psmouse
, PSMOUSE_INITIALIZING
);
1484 if (psmouse_switch_protocol(psmouse
, proto
) < 0) {
1485 psmouse_reset(psmouse
);
1486 /* default to PSMOUSE_PS2 */
1487 psmouse_switch_protocol(psmouse
, &psmouse_protocols
[0]);
1490 psmouse_initialize(psmouse
);
1491 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
1493 error
= input_register_device(psmouse
->dev
);
1495 if (psmouse
->disconnect
)
1496 psmouse
->disconnect(psmouse
);
1498 psmouse_set_state(psmouse
, PSMOUSE_IGNORE
);
1499 input_free_device(new_dev
);
1500 psmouse
->dev
= old_dev
;
1501 psmouse_set_state(psmouse
, PSMOUSE_INITIALIZING
);
1502 psmouse_switch_protocol(psmouse
, old_proto
);
1503 psmouse_initialize(psmouse
);
1504 psmouse_set_state(psmouse
, PSMOUSE_CMD_MODE
);
1509 input_unregister_device(old_dev
);
1511 if (parent
&& parent
->pt_activate
)
1512 parent
->pt_activate(parent
);
1517 static ssize_t
psmouse_attr_set_rate(struct psmouse
*psmouse
, void *data
, const char *buf
, size_t count
)
1519 unsigned long value
;
1522 value
= simple_strtoul(buf
, &rest
, 10);
1526 psmouse
->set_rate(psmouse
, value
);
1530 static ssize_t
psmouse_attr_set_resolution(struct psmouse
*psmouse
, void *data
, const char *buf
, size_t count
)
1532 unsigned long value
;
1535 value
= simple_strtoul(buf
, &rest
, 10);
1539 psmouse
->set_resolution(psmouse
, value
);
1544 static int psmouse_set_maxproto(const char *val
, struct kernel_param
*kp
)
1546 const struct psmouse_protocol
*proto
;
1551 proto
= psmouse_protocol_by_name(val
, strlen(val
));
1553 if (!proto
|| !proto
->maxproto
)
1556 *((unsigned int *)kp
->arg
) = proto
->type
;
1561 static int psmouse_get_maxproto(char *buffer
, struct kernel_param
*kp
)
1563 int type
= *((unsigned int *)kp
->arg
);
1565 return sprintf(buffer
, "%s\n", psmouse_protocol_by_type(type
)->name
);
1568 static int __init
psmouse_init(void)
1572 kpsmoused_wq
= create_singlethread_workqueue("kpsmoused");
1573 if (!kpsmoused_wq
) {
1574 printk(KERN_ERR
"psmouse: failed to create kpsmoused workqueue\n");
1578 err
= serio_register_driver(&psmouse_drv
);
1580 destroy_workqueue(kpsmoused_wq
);
1585 static void __exit
psmouse_exit(void)
1587 serio_unregister_driver(&psmouse_drv
);
1588 destroy_workqueue(kpsmoused_wq
);
1591 module_init(psmouse_init
);
1592 module_exit(psmouse_exit
);