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