diff mbox series

[v5,RESEND] Input: alps - Don't handle ALPS cs19 trackpoint-only device

Message ID 20190708022458.2585-1-hui.wang@canonical.com (mailing list archive)
State Accepted
Commit 7e4935ccc3236751e5fe4bd6846f86e46bb2e427
Headers show
Series [v5,RESEND] Input: alps - Don't handle ALPS cs19 trackpoint-only device | expand

Commit Message

Hui Wang July 8, 2019, 2:24 a.m. UTC
On a latest Lenovo laptop, the trackpoint and 3 buttons below it
don't work at all, when we move the trackpoint or press those 3
buttons, the kernel will print out:
"Rejected trackstick packet from non DualPoint device"

This device is identified as an alps touchpad but the packet has
trackpoint format, so the alps.c drops the packet and prints out
the message above.

According to XiaoXiao's explanation, this device is named cs19 and
is trackpoint-only device, its firmware is only for trackpoint, it
is independent of touchpad and is a device completely different from
DualPoint ones.

To drive this device with mininal changes to the existing driver, we
just let the alps driver not handle this device, then the trackpoint.c
will be the driver of this device if the trackpoint driver is enabled.
(if not, this device will fallback to a bare PS/2 device)

With the trackpoint.c, this trackpoint and 3 buttons all work well,
they have all features that the trackpoint should have, like
scrolling-screen, drag-and-drop and frame-selection.

Signed-off-by: XiaoXiao Liu <sliuuxiaonxiao@gmail.com>
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
---
Resend this patch to add the Reviewed-by: Pali Rohár <pali.rohar@gmail.com>

Hello Dmitry,
please take look at this patch and give some comment, Thanks. Our project
is waiting for this patch to be upstreamed.

Many Thanks.

 drivers/input/mouse/alps.c | 41 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Comments

Dmitry Torokhov July 15, 2019, 5:10 p.m. UTC | #1
Hi Hui,

On Mon, Jul 08, 2019 at 10:24:58AM +0800, Hui Wang wrote:
> +	if ((param[0] == TP_VARIANT_ALPS) && (param[1] & 0x20)) {
> +		if (IS_ENABLED(MOUSE_PS2_TRACKPOINT))
> +			psmouse_dbg(psmouse,
> +				    "ALPS CS19 trackpoint-only device detected, not using ALPS touchpad driver\n");
> +		else
> +			psmouse_warn(psmouse,
> +				     "ALPS CS19 trackpoint-only device detected but MOUSE_PS2_TRACKPOINT not enabled, fallback to bare PS/2 mouse\n");

I do not think that trackpoint driver not being enabled deserves a
warning, especially coming from unrelated driver. As far as I understand
the device still works reasonably well when handled as generic mouse.

I condensed both messages down to "ALPS CS19 trackpoint-only device
detected, ignoring", moved it down to alps_is_cs19_trackpoint() call
site, and applied the patch.

Keeping Pali's reviewed-by as the core idea of the patch has not
changed.

Thanks.
Pali Rohár July 15, 2019, 5:15 p.m. UTC | #2
On Monday 15 July 2019 10:10:42 Dmitry Torokhov wrote:
> Hi Hui,
> 
> On Mon, Jul 08, 2019 at 10:24:58AM +0800, Hui Wang wrote:
> > +	if ((param[0] == TP_VARIANT_ALPS) && (param[1] & 0x20)) {
> > +		if (IS_ENABLED(MOUSE_PS2_TRACKPOINT))
> > +			psmouse_dbg(psmouse,
> > +				    "ALPS CS19 trackpoint-only device detected, not using ALPS touchpad driver\n");
> > +		else
> > +			psmouse_warn(psmouse,
> > +				     "ALPS CS19 trackpoint-only device detected but MOUSE_PS2_TRACKPOINT not enabled, fallback to bare PS/2 mouse\n");
> 
> I do not think that trackpoint driver not being enabled deserves a
> warning, especially coming from unrelated driver. As far as I understand
> the device still works reasonably well when handled as generic mouse.
> 
> I condensed both messages down to "ALPS CS19 trackpoint-only device
> detected, ignoring", moved it down to alps_is_cs19_trackpoint() call
> site, and applied the patch.
> 
> Keeping Pali's reviewed-by as the core idea of the patch has not
> changed.
> 
> Thanks.
> 

Ok, I'm fine with it. Debug message is still a good idea for debugging
purposes, why alps.c decided to not handle particular ALPS device.
diff mbox series

Patch

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 8996323ce8d9..39e53a8f4fb1 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -21,6 +21,7 @@ 
 
 #include "psmouse.h"
 #include "alps.h"
+#include "trackpoint.h"
 
 /*
  * Definitions for ALPS version 3 and 4 command mode protocol
@@ -2861,6 +2862,34 @@  static const struct alps_protocol_info *alps_match_table(unsigned char *e7,
 	return NULL;
 }
 
+static bool alps_is_cs19_trackpoint(struct psmouse *psmouse)
+{
+	u8 param[2] = { 0 };
+
+	if (ps2_command(&psmouse->ps2dev,
+			param, MAKE_PS2_CMD(0, 2, TP_READ_ID)))
+		return false;
+
+	/*
+	 * param[0] contains the trackpoint device variant_id while param[1]
+	 * contains the firmware_id, so far for all alps trackpoint-only
+	 * devices, their variant_ids equal TP_VARIANT_ALPS and their
+	 * firmware_ids are 0x20~0x2f, so here we check param[0] as well as
+	 * param[1] to detect an ALPS trackpoint-only device.
+	 */
+	if ((param[0] == TP_VARIANT_ALPS) && (param[1] & 0x20)) {
+		if (IS_ENABLED(MOUSE_PS2_TRACKPOINT))
+			psmouse_dbg(psmouse,
+				    "ALPS CS19 trackpoint-only device detected, not using ALPS touchpad driver\n");
+		else
+			psmouse_warn(psmouse,
+				     "ALPS CS19 trackpoint-only device detected but MOUSE_PS2_TRACKPOINT not enabled, fallback to bare PS/2 mouse\n");
+		return true;
+	}
+
+	return false;
+}
+
 static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
 {
 	const struct alps_protocol_info *protocol;
@@ -3161,6 +3190,18 @@  int alps_detect(struct psmouse *psmouse, bool set_properties)
 	if (error)
 		return error;
 
+	/*
+	 * ALPS cs19 is a trackpoint-only device, it is completely independent
+	 * of touchpad. So it is a device different from DualPoint ones, if it
+	 * is identified as a cs19 trackpoint device, we return -EINVAL here and
+	 * let trackpoint.c to drive this device, if the trackpoint driver is
+	 * not enabled, the device will fallback to a bare PS/2 mouse.
+	 * If ps2_command() fails here, we depend on the immediate followed
+	 * psmouse_reset() to reset the device to normal state.
+	 */
+	if (alps_is_cs19_trackpoint(psmouse))
+		return -EINVAL;
+
 	/*
 	 * Reset the device to make sure it is fully operational:
 	 * on some laptops, like certain Dell Latitudes, we may