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