All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org, "Pali Rohár" <pali.rohar@gmail.com>
Cc: Yunkang Tang <yunkang.tang@cn.alps.com>,
	Hans de Goede <hdegoede@redhat.com>
Subject: [PATCH 5/6] Input: ALPS - fix trackstick detection on some Dell Latitudes
Date: Wed, 14 Jan 2015 14:55:53 -0800	[thread overview]
Message-ID: <1421276154-8689-6-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1421276154-8689-1-git-send-email-dmitry.torokhov@gmail.com>

On some Dell Latitudes we fail to identify presence of trackstick unless we
reset the device. The issue is quite benign as we do perform reset in
alps_init(), so the trackstick ends up working, but mouse name reported to
userspace is not accurate.

In order to fix the issue while avoiding the additional lengthy reset we
move the resrt to alps_detect() and keep the discovered state to be used
later in alps_init().

Reported-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/mouse/alps.c | 74 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 55 insertions(+), 19 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index cabb267..fd3303d 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2304,6 +2304,7 @@ static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
 {
 	const struct alps_protocol_info *protocol;
 	unsigned char e6[4], e7[4], ec[4];
+	int error;
 
 	/*
 	 * First try "E6 report".
@@ -2349,10 +2350,15 @@ static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
 		}
 	}
 
-	/* Save the Firmware version */
-	memcpy(priv->fw_ver, ec, 3);
+	if (priv) {
+		/* Save the Firmware version */
+		memcpy(priv->fw_ver, ec, 3);
+		error = alps_set_protocol(psmouse, priv, protocol);
+		if (error)
+			return error;
+	}
 
-	return alps_set_protocol(psmouse, priv, protocol);
+	return 0;
 }
 
 static int alps_reconnect(struct psmouse *psmouse)
@@ -2406,22 +2412,20 @@ static void alps_set_abs_params_mt(struct alps_data *priv,
 
 int alps_init(struct psmouse *psmouse)
 {
-	struct alps_data *priv;
+	struct alps_data *priv = psmouse->private;
 	struct input_dev *dev1 = psmouse->dev, *dev2;
+	int error;
 
-	priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
 	dev2 = input_allocate_device();
-	if (!priv || !dev2)
+	if (!dev2) {
+		error = -ENOMEM;
 		goto init_fail;
+	}
 
 	priv->dev2 = dev2;
 
-	psmouse_reset(psmouse);
-
-	if (alps_identify(psmouse, priv) < 0)
-		goto init_fail;
-
-	if (priv->hw_init(psmouse))
+	error = priv->hw_init(psmouse);
+	if (error)
 		goto init_fail;
 
 	/*
@@ -2519,24 +2523,56 @@ int alps_init(struct psmouse *psmouse)
 init_fail:
 	psmouse_reset(psmouse);
 	input_free_device(dev2);
-	kfree(priv);
+	/*
+	 * Even though we did not allocate psmouse->private we do free
+	 * it here.
+	 */
+	kfree(psmouse->private);
 	psmouse->private = NULL;
-	return -1;
+	return error;
 }
 
 int alps_detect(struct psmouse *psmouse, bool set_properties)
 {
-	struct alps_data dummy;
+	struct alps_data *priv;
+	int error;
 
-	if (alps_identify(psmouse, &dummy) < 0)
-		return -1;
+	error = alps_identify(psmouse, NULL);
+	if (error)
+		return error;
+
+	/*
+	 * Reset the device to make sure it is fully operational:
+	 * on some laptops, like certain Dell Latitudes, we may
+	 * fail to properly detect presence of trackstick if device
+	 * has not been reset.
+	 */
+	psmouse_reset(psmouse);
+
+	priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
+	if (priv)
+		return -ENOMEM;
+
+	error = alps_identify(psmouse, priv);
+	if (error)
+		return error;
 
 	if (set_properties) {
 		psmouse->vendor = "ALPS";
-		psmouse->name = dummy.flags & ALPS_DUALPOINT ?
+		psmouse->name = priv->flags & ALPS_DUALPOINT ?
 				"DualPoint TouchPad" : "GlidePoint";
-		psmouse->model = dummy.proto_version;
+		psmouse->model = priv->proto_version;
+	} else {
+		/*
+		 * Destroy alps_data structure we allocated earlier since
+		 * this was just a "trial run". Otherwise we'll keep it
+		 * to be used by alps_init() which has to be called if
+		 * we succeed and set_properties is true.
+		 */
+		kfree(priv);
+		psmouse->private = NULL;
 	}
+
 	return 0;
 }
 
-- 
2.2.0.rc0.207.ga3a616c

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-01-14 22:56 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 22:55 [PATCH 0/6] Fixes for ALPS trackstick Dmitry Torokhov
2015-01-14 22:55 ` [PATCH 1/6] Input: ALPS - renumber protocol numbers Dmitry Torokhov
2015-01-14 22:55 ` [PATCH 2/6] Input: ALPS - make Rushmore a separate protocol Dmitry Torokhov
2015-01-14 22:55 ` [PATCH 3/6] Input: ALPS - split protocol data from model info Dmitry Torokhov
2015-01-14 22:55 ` [PATCH 4/6] Input: ALPS - consolidate setting protocol parameters Dmitry Torokhov
2015-01-14 22:55 ` Dmitry Torokhov [this message]
2015-01-15 20:21   ` [PATCH 5/6] Input: ALPS - fix trackstick detection on some Dell Latitudes Pali Rohár
2015-01-15 21:00     ` Dmitry Torokhov
2015-01-17 10:26   ` Pali Rohár
2015-02-02  5:34     ` Dmitry Torokhov
2015-02-02 10:51       ` Pali Rohár
2015-01-14 22:55 ` [PATCH 6/6] Input: ALPS - mix trackstick and external PS/2 mouse data Dmitry Torokhov
2015-01-15 20:34   ` Pali Rohár
2015-01-15 21:00     ` Dmitry Torokhov
2015-01-18  9:45   ` Pali Rohár
2015-01-15 10:49 ` [PATCH 0/6] Fixes for ALPS trackstick Pali Rohár
2015-01-15 18:18   ` Dmitry Torokhov
2015-01-15 19:19     ` Pali Rohár
2015-01-15 19:38       ` Dmitry Torokhov
2015-01-15 20:28         ` Pali Rohár
2015-01-15 21:02           ` Dmitry Torokhov
2015-01-17 10:01             ` Pali Rohár
2015-01-18  7:22               ` Dmitry Torokhov
2015-01-18  9:47                 ` Pali Rohár
2015-01-24 22:20                   ` Pali Rohár
2015-02-02  5:49                   ` Dmitry Torokhov
2015-02-02 10:49                     ` Pali Rohár
2015-02-02 14:27                       ` Pali Rohár
2015-02-08 12:26                         ` Pali Rohár
2015-02-10  6:32                           ` Dmitry Torokhov
2015-02-11 18:13                             ` Pali Rohár
2015-02-12  7:52                           ` Dmitry Torokhov
2015-02-12 20:25                             ` Pali Rohár
2015-02-05 11:41                     ` Pali Rohár

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421276154-8689-6-git-send-email-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-input@vger.kernel.org \
    --cc=pali.rohar@gmail.com \
    --cc=yunkang.tang@cn.alps.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.