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