Skip to content

Commit 23fce36

Browse files
Paul Donohuedtor
authored andcommitted
Input: ALPS - clean up code for SS5 hardware
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. Reviewed-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Paul Donohue <linux-kernel@PaulSD.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 7229c58 commit 23fce36

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

‎drivers/input/mouse/alps.c‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,15 +1153,13 @@ static void alps_process_packet_v7(struct psmouse *psmouse)
11531153
alps_process_touchpad_packet_v7(psmouse);
11541154
}
11551155

1156-
static unsigned char alps_get_pkt_id_ss4_v2(unsigned char *byte)
1156+
static enum SS4_PACKET_ID alps_get_pkt_id_ss4_v2(unsigned char *byte)
11571157
{
1158-
unsigned char pkt_id = SS4_PACKET_ID_IDLE;
1158+
enum SS4_PACKET_ID pkt_id = SS4_PACKET_ID_IDLE;
11591159

11601160
switch (byte[3] & 0x30) {
11611161
case 0x00:
1162-
if (byte[0] == 0x18 && byte[1] == 0x10 && byte[2] == 0x00 &&
1163-
(byte[3] & 0x88) == 0x08 && byte[4] == 0x10 &&
1164-
byte[5] == 0x00) {
1162+
if (SS4_IS_IDLE_V2(byte)) {
11651163
pkt_id = SS4_PACKET_ID_IDLE;
11661164
} else {
11671165
pkt_id = SS4_PACKET_ID_ONE;
@@ -1188,7 +1186,7 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
11881186
unsigned char *p, struct psmouse *psmouse)
11891187
{
11901188
struct alps_data *priv = psmouse->private;
1191-
unsigned char pkt_id;
1189+
enum SS4_PACKET_ID pkt_id;
11921190
unsigned int no_data_x, no_data_y;
11931191

11941192
pkt_id = alps_get_pkt_id_ss4_v2(p);
@@ -1306,7 +1304,6 @@ static void alps_process_packet_ss4_v2(struct psmouse *psmouse)
13061304
struct input_dev *dev = psmouse->dev;
13071305
struct input_dev *dev2 = priv->dev2;
13081306
struct alps_fields *f = &priv->f;
1309-
int x, y, pressure;
13101307

13111308
memset(f, 0, sizeof(struct alps_fields));
13121309
priv->decode_fields(f, packet, psmouse);
@@ -1349,13 +1346,9 @@ static void alps_process_packet_ss4_v2(struct psmouse *psmouse)
13491346
return;
13501347
}
13511348

1352-
x = (s8)(((packet[0] & 1) << 7) | (packet[1] & 0x7f));
1353-
y = (s8)(((packet[3] & 1) << 7) | (packet[2] & 0x7f));
1354-
pressure = (s8)(packet[4] & 0x7f);
1355-
1356-
input_report_rel(dev2, REL_X, x);
1357-
input_report_rel(dev2, REL_Y, -y);
1358-
input_report_abs(dev2, ABS_PRESSURE, pressure);
1349+
input_report_rel(dev2, REL_X, SS4_TS_X_V2(packet));
1350+
input_report_rel(dev2, REL_Y, SS4_TS_Y_V2(packet));
1351+
input_report_abs(dev2, ABS_PRESSURE, SS4_TS_Z_V2(packet));
13591352

13601353
input_report_key(dev2, BTN_LEFT, f->ts_left);
13611354
input_report_key(dev2, BTN_RIGHT, f->ts_right);

‎drivers/input/mouse/alps.h‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ enum SS4_PACKET_ID {
5454

5555
#define SS4_MASK_NORMAL_BUTTONS 0x07
5656

57-
#define SS4_1F_X_V2(_b) ((_b[0] & 0x0007) | \
57+
#define SS4_IS_IDLE_V2(_b) (((_b[0]) == 0x18) && \
58+
((_b[1]) == 0x10) && \
59+
((_b[2]) == 0x00) && \
60+
((_b[3] & 0x88) == 0x08) && \
61+
((_b[4]) == 0x10) && \
62+
((_b[5]) == 0x00) \
63+
)
64+
65+
#define SS4_1F_X_V2(_b) (((_b[0]) & 0x0007) | \
5866
((_b[1] << 3) & 0x0078) | \
5967
((_b[1] << 2) & 0x0380) | \
6068
((_b[2] << 5) & 0x1C00) \
@@ -101,6 +109,18 @@ enum SS4_PACKET_ID {
101109
#define SS4_IS_MF_CONTINUE(_b) ((_b[2] & 0x10) == 0x10)
102110
#define SS4_IS_5F_DETECTED(_b) ((_b[2] & 0x10) == 0x10)
103111

112+
#define SS4_TS_X_V2(_b) (s8)( \
113+
((_b[0] & 0x01) << 7) | \
114+
(_b[1] & 0x7F) \
115+
)
116+
117+
#define SS4_TS_Y_V2(_b) (s8)( \
118+
((_b[3] & 0x01) << 7) | \
119+
(_b[2] & 0x7F) \
120+
)
121+
122+
#define SS4_TS_Z_V2(_b) (s8)(_b[4] & 0x7F)
123+
104124

105125
#define SS4_MFPACKET_NO_AX 8160 /* X-Coordinate value */
106126
#define SS4_MFPACKET_NO_AY 4080 /* Y-Coordinate value */

0 commit comments

Comments
 (0)