blob: 6f9b2c7cc9c28903c05a51b682975c112996d129 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Ingo Molnarc14471d2006-02-19 00:22:11 -050023#include <linux/mutex.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "psmouse.h"
26#include "synaptics.h"
27#include "logips2pp.h"
28#include "alps.h"
Kenan Esau02d7f582005-05-29 02:30:22 -050029#include "lifebook.h"
Stephen Evanchik541e3162005-08-08 01:26:18 -050030#include "trackpoint.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#define DRIVER_DESC "PS/2 mouse driver"
33
34MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
35MODULE_DESCRIPTION(DRIVER_DESC);
36MODULE_LICENSE("GPL");
37
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -050038static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static int psmouse_set_maxproto(const char *val, struct kernel_param *kp);
40static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
42#define param_set_proto_abbrev psmouse_set_maxproto
43#define param_get_proto_abbrev psmouse_get_maxproto
44module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -050045MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47static unsigned int psmouse_resolution = 200;
48module_param_named(resolution, psmouse_resolution, uint, 0644);
49MODULE_PARM_DESC(resolution, "Resolution, in dpi.");
50
51static unsigned int psmouse_rate = 100;
52module_param_named(rate, psmouse_rate, uint, 0644);
53MODULE_PARM_DESC(rate, "Report rate, in reports per second.");
54
55static unsigned int psmouse_smartscroll = 1;
56module_param_named(smartscroll, psmouse_smartscroll, bool, 0644);
57MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
58
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050059static unsigned int psmouse_resetafter = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060module_param_named(resetafter, psmouse_resetafter, uint, 0644);
61MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
62
Dmitry Torokhov8bd0ee92006-03-11 00:23:38 -050063static unsigned int psmouse_resync_time;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050064module_param_named(resync_time, psmouse_resync_time, uint, 0644);
65MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never).");
66
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -050067PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
68 NULL,
69 psmouse_attr_show_protocol, psmouse_attr_set_protocol);
70PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO,
71 (void *) offsetof(struct psmouse, rate),
72 psmouse_show_int_attr, psmouse_attr_set_rate);
73PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
74 (void *) offsetof(struct psmouse, resolution),
75 psmouse_show_int_attr, psmouse_attr_set_resolution);
76PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
77 (void *) offsetof(struct psmouse, resetafter),
78 psmouse_show_int_attr, psmouse_set_int_attr);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050079PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO,
80 (void *) offsetof(struct psmouse, resync_time),
81 psmouse_show_int_attr, psmouse_set_int_attr);
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -050082
83static struct attribute *psmouse_attributes[] = {
84 &psmouse_attr_protocol.dattr.attr,
85 &psmouse_attr_rate.dattr.attr,
86 &psmouse_attr_resolution.dattr.attr,
87 &psmouse_attr_resetafter.dattr.attr,
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -050088 &psmouse_attr_resync_time.dattr.attr,
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -050089 NULL
90};
91
92static struct attribute_group psmouse_attribute_group = {
93 .attrs = psmouse_attributes,
94};
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96__obsolete_setup("psmouse_noext");
97__obsolete_setup("psmouse_resolution=");
98__obsolete_setup("psmouse_smartscroll=");
99__obsolete_setup("psmouse_resetafter=");
100__obsolete_setup("psmouse_rate=");
101
Dmitry Torokhov04df1922005-06-01 02:39:44 -0500102/*
Ingo Molnarc14471d2006-02-19 00:22:11 -0500103 * psmouse_mutex protects all operations changing state of mouse
Dmitry Torokhov04df1922005-06-01 02:39:44 -0500104 * (connecting, disconnecting, changing rate or resolution via
105 * sysfs). We could use a per-device semaphore but since there
106 * rarely more than one PS/2 mouse connected and since semaphore
107 * is taken in "slow" paths it is not worth it.
108 */
Ingo Molnarc14471d2006-02-19 00:22:11 -0500109static DEFINE_MUTEX(psmouse_mutex);
Dmitry Torokhov04df1922005-06-01 02:39:44 -0500110
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500111static struct workqueue_struct *kpsmoused_wq;
112
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500113struct psmouse_protocol {
114 enum psmouse_type type;
Helge Dellere38de672006-09-10 21:54:39 -0400115 const char *name;
116 const char *alias;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500117 int maxproto;
118 int (*detect)(struct psmouse *, int);
119 int (*init)(struct psmouse *);
120};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122/*
123 * psmouse_process_byte() analyzes the PS/2 data stream and reports
124 * relevant events to the input module once full packet has arrived.
125 */
126
David Howells7d12e782006-10-05 14:55:46 +0100127static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500129 struct input_dev *dev = psmouse->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned char *packet = psmouse->packet;
131
132 if (psmouse->pktcnt < psmouse->pktsize)
133 return PSMOUSE_GOOD_DATA;
134
135/*
136 * Full packet accumulated, process it
137 */
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/*
140 * Scroll wheel on IntelliMice, scroll buttons on NetMice
141 */
142
143 if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS)
144 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
145
146/*
147 * Scroll wheel and buttons on IntelliMouse Explorer
148 */
149
150 if (psmouse->type == PSMOUSE_IMEX) {
Pozsar Balazsb0c9ad82006-06-26 01:56:08 -0400151 switch (packet[3] & 0xC0) {
152 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
153 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
154 break;
155 case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */
156 input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
157 break;
158 case 0x00:
159 case 0xC0:
160 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7));
161 input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1);
162 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1);
163 break;
164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
167/*
168 * Extra buttons on Genius NewNet 3D
169 */
170
171 if (psmouse->type == PSMOUSE_GENPS) {
172 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
173 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
174 }
175
176/*
177 * Extra button on ThinkingMouse
178 */
179 if (psmouse->type == PSMOUSE_THINKPS) {
180 input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1);
181 /* Without this bit of weirdness moving up gives wildly high Y changes. */
182 packet[1] |= (packet[0] & 0x40) << 1;
183 }
184
185/*
186 * Generic PS/2 Mouse
187 */
188
189 input_report_key(dev, BTN_LEFT, packet[0] & 1);
190 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
191 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
192
193 input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
194 input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
195
196 input_sync(dev);
197
198 return PSMOUSE_FULL_PACKET;
199}
200
201/*
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500202 * __psmouse_set_state() sets new psmouse state and resets all flags.
203 */
204
205static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
206{
207 psmouse->state = new_state;
208 psmouse->pktcnt = psmouse->out_of_sync = 0;
209 psmouse->ps2dev.flags = 0;
210 psmouse->last = jiffies;
211}
212
213
214/*
215 * psmouse_set_state() sets new psmouse state and resets all flags and
216 * counters while holding serio lock so fighting with interrupt handler
217 * is not a concern.
218 */
219
220static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
221{
222 serio_pause_rx(psmouse->ps2dev.serio);
223 __psmouse_set_state(psmouse, new_state);
224 serio_continue_rx(psmouse->ps2dev.serio);
225}
226
227/*
228 * psmouse_handle_byte() processes one byte of the input data stream
229 * by calling corresponding protocol handler.
230 */
231
David Howells7d12e782006-10-05 14:55:46 +0100232static int psmouse_handle_byte(struct psmouse *psmouse)
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500233{
David Howells7d12e782006-10-05 14:55:46 +0100234 psmouse_ret_t rc = psmouse->protocol_handler(psmouse);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500235
236 switch (rc) {
237 case PSMOUSE_BAD_DATA:
238 if (psmouse->state == PSMOUSE_ACTIVATED) {
239 printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n",
240 psmouse->name, psmouse->phys, psmouse->pktcnt);
241 if (++psmouse->out_of_sync == psmouse->resetafter) {
242 __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
243 printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n");
244 serio_reconnect(psmouse->ps2dev.serio);
245 return -1;
246 }
247 }
248 psmouse->pktcnt = 0;
249 break;
250
251 case PSMOUSE_FULL_PACKET:
252 psmouse->pktcnt = 0;
253 if (psmouse->out_of_sync) {
254 psmouse->out_of_sync = 0;
255 printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n",
256 psmouse->name, psmouse->phys);
257 }
258 break;
259
260 case PSMOUSE_GOOD_DATA:
261 break;
262 }
263 return 0;
264}
265
266/*
267 * psmouse_interrupt() handles incoming characters, either passing them
268 * for normal processing or gathering them as command response.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 */
270
271static irqreturn_t psmouse_interrupt(struct serio *serio,
David Howells7d12e782006-10-05 14:55:46 +0100272 unsigned char data, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
274 struct psmouse *psmouse = serio_get_drvdata(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 if (psmouse->state == PSMOUSE_IGNORE)
277 goto out;
278
279 if (flags & (SERIO_PARITY|SERIO_TIMEOUT)) {
280 if (psmouse->state == PSMOUSE_ACTIVATED)
281 printk(KERN_WARNING "psmouse.c: bad data from KBC -%s%s\n",
282 flags & SERIO_TIMEOUT ? " timeout" : "",
283 flags & SERIO_PARITY ? " bad parity" : "");
284 ps2_cmd_aborted(&psmouse->ps2dev);
285 goto out;
286 }
287
288 if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK))
289 if (ps2_handle_ack(&psmouse->ps2dev, data))
290 goto out;
291
292 if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_CMD))
293 if (ps2_handle_response(&psmouse->ps2dev, data))
294 goto out;
295
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500296 if (psmouse->state <= PSMOUSE_RESYNCING)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 goto out;
298
299 if (psmouse->state == PSMOUSE_ACTIVATED &&
300 psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500301 printk(KERN_INFO "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 psmouse->name, psmouse->phys, psmouse->pktcnt);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500303 psmouse->badbyte = psmouse->packet[0];
304 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
305 queue_work(kpsmoused_wq, &psmouse->resync_work);
306 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 psmouse->packet[psmouse->pktcnt++] = data;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500310/*
311 * Check if this is a new device announcement (0xAA 0x00)
312 */
313 if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) {
Dmitry Torokhov89c9b482006-04-29 01:12:44 -0400314 if (psmouse->pktcnt == 1) {
315 psmouse->last = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 goto out;
Dmitry Torokhov89c9b482006-04-29 01:12:44 -0400317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500319 if (psmouse->packet[1] == PSMOUSE_RET_ID) {
320 __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
321 serio_reconnect(serio);
322 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500324/*
325 * Not a new device, try processing first byte normally
326 */
327 psmouse->pktcnt = 1;
David Howells7d12e782006-10-05 14:55:46 +0100328 if (psmouse_handle_byte(psmouse))
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500329 goto out;
330
331 psmouse->packet[psmouse->pktcnt++] = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500334/*
335 * See if we need to force resync because mouse was idle for too long
336 */
337 if (psmouse->state == PSMOUSE_ACTIVATED &&
338 psmouse->pktcnt == 1 && psmouse->resync_time &&
339 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
340 psmouse->badbyte = psmouse->packet[0];
341 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
342 queue_work(kpsmoused_wq, &psmouse->resync_work);
343 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500345
346 psmouse->last = jiffies;
David Howells7d12e782006-10-05 14:55:46 +0100347 psmouse_handle_byte(psmouse);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500348
349 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return IRQ_HANDLED;
351}
352
353
354/*
355 * psmouse_sliced_command() sends an extended PS/2 command to the mouse
356 * using sliced syntax, understood by advanced devices, such as Logitech
357 * or Synaptics touchpads. The command is encoded as:
358 * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
359 * is the command.
360 */
361int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command)
362{
363 int i;
364
365 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
366 return -1;
367
368 for (i = 6; i >= 0; i -= 2) {
369 unsigned char d = (command >> i) & 3;
370 if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES))
371 return -1;
372 }
373
374 return 0;
375}
376
377
378/*
379 * psmouse_reset() resets the mouse into power-on state.
380 */
381int psmouse_reset(struct psmouse *psmouse)
382{
383 unsigned char param[2];
384
385 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT))
386 return -1;
387
388 if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID)
389 return -1;
390
391 return 0;
392}
393
394
395/*
396 * Genius NetMouse magic init.
397 */
398static int genius_detect(struct psmouse *psmouse, int set_properties)
399{
400 struct ps2dev *ps2dev = &psmouse->ps2dev;
401 unsigned char param[4];
402
403 param[0] = 3;
404 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
405 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
406 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
407 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
408 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
409
410 if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55)
411 return -1;
412
413 if (set_properties) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500414 set_bit(BTN_EXTRA, psmouse->dev->keybit);
415 set_bit(BTN_SIDE, psmouse->dev->keybit);
416 set_bit(REL_WHEEL, psmouse->dev->relbit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 psmouse->vendor = "Genius";
Dmitry Torokhova3f3f312006-01-29 21:50:46 -0500419 psmouse->name = "Mouse";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 psmouse->pktsize = 4;
421 }
422
423 return 0;
424}
425
426/*
427 * IntelliMouse magic init.
428 */
429static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
430{
431 struct ps2dev *ps2dev = &psmouse->ps2dev;
432 unsigned char param[2];
433
434 param[0] = 200;
435 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
436 param[0] = 100;
437 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
438 param[0] = 80;
439 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
440 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
441
442 if (param[0] != 3)
443 return -1;
444
445 if (set_properties) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500446 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
447 set_bit(REL_WHEEL, psmouse->dev->relbit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 if (!psmouse->vendor) psmouse->vendor = "Generic";
450 if (!psmouse->name) psmouse->name = "Wheel Mouse";
451 psmouse->pktsize = 4;
452 }
453
454 return 0;
455}
456
457/*
458 * Try IntelliMouse/Explorer magic init.
459 */
460static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
461{
462 struct ps2dev *ps2dev = &psmouse->ps2dev;
463 unsigned char param[2];
464
465 intellimouse_detect(psmouse, 0);
466
467 param[0] = 200;
468 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
469 param[0] = 200;
470 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
471 param[0] = 80;
472 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
473 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
474
475 if (param[0] != 4)
476 return -1;
477
Pozsar Balazsb0c9ad82006-06-26 01:56:08 -0400478/* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
479 param[0] = 200;
480 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
481 param[0] = 80;
482 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
483 param[0] = 40;
484 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 if (set_properties) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500487 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
488 set_bit(REL_WHEEL, psmouse->dev->relbit);
Pozsar Balazsb0c9ad82006-06-26 01:56:08 -0400489 set_bit(REL_HWHEEL, psmouse->dev->relbit);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500490 set_bit(BTN_SIDE, psmouse->dev->keybit);
491 set_bit(BTN_EXTRA, psmouse->dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 if (!psmouse->vendor) psmouse->vendor = "Generic";
494 if (!psmouse->name) psmouse->name = "Explorer Mouse";
495 psmouse->pktsize = 4;
496 }
497
498 return 0;
499}
500
501/*
502 * Kensington ThinkingMouse / ExpertMouse magic init.
503 */
504static int thinking_detect(struct psmouse *psmouse, int set_properties)
505{
506 struct ps2dev *ps2dev = &psmouse->ps2dev;
507 unsigned char param[2];
Helge Dellere38de672006-09-10 21:54:39 -0400508 static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 int i;
510
511 param[0] = 10;
512 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
513 param[0] = 0;
514 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
Helge Dellere38de672006-09-10 21:54:39 -0400515 for (i = 0; i < ARRAY_SIZE(seq); i++) {
516 param[0] = seq[i];
517 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
520
521 if (param[0] != 2)
522 return -1;
523
524 if (set_properties) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500525 set_bit(BTN_EXTRA, psmouse->dev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 psmouse->vendor = "Kensington";
528 psmouse->name = "ThinkingMouse";
529 }
530
531 return 0;
532}
533
534/*
535 * Bare PS/2 protocol "detection". Always succeeds.
536 */
537static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
538{
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500539 if (set_properties) {
540 if (!psmouse->vendor) psmouse->vendor = "Generic";
541 if (!psmouse->name) psmouse->name = "Mouse";
542 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 return 0;
545}
546
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548/*
549 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
550 * the mouse may have.
551 */
552
553static int psmouse_extensions(struct psmouse *psmouse,
554 unsigned int max_proto, int set_properties)
555{
556 int synaptics_hardware = 0;
557
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500558/*
559 * We always check for lifebook because it does not disturb mouse
560 * (it only checks DMI information).
561 */
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500562 if (lifebook_detect(psmouse, set_properties) == 0) {
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500563 if (max_proto > PSMOUSE_IMEX) {
564 if (!set_properties || lifebook_init(psmouse) == 0)
565 return PSMOUSE_LIFEBOOK;
566 }
567 }
Kenan Esau02d7f582005-05-29 02:30:22 -0500568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/*
570 * Try Kensington ThinkingMouse (we try first, because synaptics probe
571 * upsets the thinkingmouse).
572 */
573
574 if (max_proto > PSMOUSE_IMEX && thinking_detect(psmouse, set_properties) == 0)
575 return PSMOUSE_THINKPS;
576
577/*
578 * Try Synaptics TouchPad
579 */
580 if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) {
581 synaptics_hardware = 1;
582
583 if (max_proto > PSMOUSE_IMEX) {
584 if (!set_properties || synaptics_init(psmouse) == 0)
585 return PSMOUSE_SYNAPTICS;
586/*
587 * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
588 * Unfortunately Logitech/Genius probes confuse some firmware versions so
589 * we'll have to skip them.
590 */
591 max_proto = PSMOUSE_IMEX;
592 }
593/*
594 * Make sure that touchpad is in relative mode, gestures (taps) are enabled
595 */
596 synaptics_reset(psmouse);
597 }
598
599/*
600 * Try ALPS TouchPad
601 */
602 if (max_proto > PSMOUSE_IMEX) {
603 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
604 if (alps_detect(psmouse, set_properties) == 0) {
605 if (!set_properties || alps_init(psmouse) == 0)
606 return PSMOUSE_ALPS;
607/*
608 * Init failed, try basic relative protocols
609 */
610 max_proto = PSMOUSE_IMEX;
611 }
612 }
613
614 if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse, set_properties) == 0)
615 return PSMOUSE_GENPS;
616
617 if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties) == 0)
618 return PSMOUSE_PS2PP;
619
Dmitry Torokhovba449952005-12-21 00:51:31 -0500620 if (max_proto > PSMOUSE_IMEX && trackpoint_detect(psmouse, set_properties) == 0)
621 return PSMOUSE_TRACKPOINT;
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623/*
624 * Reset to defaults in case the device got confused by extended
Dmitry Torokhovba449952005-12-21 00:51:31 -0500625 * protocol probes. Note that we do full reset becuase some mice
626 * put themselves to sleep when see PSMOUSE_RESET_DIS.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 */
Dmitry Torokhovba449952005-12-21 00:51:31 -0500628 psmouse_reset(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0)
631 return PSMOUSE_IMEX;
632
633 if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0)
634 return PSMOUSE_IMPS;
635
636/*
637 * Okay, all failed, we have a standard mouse here. The number of the buttons
638 * is still a question, though. We assume 3.
639 */
640 ps2bare_detect(psmouse, set_properties);
641
642 if (synaptics_hardware) {
643/*
644 * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
645 * We need to reset the touchpad because if there is a track point on the
646 * pass through port it could get disabled while probing for protocol
647 * extensions.
648 */
649 psmouse_reset(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651
652 return PSMOUSE_PS2;
653}
654
Helge Dellere38de672006-09-10 21:54:39 -0400655static const struct psmouse_protocol psmouse_protocols[] = {
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500656 {
657 .type = PSMOUSE_PS2,
658 .name = "PS/2",
659 .alias = "bare",
660 .maxproto = 1,
661 .detect = ps2bare_detect,
662 },
663 {
664 .type = PSMOUSE_PS2PP,
665 .name = "PS2++",
666 .alias = "logitech",
667 .detect = ps2pp_init,
668 },
669 {
670 .type = PSMOUSE_THINKPS,
671 .name = "ThinkPS/2",
672 .alias = "thinkps",
673 .detect = thinking_detect,
674 },
675 {
676 .type = PSMOUSE_GENPS,
677 .name = "GenPS/2",
678 .alias = "genius",
679 .detect = genius_detect,
680 },
681 {
682 .type = PSMOUSE_IMPS,
683 .name = "ImPS/2",
684 .alias = "imps",
685 .maxproto = 1,
686 .detect = intellimouse_detect,
687 },
688 {
689 .type = PSMOUSE_IMEX,
690 .name = "ImExPS/2",
691 .alias = "exps",
692 .maxproto = 1,
693 .detect = im_explorer_detect,
694 },
695 {
696 .type = PSMOUSE_SYNAPTICS,
697 .name = "SynPS/2",
698 .alias = "synaptics",
699 .detect = synaptics_detect,
700 .init = synaptics_init,
701 },
702 {
703 .type = PSMOUSE_ALPS,
704 .name = "AlpsPS/2",
705 .alias = "alps",
706 .detect = alps_detect,
707 .init = alps_init,
708 },
709 {
710 .type = PSMOUSE_LIFEBOOK,
711 .name = "LBPS/2",
712 .alias = "lifebook",
713 .init = lifebook_init,
714 },
715 {
Stephen Evanchik541e3162005-08-08 01:26:18 -0500716 .type = PSMOUSE_TRACKPOINT,
717 .name = "TPPS/2",
718 .alias = "trackpoint",
719 .detect = trackpoint_detect,
720 },
721 {
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500722 .type = PSMOUSE_AUTO,
723 .name = "auto",
724 .alias = "any",
725 .maxproto = 1,
726 },
727};
728
Helge Dellere38de672006-09-10 21:54:39 -0400729static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500730{
731 int i;
732
733 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
734 if (psmouse_protocols[i].type == type)
735 return &psmouse_protocols[i];
736
737 WARN_ON(1);
738 return &psmouse_protocols[0];
739}
740
Helge Dellere38de672006-09-10 21:54:39 -0400741static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500742{
Helge Dellere38de672006-09-10 21:54:39 -0400743 const struct psmouse_protocol *p;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500744 int i;
745
746 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
747 p = &psmouse_protocols[i];
748
749 if ((strlen(p->name) == len && !strncmp(p->name, name, len)) ||
750 (strlen(p->alias) == len && !strncmp(p->alias, name, len)))
751 return &psmouse_protocols[i];
752 }
753
754 return NULL;
755}
756
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758/*
759 * psmouse_probe() probes for a PS/2 mouse.
760 */
761
762static int psmouse_probe(struct psmouse *psmouse)
763{
764 struct ps2dev *ps2dev = &psmouse->ps2dev;
765 unsigned char param[2];
766
767/*
768 * First, we check if it's a mouse. It should send 0x00 or 0x03
769 * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
Vojtech Pavlik7741e932005-05-28 02:11:42 -0500770 * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent
771 * ID queries, probably due to a firmware bug.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 */
773
774 param[0] = 0xa5;
775 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
776 return -1;
777
Vojtech Pavlik7741e932005-05-28 02:11:42 -0500778 if (param[0] != 0x00 && param[0] != 0x03 &&
779 param[0] != 0x04 && param[0] != 0xff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 return -1;
781
782/*
783 * Then we reset and disable the mouse so that it doesn't generate events.
784 */
785
786 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS))
787 printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", ps2dev->serio->phys);
788
789 return 0;
790}
791
792/*
793 * Here we set the mouse resolution.
794 */
795
796void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
797{
Helge Dellere38de672006-09-10 21:54:39 -0400798 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
799 unsigned char p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 if (resolution == 0 || resolution > 200)
802 resolution = 200;
803
Helge Dellere38de672006-09-10 21:54:39 -0400804 p = params[resolution / 50];
805 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
806 psmouse->resolution = 25 << p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
809/*
810 * Here we set the mouse report rate.
811 */
812
813static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
814{
Helge Dellere38de672006-09-10 21:54:39 -0400815 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
816 unsigned char r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 int i = 0;
818
819 while (rates[i] > rate) i++;
Helge Dellere38de672006-09-10 21:54:39 -0400820 r = rates[i];
821 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
822 psmouse->rate = r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
825/*
826 * psmouse_initialize() initializes the mouse to a sane state.
827 */
828
829static void psmouse_initialize(struct psmouse *psmouse)
830{
831/*
832 * We set the mouse into streaming mode.
833 */
834
835 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM);
836
837/*
838 * We set the mouse report rate, resolution and scaling.
839 */
840
841 if (psmouse_max_proto != PSMOUSE_PS2) {
842 psmouse->set_rate(psmouse, psmouse->rate);
843 psmouse->set_resolution(psmouse, psmouse->resolution);
844 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
845 }
846}
847
848/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 * psmouse_activate() enables the mouse so that we get motion reports from it.
850 */
851
852static void psmouse_activate(struct psmouse *psmouse)
853{
854 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE))
855 printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n",
856 psmouse->ps2dev.serio->phys);
857
858 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
859}
860
861
862/*
863 * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion
864 * reports from it unless we explicitely request it.
865 */
866
867static void psmouse_deactivate(struct psmouse *psmouse)
868{
869 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE))
870 printk(KERN_WARNING "psmouse.c: Failed to deactivate mouse on %s\n",
871 psmouse->ps2dev.serio->phys);
872
873 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
874}
875
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500876/*
877 * psmouse_poll() - default poll hanlder. Everyone except for ALPS uses it.
878 */
879
880static int psmouse_poll(struct psmouse *psmouse)
881{
882 return ps2_command(&psmouse->ps2dev, psmouse->packet,
883 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
884}
885
886
887/*
888 * psmouse_resync() attempts to re-validate current protocol.
889 */
890
891static void psmouse_resync(void *p)
892{
893 struct psmouse *psmouse = p, *parent = NULL;
894 struct serio *serio = psmouse->ps2dev.serio;
895 psmouse_ret_t rc = PSMOUSE_GOOD_DATA;
896 int failed = 0, enabled = 0;
897 int i;
898
Ingo Molnarc14471d2006-02-19 00:22:11 -0500899 mutex_lock(&psmouse_mutex);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500900
901 if (psmouse->state != PSMOUSE_RESYNCING)
902 goto out;
903
904 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
905 parent = serio_get_drvdata(serio->parent);
906 psmouse_deactivate(parent);
907 }
908
909/*
910 * Some mice don't ACK commands sent while they are in the middle of
911 * transmitting motion packet. To avoid delay we use ps2_sendbyte()
912 * instead of ps2_command() which would wait for 200ms for an ACK
913 * that may never come.
914 * As an additional quirk ALPS touchpads may not only forget to ACK
915 * disable command but will stop reporting taps, so if we see that
916 * mouse at least once ACKs disable we will do full reconnect if ACK
917 * is missing.
918 */
919 psmouse->num_resyncs++;
920
921 if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) {
922 if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command)
923 failed = 1;
924 } else
925 psmouse->acks_disable_command = 1;
926
927/*
928 * Poll the mouse. If it was reset the packet will be shorter than
929 * psmouse->pktsize and ps2_command will fail. We do not expect and
930 * do not handle scenario when mouse "upgrades" its protocol while
931 * disconnected since it would require additional delay. If we ever
932 * see a mouse that does it we'll adjust the code.
933 */
934 if (!failed) {
935 if (psmouse->poll(psmouse))
936 failed = 1;
937 else {
938 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
939 for (i = 0; i < psmouse->pktsize; i++) {
940 psmouse->pktcnt++;
David Howells7d12e782006-10-05 14:55:46 +0100941 rc = psmouse->protocol_handler(psmouse);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500942 if (rc != PSMOUSE_GOOD_DATA)
943 break;
944 }
945 if (rc != PSMOUSE_FULL_PACKET)
946 failed = 1;
947 psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
948 }
949 }
950/*
951 * Now try to enable mouse. We try to do that even if poll failed and also
952 * repeat our attempts 5 times, otherwise we may be left out with disabled
953 * mouse.
954 */
955 for (i = 0; i < 5; i++) {
956 if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
957 enabled = 1;
958 break;
959 }
960 msleep(200);
961 }
962
963 if (!enabled) {
964 printk(KERN_WARNING "psmouse.c: failed to re-enable mouse on %s\n",
965 psmouse->ps2dev.serio->phys);
966 failed = 1;
967 }
968
969 if (failed) {
970 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
971 printk(KERN_INFO "psmouse.c: resync failed, issuing reconnect request\n");
972 serio_reconnect(serio);
973 } else
974 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
975
976 if (parent)
977 psmouse_activate(parent);
978 out:
Ingo Molnarc14471d2006-02-19 00:22:11 -0500979 mutex_unlock(&psmouse_mutex);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500980}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982/*
983 * psmouse_cleanup() resets the mouse into power-on state.
984 */
985
986static void psmouse_cleanup(struct serio *serio)
987{
988 struct psmouse *psmouse = serio_get_drvdata(serio);
989
990 psmouse_reset(psmouse);
991}
992
993/*
994 * psmouse_disconnect() closes and frees.
995 */
996
997static void psmouse_disconnect(struct serio *serio)
998{
Dmitry Torokhov04df1922005-06-01 02:39:44 -0500999 struct psmouse *psmouse, *parent = NULL;
1000
1001 psmouse = serio_get_drvdata(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001003 sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Ingo Molnarc14471d2006-02-19 00:22:11 -05001005 mutex_lock(&psmouse_mutex);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1008
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001009 /* make sure we don't have a resync in progress */
Ingo Molnarc14471d2006-02-19 00:22:11 -05001010 mutex_unlock(&psmouse_mutex);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001011 flush_workqueue(kpsmoused_wq);
Ingo Molnarc14471d2006-02-19 00:22:11 -05001012 mutex_lock(&psmouse_mutex);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1015 parent = serio_get_drvdata(serio->parent);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001016 psmouse_deactivate(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018
1019 if (psmouse->disconnect)
1020 psmouse->disconnect(psmouse);
1021
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001022 if (parent && parent->pt_deactivate)
1023 parent->pt_deactivate(parent);
1024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 serio_close(serio);
1028 serio_set_drvdata(serio, NULL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001029 input_unregister_device(psmouse->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 kfree(psmouse);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001031
1032 if (parent)
1033 psmouse_activate(parent);
1034
Ingo Molnarc14471d2006-02-19 00:22:11 -05001035 mutex_unlock(&psmouse_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
Helge Dellere38de672006-09-10 21:54:39 -04001038static int psmouse_switch_protocol(struct psmouse *psmouse, const struct psmouse_protocol *proto)
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001039{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001040 struct input_dev *input_dev = psmouse->dev;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001041
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001042 input_dev->private = psmouse;
1043 input_dev->cdev.dev = &psmouse->ps2dev.serio->dev;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001044
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001045 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
1046 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
1047 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001048
1049 psmouse->set_rate = psmouse_set_rate;
1050 psmouse->set_resolution = psmouse_set_resolution;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001051 psmouse->poll = psmouse_poll;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001052 psmouse->protocol_handler = psmouse_process_byte;
1053 psmouse->pktsize = 3;
1054
1055 if (proto && (proto->detect || proto->init)) {
1056 if (proto->detect && proto->detect(psmouse, 1) < 0)
1057 return -1;
1058
1059 if (proto->init && proto->init(psmouse) < 0)
1060 return -1;
1061
1062 psmouse->type = proto->type;
1063 }
1064 else
1065 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
1066
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001067 /*
1068 * If mouse's packet size is 3 there is no point in polling the
1069 * device in hopes to detect protocol reset - we won't get less
1070 * than 3 bytes response anyhow.
1071 */
1072 if (psmouse->pktsize == 3)
1073 psmouse->resync_time = 0;
1074
1075 /*
1076 * Some smart KVMs fake response to POLL command returning just
1077 * 3 bytes and messing up our resync logic, so if initial poll
1078 * fails we won't try polling the device anymore. Hopefully
1079 * such KVM will maintain initially selected protocol.
1080 */
1081 if (psmouse->resync_time && psmouse->poll(psmouse))
1082 psmouse->resync_time = 0;
1083
Dmitry Torokhov08ffce42006-06-26 01:45:10 -04001084 snprintf(psmouse->devname, sizeof(psmouse->devname), "%s %s %s",
1085 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001086
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001087 input_dev->name = psmouse->devname;
1088 input_dev->phys = psmouse->phys;
1089 input_dev->id.bustype = BUS_I8042;
1090 input_dev->id.vendor = 0x0002;
1091 input_dev->id.product = psmouse->type;
1092 input_dev->id.version = psmouse->model;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001093
1094 return 0;
1095}
1096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097/*
1098 * psmouse_connect() is a callback from the serio module when
1099 * an unhandled serio port is found.
1100 */
1101static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1102{
1103 struct psmouse *psmouse, *parent = NULL;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001104 struct input_dev *input_dev;
1105 int retval = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Ingo Molnarc14471d2006-02-19 00:22:11 -05001107 mutex_lock(&psmouse_mutex);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 /*
1110 * If this is a pass-through port deactivate parent so the device
1111 * connected to this port can be successfully identified
1112 */
1113 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1114 parent = serio_get_drvdata(serio->parent);
1115 psmouse_deactivate(parent);
1116 }
1117
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001118 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
1119 input_dev = input_allocate_device();
1120 if (!psmouse || !input_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 ps2_init(&psmouse->ps2dev, serio);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001124 INIT_WORK(&psmouse->resync_work, psmouse_resync, psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001125 psmouse->dev = input_dev;
Dmitry Torokhov08ffce42006-06-26 01:45:10 -04001126 snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1129
1130 serio_set_drvdata(serio, psmouse);
1131
1132 retval = serio_open(serio, drv);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001133 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 if (psmouse_probe(psmouse) < 0) {
1137 serio_close(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 retval = -ENODEV;
1139 goto out;
1140 }
1141
1142 psmouse->rate = psmouse_rate;
1143 psmouse->resolution = psmouse_resolution;
1144 psmouse->resetafter = psmouse_resetafter;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001145 psmouse->resync_time = parent ? 0 : psmouse_resync_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 psmouse->smartscroll = psmouse_smartscroll;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001148 psmouse_switch_protocol(psmouse, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 psmouse_initialize(psmouse);
1152
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001153 input_register_device(psmouse->dev);
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (parent && parent->pt_activate)
1156 parent->pt_activate(parent);
1157
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001158 sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 psmouse_activate(psmouse);
1161
1162 retval = 0;
1163
1164out:
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001165 if (retval) {
1166 serio_set_drvdata(serio, NULL);
1167 input_free_device(input_dev);
1168 kfree(psmouse);
1169 }
1170
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001171 /* If this is a pass-through port the parent needs to be re-activated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 if (parent)
1173 psmouse_activate(parent);
1174
Ingo Molnarc14471d2006-02-19 00:22:11 -05001175 mutex_unlock(&psmouse_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 return retval;
1177}
1178
1179
1180static int psmouse_reconnect(struct serio *serio)
1181{
1182 struct psmouse *psmouse = serio_get_drvdata(serio);
1183 struct psmouse *parent = NULL;
1184 struct serio_driver *drv = serio->drv;
1185 int rc = -1;
1186
1187 if (!drv || !psmouse) {
1188 printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n");
1189 return -1;
1190 }
1191
Ingo Molnarc14471d2006-02-19 00:22:11 -05001192 mutex_lock(&psmouse_mutex);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1195 parent = serio_get_drvdata(serio->parent);
1196 psmouse_deactivate(parent);
1197 }
1198
1199 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1200
1201 if (psmouse->reconnect) {
1202 if (psmouse->reconnect(psmouse))
1203 goto out;
1204 } else if (psmouse_probe(psmouse) < 0 ||
1205 psmouse->type != psmouse_extensions(psmouse, psmouse_max_proto, 0))
1206 goto out;
1207
1208 /* ok, the device type (and capabilities) match the old one,
1209 * we can continue using it, complete intialization
1210 */
1211 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1212
1213 psmouse_initialize(psmouse);
1214
1215 if (parent && parent->pt_activate)
1216 parent->pt_activate(parent);
1217
1218 psmouse_activate(psmouse);
1219 rc = 0;
1220
1221out:
1222 /* If this is a pass-through port the parent waits to be activated */
1223 if (parent)
1224 psmouse_activate(parent);
1225
Ingo Molnarc14471d2006-02-19 00:22:11 -05001226 mutex_unlock(&psmouse_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 return rc;
1228}
1229
1230static struct serio_device_id psmouse_serio_ids[] = {
1231 {
1232 .type = SERIO_8042,
1233 .proto = SERIO_ANY,
1234 .id = SERIO_ANY,
1235 .extra = SERIO_ANY,
1236 },
1237 {
1238 .type = SERIO_PS_PSTHRU,
1239 .proto = SERIO_ANY,
1240 .id = SERIO_ANY,
1241 .extra = SERIO_ANY,
1242 },
1243 { 0 }
1244};
1245
1246MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
1247
1248static struct serio_driver psmouse_drv = {
1249 .driver = {
1250 .name = "psmouse",
1251 },
1252 .description = DRIVER_DESC,
1253 .id_table = psmouse_serio_ids,
1254 .interrupt = psmouse_interrupt,
1255 .connect = psmouse_connect,
1256 .reconnect = psmouse_reconnect,
1257 .disconnect = psmouse_disconnect,
1258 .cleanup = psmouse_cleanup,
1259};
1260
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001261ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr,
1262 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
1264 struct serio *serio = to_serio_port(dev);
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001265 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1266 struct psmouse *psmouse;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 int retval;
1268
1269 retval = serio_pin_driver(serio);
1270 if (retval)
1271 return retval;
1272
1273 if (serio->drv != &psmouse_drv) {
1274 retval = -ENODEV;
1275 goto out;
1276 }
1277
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001278 psmouse = serio_get_drvdata(serio);
1279
1280 retval = attr->show(psmouse, attr->data, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282out:
1283 serio_unpin_driver(serio);
1284 return retval;
1285}
1286
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001287ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr,
1288 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 struct serio *serio = to_serio_port(dev);
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001291 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1292 struct psmouse *psmouse, *parent = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 int retval;
1294
1295 retval = serio_pin_driver(serio);
1296 if (retval)
1297 return retval;
1298
1299 if (serio->drv != &psmouse_drv) {
1300 retval = -ENODEV;
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001301 goto out_unpin;
1302 }
1303
Ingo Molnarc14471d2006-02-19 00:22:11 -05001304 retval = mutex_lock_interruptible(&psmouse_mutex);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001305 if (retval)
1306 goto out_unpin;
1307
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001308 psmouse = serio_get_drvdata(serio);
1309
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001310 if (psmouse->state == PSMOUSE_IGNORE) {
1311 retval = -ENODEV;
Ingo Molnarc14471d2006-02-19 00:22:11 -05001312 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
1314
1315 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1316 parent = serio_get_drvdata(serio->parent);
1317 psmouse_deactivate(parent);
1318 }
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 psmouse_deactivate(psmouse);
1321
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001322 retval = attr->set(psmouse, attr->data, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001324 if (retval != -ENODEV)
1325 psmouse_activate(psmouse);
1326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (parent)
1328 psmouse_activate(parent);
1329
Ingo Molnarc14471d2006-02-19 00:22:11 -05001330 out_unlock:
1331 mutex_unlock(&psmouse_mutex);
Dmitry Torokhov04df1922005-06-01 02:39:44 -05001332 out_unpin:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 serio_unpin_driver(serio);
1334 return retval;
1335}
1336
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001337static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
1338{
1339 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset);
1340
1341 return sprintf(buf, "%lu\n", *field);
1342}
1343
1344static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
1345{
1346 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset);
1347 unsigned long value;
1348 char *rest;
1349
1350 value = simple_strtoul(buf, &rest, 10);
1351 if (*rest)
1352 return -EINVAL;
1353
1354 *field = value;
1355
1356 return count;
1357}
1358
1359static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf)
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001360{
1361 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
1362}
1363
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001364static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count)
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001365{
1366 struct serio *serio = psmouse->ps2dev.serio;
1367 struct psmouse *parent = NULL;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001368 struct input_dev *new_dev;
Helge Dellere38de672006-09-10 21:54:39 -04001369 const struct psmouse_protocol *proto;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001370 int retry = 0;
1371
1372 if (!(proto = psmouse_protocol_by_name(buf, count)))
1373 return -EINVAL;
1374
1375 if (psmouse->type == proto->type)
1376 return count;
1377
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001378 if (!(new_dev = input_allocate_device()))
1379 return -ENOMEM;
1380
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001381 while (serio->child) {
1382 if (++retry > 3) {
1383 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n");
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001384 input_free_device(new_dev);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001385 return -EIO;
1386 }
1387
Ingo Molnarc14471d2006-02-19 00:22:11 -05001388 mutex_unlock(&psmouse_mutex);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001389 serio_unpin_driver(serio);
1390 serio_unregister_child_port(serio);
1391 serio_pin_driver_uninterruptible(serio);
Ingo Molnarc14471d2006-02-19 00:22:11 -05001392 mutex_lock(&psmouse_mutex);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001393
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001394 if (serio->drv != &psmouse_drv) {
1395 input_free_device(new_dev);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001396 return -ENODEV;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001397 }
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001398
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001399 if (psmouse->type == proto->type) {
1400 input_free_device(new_dev);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001401 return count; /* switched by other thread */
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001402 }
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001403 }
1404
1405 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1406 parent = serio_get_drvdata(serio->parent);
1407 if (parent->pt_deactivate)
1408 parent->pt_deactivate(parent);
1409 }
1410
1411 if (psmouse->disconnect)
1412 psmouse->disconnect(psmouse);
1413
1414 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001415 input_unregister_device(psmouse->dev);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001416
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001417 psmouse->dev = new_dev;
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001418 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1419
1420 if (psmouse_switch_protocol(psmouse, proto) < 0) {
1421 psmouse_reset(psmouse);
1422 /* default to PSMOUSE_PS2 */
1423 psmouse_switch_protocol(psmouse, &psmouse_protocols[0]);
1424 }
1425
1426 psmouse_initialize(psmouse);
1427 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1428
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001429 input_register_device(psmouse->dev);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001430
1431 if (parent && parent->pt_activate)
1432 parent->pt_activate(parent);
1433
1434 return count;
1435}
1436
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001437static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
1439 unsigned long value;
1440 char *rest;
1441
1442 value = simple_strtoul(buf, &rest, 10);
1443 if (*rest)
1444 return -EINVAL;
1445
1446 psmouse->set_rate(psmouse, value);
1447 return count;
1448}
1449
Dmitry Torokhovcfe9e882005-09-04 01:40:20 -05001450static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
1452 unsigned long value;
1453 char *rest;
1454
1455 value = simple_strtoul(buf, &rest, 10);
1456 if (*rest)
1457 return -EINVAL;
1458
1459 psmouse->set_resolution(psmouse, value);
1460 return count;
1461}
1462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1465{
Helge Dellere38de672006-09-10 21:54:39 -04001466 const struct psmouse_protocol *proto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 if (!val)
1469 return -EINVAL;
1470
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001471 proto = psmouse_protocol_by_name(val, strlen(val));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001473 if (!proto || !proto->maxproto)
1474 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001476 *((unsigned int *)kp->arg) = proto->type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Stephen Evanchik541e3162005-08-08 01:26:18 -05001478 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
1481static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
1482{
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -05001483 int type = *((unsigned int *)kp->arg);
1484
1485 return sprintf(buffer, "%s\n", psmouse_protocol_by_type(type)->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486}
1487
1488static int __init psmouse_init(void)
1489{
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001490 kpsmoused_wq = create_singlethread_workqueue("kpsmoused");
1491 if (!kpsmoused_wq) {
1492 printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n");
1493 return -ENOMEM;
1494 }
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 serio_register_driver(&psmouse_drv);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001497
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 return 0;
1499}
1500
1501static void __exit psmouse_exit(void)
1502{
1503 serio_unregister_driver(&psmouse_drv);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001504 destroy_workqueue(kpsmoused_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
1507module_init(psmouse_init);
1508module_exit(psmouse_exit);