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