Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 22 | #include <linux/mutex.h> |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "psmouse.h" |
| 25 | #include "synaptics.h" |
| 26 | #include "logips2pp.h" |
| 27 | #include "alps.h" |
Andres Salomon | df08ef2 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 28 | #include "hgpk.h" |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 29 | #include "lifebook.h" |
Stephen Evanchik | 541e316 | 2005-08-08 01:26:18 -0500 | [diff] [blame] | 30 | #include "trackpoint.h" |
Stefan Lucke | 24bf10a | 2007-02-18 01:49:10 -0500 | [diff] [blame] | 31 | #include "touchkit_ps2.h" |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 32 | #include "elantech.h" |
Tai-hwa Liang | fc69f4a | 2009-05-10 18:15:39 -0700 | [diff] [blame] | 33 | #include "sentelic.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #define DRIVER_DESC "PS/2 mouse driver" |
| 36 | |
| 37 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); |
| 38 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 41 | static unsigned int psmouse_max_proto = PSMOUSE_AUTO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); |
| 43 | static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) |
| 45 | #define param_set_proto_abbrev psmouse_set_maxproto |
| 46 | #define param_get_proto_abbrev psmouse_get_maxproto |
| 47 | module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 48 | MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | static unsigned int psmouse_resolution = 200; |
| 51 | module_param_named(resolution, psmouse_resolution, uint, 0644); |
| 52 | MODULE_PARM_DESC(resolution, "Resolution, in dpi."); |
| 53 | |
| 54 | static unsigned int psmouse_rate = 100; |
| 55 | module_param_named(rate, psmouse_rate, uint, 0644); |
| 56 | MODULE_PARM_DESC(rate, "Report rate, in reports per second."); |
| 57 | |
| 58 | static unsigned int psmouse_smartscroll = 1; |
| 59 | module_param_named(smartscroll, psmouse_smartscroll, bool, 0644); |
| 60 | MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled."); |
| 61 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 62 | static unsigned int psmouse_resetafter = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | module_param_named(resetafter, psmouse_resetafter, uint, 0644); |
| 64 | MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); |
| 65 | |
Dmitry Torokhov | 8bd0ee9 | 2006-03-11 00:23:38 -0500 | [diff] [blame] | 66 | static unsigned int psmouse_resync_time; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 67 | module_param_named(resync_time, psmouse_resync_time, uint, 0644); |
| 68 | MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never)."); |
| 69 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 70 | PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO, |
| 71 | NULL, |
| 72 | psmouse_attr_show_protocol, psmouse_attr_set_protocol); |
| 73 | PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO, |
| 74 | (void *) offsetof(struct psmouse, rate), |
| 75 | psmouse_show_int_attr, psmouse_attr_set_rate); |
| 76 | PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO, |
| 77 | (void *) offsetof(struct psmouse, resolution), |
| 78 | psmouse_show_int_attr, psmouse_attr_set_resolution); |
| 79 | PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO, |
| 80 | (void *) offsetof(struct psmouse, resetafter), |
| 81 | psmouse_show_int_attr, psmouse_set_int_attr); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 82 | PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO, |
| 83 | (void *) offsetof(struct psmouse, resync_time), |
| 84 | psmouse_show_int_attr, psmouse_set_int_attr); |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 85 | |
| 86 | static struct attribute *psmouse_attributes[] = { |
| 87 | &psmouse_attr_protocol.dattr.attr, |
| 88 | &psmouse_attr_rate.dattr.attr, |
| 89 | &psmouse_attr_resolution.dattr.attr, |
| 90 | &psmouse_attr_resetafter.dattr.attr, |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 91 | &psmouse_attr_resync_time.dattr.attr, |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 92 | NULL |
| 93 | }; |
| 94 | |
| 95 | static struct attribute_group psmouse_attribute_group = { |
| 96 | .attrs = psmouse_attributes, |
| 97 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 99 | /* |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 100 | * psmouse_mutex protects all operations changing state of mouse |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 101 | * (connecting, disconnecting, changing rate or resolution via |
| 102 | * sysfs). We could use a per-device semaphore but since there |
| 103 | * rarely more than one PS/2 mouse connected and since semaphore |
| 104 | * is taken in "slow" paths it is not worth it. |
| 105 | */ |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 106 | static DEFINE_MUTEX(psmouse_mutex); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 107 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 108 | static struct workqueue_struct *kpsmoused_wq; |
| 109 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 110 | struct psmouse_protocol { |
| 111 | enum psmouse_type type; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 112 | bool maxproto; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 113 | const char *name; |
| 114 | const char *alias; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 115 | int (*detect)(struct psmouse *, bool); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 116 | int (*init)(struct psmouse *); |
| 117 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * psmouse_process_byte() analyzes the PS/2 data stream and reports |
| 121 | * relevant events to the input module once full packet has arrived. |
| 122 | */ |
| 123 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 124 | static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 126 | struct input_dev *dev = psmouse->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | unsigned char *packet = psmouse->packet; |
| 128 | |
| 129 | if (psmouse->pktcnt < psmouse->pktsize) |
| 130 | return PSMOUSE_GOOD_DATA; |
| 131 | |
| 132 | /* |
| 133 | * Full packet accumulated, process it |
| 134 | */ |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* |
| 137 | * Scroll wheel on IntelliMice, scroll buttons on NetMice |
| 138 | */ |
| 139 | |
| 140 | if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS) |
| 141 | input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); |
| 142 | |
| 143 | /* |
| 144 | * Scroll wheel and buttons on IntelliMouse Explorer |
| 145 | */ |
| 146 | |
| 147 | if (psmouse->type == PSMOUSE_IMEX) { |
Pozsar Balazs | b0c9ad8 | 2006-06-26 01:56:08 -0400 | [diff] [blame] | 148 | switch (packet[3] & 0xC0) { |
| 149 | case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */ |
| 150 | input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); |
| 151 | break; |
| 152 | case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */ |
| 153 | input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); |
| 154 | break; |
| 155 | case 0x00: |
| 156 | case 0xC0: |
| 157 | input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7)); |
| 158 | input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1); |
| 159 | input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); |
| 160 | break; |
| 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Extra buttons on Genius NewNet 3D |
| 166 | */ |
| 167 | |
| 168 | if (psmouse->type == PSMOUSE_GENPS) { |
| 169 | input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); |
| 170 | input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Extra button on ThinkingMouse |
| 175 | */ |
| 176 | if (psmouse->type == PSMOUSE_THINKPS) { |
| 177 | input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); |
| 178 | /* Without this bit of weirdness moving up gives wildly high Y changes. */ |
| 179 | packet[1] |= (packet[0] & 0x40) << 1; |
| 180 | } |
| 181 | |
| 182 | /* |
Aristeu Rozanski | aea6a46 | 2007-05-10 01:47:18 -0400 | [diff] [blame] | 183 | * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first |
| 184 | * byte. |
| 185 | */ |
| 186 | if (psmouse->type == PSMOUSE_CORTRON) { |
| 187 | input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1); |
| 188 | packet[0] |= 0x08; |
| 189 | } |
| 190 | |
| 191 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * Generic PS/2 Mouse |
| 193 | */ |
| 194 | |
| 195 | input_report_key(dev, BTN_LEFT, packet[0] & 1); |
| 196 | input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); |
| 197 | input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); |
| 198 | |
| 199 | input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); |
| 200 | input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); |
| 201 | |
| 202 | input_sync(dev); |
| 203 | |
| 204 | return PSMOUSE_FULL_PACKET; |
| 205 | } |
| 206 | |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 207 | void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, |
| 208 | unsigned long delay) |
| 209 | { |
| 210 | queue_delayed_work(kpsmoused_wq, work, delay); |
| 211 | } |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | /* |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 214 | * __psmouse_set_state() sets new psmouse state and resets all flags. |
| 215 | */ |
| 216 | |
| 217 | static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) |
| 218 | { |
| 219 | psmouse->state = new_state; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 220 | psmouse->pktcnt = psmouse->out_of_sync_cnt = 0; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 221 | psmouse->ps2dev.flags = 0; |
| 222 | psmouse->last = jiffies; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | /* |
| 227 | * psmouse_set_state() sets new psmouse state and resets all flags and |
| 228 | * counters while holding serio lock so fighting with interrupt handler |
| 229 | * is not a concern. |
| 230 | */ |
| 231 | |
Andres Salomon | a48cf5f | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 232 | void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 233 | { |
| 234 | serio_pause_rx(psmouse->ps2dev.serio); |
| 235 | __psmouse_set_state(psmouse, new_state); |
| 236 | serio_continue_rx(psmouse->ps2dev.serio); |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * psmouse_handle_byte() processes one byte of the input data stream |
| 241 | * by calling corresponding protocol handler. |
| 242 | */ |
| 243 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 244 | static int psmouse_handle_byte(struct psmouse *psmouse) |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 245 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 246 | psmouse_ret_t rc = psmouse->protocol_handler(psmouse); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 247 | |
| 248 | switch (rc) { |
| 249 | case PSMOUSE_BAD_DATA: |
| 250 | if (psmouse->state == PSMOUSE_ACTIVATED) { |
| 251 | printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n", |
| 252 | psmouse->name, psmouse->phys, psmouse->pktcnt); |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 253 | if (++psmouse->out_of_sync_cnt == psmouse->resetafter) { |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 254 | __psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 255 | printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n"); |
| 256 | serio_reconnect(psmouse->ps2dev.serio); |
| 257 | return -1; |
| 258 | } |
| 259 | } |
| 260 | psmouse->pktcnt = 0; |
| 261 | break; |
| 262 | |
| 263 | case PSMOUSE_FULL_PACKET: |
| 264 | psmouse->pktcnt = 0; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 265 | if (psmouse->out_of_sync_cnt) { |
| 266 | psmouse->out_of_sync_cnt = 0; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 267 | printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n", |
| 268 | psmouse->name, psmouse->phys); |
| 269 | } |
| 270 | break; |
| 271 | |
| 272 | case PSMOUSE_GOOD_DATA: |
| 273 | break; |
| 274 | } |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * psmouse_interrupt() handles incoming characters, either passing them |
| 280 | * for normal processing or gathering them as command response. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | */ |
| 282 | |
| 283 | static irqreturn_t psmouse_interrupt(struct serio *serio, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 284 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
| 286 | struct psmouse *psmouse = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (psmouse->state == PSMOUSE_IGNORE) |
| 289 | goto out; |
| 290 | |
| 291 | if (flags & (SERIO_PARITY|SERIO_TIMEOUT)) { |
| 292 | if (psmouse->state == PSMOUSE_ACTIVATED) |
| 293 | printk(KERN_WARNING "psmouse.c: bad data from KBC -%s%s\n", |
| 294 | flags & SERIO_TIMEOUT ? " timeout" : "", |
| 295 | flags & SERIO_PARITY ? " bad parity" : ""); |
| 296 | ps2_cmd_aborted(&psmouse->ps2dev); |
| 297 | goto out; |
| 298 | } |
| 299 | |
| 300 | if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK)) |
| 301 | if (ps2_handle_ack(&psmouse->ps2dev, data)) |
| 302 | goto out; |
| 303 | |
| 304 | if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_CMD)) |
| 305 | if (ps2_handle_response(&psmouse->ps2dev, data)) |
| 306 | goto out; |
| 307 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 308 | if (psmouse->state <= PSMOUSE_RESYNCING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | goto out; |
| 310 | |
| 311 | if (psmouse->state == PSMOUSE_ACTIVATED && |
| 312 | psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) { |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 313 | printk(KERN_INFO "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | psmouse->name, psmouse->phys, psmouse->pktcnt); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 315 | psmouse->badbyte = psmouse->packet[0]; |
| 316 | __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 317 | psmouse_queue_work(psmouse, &psmouse->resync_work, 0); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 318 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | psmouse->packet[psmouse->pktcnt++] = data; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 322 | /* |
| 323 | * Check if this is a new device announcement (0xAA 0x00) |
| 324 | */ |
| 325 | if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) { |
Dmitry Torokhov | 89c9b48 | 2006-04-29 01:12:44 -0400 | [diff] [blame] | 326 | if (psmouse->pktcnt == 1) { |
| 327 | psmouse->last = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | goto out; |
Dmitry Torokhov | 89c9b48 | 2006-04-29 01:12:44 -0400 | [diff] [blame] | 329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Zephaniah E. Hull | 535650f | 2009-05-14 22:02:33 -0700 | [diff] [blame] | 331 | if (psmouse->packet[1] == PSMOUSE_RET_ID || |
| 332 | (psmouse->type == PSMOUSE_HGPK && |
| 333 | psmouse->packet[1] == PSMOUSE_RET_BAT)) { |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 334 | __psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 335 | serio_reconnect(serio); |
| 336 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 338 | /* |
| 339 | * Not a new device, try processing first byte normally |
| 340 | */ |
| 341 | psmouse->pktcnt = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 342 | if (psmouse_handle_byte(psmouse)) |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 343 | goto out; |
| 344 | |
| 345 | psmouse->packet[psmouse->pktcnt++] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 348 | /* |
| 349 | * See if we need to force resync because mouse was idle for too long |
| 350 | */ |
| 351 | if (psmouse->state == PSMOUSE_ACTIVATED && |
| 352 | psmouse->pktcnt == 1 && psmouse->resync_time && |
| 353 | time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) { |
| 354 | psmouse->badbyte = psmouse->packet[0]; |
| 355 | __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 356 | psmouse_queue_work(psmouse, &psmouse->resync_work, 0); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 357 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 359 | |
| 360 | psmouse->last = jiffies; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 361 | psmouse_handle_byte(psmouse); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 362 | |
| 363 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | return IRQ_HANDLED; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | /* |
| 369 | * psmouse_sliced_command() sends an extended PS/2 command to the mouse |
| 370 | * using sliced syntax, understood by advanced devices, such as Logitech |
| 371 | * or Synaptics touchpads. The command is encoded as: |
| 372 | * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu |
| 373 | * is the command. |
| 374 | */ |
| 375 | int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command) |
| 376 | { |
| 377 | int i; |
| 378 | |
| 379 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) |
| 380 | return -1; |
| 381 | |
| 382 | for (i = 6; i >= 0; i -= 2) { |
| 383 | unsigned char d = (command >> i) & 3; |
| 384 | if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES)) |
| 385 | return -1; |
| 386 | } |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | |
| 392 | /* |
| 393 | * psmouse_reset() resets the mouse into power-on state. |
| 394 | */ |
| 395 | int psmouse_reset(struct psmouse *psmouse) |
| 396 | { |
| 397 | unsigned char param[2]; |
| 398 | |
| 399 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT)) |
| 400 | return -1; |
| 401 | |
| 402 | if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID) |
| 403 | return -1; |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | |
| 409 | /* |
| 410 | * Genius NetMouse magic init. |
| 411 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 412 | static int genius_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
| 414 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 415 | unsigned char param[4]; |
| 416 | |
| 417 | param[0] = 3; |
| 418 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 419 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 420 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 421 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 422 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); |
| 423 | |
| 424 | if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55) |
| 425 | return -1; |
| 426 | |
| 427 | if (set_properties) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 428 | __set_bit(BTN_EXTRA, psmouse->dev->keybit); |
| 429 | __set_bit(BTN_SIDE, psmouse->dev->keybit); |
| 430 | __set_bit(REL_WHEEL, psmouse->dev->relbit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | psmouse->vendor = "Genius"; |
Dmitry Torokhov | a3f3f31 | 2006-01-29 21:50:46 -0500 | [diff] [blame] | 433 | psmouse->name = "Mouse"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | psmouse->pktsize = 4; |
| 435 | } |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * IntelliMouse magic init. |
| 442 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 443 | static int intellimouse_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
| 445 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 446 | unsigned char param[2]; |
| 447 | |
| 448 | param[0] = 200; |
| 449 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 450 | param[0] = 100; |
| 451 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 452 | param[0] = 80; |
| 453 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 454 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); |
| 455 | |
| 456 | if (param[0] != 3) |
| 457 | return -1; |
| 458 | |
| 459 | if (set_properties) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 460 | __set_bit(BTN_MIDDLE, psmouse->dev->keybit); |
| 461 | __set_bit(REL_WHEEL, psmouse->dev->relbit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | if (!psmouse->vendor) psmouse->vendor = "Generic"; |
| 464 | if (!psmouse->name) psmouse->name = "Wheel Mouse"; |
| 465 | psmouse->pktsize = 4; |
| 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Try IntelliMouse/Explorer magic init. |
| 473 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 474 | static int im_explorer_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
| 476 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 477 | unsigned char param[2]; |
| 478 | |
| 479 | intellimouse_detect(psmouse, 0); |
| 480 | |
| 481 | param[0] = 200; |
| 482 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 483 | param[0] = 200; |
| 484 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 485 | param[0] = 80; |
| 486 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 487 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); |
| 488 | |
| 489 | if (param[0] != 4) |
| 490 | return -1; |
| 491 | |
Pozsar Balazs | b0c9ad8 | 2006-06-26 01:56:08 -0400 | [diff] [blame] | 492 | /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */ |
| 493 | param[0] = 200; |
| 494 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 495 | param[0] = 80; |
| 496 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 497 | param[0] = 40; |
| 498 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (set_properties) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 501 | __set_bit(BTN_MIDDLE, psmouse->dev->keybit); |
| 502 | __set_bit(REL_WHEEL, psmouse->dev->relbit); |
| 503 | __set_bit(REL_HWHEEL, psmouse->dev->relbit); |
| 504 | __set_bit(BTN_SIDE, psmouse->dev->keybit); |
| 505 | __set_bit(BTN_EXTRA, psmouse->dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
| 507 | if (!psmouse->vendor) psmouse->vendor = "Generic"; |
| 508 | if (!psmouse->name) psmouse->name = "Explorer Mouse"; |
| 509 | psmouse->pktsize = 4; |
| 510 | } |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Kensington ThinkingMouse / ExpertMouse magic init. |
| 517 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 518 | static int thinking_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 521 | unsigned char param[2]; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 522 | static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | int i; |
| 524 | |
| 525 | param[0] = 10; |
| 526 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 527 | param[0] = 0; |
| 528 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 529 | for (i = 0; i < ARRAY_SIZE(seq); i++) { |
| 530 | param[0] = seq[i]; |
| 531 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); |
| 532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); |
| 534 | |
| 535 | if (param[0] != 2) |
| 536 | return -1; |
| 537 | |
| 538 | if (set_properties) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 539 | __set_bit(BTN_EXTRA, psmouse->dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | psmouse->vendor = "Kensington"; |
| 542 | psmouse->name = "ThinkingMouse"; |
| 543 | } |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Bare PS/2 protocol "detection". Always succeeds. |
| 550 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 551 | static int ps2bare_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | { |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 553 | if (set_properties) { |
| 554 | if (!psmouse->vendor) psmouse->vendor = "Generic"; |
| 555 | if (!psmouse->name) psmouse->name = "Mouse"; |
| 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
Aristeu Rozanski | aea6a46 | 2007-05-10 01:47:18 -0400 | [diff] [blame] | 561 | /* |
| 562 | * Cortron PS/2 protocol detection. There's no special way to detect it, so it |
| 563 | * must be forced by sysfs protocol writing. |
| 564 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 565 | static int cortron_detect(struct psmouse *psmouse, bool set_properties) |
Aristeu Rozanski | aea6a46 | 2007-05-10 01:47:18 -0400 | [diff] [blame] | 566 | { |
| 567 | if (set_properties) { |
| 568 | psmouse->vendor = "Cortron"; |
| 569 | psmouse->name = "PS/2 Trackball"; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 570 | __set_bit(BTN_SIDE, psmouse->dev->keybit); |
Aristeu Rozanski | aea6a46 | 2007-05-10 01:47:18 -0400 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | return 0; |
| 574 | } |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | /* |
| 577 | * psmouse_extensions() probes for any extensions to the basic PS/2 protocol |
| 578 | * the mouse may have. |
| 579 | */ |
| 580 | |
| 581 | static int psmouse_extensions(struct psmouse *psmouse, |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 582 | unsigned int max_proto, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 584 | bool synaptics_hardware = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 586 | /* |
| 587 | * We always check for lifebook because it does not disturb mouse |
| 588 | * (it only checks DMI information). |
| 589 | */ |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 590 | if (lifebook_detect(psmouse, set_properties) == 0) { |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 591 | if (max_proto > PSMOUSE_IMEX) { |
| 592 | if (!set_properties || lifebook_init(psmouse) == 0) |
| 593 | return PSMOUSE_LIFEBOOK; |
| 594 | } |
| 595 | } |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* |
| 598 | * Try Kensington ThinkingMouse (we try first, because synaptics probe |
| 599 | * upsets the thinkingmouse). |
| 600 | */ |
| 601 | |
| 602 | if (max_proto > PSMOUSE_IMEX && thinking_detect(psmouse, set_properties) == 0) |
| 603 | return PSMOUSE_THINKPS; |
| 604 | |
| 605 | /* |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 606 | * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol |
| 607 | * support is disabled in config - we need to know if it is synaptics so we |
| 608 | * can reset it properly after probing for intellimouse. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | */ |
| 610 | if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 611 | synaptics_hardware = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | if (max_proto > PSMOUSE_IMEX) { |
| 614 | if (!set_properties || synaptics_init(psmouse) == 0) |
| 615 | return PSMOUSE_SYNAPTICS; |
| 616 | /* |
| 617 | * Some Synaptics touchpads can emulate extended protocols (like IMPS/2). |
| 618 | * Unfortunately Logitech/Genius probes confuse some firmware versions so |
| 619 | * we'll have to skip them. |
| 620 | */ |
| 621 | max_proto = PSMOUSE_IMEX; |
| 622 | } |
| 623 | /* |
| 624 | * Make sure that touchpad is in relative mode, gestures (taps) are enabled |
| 625 | */ |
| 626 | synaptics_reset(psmouse); |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * Try ALPS TouchPad |
| 631 | */ |
| 632 | if (max_proto > PSMOUSE_IMEX) { |
| 633 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); |
| 634 | if (alps_detect(psmouse, set_properties) == 0) { |
| 635 | if (!set_properties || alps_init(psmouse) == 0) |
| 636 | return PSMOUSE_ALPS; |
| 637 | /* |
| 638 | * Init failed, try basic relative protocols |
| 639 | */ |
| 640 | max_proto = PSMOUSE_IMEX; |
| 641 | } |
| 642 | } |
| 643 | |
Andres Salomon | df08ef2 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 644 | /* |
| 645 | * Try OLPC HGPK touchpad. |
| 646 | */ |
| 647 | if (max_proto > PSMOUSE_IMEX && |
| 648 | hgpk_detect(psmouse, set_properties) == 0) { |
| 649 | if (!set_properties || hgpk_init(psmouse) == 0) |
| 650 | return PSMOUSE_HGPK; |
| 651 | /* |
| 652 | * Init failed, try basic relative protocols |
| 653 | */ |
| 654 | max_proto = PSMOUSE_IMEX; |
| 655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 657 | /* |
| 658 | * Try Elantech touchpad. |
| 659 | */ |
| 660 | if (max_proto > PSMOUSE_IMEX && |
| 661 | elantech_detect(psmouse, set_properties) == 0) { |
| 662 | if (!set_properties || elantech_init(psmouse) == 0) |
| 663 | return PSMOUSE_ELANTECH; |
| 664 | /* |
| 665 | * Init failed, try basic relative protocols |
| 666 | */ |
| 667 | max_proto = PSMOUSE_IMEX; |
| 668 | } |
| 669 | |
Tai-hwa Liang | fc69f4a | 2009-05-10 18:15:39 -0700 | [diff] [blame] | 670 | /* |
| 671 | * Try Finger Sensing Pad |
| 672 | */ |
| 673 | if (max_proto > PSMOUSE_IMEX) { |
| 674 | if (fsp_detect(psmouse, set_properties) == 0) { |
| 675 | if (!set_properties || fsp_init(psmouse) == 0) |
| 676 | return PSMOUSE_FSP; |
| 677 | /* |
| 678 | * Init failed, try basic relative protocols |
| 679 | */ |
| 680 | max_proto = PSMOUSE_IMEX; |
| 681 | } |
| 682 | } |
| 683 | |
Andres Salomon | df08ef2 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 684 | if (max_proto > PSMOUSE_IMEX) { |
Stefan Lucke | 24bf10a | 2007-02-18 01:49:10 -0500 | [diff] [blame] | 685 | if (genius_detect(psmouse, set_properties) == 0) |
| 686 | return PSMOUSE_GENPS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Stefan Lucke | 24bf10a | 2007-02-18 01:49:10 -0500 | [diff] [blame] | 688 | if (ps2pp_init(psmouse, set_properties) == 0) |
| 689 | return PSMOUSE_PS2PP; |
| 690 | |
| 691 | if (trackpoint_detect(psmouse, set_properties) == 0) |
| 692 | return PSMOUSE_TRACKPOINT; |
| 693 | |
| 694 | if (touchkit_ps2_detect(psmouse, set_properties) == 0) |
| 695 | return PSMOUSE_TOUCHKIT_PS2; |
| 696 | } |
Dmitry Torokhov | ba44995 | 2005-12-21 00:51:31 -0500 | [diff] [blame] | 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | /* |
| 699 | * Reset to defaults in case the device got confused by extended |
Alon Ziv | 554fc19 | 2007-08-30 00:22:48 -0400 | [diff] [blame] | 700 | * protocol probes. Note that we follow up with full reset because |
| 701 | * some mice put themselves to sleep when they see PSMOUSE_RESET_DIS. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | */ |
Alon Ziv | 554fc19 | 2007-08-30 00:22:48 -0400 | [diff] [blame] | 703 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); |
Dmitry Torokhov | ba44995 | 2005-12-21 00:51:31 -0500 | [diff] [blame] | 704 | psmouse_reset(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
| 706 | if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0) |
| 707 | return PSMOUSE_IMEX; |
| 708 | |
| 709 | if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0) |
| 710 | return PSMOUSE_IMPS; |
| 711 | |
| 712 | /* |
| 713 | * Okay, all failed, we have a standard mouse here. The number of the buttons |
| 714 | * is still a question, though. We assume 3. |
| 715 | */ |
| 716 | ps2bare_detect(psmouse, set_properties); |
| 717 | |
| 718 | if (synaptics_hardware) { |
| 719 | /* |
| 720 | * We detected Synaptics hardware but it did not respond to IMPS/2 probes. |
| 721 | * We need to reset the touchpad because if there is a track point on the |
| 722 | * pass through port it could get disabled while probing for protocol |
| 723 | * extensions. |
| 724 | */ |
| 725 | psmouse_reset(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | return PSMOUSE_PS2; |
| 729 | } |
| 730 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 731 | static const struct psmouse_protocol psmouse_protocols[] = { |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 732 | { |
| 733 | .type = PSMOUSE_PS2, |
| 734 | .name = "PS/2", |
| 735 | .alias = "bare", |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 736 | .maxproto = true, |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 737 | .detect = ps2bare_detect, |
| 738 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 739 | #ifdef CONFIG_MOUSE_PS2_LOGIPS2PP |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 740 | { |
| 741 | .type = PSMOUSE_PS2PP, |
| 742 | .name = "PS2++", |
| 743 | .alias = "logitech", |
| 744 | .detect = ps2pp_init, |
| 745 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 746 | #endif |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 747 | { |
| 748 | .type = PSMOUSE_THINKPS, |
| 749 | .name = "ThinkPS/2", |
| 750 | .alias = "thinkps", |
| 751 | .detect = thinking_detect, |
| 752 | }, |
| 753 | { |
| 754 | .type = PSMOUSE_GENPS, |
| 755 | .name = "GenPS/2", |
| 756 | .alias = "genius", |
| 757 | .detect = genius_detect, |
| 758 | }, |
| 759 | { |
| 760 | .type = PSMOUSE_IMPS, |
| 761 | .name = "ImPS/2", |
| 762 | .alias = "imps", |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 763 | .maxproto = true, |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 764 | .detect = intellimouse_detect, |
| 765 | }, |
| 766 | { |
| 767 | .type = PSMOUSE_IMEX, |
| 768 | .name = "ImExPS/2", |
| 769 | .alias = "exps", |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 770 | .maxproto = true, |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 771 | .detect = im_explorer_detect, |
| 772 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 773 | #ifdef CONFIG_MOUSE_PS2_SYNAPTICS |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 774 | { |
| 775 | .type = PSMOUSE_SYNAPTICS, |
| 776 | .name = "SynPS/2", |
| 777 | .alias = "synaptics", |
| 778 | .detect = synaptics_detect, |
| 779 | .init = synaptics_init, |
| 780 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 781 | #endif |
| 782 | #ifdef CONFIG_MOUSE_PS2_ALPS |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 783 | { |
| 784 | .type = PSMOUSE_ALPS, |
| 785 | .name = "AlpsPS/2", |
| 786 | .alias = "alps", |
| 787 | .detect = alps_detect, |
| 788 | .init = alps_init, |
| 789 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 790 | #endif |
| 791 | #ifdef CONFIG_MOUSE_PS2_LIFEBOOK |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 792 | { |
| 793 | .type = PSMOUSE_LIFEBOOK, |
| 794 | .name = "LBPS/2", |
| 795 | .alias = "lifebook", |
| 796 | .init = lifebook_init, |
| 797 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 798 | #endif |
| 799 | #ifdef CONFIG_MOUSE_PS2_TRACKPOINT |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 800 | { |
Stephen Evanchik | 541e316 | 2005-08-08 01:26:18 -0500 | [diff] [blame] | 801 | .type = PSMOUSE_TRACKPOINT, |
| 802 | .name = "TPPS/2", |
| 803 | .alias = "trackpoint", |
| 804 | .detect = trackpoint_detect, |
| 805 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 806 | #endif |
| 807 | #ifdef CONFIG_MOUSE_PS2_TOUCHKIT |
Stephen Evanchik | 541e316 | 2005-08-08 01:26:18 -0500 | [diff] [blame] | 808 | { |
Stefan Lucke | 24bf10a | 2007-02-18 01:49:10 -0500 | [diff] [blame] | 809 | .type = PSMOUSE_TOUCHKIT_PS2, |
| 810 | .name = "touchkitPS/2", |
| 811 | .alias = "touchkit", |
| 812 | .detect = touchkit_ps2_detect, |
| 813 | }, |
Andres Salomon | 55e3d92 | 2007-03-10 01:39:54 -0500 | [diff] [blame] | 814 | #endif |
Andres Salomon | df08ef2 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 815 | #ifdef CONFIG_MOUSE_PS2_OLPC |
| 816 | { |
| 817 | .type = PSMOUSE_HGPK, |
| 818 | .name = "OLPC HGPK", |
| 819 | .alias = "hgpk", |
| 820 | .detect = hgpk_detect, |
| 821 | }, |
| 822 | #endif |
Arjan Opmeer | 2a0bd75 | 2008-10-16 22:10:19 -0400 | [diff] [blame] | 823 | #ifdef CONFIG_MOUSE_PS2_ELANTECH |
| 824 | { |
| 825 | .type = PSMOUSE_ELANTECH, |
| 826 | .name = "ETPS/2", |
| 827 | .alias = "elantech", |
| 828 | .detect = elantech_detect, |
| 829 | .init = elantech_init, |
| 830 | }, |
Tai-hwa Liang | fc69f4a | 2009-05-10 18:15:39 -0700 | [diff] [blame] | 831 | #endif |
| 832 | #ifdef CONFIG_MOUSE_PS2_SENTELIC |
| 833 | { |
| 834 | .type = PSMOUSE_FSP, |
| 835 | .name = "FSPPS/2", |
| 836 | .alias = "fsp", |
| 837 | .detect = fsp_detect, |
| 838 | .init = fsp_init, |
| 839 | }, |
| 840 | #endif |
Stefan Lucke | 24bf10a | 2007-02-18 01:49:10 -0500 | [diff] [blame] | 841 | { |
Aristeu Rozanski | aea6a46 | 2007-05-10 01:47:18 -0400 | [diff] [blame] | 842 | .type = PSMOUSE_CORTRON, |
| 843 | .name = "CortronPS/2", |
| 844 | .alias = "cortps", |
| 845 | .detect = cortron_detect, |
| 846 | }, |
| 847 | { |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 848 | .type = PSMOUSE_AUTO, |
| 849 | .name = "auto", |
| 850 | .alias = "any", |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 851 | .maxproto = true, |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 852 | }, |
| 853 | }; |
| 854 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 855 | static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type) |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 856 | { |
| 857 | int i; |
| 858 | |
| 859 | for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) |
| 860 | if (psmouse_protocols[i].type == type) |
| 861 | return &psmouse_protocols[i]; |
| 862 | |
| 863 | WARN_ON(1); |
| 864 | return &psmouse_protocols[0]; |
| 865 | } |
| 866 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 867 | static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len) |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 868 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 869 | const struct psmouse_protocol *p; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 870 | int i; |
| 871 | |
| 872 | for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) { |
| 873 | p = &psmouse_protocols[i]; |
| 874 | |
| 875 | if ((strlen(p->name) == len && !strncmp(p->name, name, len)) || |
| 876 | (strlen(p->alias) == len && !strncmp(p->alias, name, len))) |
| 877 | return &psmouse_protocols[i]; |
| 878 | } |
| 879 | |
| 880 | return NULL; |
| 881 | } |
| 882 | |
| 883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | /* |
| 885 | * psmouse_probe() probes for a PS/2 mouse. |
| 886 | */ |
| 887 | |
| 888 | static int psmouse_probe(struct psmouse *psmouse) |
| 889 | { |
| 890 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 891 | unsigned char param[2]; |
| 892 | |
| 893 | /* |
| 894 | * First, we check if it's a mouse. It should send 0x00 or 0x03 |
| 895 | * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer. |
Vojtech Pavlik | 7741e93 | 2005-05-28 02:11:42 -0500 | [diff] [blame] | 896 | * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent |
| 897 | * ID queries, probably due to a firmware bug. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | */ |
| 899 | |
| 900 | param[0] = 0xa5; |
| 901 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) |
| 902 | return -1; |
| 903 | |
Vojtech Pavlik | 7741e93 | 2005-05-28 02:11:42 -0500 | [diff] [blame] | 904 | if (param[0] != 0x00 && param[0] != 0x03 && |
| 905 | param[0] != 0x04 && param[0] != 0xff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | return -1; |
| 907 | |
| 908 | /* |
| 909 | * Then we reset and disable the mouse so that it doesn't generate events. |
| 910 | */ |
| 911 | |
| 912 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS)) |
| 913 | printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", ps2dev->serio->phys); |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | /* |
| 919 | * Here we set the mouse resolution. |
| 920 | */ |
| 921 | |
| 922 | void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution) |
| 923 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 924 | static const unsigned char params[] = { 0, 1, 2, 2, 3 }; |
| 925 | unsigned char p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | if (resolution == 0 || resolution > 200) |
| 928 | resolution = 200; |
| 929 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 930 | p = params[resolution / 50]; |
| 931 | ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES); |
| 932 | psmouse->resolution = 25 << p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* |
| 936 | * Here we set the mouse report rate. |
| 937 | */ |
| 938 | |
| 939 | static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate) |
| 940 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 941 | static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; |
| 942 | unsigned char r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | int i = 0; |
| 944 | |
| 945 | while (rates[i] > rate) i++; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 946 | r = rates[i]; |
| 947 | ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE); |
| 948 | psmouse->rate = r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /* |
| 952 | * psmouse_initialize() initializes the mouse to a sane state. |
| 953 | */ |
| 954 | |
| 955 | static void psmouse_initialize(struct psmouse *psmouse) |
| 956 | { |
| 957 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | * We set the mouse report rate, resolution and scaling. |
| 959 | */ |
| 960 | |
| 961 | if (psmouse_max_proto != PSMOUSE_PS2) { |
| 962 | psmouse->set_rate(psmouse, psmouse->rate); |
| 963 | psmouse->set_resolution(psmouse, psmouse->resolution); |
| 964 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | * psmouse_activate() enables the mouse so that we get motion reports from it. |
| 970 | */ |
| 971 | |
| 972 | static void psmouse_activate(struct psmouse *psmouse) |
| 973 | { |
| 974 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) |
| 975 | printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n", |
| 976 | psmouse->ps2dev.serio->phys); |
| 977 | |
| 978 | psmouse_set_state(psmouse, PSMOUSE_ACTIVATED); |
| 979 | } |
| 980 | |
| 981 | |
| 982 | /* |
| 983 | * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion |
Jean Delvare | c03983a | 2007-10-19 23:22:55 +0200 | [diff] [blame] | 984 | * reports from it unless we explicitly request it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | */ |
| 986 | |
| 987 | static void psmouse_deactivate(struct psmouse *psmouse) |
| 988 | { |
| 989 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 990 | printk(KERN_WARNING "psmouse.c: Failed to deactivate mouse on %s\n", |
| 991 | psmouse->ps2dev.serio->phys); |
| 992 | |
| 993 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 994 | } |
| 995 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 996 | /* |
| 997 | * psmouse_poll() - default poll hanlder. Everyone except for ALPS uses it. |
| 998 | */ |
| 999 | |
| 1000 | static int psmouse_poll(struct psmouse *psmouse) |
| 1001 | { |
| 1002 | return ps2_command(&psmouse->ps2dev, psmouse->packet, |
| 1003 | PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)); |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | /* |
| 1008 | * psmouse_resync() attempts to re-validate current protocol. |
| 1009 | */ |
| 1010 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1011 | static void psmouse_resync(struct work_struct *work) |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1012 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1013 | struct psmouse *parent = NULL, *psmouse = |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 1014 | container_of(work, struct psmouse, resync_work.work); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1015 | struct serio *serio = psmouse->ps2dev.serio; |
| 1016 | psmouse_ret_t rc = PSMOUSE_GOOD_DATA; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1017 | bool failed = false, enabled = false; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1018 | int i; |
| 1019 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1020 | mutex_lock(&psmouse_mutex); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1021 | |
| 1022 | if (psmouse->state != PSMOUSE_RESYNCING) |
| 1023 | goto out; |
| 1024 | |
| 1025 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1026 | parent = serio_get_drvdata(serio->parent); |
| 1027 | psmouse_deactivate(parent); |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Some mice don't ACK commands sent while they are in the middle of |
| 1032 | * transmitting motion packet. To avoid delay we use ps2_sendbyte() |
| 1033 | * instead of ps2_command() which would wait for 200ms for an ACK |
| 1034 | * that may never come. |
| 1035 | * As an additional quirk ALPS touchpads may not only forget to ACK |
| 1036 | * disable command but will stop reporting taps, so if we see that |
| 1037 | * mouse at least once ACKs disable we will do full reconnect if ACK |
| 1038 | * is missing. |
| 1039 | */ |
| 1040 | psmouse->num_resyncs++; |
| 1041 | |
| 1042 | if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) { |
| 1043 | if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1044 | failed = true; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1045 | } else |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1046 | psmouse->acks_disable_command = true; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1047 | |
| 1048 | /* |
| 1049 | * Poll the mouse. If it was reset the packet will be shorter than |
| 1050 | * psmouse->pktsize and ps2_command will fail. We do not expect and |
| 1051 | * do not handle scenario when mouse "upgrades" its protocol while |
| 1052 | * disconnected since it would require additional delay. If we ever |
| 1053 | * see a mouse that does it we'll adjust the code. |
| 1054 | */ |
| 1055 | if (!failed) { |
| 1056 | if (psmouse->poll(psmouse)) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1057 | failed = true; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1058 | else { |
| 1059 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 1060 | for (i = 0; i < psmouse->pktsize; i++) { |
| 1061 | psmouse->pktcnt++; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1062 | rc = psmouse->protocol_handler(psmouse); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1063 | if (rc != PSMOUSE_GOOD_DATA) |
| 1064 | break; |
| 1065 | } |
| 1066 | if (rc != PSMOUSE_FULL_PACKET) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1067 | failed = true; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1068 | psmouse_set_state(psmouse, PSMOUSE_RESYNCING); |
| 1069 | } |
| 1070 | } |
| 1071 | /* |
| 1072 | * Now try to enable mouse. We try to do that even if poll failed and also |
| 1073 | * repeat our attempts 5 times, otherwise we may be left out with disabled |
| 1074 | * mouse. |
| 1075 | */ |
| 1076 | for (i = 0; i < 5; i++) { |
| 1077 | if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1078 | enabled = true; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1079 | break; |
| 1080 | } |
| 1081 | msleep(200); |
| 1082 | } |
| 1083 | |
| 1084 | if (!enabled) { |
| 1085 | printk(KERN_WARNING "psmouse.c: failed to re-enable mouse on %s\n", |
| 1086 | psmouse->ps2dev.serio->phys); |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1087 | failed = true; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | if (failed) { |
| 1091 | psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 1092 | printk(KERN_INFO "psmouse.c: resync failed, issuing reconnect request\n"); |
| 1093 | serio_reconnect(serio); |
| 1094 | } else |
| 1095 | psmouse_set_state(psmouse, PSMOUSE_ACTIVATED); |
| 1096 | |
| 1097 | if (parent) |
| 1098 | psmouse_activate(parent); |
| 1099 | out: |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1100 | mutex_unlock(&psmouse_mutex); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
| 1103 | /* |
| 1104 | * psmouse_cleanup() resets the mouse into power-on state. |
| 1105 | */ |
| 1106 | |
| 1107 | static void psmouse_cleanup(struct serio *serio) |
| 1108 | { |
| 1109 | struct psmouse *psmouse = serio_get_drvdata(serio); |
Dmitry Torokhov | a1cec06 | 2007-02-18 01:40:24 -0500 | [diff] [blame] | 1110 | struct psmouse *parent = NULL; |
| 1111 | |
| 1112 | mutex_lock(&psmouse_mutex); |
| 1113 | |
| 1114 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1115 | parent = serio_get_drvdata(serio->parent); |
| 1116 | psmouse_deactivate(parent); |
| 1117 | } |
| 1118 | |
| 1119 | psmouse_deactivate(psmouse); |
| 1120 | |
| 1121 | if (psmouse->cleanup) |
| 1122 | psmouse->cleanup(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
| 1124 | psmouse_reset(psmouse); |
Dmitry Torokhov | a1cec06 | 2007-02-18 01:40:24 -0500 | [diff] [blame] | 1125 | |
| 1126 | /* |
| 1127 | * Some boxes, such as HP nx7400, get terribly confused if mouse |
| 1128 | * is not fully enabled before suspending/shutting down. |
| 1129 | */ |
| 1130 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE); |
| 1131 | |
| 1132 | if (parent) { |
| 1133 | if (parent->pt_deactivate) |
| 1134 | parent->pt_deactivate(parent); |
| 1135 | |
| 1136 | psmouse_activate(parent); |
| 1137 | } |
| 1138 | |
| 1139 | mutex_unlock(&psmouse_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | /* |
| 1143 | * psmouse_disconnect() closes and frees. |
| 1144 | */ |
| 1145 | |
| 1146 | static void psmouse_disconnect(struct serio *serio) |
| 1147 | { |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1148 | struct psmouse *psmouse, *parent = NULL; |
| 1149 | |
| 1150 | psmouse = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1152 | sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1154 | mutex_lock(&psmouse_mutex); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 1157 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1158 | /* make sure we don't have a resync in progress */ |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1159 | mutex_unlock(&psmouse_mutex); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1160 | flush_workqueue(kpsmoused_wq); |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1161 | mutex_lock(&psmouse_mutex); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1164 | parent = serio_get_drvdata(serio->parent); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1165 | psmouse_deactivate(parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | if (psmouse->disconnect) |
| 1169 | psmouse->disconnect(psmouse); |
| 1170 | |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1171 | if (parent && parent->pt_deactivate) |
| 1172 | parent->pt_deactivate(parent); |
| 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | serio_close(serio); |
| 1177 | serio_set_drvdata(serio, NULL); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1178 | input_unregister_device(psmouse->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | kfree(psmouse); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1180 | |
| 1181 | if (parent) |
| 1182 | psmouse_activate(parent); |
| 1183 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1184 | mutex_unlock(&psmouse_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 1187 | static int psmouse_switch_protocol(struct psmouse *psmouse, const struct psmouse_protocol *proto) |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1188 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1189 | struct input_dev *input_dev = psmouse->dev; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1190 | |
Dmitry Torokhov | 28aa7f1 | 2007-04-12 01:35:09 -0400 | [diff] [blame] | 1191 | input_dev->dev.parent = &psmouse->ps2dev.serio->dev; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1192 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1193 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 1194 | input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | |
| 1195 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
| 1196 | input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1197 | |
| 1198 | psmouse->set_rate = psmouse_set_rate; |
| 1199 | psmouse->set_resolution = psmouse_set_resolution; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1200 | psmouse->poll = psmouse_poll; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1201 | psmouse->protocol_handler = psmouse_process_byte; |
| 1202 | psmouse->pktsize = 3; |
| 1203 | |
| 1204 | if (proto && (proto->detect || proto->init)) { |
| 1205 | if (proto->detect && proto->detect(psmouse, 1) < 0) |
| 1206 | return -1; |
| 1207 | |
| 1208 | if (proto->init && proto->init(psmouse) < 0) |
| 1209 | return -1; |
| 1210 | |
| 1211 | psmouse->type = proto->type; |
| 1212 | } |
| 1213 | else |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1214 | psmouse->type = psmouse_extensions(psmouse, |
| 1215 | psmouse_max_proto, true); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1216 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1217 | /* |
| 1218 | * If mouse's packet size is 3 there is no point in polling the |
| 1219 | * device in hopes to detect protocol reset - we won't get less |
| 1220 | * than 3 bytes response anyhow. |
| 1221 | */ |
| 1222 | if (psmouse->pktsize == 3) |
| 1223 | psmouse->resync_time = 0; |
| 1224 | |
| 1225 | /* |
| 1226 | * Some smart KVMs fake response to POLL command returning just |
| 1227 | * 3 bytes and messing up our resync logic, so if initial poll |
| 1228 | * fails we won't try polling the device anymore. Hopefully |
| 1229 | * such KVM will maintain initially selected protocol. |
| 1230 | */ |
| 1231 | if (psmouse->resync_time && psmouse->poll(psmouse)) |
| 1232 | psmouse->resync_time = 0; |
| 1233 | |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 1234 | snprintf(psmouse->devname, sizeof(psmouse->devname), "%s %s %s", |
| 1235 | psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1236 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1237 | input_dev->name = psmouse->devname; |
| 1238 | input_dev->phys = psmouse->phys; |
| 1239 | input_dev->id.bustype = BUS_I8042; |
| 1240 | input_dev->id.vendor = 0x0002; |
| 1241 | input_dev->id.product = psmouse->type; |
| 1242 | input_dev->id.version = psmouse->model; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | /* |
| 1248 | * psmouse_connect() is a callback from the serio module when |
| 1249 | * an unhandled serio port is found. |
| 1250 | */ |
| 1251 | static int psmouse_connect(struct serio *serio, struct serio_driver *drv) |
| 1252 | { |
| 1253 | struct psmouse *psmouse, *parent = NULL; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1254 | struct input_dev *input_dev; |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1255 | int retval = 0, error = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1257 | mutex_lock(&psmouse_mutex); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | /* |
| 1260 | * If this is a pass-through port deactivate parent so the device |
| 1261 | * connected to this port can be successfully identified |
| 1262 | */ |
| 1263 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1264 | parent = serio_get_drvdata(serio->parent); |
| 1265 | psmouse_deactivate(parent); |
| 1266 | } |
| 1267 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1268 | psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL); |
| 1269 | input_dev = input_allocate_device(); |
| 1270 | if (!psmouse || !input_dev) |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1271 | goto err_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | ps2_init(&psmouse->ps2dev, serio); |
Andres Salomon | 8bf020e | 2008-09-16 12:30:33 -0400 | [diff] [blame] | 1274 | INIT_DELAYED_WORK(&psmouse->resync_work, psmouse_resync); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1275 | psmouse->dev = input_dev; |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 1276 | snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); |
| 1279 | |
| 1280 | serio_set_drvdata(serio, psmouse); |
| 1281 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1282 | error = serio_open(serio, drv); |
| 1283 | if (error) |
| 1284 | goto err_clear_drvdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
| 1286 | if (psmouse_probe(psmouse) < 0) { |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1287 | error = -ENODEV; |
| 1288 | goto err_close_serio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | psmouse->rate = psmouse_rate; |
| 1292 | psmouse->resolution = psmouse_resolution; |
| 1293 | psmouse->resetafter = psmouse_resetafter; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1294 | psmouse->resync_time = parent ? 0 : psmouse_resync_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | psmouse->smartscroll = psmouse_smartscroll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1297 | psmouse_switch_protocol(psmouse, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | psmouse_initialize(psmouse); |
| 1301 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1302 | error = input_register_device(psmouse->dev); |
| 1303 | if (error) |
| 1304 | goto err_protocol_disconnect; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | if (parent && parent->pt_activate) |
| 1307 | parent->pt_activate(parent); |
| 1308 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1309 | error = sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group); |
| 1310 | if (error) |
| 1311 | goto err_pt_deactivate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
| 1313 | psmouse_activate(psmouse); |
| 1314 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1315 | out: |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1316 | /* If this is a pass-through port the parent needs to be re-activated */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | if (parent) |
| 1318 | psmouse_activate(parent); |
| 1319 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1320 | mutex_unlock(&psmouse_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | return retval; |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1322 | |
| 1323 | err_pt_deactivate: |
| 1324 | if (parent && parent->pt_deactivate) |
| 1325 | parent->pt_deactivate(parent); |
Andres Salomon | 746b31a | 2008-01-17 12:01:30 -0500 | [diff] [blame] | 1326 | input_unregister_device(psmouse->dev); |
| 1327 | input_dev = NULL; /* so we don't try to free it below */ |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1328 | err_protocol_disconnect: |
| 1329 | if (psmouse->disconnect) |
| 1330 | psmouse->disconnect(psmouse); |
| 1331 | psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 1332 | err_close_serio: |
| 1333 | serio_close(serio); |
| 1334 | err_clear_drvdata: |
| 1335 | serio_set_drvdata(serio, NULL); |
| 1336 | err_free: |
| 1337 | input_free_device(input_dev); |
| 1338 | kfree(psmouse); |
| 1339 | |
| 1340 | retval = error; |
| 1341 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | static int psmouse_reconnect(struct serio *serio) |
| 1346 | { |
| 1347 | struct psmouse *psmouse = serio_get_drvdata(serio); |
| 1348 | struct psmouse *parent = NULL; |
| 1349 | struct serio_driver *drv = serio->drv; |
| 1350 | int rc = -1; |
| 1351 | |
| 1352 | if (!drv || !psmouse) { |
| 1353 | printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n"); |
| 1354 | return -1; |
| 1355 | } |
| 1356 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1357 | mutex_lock(&psmouse_mutex); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1360 | parent = serio_get_drvdata(serio->parent); |
| 1361 | psmouse_deactivate(parent); |
| 1362 | } |
| 1363 | |
| 1364 | psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); |
| 1365 | |
| 1366 | if (psmouse->reconnect) { |
| 1367 | if (psmouse->reconnect(psmouse)) |
| 1368 | goto out; |
| 1369 | } else if (psmouse_probe(psmouse) < 0 || |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1370 | psmouse->type != psmouse_extensions(psmouse, |
| 1371 | psmouse_max_proto, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | goto out; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | |
| 1375 | /* ok, the device type (and capabilities) match the old one, |
| 1376 | * we can continue using it, complete intialization |
| 1377 | */ |
| 1378 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 1379 | |
| 1380 | psmouse_initialize(psmouse); |
| 1381 | |
| 1382 | if (parent && parent->pt_activate) |
| 1383 | parent->pt_activate(parent); |
| 1384 | |
| 1385 | psmouse_activate(psmouse); |
| 1386 | rc = 0; |
| 1387 | |
| 1388 | out: |
| 1389 | /* If this is a pass-through port the parent waits to be activated */ |
| 1390 | if (parent) |
| 1391 | psmouse_activate(parent); |
| 1392 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1393 | mutex_unlock(&psmouse_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | return rc; |
| 1395 | } |
| 1396 | |
| 1397 | static struct serio_device_id psmouse_serio_ids[] = { |
| 1398 | { |
| 1399 | .type = SERIO_8042, |
| 1400 | .proto = SERIO_ANY, |
| 1401 | .id = SERIO_ANY, |
| 1402 | .extra = SERIO_ANY, |
| 1403 | }, |
| 1404 | { |
| 1405 | .type = SERIO_PS_PSTHRU, |
| 1406 | .proto = SERIO_ANY, |
| 1407 | .id = SERIO_ANY, |
| 1408 | .extra = SERIO_ANY, |
| 1409 | }, |
| 1410 | { 0 } |
| 1411 | }; |
| 1412 | |
| 1413 | MODULE_DEVICE_TABLE(serio, psmouse_serio_ids); |
| 1414 | |
| 1415 | static struct serio_driver psmouse_drv = { |
| 1416 | .driver = { |
| 1417 | .name = "psmouse", |
| 1418 | }, |
| 1419 | .description = DRIVER_DESC, |
| 1420 | .id_table = psmouse_serio_ids, |
| 1421 | .interrupt = psmouse_interrupt, |
| 1422 | .connect = psmouse_connect, |
| 1423 | .reconnect = psmouse_reconnect, |
| 1424 | .disconnect = psmouse_disconnect, |
| 1425 | .cleanup = psmouse_cleanup, |
| 1426 | }; |
| 1427 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1428 | ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr, |
| 1429 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | { |
| 1431 | struct serio *serio = to_serio_port(dev); |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1432 | struct psmouse_attribute *attr = to_psmouse_attr(devattr); |
| 1433 | struct psmouse *psmouse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | int retval; |
| 1435 | |
| 1436 | retval = serio_pin_driver(serio); |
| 1437 | if (retval) |
| 1438 | return retval; |
| 1439 | |
| 1440 | if (serio->drv != &psmouse_drv) { |
| 1441 | retval = -ENODEV; |
| 1442 | goto out; |
| 1443 | } |
| 1444 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1445 | psmouse = serio_get_drvdata(serio); |
| 1446 | |
| 1447 | retval = attr->show(psmouse, attr->data, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
| 1449 | out: |
| 1450 | serio_unpin_driver(serio); |
| 1451 | return retval; |
| 1452 | } |
| 1453 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1454 | ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr, |
| 1455 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
| 1457 | struct serio *serio = to_serio_port(dev); |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1458 | struct psmouse_attribute *attr = to_psmouse_attr(devattr); |
| 1459 | struct psmouse *psmouse, *parent = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | int retval; |
| 1461 | |
| 1462 | retval = serio_pin_driver(serio); |
| 1463 | if (retval) |
| 1464 | return retval; |
| 1465 | |
| 1466 | if (serio->drv != &psmouse_drv) { |
| 1467 | retval = -ENODEV; |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1468 | goto out_unpin; |
| 1469 | } |
| 1470 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1471 | retval = mutex_lock_interruptible(&psmouse_mutex); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1472 | if (retval) |
| 1473 | goto out_unpin; |
| 1474 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1475 | psmouse = serio_get_drvdata(serio); |
| 1476 | |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 1477 | if (attr->protect) { |
| 1478 | if (psmouse->state == PSMOUSE_IGNORE) { |
| 1479 | retval = -ENODEV; |
| 1480 | goto out_unlock; |
| 1481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 1483 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1484 | parent = serio_get_drvdata(serio->parent); |
| 1485 | psmouse_deactivate(parent); |
| 1486 | } |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1487 | |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 1488 | psmouse_deactivate(psmouse); |
| 1489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1491 | retval = attr->set(psmouse, attr->data, buf, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 1493 | if (attr->protect) { |
| 1494 | if (retval != -ENODEV) |
| 1495 | psmouse_activate(psmouse); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1496 | |
Andres Salomon | 68d4822 | 2008-09-16 12:30:34 -0400 | [diff] [blame] | 1497 | if (parent) |
| 1498 | psmouse_activate(parent); |
| 1499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1501 | out_unlock: |
| 1502 | mutex_unlock(&psmouse_mutex); |
Dmitry Torokhov | 04df192 | 2005-06-01 02:39:44 -0500 | [diff] [blame] | 1503 | out_unpin: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | serio_unpin_driver(serio); |
| 1505 | return retval; |
| 1506 | } |
| 1507 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1508 | static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf) |
| 1509 | { |
Sergey Vlasov | eb5d582 | 2006-11-09 00:34:27 -0500 | [diff] [blame] | 1510 | unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset); |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1511 | |
Sergey Vlasov | eb5d582 | 2006-11-09 00:34:27 -0500 | [diff] [blame] | 1512 | return sprintf(buf, "%u\n", *field); |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count) |
| 1516 | { |
Sergey Vlasov | eb5d582 | 2006-11-09 00:34:27 -0500 | [diff] [blame] | 1517 | unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset); |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1518 | unsigned long value; |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1519 | |
Joe Rouvier | 160f1fe | 2008-08-10 00:29:25 -0400 | [diff] [blame] | 1520 | if (strict_strtoul(buf, 10, &value)) |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1521 | return -EINVAL; |
| 1522 | |
Sergey Vlasov | eb5d582 | 2006-11-09 00:34:27 -0500 | [diff] [blame] | 1523 | if ((unsigned int)value != value) |
| 1524 | return -EINVAL; |
| 1525 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1526 | *field = value; |
| 1527 | |
| 1528 | return count; |
| 1529 | } |
| 1530 | |
| 1531 | static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf) |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1532 | { |
| 1533 | return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name); |
| 1534 | } |
| 1535 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1536 | static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count) |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1537 | { |
| 1538 | struct serio *serio = psmouse->ps2dev.serio; |
| 1539 | struct psmouse *parent = NULL; |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1540 | struct input_dev *old_dev, *new_dev; |
| 1541 | const struct psmouse_protocol *proto, *old_proto; |
| 1542 | int error; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1543 | int retry = 0; |
| 1544 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1545 | proto = psmouse_protocol_by_name(buf, count); |
| 1546 | if (!proto) |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1547 | return -EINVAL; |
| 1548 | |
| 1549 | if (psmouse->type == proto->type) |
| 1550 | return count; |
| 1551 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1552 | new_dev = input_allocate_device(); |
| 1553 | if (!new_dev) |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1554 | return -ENOMEM; |
| 1555 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1556 | while (serio->child) { |
| 1557 | if (++retry > 3) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1558 | printk(KERN_WARNING |
| 1559 | "psmouse: failed to destroy child port, " |
| 1560 | "protocol change aborted.\n"); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1561 | input_free_device(new_dev); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1562 | return -EIO; |
| 1563 | } |
| 1564 | |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1565 | mutex_unlock(&psmouse_mutex); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1566 | serio_unpin_driver(serio); |
| 1567 | serio_unregister_child_port(serio); |
| 1568 | serio_pin_driver_uninterruptible(serio); |
Ingo Molnar | c14471d | 2006-02-19 00:22:11 -0500 | [diff] [blame] | 1569 | mutex_lock(&psmouse_mutex); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1570 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1571 | if (serio->drv != &psmouse_drv) { |
| 1572 | input_free_device(new_dev); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1573 | return -ENODEV; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1574 | } |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1575 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1576 | if (psmouse->type == proto->type) { |
| 1577 | input_free_device(new_dev); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1578 | return count; /* switched by other thread */ |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1579 | } |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { |
| 1583 | parent = serio_get_drvdata(serio->parent); |
| 1584 | if (parent->pt_deactivate) |
| 1585 | parent->pt_deactivate(parent); |
| 1586 | } |
| 1587 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1588 | old_dev = psmouse->dev; |
| 1589 | old_proto = psmouse_protocol_by_type(psmouse->type); |
| 1590 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1591 | if (psmouse->disconnect) |
| 1592 | psmouse->disconnect(psmouse); |
| 1593 | |
| 1594 | psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1595 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1596 | psmouse->dev = new_dev; |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1597 | psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); |
| 1598 | |
| 1599 | if (psmouse_switch_protocol(psmouse, proto) < 0) { |
| 1600 | psmouse_reset(psmouse); |
| 1601 | /* default to PSMOUSE_PS2 */ |
| 1602 | psmouse_switch_protocol(psmouse, &psmouse_protocols[0]); |
| 1603 | } |
| 1604 | |
| 1605 | psmouse_initialize(psmouse); |
| 1606 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 1607 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 1608 | error = input_register_device(psmouse->dev); |
| 1609 | if (error) { |
| 1610 | if (psmouse->disconnect) |
| 1611 | psmouse->disconnect(psmouse); |
| 1612 | |
| 1613 | psmouse_set_state(psmouse, PSMOUSE_IGNORE); |
| 1614 | input_free_device(new_dev); |
| 1615 | psmouse->dev = old_dev; |
| 1616 | psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); |
| 1617 | psmouse_switch_protocol(psmouse, old_proto); |
| 1618 | psmouse_initialize(psmouse); |
| 1619 | psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); |
| 1620 | |
| 1621 | return error; |
| 1622 | } |
| 1623 | |
| 1624 | input_unregister_device(old_dev); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1625 | |
| 1626 | if (parent && parent->pt_activate) |
| 1627 | parent->pt_activate(parent); |
| 1628 | |
| 1629 | return count; |
| 1630 | } |
| 1631 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1632 | static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | { |
| 1634 | unsigned long value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | |
Joe Rouvier | 160f1fe | 2008-08-10 00:29:25 -0400 | [diff] [blame] | 1636 | if (strict_strtoul(buf, 10, &value)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | return -EINVAL; |
| 1638 | |
| 1639 | psmouse->set_rate(psmouse, value); |
| 1640 | return count; |
| 1641 | } |
| 1642 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 1643 | static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | { |
| 1645 | unsigned long value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Joe Rouvier | 160f1fe | 2008-08-10 00:29:25 -0400 | [diff] [blame] | 1647 | if (strict_strtoul(buf, 10, &value)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | return -EINVAL; |
| 1649 | |
| 1650 | psmouse->set_resolution(psmouse, value); |
| 1651 | return count; |
| 1652 | } |
| 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | |
| 1655 | static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) |
| 1656 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 1657 | const struct psmouse_protocol *proto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
| 1659 | if (!val) |
| 1660 | return -EINVAL; |
| 1661 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1662 | proto = psmouse_protocol_by_name(val, strlen(val)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1664 | if (!proto || !proto->maxproto) |
| 1665 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1667 | *((unsigned int *)kp->arg) = proto->type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
Stephen Evanchik | 541e316 | 2005-08-08 01:26:18 -0500 | [diff] [blame] | 1669 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) |
| 1673 | { |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 1674 | int type = *((unsigned int *)kp->arg); |
| 1675 | |
| 1676 | return sprintf(buffer, "%s\n", psmouse_protocol_by_type(type)->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | static int __init psmouse_init(void) |
| 1680 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 1681 | int err; |
| 1682 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1683 | kpsmoused_wq = create_singlethread_workqueue("kpsmoused"); |
| 1684 | if (!kpsmoused_wq) { |
| 1685 | printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n"); |
| 1686 | return -ENOMEM; |
| 1687 | } |
| 1688 | |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 1689 | err = serio_register_driver(&psmouse_drv); |
| 1690 | if (err) |
| 1691 | destroy_workqueue(kpsmoused_wq); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1692 | |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 1693 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | static void __exit psmouse_exit(void) |
| 1697 | { |
| 1698 | serio_unregister_driver(&psmouse_drv); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1699 | destroy_workqueue(kpsmoused_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | module_init(psmouse_init); |
| 1703 | module_exit(psmouse_exit); |