Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

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