Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec...
[firefly-linux-kernel-4.4.55.git] / drivers / input / mouse / psmouse-base.c
index 8bc61237bc1b1c95d43b0d7e3d11e90275aa8d4a..5bb1658f60c746f29efd4f5d7008068701f4d08d 100644 (file)
@@ -36,6 +36,7 @@
 #include "sentelic.h"
 #include "cypress_ps2.h"
 #include "focaltech.h"
+#include "vmmouse.h"
 
 #define DRIVER_DESC    "PS/2 mouse driver"
 
@@ -474,19 +475,45 @@ static int psmouse_poll(struct psmouse *psmouse)
                           PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
 }
 
+static bool psmouse_check_pnp_id(const char *id, const char * const ids[])
+{
+       int i;
+
+       for (i = 0; ids[i]; i++)
+               if (!strcasecmp(id, ids[i]))
+                       return true;
+
+       return false;
+}
+
 /*
  * psmouse_matches_pnp_id - check if psmouse matches one of the passed in ids.
  */
 bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[])
 {
-       int i;
-
-       if (!strncmp(psmouse->ps2dev.serio->firmware_id, "PNP:", 4))
-               for (i = 0; ids[i]; i++)
-                       if (strstr(psmouse->ps2dev.serio->firmware_id, ids[i]))
-                               return true;
+       struct serio *serio = psmouse->ps2dev.serio;
+       char *p, *fw_id_copy, *save_ptr;
+       bool found = false;
+
+       if (strncmp(serio->firmware_id, "PNP: ", 5))
+               return false;
+
+       fw_id_copy = kstrndup(&serio->firmware_id[5],
+                             sizeof(serio->firmware_id) - 5,
+                             GFP_KERNEL);
+       if (!fw_id_copy)
+               return false;
+
+       save_ptr = fw_id_copy;
+       while ((p = strsep(&fw_id_copy, " ")) != NULL) {
+               if (psmouse_check_pnp_id(p, ids)) {
+                       found = true;
+                       break;
+               }
+       }
 
-       return false;
+       kfree(save_ptr);
+       return found;
 }
 
 /*
@@ -764,6 +791,13 @@ static int psmouse_extensions(struct psmouse *psmouse,
                }
        }
 
+       if (psmouse_do_detect(vmmouse_detect, psmouse, set_properties) == 0) {
+               if (max_proto > PSMOUSE_IMEX) {
+                       if (!set_properties || vmmouse_init(psmouse) == 0)
+                               return PSMOUSE_VMMOUSE;
+               }
+       }
+
 /*
  * Try Kensington ThinkingMouse (we try first, because synaptics probe
  * upsets the thinkingmouse).
@@ -1086,6 +1120,15 @@ static const struct psmouse_protocol psmouse_protocols[] = {
                .detect         = focaltech_detect,
                .init           = focaltech_init,
        },
+#endif
+#ifdef CONFIG_MOUSE_PS2_VMMOUSE
+       {
+               .type           = PSMOUSE_VMMOUSE,
+               .name           = VMMOUSE_PSNAME,
+               .alias          = "vmmouse",
+               .detect         = vmmouse_detect,
+               .init           = vmmouse_init,
+       },
 #endif
        {
                .type           = PSMOUSE_AUTO,