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