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/slab.h>
17 #include <linux/interrupt.h>
18 #include <linux/input.h>
19 #include <linux/serio.h>
20 #include <linux/init.h>
21 #include <linux/libps2.h>
22 #include <linux/mutex.h>
25 #include "synaptics.h"
26 #include "logips2pp.h"
30 #include "trackpoint.h"
31 #include "touchkit_ps2.h"
34 #define DRIVER_DESC "PS/2 mouse driver"
36 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
37 MODULE_DESCRIPTION(DRIVER_DESC);
38 MODULE_LICENSE("GPL");
40 static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
41 static int psmouse_set_maxproto(const char *val, struct kernel_param *kp);
42 static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp);
43 #define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
44 #define param_set_proto_abbrev psmouse_set_maxproto
45 #define param_get_proto_abbrev psmouse_get_maxproto
46 module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
47 MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
49 static unsigned int psmouse_resolution = 200;
50 module_param_named(resolution, psmouse_resolution, uint, 0644);
51 MODULE_PARM_DESC(resolution, "Resolution, in dpi.");
53 static unsigned int psmouse_rate = 100;
54 module_param_named(rate, psmouse_rate, uint, 0644);
55 MODULE_PARM_DESC(rate, "Report rate, in reports per second.");
57 static unsigned int psmouse_smartscroll = 1;
58 module_param_named(smartscroll, psmouse_smartscroll, bool, 0644);
59 MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
61 static unsigned int psmouse_resetafter = 5;
62 module_param_named(resetafter, psmouse_resetafter, uint, 0644);
63 MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
65 static unsigned int psmouse_resync_time;
66 module_param_named(resync_time, psmouse_resync_time, uint, 0644);
67 MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never).");
69 PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
71 psmouse_attr_show_protocol, psmouse_attr_set_protocol);
72 PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO,
73 (void *) offsetof(struct psmouse, rate),
74 psmouse_show_int_attr, psmouse_attr_set_rate);
75 PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
76 (void *) offsetof(struct psmouse, resolution),
77 psmouse_show_int_attr, psmouse_attr_set_resolution);
78 PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
79 (void *) offsetof(struct psmouse, resetafter),
80 psmouse_show_int_attr, psmouse_set_int_attr);
81 PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO,
82 (void *) offsetof(struct psmouse, resync_time),
83 psmouse_show_int_attr, psmouse_set_int_attr);
85 static struct attribute *psmouse_attributes[] = {
86 &psmouse_attr_protocol.dattr.attr,
87 &psmouse_attr_rate.dattr.attr,
88 &psmouse_attr_resolution.dattr.attr,
89 &psmouse_attr_resetafter.dattr.attr,
90 &psmouse_attr_resync_time.dattr.attr,
94 static struct attribute_group psmouse_attribute_group = {
95 .attrs = psmouse_attributes,
99 * psmouse_mutex protects all operations changing state of mouse
100 * (connecting, disconnecting, changing rate or resolution via
101 * sysfs). We could use a per-device semaphore but since there
102 * rarely more than one PS/2 mouse connected and since semaphore
103 * is taken in "slow" paths it is not worth it.
105 static DEFINE_MUTEX(psmouse_mutex);
107 static struct workqueue_struct *kpsmoused_wq;
109 struct psmouse_protocol {
110 enum psmouse_type type;
114 int (*detect)(struct psmouse *, int);
115 int (*init)(struct psmouse *);
119 * psmouse_process_byte() analyzes the PS/2 data stream and reports
120 * relevant events to the input module once full packet has arrived.
123 static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
125 struct input_dev *dev = psmouse->dev;
126 unsigned char *packet = psmouse->packet;
128 if (psmouse->pktcnt < psmouse->pktsize)
129 return PSMOUSE_GOOD_DATA;
132 * Full packet accumulated, process it
136 * Scroll wheel on IntelliMice, scroll buttons on NetMice
139 if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS)
140 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
143 * Scroll wheel and buttons on IntelliMouse Explorer
146 if (psmouse->type == PSMOUSE_IMEX) {
147 switch (packet[3] & 0xC0) {
148 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
149 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
151 case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */
152 input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
156 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7));
157 input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1);
158 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1);
164 * Extra buttons on Genius NewNet 3D
167 if (psmouse->type == PSMOUSE_GENPS) {
168 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
169 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
173 * Extra button on ThinkingMouse
175 if (psmouse->type == PSMOUSE_THINKPS) {
176 input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1);
177 /* Without this bit of weirdness moving up gives wildly high Y changes. */
178 packet[1] |= (packet[0] & 0x40) << 1;
182 * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first
185 if (psmouse->type == PSMOUSE_CORTRON) {
186 input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1);
194 input_report_key(dev, BTN_LEFT, packet[0] & 1);
195 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
196 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
198 input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
199 input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
203 return PSMOUSE_FULL_PACKET;
206 void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
209 queue_delayed_work(kpsmoused_wq, work, delay);
213 * __psmouse_set_state() sets new psmouse state and resets all flags.
216 static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
218 psmouse->state = new_state;
219 psmouse->pktcnt = psmouse->out_of_sync = 0;
220 psmouse->ps2dev.flags = 0;
221 psmouse->last = jiffies;
226 * psmouse_set_state() sets new psmouse state and resets all flags and
227 * counters while holding serio lock so fighting with interrupt handler
231 void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
233 serio_pause_rx(psmouse->ps2dev.serio);
234 __psmouse_set_state(psmouse, new_state);
235 serio_continue_rx(psmouse->ps2dev.serio);
239 * psmouse_handle_byte() processes one byte of the input data stream
240 * by calling corresponding protocol handler.
243 static int psmouse_handle_byte(struct psmouse *psmouse)
245 psmouse_ret_t rc = psmouse->protocol_handler(psmouse);
248 case PSMOUSE_BAD_DATA:
249 if (psmouse->state == PSMOUSE_ACTIVATED) {
250 printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n",
251 psmouse->name, psmouse->phys, psmouse->pktcnt);
252 if (++psmouse->out_of_sync == psmouse->resetafter) {
253 __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
254 printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n");
255 serio_reconnect(psmouse->ps2dev.serio);
262 case PSMOUSE_FULL_PACKET:
264 if (psmouse->out_of_sync) {
265 psmouse->out_of_sync = 0;
266 printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n",
267 psmouse->name, psmouse->phys);
271 case PSMOUSE_GOOD_DATA:
278 * psmouse_interrupt() handles incoming characters, either passing them
279 * for normal processing or gathering them as command response.
282 static irqreturn_t psmouse_interrupt(struct serio *serio,
283 unsigned char data, unsigned int flags)
285 struct psmouse *psmouse = serio_get_drvdata(serio);
287 if (psmouse->state == PSMOUSE_IGNORE)
290 if (flags & (SERIO_PARITY|SERIO_TIMEOUT)) {
291 if (psmouse->state == PSMOUSE_ACTIVATED)
292 printk(KERN_WARNING "psmouse.c: bad data from KBC -%s%s\n",
293 flags & SERIO_TIMEOUT ? " timeout" : "",
294 flags & SERIO_PARITY ? " bad parity" : "");
295 ps2_cmd_aborted(&psmouse->ps2dev);
299 if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK))
300 if (ps2_handle_ack(&psmouse->ps2dev, data))
303 if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_CMD))
304 if (ps2_handle_response(&psmouse->ps2dev, data))
307 if (psmouse->state <= PSMOUSE_RESYNCING)
310 if (psmouse->state == PSMOUSE_ACTIVATED &&
311 psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
312 printk(KERN_INFO "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n",
313 psmouse->name, psmouse->phys, psmouse->pktcnt);
314 psmouse->badbyte = psmouse->packet[0];
315 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
316 psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
320 psmouse->packet[psmouse->pktcnt++] = data;
322 * Check if this is a new device announcement (0xAA 0x00)
324 if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) {
325 if (psmouse->pktcnt == 1) {
326 psmouse->last = jiffies;
330 if (psmouse->packet[1] == PSMOUSE_RET_ID ||
331 (psmouse->type == PSMOUSE_HGPK &&
332 psmouse->packet[1] == PSMOUSE_RET_BAT)) {
333 __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
334 serio_reconnect(serio);
338 * Not a new device, try processing first byte normally
341 if (psmouse_handle_byte(psmouse))
344 psmouse->packet[psmouse->pktcnt++] = data;
348 * See if we need to force resync because mouse was idle for too long
350 if (psmouse->state == PSMOUSE_ACTIVATED &&
351 psmouse->pktcnt == 1 && psmouse->resync_time &&
352 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
353 psmouse->badbyte = psmouse->packet[0];
354 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
355 psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
359 psmouse->last = jiffies;
360 psmouse_handle_byte(psmouse);
368 * psmouse_sliced_command() sends an extended PS/2 command to the mouse
369 * using sliced syntax, understood by advanced devices, such as Logitech
370 * or Synaptics touchpads. The command is encoded as:
371 * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
374 int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command)
378 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
381 for (i = 6; i >= 0; i -= 2) {
382 unsigned char d = (command >> i) & 3;
383 if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES))
392 * psmouse_reset() resets the mouse into power-on state.
394 int psmouse_reset(struct psmouse *psmouse)
396 unsigned char param[2];
398 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT))
401 if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID)
409 * Genius NetMouse magic init.
411 static int genius_detect(struct psmouse *psmouse, int set_properties)
413 struct ps2dev *ps2dev = &psmouse->ps2dev;
414 unsigned char param[4];
417 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
418 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
419 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
420 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
421 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
423 if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55)
426 if (set_properties) {
427 set_bit(BTN_EXTRA, psmouse->dev->keybit);
428 set_bit(BTN_SIDE, psmouse->dev->keybit);
429 set_bit(REL_WHEEL, psmouse->dev->relbit);
431 psmouse->vendor = "Genius";
432 psmouse->name = "Mouse";
433 psmouse->pktsize = 4;
440 * IntelliMouse magic init.
442 static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
444 struct ps2dev *ps2dev = &psmouse->ps2dev;
445 unsigned char param[2];
448 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
450 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
452 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
453 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
458 if (set_properties) {
459 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
460 set_bit(REL_WHEEL, psmouse->dev->relbit);
462 if (!psmouse->vendor) psmouse->vendor = "Generic";
463 if (!psmouse->name) psmouse->name = "Wheel Mouse";
464 psmouse->pktsize = 4;
471 * Try IntelliMouse/Explorer magic init.
473 static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
475 struct ps2dev *ps2dev = &psmouse->ps2dev;
476 unsigned char param[2];
478 intellimouse_detect(psmouse, 0);
481 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
483 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
485 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
486 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
491 /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
493 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
495 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
497 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
499 if (set_properties) {
500 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
501 set_bit(REL_WHEEL, psmouse->dev->relbit);
502 set_bit(REL_HWHEEL, psmouse->dev->relbit);
503 set_bit(BTN_SIDE, psmouse->dev->keybit);
504 set_bit(BTN_EXTRA, psmouse->dev->keybit);
506 if (!psmouse->vendor) psmouse->vendor = "Generic";
507 if (!psmouse->name) psmouse->name = "Explorer Mouse";
508 psmouse->pktsize = 4;
515 * Kensington ThinkingMouse / ExpertMouse magic init.
517 static int thinking_detect(struct psmouse *psmouse, int set_properties)
519 struct ps2dev *ps2dev = &psmouse->ps2dev;
520 unsigned char param[2];
521 static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
525 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
527 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
528 for (i = 0; i < ARRAY_SIZE(seq); i++) {
530 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
532 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
537 if (set_properties) {
538 set_bit(BTN_EXTRA, psmouse->dev->keybit);
540 psmouse->vendor = "Kensington";
541 psmouse->name = "ThinkingMouse";
548 * Bare PS/2 protocol "detection". Always succeeds.
550 static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
552 if (set_properties) {
553 if (!psmouse->vendor) psmouse->vendor = "Generic";
554 if (!psmouse->name) psmouse->name = "Mouse";
561 * Cortron PS/2 protocol detection. There's no special way to detect it, so it
562 * must be forced by sysfs protocol writing.
564 static int cortron_detect(struct psmouse *psmouse, int set_properties)
566 if (set_properties) {
567 psmouse->vendor = "Cortron";
568 psmouse->name = "PS/2 Trackball";
569 set_bit(BTN_SIDE, psmouse->dev->keybit);
576 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
577 * the mouse may have.
580 static int psmouse_extensions(struct psmouse *psmouse,
581 unsigned int max_proto, int set_properties)
583 int synaptics_hardware = 0;
586 * We always check for lifebook because it does not disturb mouse
587 * (it only checks DMI information).
589 if (lifebook_detect(psmouse, set_properties) == 0) {
590 if (max_proto > PSMOUSE_IMEX) {
591 if (!set_properties || lifebook_init(psmouse) == 0)
592 return PSMOUSE_LIFEBOOK;
597 * Try Kensington ThinkingMouse (we try first, because synaptics probe
598 * upsets the thinkingmouse).
601 if (max_proto > PSMOUSE_IMEX && thinking_detect(psmouse, set_properties) == 0)
602 return PSMOUSE_THINKPS;
605 * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol
606 * support is disabled in config - we need to know if it is synaptics so we
607 * can reset it properly after probing for intellimouse.
609 if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) {
610 synaptics_hardware = 1;
612 if (max_proto > PSMOUSE_IMEX) {
613 if (!set_properties || synaptics_init(psmouse) == 0)
614 return PSMOUSE_SYNAPTICS;
616 * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
617 * Unfortunately Logitech/Genius probes confuse some firmware versions so
618 * we'll have to skip them.
620 max_proto = PSMOUSE_IMEX;
623 * Make sure that touchpad is in relative mode, gestures (taps) are enabled
625 synaptics_reset(psmouse);
631 if (max_proto > PSMOUSE_IMEX) {
632 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
633 if (alps_detect(psmouse, set_properties) == 0) {
634 if (!set_properties || alps_init(psmouse) == 0)
637 * Init failed, try basic relative protocols
639 max_proto = PSMOUSE_IMEX;
644 * Try OLPC HGPK touchpad.
646 if (max_proto > PSMOUSE_IMEX &&
647 hgpk_detect(psmouse, set_properties) == 0) {
648 if (!set_properties || hgpk_init(psmouse) == 0)
651 * Init failed, try basic relative protocols
653 max_proto = PSMOUSE_IMEX;
657 * Try Elantech touchpad.
659 if (max_proto > PSMOUSE_IMEX &&
660 elantech_detect(psmouse, set_properties) == 0) {
661 if (!set_properties || elantech_init(psmouse) == 0)
662 return PSMOUSE_ELANTECH;
664 * Init failed, try basic relative protocols
666 max_proto = PSMOUSE_IMEX;
669 if (max_proto > PSMOUSE_IMEX) {
670 if (genius_detect(psmouse, set_properties) == 0)
671 return PSMOUSE_GENPS;
673 if (ps2pp_init(psmouse, set_properties) == 0)
674 return PSMOUSE_PS2PP;
676 if (trackpoint_detect(psmouse, set_properties) == 0)
677 return PSMOUSE_TRACKPOINT;
679 if (touchkit_ps2_detect(psmouse, set_properties) == 0)
680 return PSMOUSE_TOUCHKIT_PS2;
684 * Reset to defaults in case the device got confused by extended
685 * protocol probes. Note that we follow up with full reset because
686 * some mice put themselves to sleep when they see PSMOUSE_RESET_DIS.
688 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
689 psmouse_reset(psmouse);
691 if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0)
694 if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0)
698 * Okay, all failed, we have a standard mouse here. The number of the buttons
699 * is still a question, though. We assume 3.
701 ps2bare_detect(psmouse, set_properties);
703 if (synaptics_hardware) {
705 * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
706 * We need to reset the touchpad because if there is a track point on the
707 * pass through port it could get disabled while probing for protocol
710 psmouse_reset(psmouse);
716 static const struct psmouse_protocol psmouse_protocols[] = {
722 .detect = ps2bare_detect,
724 #ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
726 .type = PSMOUSE_PS2PP,
729 .detect = ps2pp_init,
733 .type = PSMOUSE_THINKPS,
736 .detect = thinking_detect,
739 .type = PSMOUSE_GENPS,
742 .detect = genius_detect,
745 .type = PSMOUSE_IMPS,
749 .detect = intellimouse_detect,
752 .type = PSMOUSE_IMEX,
756 .detect = im_explorer_detect,
758 #ifdef CONFIG_MOUSE_PS2_SYNAPTICS
760 .type = PSMOUSE_SYNAPTICS,
762 .alias = "synaptics",
763 .detect = synaptics_detect,
764 .init = synaptics_init,
767 #ifdef CONFIG_MOUSE_PS2_ALPS
769 .type = PSMOUSE_ALPS,
772 .detect = alps_detect,
776 #ifdef CONFIG_MOUSE_PS2_LIFEBOOK
778 .type = PSMOUSE_LIFEBOOK,
781 .init = lifebook_init,
784 #ifdef CONFIG_MOUSE_PS2_TRACKPOINT
786 .type = PSMOUSE_TRACKPOINT,
788 .alias = "trackpoint",
789 .detect = trackpoint_detect,
792 #ifdef CONFIG_MOUSE_PS2_TOUCHKIT
794 .type = PSMOUSE_TOUCHKIT_PS2,
795 .name = "touchkitPS/2",
797 .detect = touchkit_ps2_detect,
800 #ifdef CONFIG_MOUSE_PS2_OLPC
802 .type = PSMOUSE_HGPK,
805 .detect = hgpk_detect,
808 #ifdef CONFIG_MOUSE_PS2_ELANTECH
810 .type = PSMOUSE_ELANTECH,
813 .detect = elantech_detect,
814 .init = elantech_init,
818 .type = PSMOUSE_CORTRON,
819 .name = "CortronPS/2",
821 .detect = cortron_detect,
824 .type = PSMOUSE_AUTO,
831 static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
835 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
836 if (psmouse_protocols[i].type == type)
837 return &psmouse_protocols[i];
840 return &psmouse_protocols[0];
843 static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
845 const struct psmouse_protocol *p;
848 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
849 p = &psmouse_protocols[i];
851 if ((strlen(p->name) == len && !strncmp(p->name, name, len)) ||
852 (strlen(p->alias) == len && !strncmp(p->alias, name, len)))
853 return &psmouse_protocols[i];
861 * psmouse_probe() probes for a PS/2 mouse.
864 static int psmouse_probe(struct psmouse *psmouse)
866 struct ps2dev *ps2dev = &psmouse->ps2dev;
867 unsigned char param[2];
870 * First, we check if it's a mouse. It should send 0x00 or 0x03
871 * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
872 * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent
873 * ID queries, probably due to a firmware bug.
877 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
880 if (param[0] != 0x00 && param[0] != 0x03 &&
881 param[0] != 0x04 && param[0] != 0xff)
885 * Then we reset and disable the mouse so that it doesn't generate events.
888 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS))
889 printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", ps2dev->serio->phys);
895 * Here we set the mouse resolution.
898 void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
900 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
903 if (resolution == 0 || resolution > 200)
906 p = params[resolution / 50];
907 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
908 psmouse->resolution = 25 << p;
912 * Here we set the mouse report rate.
915 static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
917 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
921 while (rates[i] > rate) i++;
923 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
928 * psmouse_initialize() initializes the mouse to a sane state.
931 static void psmouse_initialize(struct psmouse *psmouse)
934 * We set the mouse report rate, resolution and scaling.
937 if (psmouse_max_proto != PSMOUSE_PS2) {
938 psmouse->set_rate(psmouse, psmouse->rate);
939 psmouse->set_resolution(psmouse, psmouse->resolution);
940 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
945 * psmouse_activate() enables the mouse so that we get motion reports from it.
948 static void psmouse_activate(struct psmouse *psmouse)
950 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE))
951 printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n",
952 psmouse->ps2dev.serio->phys);
954 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
959 * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion
960 * reports from it unless we explicitly request it.
963 static void psmouse_deactivate(struct psmouse *psmouse)
965 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE))
966 printk(KERN_WARNING "psmouse.c: Failed to deactivate mouse on %s\n",
967 psmouse->ps2dev.serio->phys);
969 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
973 * psmouse_poll() - default poll hanlder. Everyone except for ALPS uses it.
976 static int psmouse_poll(struct psmouse *psmouse)
978 return ps2_command(&psmouse->ps2dev, psmouse->packet,
979 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
984 * psmouse_resync() attempts to re-validate current protocol.
987 static void psmouse_resync(struct work_struct *work)
989 struct psmouse *parent = NULL, *psmouse =
990 container_of(work, struct psmouse, resync_work.work);
991 struct serio *serio = psmouse->ps2dev.serio;
992 psmouse_ret_t rc = PSMOUSE_GOOD_DATA;
993 int failed = 0, enabled = 0;
996 mutex_lock(&psmouse_mutex);
998 if (psmouse->state != PSMOUSE_RESYNCING)
1001 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1002 parent = serio_get_drvdata(serio->parent);
1003 psmouse_deactivate(parent);
1007 * Some mice don't ACK commands sent while they are in the middle of
1008 * transmitting motion packet. To avoid delay we use ps2_sendbyte()
1009 * instead of ps2_command() which would wait for 200ms for an ACK
1010 * that may never come.
1011 * As an additional quirk ALPS touchpads may not only forget to ACK
1012 * disable command but will stop reporting taps, so if we see that
1013 * mouse at least once ACKs disable we will do full reconnect if ACK
1016 psmouse->num_resyncs++;
1018 if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) {
1019 if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command)
1022 psmouse->acks_disable_command = 1;
1025 * Poll the mouse. If it was reset the packet will be shorter than
1026 * psmouse->pktsize and ps2_command will fail. We do not expect and
1027 * do not handle scenario when mouse "upgrades" its protocol while
1028 * disconnected since it would require additional delay. If we ever
1029 * see a mouse that does it we'll adjust the code.
1032 if (psmouse->poll(psmouse))
1035 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1036 for (i = 0; i < psmouse->pktsize; i++) {
1038 rc = psmouse->protocol_handler(psmouse);
1039 if (rc != PSMOUSE_GOOD_DATA)
1042 if (rc != PSMOUSE_FULL_PACKET)
1044 psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
1048 * Now try to enable mouse. We try to do that even if poll failed and also
1049 * repeat our attempts 5 times, otherwise we may be left out with disabled
1052 for (i = 0; i < 5; i++) {
1053 if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1061 printk(KERN_WARNING "psmouse.c: failed to re-enable mouse on %s\n",
1062 psmouse->ps2dev.serio->phys);
1067 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1068 printk(KERN_INFO "psmouse.c: resync failed, issuing reconnect request\n");
1069 serio_reconnect(serio);
1071 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
1074 psmouse_activate(parent);
1076 mutex_unlock(&psmouse_mutex);
1080 * psmouse_cleanup() resets the mouse into power-on state.
1083 static void psmouse_cleanup(struct serio *serio)
1085 struct psmouse *psmouse = serio_get_drvdata(serio);
1086 struct psmouse *parent = NULL;
1088 mutex_lock(&psmouse_mutex);
1090 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1091 parent = serio_get_drvdata(serio->parent);
1092 psmouse_deactivate(parent);
1095 psmouse_deactivate(psmouse);
1097 if (psmouse->cleanup)
1098 psmouse->cleanup(psmouse);
1100 psmouse_reset(psmouse);
1103 * Some boxes, such as HP nx7400, get terribly confused if mouse
1104 * is not fully enabled before suspending/shutting down.
1106 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1109 if (parent->pt_deactivate)
1110 parent->pt_deactivate(parent);
1112 psmouse_activate(parent);
1115 mutex_unlock(&psmouse_mutex);
1119 * psmouse_disconnect() closes and frees.
1122 static void psmouse_disconnect(struct serio *serio)
1124 struct psmouse *psmouse, *parent = NULL;
1126 psmouse = serio_get_drvdata(serio);
1128 sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
1130 mutex_lock(&psmouse_mutex);
1132 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1134 /* make sure we don't have a resync in progress */
1135 mutex_unlock(&psmouse_mutex);
1136 flush_workqueue(kpsmoused_wq);
1137 mutex_lock(&psmouse_mutex);
1139 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1140 parent = serio_get_drvdata(serio->parent);
1141 psmouse_deactivate(parent);
1144 if (psmouse->disconnect)
1145 psmouse->disconnect(psmouse);
1147 if (parent && parent->pt_deactivate)
1148 parent->pt_deactivate(parent);
1150 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1153 serio_set_drvdata(serio, NULL);
1154 input_unregister_device(psmouse->dev);
1158 psmouse_activate(parent);
1160 mutex_unlock(&psmouse_mutex);
1163 static int psmouse_switch_protocol(struct psmouse *psmouse, const struct psmouse_protocol *proto)
1165 struct input_dev *input_dev = psmouse->dev;
1167 input_dev->dev.parent = &psmouse->ps2dev.serio->dev;
1169 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
1170 input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
1171 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
1172 input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1174 psmouse->set_rate = psmouse_set_rate;
1175 psmouse->set_resolution = psmouse_set_resolution;
1176 psmouse->poll = psmouse_poll;
1177 psmouse->protocol_handler = psmouse_process_byte;
1178 psmouse->pktsize = 3;
1180 if (proto && (proto->detect || proto->init)) {
1181 if (proto->detect && proto->detect(psmouse, 1) < 0)
1184 if (proto->init && proto->init(psmouse) < 0)
1187 psmouse->type = proto->type;
1190 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
1193 * If mouse's packet size is 3 there is no point in polling the
1194 * device in hopes to detect protocol reset - we won't get less
1195 * than 3 bytes response anyhow.
1197 if (psmouse->pktsize == 3)
1198 psmouse->resync_time = 0;
1201 * Some smart KVMs fake response to POLL command returning just
1202 * 3 bytes and messing up our resync logic, so if initial poll
1203 * fails we won't try polling the device anymore. Hopefully
1204 * such KVM will maintain initially selected protocol.
1206 if (psmouse->resync_time && psmouse->poll(psmouse))
1207 psmouse->resync_time = 0;
1209 snprintf(psmouse->devname, sizeof(psmouse->devname), "%s %s %s",
1210 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
1212 input_dev->name = psmouse->devname;
1213 input_dev->phys = psmouse->phys;
1214 input_dev->id.bustype = BUS_I8042;
1215 input_dev->id.vendor = 0x0002;
1216 input_dev->id.product = psmouse->type;
1217 input_dev->id.version = psmouse->model;
1223 * psmouse_connect() is a callback from the serio module when
1224 * an unhandled serio port is found.
1226 static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1228 struct psmouse *psmouse, *parent = NULL;
1229 struct input_dev *input_dev;
1230 int retval = 0, error = -ENOMEM;
1232 mutex_lock(&psmouse_mutex);
1235 * If this is a pass-through port deactivate parent so the device
1236 * connected to this port can be successfully identified
1238 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1239 parent = serio_get_drvdata(serio->parent);
1240 psmouse_deactivate(parent);
1243 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
1244 input_dev = input_allocate_device();
1245 if (!psmouse || !input_dev)
1248 ps2_init(&psmouse->ps2dev, serio);
1249 INIT_DELAYED_WORK(&psmouse->resync_work, psmouse_resync);
1250 psmouse->dev = input_dev;
1251 snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys);
1253 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1255 serio_set_drvdata(serio, psmouse);
1257 error = serio_open(serio, drv);
1259 goto err_clear_drvdata;
1261 if (psmouse_probe(psmouse) < 0) {
1263 goto err_close_serio;
1266 psmouse->rate = psmouse_rate;
1267 psmouse->resolution = psmouse_resolution;
1268 psmouse->resetafter = psmouse_resetafter;
1269 psmouse->resync_time = parent ? 0 : psmouse_resync_time;
1270 psmouse->smartscroll = psmouse_smartscroll;
1272 psmouse_switch_protocol(psmouse, NULL);
1274 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1275 psmouse_initialize(psmouse);
1277 error = input_register_device(psmouse->dev);
1279 goto err_protocol_disconnect;
1281 if (parent && parent->pt_activate)
1282 parent->pt_activate(parent);
1284 error = sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
1286 goto err_pt_deactivate;
1288 psmouse_activate(psmouse);
1291 /* If this is a pass-through port the parent needs to be re-activated */
1293 psmouse_activate(parent);
1295 mutex_unlock(&psmouse_mutex);
1299 if (parent && parent->pt_deactivate)
1300 parent->pt_deactivate(parent);
1301 input_unregister_device(psmouse->dev);
1302 input_dev = NULL; /* so we don't try to free it below */
1303 err_protocol_disconnect:
1304 if (psmouse->disconnect)
1305 psmouse->disconnect(psmouse);
1306 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1310 serio_set_drvdata(serio, NULL);
1312 input_free_device(input_dev);
1320 static int psmouse_reconnect(struct serio *serio)
1322 struct psmouse *psmouse = serio_get_drvdata(serio);
1323 struct psmouse *parent = NULL;
1324 struct serio_driver *drv = serio->drv;
1327 if (!drv || !psmouse) {
1328 printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n");
1332 mutex_lock(&psmouse_mutex);
1334 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1335 parent = serio_get_drvdata(serio->parent);
1336 psmouse_deactivate(parent);
1339 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1341 if (psmouse->reconnect) {
1342 if (psmouse->reconnect(psmouse))
1344 } else if (psmouse_probe(psmouse) < 0 ||
1345 psmouse->type != psmouse_extensions(psmouse, psmouse_max_proto, 0))
1348 /* ok, the device type (and capabilities) match the old one,
1349 * we can continue using it, complete intialization
1351 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1353 psmouse_initialize(psmouse);
1355 if (parent && parent->pt_activate)
1356 parent->pt_activate(parent);
1358 psmouse_activate(psmouse);
1362 /* If this is a pass-through port the parent waits to be activated */
1364 psmouse_activate(parent);
1366 mutex_unlock(&psmouse_mutex);
1370 static struct serio_device_id psmouse_serio_ids[] = {
1378 .type = SERIO_PS_PSTHRU,
1386 MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
1388 static struct serio_driver psmouse_drv = {
1392 .description = DRIVER_DESC,
1393 .id_table = psmouse_serio_ids,
1394 .interrupt = psmouse_interrupt,
1395 .connect = psmouse_connect,
1396 .reconnect = psmouse_reconnect,
1397 .disconnect = psmouse_disconnect,
1398 .cleanup = psmouse_cleanup,
1401 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr,
1404 struct serio *serio = to_serio_port(dev);
1405 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1406 struct psmouse *psmouse;
1409 retval = serio_pin_driver(serio);
1413 if (serio->drv != &psmouse_drv) {
1418 psmouse = serio_get_drvdata(serio);
1420 retval = attr->show(psmouse, attr->data, buf);
1423 serio_unpin_driver(serio);
1427 ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr,
1428 const char *buf, size_t count)
1430 struct serio *serio = to_serio_port(dev);
1431 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1432 struct psmouse *psmouse, *parent = NULL;
1435 retval = serio_pin_driver(serio);
1439 if (serio->drv != &psmouse_drv) {
1444 retval = mutex_lock_interruptible(&psmouse_mutex);
1448 psmouse = serio_get_drvdata(serio);
1450 if (attr->protect) {
1451 if (psmouse->state == PSMOUSE_IGNORE) {
1456 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1457 parent = serio_get_drvdata(serio->parent);
1458 psmouse_deactivate(parent);
1461 psmouse_deactivate(psmouse);
1464 retval = attr->set(psmouse, attr->data, buf, count);
1466 if (attr->protect) {
1467 if (retval != -ENODEV)
1468 psmouse_activate(psmouse);
1471 psmouse_activate(parent);
1475 mutex_unlock(&psmouse_mutex);
1477 serio_unpin_driver(serio);
1481 static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
1483 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
1485 return sprintf(buf, "%u\n", *field);
1488 static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
1490 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
1491 unsigned long value;
1493 if (strict_strtoul(buf, 10, &value))
1496 if ((unsigned int)value != value)
1504 static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf)
1506 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
1509 static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1511 struct serio *serio = psmouse->ps2dev.serio;
1512 struct psmouse *parent = NULL;
1513 struct input_dev *old_dev, *new_dev;
1514 const struct psmouse_protocol *proto, *old_proto;
1518 proto = psmouse_protocol_by_name(buf, count);
1522 if (psmouse->type == proto->type)
1525 new_dev = input_allocate_device();
1529 while (serio->child) {
1531 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n");
1532 input_free_device(new_dev);
1536 mutex_unlock(&psmouse_mutex);
1537 serio_unpin_driver(serio);
1538 serio_unregister_child_port(serio);
1539 serio_pin_driver_uninterruptible(serio);
1540 mutex_lock(&psmouse_mutex);
1542 if (serio->drv != &psmouse_drv) {
1543 input_free_device(new_dev);
1547 if (psmouse->type == proto->type) {
1548 input_free_device(new_dev);
1549 return count; /* switched by other thread */
1553 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1554 parent = serio_get_drvdata(serio->parent);
1555 if (parent->pt_deactivate)
1556 parent->pt_deactivate(parent);
1559 old_dev = psmouse->dev;
1560 old_proto = psmouse_protocol_by_type(psmouse->type);
1562 if (psmouse->disconnect)
1563 psmouse->disconnect(psmouse);
1565 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1567 psmouse->dev = new_dev;
1568 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1570 if (psmouse_switch_protocol(psmouse, proto) < 0) {
1571 psmouse_reset(psmouse);
1572 /* default to PSMOUSE_PS2 */
1573 psmouse_switch_protocol(psmouse, &psmouse_protocols[0]);
1576 psmouse_initialize(psmouse);
1577 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1579 error = input_register_device(psmouse->dev);
1581 if (psmouse->disconnect)
1582 psmouse->disconnect(psmouse);
1584 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1585 input_free_device(new_dev);
1586 psmouse->dev = old_dev;
1587 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1588 psmouse_switch_protocol(psmouse, old_proto);
1589 psmouse_initialize(psmouse);
1590 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1595 input_unregister_device(old_dev);
1597 if (parent && parent->pt_activate)
1598 parent->pt_activate(parent);
1603 static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1605 unsigned long value;
1607 if (strict_strtoul(buf, 10, &value))
1610 psmouse->set_rate(psmouse, value);
1614 static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1616 unsigned long value;
1618 if (strict_strtoul(buf, 10, &value))
1621 psmouse->set_resolution(psmouse, value);
1626 static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1628 const struct psmouse_protocol *proto;
1633 proto = psmouse_protocol_by_name(val, strlen(val));
1635 if (!proto || !proto->maxproto)
1638 *((unsigned int *)kp->arg) = proto->type;
1643 static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
1645 int type = *((unsigned int *)kp->arg);
1647 return sprintf(buffer, "%s\n", psmouse_protocol_by_type(type)->name);
1650 static int __init psmouse_init(void)
1654 kpsmoused_wq = create_singlethread_workqueue("kpsmoused");
1655 if (!kpsmoused_wq) {
1656 printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n");
1660 err = serio_register_driver(&psmouse_drv);
1662 destroy_workqueue(kpsmoused_wq);
1667 static void __exit psmouse_exit(void)
1669 serio_unregister_driver(&psmouse_drv);
1670 destroy_workqueue(kpsmoused_wq);
1673 module_init(psmouse_init);
1674 module_exit(psmouse_exit);