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