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