All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Donohue <linux-kernel@PaulSD.com>
To: linux-input@vger.kernel.org
Cc: "Ben Gamari" <ben@smart-cactus.org>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Michal Hocko" <mhocko@suse.com>
Subject: [PATCH v4 3/3] Input: ALPS - Clean up code for SS5 hardware
Date: Tue, 8 Nov 2016 10:49:48 -0500	[thread overview]
Message-ID: <20161108154947.GR2927@TopQuark.net> (raw)
In-Reply-To: <20161108154642.GQ2927@TopQuark.net>

The return value of alps_get_pkt_id_ss4_v2() should really be
"enum SS4_PACKET_ID", not "unsigned char".  Correct this.
    
Also, most of the Alps SS5 (SS4 v2) packet byte parsing code is
implemented using macros, but there are a few places where bytes are
directly manipulated in alps.c.  For consistency, migrate the rest of
these to macros.
    
Signed-off-by: Paul Donohue <linux-kernel@PaulSD.com>

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 12376d2..6a2fb69 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1153,15 +1153,13 @@ static void alps_process_packet_v7(struct psmouse *psmouse)
 		alps_process_touchpad_packet_v7(psmouse);
 }
 
-static unsigned char alps_get_pkt_id_ss4_v2(unsigned char *byte)
+static enum SS4_PACKET_ID alps_get_pkt_id_ss4_v2(unsigned char *byte)
 {
-	unsigned char pkt_id = SS4_PACKET_ID_IDLE;
+	enum SS4_PACKET_ID pkt_id = SS4_PACKET_ID_IDLE;
 
 	switch (byte[3] & 0x30) {
 	case 0x00:
-		if (byte[0] == 0x18 && byte[1] == 0x10 && byte[2] == 0x00 &&
-		    (byte[3] & 0x88) == 0x08 && byte[4] == 0x10 &&
-		    byte[5] == 0x00) {
+		if (SS4_IS_IDLE_V2(byte)) {
 			pkt_id = SS4_PACKET_ID_IDLE;
 		} else {
 			pkt_id = SS4_PACKET_ID_ONE;
@@ -1188,7 +1186,7 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
 			      unsigned char *p, struct psmouse *psmouse)
 {
 	struct alps_data *priv = psmouse->private;
-	unsigned char pkt_id;
+	enum SS4_PACKET_ID pkt_id;
 	unsigned int no_data_x, no_data_y;
 
 	pkt_id = alps_get_pkt_id_ss4_v2(p);
@@ -1267,9 +1265,9 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
 		break;
 
 	case SS4_PACKET_ID_STICK:
-		f->st.x = (s8)(((p[0] & 1) << 7) | (p[1] & 0x7f));
-		f->st.y = -(s8)(((p[3] & 1) << 7) | (p[2] & 0x7f));
-		f->pressure = (s8)(p[4] & 0x7f);
+		f->st.x = SS4_TS_X_V2(p);
+		f->st.y = SS4_TS_Y_V2(p);
+		f->pressure = SS4_TS_Z_V2(p);
 		f->first_mp = 0;
 		f->is_mp = 0;
 		break;
@@ -1361,14 +1359,13 @@ static void alps_process_packet_ss4_v2(struct psmouse *psmouse)
 
 	/* Report touchpad */
 	alps_report_mt_data(psmouse, (f->fingers <= 4) ? f->fingers : 4);
-
 	input_mt_report_finger_count(dev, f->fingers);
+	input_report_abs(dev, ABS_PRESSURE, f->pressure);
 
 	input_report_key(dev, BTN_LEFT, f->left);
 	input_report_key(dev, BTN_RIGHT, f->right);
 	input_report_key(dev, BTN_MIDDLE, f->middle);
 
-	input_report_abs(dev, ABS_PRESSURE, f->pressure);
 	input_sync(dev);
 }
 
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index b9417e2..96e1d1d 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -54,7 +54,15 @@ enum SS4_PACKET_ID {
 
 #define SS4_MASK_NORMAL_BUTTONS		0x07
 
-#define SS4_1F_X_V2(_b)		((_b[0] & 0x0007) |		\
+#define SS4_IS_IDLE_V2(_b)	(((_b[0]) == 0x18) &&		\
+				 ((_b[1]) == 0x10) &&		\
+				 ((_b[2]) == 0x00) &&		\
+				 ((_b[3] & 0x88) == 0x08) &&	\
+				 ((_b[4]) == 0x10) &&		\
+				 ((_b[5]) == 0x00)		\
+				)
+
+#define SS4_1F_X_V2(_b)		(((_b[0]) & 0x0007) |		\
 				 ((_b[1] << 3) & 0x0078) |	\
 				 ((_b[1] << 2) & 0x0380) |	\
 				 ((_b[2] << 5) & 0x1C00)	\
@@ -101,6 +109,18 @@ enum SS4_PACKET_ID {
 #define SS4_IS_MF_CONTINUE(_b)	((_b[2] & 0x10) == 0x10)
 #define SS4_IS_5F_DETECTED(_b)	((_b[2] & 0x10) == 0x10)
 
+#define SS4_TS_X_V2(_b)		(s8)(				\
+				 ((_b[0] & 0x01) << 7) |	\
+				 ((_b[1]) & 0x7F)		\
+				)
+
+#define SS4_TS_Y_V2(_b)		-(s8)(				\
+				 ((_b[3] & 0x01) << 7) |	\
+				 ((_b[2]) & 0x7F)		\
+				)
+
+#define SS4_TS_Z_V2(_b)		(s8)(_b[4] & 0x7F)
+
 
 #define SS4_MFPACKET_NO_AX	8160	/* X-Coordinate value */
 #define SS4_MFPACKET_NO_AY	4080	/* Y-Coordinate value */

  reply	other threads:[~2016-11-08 15:49 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 21:01 [PATCH] Input: ALPS - Fix TrackStick support for SS5 hardware Paul Donohue
2016-11-01  9:35 ` Pali Rohár
2016-11-05 16:30   ` Paul Donohue
2016-11-05 16:44     ` [PATCH v2] " Paul Donohue
2016-11-06 19:59       ` Pali Rohár
2016-11-08 14:24         ` Paul Donohue
2016-11-06 19:57     ` [PATCH] " Pali Rohár
2016-11-08 14:54 ` [PATCH v3 1/3] " Paul Donohue
2016-11-08 14:59   ` [PATCH v3 2/3] " Paul Donohue
2016-11-08 15:06     ` Paul Donohue
2016-11-08 15:14 ` [PATCH v4 1/3] " Paul Donohue
2016-11-08 15:16   ` [PATCH v4 2/3] Input: ALPS - Clean up TrackStick handling " Paul Donohue
2016-11-08 15:17     ` [PATCH v4 3/3] Input: ALPS - Clean up code " Paul Donohue
2016-11-08 15:46       ` Paul Donohue
2016-11-08 15:49         ` Paul Donohue [this message]
2016-11-09 12:14     ` [PATCH v4 2/3] Input: ALPS - Clean up TrackStick handling " Pali Rohár
2016-11-10 14:27       ` Paul Donohue
2016-11-10 15:19         ` Pali Rohár
2016-11-10 16:44           ` [PATCH v5 0/3] Input: ALPS - Bug fix and cleanup " Paul Donohue
2016-11-10 16:44             ` [PATCH v5 1/3] Input: ALPS - Fix TrackStick support " Paul Donohue
2016-11-10 16:44             ` [PATCH v5 2/3] Input: ALPS - Clean up TrackStick handling " Paul Donohue
2016-11-10 16:44             ` [PATCH v5 3/3] Input: ALPS - Clean up code " Paul Donohue
2016-11-11 13:59             ` [PATCH v5 0/3] Input: ALPS - Bug fix and cleanup " Pali Rohár
2016-11-12  0:56               ` Dmitry Torokhov
2016-11-12  1:03                 ` Pali Rohár
2016-11-12  1:06                   ` Dmitry Torokhov
2016-11-12 12:29                     ` Pali Rohár
2016-11-13  6:43                       ` Dmitry Torokhov
2016-11-13 10:31                         ` Pali Rohár
2016-11-13 15:28                           ` Paul Donohue
2016-11-24 14:25               ` [PATCH v6 " Paul Donohue
2016-11-24 14:25                 ` [PATCH v6 1/3] Input: ALPS - Fix TrackStick support " Paul Donohue
2016-11-24 14:25                 ` [PATCH v6 2/3] Input: ALPS - Clean up TrackStick handling " Paul Donohue
2016-11-24 14:25                 ` [PATCH v6 3/3] Input: ALPS - Clean up code " Paul Donohue
2016-11-09 12:12   ` [PATCH v4 1/3] Input: ALPS - Fix TrackStick support " Pali Rohár
2016-11-10 14:17     ` Paul Donohue

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=20161108154947.GR2927@TopQuark.net \
    --to=linux-kernel@paulsd.com \
    --cc=ben@smart-cactus.org \
    --cc=linux-input@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=pali.rohar@gmail.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.