Input: psmouse - add a custom serio protocol to send extra information
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>
Wed, 8 Feb 2017 07:58:02 +0000 (23:58 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 9 Feb 2017 19:43:15 +0000 (11:43 -0800)
The tracksticks on the Lenovo thinkpads have their buttons connected
through the touchpad device. We already fixed that in synaptics.c, but
when we switch the device into RMI4 mode to have proper support, the
pass-through functionality can't deal with them easily.

We add a new PS/2 flag and protocol designed for psmouse.  The RMI4 F03
pass-through can then emit a special set of commands to notify psmouse the
state of the buttons.

This patch implements the protocol in psmouse, while an other will
do the same for rmi4-f03.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/mouse/psmouse-base.c
drivers/input/mouse/psmouse.h
include/uapi/linux/serio.h

index bee2674..a598b72 100644 (file)
@@ -127,6 +127,13 @@ struct psmouse_protocol {
        int (*init)(struct psmouse *);
 };
 
+static void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons)
+{
+       input_report_key(dev, BTN_LEFT,   buttons & BIT(0));
+       input_report_key(dev, BTN_MIDDLE, buttons & BIT(2));
+       input_report_key(dev, BTN_RIGHT,  buttons & BIT(1));
+}
+
 /*
  * psmouse_process_byte() analyzes the PS/2 data stream and reports
  * relevant events to the input module once full packet has arrived.
@@ -199,9 +206,8 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
        }
 
        /* Generic PS/2 Mouse */
-       input_report_key(dev, BTN_LEFT,    packet[0]       & 1);
-       input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
-       input_report_key(dev, BTN_RIGHT,  (packet[0] >> 1) & 1);
+       psmouse_report_standard_buttons(dev,
+                                       packet[0] | psmouse->extra_buttons);
 
        input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
        input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
@@ -282,6 +288,30 @@ static int psmouse_handle_byte(struct psmouse *psmouse)
        return 0;
 }
 
+static void psmouse_handle_oob_data(struct psmouse *psmouse, u8 data)
+{
+       switch (psmouse->oob_data_type) {
+       case PSMOUSE_OOB_NONE:
+               psmouse->oob_data_type = data;
+               break;
+
+       case PSMOUSE_OOB_EXTRA_BTNS:
+               psmouse_report_standard_buttons(psmouse->dev, data);
+               input_sync(psmouse->dev);
+
+               psmouse->extra_buttons = data;
+               psmouse->oob_data_type = PSMOUSE_OOB_NONE;
+               break;
+
+       default:
+               psmouse_warn(psmouse,
+                            "unknown OOB_DATA type: 0x%02x\n",
+                            psmouse->oob_data_type);
+               psmouse->oob_data_type = PSMOUSE_OOB_NONE;
+               break;
+       }
+}
+
 /*
  * psmouse_interrupt() handles incoming characters, either passing them
  * for normal processing or gathering them as command response.
@@ -306,6 +336,11 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
                goto out;
        }
 
+       if (flags & SERIO_OOB_DATA) {
+               psmouse_handle_oob_data(psmouse, data);
+               goto out;
+       }
+
        if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK))
                if  (ps2_handle_ack(&psmouse->ps2dev, data))
                        goto out;
index e0ca6cd..8c83b8e 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef _PSMOUSE_H
 #define _PSMOUSE_H
 
+#define PSMOUSE_OOB_NONE       0x00
+#define PSMOUSE_OOB_EXTRA_BTNS 0x01
+
 #define PSMOUSE_CMD_SETSCALE11 0x00e6
 #define PSMOUSE_CMD_SETSCALE21 0x00e7
 #define PSMOUSE_CMD_SETRES     0x10e8
@@ -53,6 +56,8 @@ struct psmouse {
        unsigned char pktcnt;
        unsigned char pktsize;
        unsigned char type;
+       unsigned char oob_data_type;
+       unsigned char extra_buttons;
        bool ignore_parity;
        bool acks_disable_command;
        unsigned int model;
index f2447a8..ccd0ccd 100644 (file)
 /*
  * bit masks for use in "interrupt" flags (3rd argument)
  */
-#define SERIO_TIMEOUT  1
-#define SERIO_PARITY   2
-#define SERIO_FRAME    4
+#define SERIO_TIMEOUT  BIT(0)
+#define SERIO_PARITY   BIT(1)
+#define SERIO_FRAME    BIT(2)
+#define SERIO_OOB_DATA BIT(3)
 
 /*
  * Serio types