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