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