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_V7 0xc2c0
35 #define ALPS_REG_BASE_PINNACLE 0x0000
37 static const struct alps_nibble_commands alps_v3_nibble_commands
[] = {
38 { PSMOUSE_CMD_SETPOLL
, 0x00 }, /* 0 */
39 { PSMOUSE_CMD_RESET_DIS
, 0x00 }, /* 1 */
40 { PSMOUSE_CMD_SETSCALE21
, 0x00 }, /* 2 */
41 { PSMOUSE_CMD_SETRATE
, 0x0a }, /* 3 */
42 { PSMOUSE_CMD_SETRATE
, 0x14 }, /* 4 */
43 { PSMOUSE_CMD_SETRATE
, 0x28 }, /* 5 */
44 { PSMOUSE_CMD_SETRATE
, 0x3c }, /* 6 */
45 { PSMOUSE_CMD_SETRATE
, 0x50 }, /* 7 */
46 { PSMOUSE_CMD_SETRATE
, 0x64 }, /* 8 */
47 { PSMOUSE_CMD_SETRATE
, 0xc8 }, /* 9 */
48 { ALPS_CMD_NIBBLE_10
, 0x00 }, /* a */
49 { PSMOUSE_CMD_SETRES
, 0x00 }, /* b */
50 { PSMOUSE_CMD_SETRES
, 0x01 }, /* c */
51 { PSMOUSE_CMD_SETRES
, 0x02 }, /* d */
52 { PSMOUSE_CMD_SETRES
, 0x03 }, /* e */
53 { PSMOUSE_CMD_SETSCALE11
, 0x00 }, /* f */
56 static const struct alps_nibble_commands alps_v4_nibble_commands
[] = {
57 { PSMOUSE_CMD_ENABLE
, 0x00 }, /* 0 */
58 { PSMOUSE_CMD_RESET_DIS
, 0x00 }, /* 1 */
59 { PSMOUSE_CMD_SETSCALE21
, 0x00 }, /* 2 */
60 { PSMOUSE_CMD_SETRATE
, 0x0a }, /* 3 */
61 { PSMOUSE_CMD_SETRATE
, 0x14 }, /* 4 */
62 { PSMOUSE_CMD_SETRATE
, 0x28 }, /* 5 */
63 { PSMOUSE_CMD_SETRATE
, 0x3c }, /* 6 */
64 { PSMOUSE_CMD_SETRATE
, 0x50 }, /* 7 */
65 { PSMOUSE_CMD_SETRATE
, 0x64 }, /* 8 */
66 { PSMOUSE_CMD_SETRATE
, 0xc8 }, /* 9 */
67 { ALPS_CMD_NIBBLE_10
, 0x00 }, /* a */
68 { PSMOUSE_CMD_SETRES
, 0x00 }, /* b */
69 { PSMOUSE_CMD_SETRES
, 0x01 }, /* c */
70 { PSMOUSE_CMD_SETRES
, 0x02 }, /* d */
71 { PSMOUSE_CMD_SETRES
, 0x03 }, /* e */
72 { PSMOUSE_CMD_SETSCALE11
, 0x00 }, /* f */
75 static const struct alps_nibble_commands alps_v6_nibble_commands
[] = {
76 { PSMOUSE_CMD_ENABLE
, 0x00 }, /* 0 */
77 { PSMOUSE_CMD_SETRATE
, 0x0a }, /* 1 */
78 { PSMOUSE_CMD_SETRATE
, 0x14 }, /* 2 */
79 { PSMOUSE_CMD_SETRATE
, 0x28 }, /* 3 */
80 { PSMOUSE_CMD_SETRATE
, 0x3c }, /* 4 */
81 { PSMOUSE_CMD_SETRATE
, 0x50 }, /* 5 */
82 { PSMOUSE_CMD_SETRATE
, 0x64 }, /* 6 */
83 { PSMOUSE_CMD_SETRATE
, 0xc8 }, /* 7 */
84 { PSMOUSE_CMD_GETID
, 0x00 }, /* 8 */
85 { PSMOUSE_CMD_GETINFO
, 0x00 }, /* 9 */
86 { PSMOUSE_CMD_SETRES
, 0x00 }, /* a */
87 { PSMOUSE_CMD_SETRES
, 0x01 }, /* b */
88 { PSMOUSE_CMD_SETRES
, 0x02 }, /* c */
89 { PSMOUSE_CMD_SETRES
, 0x03 }, /* d */
90 { PSMOUSE_CMD_SETSCALE21
, 0x00 }, /* e */
91 { PSMOUSE_CMD_SETSCALE11
, 0x00 }, /* f */
95 #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
96 #define ALPS_PASS 0x04 /* device has a pass-through port */
98 #define ALPS_WHEEL 0x08 /* hardware wheel present */
99 #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
100 #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
101 #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
102 #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
103 6-byte ALPS packet */
104 #define ALPS_STICK_BITS 0x100 /* separate stick button bits */
105 #define ALPS_BUTTONPAD 0x200 /* device is a clickpad */
106 #define ALPS_DUALPOINT_WITH_PRESSURE 0x400 /* device can report trackpoint pressure */
108 static const struct alps_model_info alps_model_data
[] = {
110 * XXX This entry is suspicious. First byte has zero lower nibble,
111 * which is what a normal mouse would report. Also, the value 0x0e
112 * isn't valid per PS/2 spec.
114 { { 0x20, 0x02, 0x0e }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} },
116 { { 0x22, 0x02, 0x0a }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} },
117 { { 0x22, 0x02, 0x14 }, { ALPS_PROTO_V2
, 0xff, 0xff, ALPS_PASS
| ALPS_DUALPOINT
} }, /* Dell Latitude D600 */
118 { { 0x32, 0x02, 0x14 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} }, /* Toshiba Salellite Pro M10 */
119 { { 0x33, 0x02, 0x0a }, { ALPS_PROTO_V1
, 0x88, 0xf8, 0 } }, /* UMAX-530T */
120 { { 0x52, 0x01, 0x14 }, { ALPS_PROTO_V2
, 0xff, 0xff,
121 ALPS_PASS
| ALPS_DUALPOINT
| ALPS_PS2_INTERLEAVED
} }, /* Toshiba Tecra A11-11L */
122 { { 0x53, 0x02, 0x0a }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
123 { { 0x53, 0x02, 0x14 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
124 { { 0x60, 0x03, 0xc8 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } }, /* HP ze1115 */
125 { { 0x62, 0x02, 0x14 }, { ALPS_PROTO_V2
, 0xcf, 0xcf,
126 ALPS_PASS
| ALPS_DUALPOINT
| ALPS_PS2_INTERLEAVED
} }, /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
127 { { 0x63, 0x02, 0x0a }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
128 { { 0x63, 0x02, 0x14 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
129 { { 0x63, 0x02, 0x28 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_FW_BK_2
} }, /* Fujitsu Siemens S6010 */
130 { { 0x63, 0x02, 0x3c }, { ALPS_PROTO_V2
, 0x8f, 0x8f, ALPS_WHEEL
} }, /* Toshiba Satellite S2400-103 */
131 { { 0x63, 0x02, 0x50 }, { ALPS_PROTO_V2
, 0xef, 0xef, ALPS_FW_BK_1
} }, /* NEC Versa L320 */
132 { { 0x63, 0x02, 0x64 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
133 { { 0x63, 0x03, 0xc8 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_PASS
| ALPS_DUALPOINT
} }, /* Dell Latitude D800 */
134 { { 0x73, 0x00, 0x0a }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_DUALPOINT
} }, /* ThinkPad R61 8918-5QG */
135 { { 0x73, 0x00, 0x14 }, { ALPS_PROTO_V6
, 0xff, 0xff, ALPS_DUALPOINT
} }, /* Dell XT2 */
136 { { 0x73, 0x02, 0x0a }, { ALPS_PROTO_V2
, 0xf8, 0xf8, 0 } },
137 { { 0x73, 0x02, 0x14 }, { ALPS_PROTO_V2
, 0xf8, 0xf8, ALPS_FW_BK_2
} }, /* Ahtec Laptop */
138 { { 0x73, 0x02, 0x50 }, { ALPS_PROTO_V2
, 0xcf, 0xcf, ALPS_FOUR_BUTTONS
} }, /* Dell Vostro 1400 */
141 static const struct alps_protocol_info alps_v3_protocol_data
= {
142 ALPS_PROTO_V3
, 0x8f, 0x8f, ALPS_DUALPOINT
| ALPS_DUALPOINT_WITH_PRESSURE
145 static const struct alps_protocol_info alps_v3_rushmore_data
= {
146 ALPS_PROTO_V3_RUSHMORE
, 0x8f, 0x8f, ALPS_DUALPOINT
| ALPS_DUALPOINT_WITH_PRESSURE
149 static const struct alps_protocol_info alps_v4_protocol_data
= {
150 ALPS_PROTO_V4
, 0x8f, 0x8f, 0
153 static const struct alps_protocol_info alps_v5_protocol_data
= {
154 ALPS_PROTO_V5
, 0xc8, 0xd8, 0
157 static const struct alps_protocol_info alps_v7_protocol_data
= {
158 ALPS_PROTO_V7
, 0x48, 0x48, ALPS_DUALPOINT
| ALPS_DUALPOINT_WITH_PRESSURE
161 static const struct alps_protocol_info alps_v8_protocol_data
= {
162 ALPS_PROTO_V8
, 0x18, 0x18, 0
165 static const struct alps_protocol_info alps_v9_protocol_data
= {
166 ALPS_PROTO_V9
, 0xc8, 0xc8, 0
170 * Some v2 models report the stick buttons in separate bits
172 static const struct dmi_system_id alps_dmi_has_separate_stick_buttons
[] = {
173 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
175 /* Extrapolated from other entries */
177 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
178 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude D420"),
182 /* Reported-by: Hans de Bruin <jmdebruin@xmsnet.nl> */
184 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
185 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude D430"),
189 /* Reported-by: Hans de Goede <hdegoede@redhat.com> */
191 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
192 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude D620"),
196 /* Extrapolated from other entries */
198 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
199 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude D630"),
206 static void alps_set_abs_params_st(struct alps_data
*priv
,
207 struct input_dev
*dev1
);
208 static void alps_set_abs_params_semi_mt(struct alps_data
*priv
,
209 struct input_dev
*dev1
);
210 static void alps_set_abs_params_v7(struct alps_data
*priv
,
211 struct input_dev
*dev1
);
212 static void alps_set_abs_params_ss4_v2(struct alps_data
*priv
,
213 struct input_dev
*dev1
);
215 /* Packet formats are described in Documentation/input/devices/alps.rst */
217 static bool alps_is_valid_first_byte(struct alps_data
*priv
,
220 return (data
& priv
->mask0
) == priv
->byte0
;
223 static void alps_report_buttons(struct input_dev
*dev1
, struct input_dev
*dev2
,
224 int left
, int right
, int middle
)
226 struct input_dev
*dev
;
229 * If shared button has already been reported on the
230 * other device (dev2) then this event should be also
231 * sent through that device.
233 dev
= (dev2
&& test_bit(BTN_LEFT
, dev2
->key
)) ? dev2
: dev1
;
234 input_report_key(dev
, BTN_LEFT
, left
);
236 dev
= (dev2
&& test_bit(BTN_RIGHT
, dev2
->key
)) ? dev2
: dev1
;
237 input_report_key(dev
, BTN_RIGHT
, right
);
239 dev
= (dev2
&& test_bit(BTN_MIDDLE
, dev2
->key
)) ? dev2
: dev1
;
240 input_report_key(dev
, BTN_MIDDLE
, middle
);
243 * Sync the _other_ device now, we'll do the first
244 * device later once we report the rest of the events.
250 static void alps_process_packet_v1_v2(struct psmouse
*psmouse
)
252 struct alps_data
*priv
= psmouse
->private;
253 unsigned char *packet
= psmouse
->packet
;
254 struct input_dev
*dev
= psmouse
->dev
;
255 struct input_dev
*dev2
= priv
->dev2
;
256 int x
, y
, z
, ges
, fin
, left
, right
, middle
;
257 int back
= 0, forward
= 0;
259 if (priv
->proto_version
== ALPS_PROTO_V1
) {
260 left
= packet
[2] & 0x10;
261 right
= packet
[2] & 0x08;
263 x
= packet
[1] | ((packet
[0] & 0x07) << 7);
264 y
= packet
[4] | ((packet
[3] & 0x07) << 7);
267 left
= packet
[3] & 1;
268 right
= packet
[3] & 2;
269 middle
= packet
[3] & 4;
270 x
= packet
[1] | ((packet
[2] & 0x78) << (7 - 3));
271 y
= packet
[4] | ((packet
[3] & 0x70) << (7 - 4));
275 if (priv
->flags
& ALPS_FW_BK_1
) {
276 back
= packet
[0] & 0x10;
277 forward
= packet
[2] & 4;
280 if (priv
->flags
& ALPS_FW_BK_2
) {
281 back
= packet
[3] & 4;
282 forward
= packet
[2] & 4;
283 if ((middle
= forward
&& back
))
290 if ((priv
->flags
& ALPS_DUALPOINT
) && z
== 127) {
291 input_report_rel(dev2
, REL_X
, (x
> 383 ? (x
- 768) : x
));
292 input_report_rel(dev2
, REL_Y
, -(y
> 255 ? (y
- 512) : y
));
294 alps_report_buttons(dev2
, dev
, left
, right
, middle
);
300 /* Some models have separate stick button bits */
301 if (priv
->flags
& ALPS_STICK_BITS
) {
302 left
|= packet
[0] & 1;
303 right
|= packet
[0] & 2;
304 middle
|= packet
[0] & 4;
307 alps_report_buttons(dev
, dev2
, left
, right
, middle
);
309 /* Convert hardware tap to a reasonable Z value */
314 * A "tap and drag" operation is reported by the hardware as a transition
315 * from (!fin && ges) to (fin && ges). This should be translated to the
316 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
318 if (ges
&& fin
&& !priv
->prev_fin
) {
319 input_report_abs(dev
, ABS_X
, x
);
320 input_report_abs(dev
, ABS_Y
, y
);
321 input_report_abs(dev
, ABS_PRESSURE
, 0);
322 input_report_key(dev
, BTN_TOOL_FINGER
, 0);
325 priv
->prev_fin
= fin
;
328 input_report_key(dev
, BTN_TOUCH
, 1);
330 input_report_key(dev
, BTN_TOUCH
, 0);
333 input_report_abs(dev
, ABS_X
, x
);
334 input_report_abs(dev
, ABS_Y
, y
);
337 input_report_abs(dev
, ABS_PRESSURE
, z
);
338 input_report_key(dev
, BTN_TOOL_FINGER
, z
> 0);
340 if (priv
->flags
& ALPS_WHEEL
)
341 input_report_rel(dev
, REL_WHEEL
, ((packet
[2] << 1) & 0x08) - ((packet
[0] >> 4) & 0x07));
343 if (priv
->flags
& (ALPS_FW_BK_1
| ALPS_FW_BK_2
)) {
344 input_report_key(dev
, BTN_FORWARD
, forward
);
345 input_report_key(dev
, BTN_BACK
, back
);
348 if (priv
->flags
& ALPS_FOUR_BUTTONS
) {
349 input_report_key(dev
, BTN_0
, packet
[2] & 4);
350 input_report_key(dev
, BTN_1
, packet
[0] & 0x10);
351 input_report_key(dev
, BTN_2
, packet
[3] & 4);
352 input_report_key(dev
, BTN_3
, packet
[0] & 0x20);
358 static void alps_get_bitmap_points(unsigned int map
,
359 struct alps_bitmap_point
*low
,
360 struct alps_bitmap_point
*high
,
363 struct alps_bitmap_point
*point
;
364 int i
, bit
, prev_bit
= 0;
367 for (i
= 0; map
!= 0; i
++, map
>>= 1) {
371 point
->start_bit
= i
;
385 * Process bitmap data from semi-mt protocols. Returns the number of
386 * fingers detected. A return value of 0 means at least one of the
389 * The bitmaps don't have enough data to track fingers, so this function
390 * only generates points representing a bounding box of all contacts.
391 * These points are returned in fields->mt when the return value
394 static int alps_process_bitmap(struct alps_data
*priv
,
395 struct alps_fields
*fields
)
397 int i
, fingers_x
= 0, fingers_y
= 0, fingers
, closest
;
398 struct alps_bitmap_point x_low
= {0,}, x_high
= {0,};
399 struct alps_bitmap_point y_low
= {0,}, y_high
= {0,};
400 struct input_mt_pos corner
[4];
402 if (!fields
->x_map
|| !fields
->y_map
)
405 alps_get_bitmap_points(fields
->x_map
, &x_low
, &x_high
, &fingers_x
);
406 alps_get_bitmap_points(fields
->y_map
, &y_low
, &y_high
, &fingers_y
);
409 * Fingers can overlap, so we use the maximum count of fingers
410 * on either axis as the finger count.
412 fingers
= max(fingers_x
, fingers_y
);
415 * If an axis reports only a single contact, we have overlapping or
416 * adjacent fingers. Divide the single contact between the two points.
418 if (fingers_x
== 1) {
419 i
= (x_low
.num_bits
- 1) / 2;
420 x_low
.num_bits
= x_low
.num_bits
- i
;
421 x_high
.start_bit
= x_low
.start_bit
+ i
;
422 x_high
.num_bits
= max(i
, 1);
424 if (fingers_y
== 1) {
425 i
= (y_low
.num_bits
- 1) / 2;
426 y_low
.num_bits
= y_low
.num_bits
- i
;
427 y_high
.start_bit
= y_low
.start_bit
+ i
;
428 y_high
.num_bits
= max(i
, 1);
431 /* top-left corner */
433 (priv
->x_max
* (2 * x_low
.start_bit
+ x_low
.num_bits
- 1)) /
434 (2 * (priv
->x_bits
- 1));
436 (priv
->y_max
* (2 * y_low
.start_bit
+ y_low
.num_bits
- 1)) /
437 (2 * (priv
->y_bits
- 1));
439 /* top-right corner */
441 (priv
->x_max
* (2 * x_high
.start_bit
+ x_high
.num_bits
- 1)) /
442 (2 * (priv
->x_bits
- 1));
444 (priv
->y_max
* (2 * y_low
.start_bit
+ y_low
.num_bits
- 1)) /
445 (2 * (priv
->y_bits
- 1));
447 /* bottom-right corner */
449 (priv
->x_max
* (2 * x_high
.start_bit
+ x_high
.num_bits
- 1)) /
450 (2 * (priv
->x_bits
- 1));
452 (priv
->y_max
* (2 * y_high
.start_bit
+ y_high
.num_bits
- 1)) /
453 (2 * (priv
->y_bits
- 1));
455 /* bottom-left corner */
457 (priv
->x_max
* (2 * x_low
.start_bit
+ x_low
.num_bits
- 1)) /
458 (2 * (priv
->x_bits
- 1));
460 (priv
->y_max
* (2 * y_high
.start_bit
+ y_high
.num_bits
- 1)) /
461 (2 * (priv
->y_bits
- 1));
463 /* x-bitmap order is reversed on v5 touchpads */
464 if (priv
->proto_version
== ALPS_PROTO_V5
) {
465 for (i
= 0; i
< 4; i
++)
466 corner
[i
].x
= priv
->x_max
- corner
[i
].x
;
469 /* y-bitmap order is reversed on v3 and v4 touchpads */
470 if (priv
->proto_version
== ALPS_PROTO_V3
||
471 priv
->proto_version
== ALPS_PROTO_V4
) {
472 for (i
= 0; i
< 4; i
++)
473 corner
[i
].y
= priv
->y_max
- corner
[i
].y
;
477 * We only select a corner for the second touch once per 2 finger
478 * touch sequence to avoid the chosen corner (and thus the coordinates)
479 * jumping around when the first touch is in the middle.
481 if (priv
->second_touch
== -1) {
482 /* Find corner closest to our st coordinates */
483 closest
= 0x7fffffff;
484 for (i
= 0; i
< 4; i
++) {
485 int dx
= fields
->st
.x
- corner
[i
].x
;
486 int dy
= fields
->st
.y
- corner
[i
].y
;
487 int distance
= dx
* dx
+ dy
* dy
;
489 if (distance
< closest
) {
490 priv
->second_touch
= i
;
494 /* And select the opposite corner to use for the 2nd touch */
495 priv
->second_touch
= (priv
->second_touch
+ 2) % 4;
498 fields
->mt
[0] = fields
->st
;
499 fields
->mt
[1] = corner
[priv
->second_touch
];
504 static void alps_set_slot(struct input_dev
*dev
, int slot
, int x
, int y
)
506 input_mt_slot(dev
, slot
);
507 input_mt_report_slot_state(dev
, MT_TOOL_FINGER
, true);
508 input_report_abs(dev
, ABS_MT_POSITION_X
, x
);
509 input_report_abs(dev
, ABS_MT_POSITION_Y
, y
);
512 static void alps_report_mt_data(struct psmouse
*psmouse
, int n
)
514 struct alps_data
*priv
= psmouse
->private;
515 struct input_dev
*dev
= psmouse
->dev
;
516 struct alps_fields
*f
= &priv
->f
;
517 int i
, slot
[MAX_TOUCHES
];
519 input_mt_assign_slots(dev
, slot
, f
->mt
, n
, 0);
520 for (i
= 0; i
< n
; i
++)
521 alps_set_slot(dev
, slot
[i
], f
->mt
[i
].x
, f
->mt
[i
].y
);
523 input_mt_sync_frame(dev
);
526 static void alps_report_semi_mt_data(struct psmouse
*psmouse
, int fingers
)
528 struct alps_data
*priv
= psmouse
->private;
529 struct input_dev
*dev
= psmouse
->dev
;
530 struct alps_fields
*f
= &priv
->f
;
532 /* Use st data when we don't have mt data */
534 f
->mt
[0].x
= f
->st
.x
;
535 f
->mt
[0].y
= f
->st
.y
;
536 fingers
= f
->pressure
> 0 ? 1 : 0;
537 priv
->second_touch
= -1;
541 alps_set_slot(dev
, 0, f
->mt
[0].x
, f
->mt
[0].y
);
543 alps_set_slot(dev
, 1, f
->mt
[1].x
, f
->mt
[1].y
);
544 input_mt_sync_frame(dev
);
546 input_mt_report_finger_count(dev
, fingers
);
548 input_report_key(dev
, BTN_LEFT
, f
->left
);
549 input_report_key(dev
, BTN_RIGHT
, f
->right
);
550 input_report_key(dev
, BTN_MIDDLE
, f
->middle
);
552 input_report_abs(dev
, ABS_PRESSURE
, f
->pressure
);
557 static void alps_process_trackstick_packet_v3(struct psmouse
*psmouse
)
559 struct alps_data
*priv
= psmouse
->private;
560 unsigned char *packet
= psmouse
->packet
;
561 struct input_dev
*dev
= priv
->dev2
;
562 int x
, y
, z
, left
, right
, middle
;
564 /* It should be a DualPoint when received trackstick packet */
565 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
566 psmouse_warn(psmouse
,
567 "Rejected trackstick packet from non DualPoint device");
571 /* Sanity check packet */
572 if (!(packet
[0] & 0x40)) {
573 psmouse_dbg(psmouse
, "Bad trackstick packet, discarding\n");
578 * There's a special packet that seems to indicate the end
579 * of a stream of trackstick data. Filter these out.
581 if (packet
[1] == 0x7f && packet
[2] == 0x7f && packet
[4] == 0x7f)
584 x
= (s8
)(((packet
[0] & 0x20) << 2) | (packet
[1] & 0x7f));
585 y
= (s8
)(((packet
[0] & 0x10) << 3) | (packet
[2] & 0x7f));
586 z
= packet
[4] & 0x7f;
589 * The x and y values tend to be quite large, and when used
590 * alone the trackstick is difficult to use. Scale them down
596 input_report_rel(dev
, REL_X
, x
);
597 input_report_rel(dev
, REL_Y
, -y
);
598 input_report_abs(dev
, ABS_PRESSURE
, z
);
601 * Most ALPS models report the trackstick buttons in the touchpad
602 * packets, but a few report them here. No reliable way has been
603 * found to differentiate between the models upfront, so we enable
604 * the quirk in response to seeing a button press in the trackstick
607 left
= packet
[3] & 0x01;
608 right
= packet
[3] & 0x02;
609 middle
= packet
[3] & 0x04;
611 if (!(priv
->quirks
& ALPS_QUIRK_TRACKSTICK_BUTTONS
) &&
612 (left
|| right
|| middle
))
613 priv
->quirks
|= ALPS_QUIRK_TRACKSTICK_BUTTONS
;
615 if (priv
->quirks
& ALPS_QUIRK_TRACKSTICK_BUTTONS
) {
616 input_report_key(dev
, BTN_LEFT
, left
);
617 input_report_key(dev
, BTN_RIGHT
, right
);
618 input_report_key(dev
, BTN_MIDDLE
, middle
);
625 static void alps_decode_buttons_v3(struct alps_fields
*f
, unsigned char *p
)
627 f
->left
= !!(p
[3] & 0x01);
628 f
->right
= !!(p
[3] & 0x02);
629 f
->middle
= !!(p
[3] & 0x04);
631 f
->ts_left
= !!(p
[3] & 0x10);
632 f
->ts_right
= !!(p
[3] & 0x20);
633 f
->ts_middle
= !!(p
[3] & 0x40);
636 static int alps_decode_pinnacle(struct alps_fields
*f
, unsigned char *p
,
637 struct psmouse
*psmouse
)
639 f
->first_mp
= !!(p
[4] & 0x40);
640 f
->is_mp
= !!(p
[0] & 0x40);
643 f
->fingers
= (p
[5] & 0x3) + 1;
644 f
->x_map
= ((p
[4] & 0x7e) << 8) |
645 ((p
[1] & 0x7f) << 2) |
646 ((p
[0] & 0x30) >> 4);
647 f
->y_map
= ((p
[3] & 0x70) << 4) |
648 ((p
[2] & 0x7f) << 1) |
651 f
->st
.x
= ((p
[1] & 0x7f) << 4) | ((p
[4] & 0x30) >> 2) |
652 ((p
[0] & 0x30) >> 4);
653 f
->st
.y
= ((p
[2] & 0x7f) << 4) | (p
[4] & 0x0f);
654 f
->pressure
= p
[5] & 0x7f;
656 alps_decode_buttons_v3(f
, p
);
662 static int alps_decode_rushmore(struct alps_fields
*f
, unsigned char *p
,
663 struct psmouse
*psmouse
)
665 f
->first_mp
= !!(p
[4] & 0x40);
666 f
->is_mp
= !!(p
[5] & 0x40);
669 f
->fingers
= max((p
[5] & 0x3), ((p
[5] >> 2) & 0x3)) + 1;
670 f
->x_map
= ((p
[5] & 0x10) << 11) |
671 ((p
[4] & 0x7e) << 8) |
672 ((p
[1] & 0x7f) << 2) |
673 ((p
[0] & 0x30) >> 4);
674 f
->y_map
= ((p
[5] & 0x20) << 6) |
675 ((p
[3] & 0x70) << 4) |
676 ((p
[2] & 0x7f) << 1) |
679 f
->st
.x
= ((p
[1] & 0x7f) << 4) | ((p
[4] & 0x30) >> 2) |
680 ((p
[0] & 0x30) >> 4);
681 f
->st
.y
= ((p
[2] & 0x7f) << 4) | (p
[4] & 0x0f);
682 f
->pressure
= p
[5] & 0x7f;
684 alps_decode_buttons_v3(f
, p
);
690 static int alps_decode_dolphin(struct alps_fields
*f
, unsigned char *p
,
691 struct psmouse
*psmouse
)
694 struct alps_data
*priv
= psmouse
->private;
696 f
->first_mp
= !!(p
[0] & 0x02);
697 f
->is_mp
= !!(p
[0] & 0x20);
700 f
->st
.x
= ((p
[1] & 0x7f) | ((p
[4] & 0x0f) << 7));
701 f
->st
.y
= ((p
[2] & 0x7f) | ((p
[4] & 0xf0) << 3));
702 f
->pressure
= (p
[0] & 4) ? 0 : p
[5] & 0x7f;
703 alps_decode_buttons_v3(f
, p
);
705 f
->fingers
= ((p
[0] & 0x6) >> 1 |
708 palm_data
= (p
[1] & 0x7f) |
709 ((p
[2] & 0x7f) << 7) |
710 ((p
[4] & 0x7f) << 14) |
711 ((p
[5] & 0x7f) << 21) |
712 ((p
[3] & 0x07) << 28) |
713 (((u64
)p
[3] & 0x70) << 27) |
714 (((u64
)p
[0] & 0x01) << 34);
716 /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */
717 f
->y_map
= palm_data
& (BIT(priv
->y_bits
) - 1);
719 /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */
720 f
->x_map
= (palm_data
>> priv
->y_bits
) &
721 (BIT(priv
->x_bits
) - 1);
727 static void alps_process_touchpad_packet_v3_v5(struct psmouse
*psmouse
)
729 struct alps_data
*priv
= psmouse
->private;
730 unsigned char *packet
= psmouse
->packet
;
731 struct input_dev
*dev2
= priv
->dev2
;
732 struct alps_fields
*f
= &priv
->f
;
735 memset(f
, 0, sizeof(*f
));
737 priv
->decode_fields(f
, packet
, psmouse
);
740 * There's no single feature of touchpad position and bitmap packets
741 * that can be used to distinguish between them. We rely on the fact
742 * that a bitmap packet should always follow a position packet with
743 * bit 6 of packet[4] set.
745 if (priv
->multi_packet
) {
747 * Sometimes a position packet will indicate a multi-packet
748 * sequence, but then what follows is another position
749 * packet. Check for this, and when it happens process the
750 * position packet as usual.
753 fingers
= f
->fingers
;
755 * Bitmap processing uses position packet's coordinate
756 * data, so we need to do decode it first.
758 priv
->decode_fields(f
, priv
->multi_data
, psmouse
);
759 if (alps_process_bitmap(priv
, f
) == 0)
760 fingers
= 0; /* Use st data */
762 priv
->multi_packet
= 0;
767 * Bit 6 of byte 0 is not usually set in position packets. The only
768 * times it seems to be set is in situations where the data is
769 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
770 * this combined with the fact that this bit is useful for filtering
771 * out misidentified bitmap packets, we reject anything with this
777 if (!priv
->multi_packet
&& f
->first_mp
) {
778 priv
->multi_packet
= 1;
779 memcpy(priv
->multi_data
, packet
, sizeof(priv
->multi_data
));
783 priv
->multi_packet
= 0;
786 * Sometimes the hardware sends a single packet with z = 0
787 * in the middle of a stream. Real releases generate packets
788 * with x, y, and z all zero, so these seem to be flukes.
791 if (f
->st
.x
&& f
->st
.y
&& !f
->pressure
)
794 alps_report_semi_mt_data(psmouse
, fingers
);
796 if ((priv
->flags
& ALPS_DUALPOINT
) &&
797 !(priv
->quirks
& ALPS_QUIRK_TRACKSTICK_BUTTONS
)) {
798 input_report_key(dev2
, BTN_LEFT
, f
->ts_left
);
799 input_report_key(dev2
, BTN_RIGHT
, f
->ts_right
);
800 input_report_key(dev2
, BTN_MIDDLE
, f
->ts_middle
);
805 static void alps_process_packet_v3(struct psmouse
*psmouse
)
807 unsigned char *packet
= psmouse
->packet
;
810 * v3 protocol packets come in three types, two representing
811 * touchpad data and one representing trackstick data.
812 * Trackstick packets seem to be distinguished by always
813 * having 0x3f in the last byte. This value has never been
814 * observed in the last byte of either of the other types
817 if (packet
[5] == 0x3f) {
818 alps_process_trackstick_packet_v3(psmouse
);
822 alps_process_touchpad_packet_v3_v5(psmouse
);
825 static void alps_process_packet_v6(struct psmouse
*psmouse
)
827 struct alps_data
*priv
= psmouse
->private;
828 unsigned char *packet
= psmouse
->packet
;
829 struct input_dev
*dev
= psmouse
->dev
;
830 struct input_dev
*dev2
= priv
->dev2
;
834 * We can use Byte5 to distinguish if the packet is from Touchpad
839 if (packet
[5] == 0x7F) {
840 /* It should be a DualPoint when received Trackpoint packet */
841 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
842 psmouse_warn(psmouse
,
843 "Rejected trackstick packet from non DualPoint device");
847 /* Trackpoint packet */
848 x
= packet
[1] | ((packet
[3] & 0x20) << 2);
849 y
= packet
[2] | ((packet
[3] & 0x40) << 1);
852 /* To prevent the cursor jump when finger lifted */
853 if (x
== 0x7F && y
== 0x7F && z
== 0x7F)
856 /* Divide 4 since trackpoint's speed is too fast */
857 input_report_rel(dev2
, REL_X
, (char)x
/ 4);
858 input_report_rel(dev2
, REL_Y
, -((char)y
/ 4));
860 psmouse_report_standard_buttons(dev2
, packet
[3]);
866 /* Touchpad packet */
867 x
= packet
[1] | ((packet
[3] & 0x78) << 4);
868 y
= packet
[2] | ((packet
[4] & 0x78) << 4);
872 input_report_key(dev
, BTN_TOUCH
, 1);
874 input_report_key(dev
, BTN_TOUCH
, 0);
877 input_report_abs(dev
, ABS_X
, x
);
878 input_report_abs(dev
, ABS_Y
, y
);
881 input_report_abs(dev
, ABS_PRESSURE
, z
);
882 input_report_key(dev
, BTN_TOOL_FINGER
, z
> 0);
884 /* v6 touchpad does not have middle button */
885 packet
[3] &= ~BIT(2);
886 psmouse_report_standard_buttons(dev2
, packet
[3]);
891 static void alps_process_packet_v4(struct psmouse
*psmouse
)
893 struct alps_data
*priv
= psmouse
->private;
894 unsigned char *packet
= psmouse
->packet
;
895 struct alps_fields
*f
= &priv
->f
;
899 * v4 has a 6-byte encoding for bitmap data, but this data is
900 * broken up between 3 normal packets. Use priv->multi_packet to
901 * track our position in the bitmap packet.
903 if (packet
[6] & 0x40) {
904 /* sync, reset position */
905 priv
->multi_packet
= 0;
908 if (WARN_ON_ONCE(priv
->multi_packet
> 2))
911 offset
= 2 * priv
->multi_packet
;
912 priv
->multi_data
[offset
] = packet
[6];
913 priv
->multi_data
[offset
+ 1] = packet
[7];
915 f
->left
= !!(packet
[4] & 0x01);
916 f
->right
= !!(packet
[4] & 0x02);
918 f
->st
.x
= ((packet
[1] & 0x7f) << 4) | ((packet
[3] & 0x30) >> 2) |
919 ((packet
[0] & 0x30) >> 4);
920 f
->st
.y
= ((packet
[2] & 0x7f) << 4) | (packet
[3] & 0x0f);
921 f
->pressure
= packet
[5] & 0x7f;
923 if (++priv
->multi_packet
> 2) {
924 priv
->multi_packet
= 0;
926 f
->x_map
= ((priv
->multi_data
[2] & 0x1f) << 10) |
927 ((priv
->multi_data
[3] & 0x60) << 3) |
928 ((priv
->multi_data
[0] & 0x3f) << 2) |
929 ((priv
->multi_data
[1] & 0x60) >> 5);
930 f
->y_map
= ((priv
->multi_data
[5] & 0x01) << 10) |
931 ((priv
->multi_data
[3] & 0x1f) << 5) |
932 (priv
->multi_data
[1] & 0x1f);
934 f
->fingers
= alps_process_bitmap(priv
, f
);
937 alps_report_semi_mt_data(psmouse
, f
->fingers
);
940 static bool alps_is_valid_package_v7(struct psmouse
*psmouse
)
942 switch (psmouse
->pktcnt
) {
944 return (psmouse
->packet
[2] & 0x40) == 0x40;
946 return (psmouse
->packet
[3] & 0x48) == 0x48;
948 return (psmouse
->packet
[5] & 0x40) == 0x00;
953 static unsigned char alps_get_packet_id_v7(char *byte
)
955 unsigned char packet_id
;
958 packet_id
= V7_PACKET_ID_TWO
;
959 else if (byte
[4] & 0x01)
960 packet_id
= V7_PACKET_ID_MULTI
;
961 else if ((byte
[0] & 0x10) && !(byte
[4] & 0x43))
962 packet_id
= V7_PACKET_ID_NEW
;
963 else if (byte
[1] == 0x00 && byte
[4] == 0x00)
964 packet_id
= V7_PACKET_ID_IDLE
;
966 packet_id
= V7_PACKET_ID_UNKNOWN
;
971 static void alps_get_finger_coordinate_v7(struct input_mt_pos
*mt
,
973 unsigned char pkt_id
)
975 mt
[0].x
= ((pkt
[2] & 0x80) << 4);
976 mt
[0].x
|= ((pkt
[2] & 0x3F) << 5);
977 mt
[0].x
|= ((pkt
[3] & 0x30) >> 1);
978 mt
[0].x
|= (pkt
[3] & 0x07);
979 mt
[0].y
= (pkt
[1] << 3) | (pkt
[0] & 0x07);
981 mt
[1].x
= ((pkt
[3] & 0x80) << 4);
982 mt
[1].x
|= ((pkt
[4] & 0x80) << 3);
983 mt
[1].x
|= ((pkt
[4] & 0x3F) << 4);
984 mt
[1].y
= ((pkt
[5] & 0x80) << 3);
985 mt
[1].y
|= ((pkt
[5] & 0x3F) << 4);
988 case V7_PACKET_ID_TWO
:
991 /* Detect false-postive touches where x & y report max value */
992 if (mt
[1].y
== 0x7ff && mt
[1].x
== 0xff0) {
994 /* y gets set to 0 at the end of this function */
998 case V7_PACKET_ID_MULTI
:
1001 mt
[1].y
|= ((pkt
[4] & 0x02) << 4);
1005 case V7_PACKET_ID_NEW
:
1007 mt
[1].x
|= (pkt
[0] & 0x20);
1012 mt
[0].y
= 0x7FF - mt
[0].y
;
1013 mt
[1].y
= 0x7FF - mt
[1].y
;
1016 static int alps_get_mt_count(struct input_mt_pos
*mt
)
1020 for (i
= 0; i
< MAX_TOUCHES
; i
++) {
1021 if (mt
[i
].x
!= 0 || mt
[i
].y
!= 0)
1028 static int alps_decode_packet_v7(struct alps_fields
*f
,
1030 struct psmouse
*psmouse
)
1032 struct alps_data
*priv
= psmouse
->private;
1033 unsigned char pkt_id
;
1035 pkt_id
= alps_get_packet_id_v7(p
);
1036 if (pkt_id
== V7_PACKET_ID_IDLE
)
1038 if (pkt_id
== V7_PACKET_ID_UNKNOWN
)
1041 * NEW packets are send to indicate a discontinuity in the finger
1042 * coordinate reporting. Specifically a finger may have moved from
1043 * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for
1046 * NEW packets have 3 problems:
1047 * 1) They do not contain middle / right button info (on non clickpads)
1048 * this can be worked around by preserving the old button state
1049 * 2) They do not contain an accurate fingercount, and they are
1050 * typically send when the number of fingers changes. We cannot use
1051 * the old finger count as that may mismatch with the amount of
1052 * touch coordinates we've available in the NEW packet
1053 * 3) Their x data for the second touch is inaccurate leading to
1054 * a possible jump of the x coordinate by 16 units when the first
1055 * non NEW packet comes in
1056 * Since problems 2 & 3 cannot be worked around, just ignore them.
1058 if (pkt_id
== V7_PACKET_ID_NEW
)
1061 alps_get_finger_coordinate_v7(f
->mt
, p
, pkt_id
);
1063 if (pkt_id
== V7_PACKET_ID_TWO
)
1064 f
->fingers
= alps_get_mt_count(f
->mt
);
1065 else /* pkt_id == V7_PACKET_ID_MULTI */
1066 f
->fingers
= 3 + (p
[5] & 0x03);
1068 f
->left
= (p
[0] & 0x80) >> 7;
1069 if (priv
->flags
& ALPS_BUTTONPAD
) {
1075 f
->right
= (p
[0] & 0x20) >> 5;
1076 f
->middle
= (p
[0] & 0x10) >> 4;
1079 /* Sometimes a single touch is reported in mt[1] rather then mt[0] */
1080 if (f
->fingers
== 1 && f
->mt
[0].x
== 0 && f
->mt
[0].y
== 0) {
1081 f
->mt
[0].x
= f
->mt
[1].x
;
1082 f
->mt
[0].y
= f
->mt
[1].y
;
1090 static void alps_process_trackstick_packet_v7(struct psmouse
*psmouse
)
1092 struct alps_data
*priv
= psmouse
->private;
1093 unsigned char *packet
= psmouse
->packet
;
1094 struct input_dev
*dev2
= priv
->dev2
;
1097 /* It should be a DualPoint when received trackstick packet */
1098 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
1099 psmouse_warn(psmouse
,
1100 "Rejected trackstick packet from non DualPoint device");
1104 x
= ((packet
[2] & 0xbf)) | ((packet
[3] & 0x10) << 2);
1105 y
= (packet
[3] & 0x07) | (packet
[4] & 0xb8) |
1106 ((packet
[3] & 0x20) << 1);
1107 z
= (packet
[5] & 0x3f) | ((packet
[3] & 0x80) >> 1);
1109 input_report_rel(dev2
, REL_X
, (char)x
);
1110 input_report_rel(dev2
, REL_Y
, -((char)y
));
1111 input_report_abs(dev2
, ABS_PRESSURE
, z
);
1113 psmouse_report_standard_buttons(dev2
, packet
[1]);
1118 static void alps_process_touchpad_packet_v7(struct psmouse
*psmouse
)
1120 struct alps_data
*priv
= psmouse
->private;
1121 struct input_dev
*dev
= psmouse
->dev
;
1122 struct alps_fields
*f
= &priv
->f
;
1124 memset(f
, 0, sizeof(*f
));
1126 if (priv
->decode_fields(f
, psmouse
->packet
, psmouse
))
1129 alps_report_mt_data(psmouse
, alps_get_mt_count(f
->mt
));
1131 input_mt_report_finger_count(dev
, f
->fingers
);
1133 input_report_key(dev
, BTN_LEFT
, f
->left
);
1134 input_report_key(dev
, BTN_RIGHT
, f
->right
);
1135 input_report_key(dev
, BTN_MIDDLE
, f
->middle
);
1140 static void alps_process_packet_v7(struct psmouse
*psmouse
)
1142 unsigned char *packet
= psmouse
->packet
;
1144 if (packet
[0] == 0x48 && (packet
[4] & 0x47) == 0x06)
1145 alps_process_trackstick_packet_v7(psmouse
);
1147 alps_process_touchpad_packet_v7(psmouse
);
1150 static enum SS4_PACKET_ID
alps_get_pkt_id_ss4_v2(unsigned char *byte
)
1152 enum SS4_PACKET_ID pkt_id
= SS4_PACKET_ID_IDLE
;
1154 switch (byte
[3] & 0x30) {
1156 if (SS4_IS_IDLE_V2(byte
)) {
1157 pkt_id
= SS4_PACKET_ID_IDLE
;
1159 pkt_id
= SS4_PACKET_ID_ONE
;
1163 /* two-finger finger positions */
1164 pkt_id
= SS4_PACKET_ID_TWO
;
1168 pkt_id
= SS4_PACKET_ID_STICK
;
1171 /* third and fourth finger positions */
1172 pkt_id
= SS4_PACKET_ID_MULTI
;
1179 static int alps_decode_ss4_v2(struct alps_fields
*f
,
1180 unsigned char *p
, struct psmouse
*psmouse
)
1182 struct alps_data
*priv
= psmouse
->private;
1183 enum SS4_PACKET_ID pkt_id
;
1184 unsigned int no_data_x
, no_data_y
;
1186 pkt_id
= alps_get_pkt_id_ss4_v2(p
);
1188 /* Current packet is 1Finger coordinate packet */
1190 case SS4_PACKET_ID_ONE
:
1191 f
->mt
[0].x
= SS4_1F_X_V2(p
);
1192 f
->mt
[0].y
= SS4_1F_Y_V2(p
);
1193 f
->pressure
= ((SS4_1F_Z_V2(p
)) * 2) & 0x7f;
1195 * When a button is held the device will give us events
1196 * with x, y, and pressure of 0. This causes annoying jumps
1197 * if a touch is released while the button is held.
1198 * Handle this by claiming zero contacts.
1200 f
->fingers
= f
->pressure
> 0 ? 1 : 0;
1205 case SS4_PACKET_ID_TWO
:
1206 if (priv
->flags
& ALPS_BUTTONPAD
) {
1207 if (IS_SS4PLUS_DEV(priv
->dev_id
)) {
1208 f
->mt
[0].x
= SS4_PLUS_BTL_MF_X_V2(p
, 0);
1209 f
->mt
[1].x
= SS4_PLUS_BTL_MF_X_V2(p
, 1);
1211 f
->mt
[0].x
= SS4_BTL_MF_X_V2(p
, 0);
1212 f
->mt
[1].x
= SS4_BTL_MF_X_V2(p
, 1);
1214 f
->mt
[0].y
= SS4_BTL_MF_Y_V2(p
, 0);
1215 f
->mt
[1].y
= SS4_BTL_MF_Y_V2(p
, 1);
1217 if (IS_SS4PLUS_DEV(priv
->dev_id
)) {
1218 f
->mt
[0].x
= SS4_PLUS_STD_MF_X_V2(p
, 0);
1219 f
->mt
[1].x
= SS4_PLUS_STD_MF_X_V2(p
, 1);
1221 f
->mt
[0].x
= SS4_STD_MF_X_V2(p
, 0);
1222 f
->mt
[1].x
= SS4_STD_MF_X_V2(p
, 1);
1224 f
->mt
[0].y
= SS4_STD_MF_Y_V2(p
, 0);
1225 f
->mt
[1].y
= SS4_STD_MF_Y_V2(p
, 1);
1227 f
->pressure
= SS4_MF_Z_V2(p
, 0) ? 0x30 : 0;
1229 if (SS4_IS_MF_CONTINUE(p
)) {
1239 case SS4_PACKET_ID_MULTI
:
1240 if (priv
->flags
& ALPS_BUTTONPAD
) {
1241 if (IS_SS4PLUS_DEV(priv
->dev_id
)) {
1242 f
->mt
[2].x
= SS4_PLUS_BTL_MF_X_V2(p
, 0);
1243 f
->mt
[3].x
= SS4_PLUS_BTL_MF_X_V2(p
, 1);
1244 no_data_x
= SS4_PLUS_MFPACKET_NO_AX_BL
;
1246 f
->mt
[2].x
= SS4_BTL_MF_X_V2(p
, 0);
1247 f
->mt
[3].x
= SS4_BTL_MF_X_V2(p
, 1);
1248 no_data_x
= SS4_MFPACKET_NO_AX_BL
;
1250 no_data_y
= SS4_MFPACKET_NO_AY_BL
;
1252 f
->mt
[2].y
= SS4_BTL_MF_Y_V2(p
, 0);
1253 f
->mt
[3].y
= SS4_BTL_MF_Y_V2(p
, 1);
1255 if (IS_SS4PLUS_DEV(priv
->dev_id
)) {
1256 f
->mt
[2].x
= SS4_PLUS_STD_MF_X_V2(p
, 0);
1257 f
->mt
[3].x
= SS4_PLUS_STD_MF_X_V2(p
, 1);
1258 no_data_x
= SS4_PLUS_MFPACKET_NO_AX
;
1260 f
->mt
[2].x
= SS4_STD_MF_X_V2(p
, 0);
1261 f
->mt
[3].x
= SS4_STD_MF_X_V2(p
, 1);
1262 no_data_x
= SS4_MFPACKET_NO_AX
;
1264 no_data_y
= SS4_MFPACKET_NO_AY
;
1266 f
->mt
[2].y
= SS4_STD_MF_Y_V2(p
, 0);
1267 f
->mt
[3].y
= SS4_STD_MF_Y_V2(p
, 1);
1273 if (SS4_IS_5F_DETECTED(p
)) {
1275 } else if (f
->mt
[3].x
== no_data_x
&&
1276 f
->mt
[3].y
== no_data_y
) {
1285 case SS4_PACKET_ID_STICK
:
1287 * x, y, and pressure are decoded in
1288 * alps_process_packet_ss4_v2()
1294 case SS4_PACKET_ID_IDLE
:
1296 memset(f
, 0, sizeof(struct alps_fields
));
1300 /* handle buttons */
1301 if (pkt_id
== SS4_PACKET_ID_STICK
) {
1302 f
->ts_left
= !!(SS4_BTN_V2(p
) & 0x01);
1303 f
->ts_right
= !!(SS4_BTN_V2(p
) & 0x02);
1304 f
->ts_middle
= !!(SS4_BTN_V2(p
) & 0x04);
1306 f
->left
= !!(SS4_BTN_V2(p
) & 0x01);
1307 if (!(priv
->flags
& ALPS_BUTTONPAD
)) {
1308 f
->right
= !!(SS4_BTN_V2(p
) & 0x02);
1309 f
->middle
= !!(SS4_BTN_V2(p
) & 0x04);
1316 static void alps_process_packet_ss4_v2(struct psmouse
*psmouse
)
1318 struct alps_data
*priv
= psmouse
->private;
1319 unsigned char *packet
= psmouse
->packet
;
1320 struct input_dev
*dev
= psmouse
->dev
;
1321 struct input_dev
*dev2
= priv
->dev2
;
1322 struct alps_fields
*f
= &priv
->f
;
1324 memset(f
, 0, sizeof(struct alps_fields
));
1325 priv
->decode_fields(f
, packet
, psmouse
);
1326 if (priv
->multi_packet
) {
1328 * Sometimes the first packet will indicate a multi-packet
1329 * sequence, but sometimes the next multi-packet would not
1330 * come. Check for this, and when it happens process the
1331 * position packet as usual.
1334 /* Now process the 1st packet */
1335 priv
->decode_fields(f
, priv
->multi_data
, psmouse
);
1337 priv
->multi_packet
= 0;
1342 * "f.is_mp" would always be '0' after merging the 1st and 2nd packet.
1343 * When it is set, it means 2nd packet comes without 1st packet come.
1348 /* Save the first packet */
1349 if (!priv
->multi_packet
&& f
->first_mp
) {
1350 priv
->multi_packet
= 1;
1351 memcpy(priv
->multi_data
, packet
, sizeof(priv
->multi_data
));
1355 priv
->multi_packet
= 0;
1357 /* Report trackstick */
1358 if (alps_get_pkt_id_ss4_v2(packet
) == SS4_PACKET_ID_STICK
) {
1359 if (!(priv
->flags
& ALPS_DUALPOINT
)) {
1360 psmouse_warn(psmouse
,
1361 "Rejected trackstick packet from non DualPoint device");
1365 input_report_rel(dev2
, REL_X
, SS4_TS_X_V2(packet
));
1366 input_report_rel(dev2
, REL_Y
, SS4_TS_Y_V2(packet
));
1367 input_report_abs(dev2
, ABS_PRESSURE
, SS4_TS_Z_V2(packet
));
1369 input_report_key(dev2
, BTN_LEFT
, f
->ts_left
);
1370 input_report_key(dev2
, BTN_RIGHT
, f
->ts_right
);
1371 input_report_key(dev2
, BTN_MIDDLE
, f
->ts_middle
);
1377 /* Report touchpad */
1378 alps_report_mt_data(psmouse
, (f
->fingers
<= 4) ? f
->fingers
: 4);
1380 input_mt_report_finger_count(dev
, f
->fingers
);
1382 input_report_key(dev
, BTN_LEFT
, f
->left
);
1383 input_report_key(dev
, BTN_RIGHT
, f
->right
);
1384 input_report_key(dev
, BTN_MIDDLE
, f
->middle
);
1386 input_report_abs(dev
, ABS_PRESSURE
, f
->pressure
);
1390 static bool alps_is_valid_package_ss4_v2(struct psmouse
*psmouse
)
1392 if (psmouse
->pktcnt
== 4 && ((psmouse
->packet
[3] & 0x08) != 0x08))
1394 if (psmouse
->pktcnt
== 6 && ((psmouse
->packet
[5] & 0x10) != 0x0))
1399 static DEFINE_MUTEX(alps_mutex
);
1401 static void alps_register_bare_ps2_mouse(struct work_struct
*work
)
1403 struct alps_data
*priv
=
1404 container_of(work
, struct alps_data
, dev3_register_work
.work
);
1405 struct psmouse
*psmouse
= priv
->psmouse
;
1406 struct input_dev
*dev3
;
1409 mutex_lock(&alps_mutex
);
1414 dev3
= input_allocate_device();
1416 psmouse_err(psmouse
, "failed to allocate secondary device\n");
1421 snprintf(priv
->phys3
, sizeof(priv
->phys3
), "%s/%s",
1422 psmouse
->ps2dev
.serio
->phys
,
1423 (priv
->dev2
? "input2" : "input1"));
1424 dev3
->phys
= priv
->phys3
;
1427 * format of input device name is: "protocol vendor name"
1428 * see function psmouse_switch_protocol() in psmouse-base.c
1430 dev3
->name
= "PS/2 ALPS Mouse";
1432 dev3
->id
.bustype
= BUS_I8042
;
1433 dev3
->id
.vendor
= 0x0002;
1434 dev3
->id
.product
= PSMOUSE_PS2
;
1435 dev3
->id
.version
= 0x0000;
1436 dev3
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
1438 input_set_capability(dev3
, EV_REL
, REL_X
);
1439 input_set_capability(dev3
, EV_REL
, REL_Y
);
1440 input_set_capability(dev3
, EV_KEY
, BTN_LEFT
);
1441 input_set_capability(dev3
, EV_KEY
, BTN_RIGHT
);
1442 input_set_capability(dev3
, EV_KEY
, BTN_MIDDLE
);
1444 __set_bit(INPUT_PROP_POINTER
, dev3
->propbit
);
1446 error
= input_register_device(dev3
);
1448 psmouse_err(psmouse
,
1449 "failed to register secondary device: %d\n",
1451 input_free_device(dev3
);
1459 * Save the error code so that we can detect that we
1460 * already tried to create the device.
1463 priv
->dev3
= ERR_PTR(error
);
1465 mutex_unlock(&alps_mutex
);
1468 static void alps_report_bare_ps2_packet(struct psmouse
*psmouse
,
1469 unsigned char packet
[],
1470 bool report_buttons
)
1472 struct alps_data
*priv
= psmouse
->private;
1473 struct input_dev
*dev
, *dev2
= NULL
;
1475 /* Figure out which device to use to report the bare packet */
1476 if (priv
->proto_version
== ALPS_PROTO_V2
&&
1477 (priv
->flags
& ALPS_DUALPOINT
)) {
1478 /* On V2 devices the DualPoint Stick reports bare packets */
1480 dev2
= psmouse
->dev
;
1481 } else if (unlikely(IS_ERR_OR_NULL(priv
->dev3
))) {
1482 /* Register dev3 mouse if we received PS/2 packet first time */
1483 if (!IS_ERR(priv
->dev3
))
1484 psmouse_queue_work(psmouse
, &priv
->dev3_register_work
,
1492 alps_report_buttons(dev
, dev2
,
1493 packet
[0] & 1, packet
[0] & 2, packet
[0] & 4);
1495 psmouse_report_standard_motion(dev
, packet
);
1500 static psmouse_ret_t
alps_handle_interleaved_ps2(struct psmouse
*psmouse
)
1502 struct alps_data
*priv
= psmouse
->private;
1504 if (psmouse
->pktcnt
< 6)
1505 return PSMOUSE_GOOD_DATA
;
1507 if (psmouse
->pktcnt
== 6) {
1509 * Start a timer to flush the packet if it ends up last
1510 * 6-byte packet in the stream. Timer needs to fire
1511 * psmouse core times out itself. 20 ms should be enough
1512 * to decide if we are getting more data or not.
1514 mod_timer(&priv
->timer
, jiffies
+ msecs_to_jiffies(20));
1515 return PSMOUSE_GOOD_DATA
;
1518 del_timer(&priv
->timer
);
1520 if (psmouse
->packet
[6] & 0x80) {
1523 * Highest bit is set - that means we either had
1524 * complete ALPS packet and this is start of the
1525 * next packet or we got garbage.
1528 if (((psmouse
->packet
[3] |
1529 psmouse
->packet
[4] |
1530 psmouse
->packet
[5]) & 0x80) ||
1531 (!alps_is_valid_first_byte(priv
, psmouse
->packet
[6]))) {
1532 psmouse_dbg(psmouse
,
1533 "refusing packet %4ph (suspected interleaved ps/2)\n",
1534 psmouse
->packet
+ 3);
1535 return PSMOUSE_BAD_DATA
;
1538 priv
->process_packet(psmouse
);
1540 /* Continue with the next packet */
1541 psmouse
->packet
[0] = psmouse
->packet
[6];
1542 psmouse
->pktcnt
= 1;
1547 * High bit is 0 - that means that we indeed got a PS/2
1548 * packet in the middle of ALPS packet.
1550 * There is also possibility that we got 6-byte ALPS
1551 * packet followed by 3-byte packet from trackpoint. We
1552 * can not distinguish between these 2 scenarios but
1553 * because the latter is unlikely to happen in course of
1554 * normal operation (user would need to press all
1555 * buttons on the pad and start moving trackpoint
1556 * without touching the pad surface) we assume former.
1557 * Even if we are wrong the wost thing that would happen
1558 * the cursor would jump but we should not get protocol
1559 * de-synchronization.
1562 alps_report_bare_ps2_packet(psmouse
, &psmouse
->packet
[3],
1566 * Continue with the standard ALPS protocol handling,
1567 * but make sure we won't process it as an interleaved
1568 * packet again, which may happen if all buttons are
1569 * pressed. To avoid this let's reset the 4th bit which
1572 psmouse
->packet
[3] = psmouse
->packet
[6] & 0xf7;
1573 psmouse
->pktcnt
= 4;
1576 return PSMOUSE_GOOD_DATA
;
1579 static void alps_flush_packet(struct timer_list
*t
)
1581 struct alps_data
*priv
= from_timer(priv
, t
, timer
);
1582 struct psmouse
*psmouse
= priv
->psmouse
;
1584 serio_pause_rx(psmouse
->ps2dev
.serio
);
1586 if (psmouse
->pktcnt
== psmouse
->pktsize
) {
1589 * We did not any more data in reasonable amount of time.
1590 * Validate the last 3 bytes and process as a standard
1593 if ((psmouse
->packet
[3] |
1594 psmouse
->packet
[4] |
1595 psmouse
->packet
[5]) & 0x80) {
1596 psmouse_dbg(psmouse
,
1597 "refusing packet %3ph (suspected interleaved ps/2)\n",
1598 psmouse
->packet
+ 3);
1600 priv
->process_packet(psmouse
);
1602 psmouse
->pktcnt
= 0;
1605 serio_continue_rx(psmouse
->ps2dev
.serio
);
1608 static psmouse_ret_t
alps_process_byte(struct psmouse
*psmouse
)
1610 struct alps_data
*priv
= psmouse
->private;
1613 * Check if we are dealing with a bare PS/2 packet, presumably from
1614 * a device connected to the external PS/2 port. Because bare PS/2
1615 * protocol does not have enough constant bits to self-synchronize
1616 * properly we only do this if the device is fully synchronized.
1617 * Can not distinguish V8's first byte from PS/2 packet's
1619 if (priv
->proto_version
!= ALPS_PROTO_V8
&&
1620 !psmouse
->out_of_sync_cnt
&&
1621 (psmouse
->packet
[0] & 0xc8) == 0x08) {
1623 if (psmouse
->pktcnt
== 3) {
1624 alps_report_bare_ps2_packet(psmouse
, psmouse
->packet
,
1626 return PSMOUSE_FULL_PACKET
;
1628 return PSMOUSE_GOOD_DATA
;
1631 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
1633 if ((priv
->flags
& ALPS_PS2_INTERLEAVED
) &&
1634 psmouse
->pktcnt
>= 4 && (psmouse
->packet
[3] & 0x0f) == 0x0f) {
1635 return alps_handle_interleaved_ps2(psmouse
);
1638 if (!alps_is_valid_first_byte(priv
, psmouse
->packet
[0])) {
1639 psmouse_dbg(psmouse
,
1640 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
1641 psmouse
->packet
[0], priv
->mask0
, priv
->byte0
);
1642 return PSMOUSE_BAD_DATA
;
1645 /* Bytes 2 - pktsize should have 0 in the highest bit */
1646 if (priv
->proto_version
< ALPS_PROTO_V5
&&
1647 psmouse
->pktcnt
>= 2 && psmouse
->pktcnt
<= psmouse
->pktsize
&&
1648 (psmouse
->packet
[psmouse
->pktcnt
- 1] & 0x80)) {
1649 psmouse_dbg(psmouse
, "refusing packet[%i] = %x\n",
1650 psmouse
->pktcnt
- 1,
1651 psmouse
->packet
[psmouse
->pktcnt
- 1]);
1653 if (priv
->proto_version
== ALPS_PROTO_V3_RUSHMORE
&&
1654 psmouse
->pktcnt
== psmouse
->pktsize
) {
1656 * Some Dell boxes, such as Latitude E6440 or E7440
1657 * with closed lid, quite often smash last byte of
1658 * otherwise valid packet with 0xff. Given that the
1659 * next packet is very likely to be valid let's
1660 * report PSMOUSE_FULL_PACKET but not process data,
1661 * rather than reporting PSMOUSE_BAD_DATA and
1664 return PSMOUSE_FULL_PACKET
;
1667 return PSMOUSE_BAD_DATA
;
1670 if ((priv
->proto_version
== ALPS_PROTO_V7
&&
1671 !alps_is_valid_package_v7(psmouse
)) ||
1672 (priv
->proto_version
== ALPS_PROTO_V8
&&
1673 !alps_is_valid_package_ss4_v2(psmouse
))) {
1674 psmouse_dbg(psmouse
, "refusing packet[%i] = %x\n",
1675 psmouse
->pktcnt
- 1,
1676 psmouse
->packet
[psmouse
->pktcnt
- 1]);
1677 return PSMOUSE_BAD_DATA
;
1680 if (psmouse
->pktcnt
== psmouse
->pktsize
) {
1681 priv
->process_packet(psmouse
);
1682 return PSMOUSE_FULL_PACKET
;
1685 return PSMOUSE_GOOD_DATA
;
1688 static int alps_command_mode_send_nibble(struct psmouse
*psmouse
, int nibble
)
1690 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1691 struct alps_data
*priv
= psmouse
->private;
1693 unsigned char *param
;
1694 unsigned char dummy
[4];
1696 BUG_ON(nibble
> 0xf);
1698 command
= priv
->nibble_commands
[nibble
].command
;
1699 param
= (command
& 0x0f00) ?
1700 dummy
: (unsigned char *)&priv
->nibble_commands
[nibble
].data
;
1702 if (ps2_command(ps2dev
, param
, command
))
1708 static int alps_command_mode_set_addr(struct psmouse
*psmouse
, int addr
)
1710 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1711 struct alps_data
*priv
= psmouse
->private;
1714 if (ps2_command(ps2dev
, NULL
, priv
->addr_command
))
1717 for (i
= 12; i
>= 0; i
-= 4) {
1718 nibble
= (addr
>> i
) & 0xf;
1719 if (alps_command_mode_send_nibble(psmouse
, nibble
))
1726 static int __alps_command_mode_read_reg(struct psmouse
*psmouse
, int addr
)
1728 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1729 unsigned char param
[4];
1731 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
1735 * The address being read is returned in the first two bytes
1736 * of the result. Check that this address matches the expected
1739 if (addr
!= ((param
[0] << 8) | param
[1]))
1745 static int alps_command_mode_read_reg(struct psmouse
*psmouse
, int addr
)
1747 if (alps_command_mode_set_addr(psmouse
, addr
))
1749 return __alps_command_mode_read_reg(psmouse
, addr
);
1752 static int __alps_command_mode_write_reg(struct psmouse
*psmouse
, u8 value
)
1754 if (alps_command_mode_send_nibble(psmouse
, (value
>> 4) & 0xf))
1756 if (alps_command_mode_send_nibble(psmouse
, value
& 0xf))
1761 static int alps_command_mode_write_reg(struct psmouse
*psmouse
, int addr
,
1764 if (alps_command_mode_set_addr(psmouse
, addr
))
1766 return __alps_command_mode_write_reg(psmouse
, value
);
1769 static int alps_rpt_cmd(struct psmouse
*psmouse
, int init_command
,
1770 int repeated_command
, unsigned char *param
)
1772 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1775 if (init_command
&& ps2_command(ps2dev
, param
, init_command
))
1778 if (ps2_command(ps2dev
, NULL
, repeated_command
) ||
1779 ps2_command(ps2dev
, NULL
, repeated_command
) ||
1780 ps2_command(ps2dev
, NULL
, repeated_command
))
1783 param
[0] = param
[1] = param
[2] = 0xff;
1784 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
1787 psmouse_dbg(psmouse
, "%2.2X report: %3ph\n",
1788 repeated_command
, param
);
1792 static bool alps_check_valid_firmware_id(unsigned char id
[])
1797 if (id
[0] == 0x88 &&
1800 (id
[1] & 0xf0) == 0xb0 ||
1801 (id
[1] & 0xf0) == 0xc0)) {
1808 static int alps_enter_command_mode(struct psmouse
*psmouse
)
1810 unsigned char param
[4];
1812 if (alps_rpt_cmd(psmouse
, 0, PSMOUSE_CMD_RESET_WRAP
, param
)) {
1813 psmouse_err(psmouse
, "failed to enter command mode\n");
1817 if (!alps_check_valid_firmware_id(param
)) {
1818 psmouse_dbg(psmouse
,
1819 "unknown response while entering command mode\n");
1825 static inline int alps_exit_command_mode(struct psmouse
*psmouse
)
1827 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1828 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
))
1834 * For DualPoint devices select the device that should respond to
1835 * subsequent commands. It looks like glidepad is behind stickpointer,
1836 * I'd thought it would be other way around...
1838 static int alps_passthrough_mode_v2(struct psmouse
*psmouse
, bool enable
)
1840 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1841 int cmd
= enable
? PSMOUSE_CMD_SETSCALE21
: PSMOUSE_CMD_SETSCALE11
;
1843 if (ps2_command(ps2dev
, NULL
, cmd
) ||
1844 ps2_command(ps2dev
, NULL
, cmd
) ||
1845 ps2_command(ps2dev
, NULL
, cmd
) ||
1846 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
))
1849 /* we may get 3 more bytes, just ignore them */
1850 ps2_drain(ps2dev
, 3, 100);
1855 static int alps_absolute_mode_v1_v2(struct psmouse
*psmouse
)
1857 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1859 /* Try ALPS magic knock - 4 disable before enable */
1860 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1861 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1862 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1863 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1864 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
))
1868 * Switch mouse to poll (remote) mode so motion data will not
1871 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
);
1874 static int alps_monitor_mode_send_word(struct psmouse
*psmouse
, u16 word
)
1879 * b0-b11 are valid bits, send sequence is inverse.
1880 * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1
1882 for (i
= 0; i
<= 8; i
+= 4) {
1883 nibble
= (word
>> i
) & 0xf;
1884 if (alps_command_mode_send_nibble(psmouse
, nibble
))
1891 static int alps_monitor_mode_write_reg(struct psmouse
*psmouse
,
1892 u16 addr
, u16 value
)
1894 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1896 /* 0x0A0 is the command to write the word */
1897 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
) ||
1898 alps_monitor_mode_send_word(psmouse
, 0x0A0) ||
1899 alps_monitor_mode_send_word(psmouse
, addr
) ||
1900 alps_monitor_mode_send_word(psmouse
, value
) ||
1901 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
))
1907 static int alps_monitor_mode(struct psmouse
*psmouse
, bool enable
)
1909 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1912 /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */
1913 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_WRAP
) ||
1914 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_GETINFO
) ||
1915 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1916 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1917 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE21
) ||
1918 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
1919 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE21
) ||
1920 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_GETINFO
))
1923 /* EC to exit monitor mode */
1924 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_WRAP
))
1931 static int alps_absolute_mode_v6(struct psmouse
*psmouse
)
1933 u16 reg_val
= 0x181;
1936 /* enter monitor mode, to write the register */
1937 if (alps_monitor_mode(psmouse
, true))
1940 ret
= alps_monitor_mode_write_reg(psmouse
, 0x000, reg_val
);
1942 if (alps_monitor_mode(psmouse
, false))
1948 static int alps_get_status(struct psmouse
*psmouse
, char *param
)
1950 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
1951 if (alps_rpt_cmd(psmouse
, 0, PSMOUSE_CMD_DISABLE
, param
))
1958 * Turn touchpad tapping on or off. The sequences are:
1959 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1960 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1961 * My guess that 0xE9 (GetInfo) is here as a sync point.
1962 * For models that also have stickpointer (DualPoints) its tapping
1963 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1964 * we don't fiddle with it.
1966 static int alps_tap_mode(struct psmouse
*psmouse
, int enable
)
1968 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
1969 int cmd
= enable
? PSMOUSE_CMD_SETRATE
: PSMOUSE_CMD_SETRES
;
1970 unsigned char tap_arg
= enable
? 0x0A : 0x00;
1971 unsigned char param
[4];
1973 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
) ||
1974 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1975 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_DISABLE
) ||
1976 ps2_command(ps2dev
, &tap_arg
, cmd
))
1979 if (alps_get_status(psmouse
, param
))
1986 * alps_poll() - poll the touchpad for current motion packet.
1989 static int alps_poll(struct psmouse
*psmouse
)
1991 struct alps_data
*priv
= psmouse
->private;
1992 unsigned char buf
[sizeof(psmouse
->packet
)];
1995 if (priv
->flags
& ALPS_PASS
)
1996 alps_passthrough_mode_v2(psmouse
, true);
1998 poll_failed
= ps2_command(&psmouse
->ps2dev
, buf
,
1999 PSMOUSE_CMD_POLL
| (psmouse
->pktsize
<< 8)) < 0;
2001 if (priv
->flags
& ALPS_PASS
)
2002 alps_passthrough_mode_v2(psmouse
, false);
2004 if (poll_failed
|| (buf
[0] & priv
->mask0
) != priv
->byte0
)
2007 if ((psmouse
->badbyte
& 0xc8) == 0x08) {
2009 * Poll the track stick ...
2011 if (ps2_command(&psmouse
->ps2dev
, buf
, PSMOUSE_CMD_POLL
| (3 << 8)))
2015 memcpy(psmouse
->packet
, buf
, sizeof(buf
));
2019 static int alps_hw_init_v1_v2(struct psmouse
*psmouse
)
2021 struct alps_data
*priv
= psmouse
->private;
2023 if ((priv
->flags
& ALPS_PASS
) &&
2024 alps_passthrough_mode_v2(psmouse
, true)) {
2028 if (alps_tap_mode(psmouse
, true)) {
2029 psmouse_warn(psmouse
, "Failed to enable hardware tapping\n");
2033 if (alps_absolute_mode_v1_v2(psmouse
)) {
2034 psmouse_err(psmouse
, "Failed to enable absolute mode\n");
2038 if ((priv
->flags
& ALPS_PASS
) &&
2039 alps_passthrough_mode_v2(psmouse
, false)) {
2043 /* ALPS needs stream mode, otherwise it won't report any data */
2044 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
)) {
2045 psmouse_err(psmouse
, "Failed to enable stream mode\n");
2052 /* Must be in passthrough mode when calling this function */
2053 static int alps_trackstick_enter_extended_mode_v3_v6(struct psmouse
*psmouse
)
2055 unsigned char param
[2] = {0xC8, 0x14};
2057 if (ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
2058 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
2059 ps2_command(&psmouse
->ps2dev
, NULL
, PSMOUSE_CMD_SETSCALE11
) ||
2060 ps2_command(&psmouse
->ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2061 ps2_command(&psmouse
->ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
))
2067 static int alps_hw_init_v6(struct psmouse
*psmouse
)
2071 /* Enter passthrough mode to let trackpoint enter 6byte raw mode */
2072 if (alps_passthrough_mode_v2(psmouse
, true))
2075 ret
= alps_trackstick_enter_extended_mode_v3_v6(psmouse
);
2077 if (alps_passthrough_mode_v2(psmouse
, false))
2083 if (alps_absolute_mode_v6(psmouse
)) {
2084 psmouse_err(psmouse
, "Failed to enable absolute mode\n");
2092 * Enable or disable passthrough mode to the trackstick.
2094 static int alps_passthrough_mode_v3(struct psmouse
*psmouse
,
2095 int reg_base
, bool enable
)
2097 int reg_val
, ret
= -1;
2099 if (alps_enter_command_mode(psmouse
))
2102 reg_val
= alps_command_mode_read_reg(psmouse
, reg_base
+ 0x0008);
2111 ret
= __alps_command_mode_write_reg(psmouse
, reg_val
);
2114 if (alps_exit_command_mode(psmouse
))
2119 /* Must be in command mode when calling this function */
2120 static int alps_absolute_mode_v3(struct psmouse
*psmouse
)
2124 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0004);
2129 if (__alps_command_mode_write_reg(psmouse
, reg_val
))
2135 static int alps_probe_trackstick_v3_v7(struct psmouse
*psmouse
, int reg_base
)
2137 int ret
= -EIO
, reg_val
;
2139 if (alps_enter_command_mode(psmouse
))
2142 reg_val
= alps_command_mode_read_reg(psmouse
, reg_base
+ 0x08);
2146 /* bit 7: trackstick is present */
2147 ret
= reg_val
& 0x80 ? 0 : -ENODEV
;
2150 alps_exit_command_mode(psmouse
);
2154 static int alps_setup_trackstick_v3(struct psmouse
*psmouse
, int reg_base
)
2158 unsigned char param
[4];
2161 * We need to configure trackstick to report data for touchpad in
2162 * extended format. And also we need to tell touchpad to expect data
2163 * from trackstick in extended format. Without this configuration
2164 * trackstick packets sent from touchpad are in basic format which is
2165 * different from what we expect.
2168 if (alps_passthrough_mode_v3(psmouse
, reg_base
, true))
2172 * E7 report for the trackstick
2174 * There have been reports of failures to seem to trace back
2175 * to the above trackstick check failing. When these occur
2176 * this E7 report fails, so when that happens we continue
2177 * with the assumption that there isn't a trackstick after
2180 if (alps_rpt_cmd(psmouse
, 0, PSMOUSE_CMD_SETSCALE21
, param
)) {
2181 psmouse_warn(psmouse
, "Failed to initialize trackstick (E7 report failed)\n");
2184 psmouse_dbg(psmouse
, "trackstick E7 report: %3ph\n", param
);
2185 if (alps_trackstick_enter_extended_mode_v3_v6(psmouse
)) {
2186 psmouse_err(psmouse
, "Failed to enter into trackstick extended mode\n");
2191 if (alps_passthrough_mode_v3(psmouse
, reg_base
, false))
2197 if (alps_enter_command_mode(psmouse
))
2200 reg_val
= alps_command_mode_read_reg(psmouse
, reg_base
+ 0x08);
2201 if (reg_val
== -1) {
2205 * Tell touchpad that trackstick is now in extended mode.
2206 * If bit 1 isn't set the packet format is different.
2209 if (__alps_command_mode_write_reg(psmouse
, reg_val
))
2213 if (alps_exit_command_mode(psmouse
))
2219 static int alps_hw_init_v3(struct psmouse
*psmouse
)
2221 struct alps_data
*priv
= psmouse
->private;
2222 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2224 unsigned char param
[4];
2226 if ((priv
->flags
& ALPS_DUALPOINT
) &&
2227 alps_setup_trackstick_v3(psmouse
, ALPS_REG_BASE_PINNACLE
) == -EIO
)
2230 if (alps_enter_command_mode(psmouse
) ||
2231 alps_absolute_mode_v3(psmouse
)) {
2232 psmouse_err(psmouse
, "Failed to enter absolute mode\n");
2236 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0006);
2239 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x01))
2242 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0007);
2245 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x01))
2248 if (alps_command_mode_read_reg(psmouse
, 0x0144) == -1)
2250 if (__alps_command_mode_write_reg(psmouse
, 0x04))
2253 if (alps_command_mode_read_reg(psmouse
, 0x0159) == -1)
2255 if (__alps_command_mode_write_reg(psmouse
, 0x03))
2258 if (alps_command_mode_read_reg(psmouse
, 0x0163) == -1)
2260 if (alps_command_mode_write_reg(psmouse
, 0x0163, 0x03))
2263 if (alps_command_mode_read_reg(psmouse
, 0x0162) == -1)
2265 if (alps_command_mode_write_reg(psmouse
, 0x0162, 0x04))
2268 alps_exit_command_mode(psmouse
);
2270 /* Set rate and enable data reporting */
2272 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
) ||
2273 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
)) {
2274 psmouse_err(psmouse
, "Failed to enable data reporting\n");
2282 * Leaving the touchpad in command mode will essentially render
2283 * it unusable until the machine reboots, so exit it here just
2286 alps_exit_command_mode(psmouse
);
2290 static int alps_get_v3_v7_resolution(struct psmouse
*psmouse
, int reg_pitch
)
2292 int reg
, x_pitch
, y_pitch
, x_electrode
, y_electrode
, x_phys
, y_phys
;
2293 struct alps_data
*priv
= psmouse
->private;
2295 reg
= alps_command_mode_read_reg(psmouse
, reg_pitch
);
2299 x_pitch
= (char)(reg
<< 4) >> 4; /* sign extend lower 4 bits */
2300 x_pitch
= 50 + 2 * x_pitch
; /* In 0.1 mm units */
2302 y_pitch
= (char)reg
>> 4; /* sign extend upper 4 bits */
2303 y_pitch
= 36 + 2 * y_pitch
; /* In 0.1 mm units */
2305 reg
= alps_command_mode_read_reg(psmouse
, reg_pitch
+ 1);
2309 x_electrode
= (char)(reg
<< 4) >> 4; /* sign extend lower 4 bits */
2310 x_electrode
= 17 + x_electrode
;
2312 y_electrode
= (char)reg
>> 4; /* sign extend upper 4 bits */
2313 y_electrode
= 13 + y_electrode
;
2315 x_phys
= x_pitch
* (x_electrode
- 1); /* In 0.1 mm units */
2316 y_phys
= y_pitch
* (y_electrode
- 1); /* In 0.1 mm units */
2318 priv
->x_res
= priv
->x_max
* 10 / x_phys
; /* units / mm */
2319 priv
->y_res
= priv
->y_max
* 10 / y_phys
; /* units / mm */
2321 psmouse_dbg(psmouse
,
2322 "pitch %dx%d num-electrodes %dx%d physical size %dx%d mm res %dx%d\n",
2323 x_pitch
, y_pitch
, x_electrode
, y_electrode
,
2324 x_phys
/ 10, y_phys
/ 10, priv
->x_res
, priv
->y_res
);
2329 static int alps_hw_init_rushmore_v3(struct psmouse
*psmouse
)
2331 struct alps_data
*priv
= psmouse
->private;
2332 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2333 int reg_val
, ret
= -1;
2335 if (priv
->flags
& ALPS_DUALPOINT
) {
2336 reg_val
= alps_setup_trackstick_v3(psmouse
,
2337 ALPS_REG_BASE_RUSHMORE
);
2338 if (reg_val
== -EIO
)
2342 if (alps_enter_command_mode(psmouse
) ||
2343 alps_command_mode_read_reg(psmouse
, 0xc2d9) == -1 ||
2344 alps_command_mode_write_reg(psmouse
, 0xc2cb, 0x00))
2347 if (alps_get_v3_v7_resolution(psmouse
, 0xc2da))
2350 reg_val
= alps_command_mode_read_reg(psmouse
, 0xc2c6);
2353 if (__alps_command_mode_write_reg(psmouse
, reg_val
& 0xfd))
2356 if (alps_command_mode_write_reg(psmouse
, 0xc2c9, 0x64))
2359 /* enter absolute mode */
2360 reg_val
= alps_command_mode_read_reg(psmouse
, 0xc2c4);
2363 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x02))
2366 alps_exit_command_mode(psmouse
);
2367 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2370 alps_exit_command_mode(psmouse
);
2374 /* Must be in command mode when calling this function */
2375 static int alps_absolute_mode_v4(struct psmouse
*psmouse
)
2379 reg_val
= alps_command_mode_read_reg(psmouse
, 0x0004);
2384 if (__alps_command_mode_write_reg(psmouse
, reg_val
))
2390 static int alps_hw_init_v4(struct psmouse
*psmouse
)
2392 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2393 unsigned char param
[4];
2395 if (alps_enter_command_mode(psmouse
))
2398 if (alps_absolute_mode_v4(psmouse
)) {
2399 psmouse_err(psmouse
, "Failed to enter absolute mode\n");
2403 if (alps_command_mode_write_reg(psmouse
, 0x0007, 0x8c))
2406 if (alps_command_mode_write_reg(psmouse
, 0x0149, 0x03))
2409 if (alps_command_mode_write_reg(psmouse
, 0x0160, 0x03))
2412 if (alps_command_mode_write_reg(psmouse
, 0x017f, 0x15))
2415 if (alps_command_mode_write_reg(psmouse
, 0x0151, 0x01))
2418 if (alps_command_mode_write_reg(psmouse
, 0x0168, 0x03))
2421 if (alps_command_mode_write_reg(psmouse
, 0x014a, 0x03))
2424 if (alps_command_mode_write_reg(psmouse
, 0x0161, 0x03))
2427 alps_exit_command_mode(psmouse
);
2430 * This sequence changes the output from a 9-byte to an
2431 * 8-byte format. All the same data seems to be present,
2432 * just in a more compact format.
2437 if (ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2438 ps2_command(ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
) ||
2439 ps2_command(ps2dev
, ¶m
[2], PSMOUSE_CMD_SETRATE
) ||
2440 ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETID
))
2443 /* Set rate and enable data reporting */
2445 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_SETRATE
) ||
2446 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
)) {
2447 psmouse_err(psmouse
, "Failed to enable data reporting\n");
2455 * Leaving the touchpad in command mode will essentially render
2456 * it unusable until the machine reboots, so exit it here just
2459 alps_exit_command_mode(psmouse
);
2463 static int alps_get_otp_values_ss4_v2(struct psmouse
*psmouse
,
2464 unsigned char index
, unsigned char otp
[])
2466 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2470 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2471 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2472 ps2_command(ps2dev
, otp
, PSMOUSE_CMD_GETINFO
))
2478 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2479 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2480 ps2_command(ps2dev
, otp
, PSMOUSE_CMD_GETINFO
))
2489 static int alps_update_device_area_ss4_v2(unsigned char otp
[][4],
2490 struct alps_data
*priv
)
2492 int num_x_electrode
;
2493 int num_y_electrode
;
2494 int x_pitch
, y_pitch
, x_phys
, y_phys
;
2496 if (IS_SS4PLUS_DEV(priv
->dev_id
)) {
2498 SS4PLUS_NUMSENSOR_XOFFSET
+ (otp
[0][2] & 0x0F);
2500 SS4PLUS_NUMSENSOR_YOFFSET
+ ((otp
[0][2] >> 4) & 0x0F);
2503 (num_x_electrode
- 1) * SS4PLUS_COUNT_PER_ELECTRODE
;
2505 (num_y_electrode
- 1) * SS4PLUS_COUNT_PER_ELECTRODE
;
2507 x_pitch
= (otp
[0][1] & 0x0F) + SS4PLUS_MIN_PITCH_MM
;
2508 y_pitch
= ((otp
[0][1] >> 4) & 0x0F) + SS4PLUS_MIN_PITCH_MM
;
2512 SS4_NUMSENSOR_XOFFSET
+ (otp
[1][0] & 0x0F);
2514 SS4_NUMSENSOR_YOFFSET
+ ((otp
[1][0] >> 4) & 0x0F);
2517 (num_x_electrode
- 1) * SS4_COUNT_PER_ELECTRODE
;
2519 (num_y_electrode
- 1) * SS4_COUNT_PER_ELECTRODE
;
2521 x_pitch
= ((otp
[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM
;
2522 y_pitch
= ((otp
[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM
;
2525 x_phys
= x_pitch
* (num_x_electrode
- 1); /* In 0.1 mm units */
2526 y_phys
= y_pitch
* (num_y_electrode
- 1); /* In 0.1 mm units */
2528 priv
->x_res
= priv
->x_max
* 10 / x_phys
; /* units / mm */
2529 priv
->y_res
= priv
->y_max
* 10 / y_phys
; /* units / mm */
2534 static int alps_update_btn_info_ss4_v2(unsigned char otp
[][4],
2535 struct alps_data
*priv
)
2537 unsigned char is_btnless
;
2539 if (IS_SS4PLUS_DEV(priv
->dev_id
))
2540 is_btnless
= (otp
[1][0] >> 1) & 0x01;
2542 is_btnless
= (otp
[1][1] >> 3) & 0x01;
2545 priv
->flags
|= ALPS_BUTTONPAD
;
2550 static int alps_update_dual_info_ss4_v2(unsigned char otp
[][4],
2551 struct alps_data
*priv
,
2552 struct psmouse
*psmouse
)
2554 bool is_dual
= false;
2556 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2558 if (IS_SS4PLUS_DEV(priv
->dev_id
)) {
2559 is_dual
= (otp
[0][0] >> 4) & 0x01;
2562 /* For support TrackStick of Thinkpad L/E series */
2563 if (alps_exit_command_mode(psmouse
) == 0 &&
2564 alps_enter_command_mode(psmouse
) == 0) {
2565 reg_val
= alps_command_mode_read_reg(psmouse
,
2568 alps_exit_command_mode(psmouse
);
2569 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2571 if (reg_val
== 0x0C || reg_val
== 0x1D)
2577 priv
->flags
|= ALPS_DUALPOINT
|
2578 ALPS_DUALPOINT_WITH_PRESSURE
;
2583 static int alps_set_defaults_ss4_v2(struct psmouse
*psmouse
,
2584 struct alps_data
*priv
)
2586 unsigned char otp
[2][4];
2588 memset(otp
, 0, sizeof(otp
));
2590 if (alps_get_otp_values_ss4_v2(psmouse
, 1, &otp
[1][0]) ||
2591 alps_get_otp_values_ss4_v2(psmouse
, 0, &otp
[0][0]))
2594 alps_update_device_area_ss4_v2(otp
, priv
);
2596 alps_update_btn_info_ss4_v2(otp
, priv
);
2598 alps_update_dual_info_ss4_v2(otp
, priv
, psmouse
);
2603 static int alps_dolphin_get_device_area(struct psmouse
*psmouse
,
2604 struct alps_data
*priv
)
2606 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2607 unsigned char param
[4] = {0};
2608 int num_x_electrode
, num_y_electrode
;
2610 if (alps_enter_command_mode(psmouse
))
2614 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_RESET_WRAP
) ||
2615 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2616 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETPOLL
) ||
2617 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2618 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
))
2621 if (ps2_command(ps2dev
, param
, PSMOUSE_CMD_GETINFO
))
2625 * Dolphin's sensor line number is not fixed. It can be calculated
2626 * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET.
2627 * Further more, we can get device's x_max and y_max by multiplying
2628 * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE.
2630 * e.g. When we get register's sensor_x = 11 & sensor_y = 8,
2631 * real sensor line number X = 11 + 8 = 19, and
2632 * real sensor line number Y = 8 + 1 = 9.
2633 * So, x_max = (19 - 1) * 64 = 1152, and
2634 * y_max = (9 - 1) * 64 = 512.
2636 num_x_electrode
= DOLPHIN_PROFILE_XOFFSET
+ (param
[2] & 0x0F);
2637 num_y_electrode
= DOLPHIN_PROFILE_YOFFSET
+ ((param
[2] >> 4) & 0x0F);
2638 priv
->x_bits
= num_x_electrode
;
2639 priv
->y_bits
= num_y_electrode
;
2640 priv
->x_max
= (num_x_electrode
- 1) * DOLPHIN_COUNT_PER_ELECTRODE
;
2641 priv
->y_max
= (num_y_electrode
- 1) * DOLPHIN_COUNT_PER_ELECTRODE
;
2643 if (alps_exit_command_mode(psmouse
))
2649 static int alps_hw_init_dolphin_v1(struct psmouse
*psmouse
)
2651 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2652 unsigned char param
[2];
2654 /* This is dolphin "v1" as empirically defined by florin9doi */
2658 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2659 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2660 ps2_command(ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
))
2666 static int alps_hw_init_v7(struct psmouse
*psmouse
)
2668 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2669 int reg_val
, ret
= -1;
2671 if (alps_enter_command_mode(psmouse
) ||
2672 alps_command_mode_read_reg(psmouse
, 0xc2d9) == -1)
2675 if (alps_get_v3_v7_resolution(psmouse
, 0xc397))
2678 if (alps_command_mode_write_reg(psmouse
, 0xc2c9, 0x64))
2681 reg_val
= alps_command_mode_read_reg(psmouse
, 0xc2c4);
2684 if (__alps_command_mode_write_reg(psmouse
, reg_val
| 0x02))
2687 alps_exit_command_mode(psmouse
);
2688 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2691 alps_exit_command_mode(psmouse
);
2695 static int alps_hw_init_ss4_v2(struct psmouse
*psmouse
)
2697 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
2698 char param
[2] = {0x64, 0x28};
2701 /* enter absolute mode */
2702 if (ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2703 ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_SETSTREAM
) ||
2704 ps2_command(ps2dev
, ¶m
[0], PSMOUSE_CMD_SETRATE
) ||
2705 ps2_command(ps2dev
, ¶m
[1], PSMOUSE_CMD_SETRATE
)) {
2709 /* T.B.D. Decread noise packet number, delete in the future */
2710 if (alps_exit_command_mode(psmouse
) ||
2711 alps_enter_command_mode(psmouse
) ||
2712 alps_command_mode_write_reg(psmouse
, 0x001D, 0x20)) {
2715 alps_exit_command_mode(psmouse
);
2717 return ps2_command(ps2dev
, NULL
, PSMOUSE_CMD_ENABLE
);
2720 alps_exit_command_mode(psmouse
);
2724 static int alps_set_protocol(struct psmouse
*psmouse
,
2725 struct alps_data
*priv
,
2726 const struct alps_protocol_info
*protocol
)
2728 psmouse
->private = priv
;
2730 timer_setup(&priv
->timer
, alps_flush_packet
, 0);
2732 priv
->proto_version
= protocol
->version
;
2733 priv
->byte0
= protocol
->byte0
;
2734 priv
->mask0
= protocol
->mask0
;
2735 priv
->flags
= protocol
->flags
;
2742 switch (priv
->proto_version
) {
2745 priv
->hw_init
= alps_hw_init_v1_v2
;
2746 priv
->process_packet
= alps_process_packet_v1_v2
;
2747 priv
->set_abs_params
= alps_set_abs_params_st
;
2750 if (dmi_check_system(alps_dmi_has_separate_stick_buttons
))
2751 priv
->flags
|= ALPS_STICK_BITS
;
2755 priv
->hw_init
= alps_hw_init_v3
;
2756 priv
->process_packet
= alps_process_packet_v3
;
2757 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2758 priv
->decode_fields
= alps_decode_pinnacle
;
2759 priv
->nibble_commands
= alps_v3_nibble_commands
;
2760 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2762 if (alps_probe_trackstick_v3_v7(psmouse
,
2763 ALPS_REG_BASE_PINNACLE
) < 0)
2764 priv
->flags
&= ~ALPS_DUALPOINT
;
2768 case ALPS_PROTO_V3_RUSHMORE
:
2769 priv
->hw_init
= alps_hw_init_rushmore_v3
;
2770 priv
->process_packet
= alps_process_packet_v3
;
2771 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2772 priv
->decode_fields
= alps_decode_rushmore
;
2773 priv
->nibble_commands
= alps_v3_nibble_commands
;
2774 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2778 if (alps_probe_trackstick_v3_v7(psmouse
,
2779 ALPS_REG_BASE_RUSHMORE
) < 0)
2780 priv
->flags
&= ~ALPS_DUALPOINT
;
2785 priv
->hw_init
= alps_hw_init_v4
;
2786 priv
->process_packet
= alps_process_packet_v4
;
2787 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2788 priv
->nibble_commands
= alps_v4_nibble_commands
;
2789 priv
->addr_command
= PSMOUSE_CMD_DISABLE
;
2793 priv
->hw_init
= alps_hw_init_dolphin_v1
;
2794 priv
->process_packet
= alps_process_touchpad_packet_v3_v5
;
2795 priv
->decode_fields
= alps_decode_dolphin
;
2796 priv
->set_abs_params
= alps_set_abs_params_semi_mt
;
2797 priv
->nibble_commands
= alps_v3_nibble_commands
;
2798 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2802 if (alps_dolphin_get_device_area(psmouse
, priv
))
2808 priv
->hw_init
= alps_hw_init_v6
;
2809 priv
->process_packet
= alps_process_packet_v6
;
2810 priv
->set_abs_params
= alps_set_abs_params_st
;
2811 priv
->nibble_commands
= alps_v6_nibble_commands
;
2817 priv
->hw_init
= alps_hw_init_v7
;
2818 priv
->process_packet
= alps_process_packet_v7
;
2819 priv
->decode_fields
= alps_decode_packet_v7
;
2820 priv
->set_abs_params
= alps_set_abs_params_v7
;
2821 priv
->nibble_commands
= alps_v3_nibble_commands
;
2822 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2823 priv
->x_max
= 0xfff;
2824 priv
->y_max
= 0x7ff;
2826 if (priv
->fw_ver
[1] != 0xba)
2827 priv
->flags
|= ALPS_BUTTONPAD
;
2829 if (alps_probe_trackstick_v3_v7(psmouse
, ALPS_REG_BASE_V7
) < 0)
2830 priv
->flags
&= ~ALPS_DUALPOINT
;
2835 priv
->hw_init
= alps_hw_init_ss4_v2
;
2836 priv
->process_packet
= alps_process_packet_ss4_v2
;
2837 priv
->decode_fields
= alps_decode_ss4_v2
;
2838 priv
->set_abs_params
= alps_set_abs_params_ss4_v2
;
2839 priv
->nibble_commands
= alps_v3_nibble_commands
;
2840 priv
->addr_command
= PSMOUSE_CMD_RESET_WRAP
;
2842 if (alps_set_defaults_ss4_v2(psmouse
, priv
))
2851 static const struct alps_protocol_info
*alps_match_table(unsigned char *e7
,
2854 const struct alps_model_info
*model
;
2857 for (i
= 0; i
< ARRAY_SIZE(alps_model_data
); i
++) {
2858 model
= &alps_model_data
[i
];
2860 if (!memcmp(e7
, model
->signature
, sizeof(model
->signature
)))
2861 return &model
->protocol_info
;
2867 static int alps_identify(struct psmouse
*psmouse
, struct alps_data
*priv
)
2869 const struct alps_protocol_info
*protocol
;
2870 unsigned char e6
[4], e7
[4], ec
[4];
2874 * First try "E6 report".
2875 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
2876 * The bits 0-2 of the first byte will be 1s if some buttons are
2879 if (alps_rpt_cmd(psmouse
, PSMOUSE_CMD_SETRES
,
2880 PSMOUSE_CMD_SETSCALE11
, e6
))
2883 if ((e6
[0] & 0xf8) != 0 || e6
[1] != 0 || (e6
[2] != 10 && e6
[2] != 100))
2887 * Now get the "E7" and "EC" reports. These will uniquely identify
2888 * most ALPS touchpads.
2890 if (alps_rpt_cmd(psmouse
, PSMOUSE_CMD_SETRES
,
2891 PSMOUSE_CMD_SETSCALE21
, e7
) ||
2892 alps_rpt_cmd(psmouse
, PSMOUSE_CMD_SETRES
,
2893 PSMOUSE_CMD_RESET_WRAP
, ec
) ||
2894 alps_exit_command_mode(psmouse
))
2897 protocol
= alps_match_table(e7
, ec
);
2899 if (e7
[0] == 0x73 && e7
[1] == 0x02 && e7
[2] == 0x64 &&
2901 protocol
= &alps_v4_protocol_data
;
2902 } else if (e7
[0] == 0x73 && e7
[1] == 0x03 && e7
[2] == 0x50 &&
2903 ec
[0] == 0x73 && (ec
[1] == 0x01 || ec
[1] == 0x02)) {
2904 protocol
= &alps_v5_protocol_data
;
2905 } else if (ec
[0] == 0x88 &&
2906 ((ec
[1] & 0xf0) == 0xb0 || (ec
[1] & 0xf0) == 0xc0)) {
2907 protocol
= &alps_v7_protocol_data
;
2908 } else if (ec
[0] == 0x88 && ec
[1] == 0x08) {
2909 protocol
= &alps_v3_rushmore_data
;
2910 } else if (ec
[0] == 0x88 && ec
[1] == 0x07 &&
2911 ec
[2] >= 0x90 && ec
[2] <= 0x9d) {
2912 protocol
= &alps_v3_protocol_data
;
2913 } else if (e7
[0] == 0x73 && e7
[1] == 0x03 &&
2914 (e7
[2] == 0x14 || e7
[2] == 0x28)) {
2915 protocol
= &alps_v8_protocol_data
;
2916 } else if (e7
[0] == 0x73 && e7
[1] == 0x03 && e7
[2] == 0xc8) {
2917 protocol
= &alps_v9_protocol_data
;
2918 psmouse_warn(psmouse
,
2919 "Unsupported ALPS V9 touchpad: E7=%3ph, EC=%3ph\n",
2923 psmouse_dbg(psmouse
,
2924 "Likely not an ALPS touchpad: E7=%3ph, EC=%3ph\n", e7
, ec
);
2930 /* Save Device ID and Firmware version */
2931 memcpy(priv
->dev_id
, e7
, 3);
2932 memcpy(priv
->fw_ver
, ec
, 3);
2933 error
= alps_set_protocol(psmouse
, priv
, protocol
);
2941 static int alps_reconnect(struct psmouse
*psmouse
)
2943 struct alps_data
*priv
= psmouse
->private;
2945 psmouse_reset(psmouse
);
2947 if (alps_identify(psmouse
, priv
) < 0)
2950 return priv
->hw_init(psmouse
);
2953 static void alps_disconnect(struct psmouse
*psmouse
)
2955 struct alps_data
*priv
= psmouse
->private;
2957 psmouse_reset(psmouse
);
2958 del_timer_sync(&priv
->timer
);
2960 input_unregister_device(priv
->dev2
);
2961 if (!IS_ERR_OR_NULL(priv
->dev3
))
2962 input_unregister_device(priv
->dev3
);
2966 static void alps_set_abs_params_st(struct alps_data
*priv
,
2967 struct input_dev
*dev1
)
2969 input_set_abs_params(dev1
, ABS_X
, 0, priv
->x_max
, 0, 0);
2970 input_set_abs_params(dev1
, ABS_Y
, 0, priv
->y_max
, 0, 0);
2971 input_set_abs_params(dev1
, ABS_PRESSURE
, 0, 127, 0, 0);
2974 static void alps_set_abs_params_mt_common(struct alps_data
*priv
,
2975 struct input_dev
*dev1
)
2977 input_set_abs_params(dev1
, ABS_MT_POSITION_X
, 0, priv
->x_max
, 0, 0);
2978 input_set_abs_params(dev1
, ABS_MT_POSITION_Y
, 0, priv
->y_max
, 0, 0);
2980 input_abs_set_res(dev1
, ABS_MT_POSITION_X
, priv
->x_res
);
2981 input_abs_set_res(dev1
, ABS_MT_POSITION_Y
, priv
->y_res
);
2983 set_bit(BTN_TOOL_TRIPLETAP
, dev1
->keybit
);
2984 set_bit(BTN_TOOL_QUADTAP
, dev1
->keybit
);
2987 static void alps_set_abs_params_semi_mt(struct alps_data
*priv
,
2988 struct input_dev
*dev1
)
2990 alps_set_abs_params_mt_common(priv
, dev1
);
2991 input_set_abs_params(dev1
, ABS_PRESSURE
, 0, 127, 0, 0);
2993 input_mt_init_slots(dev1
, MAX_TOUCHES
,
2994 INPUT_MT_POINTER
| INPUT_MT_DROP_UNUSED
|
2998 static void alps_set_abs_params_v7(struct alps_data
*priv
,
2999 struct input_dev
*dev1
)
3001 alps_set_abs_params_mt_common(priv
, dev1
);
3002 set_bit(BTN_TOOL_QUINTTAP
, dev1
->keybit
);
3004 input_mt_init_slots(dev1
, MAX_TOUCHES
,
3005 INPUT_MT_POINTER
| INPUT_MT_DROP_UNUSED
|
3008 set_bit(BTN_TOOL_QUINTTAP
, dev1
->keybit
);
3011 static void alps_set_abs_params_ss4_v2(struct alps_data
*priv
,
3012 struct input_dev
*dev1
)
3014 alps_set_abs_params_mt_common(priv
, dev1
);
3015 input_set_abs_params(dev1
, ABS_PRESSURE
, 0, 127, 0, 0);
3016 set_bit(BTN_TOOL_QUINTTAP
, dev1
->keybit
);
3018 input_mt_init_slots(dev1
, MAX_TOUCHES
,
3019 INPUT_MT_POINTER
| INPUT_MT_DROP_UNUSED
|
3023 int alps_init(struct psmouse
*psmouse
)
3025 struct alps_data
*priv
= psmouse
->private;
3026 struct input_dev
*dev1
= psmouse
->dev
;
3029 error
= priv
->hw_init(psmouse
);
3034 * Undo part of setup done for us by psmouse core since touchpad
3035 * is not a relative device.
3037 __clear_bit(EV_REL
, dev1
->evbit
);
3038 __clear_bit(REL_X
, dev1
->relbit
);
3039 __clear_bit(REL_Y
, dev1
->relbit
);
3042 * Now set up our capabilities.
3044 dev1
->evbit
[BIT_WORD(EV_KEY
)] |= BIT_MASK(EV_KEY
);
3045 dev1
->keybit
[BIT_WORD(BTN_TOUCH
)] |= BIT_MASK(BTN_TOUCH
);
3046 dev1
->keybit
[BIT_WORD(BTN_TOOL_FINGER
)] |= BIT_MASK(BTN_TOOL_FINGER
);
3047 dev1
->keybit
[BIT_WORD(BTN_LEFT
)] |=
3048 BIT_MASK(BTN_LEFT
) | BIT_MASK(BTN_RIGHT
);
3050 dev1
->evbit
[BIT_WORD(EV_ABS
)] |= BIT_MASK(EV_ABS
);
3052 priv
->set_abs_params(priv
, dev1
);
3054 if (priv
->flags
& ALPS_WHEEL
) {
3055 dev1
->evbit
[BIT_WORD(EV_REL
)] |= BIT_MASK(EV_REL
);
3056 dev1
->relbit
[BIT_WORD(REL_WHEEL
)] |= BIT_MASK(REL_WHEEL
);
3059 if (priv
->flags
& (ALPS_FW_BK_1
| ALPS_FW_BK_2
)) {
3060 dev1
->keybit
[BIT_WORD(BTN_FORWARD
)] |= BIT_MASK(BTN_FORWARD
);
3061 dev1
->keybit
[BIT_WORD(BTN_BACK
)] |= BIT_MASK(BTN_BACK
);
3064 if (priv
->flags
& ALPS_FOUR_BUTTONS
) {
3065 dev1
->keybit
[BIT_WORD(BTN_0
)] |= BIT_MASK(BTN_0
);
3066 dev1
->keybit
[BIT_WORD(BTN_1
)] |= BIT_MASK(BTN_1
);
3067 dev1
->keybit
[BIT_WORD(BTN_2
)] |= BIT_MASK(BTN_2
);
3068 dev1
->keybit
[BIT_WORD(BTN_3
)] |= BIT_MASK(BTN_3
);
3069 } else if (priv
->flags
& ALPS_BUTTONPAD
) {
3070 set_bit(INPUT_PROP_BUTTONPAD
, dev1
->propbit
);
3071 clear_bit(BTN_RIGHT
, dev1
->keybit
);
3073 dev1
->keybit
[BIT_WORD(BTN_MIDDLE
)] |= BIT_MASK(BTN_MIDDLE
);
3076 if (priv
->flags
& ALPS_DUALPOINT
) {
3077 struct input_dev
*dev2
;
3079 dev2
= input_allocate_device();
3081 psmouse_err(psmouse
,
3082 "failed to allocate trackstick device\n");
3087 snprintf(priv
->phys2
, sizeof(priv
->phys2
), "%s/input1",
3088 psmouse
->ps2dev
.serio
->phys
);
3089 dev2
->phys
= priv
->phys2
;
3092 * format of input device name is: "protocol vendor name"
3093 * see function psmouse_switch_protocol() in psmouse-base.c
3095 dev2
->name
= "AlpsPS/2 ALPS DualPoint Stick";
3097 dev2
->id
.bustype
= BUS_I8042
;
3098 dev2
->id
.vendor
= 0x0002;
3099 dev2
->id
.product
= PSMOUSE_ALPS
;
3100 dev2
->id
.version
= priv
->proto_version
;
3101 dev2
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
3103 input_set_capability(dev2
, EV_REL
, REL_X
);
3104 input_set_capability(dev2
, EV_REL
, REL_Y
);
3105 if (priv
->flags
& ALPS_DUALPOINT_WITH_PRESSURE
) {
3106 input_set_capability(dev2
, EV_ABS
, ABS_PRESSURE
);
3107 input_set_abs_params(dev2
, ABS_PRESSURE
, 0, 127, 0, 0);
3109 input_set_capability(dev2
, EV_KEY
, BTN_LEFT
);
3110 input_set_capability(dev2
, EV_KEY
, BTN_RIGHT
);
3111 input_set_capability(dev2
, EV_KEY
, BTN_MIDDLE
);
3113 __set_bit(INPUT_PROP_POINTER
, dev2
->propbit
);
3114 __set_bit(INPUT_PROP_POINTING_STICK
, dev2
->propbit
);
3116 error
= input_register_device(dev2
);
3118 psmouse_err(psmouse
,
3119 "failed to register trackstick device: %d\n",
3121 input_free_device(dev2
);
3128 priv
->psmouse
= psmouse
;
3130 INIT_DELAYED_WORK(&priv
->dev3_register_work
,
3131 alps_register_bare_ps2_mouse
);
3133 psmouse
->protocol_handler
= alps_process_byte
;
3134 psmouse
->poll
= alps_poll
;
3135 psmouse
->disconnect
= alps_disconnect
;
3136 psmouse
->reconnect
= alps_reconnect
;
3137 psmouse
->pktsize
= priv
->proto_version
== ALPS_PROTO_V4
? 8 : 6;
3139 /* We are having trouble resyncing ALPS touchpads so disable it for now */
3140 psmouse
->resync_time
= 0;
3142 /* Allow 2 invalid packets without resetting device */
3143 psmouse
->resetafter
= psmouse
->pktsize
* 2;
3148 psmouse_reset(psmouse
);
3150 * Even though we did not allocate psmouse->private we do free
3153 kfree(psmouse
->private);
3154 psmouse
->private = NULL
;
3158 int alps_detect(struct psmouse
*psmouse
, bool set_properties
)
3160 struct alps_data
*priv
;
3163 error
= alps_identify(psmouse
, NULL
);
3168 * Reset the device to make sure it is fully operational:
3169 * on some laptops, like certain Dell Latitudes, we may
3170 * fail to properly detect presence of trackstick if device
3171 * has not been reset.
3173 psmouse_reset(psmouse
);
3175 priv
= kzalloc(sizeof(struct alps_data
), GFP_KERNEL
);
3179 error
= alps_identify(psmouse
, priv
);
3185 if (set_properties
) {
3186 psmouse
->vendor
= "ALPS";
3187 psmouse
->name
= priv
->flags
& ALPS_DUALPOINT
?
3188 "DualPoint TouchPad" : "GlidePoint";
3189 psmouse
->model
= priv
->proto_version
;
3192 * Destroy alps_data structure we allocated earlier since
3193 * this was just a "trial run". Otherwise we'll keep it
3194 * to be used by alps_init() which has to be called if
3195 * we succeed and set_properties is true.
3198 psmouse
->private = NULL
;