aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2015-12-17 18:25:10 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-12-17 18:25:10 -0500
commitf01c5e652ca949722a7fe4cfdecd73e8026971d2 (patch)
tree95ccc81f76a685e1e3462fd8555e96156b83993a
parent40e3be3933aee185fd6ab1ec87dfaf3502d9f5b3 (diff)
parent190e2031e2db542094659cfa55bfc28545458df5 (diff)
Merge branch 'psmouse-passthrough' into next
Bring in changes to limit number of protocols we try on pass-though PS/2 ports so that probe ocmpletes faster.
-rw-r--r--drivers/input/mouse/focaltech.c22
-rw-r--r--drivers/input/mouse/focaltech.h8
-rw-r--r--drivers/input/mouse/logips2pp.c2
-rw-r--r--drivers/input/mouse/logips2pp.h4
-rw-r--r--drivers/input/mouse/psmouse-base.c770
5 files changed, 392 insertions, 414 deletions
diff --git a/drivers/input/mouse/focaltech.c b/drivers/input/mouse/focaltech.c
index 4d5576de81be..c8c6a8cc329d 100644
--- a/drivers/input/mouse/focaltech.c
+++ b/drivers/input/mouse/focaltech.c
@@ -49,12 +49,6 @@ int focaltech_detect(struct psmouse *psmouse, bool set_properties)
49 return 0; 49 return 0;
50} 50}
51 51
52static void focaltech_reset(struct psmouse *psmouse)
53{
54 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
55 psmouse_reset(psmouse);
56}
57
58#ifdef CONFIG_MOUSE_PS2_FOCALTECH 52#ifdef CONFIG_MOUSE_PS2_FOCALTECH
59 53
60/* 54/*
@@ -300,6 +294,12 @@ static int focaltech_switch_protocol(struct psmouse *psmouse)
300 return 0; 294 return 0;
301} 295}
302 296
297static void focaltech_reset(struct psmouse *psmouse)
298{
299 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
300 psmouse_reset(psmouse);
301}
302
303static void focaltech_disconnect(struct psmouse *psmouse) 303static void focaltech_disconnect(struct psmouse *psmouse)
304{ 304{
305 focaltech_reset(psmouse); 305 focaltech_reset(psmouse);
@@ -456,14 +456,4 @@ fail:
456 kfree(priv); 456 kfree(priv);
457 return error; 457 return error;
458} 458}
459
460#else /* CONFIG_MOUSE_PS2_FOCALTECH */
461
462int focaltech_init(struct psmouse *psmouse)
463{
464 focaltech_reset(psmouse);
465
466 return 0;
467}
468
469#endif /* CONFIG_MOUSE_PS2_FOCALTECH */ 459#endif /* CONFIG_MOUSE_PS2_FOCALTECH */
diff --git a/drivers/input/mouse/focaltech.h b/drivers/input/mouse/focaltech.h
index ca61ebff373e..783b28e8e10b 100644
--- a/drivers/input/mouse/focaltech.h
+++ b/drivers/input/mouse/focaltech.h
@@ -18,6 +18,14 @@
18#define _FOCALTECH_H 18#define _FOCALTECH_H
19 19
20int focaltech_detect(struct psmouse *psmouse, bool set_properties); 20int focaltech_detect(struct psmouse *psmouse, bool set_properties);
21
22#ifdef CONFIG_MOUSE_PS2_FOCALTECH
21int focaltech_init(struct psmouse *psmouse); 23int focaltech_init(struct psmouse *psmouse);
24#else
25static inline int focaltech_init(struct psmouse *psmouse)
26{
27 return -ENOSYS;
28}
29#endif
22 30
23#endif 31#endif
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 136e222e2a16..422da1cd9e76 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -325,7 +325,7 @@ static void ps2pp_set_model_properties(struct psmouse *psmouse,
325 * that support it. 325 * that support it.
326 */ 326 */
327 327
328int ps2pp_init(struct psmouse *psmouse, bool set_properties) 328int ps2pp_detect(struct psmouse *psmouse, bool set_properties)
329{ 329{
330 struct ps2dev *ps2dev = &psmouse->ps2dev; 330 struct ps2dev *ps2dev = &psmouse->ps2dev;
331 unsigned char param[4]; 331 unsigned char param[4];
diff --git a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
index 0c186f0282d9..bf629453e095 100644
--- a/drivers/input/mouse/logips2pp.h
+++ b/drivers/input/mouse/logips2pp.h
@@ -12,9 +12,9 @@
12#define _LOGIPS2PP_H 12#define _LOGIPS2PP_H
13 13
14#ifdef CONFIG_MOUSE_PS2_LOGIPS2PP 14#ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
15int ps2pp_init(struct psmouse *psmouse, bool set_properties); 15int ps2pp_detect(struct psmouse *psmouse, bool set_properties);
16#else 16#else
17inline int ps2pp_init(struct psmouse *psmouse, bool set_properties) 17static inline int ps2pp_detect(struct psmouse *psmouse, bool set_properties)
18{ 18{
19 return -ENOSYS; 19 return -ENOSYS;
20} 20}
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index ad18dab0ac47..b9e4ee34c132 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -119,6 +119,7 @@ struct psmouse_protocol {
119 enum psmouse_type type; 119 enum psmouse_type type;
120 bool maxproto; 120 bool maxproto;
121 bool ignore_parity; /* Protocol should ignore parity errors from KBC */ 121 bool ignore_parity; /* Protocol should ignore parity errors from KBC */
122 bool try_passthru; /* Try protocol also on passthrough ports */
122 const char *name; 123 const char *name;
123 const char *alias; 124 const char *alias;
124 int (*detect)(struct psmouse *, bool); 125 int (*detect)(struct psmouse *, bool);
@@ -129,7 +130,6 @@ struct psmouse_protocol {
129 * psmouse_process_byte() analyzes the PS/2 data stream and reports 130 * psmouse_process_byte() analyzes the PS/2 data stream and reports
130 * relevant events to the input module once full packet has arrived. 131 * relevant events to the input module once full packet has arrived.
131 */ 132 */
132
133psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) 133psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
134{ 134{
135 struct input_dev *dev = psmouse->dev; 135 struct input_dev *dev = psmouse->dev;
@@ -138,22 +138,16 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
138 if (psmouse->pktcnt < psmouse->pktsize) 138 if (psmouse->pktcnt < psmouse->pktsize)
139 return PSMOUSE_GOOD_DATA; 139 return PSMOUSE_GOOD_DATA;
140 140
141/* 141 /* Full packet accumulated, process it */
142 * Full packet accumulated, process it
143 */
144 142
145/* 143 switch (psmouse->type) {
146 * Scroll wheel on IntelliMice, scroll buttons on NetMice 144 case PSMOUSE_IMPS:
147 */ 145 /* IntelliMouse has scroll wheel */
148
149 if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS)
150 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 146 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
147 break;
151 148
152/* 149 case PSMOUSE_IMEX:
153 * Scroll wheel and buttons on IntelliMouse Explorer 150 /* Scroll wheel and buttons on IntelliMouse Explorer */
154 */
155
156 if (psmouse->type == PSMOUSE_IMEX) {
157 switch (packet[3] & 0xC0) { 151 switch (packet[3] & 0xC0) {
158 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */ 152 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
159 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); 153 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
@@ -168,39 +162,42 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
168 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); 162 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1);
169 break; 163 break;
170 } 164 }
171 } 165 break;
172 166
173/* 167 case PSMOUSE_GENPS:
174 * Extra buttons on Genius NewNet 3D 168 /* Report scroll buttons on NetMice */
175 */ 169 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
176 170
177 if (psmouse->type == PSMOUSE_GENPS) { 171 /* Extra buttons on Genius NewNet 3D */
178 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); 172 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
179 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); 173 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
180 } 174 break;
181 175
182/* 176 case PSMOUSE_THINKPS:
183 * Extra button on ThinkingMouse 177 /* Extra button on ThinkingMouse */
184 */
185 if (psmouse->type == PSMOUSE_THINKPS) {
186 input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); 178 input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1);
187 /* Without this bit of weirdness moving up gives wildly high Y changes. */ 179
180 /*
181 * Without this bit of weirdness moving up gives wildly
182 * high Y changes.
183 */
188 packet[1] |= (packet[0] & 0x40) << 1; 184 packet[1] |= (packet[0] & 0x40) << 1;
189 } 185 break;
190 186
191/* 187 case PSMOUSE_CORTRON:
192 * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first 188 /*
193 * byte. 189 * Cortron PS2 Trackball reports SIDE button in the
194 */ 190 * 4th bit of the first byte.
195 if (psmouse->type == PSMOUSE_CORTRON) { 191 */
196 input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1); 192 input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1);
197 packet[0] |= 0x08; 193 packet[0] |= 0x08;
198 } 194 break;
199 195
200/* 196 default:
201 * Generic PS/2 Mouse 197 break;
202 */ 198 }
203 199
200 /* Generic PS/2 Mouse */
204 input_report_key(dev, BTN_LEFT, packet[0] & 1); 201 input_report_key(dev, BTN_LEFT, packet[0] & 1);
205 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); 202 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
206 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); 203 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
@@ -222,7 +219,6 @@ void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
222/* 219/*
223 * __psmouse_set_state() sets new psmouse state and resets all flags. 220 * __psmouse_set_state() sets new psmouse state and resets all flags.
224 */ 221 */
225
226static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) 222static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
227{ 223{
228 psmouse->state = new_state; 224 psmouse->state = new_state;
@@ -231,13 +227,11 @@ static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_sta
231 psmouse->last = jiffies; 227 psmouse->last = jiffies;
232} 228}
233 229
234
235/* 230/*
236 * psmouse_set_state() sets new psmouse state and resets all flags and 231 * psmouse_set_state() sets new psmouse state and resets all flags and
237 * counters while holding serio lock so fighting with interrupt handler 232 * counters while holding serio lock so fighting with interrupt handler
238 * is not a concern. 233 * is not a concern.
239 */ 234 */
240
241void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) 235void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
242{ 236{
243 serio_pause_rx(psmouse->ps2dev.serio); 237 serio_pause_rx(psmouse->ps2dev.serio);
@@ -249,7 +243,6 @@ void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
249 * psmouse_handle_byte() processes one byte of the input data stream 243 * psmouse_handle_byte() processes one byte of the input data stream
250 * by calling corresponding protocol handler. 244 * by calling corresponding protocol handler.
251 */ 245 */
252
253static int psmouse_handle_byte(struct psmouse *psmouse) 246static int psmouse_handle_byte(struct psmouse *psmouse)
254{ 247{
255 psmouse_ret_t rc = psmouse->protocol_handler(psmouse); 248 psmouse_ret_t rc = psmouse->protocol_handler(psmouse);
@@ -292,7 +285,6 @@ static int psmouse_handle_byte(struct psmouse *psmouse)
292 * psmouse_interrupt() handles incoming characters, either passing them 285 * psmouse_interrupt() handles incoming characters, either passing them
293 * for normal processing or gathering them as command response. 286 * for normal processing or gathering them as command response.
294 */ 287 */
295
296static irqreturn_t psmouse_interrupt(struct serio *serio, 288static irqreturn_t psmouse_interrupt(struct serio *serio,
297 unsigned char data, unsigned int flags) 289 unsigned char data, unsigned int flags)
298{ 290{
@@ -335,9 +327,8 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
335 } 327 }
336 328
337 psmouse->packet[psmouse->pktcnt++] = data; 329 psmouse->packet[psmouse->pktcnt++] = data;
338/* 330
339 * Check if this is a new device announcement (0xAA 0x00) 331 /* Check if this is a new device announcement (0xAA 0x00) */
340 */
341 if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) { 332 if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) {
342 if (psmouse->pktcnt == 1) { 333 if (psmouse->pktcnt == 1) {
343 psmouse->last = jiffies; 334 psmouse->last = jiffies;
@@ -351,9 +342,8 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
351 serio_reconnect(serio); 342 serio_reconnect(serio);
352 goto out; 343 goto out;
353 } 344 }
354/* 345
355 * Not a new device, try processing first byte normally 346 /* Not a new device, try processing first byte normally */
356 */
357 psmouse->pktcnt = 1; 347 psmouse->pktcnt = 1;
358 if (psmouse_handle_byte(psmouse)) 348 if (psmouse_handle_byte(psmouse))
359 goto out; 349 goto out;
@@ -361,9 +351,10 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
361 psmouse->packet[psmouse->pktcnt++] = data; 351 psmouse->packet[psmouse->pktcnt++] = data;
362 } 352 }
363 353
364/* 354 /*
365 * See if we need to force resync because mouse was idle for too long 355 * See if we need to force resync because mouse was idle for
366 */ 356 * too long.
357 */
367 if (psmouse->state == PSMOUSE_ACTIVATED && 358 if (psmouse->state == PSMOUSE_ACTIVATED &&
368 psmouse->pktcnt == 1 && psmouse->resync_time && 359 psmouse->pktcnt == 1 && psmouse->resync_time &&
369 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) { 360 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
@@ -380,7 +371,6 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
380 return IRQ_HANDLED; 371 return IRQ_HANDLED;
381} 372}
382 373
383
384/* 374/*
385 * psmouse_sliced_command() sends an extended PS/2 command to the mouse 375 * psmouse_sliced_command() sends an extended PS/2 command to the mouse
386 * using sliced syntax, understood by advanced devices, such as Logitech 376 * using sliced syntax, understood by advanced devices, such as Logitech
@@ -404,7 +394,6 @@ int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command)
404 return 0; 394 return 0;
405} 395}
406 396
407
408/* 397/*
409 * psmouse_reset() resets the mouse into power-on state. 398 * psmouse_reset() resets the mouse into power-on state.
410 */ 399 */
@@ -424,7 +413,6 @@ int psmouse_reset(struct psmouse *psmouse)
424/* 413/*
425 * Here we set the mouse resolution. 414 * Here we set the mouse resolution.
426 */ 415 */
427
428void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution) 416void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
429{ 417{
430 static const unsigned char params[] = { 0, 1, 2, 2, 3 }; 418 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
@@ -441,7 +429,6 @@ void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
441/* 429/*
442 * Here we set the mouse report rate. 430 * Here we set the mouse report rate.
443 */ 431 */
444
445static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate) 432static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
446{ 433{
447 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; 434 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
@@ -457,7 +444,6 @@ static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
457/* 444/*
458 * Here we set the mouse scaling. 445 * Here we set the mouse scaling.
459 */ 446 */
460
461static void psmouse_set_scale(struct psmouse *psmouse, enum psmouse_scale scale) 447static void psmouse_set_scale(struct psmouse *psmouse, enum psmouse_scale scale)
462{ 448{
463 ps2_command(&psmouse->ps2dev, NULL, 449 ps2_command(&psmouse->ps2dev, NULL,
@@ -468,7 +454,6 @@ static void psmouse_set_scale(struct psmouse *psmouse, enum psmouse_scale scale)
468/* 454/*
469 * psmouse_poll() - default poll handler. Everyone except for ALPS uses it. 455 * psmouse_poll() - default poll handler. Everyone except for ALPS uses it.
470 */ 456 */
471
472static int psmouse_poll(struct psmouse *psmouse) 457static int psmouse_poll(struct psmouse *psmouse)
473{ 458{
474 return ps2_command(&psmouse->ps2dev, psmouse->packet, 459 return ps2_command(&psmouse->ps2dev, psmouse->packet,
@@ -602,7 +587,7 @@ static int im_explorer_detect(struct psmouse *psmouse, bool set_properties)
602 if (param[0] != 4) 587 if (param[0] != 4)
603 return -1; 588 return -1;
604 589
605/* Magic to enable horizontal scrolling on IntelliMouse 4.0 */ 590 /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
606 param[0] = 200; 591 param[0] = 200;
607 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); 592 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
608 param[0] = 80; 593 param[0] = 80;
@@ -672,10 +657,10 @@ static int ps2bare_detect(struct psmouse *psmouse, bool set_properties)
672 if (!psmouse->name) 657 if (!psmouse->name)
673 psmouse->name = "Mouse"; 658 psmouse->name = "Mouse";
674 659
675/* 660 /*
676 * We have no way of figuring true number of buttons so let's 661 * We have no way of figuring true number of buttons so let's
677 * assume that the device has 3. 662 * assume that the device has 3.
678 */ 663 */
679 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 664 __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
680 } 665 }
681 666
@@ -699,284 +684,6 @@ static int cortron_detect(struct psmouse *psmouse, bool set_properties)
699 return 0; 684 return 0;
700} 685}
701 686
702/*
703 * Apply default settings to the psmouse structure. Most of them will
704 * be overridden by individual protocol initialization routines.
705 */
706
707static void psmouse_apply_defaults(struct psmouse *psmouse)
708{
709 struct input_dev *input_dev = psmouse->dev;
710
711 memset(input_dev->evbit, 0, sizeof(input_dev->evbit));
712 memset(input_dev->keybit, 0, sizeof(input_dev->keybit));
713 memset(input_dev->relbit, 0, sizeof(input_dev->relbit));
714 memset(input_dev->absbit, 0, sizeof(input_dev->absbit));
715 memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit));
716
717 __set_bit(EV_KEY, input_dev->evbit);
718 __set_bit(EV_REL, input_dev->evbit);
719
720 __set_bit(BTN_LEFT, input_dev->keybit);
721 __set_bit(BTN_RIGHT, input_dev->keybit);
722
723 __set_bit(REL_X, input_dev->relbit);
724 __set_bit(REL_Y, input_dev->relbit);
725
726 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
727
728 psmouse->set_rate = psmouse_set_rate;
729 psmouse->set_resolution = psmouse_set_resolution;
730 psmouse->set_scale = psmouse_set_scale;
731 psmouse->poll = psmouse_poll;
732 psmouse->protocol_handler = psmouse_process_byte;
733 psmouse->pktsize = 3;
734 psmouse->reconnect = NULL;
735 psmouse->disconnect = NULL;
736 psmouse->cleanup = NULL;
737 psmouse->pt_activate = NULL;
738 psmouse->pt_deactivate = NULL;
739}
740
741/*
742 * Apply default settings to the psmouse structure and call specified
743 * protocol detection or initialization routine.
744 */
745static int psmouse_do_detect(int (*detect)(struct psmouse *psmouse,
746 bool set_properties),
747 struct psmouse *psmouse, bool set_properties)
748{
749 if (set_properties)
750 psmouse_apply_defaults(psmouse);
751
752 return detect(psmouse, set_properties);
753}
754
755/*
756 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
757 * the mouse may have.
758 */
759
760static int psmouse_extensions(struct psmouse *psmouse,
761 unsigned int max_proto, bool set_properties)
762{
763 bool synaptics_hardware = false;
764
765/* Always check for focaltech, this is safe as it uses pnp-id matching */
766 if (psmouse_do_detect(focaltech_detect, psmouse, set_properties) == 0) {
767 if (max_proto > PSMOUSE_IMEX) {
768 if (!set_properties || focaltech_init(psmouse) == 0) {
769 if (IS_ENABLED(CONFIG_MOUSE_PS2_FOCALTECH))
770 return PSMOUSE_FOCALTECH;
771 /*
772 * Note that we need to also restrict
773 * psmouse_max_proto so that psmouse_initialize()
774 * does not try to reset rate and resolution,
775 * because even that upsets the device.
776 */
777 psmouse_max_proto = PSMOUSE_PS2;
778 return PSMOUSE_PS2;
779 }
780 }
781 }
782
783/*
784 * We always check for lifebook because it does not disturb mouse
785 * (it only checks DMI information).
786 */
787 if (psmouse_do_detect(lifebook_detect, psmouse, set_properties) == 0) {
788 if (max_proto > PSMOUSE_IMEX) {
789 if (!set_properties || lifebook_init(psmouse) == 0)
790 return PSMOUSE_LIFEBOOK;
791 }
792 }
793
794 if (psmouse_do_detect(vmmouse_detect, psmouse, set_properties) == 0) {
795 if (max_proto > PSMOUSE_IMEX) {
796 if (!set_properties || vmmouse_init(psmouse) == 0)
797 return PSMOUSE_VMMOUSE;
798 }
799 }
800
801/*
802 * Try Kensington ThinkingMouse (we try first, because synaptics probe
803 * upsets the thinkingmouse).
804 */
805
806 if (max_proto > PSMOUSE_IMEX &&
807 psmouse_do_detect(thinking_detect, psmouse, set_properties) == 0) {
808 return PSMOUSE_THINKPS;
809 }
810
811/*
812 * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol
813 * support is disabled in config - we need to know if it is synaptics so we
814 * can reset it properly after probing for intellimouse.
815 */
816 if (max_proto > PSMOUSE_PS2 &&
817 psmouse_do_detect(synaptics_detect, psmouse, set_properties) == 0) {
818 synaptics_hardware = true;
819
820 if (max_proto > PSMOUSE_IMEX) {
821/*
822 * Try activating protocol, but check if support is enabled first, since
823 * we try detecting Synaptics even when protocol is disabled.
824 */
825 if (IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS) &&
826 (!set_properties || synaptics_init(psmouse) == 0)) {
827 return PSMOUSE_SYNAPTICS;
828 }
829
830/*
831 * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
832 * Unfortunately Logitech/Genius probes confuse some firmware versions so
833 * we'll have to skip them.
834 */
835 max_proto = PSMOUSE_IMEX;
836 }
837/*
838 * Make sure that touchpad is in relative mode, gestures (taps) are enabled
839 */
840 synaptics_reset(psmouse);
841 }
842
843/*
844 * Try Cypress Trackpad.
845 * Must try it before Finger Sensing Pad because Finger Sensing Pad probe
846 * upsets some modules of Cypress Trackpads.
847 */
848 if (max_proto > PSMOUSE_IMEX &&
849 cypress_detect(psmouse, set_properties) == 0) {
850 if (IS_ENABLED(CONFIG_MOUSE_PS2_CYPRESS)) {
851 if (cypress_init(psmouse) == 0)
852 return PSMOUSE_CYPRESS;
853
854 /*
855 * Finger Sensing Pad probe upsets some modules of
856 * Cypress Trackpad, must avoid Finger Sensing Pad
857 * probe if Cypress Trackpad device detected.
858 */
859 return PSMOUSE_PS2;
860 }
861
862 max_proto = PSMOUSE_IMEX;
863 }
864
865/*
866 * Try ALPS TouchPad
867 */
868 if (max_proto > PSMOUSE_IMEX) {
869 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
870 if (psmouse_do_detect(alps_detect,
871 psmouse, set_properties) == 0) {
872 if (!set_properties || alps_init(psmouse) == 0)
873 return PSMOUSE_ALPS;
874/*
875 * Init failed, try basic relative protocols
876 */
877 max_proto = PSMOUSE_IMEX;
878 }
879 }
880
881/*
882 * Try OLPC HGPK touchpad.
883 */
884 if (max_proto > PSMOUSE_IMEX &&
885 psmouse_do_detect(hgpk_detect, psmouse, set_properties) == 0) {
886 if (!set_properties || hgpk_init(psmouse) == 0)
887 return PSMOUSE_HGPK;
888/*
889 * Init failed, try basic relative protocols
890 */
891 max_proto = PSMOUSE_IMEX;
892 }
893
894/*
895 * Try Elantech touchpad.
896 */
897 if (max_proto > PSMOUSE_IMEX &&
898 psmouse_do_detect(elantech_detect, psmouse, set_properties) == 0) {
899 if (!set_properties || elantech_init(psmouse) == 0)
900 return PSMOUSE_ELANTECH;
901/*
902 * Init failed, try basic relative protocols
903 */
904 max_proto = PSMOUSE_IMEX;
905 }
906
907 if (max_proto > PSMOUSE_IMEX) {
908 if (psmouse_do_detect(genius_detect,
909 psmouse, set_properties) == 0)
910 return PSMOUSE_GENPS;
911
912 if (psmouse_do_detect(ps2pp_init,
913 psmouse, set_properties) == 0)
914 return PSMOUSE_PS2PP;
915
916 if (psmouse_do_detect(trackpoint_detect,
917 psmouse, set_properties) == 0)
918 return PSMOUSE_TRACKPOINT;
919
920 if (psmouse_do_detect(touchkit_ps2_detect,
921 psmouse, set_properties) == 0)
922 return PSMOUSE_TOUCHKIT_PS2;
923 }
924
925/*
926 * Try Finger Sensing Pad. We do it here because its probe upsets
927 * Trackpoint devices (causing TP_READ_ID command to time out).
928 */
929 if (max_proto > PSMOUSE_IMEX) {
930 if (psmouse_do_detect(fsp_detect,
931 psmouse, set_properties) == 0) {
932 if (!set_properties || fsp_init(psmouse) == 0)
933 return PSMOUSE_FSP;
934/*
935 * Init failed, try basic relative protocols
936 */
937 max_proto = PSMOUSE_IMEX;
938 }
939 }
940
941/*
942 * Reset to defaults in case the device got confused by extended
943 * protocol probes. Note that we follow up with full reset because
944 * some mice put themselves to sleep when they see PSMOUSE_RESET_DIS.
945 */
946 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
947 psmouse_reset(psmouse);
948
949 if (max_proto >= PSMOUSE_IMEX &&
950 psmouse_do_detect(im_explorer_detect,
951 psmouse, set_properties) == 0) {
952 return PSMOUSE_IMEX;
953 }
954
955 if (max_proto >= PSMOUSE_IMPS &&
956 psmouse_do_detect(intellimouse_detect,
957 psmouse, set_properties) == 0) {
958 return PSMOUSE_IMPS;
959 }
960
961/*
962 * Okay, all failed, we have a standard mouse here. The number of the buttons
963 * is still a question, though. We assume 3.
964 */
965 psmouse_do_detect(ps2bare_detect, psmouse, set_properties);
966
967 if (synaptics_hardware) {
968/*
969 * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
970 * We need to reset the touchpad because if there is a track point on the
971 * pass through port it could get disabled while probing for protocol
972 * extensions.
973 */
974 psmouse_reset(psmouse);
975 }
976
977 return PSMOUSE_PS2;
978}
979
980static const struct psmouse_protocol psmouse_protocols[] = { 687static const struct psmouse_protocol psmouse_protocols[] = {
981 { 688 {
982 .type = PSMOUSE_PS2, 689 .type = PSMOUSE_PS2,
@@ -985,13 +692,14 @@ static const struct psmouse_protocol psmouse_protocols[] = {
985 .maxproto = true, 692 .maxproto = true,
986 .ignore_parity = true, 693 .ignore_parity = true,
987 .detect = ps2bare_detect, 694 .detect = ps2bare_detect,
695 .try_passthru = true,
988 }, 696 },
989#ifdef CONFIG_MOUSE_PS2_LOGIPS2PP 697#ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
990 { 698 {
991 .type = PSMOUSE_PS2PP, 699 .type = PSMOUSE_PS2PP,
992 .name = "PS2++", 700 .name = "PS2++",
993 .alias = "logitech", 701 .alias = "logitech",
994 .detect = ps2pp_init, 702 .detect = ps2pp_detect,
995 }, 703 },
996#endif 704#endif
997 { 705 {
@@ -1022,6 +730,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
1022 .maxproto = true, 730 .maxproto = true,
1023 .ignore_parity = true, 731 .ignore_parity = true,
1024 .detect = intellimouse_detect, 732 .detect = intellimouse_detect,
733 .try_passthru = true,
1025 }, 734 },
1026 { 735 {
1027 .type = PSMOUSE_IMEX, 736 .type = PSMOUSE_IMEX,
@@ -1030,6 +739,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
1030 .maxproto = true, 739 .maxproto = true,
1031 .ignore_parity = true, 740 .ignore_parity = true,
1032 .detect = im_explorer_detect, 741 .detect = im_explorer_detect,
742 .try_passthru = true,
1033 }, 743 },
1034#ifdef CONFIG_MOUSE_PS2_SYNAPTICS 744#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
1035 { 745 {
@@ -1061,6 +771,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
1061 .type = PSMOUSE_LIFEBOOK, 771 .type = PSMOUSE_LIFEBOOK,
1062 .name = "LBPS/2", 772 .name = "LBPS/2",
1063 .alias = "lifebook", 773 .alias = "lifebook",
774 .detect = lifebook_detect,
1064 .init = lifebook_init, 775 .init = lifebook_init,
1065 }, 776 },
1066#endif 777#endif
@@ -1070,6 +781,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
1070 .name = "TPPS/2", 781 .name = "TPPS/2",
1071 .alias = "trackpoint", 782 .alias = "trackpoint",
1072 .detect = trackpoint_detect, 783 .detect = trackpoint_detect,
784 .try_passthru = true,
1073 }, 785 },
1074#endif 786#endif
1075#ifdef CONFIG_MOUSE_PS2_TOUCHKIT 787#ifdef CONFIG_MOUSE_PS2_TOUCHKIT
@@ -1138,7 +850,7 @@ static const struct psmouse_protocol psmouse_protocols[] = {
1138 }, 850 },
1139}; 851};
1140 852
1141static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type) 853static const struct psmouse_protocol *__psmouse_protocol_by_type(enum psmouse_type type)
1142{ 854{
1143 int i; 855 int i;
1144 856
@@ -1146,6 +858,17 @@ static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type
1146 if (psmouse_protocols[i].type == type) 858 if (psmouse_protocols[i].type == type)
1147 return &psmouse_protocols[i]; 859 return &psmouse_protocols[i];
1148 860
861 return NULL;
862}
863
864static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
865{
866 const struct psmouse_protocol *proto;
867
868 proto = __psmouse_protocol_by_type(type);
869 if (proto)
870 return proto;
871
1149 WARN_ON(1); 872 WARN_ON(1);
1150 return &psmouse_protocols[0]; 873 return &psmouse_protocols[0];
1151} 874}
@@ -1166,23 +889,288 @@ static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name,
1166 return NULL; 889 return NULL;
1167} 890}
1168 891
892/*
893 * Apply default settings to the psmouse structure. Most of them will
894 * be overridden by individual protocol initialization routines.
895 */
896static void psmouse_apply_defaults(struct psmouse *psmouse)
897{
898 struct input_dev *input_dev = psmouse->dev;
899
900 memset(input_dev->evbit, 0, sizeof(input_dev->evbit));
901 memset(input_dev->keybit, 0, sizeof(input_dev->keybit));
902 memset(input_dev->relbit, 0, sizeof(input_dev->relbit));
903 memset(input_dev->absbit, 0, sizeof(input_dev->absbit));
904 memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit));
905
906 __set_bit(EV_KEY, input_dev->evbit);
907 __set_bit(EV_REL, input_dev->evbit);
908
909 __set_bit(BTN_LEFT, input_dev->keybit);
910 __set_bit(BTN_RIGHT, input_dev->keybit);
911
912 __set_bit(REL_X, input_dev->relbit);
913 __set_bit(REL_Y, input_dev->relbit);
914
915 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
916
917 psmouse->set_rate = psmouse_set_rate;
918 psmouse->set_resolution = psmouse_set_resolution;
919 psmouse->set_scale = psmouse_set_scale;
920 psmouse->poll = psmouse_poll;
921 psmouse->protocol_handler = psmouse_process_byte;
922 psmouse->pktsize = 3;
923 psmouse->reconnect = NULL;
924 psmouse->disconnect = NULL;
925 psmouse->cleanup = NULL;
926 psmouse->pt_activate = NULL;
927 psmouse->pt_deactivate = NULL;
928}
929
930static bool psmouse_try_protocol(struct psmouse *psmouse,
931 enum psmouse_type type,
932 unsigned int *max_proto,
933 bool set_properties, bool init_allowed)
934{
935 const struct psmouse_protocol *proto;
936
937 proto = __psmouse_protocol_by_type(type);
938 if (!proto)
939 return false;
940
941 if (psmouse->ps2dev.serio->id.type == SERIO_PS_PSTHRU &&
942 !proto->try_passthru) {
943 return false;
944 }
945
946 if (set_properties)
947 psmouse_apply_defaults(psmouse);
948
949 if (proto->detect(psmouse, set_properties) != 0)
950 return false;
951
952 if (set_properties && proto->init && init_allowed) {
953 if (proto->init(psmouse) != 0) {
954 /*
955 * We detected device, but init failed. Adjust
956 * max_proto so we only try standard protocols.
957 */
958 if (*max_proto > PSMOUSE_IMEX)
959 *max_proto = PSMOUSE_IMEX;
960
961 return false;
962 }
963 }
964
965 return true;
966}
1169 967
1170/* 968/*
1171 * psmouse_probe() probes for a PS/2 mouse. 969 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
970 * the mouse may have.
1172 */ 971 */
972static int psmouse_extensions(struct psmouse *psmouse,
973 unsigned int max_proto, bool set_properties)
974{
975 bool synaptics_hardware = false;
976
977 /*
978 * Always check for focaltech, this is safe as it uses pnp-id
979 * matching.
980 */
981 if (psmouse_try_protocol(psmouse, PSMOUSE_FOCALTECH,
982 &max_proto, set_properties, false)) {
983 if (max_proto > PSMOUSE_IMEX &&
984 IS_ENABLED(CONFIG_MOUSE_PS2_FOCALTECH) &&
985 (!set_properties || focaltech_init(psmouse) == 0)) {
986 return PSMOUSE_FOCALTECH;
987 }
988 /*
989 * Restrict psmouse_max_proto so that psmouse_initialize()
990 * does not try to reset rate and resolution, because even
991 * that upsets the device.
992 * This also causes us to basically fall through to basic
993 * protocol detection, where we fully reset the mouse,
994 * and set it up as bare PS/2 protocol device.
995 */
996 psmouse_max_proto = max_proto = PSMOUSE_PS2;
997 }
998
999 /*
1000 * We always check for LifeBook because it does not disturb mouse
1001 * (it only checks DMI information).
1002 */
1003 if (psmouse_try_protocol(psmouse, PSMOUSE_LIFEBOOK, &max_proto,
1004 set_properties, max_proto > PSMOUSE_IMEX))
1005 return PSMOUSE_LIFEBOOK;
1173 1006
1007 if (psmouse_try_protocol(psmouse, PSMOUSE_VMMOUSE, &max_proto,
1008 set_properties, max_proto > PSMOUSE_IMEX))
1009 return PSMOUSE_VMMOUSE;
1010
1011 /*
1012 * Try Kensington ThinkingMouse (we try first, because Synaptics
1013 * probe upsets the ThinkingMouse).
1014 */
1015 if (max_proto > PSMOUSE_IMEX &&
1016 psmouse_try_protocol(psmouse, PSMOUSE_THINKPS, &max_proto,
1017 set_properties, true)) {
1018 return PSMOUSE_THINKPS;
1019 }
1020
1021 /*
1022 * Try Synaptics TouchPad. Note that probing is done even if
1023 * Synaptics protocol support is disabled in config - we need to
1024 * know if it is Synaptics so we can reset it properly after
1025 * probing for IntelliMouse.
1026 */
1027 if (max_proto > PSMOUSE_PS2 &&
1028 psmouse_try_protocol(psmouse, PSMOUSE_SYNAPTICS, &max_proto,
1029 set_properties, false)) {
1030 synaptics_hardware = true;
1031
1032 if (max_proto > PSMOUSE_IMEX) {
1033 /*
1034 * Try activating protocol, but check if support is
1035 * enabled first, since we try detecting Synaptics
1036 * even when protocol is disabled.
1037 */
1038 if (IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS) &&
1039 (!set_properties || synaptics_init(psmouse) == 0)) {
1040 return PSMOUSE_SYNAPTICS;
1041 }
1042
1043 /*
1044 * Some Synaptics touchpads can emulate extended
1045 * protocols (like IMPS/2). Unfortunately
1046 * Logitech/Genius probes confuse some firmware
1047 * versions so we'll have to skip them.
1048 */
1049 max_proto = PSMOUSE_IMEX;
1050 }
1051
1052 /*
1053 * Make sure that touchpad is in relative mode, gestures
1054 * (taps) are enabled.
1055 */
1056 synaptics_reset(psmouse);
1057 }
1058
1059 /*
1060 * Try Cypress Trackpad. We must try it before Finger Sensing Pad
1061 * because Finger Sensing Pad probe upsets some modules of Cypress
1062 * Trackpads.
1063 */
1064 if (max_proto > PSMOUSE_IMEX &&
1065 psmouse_try_protocol(psmouse, PSMOUSE_CYPRESS, &max_proto,
1066 set_properties, true)) {
1067 return PSMOUSE_CYPRESS;
1068 }
1069
1070 /* Try ALPS TouchPad */
1071 if (max_proto > PSMOUSE_IMEX) {
1072 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
1073 if (psmouse_try_protocol(psmouse, PSMOUSE_ALPS,
1074 &max_proto, set_properties, true))
1075 return PSMOUSE_ALPS;
1076 }
1077
1078 /* Try OLPC HGPK touchpad */
1079 if (max_proto > PSMOUSE_IMEX &&
1080 psmouse_try_protocol(psmouse, PSMOUSE_HGPK, &max_proto,
1081 set_properties, true)) {
1082 return PSMOUSE_HGPK;
1083 }
1084
1085 /* Try Elantech touchpad */
1086 if (max_proto > PSMOUSE_IMEX &&
1087 psmouse_try_protocol(psmouse, PSMOUSE_ELANTECH,
1088 &max_proto, set_properties, true)) {
1089 return PSMOUSE_ELANTECH;
1090 }
1091
1092 if (max_proto > PSMOUSE_IMEX) {
1093 if (psmouse_try_protocol(psmouse, PSMOUSE_GENPS,
1094 &max_proto, set_properties, true))
1095 return PSMOUSE_GENPS;
1096
1097 if (psmouse_try_protocol(psmouse, PSMOUSE_PS2PP,
1098 &max_proto, set_properties, true))
1099 return PSMOUSE_PS2PP;
1100
1101 if (psmouse_try_protocol(psmouse, PSMOUSE_TRACKPOINT,
1102 &max_proto, set_properties, true))
1103 return PSMOUSE_TRACKPOINT;
1104
1105 if (psmouse_try_protocol(psmouse, PSMOUSE_TOUCHKIT_PS2,
1106 &max_proto, set_properties, true))
1107 return PSMOUSE_TOUCHKIT_PS2;
1108 }
1109
1110 /*
1111 * Try Finger Sensing Pad. We do it here because its probe upsets
1112 * Trackpoint devices (causing TP_READ_ID command to time out).
1113 */
1114 if (max_proto > PSMOUSE_IMEX &&
1115 psmouse_try_protocol(psmouse, PSMOUSE_FSP,
1116 &max_proto, set_properties, true)) {
1117 return PSMOUSE_FSP;
1118 }
1119
1120 /*
1121 * Reset to defaults in case the device got confused by extended
1122 * protocol probes. Note that we follow up with full reset because
1123 * some mice put themselves to sleep when they see PSMOUSE_RESET_DIS.
1124 */
1125 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
1126 psmouse_reset(psmouse);
1127
1128 if (max_proto >= PSMOUSE_IMEX &&
1129 psmouse_try_protocol(psmouse, PSMOUSE_IMEX,
1130 &max_proto, set_properties, true)) {
1131 return PSMOUSE_IMEX;
1132 }
1133
1134 if (max_proto >= PSMOUSE_IMPS &&
1135 psmouse_try_protocol(psmouse, PSMOUSE_IMPS,
1136 &max_proto, set_properties, true)) {
1137 return PSMOUSE_IMPS;
1138 }
1139
1140 /*
1141 * Okay, all failed, we have a standard mouse here. The number of
1142 * the buttons is still a question, though. We assume 3.
1143 */
1144 psmouse_try_protocol(psmouse, PSMOUSE_PS2,
1145 &max_proto, set_properties, true);
1146
1147 if (synaptics_hardware) {
1148 /*
1149 * We detected Synaptics hardware but it did not respond to
1150 * IMPS/2 probes. We need to reset the touchpad because if
1151 * there is a track point on the pass through port it could
1152 * get disabled while probing for protocol extensions.
1153 */
1154 psmouse_reset(psmouse);
1155 }
1156
1157 return PSMOUSE_PS2;
1158}
1159
1160/*
1161 * psmouse_probe() probes for a PS/2 mouse.
1162 */
1174static int psmouse_probe(struct psmouse *psmouse) 1163static int psmouse_probe(struct psmouse *psmouse)
1175{ 1164{
1176 struct ps2dev *ps2dev = &psmouse->ps2dev; 1165 struct ps2dev *ps2dev = &psmouse->ps2dev;
1177 unsigned char param[2]; 1166 unsigned char param[2];
1178 1167
1179/* 1168 /*
1180 * First, we check if it's a mouse. It should send 0x00 or 0x03 1169 * First, we check if it's a mouse. It should send 0x00 or 0x03 in
1181 * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer. 1170 * case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
1182 * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and subsequent 1171 * Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and
1183 * ID queries, probably due to a firmware bug. 1172 * subsequent ID queries, probably due to a firmware bug.
1184 */ 1173 */
1185
1186 param[0] = 0xa5; 1174 param[0] = 0xa5;
1187 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) 1175 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1188 return -1; 1176 return -1;
@@ -1191,10 +1179,10 @@ static int psmouse_probe(struct psmouse *psmouse)
1191 param[0] != 0x04 && param[0] != 0xff) 1179 param[0] != 0x04 && param[0] != 0xff)
1192 return -1; 1180 return -1;
1193 1181
1194/* 1182 /*
1195 * Then we reset and disable the mouse so that it doesn't generate events. 1183 * Then we reset and disable the mouse so that it doesn't generate
1196 */ 1184 * events.
1197 1185 */
1198 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS)) 1186 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS))
1199 psmouse_warn(psmouse, "Failed to reset mouse on %s\n", 1187 psmouse_warn(psmouse, "Failed to reset mouse on %s\n",
1200 ps2dev->serio->phys); 1188 ps2dev->serio->phys);
@@ -1205,13 +1193,11 @@ static int psmouse_probe(struct psmouse *psmouse)
1205/* 1193/*
1206 * psmouse_initialize() initializes the mouse to a sane state. 1194 * psmouse_initialize() initializes the mouse to a sane state.
1207 */ 1195 */
1208
1209static void psmouse_initialize(struct psmouse *psmouse) 1196static void psmouse_initialize(struct psmouse *psmouse)
1210{ 1197{
1211/* 1198 /*
1212 * We set the mouse report rate, resolution and scaling. 1199 * We set the mouse report rate, resolution and scaling.
1213 */ 1200 */
1214
1215 if (psmouse_max_proto != PSMOUSE_PS2) { 1201 if (psmouse_max_proto != PSMOUSE_PS2) {
1216 psmouse->set_rate(psmouse, psmouse->rate); 1202 psmouse->set_rate(psmouse, psmouse->rate);
1217 psmouse->set_resolution(psmouse, psmouse->resolution); 1203 psmouse->set_resolution(psmouse, psmouse->resolution);
@@ -1222,7 +1208,6 @@ static void psmouse_initialize(struct psmouse *psmouse)
1222/* 1208/*
1223 * psmouse_activate() enables the mouse so that we get motion reports from it. 1209 * psmouse_activate() enables the mouse so that we get motion reports from it.
1224 */ 1210 */
1225
1226int psmouse_activate(struct psmouse *psmouse) 1211int psmouse_activate(struct psmouse *psmouse)
1227{ 1212{
1228 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { 1213 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
@@ -1236,10 +1221,9 @@ int psmouse_activate(struct psmouse *psmouse)
1236} 1221}
1237 1222
1238/* 1223/*
1239 * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion 1224 * psmouse_deactivate() puts the mouse into poll mode so that we don't get
1240 * reports from it unless we explicitly request it. 1225 * motion reports from it unless we explicitly request it.
1241 */ 1226 */
1242
1243int psmouse_deactivate(struct psmouse *psmouse) 1227int psmouse_deactivate(struct psmouse *psmouse)
1244{ 1228{
1245 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) { 1229 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) {
@@ -1252,11 +1236,9 @@ int psmouse_deactivate(struct psmouse *psmouse)
1252 return 0; 1236 return 0;
1253} 1237}
1254 1238
1255
1256/* 1239/*
1257 * psmouse_resync() attempts to re-validate current protocol. 1240 * psmouse_resync() attempts to re-validate current protocol.
1258 */ 1241 */
1259
1260static void psmouse_resync(struct work_struct *work) 1242static void psmouse_resync(struct work_struct *work)
1261{ 1243{
1262 struct psmouse *parent = NULL, *psmouse = 1244 struct psmouse *parent = NULL, *psmouse =
@@ -1276,16 +1258,16 @@ static void psmouse_resync(struct work_struct *work)
1276 psmouse_deactivate(parent); 1258 psmouse_deactivate(parent);
1277 } 1259 }
1278 1260
1279/* 1261 /*
1280 * Some mice don't ACK commands sent while they are in the middle of 1262 * 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() 1263 * transmitting motion packet. To avoid delay we use ps2_sendbyte()
1282 * instead of ps2_command() which would wait for 200ms for an ACK 1264 * instead of ps2_command() which would wait for 200ms for an ACK
1283 * that may never come. 1265 * that may never come.
1284 * As an additional quirk ALPS touchpads may not only forget to ACK 1266 * 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 1267 * 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 1268 * mouse at least once ACKs disable we will do full reconnect if ACK
1287 * is missing. 1269 * is missing.
1288 */ 1270 */
1289 psmouse->num_resyncs++; 1271 psmouse->num_resyncs++;
1290 1272
1291 if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) { 1273 if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) {
@@ -1294,13 +1276,13 @@ static void psmouse_resync(struct work_struct *work)
1294 } else 1276 } else
1295 psmouse->acks_disable_command = true; 1277 psmouse->acks_disable_command = true;
1296 1278
1297/* 1279 /*
1298 * Poll the mouse. If it was reset the packet will be shorter than 1280 * 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 1281 * psmouse->pktsize and ps2_command will fail. We do not expect and
1300 * do not handle scenario when mouse "upgrades" its protocol while 1282 * do not handle scenario when mouse "upgrades" its protocol while
1301 * disconnected since it would require additional delay. If we ever 1283 * disconnected since it would require additional delay. If we ever
1302 * see a mouse that does it we'll adjust the code. 1284 * see a mouse that does it we'll adjust the code.
1303 */ 1285 */
1304 if (!failed) { 1286 if (!failed) {
1305 if (psmouse->poll(psmouse)) 1287 if (psmouse->poll(psmouse))
1306 failed = true; 1288 failed = true;
@@ -1317,11 +1299,12 @@ static void psmouse_resync(struct work_struct *work)
1317 psmouse_set_state(psmouse, PSMOUSE_RESYNCING); 1299 psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
1318 } 1300 }
1319 } 1301 }
1320/* 1302
1321 * Now try to enable mouse. We try to do that even if poll failed and also 1303 /*
1322 * repeat our attempts 5 times, otherwise we may be left out with disabled 1304 * Now try to enable mouse. We try to do that even if poll failed
1323 * mouse. 1305 * and also repeat our attempts 5 times, otherwise we may be left
1324 */ 1306 * out with disabled mouse.
1307 */
1325 for (i = 0; i < 5; i++) { 1308 for (i = 0; i < 5; i++) {
1326 if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { 1309 if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1327 enabled = true; 1310 enabled = true;
@@ -1353,7 +1336,6 @@ static void psmouse_resync(struct work_struct *work)
1353/* 1336/*
1354 * psmouse_cleanup() resets the mouse into power-on state. 1337 * psmouse_cleanup() resets the mouse into power-on state.
1355 */ 1338 */
1356
1357static void psmouse_cleanup(struct serio *serio) 1339static void psmouse_cleanup(struct serio *serio)
1358{ 1340{
1359 struct psmouse *psmouse = serio_get_drvdata(serio); 1341 struct psmouse *psmouse = serio_get_drvdata(serio);
@@ -1378,15 +1360,15 @@ static void psmouse_cleanup(struct serio *serio)
1378 if (psmouse->cleanup) 1360 if (psmouse->cleanup)
1379 psmouse->cleanup(psmouse); 1361 psmouse->cleanup(psmouse);
1380 1362
1381/* 1363 /*
1382 * Reset the mouse to defaults (bare PS/2 protocol). 1364 * Reset the mouse to defaults (bare PS/2 protocol).
1383 */ 1365 */
1384 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); 1366 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
1385 1367
1386/* 1368 /*
1387 * Some boxes, such as HP nx7400, get terribly confused if mouse 1369 * Some boxes, such as HP nx7400, get terribly confused if mouse
1388 * is not fully enabled before suspending/shutting down. 1370 * is not fully enabled before suspending/shutting down.
1389 */ 1371 */
1390 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE); 1372 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1391 1373
1392 if (parent) { 1374 if (parent) {
@@ -1402,7 +1384,6 @@ static void psmouse_cleanup(struct serio *serio)
1402/* 1384/*
1403 * psmouse_disconnect() closes and frees. 1385 * psmouse_disconnect() closes and frees.
1404 */ 1386 */
1405
1406static void psmouse_disconnect(struct serio *serio) 1387static void psmouse_disconnect(struct serio *serio)
1407{ 1388{
1408 struct psmouse *psmouse, *parent = NULL; 1389 struct psmouse *psmouse, *parent = NULL;
@@ -1602,7 +1583,6 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1602 goto out; 1583 goto out;
1603} 1584}
1604 1585
1605
1606static int psmouse_reconnect(struct serio *serio) 1586static int psmouse_reconnect(struct serio *serio)
1607{ 1587{
1608 struct psmouse *psmouse = serio_get_drvdata(serio); 1588 struct psmouse *psmouse = serio_get_drvdata(serio);