2 * ALPS touchpad PS/2 mouse driver
4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
5 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
6 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
8 * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net>
10 * ALPS detection, tap switching and status querying info is taken from
11 * tpconfig utility (by C. Scott Ananian and Bruce Kall).
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License version 2 as published by
15 * the Free Software Foundation.
18 #include <linux/slab.h>
19 #include <linux/input.h>
20 #include <linux/input/mt.h>
21 #include <linux/serio.h>
22 #include <linux/libps2.h>
23 #include <linux/dmi.h>
29 * Definitions for ALPS version 3 and 4 command mode protocol
31 #define ALPS_CMD_NIBBLE_10 0x01f2
33 #define ALPS_REG_BASE_RUSHMORE 0xc2c0
34 #define ALPS_REG_BASE_PINNACLE 0x0000
36 static const struct alps_nibble_commands alps_v3_nibble_commands
[] = {
37 { PSMOUSE_CMD_SETPOLL
, 0x00 }, /* 0 */
38 { PSMOUSE_CMD_RESET_DIS
, 0x00 }, /* 1 */
39 { PSMOUSE_CMD_SETSCALE21
, 0x00 }, /* 2 */
40 { PSMOUSE_CMD_SETRATE
, 0x0a }, /* 3 */
41 { PSMOUSE_CMD_SETRATE
, 0x14 }, /* 4 */
42 { PSMOUSE_CMD_SETRATE
, 0x28 }, /* 5 */
43 { PSMOUSE_CMD_SETRATE
, 0x3c }, /* 6 */
44 { PSMOUSE_CMD_SETRATE
, 0x50 }, /* 7 */
45 { PSMOUSE_CMD_SETRATE
, 0x64 }, /* 8 */
46 { PSMOUSE_CMD_SETRATE
, 0xc8 }, /* 9 */
47 { ALPS_CMD_NIBBLE_10
, 0x00 }, /* a */
48 { PSMOUSE_CMD_SETRES
, 0x00 }, /* b */
49 { PSMOUSE_CMD_SETRES
, 0x01 }, /* c */
50 { PSMOUSE_CMD_SETRES
, 0x02 }, /* d */
51 { PSMOUSE_CMD_SETRES
, 0x03 }, /* e */
52 { PSMOUSE_CMD_SETSCALE11
, 0x00 }, /* f */
55 static const struct alps_nibble_commands alps_v4_nibble_commands
[] = {
56 { PSMOUSE_CMD_ENABLE
, 0x00 }, /* 0 */
57 { PSMOUSE_CMD_RESET_DIS
, 0x00 }, /* 1 */
58 { PSMOUSE_CMD_SETSCALE21
, 0x00 }, /* 2 */
59 { PSMOUSE_CMD_SETRATE
, 0x0a }, /* 3 */
60 { PSMOUSE_CMD_SETRATE
, 0x14 }, /* 4 */
61 { PSMOUSE_CMD_SETRATE
, 0x28 }, /* 5 */
62 { PSMOUSE_CMD_SETRATE
, 0x3c }, /* 6 */
63 { PSMOUSE_CMD_SETRATE
, 0x50 }, /* 7 */
64 { PSMOUSE_CMD_SETRATE
, 0x64 }, /* 8 */
65 { PSMOUSE_CMD_SETRATE
, 0xc8 }, /* 9 */
66 { ALPS_CMD_NIBBLE_10
, 0x00 }, /* a */
67 { PSMOUSE_CMD_SETRES
, 0x00 }, /* b */
68 { PSMOUSE_CMD_SETRES
, 0x01 }, /* c */
69 { PSMOUSE_CMD_SETRES
, 0x02 }, /* d */
70 { PSMOUSE_CMD_SETRES
, 0x03 }, /* e */
71 { PSMOUSE_CMD_SETSCALE11
, 0x00 }, /* f */
74 static const struct alps_nibble_commands alps_v6_nibble_commands
[] = {
75 { PSMOUSE_CMD_ENABLE
, 0x00 }, /* 0 */
76 { PSMOUSE_CMD_SETRATE
, 0x0a }, /* 1 */
77 { PSMOUSE_CMD_SETRATE
, 0x14 }, /* 2 */
78 { PSMOUSE_CMD_SETRATE
, 0x28 }, /* 3 */
79 { PSMOUSE_CMD_SETRATE
, 0x3c }, /* 4 */
80 { PSMOUSE_CMD_SETRATE
, 0x50 }, /* 5 */
81 { PSMOUSE_CMD_SETRATE
, 0x64 }, /* 6 */
82 { PSMOUSE_CMD_SETRATE
, 0xc8 }, /* 7 */
83 { PSMOUSE_CMD_GETID
, 0x00 }, /* 8 */
84 { PSMOUSE_CMD_GETINFO
, 0x00 }, /* 9 */
85 { PSMOUSE_CMD_SETRES
, 0x00 }, /* a */
86 { PSMOUSE_CMD_SETRES
, 0x01 }, /* b */
87 { PSMOUSE_CMD_SETRES
, 0x02 }, /* c */
88 { PSMOUSE_CMD_SETRES
, 0x03 }, /* d */
89 { PSMOUSE_CMD_SETSCALE21
, 0x00 }, /* e */
90 { PSMOUSE_CMD_SETSCALE11
, 0x00 }, /* f */
94 #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
95 #define ALPS_PASS 0x04 /* device has a pass-through port */
97 #define ALPS_WHEEL 0x08 /* hardware wheel present */
98 #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
99 #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
100 #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
101 #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
102 6-byte ALPS packet */
103 #define ALPS_DELL 0x100 /* device is a Dell laptop */
104 #define ALPS_BUTTONPAD 0x200 /* device is a clickpad */
106 static const struct alps_model_info alps_model_data
[] = {
107 { { 0x32, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} }, /* Toshiba Salellite Pro M10 */
108 { { 0x33, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V1
, 0x88, 0xf8, 0 } }, /* UMAX-530T */
109 { { 0x53, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
110 { { 0x53, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
111 { { 0x60, 0x03, 0xc8 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } }, /* HP ze1115 */
112 { { 0x63, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
113 { { 0x63, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
114 { { 0x63, 0x02, 0x28 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_FW_BK_2
} }, /* Fujitsu Siemens S6010 */
115 { { 0x63, 0x02, 0x3c }, 0x00, { ALPS_PROTO_V2
, 0x8f, 0x8f, ALPS_WHEEL
} }, /* Toshiba Satellite S2400-103 */
116 { { 0x63, 0x02, 0x50 }, 0x00, { ALPS_PROTO_V2
, 0xef, 0xef, ALPS_FW_BK_1
} }, /* NEC Versa L320 */
117 { { 0x63, 0x02, 0x64 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
118 { { 0x63, 0x03, 0xc8 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} }, /* Dell Latitude D800 */
119 { { 0x73, 0x00, 0x0a }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_DUALPOINT
} }, /* ThinkPad R61 8918-5QG */
120 { { 0x73, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
121 { { 0x73, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_FW_BK_2
} }, /* Ahtec Laptop */
124 * XXX This entry is suspicious. First byte has zero lower nibble,
125 * which is what a normal mouse would report. Also, the value 0x0e
126 * isn't valid per PS/2 spec.
128 { { 0x20, 0x02, 0x0e }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} },
130 { { 0x22, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} },
131 { { 0x22, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xff, 0xff, ALPS_PASS
| ALPS_DUALPOINT
} }, /* Dell Latitude D600 */
132 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
133 { { 0x62, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xcf, 0xcf,
134 ALPS_PASS
| ALPS_DUALPOINT
| ALPS_PS2_INTERLEAVED
} },
135 { { 0x73, 0x00, 0x14 }, 0x00, { ALPS_PROTO_V6
, 0xff, 0xff, ALPS_DUALPOINT
} }, /* Dell XT2 */
136 { { 0x73, 0x02, 0x50 }, 0x00, { ALPS_PROTO_V2
, 0xcf, 0xcf, ALPS_FOUR_BUTTONS
} }, /* Dell Vostro 1400 */
137 { { 0x52, 0x01, 0x14 }, 0x00, { ALPS_PROTO_V2
, 0xff, 0xff,
138 ALPS_PASS
| ALPS_DUALPOINT
| ALPS_PS2_INTERLEAVED
} }, /* Toshiba Tecra A11-11L */
139 { { 0x73, 0x02, 0x64 }, 0x8a, { ALPS_PROTO_V4
, 0x8f, 0x8f, 0 } },
142 static const struct alps_protocol_info alps_v3_protocol_data
= {
143 ALPS_PROTO_V3
, 0x8f, 0x8f, ALPS_DUALPOINT
146 static const struct alps_protocol_info alps_v3_rushmore_data
= {
147 ALPS_PROTO_V3_RUSHMORE
, 0x8f, 0x8f, ALPS_DUALPOINT
150 static const struct alps_protocol_info alps_v5_protocol_data
= {
151 ALPS_PROTO_V5
, 0xc8, 0xd8, 0
154 static const struct alps_protocol_info alps_v7_protocol_data
= {
155 ALPS_PROTO_V7
, 0x48, 0x48, ALPS_DUALPOINT
158 static const struct alps_protocol_info alps_v8_protocol_data
= {
159 ALPS_PROTO_V8
, 0x18, 0x18, 0
162 static void alps_set_abs_params_st(struct alps_data
*priv
,
163 struct input_dev
*dev1
);
164 static void alps_set_abs_params_semi_mt(struct alps_data
*priv
,
165 struct input_dev
*dev1
);
166 static void alps_set_abs_params_v7(struct alps_data
*priv
,
167 struct input_dev
*dev1
);
168 static void alps_set_abs_params_ss4_v2(struct alps_data
*priv
,
169 struct input_dev
*dev1
);
171 /* Packet formats are described in Documentation/input/alps.txt */
173 static bool alps_is_valid_first_byte(struct alps_data
*priv
,
176 return (data
& priv
->mask0
) == priv
->byte0
;
179 static void alps_report_buttons(struct input_dev
*dev1
, struct input_dev
*dev2
,
180 int left
, int right
, int middle
)
182 struct input_dev
*dev
;
185 * If shared button has already been reported on the
186 * other device (dev2) then this event should be also
187 * sent through that device.
189 dev
= (dev2
&& test_bit(BTN_LEFT
, dev2
->key
)) ? dev2
: dev1
;
190 input_report_key(dev
, BTN_LEFT
, left
);
192 dev
= (dev2
&& test_bit(BTN_RIGHT
, dev2
->key
)) ? dev2
: dev1
;
193 input_report_key(dev
, BTN_RIGHT
, right
);
195 dev
= (dev2
&& test_bit(BTN_MIDDLE
, dev2
->key
)) ? dev2
: dev1
;
196 input_report_key(dev
, BTN_MIDDLE
, middle
);
199 * Sync the _other_ device now, we'll do the first
200 * device later once we report the rest of the events.
206 static void alps_process_packet_v1_v2(struct psmouse
*psmouse
)
208 struct alps_data
*priv
= psmouse
->private;
209 unsigned char *packet
= psmouse
->packet
;
210 struct input_dev
*dev
= psmouse
->dev
;
211 struct input_dev
*dev2
= priv
->dev2
;
212 int x
, y
, z
, ges
, fin
, left
, right
, middle
;
213 int back
= 0, forward
= 0;
215 if (priv
->proto_version
== ALPS_PROTO_V1
) {
216 left
= packet
[2] & 0x10;
217 right
= packet
[2] & 0x08;
219 x
= packet
[1] | ((packet
[0] & 0x07) << 7);
220 y
= packet
[4] | ((packet
[3] & 0x07) << 7);
223 left
= packet
[3] & 1;
224 right
= packet
[3] & 2;
225 middle
= packet
[3] & 4;
226 x
= packet
[1] | ((packet
[2] & 0x78) << (7 - 3));
227 y
= packet
[4] | ((packet
[3] & 0x70) << (7 - 4));
231 if (priv
->flags
& ALPS_FW_BK_1
) {
232 back
= packet
[0] & 0x10;
233 forward
= packet
[2] & 4;
236 if (priv
->flags
& ALPS_FW_BK_2
) {
237 back
= packet
[3] & 4;
238 forward
= packet
[2] & 4;
239 if ((middle
= forward
&& back
))
246 if ((priv
->flags
& ALPS_DUALPOINT
) && z
== 127) {
247 input_report_rel(dev2
, REL_X
, (x
> 383 ? (x
- 768) : x
));
248 input_report_rel(dev2
, REL_Y
, -(y
> 255 ? (y
- 512) : y
));
250 alps_report_buttons(dev2
, dev
, left
, right
, middle
);
256 /* Dell non interleaved V2 dualpoint has separate stick button bits */
257 if (priv
->proto_version
== ALPS_PROTO_V2
&&
258 priv
->flags
== (ALPS_DELL
| ALPS_PASS
| ALPS_DUALPOINT
)) {
259 left
|= packet
[0] & 1;
260 right
|= packet
[0] & 2;
261 middle
|= packet
[0] & 4;
264 alps_report_buttons(dev
, dev2
, left
, right
, middle
);
266 /* Convert hardware tap to a reasonable Z value */
271 * A "tap and drag" operation is reported by the hardware as a transition
272 * from (!fin && ges) to (fin && ges). This should be translated to the
273 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
275 if (ges
&& fin
&& !priv
->prev_fin
) {
276 input_report_abs(dev
, ABS_X
, x
);
277 input_report_abs(dev
, ABS_Y
, y
);
278 input_report_abs(dev
, ABS_PRESSURE
, 0);
279 input_report_key(dev
, BTN_TOOL_FINGER
, 0);
282 priv
->prev_fin
= fin
;
285 input_report_key(dev
, BTN_TOUCH
, 1);
287 input_report_key(dev
, BTN_TOUCH
, 0);
290 input_report_abs(dev
, ABS_X
, x
);
291 input_report_abs(dev
, ABS_Y
, y
);
294 input_report_abs(dev
, ABS_PRESSURE
, z
);
295 input_report_key(dev
, BTN_TOOL_FINGER
, z
> 0);
297 if (priv
->flags
& ALPS_WHEEL
)
298 input_report_rel(dev
, REL_WHEEL
, ((packet
[2] << 1) & 0x08) - ((packet
[0] >> 4) & 0x07));
300 if (priv
->flags
& (ALPS_FW_BK_1
| ALPS_FW_BK_2
)) {
301 input_report_key(dev
, BTN_FORWARD
, forward
);
302 input_report_key(dev
, BTN_BACK
, back
);
305 if (priv
->flags
& ALPS_FOUR_BUTTONS
) {
306 input_report_key(dev
, BTN_0
, packet
[2] & 4);
307 input_report_key(dev
, BTN_1
, packet
[0] & 0x10);
308 input_report_key(dev
, BTN_2
, packet
[3] & 4);
309 input_report_key(dev
, BTN_3
, packet
[0] & 0x20);
315 static void alps_get_bitmap_points(unsigned int map
,
316 struct alps_bitmap_point
*low
,
317 struct alps_bitmap_point
*high
,
320 struct alps_bitmap_point
*point
;
321 int i
, bit
, prev_bit
= 0;
324 for (i
= 0; map
!= 0; i
++, map
>>= 1) {
328 point
->start_bit
= i
;
342 * Process bitmap data from semi-mt protocols. Returns the number of
343 * fingers detected. A return value of 0 means at least one of the
346 * The bitmaps don't have enough data to track fingers, so this function
347 * only generates points representing a bounding box of all contacts.
348 * These points are returned in fields->mt when the return value
351 static int alps_process_bitmap(struct alps_data
*priv
,
352 struct alps_fields
*fields
)
354 int i
, fingers_x
= 0, fingers_y
= 0, fingers
, closest
;
355 struct alps_bitmap_point x_low
= {0,}, x_high
= {0,};
356 struct alps_bitmap_point y_low
= {0,}, y_high
= {0,};
357 struct input_mt_pos corner
[4];
359 if (!fields
->x_map
|| !fields
->y_map
)
362 alps_get_bitmap_points(fields
->x_map
, &x_low
, &x_high
, &fingers_x
);
363 alps_get_bitmap_points(fields
->y_map
, &y_low
, &y_high
, &fingers_y
);
366 * Fingers can overlap, so we use the maximum count of fingers
367 * on either axis as the finger count.
369 fingers
= max(fingers_x
, fingers_y
);
372 * If an axis reports only a single contact, we have overlapping or
373 * adjacent fingers. Divide the single contact between the two points.
375 if (fingers_x
== 1) {
376 i
= (x_low
.num_bits
- 1) / 2;
377 x_low
.num_bits
= x_low
.num_bits
- i
;
378 x_high
.start_bit
= x_low
.start_bit
+ i
;
379 x_high
.num_bits
= max(i
, 1);
381 if (fingers_y
== 1) {
382 i
= (y_low
.num_bits
- 1) / 2;
383 y_low
.num_bits
= y_low
.num_bits
- i
;
384 y_high
.start_bit
= y_low
.start_bit
+ i
;
385 y_high
.num_bits
= max(i
, 1);
388 /* top-left corner */
390 (priv
->x_max
* (2 * x_low
.start_bit
+ x_low
.num_bits
- 1)) /
391 (2 * (priv
->x_bits
- 1));
393 (priv
->y_max
* (2 * y_low
.start_bit
+ y_low
.num_bits
- 1)) /
394 (2 * (priv
->y_bits
- 1));
396 /* top-right corner */
398 (priv
->x_max
* (2 * x_high
.start_bit
+ x_high
.num_bits
- 1)) /
399 (2 * (priv
->x_bits
- 1));
401 (priv
->y_max
* (2 * y_low
.start_bit
+ y_low
.num_bits
- 1)) /
402 (2 * (priv
->y_bits
- 1));
404 /* bottom-right corner */
406 (priv
->x_max
* (2 * x_high
.start_bit
+ x_high
.num_bits
- 1)) /
407 (2 * (priv
->x_bits
- 1));
409 (priv
->y_max
* (2 * y_high
.start_bit
+ y_high
.num_bits
- 1)) /
410 (2 * (priv
->y_bits
- 1));
412 /* bottom-left corner */
414 (priv
->x_max
* (2 * x_low
.start_bit
+ x_low
.num_bits
- 1)) /
415 (2 * (priv
->x_bits
- 1));
417 (priv
->y_max
* (2 * y_high
.start_bit
+ y_high
.num_bits
- 1)) /
418 (2 * (priv
->y_bits
- 1));
420 /* x-bitmap order is reversed on v5 touchpads */
421 if (priv
->proto_version
== ALPS_PROTO_V5
) {
422 for (i
= 0; i
< 4; i
++)
423 corner
[i
].x
= priv
->x_max
- corner
[i
].x
;
426 /* y-bitmap order is reversed on v3 and v4 touchpads */
427 if (priv
->proto_version
== ALPS_PROTO_V3
||
428 priv
->proto_version
== ALPS_PROTO_V4
) {
429 for (i
= 0; i
< 4; i
++)
430 corner
[i
].y
= priv
->y_max
- corner
[i
].y
;
434 * We only select a corner for the second touch once per 2 finger
435 * touch sequence to avoid the chosen corner (and thus the coordinates)
436 * jumping around when the first touch is in the middle.
438 if (priv
->second_touch
== -1) {
439 /* Find corner closest to our st coordinates */
440 closest
= 0x7fffffff;
441 for (i
= 0; i
< 4; i
++) {
442 int dx
= fields
->st
.x
- corner
[i
].x
;
443 int dy
= fields
->st
.y
- corner
[i
].y
;
444 int distance
= dx
* dx
+ dy
* dy
;
446 if (distance
< closest
) {
447 priv
->second_touch
= i
;
451 /* And select the opposite corner to use for the 2nd touch */
452 priv
->second_touch
= (priv
->second_touch
+ 2) % 4;
455 fields
->mt
[0] = fields
->st
;
456 fields
->mt
[1] = corner
[priv
->second_touch
];
461 static void alps_set_slot(struct input_dev
*dev
, int slot
, int x
, int y
)
463 input_mt_slot(dev
, slot
);
464 input_mt_report_slot_state(dev
, MT_TOOL_FINGER
, true);
465 input_report_abs(dev
, ABS_MT_POSITION_X
, x
);
466 input_report_abs(dev
, ABS_MT_POSITION_Y
, y
);
469 static void alps_report_mt_data(struct psmouse
*psmouse
, int n
)
471 struct alps_data
*priv
= psmouse
->private;
472 struct input_dev
*dev
= psmouse
->dev
;
473 struct alps_fields
*f
= &priv
->f
;
474 int i
, slot
[MAX_TOUCHES
];
476 input_mt_assign_slots(dev
, slot
, f
->mt
, n
, 0);
477 for (i
= 0; i
< n
; i
++)
478 alps_set_slot(dev
, slot
[i
], f
->mt
[i
].x
, f
->mt
[i
].y
);
480 input_mt_sync_frame(dev
);
483 static void alps_report_semi_mt_data(struct psmouse
*psmouse
, int fingers
)
485 struct alps_data
*priv
= psmouse
->private;
486 struct input_dev
*dev
= psmouse
->dev
;
487 struct alps_fields
*f
= &priv
->f
;
489 /* Use st data when we don't have mt data */
491 f
->mt
[0].x
= f
->st
.x
;
492 f
->mt
[0].y
= f
->st
.y
;
493 fingers
= f
->pressure
> 0 ? 1 : 0;
494 priv
->second_touch
= -1;
498 alps_set_slot(dev
, 0, f
->mt
[0].x
, f
->mt
[0].y
);
500 alps_set_slot(dev
, 1, f
->mt
[1].x
, f
->mt
[1].y
);
501 input_mt_sync_frame(dev
);
503 input_mt_report_finger_count(dev
, fingers
);
505 input_report_key(dev
, BTN_LEFT
, f
->left
);
506 input_report_key(dev
, BTN_RIGHT
, f
->right
);
507 input_report_key(dev
, BTN_MIDDLE
, f
->middle
);
509 input_report_abs(dev
, ABS_PRESSURE
, f
->pressure
);
514 static void alps_process_trackstick_packet_v3(struct psmouse
*psmouse
)
516 struct alps_data
*priv
= psmouse
->private;
517 unsigned char *packet
= psmouse
->packet
;
518 struct input_dev
*dev
= priv
->dev2
;
519 int x
, y
, z
, left
, right
, middle
;
521 /* It should be a DualPoint when received trackstick packet */
522 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
523 psmouse_warn(psmouse
,
524 "Rejected trackstick packet from non DualPoint device");
528 /* Sanity check packet */
529 if (!(packet
[0] & 0x40)) {
530 psmouse_dbg(psmouse
, "Bad trackstick packet, discarding\n");
535 * There's a special packet that seems to indicate the end
536 * of a stream of trackstick data. Filter these out.
538 if (packet
[1] == 0x7f && packet
[2] == 0x7f && packet
[4] == 0x7f)
541 x
= (s8
)(((packet
[0] & 0x20) << 2) | (packet
[1] & 0x7f));
542 y
= (s8
)(((packet
[0] & 0x10) << 3) | (packet
[2] & 0x7f));
543 z
= (packet
[4] & 0x7c) >> 2;
546 * The x and y values tend to be quite large, and when used
547 * alone the trackstick is difficult to use. Scale them down
553 input_report_rel(dev
, REL_X
, x
);
554 input_report_rel(dev
, REL_Y
, -y
);
557 * Most ALPS models report the trackstick buttons in the touchpad
558 * packets, but a few report them here. No reliable way has been
559 * found to differentiate between the models upfront, so we enable
560 * the quirk in response to seeing a button press in the trackstick
563 left
= packet
[3] & 0x01;
564 right
= packet
[3] & 0x02;
565 middle
= packet
[3] & 0x04;
567 if (!(priv
->quirks
& ALPS_QUIRK_TRACKSTICK_BUTTONS
) &&
568 (left
|| right
|| middle
))
569 priv
->quirks
|= ALPS_QUIRK_TRACKSTICK_BUTTONS
;
571 if (priv
->quirks
& ALPS_QUIRK_TRACKSTICK_BUTTONS
) {
572 input_report_key(dev
, BTN_LEFT
, left
);
573 input_report_key(dev
, BTN_RIGHT
, right
);
574 input_report_key(dev
, BTN_MIDDLE
, middle
);
581 static void alps_decode_buttons_v3(struct alps_fields
*f
, unsigned char *p
)
583 f
->left
= !!(p
[3] & 0x01);
584 f
->right
= !!(p
[3] & 0x02);
585 f
->middle
= !!(p
[3] & 0x04);
587 f
->ts_left
= !!(p
[3] & 0x10);
588 f
->ts_right
= !!(p
[3] & 0x20);
589 f
->ts_middle
= !!(p
[3] & 0x40);
592 static int alps_decode_pinnacle(struct alps_fields
*f
, unsigned char *p
,
593 struct psmouse
*psmouse
)
595 f
->first_mp
= !!(p
[4] & 0x40);
596 f
->is_mp
= !!(p
[0] & 0x40);
599 f
->fingers
= (p
[5] & 0x3) + 1;
600 f
->x_map
= ((p
[4] & 0x7e) << 8) |
601 ((p
[1] & 0x7f) << 2) |
602 ((p
[0] & 0x30) >> 4);
603 f
->y_map
= ((p
[3] & 0x70) << 4) |
604 ((p
[2] & 0x7f) << 1) |
607 f
->st
.x
= ((p
[1] & 0x7f) << 4) | ((p
[4] & 0x30) >> 2) |
608 ((p
[0] & 0x30) >> 4);
609 f
->st
.y
= ((p
[2] & 0x7f) << 4) | (p
[4] & 0x0f);
610 f
->pressure
= p
[5] & 0x7f;
612 alps_decode_buttons_v3(f
, p
);
618 static int alps_decode_rushmore(struct alps_fields
*f
, unsigned char *p
,
619 struct psmouse
*psmouse
)
621 f
->first_mp
= !!(p
[4] & 0x40);
622 f
->is_mp
= !!(p
[5] & 0x40);
625 f
->fingers
= max((p
[5] & 0x3), ((p
[5] >> 2) & 0x3)) + 1;
626 f
->x_map
= ((p
[5] & 0x10) << 11) |
627 ((p
[4] & 0x7e) << 8) |
628 ((p
[1] & 0x7f) << 2) |
629 ((p
[0] & 0x30) >> 4);
630 f
->y_map
= ((p
[5] & 0x20) << 6) |
631 ((p
[3] & 0x70) << 4) |
632 ((p
[2] & 0x7f) << 1) |
635 f
->st
.x
= ((p
[1] & 0x7f) << 4) | ((p
[4] & 0x30) >> 2) |
636 ((p
[0] & 0x30) >> 4);
637 f
->st
.y
= ((p
[2] & 0x7f) << 4) | (p
[4] & 0x0f);
638 f
->pressure
= p
[5] & 0x7f;
640 alps_decode_buttons_v3(f
, p
);
646 static int alps_decode_dolphin(struct alps_fields
*f
, unsigned char *p
,
647 struct psmouse
*psmouse
)
650 struct alps_data
*priv
= psmouse
->private;
652 f
->first_mp
= !!(p
[0] & 0x02);
653 f
->is_mp
= !!(p
[0] & 0x20);
656 f
->st
.x
= ((p
[1] & 0x7f) | ((p
[4] & 0x0f) << 7));
657 f
->st
.y
= ((p
[2] & 0x7f) | ((p
[4] & 0xf0) << 3));
658 f
->pressure
= (p
[0] & 4) ? 0 : p
[5] & 0x7f;
659 alps_decode_buttons_v3(f
, p
);
661 f
->fingers
= ((p
[0] & 0x6) >> 1 |
664 palm_data
= (p
[1] & 0x7f) |
665 ((p
[2] & 0x7f) << 7) |
666 ((p
[4] & 0x7f) << 14) |
667 ((p
[5] & 0x7f) << 21) |
668 ((p
[3] & 0x07) << 28) |
669 (((u64
)p
[3] & 0x70) << 27) |
670 (((u64
)p
[0] & 0x01) << 34);
672 /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */
673 f
->y_map
= palm_data
& (BIT(priv
->y_bits
) - 1);
675 /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */
676 f
->x_map
= (palm_data
>> priv
->y_bits
) &
677 (BIT(priv
->x_bits
) - 1);
683 static void alps_process_touchpad_packet_v3_v5(struct psmouse
*psmouse
)
685 struct alps_data
*priv
= psmouse
->private;
686 unsigned char *packet
= psmouse
->packet
;
687 struct input_dev
*dev2
= priv
->dev2
;
688 struct alps_fields
*f
= &priv
->f
;
691 memset(f
, 0, sizeof(*f
));
693 priv
->decode_fields(f
, packet
, psmouse
);
696 * There's no single feature of touchpad position and bitmap packets
697 * that can be used to distinguish between them. We rely on the fact
698 * that a bitmap packet should always follow a position packet with
699 * bit 6 of packet[4] set.
701 if (priv
->multi_packet
) {
703 * Sometimes a position packet will indicate a multi-packet
704 * sequence, but then what follows is another position
705 * packet. Check for this, and when it happens process the
706 * position packet as usual.
709 fingers
= f
->fingers
;
711 * Bitmap processing uses position packet's coordinate
712 * data, so we need to do decode it first.
714 priv
->decode_fields(f
, priv
->multi_data
, psmouse
);
715 if (alps_process_bitmap(priv
, f
) == 0)
716 fingers
= 0; /* Use st data */
718 priv
->multi_packet
= 0;
723 * Bit 6 of byte 0 is not usually set in position packets. The only
724 * times it seems to be set is in situations where the data is
725 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
726 * this combined with the fact that this bit is useful for filtering
727 * out misidentified bitmap packets, we reject anything with this
733 if (!priv
->multi_packet
&& f
->first_mp
) {
734 priv
->multi_packet
= 1;
735 memcpy(priv
->multi_data
, packet
, sizeof(priv
->multi_data
));
739 priv
->multi_packet
= 0;
742 * Sometimes the hardware sends a single packet with z = 0
743 * in the middle of a stream. Real releases generate packets
744 * with x, y, and z all zero, so these seem to be flukes.
747 if (f
->st
.x
&& f
->st
.y
&& !f
->pressure
)
750 alps_report_semi_mt_data(psmouse
, fingers
);
752 if ((priv
->flags
& ALPS_DUALPOINT
) &&
753 !(priv
->quirks
& ALPS_QUIRK_TRACKSTICK_BUTTONS
)) {
754 input_report_key(dev2
, BTN_LEFT
, f
->ts_left
);
755 input_report_key(dev2
, BTN_RIGHT
, f
->ts_right
);
756 input_report_key(dev2
, BTN_MIDDLE
, f
->ts_middle
);
761 static void alps_process_packet_v3(struct psmouse
*psmouse
)
763 unsigned char *packet
= psmouse
->packet
;
766 * v3 protocol packets come in three types, two representing
767 * touchpad data and one representing trackstick data.
768 * Trackstick packets seem to be distinguished by always
769 * having 0x3f in the last byte. This value has never been
770 * observed in the last byte of either of the other types
773 if (packet
[5] == 0x3f) {
774 alps_process_trackstick_packet_v3(psmouse
);
778 alps_process_touchpad_packet_v3_v5(psmouse
);
781 static void alps_process_packet_v6(struct psmouse
*psmouse
)
783 struct alps_data
*priv
= psmouse
->private;
784 unsigned char *packet
= psmouse
->packet
;
785 struct input_dev
*dev
= psmouse
->dev
;
786 struct input_dev
*dev2
= priv
->dev2
;
787 int x
, y
, z
, left
, right
, middle
;
790 * We can use Byte5 to distinguish if the packet is from Touchpad
795 if (packet
[5] == 0x7F) {
796 /* It should be a DualPoint when received Trackpoint packet */
797 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
798 psmouse_warn(psmouse
,
799 "Rejected trackstick packet from non DualPoint device");
803 /* Trackpoint packet */
804 x
= packet
[1] | ((packet
[3] & 0x20) << 2);
805 y
= packet
[2] | ((packet
[3] & 0x40) << 1);
807 left
= packet
[3] & 0x01;
808 right
= packet
[3] & 0x02;
809 middle
= packet
[3] & 0x04;
811 /* To prevent the cursor jump when finger lifted */
812 if (x
== 0x7F && y
== 0x7F && z
== 0x7F)
815 /* Divide 4 since trackpoint's speed is too fast */
816 input_report_rel(dev2
, REL_X
, (char)x
/ 4);
817 input_report_rel(dev2
, REL_Y
, -((char)y
/ 4));
819 input_report_key(dev2
, BTN_LEFT
, left
);
820 input_report_key(dev2
, BTN_RIGHT
, right
);
821 input_report_key(dev2
, BTN_MIDDLE
, middle
);
827 /* Touchpad packet */
828 x
= packet
[1] | ((packet
[3] & 0x78) << 4);
829 y
= packet
[2] | ((packet
[4] & 0x78) << 4);
831 left
= packet
[3] & 0x01;
832 right
= packet
[3] & 0x02;
835 input_report_key(dev
, BTN_TOUCH
, 1);
837 input_report_key(dev
, BTN_TOUCH
, 0);
840 input_report_abs(dev
, ABS_X
, x
);
841 input_report_abs(dev
, ABS_Y
, y
);
844 input_report_abs(dev
, ABS_PRESSURE
, z
);
845 input_report_key(dev
, BTN_TOOL_FINGER
, z
> 0);
847 /* v6 touchpad does not have middle button */
848 input_report_key(dev
, BTN_LEFT
, left
);
849 input_report_key(dev
, BTN_RIGHT
, right
);
854 static void alps_process_packet_v4(struct psmouse
*psmouse
)
856 struct alps_data
*priv
= psmouse
->private;
857 unsigned char *packet
= psmouse
->packet
;
858 struct alps_fields
*f
= &priv
->f
;
862 * v4 has a 6-byte encoding for bitmap data, but this data is
863 * broken up between 3 normal packets. Use priv->multi_packet to
864 * track our position in the bitmap packet.
866 if (packet
[6] & 0x40) {
867 /* sync, reset position */
868 priv
->multi_packet
= 0;
871 if (WARN_ON_ONCE(priv
->multi_packet
> 2))
874 offset
= 2 * priv
->multi_packet
;
875 priv
->multi_data
[offset
] = packet
[6];
876 priv
->multi_data
[offset
+ 1] = packet
[7];
878 f
->left
= !!(packet
[4] & 0x01);
879 f
->right
= !!(packet
[4] & 0x02);
881 f
->st
.x
= ((packet
[1] & 0x7f) << 4) | ((packet
[3] & 0x30) >> 2) |
882 ((packet
[0] & 0x30) >> 4);
883 f
->st
.y
= ((packet
[2] & 0x7f) << 4) | (packet
[3] & 0x0f);
884 f
->pressure
= packet
[5] & 0x7f;
886 if (++priv
->multi_packet
> 2) {
887 priv
->multi_packet
= 0;
889 f
->x_map
= ((priv
->multi_data
[2] & 0x1f) << 10) |
890 ((priv
->multi_data
[3] & 0x60) << 3) |
891 ((priv
->multi_data
[0] & 0x3f) << 2) |
892 ((priv
->multi_data
[1] & 0x60) >> 5);
893 f
->y_map
= ((priv
->multi_data
[5] & 0x01) << 10) |
894 ((priv
->multi_data
[3] & 0x1f) << 5) |
895 (priv
->multi_data
[1] & 0x1f);
897 f
->fingers
= alps_process_bitmap(priv
, f
);
900 alps_report_semi_mt_data(psmouse
, f
->fingers
);
903 static bool alps_is_valid_package_v7(struct psmouse
*psmouse
)
905 switch (psmouse
->pktcnt
) {
907 return (psmouse
->packet
[2] & 0x40) == 0x40;
909 return (psmouse
->packet
[3] & 0x48) == 0x48;
911 return (psmouse
->packet
[5] & 0x40) == 0x00;
916 static unsigned char alps_get_packet_id_v7(char *byte
)
918 unsigned char packet_id
;
921 packet_id
= V7_PACKET_ID_TWO
;
922 else if (byte
[4] & 0x01)
923 packet_id
= V7_PACKET_ID_MULTI
;
924 else if ((byte
[0] & 0x10) && !(byte
[4] & 0x43))
925 packet_id
= V7_PACKET_ID_NEW
;
926 else if (byte
[1] == 0x00 && byte
[4] == 0x00)
927 packet_id
= V7_PACKET_ID_IDLE
;
929 packet_id
= V7_PACKET_ID_UNKNOWN
;
934 static void alps_get_finger_coordinate_v7(struct input_mt_pos
*mt
,
936 unsigned char pkt_id
)
938 mt
[0].x
= ((pkt
[2] & 0x80) << 4);
939 mt
[0].x
|= ((pkt
[2] & 0x3F) << 5);
940 mt
[0].x
|= ((pkt
[3] & 0x30) >> 1);
941 mt
[0].x
|= (pkt
[3] & 0x07);
942 mt
[0].y
= (pkt
[1] << 3) | (pkt
[0] & 0x07);
944 mt
[1].x
= ((pkt
[3] & 0x80) << 4);
945 mt
[1].x
|= ((pkt
[4] & 0x80) << 3);
946 mt
[1].x
|= ((pkt
[4] & 0x3F) << 4);
947 mt
[1].y
= ((pkt
[5] & 0x80) << 3);
948 mt
[1].y
|= ((pkt
[5] & 0x3F) << 4);
951 case V7_PACKET_ID_TWO
:
954 /* Detect false-postive touches where x & y report max value */
955 if (mt
[1].y
== 0x7ff && mt
[1].x
== 0xff0) {
957 /* y gets set to 0 at the end of this function */
961 case V7_PACKET_ID_MULTI
:
964 mt
[1].y
|= ((pkt
[4] & 0x02) << 4);
968 case V7_PACKET_ID_NEW
:
970 mt
[1].x
|= (pkt
[0] & 0x20);
975 mt
[0].y
= 0x7FF - mt
[0].y
;
976 mt
[1].y
= 0x7FF - mt
[1].y
;
979 static int alps_get_mt_count(struct input_mt_pos
*mt
)
983 for (i
= 0; i
< MAX_TOUCHES
; i
++) {
984 if (mt
[i
].x
!= 0 || mt
[i
].y
!= 0)
991 static int alps_decode_packet_v7(struct alps_fields
*f
,
993 struct psmouse
*psmouse
)
995 struct alps_data
*priv
= psmouse
->private;
996 unsigned char pkt_id
;
998 pkt_id
= alps_get_packet_id_v7(p
);
999 if (pkt_id
== V7_PACKET_ID_IDLE
)
1001 if (pkt_id
== V7_PACKET_ID_UNKNOWN
)
1004 * NEW packets are send to indicate a discontinuity in the finger
1005 * coordinate reporting. Specifically a finger may have moved from
1006 * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for
1009 * NEW packets have 3 problems:
1010 * 1) They do not contain middle / right button info (on non clickpads)
1011 * this can be worked around by preserving the old button state
1012 * 2) They do not contain an accurate fingercount, and they are
1013 * typically send when the number of fingers changes. We cannot use
1014 * the old finger count as that may mismatch with the amount of
1015 * touch coordinates we've available in the NEW packet
1016 * 3) Their x data for the second touch is inaccurate leading to
1017 * a possible jump of the x coordinate by 16 units when the first
1018 * non NEW packet comes in
1019 * Since problems 2 & 3 cannot be worked around, just ignore them.
1021 if (pkt_id
== V7_PACKET_ID_NEW
)
1024 alps_get_finger_coordinate_v7(f
->mt
, p
, pkt_id
);
1026 if (pkt_id
== V7_PACKET_ID_TWO
)
1027 f
->fingers
= alps_get_mt_count(f
->mt
);
1028 else /* pkt_id == V7_PACKET_ID_MULTI */
1029 f
->fingers
= 3 + (p
[5] & 0x03);
1031 f
->left
= (p
[0] & 0x80) >> 7;
1032 if (priv
->flags
& ALPS_BUTTONPAD
) {
1038 f
->right
= (p
[0] & 0x20) >> 5;
1039 f
->middle
= (p
[0] & 0x10) >> 4;
1042 /* Sometimes a single touch is reported in mt[1] rather then mt[0] */
1043 if (f
->fingers
== 1 && f
->mt
[0].x
== 0 && f
->mt
[0].y
== 0) {
1044 f
->mt
[0].x
= f
->mt
[1].x
;
1045 f
->mt
[0].y
= f
->mt
[1].y
;
1053 static void alps_process_trackstick_packet_v7(struct psmouse
*psmouse
)
1055 struct alps_data
*priv
= psmouse
->private;
1056 unsigned char *packet
= psmouse
->packet
;
1057 struct input_dev
*dev2
= priv
->dev2
;
1058 int x
, y
, z
, left
, right
, middle
;
1060 /* It should be a DualPoint when received trackstick packet */
1061 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
1062 psmouse_warn(psmouse
,
1063 "Rejected trackstick packet from non DualPoint device");
1067 x
= ((packet
[2] & 0xbf)) | ((packet
[3] & 0x10) << 2);
1068 y
= (packet
[3] & 0x07) | (packet
[4] & 0xb8) |
1069 ((packet
[3] & 0x20) << 1);
1070 z
= (packet
[5] & 0x3f) | ((packet
[3] & 0x80) >> 1);
1072 left
= (packet
[1] & 0x01);
1073 right
= (packet
[1] & 0x02) >> 1;
1074 middle
= (packet
[1] & 0x04) >> 2;
1076 input_report_rel(dev2
, REL_X
, (char)x
);
1077 input_report_rel(dev2
, REL_Y
, -((char)y
));
1079 input_report_key(dev2
, BTN_LEFT
, left
);
1080 input_report_key(dev2
, BTN_RIGHT
, right
);
1081 input_report_key(dev2
, BTN_MIDDLE
, middle
);
1086 static void alps_process_touchpad_packet_v7(struct psmouse
*psmouse
)
1088 struct alps_data
*priv
= psmouse
->private;
1089 struct input_dev
*dev
= psmouse
->dev
;
1090 struct alps_fields
*f
= &priv
->f
;
1092 memset(f
, 0, sizeof(*f
));
1094 if (priv
->decode_fields(f
, psmouse
->packet
, psmouse
))
1097 alps_report_mt_data(psmouse
, alps_get_mt_count(f
->mt
));
1099 input_mt_report_finger_count(dev
, f
->fingers
);
1101 input_report_key(dev
, BTN_LEFT
, f
->left
);
1102 input_report_key(dev
, BTN_RIGHT
, f
->right
);
1103 input_report_key(dev
, BTN_MIDDLE
, f
->middle
);
1108 static void alps_process_packet_v7(struct psmouse
*psmouse
)
1110 unsigned char *packet
= psmouse
->packet
;
1112 if (packet
[0] == 0x48 && (packet
[4] & 0x47) == 0x06)
1113 alps_process_trackstick_packet_v7(psmouse
);
1115 alps_process_touchpad_packet_v7(psmouse
);
1118 static unsigned char alps_get_pkt_id_ss4_v2(unsigned char *byte
)
1120 unsigned char pkt_id
= SS4_PACKET_ID_IDLE
;
1122 if (byte
[0] == 0x18 && byte
[1] == 0x10 && byte
[2] == 0x00 &&
1123 (byte
[3] & 0x88) == 0x08 && byte
[4] == 0x10 && byte
[5] == 0x00) {
1124 pkt_id
= SS4_PACKET_ID_IDLE
;
1125 } else if (!(byte
[3] & 0x10)) {
1126 pkt_id
= SS4_PACKET_ID_ONE
;
1127 } else if (!(byte
[3] & 0x20)) {
1128 pkt_id
= SS4_PACKET_ID_TWO
;
1130 pkt_id
= SS4_PACKET_ID_MULTI
;
1136 static int alps_decode_ss4_v2(struct alps_fields
*f
,
1137 unsigned char *p
, struct psmouse
*psmouse
)
1139 struct alps_data
*priv
= psmouse
->private;
1140 unsigned char pkt_id
;
1141 unsigned int no_data_x
, no_data_y
;
1143 pkt_id
= alps_get_pkt_id_ss4_v2(p
);
1145 /* Current packet is 1Finger coordinate packet */
1147 case SS4_PACKET_ID_ONE
:
1148 f
->mt
[0].x
= SS4_1F_X_V2(p
);
1149 f
->mt
[0].y
= SS4_1F_Y_V2(p
);
1150 f
->pressure
= ((SS4_1F_Z_V2(p
)) * 2) & 0x7f;
1156 case SS4_PACKET_ID_TWO
:
1157 if (priv
->flags
& ALPS_BUTTONPAD
) {
1158 f
->mt
[0].x
= SS4_BTL_MF_X_V2(p
, 0);
1159 f
->mt
[0].y
= SS4_BTL_MF_Y_V2(p
, 0);
1160 f
->mt
[1].x
= SS4_BTL_MF_X_V2(p
, 1);
1161 f
->mt
[1].y
= SS4_BTL_MF_Y_V2(p
, 1);
1163 f
->mt
[0].x
= SS4_STD_MF_X_V2(p
, 0);
1164 f
->mt
[0].y
= SS4_STD_MF_Y_V2(p
, 0);
1165 f
->mt
[1].x
= SS4_STD_MF_X_V2(p
, 1);
1166 f
->mt
[1].y
= SS4_STD_MF_Y_V2(p
, 1);
1168 f
->pressure
= SS4_MF_Z_V2(p
, 0) ? 0x30 : 0;
1170 if (SS4_IS_MF_CONTINUE(p
)) {
1180 case SS4_PACKET_ID_MULTI
:
1181 if (priv
->flags
& ALPS_BUTTONPAD
) {
1182 f
->mt
[2].x
= SS4_BTL_MF_X_V2(p
, 0);
1183 f
->mt
[2].y
= SS4_BTL_MF_Y_V2(p
, 0);
1184 f
->mt
[3].x
= SS4_BTL_MF_X_V2(p
, 1);
1185 f
->mt
[3].y
= SS4_BTL_MF_Y_V2(p
, 1);
1186 no_data_x
= SS4_MFPACKET_NO_AX_BL
;
1187 no_data_y
= SS4_MFPACKET_NO_AY_BL
;
1189 f
->mt
[2].x
= SS4_STD_MF_X_V2(p
, 0);
1190 f
->mt
[2].y
= SS4_STD_MF_Y_V2(p
, 0);
1191 f
->mt
[3].x
= SS4_STD_MF_X_V2(p
, 1);
1192 f
->mt
[3].y
= SS4_STD_MF_Y_V2(p
, 1);
1193 no_data_x
= SS4_MFPACKET_NO_AX
;
1194 no_data_y
= SS4_MFPACKET_NO_AY
;
1200 if (SS4_IS_5F_DETECTED(p
)) {
1202 } else if (f
->mt
[3].x
== no_data_x
&&
1203 f
->mt
[3].y
== no_data_y
) {
1212 case SS4_PACKET_ID_IDLE
:
1214 memset(f
, 0, sizeof(struct alps_fields
));
1218 f
->left
= !!(SS4_BTN_V2(p
) & 0x01);
1219 if (!(priv
->flags
& ALPS_BUTTONPAD
)) {
1220 f
->right
= !!(SS4_BTN_V2(p
) & 0x02);
1221 f
->middle
= !!(SS4_BTN_V2(p
) & 0x04);
1227 static void alps_process_packet_ss4_v2(struct psmouse
*psmouse
)
1229 struct alps_data
*priv
= psmouse
->private;
1230 unsigned char *packet
= psmouse
->packet
;
1231 struct input_dev
*dev
= psmouse
->dev
;
1232 struct alps_fields
*f
= &priv
->f
;
1234 memset(f
, 0, sizeof(struct alps_fields
));
1235 priv
->decode_fields(f
, packet
, psmouse
);
1236 if (priv
->multi_packet
) {
1238 * Sometimes the first packet will indicate a multi-packet
1239 * sequence, but sometimes the next multi-packet would not
1240 * come. Check for this, and when it happens process the
1241 * position packet as usual.
1244 /* Now process the 1st packet */
1245 priv
->decode_fields(f
, priv
->multi_data
, psmouse
);
1247 priv
->multi_packet
= 0;
1252 * "f.is_mp" would always be '0' after merging the 1st and 2nd packet.
1253 * When it is set, it means 2nd packet comes without 1st packet come.
1258 /* Save the first packet */
1259 if (!priv
->multi_packet
&& f
->first_mp
) {
1260 priv
->multi_packet
= 1;
1261 memcpy(priv
->multi_data
, packet
, sizeof(priv
->multi_data
));
1265 priv
->multi_packet
= 0;
1267 alps_report_mt_data(psmouse
, (f
->fingers
<= 4) ? f
->fingers
: 4);
1269 input_mt_report_finger_count(dev
, f
->fingers
);
1271 input_report_key(dev
, BTN_LEFT
, f
->left
);
1272 input_report_key(dev
, BTN_RIGHT
, f
->right
);
1273 input_report_key(dev
, BTN_MIDDLE
, f
->middle
);
1275 input_report_abs(dev
, ABS_PRESSURE
, f
->pressure
);
1279 static bool alps_is_valid_package_ss4_v2(struct psmouse
*psmouse
)
1281 if (psmouse
->pktcnt
== 4 && ((psmouse
->packet
[3] & 0x08) != 0x08))
1283 if (psmouse
->pktcnt
== 6 && ((psmouse
->packet
[5] & 0x10) != 0x0))
1288 static DEFINE_MUTEX(alps_mutex
);
1290 static void alps_register_bare_ps2_mouse(struct work_struct
*work
)
1292 struct alps_data
*priv
=
1293 container_of(work
, struct alps_data
, dev3_register_work
.work
);
1294 struct psmouse
*psmouse
= priv
->psmouse
;
1295 struct input_dev
*dev3
;
1298 mutex_lock(&alps_mutex
);
1303 dev3
= input_allocate_device();
1305 psmouse_err(psmouse
, "failed to allocate secondary device\n");
1310 snprintf(priv
->phys3
, sizeof(priv
->phys3
), "%s/%s",
1311 psmouse
->ps2dev
.serio
->phys
,
1312 (priv
->dev2
? "input2" : "input1"));
1313 dev3
->phys
= priv
->phys3
;
1316 * format of input device name is: "protocol vendor name"
1317 * see function psmouse_switch_protocol() in psmouse-base.c
1319 dev3
->name
= "PS/2 ALPS Mouse";
1321 dev3
->id
.bustype
= BUS_I8042
;
1322 dev3
->id
.vendor
= 0x0002;
1323 dev3
->id
.product
= PSMOUSE_PS2
;
1324 dev3
->id
.version
= 0x0000;
1325 dev3
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
1327 input_set_capability(dev3
, EV_REL
, REL_X
);
1328 input_set_capability(dev3
, EV_REL
, REL_Y
);
1329 input_set_capability(dev3
, EV_KEY
, BTN_LEFT
);
1330 input_set_capability(dev3
, EV_KEY
, BTN_RIGHT
);
1331 input_set_capability(dev3
, EV_KEY
, BTN_MIDDLE
);
1333 __set_bit(INPUT_PROP_POINTER
, dev3
->propbit
);
1335 error
= input_register_device(dev3
);
1337 psmouse_err(psmouse
,
1338 "failed to register secondary device: %d\n",
1340 input_free_device(dev3
);
1348 * Save the error code so that we can detect that we
1349 * already tried to create the device.
1352 priv
->dev3
= ERR_PTR(error
);
1354 mutex_unlock(&alps_mutex
);
1357 static void alps_report_bare_ps2_packet(struct psmouse
*psmouse
,
1358 unsigned char packet
[],
1359 bool report_buttons
)
1361 struct alps_data
*priv
= psmouse
->private;
1362 struct input_dev
*dev
, *dev2
= NULL
;
1364 /* Figure out which device to use to report the bare packet */
1365 if (priv
->proto_version
== ALPS_PROTO_V2
&&
1366 (priv
->flags
& ALPS_DUALPOINT
)) {
1367 /* On V2 devices the DualPoint Stick reports bare packets */
1369 dev2
= psmouse
->dev
;
1370 } else if (unlikely(IS_ERR_OR_NULL(priv
->dev3
))) {
1371 /* Register dev3 mouse if we received PS/2 packet first time */
1372 if (!IS_ERR(priv
->dev3
))
1373 psmouse_queue_work(psmouse
, &priv
->dev3_register_work
,
1381 alps_report_buttons(dev
, dev2
,
1382 packet
[0] & 1, packet
[0] & 2, packet
[0] & 4);
1384 input_report_rel(dev
, REL_X
,
1385 packet
[1] ? packet
[1] - ((packet
[0] << 4) & 0x100) : 0);
1386 input_report_rel(dev
, REL_Y
,
1387 packet
[2] ? ((packet
[0] << 3) & 0x100) - packet
[2] : 0);
1392 static psmouse_ret_t
alps_handle_interleaved_ps2(struct psmouse
*psmouse
)
1394 struct alps_data
*priv
= psmouse
->private;
1396 if (psmouse
->pktcnt
< 6)
1397 return PSMOUSE_GOOD_DATA
;
1399 if (psmouse
->pktcnt
== 6) {
1401 * Start a timer to flush the packet if it ends up last
1402 * 6-byte packet in the stream. Timer needs to fire
1403 * psmouse core times out itself. 20 ms should be enough
1404 * to decide if we are getting more data or not.
1406 mod_timer(&priv
->timer
, jiffies
+ msecs_to_jiffies(20));
1407 return PSMOUSE_GOOD_DATA
;
1410 del_timer(&priv
->timer
);
1412 if (psmouse
->packet
[6] & 0x80) {
1415 * Highest bit is set - that means we either had
1416 * complete ALPS packet and this is start of the
1417 * next packet or we got garbage.
1420 if (((psmouse
->packet
[3] |
1421 psmouse
->packet
[4] |
1422 psmouse
->packet
[5]) & 0x80) ||
1423 (!alps_is_valid_first_byte(priv
, psmouse
->packet
[6]))) {
1424 psmouse_dbg(psmouse
,
1425 "refusing packet %4ph (suspected interleaved ps/2)\n",
1426 psmouse
->packet
+ 3);
1427 return PSMOUSE_BAD_DATA
;
1430 priv
->process_packet(psmouse
);
1432 /* Continue with the next packet */
1433 psmouse
->packet
[0] = psmouse
->packet
[6];
1434 psmouse
->pktcnt
= 1;
1439 * High bit is 0 - that means that we indeed got a PS/2
1440 * packet in the middle of ALPS packet.
1442 * There is also possibility that we got 6-byte ALPS
1443 * packet followed by 3-byte packet from trackpoint. We
1444 * can not distinguish between these 2 scenarios but
1445 * because the latter is unlikely to happen in course of
1446 * normal operation (user would need to press all
1447 * buttons on the pad and start moving trackpoint
1448 * without touching the pad surface) we assume former.
1449 * Even if we are wrong the wost thing that would happen
1450 * the cursor would jump but we should not get protocol
1451 * de-synchronization.
1454 alps_report_bare_ps2_packet(psmouse
, &psmouse
->packet
[3],
1458 * Continue with the standard ALPS protocol handling,
1459 * but make sure we won't process it as an interleaved
1460 * packet again, which may happen if all buttons are
1461 * pressed. To avoid this let's reset the 4th bit which
1464 psmouse
->packet
[3] = psmouse
->packet
[6] & 0xf7;
1465 psmouse
->pktcnt
= 4;
1468 return PSMOUSE_GOOD_DATA
;
1471 static void alps_flush_packet(unsigned long data
)
1473 struct psmouse
*psmouse
= (struct psmouse
*)data
;
1474 struct alps_data
*priv
= psmouse
->private;
1476 serio_pause_rx(psmouse
->ps2dev
.serio
);
1478 if (psmouse
->pktcnt
== psmouse
->pktsize
) {
1481 * We did not any more data in reasonable amount of time.
1482 * Validate the last 3 bytes and process as a standard
1485 if ((psmouse
->packet
[3] |
1486 psmouse
->packet
[4] |
1487 psmouse
->packet
[5]) & 0x80) {
1488 psmouse_dbg(psmouse
,
1489 "refusing packet %3ph (suspected interleaved ps/2)\n",
1490 psmouse
->packet
+ 3);
1492 priv
->process_packet(psmouse
);
1494 psmouse
->pktcnt
= 0;
1497 serio_continue_rx(psmouse
->ps2dev
.serio
);
1500 static psmouse_ret_t
alps_process_byte(struct psmouse
*psmouse
)
1502 struct alps_data
*priv
= psmouse
->private;
1505 * Check if we are dealing with a bare PS/2 packet, presumably from
1506 * a device connected to the external PS/2 port. Because bare PS/2
1507 * protocol does not have enough constant bits to self-synchronize
1508 * properly we only do this if the device is fully synchronized.
1509 * Can not distinguish V8's first byte from PS/2 packet's
1511 if (priv
->proto_version
!= ALPS_PROTO_V8
&&
1512 !psmouse
->out_of_sync_cnt
&&
1513 (psmouse
->packet
[0] & 0xc8) == 0x08) {
1515 if (psmouse
->pktcnt
== 3) {
1516 alps_report_bare_ps2_packet(psmouse
, psmouse
->packet
,
1518 return PSMOUSE_FULL_PACKET
;
1520 return PSMOUSE_GOOD_DATA
;
1523 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
1525 if ((priv
->flags
& ALPS_PS2_INTERLEAVED
) &&
1526 psmouse
->pktcnt
>= 4 && (psmouse
->packet
[3] & 0x0f) == 0x0f) {
1527 return alps_handle_interleaved_ps2(psmouse
);
1530 if (!alps_is_valid_first_byte(priv
, psmouse
->packet
[0])) {
1531 psmouse_dbg(psmouse
,
1532 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
1533 psmouse
->packet
[0], priv
->mask0
, priv
->byte0
);
1534 return PSMOUSE_BAD_DATA
;
1537 /* Bytes 2 - pktsize should have 0 in the highest bit */
1538 if (priv
->proto_version
< ALPS_PROTO_V5
&&
1539 psmouse
->pktcnt
>= 2 && psmouse
->pktcnt
<= psmouse
->pktsize
&&
1540 (psmouse
->packet
[psmouse
->pktcnt
- 1] & 0x80)) {
1541 psmouse_dbg(psmouse
, "refusing packet[%i] = %x\n",
1542 psmouse
->pktcnt
- 1,
1543 psmouse
->packet
[psmouse
->pktcnt
- 1]);
1545 if (priv
->proto_version
== ALPS_PROTO_V3_RUSHMORE
&&
1546 psmouse
->pktcnt
== psmouse
->pktsize
) {
1548 * Some Dell boxes, such as Latitude E6440 or E7440
1549 * with closed lid, quite often smash last byte of
1550 * otherwise valid packet with 0xff. Given that the
1551 * next packet is very likely to be valid let's
1552 * report PSMOUSE_FULL_PACKET but not process data,
1553 * rather than reporting PSMOUSE_BAD_DATA and
1556 return PSMOUSE_FULL_PACKET
;
1559 return PSMOUSE_BAD_DATA
;
1562 if ((priv
->proto_version
== ALPS_PROTO_V7
&&
1563 !alps_is_valid_package_v7(psmouse
)) ||
1564 (priv
->proto_version
== ALPS_PROTO_V8
&&
1565 !alps_is_valid_package_ss4_v2(psmouse
))) {
1566 psmouse_dbg(psmouse
, "refusing packet[%i] = %x\n",
1567 psmouse
->pktcnt
- 1,
1568 psmouse
->packet
[psmouse
->pktcnt
- 1]);
1569 return PSMOUSE_BAD_DATA
;
1572 if (psmouse
->pktcnt
== psmouse
->pktsize
) {
1573 priv
->process_packet(psmouse
);
1574 return PSMOUSE_FULL_PACKET
;
1577 return PSMOUSE_GOOD_DATA
;
1580 static int alps_command_mode_send_nibble(struct psmouse
*psmouse
, int nibble
)
1582 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1583 struct alps_data
*priv
= psmouse
->private;
1585 unsigned char *param
;
1586 unsigned char dummy
[4];
1588 BUG_ON(nibble
> 0xf);
1590 command
= priv
->nibble_commands
[nibble
].command
;
1591 param
= (command
& 0x0f00) ?
1592 dummy
: (unsigned char *)&priv
->nibble_commands
[nibble
].data
;
1594 if (ps2_command(ps2dev
, param
, command
))
1600 static int alps_command_mode_set_addr(struct psmouse
*psmouse
, int addr
)
1602 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1603 struct alps_data
*priv
= psmouse
->private;
1606 if (ps2_command(ps2dev
, NULL
, priv
->addr_command
))
1609 for (i
= 12; i
>= 0; i
-= 4) {
1610 nibble
= (addr
>> i
) & 0xf;
1611 if (alps_command_mode_send_nibble(psmouse
, nibble
))
1618 static int __alps_command_mode_read_reg(struct psmouse
*psmouse
, int addr
)
1620 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1621 unsigned char param
[4];
1623 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
1627 * The address being read is returned in the first two bytes
1628 * of the result. Check that this address matches the expected
1631 if (addr
!= ((param
[0] << 8) | param
[1]))
1637 static int alps_command_mode_read_reg(struct psmouse
*psmouse
, int addr
)
1639 if (alps_command_mode_set_addr(psmouse
, addr
))
1641 return __alps_command_mode_read_reg(psmouse
, addr
);
1644 static int __alps_command_mode_write_reg(struct psmouse
*psmouse
, u8 value
)
1646 if (alps_command_mode_send_nibble(psmouse
, (value
>> 4) & 0xf))
1648 if (alps_command_mode_send_nibble(psmouse
, value
& 0xf))
1653 static int alps_command_mode_write_reg(struct psmouse
*psmouse
, int addr
,
1656 if (alps_command_mode_set_addr(psmouse
, addr
))
1658 return __alps_command_mode_write_reg(psmouse
, value
);
1661 static int alps_rpt_cmd(struct psmouse
*psmouse
, int init_command
,
1662 int repeated_command
, unsigned char *param
)
1664 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1667 if (init_command
&& ps2_command(ps2dev
, param
, init_command
))
1670 if (ps2_command(ps2dev
, NULL
, repeated_command
) ||
1671 ps2_command(ps2dev
, NULL
, repeated_command
) ||
1672 ps2_command(ps2dev
, NULL
, repeated_command
))
1675 param
[0] = param
[1] = param
[2] = 0xff;
1676 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
1679 psmouse_dbg(psmouse
, "%2.2X report: %3ph\n",
1680 repeated_command
, param
);
1684 static bool alps_check_valid_firmware_id(unsigned char id
[])
1689 if (id
[0] == 0x88 &&
1692 (id
[1] & 0xf0) == 0xb0 ||
1693 (id
[1] & 0xf0) == 0xc0)) {
1700 static int alps_enter_command_mode(struct psmouse
*psmouse
)
1702 unsigned char param
[4];
1704 if (alps_rpt_cmd(psmouse
, 0, PSMOUSE_CMD_RESET_WRAP
, param
)) {
1705 psmouse_err(psmouse
, "failed to enter command mode\n");
1709 if (!alps_check_valid_firmware_id(param
)) {
1710 psmouse_dbg(psmouse
,
1711 "unknown response while entering command mode\n");
1717 static inline int alps_exit_command_mode(struct psmouse
*psmouse
)
1719 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1720 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
))
1726 * For DualPoint devices select the device that should respond to
1727 * subsequent commands. It looks like glidepad is behind stickpointer,
1728 * I'd thought it would be other way around...
1730 static int alps_passthrough_mode_v2(struct psmouse
*psmouse
, bool enable
)
1732 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1733 int cmd
= enable
? PSMOUSE_CMD_SETSCALE21
: PSMOUSE_CMD_SETSCALE11
;
1735 if (ps2_command(ps2dev
, NULL
, cmd
) ||
1736 ps2_command(ps2dev
, NULL
, cmd
) ||
1737 ps2_command(ps2dev
, NULL
, cmd
) ||
1738 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
))
1741 /* we may get 3 more bytes, just ignore them */
1742 ps2_drain(ps2dev
, 3, 100);
1747 static int alps_absolute_mode_v1_v2(struct psmouse
*psmouse
)
1749 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1751 /* Try ALPS magic knock - 4 disable before enable */
1752 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1753 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1754 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1755 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1756 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
))
1760 * Switch mouse to poll (remote) mode so motion data will not
1763 return ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
);
1766 static int alps_monitor_mode_send_word(struct psmouse
*psmouse
, u16 word
)
1771 * b0-b11 are valid bits, send sequence is inverse.
1772 * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1
1774 for (i
= 0; i
<= 8; i
+= 4) {
1775 nibble
= (word
>> i
) & 0xf;
1776 if (alps_command_mode_send_nibble(psmouse
, nibble
))
1783 static int alps_monitor_mode_write_reg(struct psmouse
*psmouse
,
1784 u16 addr
, u16 value
)
1786 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1788 /* 0x0A0 is the command to write the word */
1789 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
) ||
1790 alps_monitor_mode_send_word(psmouse
, 0x0A0) ||
1791 alps_monitor_mode_send_word(psmouse
, addr
) ||
1792 alps_monitor_mode_send_word(psmouse
, value
) ||
1793 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
))
1799 static int alps_monitor_mode(struct psmouse
*psmouse
, bool enable
)
1801 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1804 /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */
1805 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_WRAP
) ||
1806 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_GETINFO
) ||
1807 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1808 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1809 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE21
) ||
1810 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
1811 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE21
) ||
1812 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_GETINFO
))
1815 /* EC to exit monitor mode */
1816 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_WRAP
))
1823 static int alps_absolute_mode_v6(struct psmouse
*psmouse
)
1825 u16 reg_val
= 0x181;
1828 /* enter monitor mode, to write the register */
1829 if (alps_monitor_mode(psmouse
, true))
1832 ret
= alps_monitor_mode_write_reg(psmouse
, 0x000, reg_val
);
1834 if (alps_monitor_mode(psmouse
, false))
1840 static int alps_get_status(struct psmouse
*psmouse
, char *param
)
1842 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
1843 if (alps_rpt_cmd(psmouse
, 0, PSMOUSE_CMD_DISABLE
, param
))
1850 * Turn touchpad tapping on or off. The sequences are:
1851 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1852 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1853 * My guess that 0xE9 (GetInfo) is here as a sync point.
1854 * For models that also have stickpointer (DualPoints) its tapping
1855 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1856 * we don't fiddle with it.
1858 static int alps_tap_mode(struct psmouse
*psmouse
, int enable
)
1860 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1861 int cmd
= enable
? PSMOUSE_CMD_SETRATE
: PSMOUSE_CMD_SETRES
;
1862 unsigned char tap_arg
= enable
? 0x0A : 0x00;
1863 unsigned char param
[4];
1865 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
) ||
1866 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1867 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1868 ps2_command(ps2dev
, &tap_arg
, cmd
))
1871 if (alps_get_status(psmouse
, param
))
1878 * alps_poll() - poll the touchpad for current motion packet.
1881 static int alps_poll(struct psmouse
*psmouse
)
1883 struct alps_data
*priv
= psmouse
->private;
1884 unsigned char buf
[sizeof(psmouse
->packet
)];
1887 if (priv
->flags
& ALPS_PASS
)
1888 alps_passthrough_mode_v2(psmouse
, true);
1890 poll_failed
= ps2_command(&psmouse
->ps2dev
, buf
,
1891 PSMOUSE_CMD_POLL
| (psmouse
->pktsize
<< 8)) < 0;
1893 if (priv
->flags
& ALPS_PASS
)
1894 alps_passthrough_mode_v2(psmouse
, false);
1896 if (poll_failed
|| (buf
[0] & priv
->mask0
) != priv
->byte0
)
1899 if ((psmouse
->badbyte
& 0xc8) == 0x08) {
1901 * Poll the track stick ...
1903 if (ps2_command(&psmouse
->ps2dev
, buf
, PSMOUSE_CMD_POLL
| (3 << 8)))
1907 memcpy(psmouse
->packet
, buf
, sizeof(buf
));
1911 static int alps_hw_init_v1_v2(struct psmouse
*psmouse
)
1913 struct alps_data
*priv
= psmouse
->private;
1915 if ((priv
->flags
& ALPS_PASS
) &&
1916 alps_passthrough_mode_v2(psmouse
, true)) {
1920 if (alps_tap_mode(psmouse
, true)) {
1921 psmouse_warn(psmouse
, "Failed to enable hardware tapping\n");
1925 if (alps_absolute_mode_v1_v2(psmouse
)) {
1926 psmouse_err(psmouse
, "Failed to enable absolute mode\n");
1930 if ((priv
->flags
& ALPS_PASS
) &&
1931 alps_passthrough_mode_v2(psmouse
, false)) {
1935 /* ALPS needs stream mode, otherwise it won't report any data */
1936 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
)) {
1937 psmouse_err(psmouse
, "Failed to enable stream mode\n");
1944 static int alps_hw_init_v6(struct psmouse
*psmouse
)
1946 unsigned char param
[2] = {0xC8, 0x14};
1948 /* Enter passthrough mode to let trackpoint enter 6byte raw mode */
1949 if (alps_passthrough_mode_v2(psmouse
, true))
1952 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
1953 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
1954 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
1955 ps2_command(&psmouse
->ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
1956 ps2_command(&psmouse
->ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
))
1959 if (alps_passthrough_mode_v2(psmouse
, false))
1962 if (alps_absolute_mode_v6(psmouse
)) {
1963 psmouse_err(psmouse
, "Failed to enable absolute mode\n");
1971 * Enable or disable passthrough mode to the trackstick.
1973 static int alps_passthrough_mode_v3(struct psmouse
*psmouse
,
1974 int reg_base
, bool enable
)
1976 int reg_val
, ret
= -1;
1978 if (alps_enter_command_mode(psmouse
))
1981 reg_val
= alps_command_mode_read_reg(psmouse
, reg_base
+ 0x0008);
1990 ret
= __alps_command_mode_write_reg(psmouse
, reg_val
);
1993 if (alps_exit_command_mode(psmouse
))
1998 /* Must be in command mode when calling this function */
1999 static int alps_absolute_mode_v3(struct psmouse
*psmouse
)
2003 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0004);
2008 if (__alps_command_mode_write_reg(psmouse
, reg_val
))
2014 static int alps_probe_trackstick_v3(struct psmouse
*psmouse
, int reg_base
)
2016 int ret
= -EIO
, reg_val
;
2018 if (alps_enter_command_mode(psmouse
))
2021 reg_val
= alps_command_mode_read_reg(psmouse
, reg_base
+ 0x08);
2025 /* bit 7: trackstick is present */
2026 ret
= reg_val
& 0x80 ? 0 : -ENODEV
;
2029 alps_exit_command_mode(psmouse
);
2033 static int alps_setup_trackstick_v3(struct psmouse
*psmouse
, int reg_base
)
2035 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2037 unsigned char param
[4];
2039 if (alps_passthrough_mode_v3(psmouse
, reg_base
, true))
2043 * E7 report for the trackstick
2045 * There have been reports of failures to seem to trace back
2046 * to the above trackstick check failing. When these occur
2047 * this E7 report fails, so when that happens we continue
2048 * with the assumption that there isn't a trackstick after
2051 if (alps_rpt_cmd(psmouse
, 0, PSMOUSE_CMD_SETSCALE21
, param
)) {
2052 psmouse_warn(psmouse
, "Failed to initialize trackstick (E7 report failed)\n");
2055 psmouse_dbg(psmouse
, "trackstick E7 report: %3ph\n", param
);
2058 * Not sure what this does, but it is absolutely
2059 * essential. Without it, the touchpad does not
2060 * work at all and the trackstick just emits normal
2063 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
2064 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
2065 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
2066 alps_command_mode_send_nibble(psmouse
, 0x9) ||
2067 alps_command_mode_send_nibble(psmouse
, 0x4)) {
2068 psmouse_err(psmouse
,
2069 "Error sending magic E6 sequence\n");
2075 * This ensures the trackstick packets are in the format
2076 * supported by this driver. If bit 1 isn't set the packet
2077 * format is different.
2079 if (alps_enter_command_mode(psmouse
) ||
2080 alps_command_mode_write_reg(psmouse
,
2081 reg_base
+ 0x08, 0x82) ||
2082 alps_exit_command_mode(psmouse
))
2087 if (alps_passthrough_mode_v3(psmouse
, reg_base
, false))
2093 static int alps_hw_init_v3(struct psmouse
*psmouse
)
2095 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2097 unsigned char param
[4];
2099 reg_val
= alps_probe_trackstick_v3(psmouse
, ALPS_REG_BASE_PINNACLE
);
2100 if (reg_val
== -EIO
)
2104 alps_setup_trackstick_v3(psmouse
, ALPS_REG_BASE_PINNACLE
) == -EIO
)
2107 if (alps_enter_command_mode(psmouse
) ||
2108 alps_absolute_mode_v3(psmouse
)) {
2109 psmouse_err(psmouse
, "Failed to enter absolute mode\n");
2113 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0006);
2116 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x01))
2119 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0007);
2122 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x01))
2125 if (alps_command_mode_read_reg(psmouse
, 0x0144) == -1)
2127 if (__alps_command_mode_write_reg(psmouse
, 0x04))
2130 if (alps_command_mode_read_reg(psmouse
, 0x0159) == -1)
2132 if (__alps_command_mode_write_reg(psmouse
, 0x03))
2135 if (alps_command_mode_read_reg(psmouse
, 0x0163) == -1)
2137 if (alps_command_mode_write_reg(psmouse
, 0x0163, 0x03))
2140 if (alps_command_mode_read_reg(psmouse
, 0x0162) == -1)
2142 if (alps_command_mode_write_reg(psmouse
, 0x0162, 0x04))
2145 alps_exit_command_mode(psmouse
);
2147 /* Set rate and enable data reporting */
2149 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
) ||
2150 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
)) {
2151 psmouse_err(psmouse
, "Failed to enable data reporting\n");
2159 * Leaving the touchpad in command mode will essentially render
2160 * it unusable until the machine reboots, so exit it here just
2163 alps_exit_command_mode(psmouse
);
2167 static int alps_get_v3_v7_resolution(struct psmouse
*psmouse
, int reg_pitch
)
2169 int reg
, x_pitch
, y_pitch
, x_electrode
, y_electrode
, x_phys
, y_phys
;
2170 struct alps_data
*priv
= psmouse
->private;
2172 reg
= alps_command_mode_read_reg(psmouse
, reg_pitch
);
2176 x_pitch
= (char)(reg
<< 4) >> 4; /* sign extend lower 4 bits */
2177 x_pitch
= 50 + 2 * x_pitch
; /* In 0.1 mm units */
2179 y_pitch
= (char)reg
>> 4; /* sign extend upper 4 bits */
2180 y_pitch
= 36 + 2 * y_pitch
; /* In 0.1 mm units */
2182 reg
= alps_command_mode_read_reg(psmouse
, reg_pitch
+ 1);
2186 x_electrode
= (char)(reg
<< 4) >> 4; /* sign extend lower 4 bits */
2187 x_electrode
= 17 + x_electrode
;
2189 y_electrode
= (char)reg
>> 4; /* sign extend upper 4 bits */
2190 y_electrode
= 13 + y_electrode
;
2192 x_phys
= x_pitch
* (x_electrode
- 1); /* In 0.1 mm units */
2193 y_phys
= y_pitch
* (y_electrode
- 1); /* In 0.1 mm units */
2195 priv
->x_res
= priv
->x_max
* 10 / x_phys
; /* units / mm */
2196 priv
->y_res
= priv
->y_max
* 10 / y_phys
; /* units / mm */
2198 psmouse_dbg(psmouse
,
2199 "pitch %dx%d num-electrodes %dx%d physical size %dx%d mm res %dx%d\n",
2200 x_pitch
, y_pitch
, x_electrode
, y_electrode
,
2201 x_phys
/ 10, y_phys
/ 10, priv
->x_res
, priv
->y_res
);
2206 static int alps_hw_init_rushmore_v3(struct psmouse
*psmouse
)
2208 struct alps_data
*priv
= psmouse
->private;
2209 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2210 int reg_val
, ret
= -1;
2212 if (priv
->flags
& ALPS_DUALPOINT
) {
2213 reg_val
= alps_setup_trackstick_v3(psmouse
,
2214 ALPS_REG_BASE_RUSHMORE
);
2215 if (reg_val
== -EIO
)
2219 if (alps_enter_command_mode(psmouse
) ||
2220 alps_command_mode_read_reg(psmouse
, 0xc2d9) == -1 ||
2221 alps_command_mode_write_reg(psmouse
, 0xc2cb, 0x00))
2224 if (alps_get_v3_v7_resolution(psmouse
, 0xc2da))
2227 reg_val
= alps_command_mode_read_reg(psmouse
, 0xc2c6);
2230 if (__alps_command_mode_write_reg(psmouse
, reg_val
& 0xfd))
2233 if (alps_command_mode_write_reg(psmouse
, 0xc2c9, 0x64))
2236 /* enter absolute mode */
2237 reg_val
= alps_command_mode_read_reg(psmouse
, 0xc2c4);
2240 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x02))
2243 alps_exit_command_mode(psmouse
);
2244 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2247 alps_exit_command_mode(psmouse
);
2251 /* Must be in command mode when calling this function */
2252 static int alps_absolute_mode_v4(struct psmouse
*psmouse
)
2256 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0004);
2261 if (__alps_command_mode_write_reg(psmouse
, reg_val
))
2267 static int alps_hw_init_v4(struct psmouse
*psmouse
)
2269 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2270 unsigned char param
[4];
2272 if (alps_enter_command_mode(psmouse
))
2275 if (alps_absolute_mode_v4(psmouse
)) {
2276 psmouse_err(psmouse
, "Failed to enter absolute mode\n");
2280 if (alps_command_mode_write_reg(psmouse
, 0x0007, 0x8c))
2283 if (alps_command_mode_write_reg(psmouse
, 0x0149, 0x03))
2286 if (alps_command_mode_write_reg(psmouse
, 0x0160, 0x03))
2289 if (alps_command_mode_write_reg(psmouse
, 0x017f, 0x15))
2292 if (alps_command_mode_write_reg(psmouse
, 0x0151, 0x01))
2295 if (alps_command_mode_write_reg(psmouse
, 0x0168, 0x03))
2298 if (alps_command_mode_write_reg(psmouse
, 0x014a, 0x03))
2301 if (alps_command_mode_write_reg(psmouse
, 0x0161, 0x03))
2304 alps_exit_command_mode(psmouse
);
2307 * This sequence changes the output from a 9-byte to an
2308 * 8-byte format. All the same data seems to be present,
2309 * just in a more compact format.
2314 if (ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2315 ps2_command(ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
) ||
2316 ps2_command(ps2dev
, ¶m
[2], PSMOUSE_CMD_SETRATE
) ||
2317 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
))
2320 /* Set rate and enable data reporting */
2322 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
) ||
2323 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
)) {
2324 psmouse_err(psmouse
, "Failed to enable data reporting\n");
2332 * Leaving the touchpad in command mode will essentially render
2333 * it unusable until the machine reboots, so exit it here just
2336 alps_exit_command_mode(psmouse
);
2340 static int alps_get_otp_values_ss4_v2(struct psmouse
*psmouse
,
2341 unsigned char index
, unsigned char otp
[])
2343 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2347 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2348 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2349 ps2_command(ps2dev
, otp
, PSMOUSE_CMD_GETINFO
))
2355 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2356 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2357 ps2_command(ps2dev
, otp
, PSMOUSE_CMD_GETINFO
))
2366 static int alps_update_device_area_ss4_v2(unsigned char otp
[][4],
2367 struct alps_data
*priv
)
2369 int num_x_electrode
;
2370 int num_y_electrode
;
2371 int x_pitch
, y_pitch
, x_phys
, y_phys
;
2373 num_x_electrode
= SS4_NUMSENSOR_XOFFSET
+ (otp
[1][0] & 0x0F);
2374 num_y_electrode
= SS4_NUMSENSOR_YOFFSET
+ ((otp
[1][0] >> 4) & 0x0F);
2376 priv
->x_max
= (num_x_electrode
- 1) * SS4_COUNT_PER_ELECTRODE
;
2377 priv
->y_max
= (num_y_electrode
- 1) * SS4_COUNT_PER_ELECTRODE
;
2379 x_pitch
= ((otp
[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM
;
2380 y_pitch
= ((otp
[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM
;
2382 x_phys
= x_pitch
* (num_x_electrode
- 1); /* In 0.1 mm units */
2383 y_phys
= y_pitch
* (num_y_electrode
- 1); /* In 0.1 mm units */
2385 priv
->x_res
= priv
->x_max
* 10 / x_phys
; /* units / mm */
2386 priv
->y_res
= priv
->y_max
* 10 / y_phys
; /* units / mm */
2391 static int alps_update_btn_info_ss4_v2(unsigned char otp
[][4],
2392 struct alps_data
*priv
)
2394 unsigned char is_btnless
;
2396 is_btnless
= (otp
[1][1] >> 3) & 0x01;
2399 priv
->flags
|= ALPS_BUTTONPAD
;
2404 static int alps_set_defaults_ss4_v2(struct psmouse
*psmouse
,
2405 struct alps_data
*priv
)
2407 unsigned char otp
[2][4];
2409 memset(otp
, 0, sizeof(otp
));
2411 if (alps_get_otp_values_ss4_v2(psmouse
, 0, &otp
[0][0]) ||
2412 alps_get_otp_values_ss4_v2(psmouse
, 1, &otp
[1][0]))
2415 alps_update_device_area_ss4_v2(otp
, priv
);
2417 alps_update_btn_info_ss4_v2(otp
, priv
);
2422 static int alps_dolphin_get_device_area(struct psmouse
*psmouse
,
2423 struct alps_data
*priv
)
2425 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2426 unsigned char param
[4] = {0};
2427 int num_x_electrode
, num_y_electrode
;
2429 if (alps_enter_command_mode(psmouse
))
2433 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_WRAP
) ||
2434 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2435 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2436 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2437 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
))
2440 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
2444 * Dolphin's sensor line number is not fixed. It can be calculated
2445 * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET.
2446 * Further more, we can get device's x_max and y_max by multiplying
2447 * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE.
2449 * e.g. When we get register's sensor_x = 11 & sensor_y = 8,
2450 * real sensor line number X = 11 + 8 = 19, and
2451 * real sensor line number Y = 8 + 1 = 9.
2452 * So, x_max = (19 - 1) * 64 = 1152, and
2453 * y_max = (9 - 1) * 64 = 512.
2455 num_x_electrode
= DOLPHIN_PROFILE_XOFFSET
+ (param
[2] & 0x0F);
2456 num_y_electrode
= DOLPHIN_PROFILE_YOFFSET
+ ((param
[2] >> 4) & 0x0F);
2457 priv
->x_bits
= num_x_electrode
;
2458 priv
->y_bits
= num_y_electrode
;
2459 priv
->x_max
= (num_x_electrode
- 1) * DOLPHIN_COUNT_PER_ELECTRODE
;
2460 priv
->y_max
= (num_y_electrode
- 1) * DOLPHIN_COUNT_PER_ELECTRODE
;
2462 if (alps_exit_command_mode(psmouse
))
2468 static int alps_hw_init_dolphin_v1(struct psmouse
*psmouse
)
2470 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2471 unsigned char param
[2];
2473 /* This is dolphin "v1" as empirically defined by florin9doi */
2477 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2478 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2479 ps2_command(ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
))
2485 static int alps_hw_init_v7(struct psmouse
*psmouse
)
2487 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2488 int reg_val
, ret
= -1;
2490 if (alps_enter_command_mode(psmouse
) ||
2491 alps_command_mode_read_reg(psmouse
, 0xc2d9) == -1)
2494 if (alps_get_v3_v7_resolution(psmouse
, 0xc397))
2497 if (alps_command_mode_write_reg(psmouse
, 0xc2c9, 0x64))
2500 reg_val
= alps_command_mode_read_reg(psmouse
, 0xc2c4);
2503 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x02))
2506 alps_exit_command_mode(psmouse
);
2507 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2510 alps_exit_command_mode(psmouse
);
2514 static int alps_hw_init_ss4_v2(struct psmouse
*psmouse
)
2516 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2517 char param
[2] = {0x64, 0x28};
2520 /* enter absolute mode */
2521 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2522 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2523 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2524 ps2_command(ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
)) {
2528 /* T.B.D. Decread noise packet number, delete in the future */
2529 if (alps_exit_command_mode(psmouse
) ||
2530 alps_enter_command_mode(psmouse
) ||
2531 alps_command_mode_write_reg(psmouse
, 0x001D, 0x20)) {
2534 alps_exit_command_mode(psmouse
);
2536 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2539 alps_exit_command_mode(psmouse
);
2543 static int alps_set_protocol(struct psmouse
*psmouse
,
2544 struct alps_data
*priv
,
2545 const struct alps_protocol_info
*protocol
)
2547 psmouse
->private = priv
;
2549 setup_timer(&priv
->timer
, alps_flush_packet
, (unsigned long)psmouse
);
2551 priv
->proto_version
= protocol
->version
;
2552 priv
->byte0
= protocol
->byte0
;
2553 priv
->mask0
= protocol
->mask0
;
2554 priv
->flags
= protocol
->flags
;
2555 if (dmi_name_in_vendors("Dell"))
2556 priv
->flags
|= ALPS_DELL
;
2563 switch (priv
->proto_version
) {
2566 priv
->hw_init
= alps_hw_init_v1_v2
;
2567 priv
->process_packet
= alps_process_packet_v1_v2
;
2568 priv
->set_abs_params
= alps_set_abs_params_st
;
2574 priv
->hw_init
= alps_hw_init_v3
;
2575 priv
->process_packet
= alps_process_packet_v3
;
2576 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2577 priv
->decode_fields
= alps_decode_pinnacle
;
2578 priv
->nibble_commands
= alps_v3_nibble_commands
;
2579 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2582 case ALPS_PROTO_V3_RUSHMORE
:
2583 priv
->hw_init
= alps_hw_init_rushmore_v3
;
2584 priv
->process_packet
= alps_process_packet_v3
;
2585 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2586 priv
->decode_fields
= alps_decode_rushmore
;
2587 priv
->nibble_commands
= alps_v3_nibble_commands
;
2588 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2592 if (alps_probe_trackstick_v3(psmouse
,
2593 ALPS_REG_BASE_RUSHMORE
) < 0)
2594 priv
->flags
&= ~ALPS_DUALPOINT
;
2599 priv
->hw_init
= alps_hw_init_v4
;
2600 priv
->process_packet
= alps_process_packet_v4
;
2601 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2602 priv
->nibble_commands
= alps_v4_nibble_commands
;
2603 priv
->addr_command
= PSMOUSE_CMD_DISABLE
;
2607 priv
->hw_init
= alps_hw_init_dolphin_v1
;
2608 priv
->process_packet
= alps_process_touchpad_packet_v3_v5
;
2609 priv
->decode_fields
= alps_decode_dolphin
;
2610 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2611 priv
->nibble_commands
= alps_v3_nibble_commands
;
2612 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2616 if (alps_dolphin_get_device_area(psmouse
, priv
))
2622 priv
->hw_init
= alps_hw_init_v6
;
2623 priv
->process_packet
= alps_process_packet_v6
;
2624 priv
->set_abs_params
= alps_set_abs_params_st
;
2625 priv
->nibble_commands
= alps_v6_nibble_commands
;
2631 priv
->hw_init
= alps_hw_init_v7
;
2632 priv
->process_packet
= alps_process_packet_v7
;
2633 priv
->decode_fields
= alps_decode_packet_v7
;
2634 priv
->set_abs_params
= alps_set_abs_params_v7
;
2635 priv
->nibble_commands
= alps_v3_nibble_commands
;
2636 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2637 priv
->x_max
= 0xfff;
2638 priv
->y_max
= 0x7ff;
2640 if (priv
->fw_ver
[1] != 0xba)
2641 priv
->flags
|= ALPS_BUTTONPAD
;
2646 priv
->hw_init
= alps_hw_init_ss4_v2
;
2647 priv
->process_packet
= alps_process_packet_ss4_v2
;
2648 priv
->decode_fields
= alps_decode_ss4_v2
;
2649 priv
->set_abs_params
= alps_set_abs_params_ss4_v2
;
2650 priv
->nibble_commands
= alps_v3_nibble_commands
;
2651 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2653 if (alps_set_defaults_ss4_v2(psmouse
, priv
))
2662 static const struct alps_protocol_info
*alps_match_table(unsigned char *e7
,
2665 const struct alps_model_info
*model
;
2668 for (i
= 0; i
< ARRAY_SIZE(alps_model_data
); i
++) {
2669 model
= &alps_model_data
[i
];
2671 if (!memcmp(e7
, model
->signature
, sizeof(model
->signature
)) &&
2672 (!model
->command_mode_resp
||
2673 model
->command_mode_resp
== ec
[2])) {
2675 return &model
->protocol_info
;
2682 static int alps_identify(struct psmouse
*psmouse
, struct alps_data
*priv
)
2684 const struct alps_protocol_info
*protocol
;
2685 unsigned char e6
[4], e7
[4], ec
[4];
2689 * First try "E6 report".
2690 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
2691 * The bits 0-2 of the first byte will be 1s if some buttons are
2694 if (alps_rpt_cmd(psmouse
, PSMOUSE_CMD_SETRES
,
2695 PSMOUSE_CMD_SETSCALE11
, e6
))
2698 if ((e6
[0] & 0xf8) != 0 || e6
[1] != 0 || (e6
[2] != 10 && e6
[2] != 100))
2702 * Now get the "E7" and "EC" reports. These will uniquely identify
2703 * most ALPS touchpads.
2705 if (alps_rpt_cmd(psmouse
, PSMOUSE_CMD_SETRES
,
2706 PSMOUSE_CMD_SETSCALE21
, e7
) ||
2707 alps_rpt_cmd(psmouse
, PSMOUSE_CMD_SETRES
,
2708 PSMOUSE_CMD_RESET_WRAP
, ec
) ||
2709 alps_exit_command_mode(psmouse
))
2712 protocol
= alps_match_table(e7
, ec
);
2714 if (e7
[0] == 0x73 && e7
[1] == 0x03 && e7
[2] == 0x50 &&
2715 ec
[0] == 0x73 && (ec
[1] == 0x01 || ec
[1] == 0x02)) {
2716 protocol
= &alps_v5_protocol_data
;
2717 } else if (ec
[0] == 0x88 &&
2718 ((ec
[1] & 0xf0) == 0xb0 || (ec
[1] & 0xf0) == 0xc0)) {
2719 protocol
= &alps_v7_protocol_data
;
2720 } else if (ec
[0] == 0x88 && ec
[1] == 0x08) {
2721 protocol
= &alps_v3_rushmore_data
;
2722 } else if (ec
[0] == 0x88 && ec
[1] == 0x07 &&
2723 ec
[2] >= 0x90 && ec
[2] <= 0x9d) {
2724 protocol
= &alps_v3_protocol_data
;
2725 } else if (e7
[0] == 0x73 && e7
[1] == 0x03 &&
2726 e7
[2] == 0x14 && ec
[1] == 0x02) {
2727 protocol
= &alps_v8_protocol_data
;
2729 psmouse_dbg(psmouse
,
2730 "Likely not an ALPS touchpad: E7=%3ph, EC=%3ph\n", e7
, ec
);
2736 /* Save the Firmware version */
2737 memcpy(priv
->fw_ver
, ec
, 3);
2738 error
= alps_set_protocol(psmouse
, priv
, protocol
);
2746 static int alps_reconnect(struct psmouse
*psmouse
)
2748 struct alps_data
*priv
= psmouse
->private;
2750 psmouse_reset(psmouse
);
2752 if (alps_identify(psmouse
, priv
) < 0)
2755 return priv
->hw_init(psmouse
);
2758 static void alps_disconnect(struct psmouse
*psmouse
)
2760 struct alps_data
*priv
= psmouse
->private;
2762 psmouse_reset(psmouse
);
2763 del_timer_sync(&priv
->timer
);
2765 input_unregister_device(priv
->dev2
);
2766 if (!IS_ERR_OR_NULL(priv
->dev3
))
2767 input_unregister_device(priv
->dev3
);
2771 static void alps_set_abs_params_st(struct alps_data
*priv
,
2772 struct input_dev
*dev1
)
2774 input_set_abs_params(dev1
, ABS_X
, 0, priv
->x_max
, 0, 0);
2775 input_set_abs_params(dev1
, ABS_Y
, 0, priv
->y_max
, 0, 0);
2776 input_set_abs_params(dev1
, ABS_PRESSURE
, 0, 127, 0, 0);
2779 static void alps_set_abs_params_mt_common(struct alps_data
*priv
,
2780 struct input_dev
*dev1
)
2782 input_set_abs_params(dev1
, ABS_MT_POSITION_X
, 0, priv
->x_max
, 0, 0);
2783 input_set_abs_params(dev1
, ABS_MT_POSITION_Y
, 0, priv
->y_max
, 0, 0);
2785 input_abs_set_res(dev1
, ABS_MT_POSITION_X
, priv
->x_res
);
2786 input_abs_set_res(dev1
, ABS_MT_POSITION_Y
, priv
->y_res
);
2788 set_bit(BTN_TOOL_TRIPLETAP
, dev1
->keybit
);
2789 set_bit(BTN_TOOL_QUADTAP
, dev1
->keybit
);
2792 static void alps_set_abs_params_semi_mt(struct alps_data
*priv
,
2793 struct input_dev
*dev1
)
2795 alps_set_abs_params_mt_common(priv
, dev1
);
2796 input_set_abs_params(dev1
, ABS_PRESSURE
, 0, 127, 0, 0);
2798 input_mt_init_slots(dev1
, MAX_TOUCHES
,
2799 INPUT_MT_POINTER
| INPUT_MT_DROP_UNUSED
|
2803 static void alps_set_abs_params_v7(struct alps_data
*priv
,
2804 struct input_dev
*dev1
)
2806 alps_set_abs_params_mt_common(priv
, dev1
);
2807 set_bit(BTN_TOOL_QUINTTAP
, dev1
->keybit
);
2809 input_mt_init_slots(dev1
, MAX_TOUCHES
,
2810 INPUT_MT_POINTER
| INPUT_MT_DROP_UNUSED
|
2813 set_bit(BTN_TOOL_QUINTTAP
, dev1
->keybit
);
2816 static void alps_set_abs_params_ss4_v2(struct alps_data
*priv
,
2817 struct input_dev
*dev1
)
2819 alps_set_abs_params_mt_common(priv
, dev1
);
2820 input_set_abs_params(dev1
, ABS_PRESSURE
, 0, 127, 0, 0);
2821 set_bit(BTN_TOOL_QUINTTAP
, dev1
->keybit
);
2823 input_mt_init_slots(dev1
, MAX_TOUCHES
,
2824 INPUT_MT_POINTER
| INPUT_MT_DROP_UNUSED
|
2828 int alps_init(struct psmouse
*psmouse
)
2830 struct alps_data
*priv
= psmouse
->private;
2831 struct input_dev
*dev1
= psmouse
->dev
;
2834 error
= priv
->hw_init(psmouse
);
2839 * Undo part of setup done for us by psmouse core since touchpad
2840 * is not a relative device.
2842 __clear_bit(EV_REL
, dev1
->evbit
);
2843 __clear_bit(REL_X
, dev1
->relbit
);
2844 __clear_bit(REL_Y
, dev1
->relbit
);
2847 * Now set up our capabilities.
2849 dev1
->evbit
[BIT_WORD(EV_KEY
)] |= BIT_MASK(EV_KEY
);
2850 dev1
->keybit
[BIT_WORD(BTN_TOUCH
)] |= BIT_MASK(BTN_TOUCH
);
2851 dev1
->keybit
[BIT_WORD(BTN_TOOL_FINGER
)] |= BIT_MASK(BTN_TOOL_FINGER
);
2852 dev1
->keybit
[BIT_WORD(BTN_LEFT
)] |=
2853 BIT_MASK(BTN_LEFT
) | BIT_MASK(BTN_RIGHT
);
2855 dev1
->evbit
[BIT_WORD(EV_ABS
)] |= BIT_MASK(EV_ABS
);
2857 priv
->set_abs_params(priv
, dev1
);
2859 if (priv
->flags
& ALPS_WHEEL
) {
2860 dev1
->evbit
[BIT_WORD(EV_REL
)] |= BIT_MASK(EV_REL
);
2861 dev1
->relbit
[BIT_WORD(REL_WHEEL
)] |= BIT_MASK(REL_WHEEL
);
2864 if (priv
->flags
& (ALPS_FW_BK_1
| ALPS_FW_BK_2
)) {
2865 dev1
->keybit
[BIT_WORD(BTN_FORWARD
)] |= BIT_MASK(BTN_FORWARD
);
2866 dev1
->keybit
[BIT_WORD(BTN_BACK
)] |= BIT_MASK(BTN_BACK
);
2869 if (priv
->flags
& ALPS_FOUR_BUTTONS
) {
2870 dev1
->keybit
[BIT_WORD(BTN_0
)] |= BIT_MASK(BTN_0
);
2871 dev1
->keybit
[BIT_WORD(BTN_1
)] |= BIT_MASK(BTN_1
);
2872 dev1
->keybit
[BIT_WORD(BTN_2
)] |= BIT_MASK(BTN_2
);
2873 dev1
->keybit
[BIT_WORD(BTN_3
)] |= BIT_MASK(BTN_3
);
2874 } else if (priv
->flags
& ALPS_BUTTONPAD
) {
2875 set_bit(INPUT_PROP_BUTTONPAD
, dev1
->propbit
);
2876 clear_bit(BTN_RIGHT
, dev1
->keybit
);
2878 dev1
->keybit
[BIT_WORD(BTN_MIDDLE
)] |= BIT_MASK(BTN_MIDDLE
);
2881 if (priv
->flags
& ALPS_DUALPOINT
) {
2882 struct input_dev
*dev2
;
2884 dev2
= input_allocate_device();
2886 psmouse_err(psmouse
,
2887 "failed to allocate trackstick device\n");
2892 snprintf(priv
->phys2
, sizeof(priv
->phys2
), "%s/input1",
2893 psmouse
->ps2dev
.serio
->phys
);
2894 dev2
->phys
= priv
->phys2
;
2897 * format of input device name is: "protocol vendor name"
2898 * see function psmouse_switch_protocol() in psmouse-base.c
2900 dev2
->name
= "AlpsPS/2 ALPS DualPoint Stick";
2902 dev2
->id
.bustype
= BUS_I8042
;
2903 dev2
->id
.vendor
= 0x0002;
2904 dev2
->id
.product
= PSMOUSE_ALPS
;
2905 dev2
->id
.version
= priv
->proto_version
;
2906 dev2
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
2908 input_set_capability(dev2
, EV_REL
, REL_X
);
2909 input_set_capability(dev2
, EV_REL
, REL_Y
);
2910 input_set_capability(dev2
, EV_KEY
, BTN_LEFT
);
2911 input_set_capability(dev2
, EV_KEY
, BTN_RIGHT
);
2912 input_set_capability(dev2
, EV_KEY
, BTN_MIDDLE
);
2914 __set_bit(INPUT_PROP_POINTER
, dev2
->propbit
);
2915 __set_bit(INPUT_PROP_POINTING_STICK
, dev2
->propbit
);
2917 error
= input_register_device(dev2
);
2919 psmouse_err(psmouse
,
2920 "failed to register trackstick device: %d\n",
2922 input_free_device(dev2
);
2929 priv
->psmouse
= psmouse
;
2931 INIT_DELAYED_WORK(&priv
->dev3_register_work
,
2932 alps_register_bare_ps2_mouse
);
2934 psmouse
->protocol_handler
= alps_process_byte
;
2935 psmouse
->poll
= alps_poll
;
2936 psmouse
->disconnect
= alps_disconnect
;
2937 psmouse
->reconnect
= alps_reconnect
;
2938 psmouse
->pktsize
= priv
->proto_version
== ALPS_PROTO_V4
? 8 : 6;
2940 /* We are having trouble resyncing ALPS touchpads so disable it for now */
2941 psmouse
->resync_time
= 0;
2943 /* Allow 2 invalid packets without resetting device */
2944 psmouse
->resetafter
= psmouse
->pktsize
* 2;
2949 psmouse_reset(psmouse
);
2951 * Even though we did not allocate psmouse->private we do free
2954 kfree(psmouse
->private);
2955 psmouse
->private = NULL
;
2959 int alps_detect(struct psmouse
*psmouse
, bool set_properties
)
2961 struct alps_data
*priv
;
2964 error
= alps_identify(psmouse
, NULL
);
2969 * Reset the device to make sure it is fully operational:
2970 * on some laptops, like certain Dell Latitudes, we may
2971 * fail to properly detect presence of trackstick if device
2972 * has not been reset.
2974 psmouse_reset(psmouse
);
2976 priv
= kzalloc(sizeof(struct alps_data
), GFP_KERNEL
);
2980 error
= alps_identify(psmouse
, priv
);
2986 if (set_properties
) {
2987 psmouse
->vendor
= "ALPS";
2988 psmouse
->name
= priv
->flags
& ALPS_DUALPOINT
?
2989 "DualPoint TouchPad" : "GlidePoint";
2990 psmouse
->model
= priv
->proto_version
;
2993 * Destroy alps_data structure we allocated earlier since
2994 * this was just a "trial run". Otherwise we'll keep it
2995 * to be used by alps_init() which has to be called if
2996 * we succeed and set_properties is true.
2999 psmouse
->private = NULL
;