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>
28 * Definitions for ALPS version 3 and 4 command mode protocol
30 #define ALPS_CMD_NIBBLE_10 0x01f2
32 #define ALPS_REG_BASE_RUSHMORE 0xc2c0
33 #define ALPS_REG_BASE_PINNACLE 0x0000
35 static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
36 { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
37 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
38 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
39 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
40 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
41 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
42 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
43 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
44 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
45 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
46 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
47 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
48 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
49 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
50 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
51 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
54 static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
55 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
56 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
57 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
58 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
59 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
60 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
61 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
62 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
63 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
64 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
65 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
66 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
67 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
68 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
69 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
70 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
73 static const struct alps_nibble_commands alps_v6_nibble_commands[] = {
74 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
75 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 1 */
76 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 2 */
77 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 3 */
78 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 4 */
79 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 5 */
80 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 6 */
81 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 7 */
82 { PSMOUSE_CMD_GETID, 0x00 }, /* 8 */
83 { PSMOUSE_CMD_GETINFO, 0x00 }, /* 9 */
84 { PSMOUSE_CMD_SETRES, 0x00 }, /* a */
85 { PSMOUSE_CMD_SETRES, 0x01 }, /* b */
86 { PSMOUSE_CMD_SETRES, 0x02 }, /* c */
87 { PSMOUSE_CMD_SETRES, 0x03 }, /* d */
88 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* e */
89 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
93 #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
94 #define ALPS_PASS 0x04 /* device has a pass-through port */
96 #define ALPS_WHEEL 0x08 /* hardware wheel present */
97 #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
98 #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
99 #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
100 #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
101 6-byte ALPS packet */
102 #define ALPS_BUTTONPAD 0x200 /* device is a clickpad */
104 static const struct alps_model_info alps_model_data[] = {
105 { { 0x32, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT } }, /* Toshiba Salellite Pro M10 */
106 { { 0x33, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V1, 0x88, 0xf8, 0 } }, /* UMAX-530T */
107 { { 0x53, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
108 { { 0x53, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
109 { { 0x60, 0x03, 0xc8 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } }, /* HP ze1115 */
110 { { 0x63, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
111 { { 0x63, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
112 { { 0x63, 0x02, 0x28 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 } }, /* Fujitsu Siemens S6010 */
113 { { 0x63, 0x02, 0x3c }, 0x00, { ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL } }, /* Toshiba Satellite S2400-103 */
114 { { 0x63, 0x02, 0x50 }, 0x00, { ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 } }, /* NEC Versa L320 */
115 { { 0x63, 0x02, 0x64 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
116 { { 0x63, 0x03, 0xc8 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT } }, /* Dell Latitude D800 */
117 { { 0x73, 0x00, 0x0a }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT } }, /* ThinkPad R61 8918-5QG */
118 { { 0x73, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
119 { { 0x73, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 } }, /* Ahtec Laptop */
122 * XXX This entry is suspicious. First byte has zero lower nibble,
123 * which is what a normal mouse would report. Also, the value 0x0e
124 * isn't valid per PS/2 spec.
126 { { 0x20, 0x02, 0x0e }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT } },
128 { { 0x22, 0x02, 0x0a }, 0x00, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT } },
129 { { 0x22, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT } }, /* Dell Latitude D600 */
130 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
131 { { 0x62, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xcf, 0xcf,
132 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED } },
133 { { 0x73, 0x00, 0x14 }, 0x00, { ALPS_PROTO_V6, 0xff, 0xff, ALPS_DUALPOINT } }, /* Dell XT2 */
134 { { 0x73, 0x02, 0x50 }, 0x00, { ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS } }, /* Dell Vostro 1400 */
135 { { 0x52, 0x01, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xff, 0xff,
136 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED } }, /* Toshiba Tecra A11-11L */
137 { { 0x73, 0x02, 0x64 }, 0x8a, { ALPS_PROTO_V4, 0x8f, 0x8f, 0 } },
140 static const struct alps_protocol_info alps_v3_protocol_data = {
141 ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT
144 static const struct alps_protocol_info alps_v3_rushmore_data = {
145 ALPS_PROTO_V3_RUSHMORE, 0x8f, 0x8f, ALPS_DUALPOINT
148 static const struct alps_protocol_info alps_v5_protocol_data = {
149 ALPS_PROTO_V5, 0xc8, 0xd8, 0
152 static const struct alps_protocol_info alps_v7_protocol_data = {
153 ALPS_PROTO_V7, 0x48, 0x48, ALPS_DUALPOINT
156 static const struct alps_protocol_info alps_v8_protocol_data = {
157 ALPS_PROTO_V8, 0x18, 0x18, 0
160 static void alps_set_abs_params_st(struct alps_data *priv,
161 struct input_dev *dev1);
162 static void alps_set_abs_params_mt(struct alps_data *priv,
163 struct input_dev *dev1);
164 static void alps_set_abs_params_v7(struct alps_data *priv,
165 struct input_dev *dev1);
166 static void alps_set_abs_params_ss4_v2(struct alps_data *priv,
167 struct input_dev *dev1);
169 /* Packet formats are described in Documentation/input/alps.txt */
171 static bool alps_is_valid_first_byte(struct alps_data *priv,
174 return (data & priv->mask0) == priv->byte0;
177 static void alps_report_buttons(struct input_dev *dev1, struct input_dev *dev2,
178 int left, int right, int middle)
180 struct input_dev *dev;
183 * If shared button has already been reported on the
184 * other device (dev2) then this event should be also
185 * sent through that device.
187 dev = (dev2 && test_bit(BTN_LEFT, dev2->key)) ? dev2 : dev1;
188 input_report_key(dev, BTN_LEFT, left);
190 dev = (dev2 && test_bit(BTN_RIGHT, dev2->key)) ? dev2 : dev1;
191 input_report_key(dev, BTN_RIGHT, right);
193 dev = (dev2 && test_bit(BTN_MIDDLE, dev2->key)) ? dev2 : dev1;
194 input_report_key(dev, BTN_MIDDLE, middle);
197 * Sync the _other_ device now, we'll do the first
198 * device later once we report the rest of the events.
204 static void alps_process_packet_v1_v2(struct psmouse *psmouse)
206 struct alps_data *priv = psmouse->private;
207 unsigned char *packet = psmouse->packet;
208 struct input_dev *dev = psmouse->dev;
209 struct input_dev *dev2 = priv->dev2;
210 int x, y, z, ges, fin, left, right, middle;
211 int back = 0, forward = 0;
213 if (priv->proto_version == ALPS_PROTO_V1) {
214 left = packet[2] & 0x10;
215 right = packet[2] & 0x08;
217 x = packet[1] | ((packet[0] & 0x07) << 7);
218 y = packet[4] | ((packet[3] & 0x07) << 7);
221 left = packet[3] & 1;
222 right = packet[3] & 2;
223 middle = packet[3] & 4;
224 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
225 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
229 if (priv->flags & ALPS_FW_BK_1) {
230 back = packet[0] & 0x10;
231 forward = packet[2] & 4;
234 if (priv->flags & ALPS_FW_BK_2) {
235 back = packet[3] & 4;
236 forward = packet[2] & 4;
237 if ((middle = forward && back))
244 if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
245 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
246 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
248 alps_report_buttons(dev2, dev, left, right, middle);
254 alps_report_buttons(dev, dev2, left, right, middle);
256 /* Convert hardware tap to a reasonable Z value */
261 * A "tap and drag" operation is reported by the hardware as a transition
262 * from (!fin && ges) to (fin && ges). This should be translated to the
263 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
265 if (ges && fin && !priv->prev_fin) {
266 input_report_abs(dev, ABS_X, x);
267 input_report_abs(dev, ABS_Y, y);
268 input_report_abs(dev, ABS_PRESSURE, 0);
269 input_report_key(dev, BTN_TOOL_FINGER, 0);
272 priv->prev_fin = fin;
275 input_report_key(dev, BTN_TOUCH, 1);
277 input_report_key(dev, BTN_TOUCH, 0);
280 input_report_abs(dev, ABS_X, x);
281 input_report_abs(dev, ABS_Y, y);
284 input_report_abs(dev, ABS_PRESSURE, z);
285 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
287 if (priv->flags & ALPS_WHEEL)
288 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
290 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
291 input_report_key(dev, BTN_FORWARD, forward);
292 input_report_key(dev, BTN_BACK, back);
295 if (priv->flags & ALPS_FOUR_BUTTONS) {
296 input_report_key(dev, BTN_0, packet[2] & 4);
297 input_report_key(dev, BTN_1, packet[0] & 0x10);
298 input_report_key(dev, BTN_2, packet[3] & 4);
299 input_report_key(dev, BTN_3, packet[0] & 0x20);
306 * Process bitmap data for V5 protocols. Return value is null.
308 * The bitmaps don't have enough data to track fingers, so this function
309 * only generates points representing a bounding box of at most two contacts.
310 * These two points are returned in fields->mt.
312 static void alps_process_bitmap_dolphin(struct alps_data *priv,
313 struct alps_fields *fields)
315 int box_middle_x, box_middle_y;
316 unsigned int x_map, y_map;
317 unsigned char start_bit, end_bit;
318 unsigned char x_msb, x_lsb, y_msb, y_lsb;
320 x_map = fields->x_map;
321 y_map = fields->y_map;
323 if (!x_map || !y_map)
326 /* Get Most-significant and Least-significant bit */
332 /* Most-significant bit should never exceed max sensor line number */
333 if (x_msb > priv->x_bits || y_msb > priv->y_bits)
336 if (fields->fingers > 1) {
337 start_bit = priv->x_bits - x_msb;
338 end_bit = priv->x_bits - x_lsb;
339 box_middle_x = (priv->x_max * (start_bit + end_bit)) /
340 (2 * (priv->x_bits - 1));
342 start_bit = y_lsb - 1;
344 box_middle_y = (priv->y_max * (start_bit + end_bit)) /
345 (2 * (priv->y_bits - 1));
346 fields->mt[0] = fields->st;
347 fields->mt[1].x = 2 * box_middle_x - fields->mt[0].x;
348 fields->mt[1].y = 2 * box_middle_y - fields->mt[0].y;
352 static void alps_get_bitmap_points(unsigned int map,
353 struct alps_bitmap_point *low,
354 struct alps_bitmap_point *high,
357 struct alps_bitmap_point *point;
358 int i, bit, prev_bit = 0;
361 for (i = 0; map != 0; i++, map >>= 1) {
365 point->start_bit = i;
379 * Process bitmap data from v3 and v4 protocols. Returns the number of
380 * fingers detected. A return value of 0 means at least one of the
383 * The bitmaps don't have enough data to track fingers, so this function
384 * only generates points representing a bounding box of all contacts.
385 * These points are returned in fields->mt when the return value
388 static int alps_process_bitmap(struct alps_data *priv,
389 struct alps_fields *fields)
391 int i, fingers_x = 0, fingers_y = 0, fingers, closest;
392 struct alps_bitmap_point x_low = {0,}, x_high = {0,};
393 struct alps_bitmap_point y_low = {0,}, y_high = {0,};
394 struct input_mt_pos corner[4];
396 if (!fields->x_map || !fields->y_map)
399 alps_get_bitmap_points(fields->x_map, &x_low, &x_high, &fingers_x);
400 alps_get_bitmap_points(fields->y_map, &y_low, &y_high, &fingers_y);
403 * Fingers can overlap, so we use the maximum count of fingers
404 * on either axis as the finger count.
406 fingers = max(fingers_x, fingers_y);
409 * If an axis reports only a single contact, we have overlapping or
410 * adjacent fingers. Divide the single contact between the two points.
412 if (fingers_x == 1) {
413 i = (x_low.num_bits - 1) / 2;
414 x_low.num_bits = x_low.num_bits - i;
415 x_high.start_bit = x_low.start_bit + i;
416 x_high.num_bits = max(i, 1);
418 if (fingers_y == 1) {
419 i = (y_low.num_bits - 1) / 2;
420 y_low.num_bits = y_low.num_bits - i;
421 y_high.start_bit = y_low.start_bit + i;
422 y_high.num_bits = max(i, 1);
425 /* top-left corner */
427 (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) /
428 (2 * (priv->x_bits - 1));
430 (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) /
431 (2 * (priv->y_bits - 1));
433 /* top-right corner */
435 (priv->x_max * (2 * x_high.start_bit + x_high.num_bits - 1)) /
436 (2 * (priv->x_bits - 1));
438 (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) /
439 (2 * (priv->y_bits - 1));
441 /* bottom-right corner */
443 (priv->x_max * (2 * x_high.start_bit + x_high.num_bits - 1)) /
444 (2 * (priv->x_bits - 1));
446 (priv->y_max * (2 * y_high.start_bit + y_high.num_bits - 1)) /
447 (2 * (priv->y_bits - 1));
449 /* bottom-left corner */
451 (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) /
452 (2 * (priv->x_bits - 1));
454 (priv->y_max * (2 * y_high.start_bit + y_high.num_bits - 1)) /
455 (2 * (priv->y_bits - 1));
457 /* y-bitmap order is reversed, except on rushmore */
458 if (priv->proto_version != ALPS_PROTO_V3_RUSHMORE) {
459 for (i = 0; i < 4; i++)
460 corner[i].y = priv->y_max - corner[i].y;
464 * We only select a corner for the second touch once per 2 finger
465 * touch sequence to avoid the chosen corner (and thus the coordinates)
466 * jumping around when the first touch is in the middle.
468 if (priv->second_touch == -1) {
469 /* Find corner closest to our st coordinates */
470 closest = 0x7fffffff;
471 for (i = 0; i < 4; i++) {
472 int dx = fields->st.x - corner[i].x;
473 int dy = fields->st.y - corner[i].y;
474 int distance = dx * dx + dy * dy;
476 if (distance < closest) {
477 priv->second_touch = i;
481 /* And select the opposite corner to use for the 2nd touch */
482 priv->second_touch = (priv->second_touch + 2) % 4;
485 fields->mt[0] = fields->st;
486 fields->mt[1] = corner[priv->second_touch];
491 static void alps_set_slot(struct input_dev *dev, int slot, int x, int y)
493 input_mt_slot(dev, slot);
494 input_mt_report_slot_state(dev, MT_TOOL_FINGER, true);
495 input_report_abs(dev, ABS_MT_POSITION_X, x);
496 input_report_abs(dev, ABS_MT_POSITION_Y, y);
499 static void alps_report_mt_data(struct psmouse *psmouse, int n)
501 struct alps_data *priv = psmouse->private;
502 struct input_dev *dev = psmouse->dev;
503 struct alps_fields *f = &priv->f;
504 int i, slot[MAX_TOUCHES];
506 input_mt_assign_slots(dev, slot, f->mt, n, 0);
507 for (i = 0; i < n; i++)
508 alps_set_slot(dev, slot[i], f->mt[i].x, f->mt[i].y);
510 input_mt_sync_frame(dev);
513 static void alps_report_semi_mt_data(struct psmouse *psmouse, int fingers)
515 struct alps_data *priv = psmouse->private;
516 struct input_dev *dev = psmouse->dev;
517 struct alps_fields *f = &priv->f;
519 /* Use st data when we don't have mt data */
521 f->mt[0].x = f->st.x;
522 f->mt[0].y = f->st.y;
523 fingers = f->pressure > 0 ? 1 : 0;
524 priv->second_touch = -1;
528 alps_set_slot(dev, 0, f->mt[0].x, f->mt[0].y);
530 alps_set_slot(dev, 1, f->mt[1].x, f->mt[1].y);
531 input_mt_sync_frame(dev);
533 input_mt_report_finger_count(dev, fingers);
535 input_report_key(dev, BTN_LEFT, f->left);
536 input_report_key(dev, BTN_RIGHT, f->right);
537 input_report_key(dev, BTN_MIDDLE, f->middle);
539 input_report_abs(dev, ABS_PRESSURE, f->pressure);
544 static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
546 struct alps_data *priv = psmouse->private;
547 unsigned char *packet = psmouse->packet;
548 struct input_dev *dev = priv->dev2;
549 int x, y, z, left, right, middle;
551 /* It should be a DualPoint when received trackstick packet */
552 if (!(priv->flags & ALPS_DUALPOINT)) {
553 psmouse_warn(psmouse,
554 "Rejected trackstick packet from non DualPoint device");
558 /* Sanity check packet */
559 if (!(packet[0] & 0x40)) {
560 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
565 * There's a special packet that seems to indicate the end
566 * of a stream of trackstick data. Filter these out.
568 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
571 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
572 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
573 z = (packet[4] & 0x7c) >> 2;
576 * The x and y values tend to be quite large, and when used
577 * alone the trackstick is difficult to use. Scale them down
583 input_report_rel(dev, REL_X, x);
584 input_report_rel(dev, REL_Y, -y);
587 * Most ALPS models report the trackstick buttons in the touchpad
588 * packets, but a few report them here. No reliable way has been
589 * found to differentiate between the models upfront, so we enable
590 * the quirk in response to seeing a button press in the trackstick
593 left = packet[3] & 0x01;
594 right = packet[3] & 0x02;
595 middle = packet[3] & 0x04;
597 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
598 (left || right || middle))
599 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
601 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
602 input_report_key(dev, BTN_LEFT, left);
603 input_report_key(dev, BTN_RIGHT, right);
604 input_report_key(dev, BTN_MIDDLE, middle);
611 static void alps_decode_buttons_v3(struct alps_fields *f, unsigned char *p)
613 f->left = !!(p[3] & 0x01);
614 f->right = !!(p[3] & 0x02);
615 f->middle = !!(p[3] & 0x04);
617 f->ts_left = !!(p[3] & 0x10);
618 f->ts_right = !!(p[3] & 0x20);
619 f->ts_middle = !!(p[3] & 0x40);
622 static int alps_decode_pinnacle(struct alps_fields *f, unsigned char *p,
623 struct psmouse *psmouse)
625 f->first_mp = !!(p[4] & 0x40);
626 f->is_mp = !!(p[0] & 0x40);
629 f->fingers = (p[5] & 0x3) + 1;
630 f->x_map = ((p[4] & 0x7e) << 8) |
631 ((p[1] & 0x7f) << 2) |
632 ((p[0] & 0x30) >> 4);
633 f->y_map = ((p[3] & 0x70) << 4) |
634 ((p[2] & 0x7f) << 1) |
637 f->st.x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) |
638 ((p[0] & 0x30) >> 4);
639 f->st.y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f);
640 f->pressure = p[5] & 0x7f;
642 alps_decode_buttons_v3(f, p);
648 static int alps_decode_rushmore(struct alps_fields *f, unsigned char *p,
649 struct psmouse *psmouse)
651 f->first_mp = !!(p[4] & 0x40);
652 f->is_mp = !!(p[5] & 0x40);
655 f->fingers = max((p[5] & 0x3), ((p[5] >> 2) & 0x3)) + 1;
656 f->x_map = ((p[5] & 0x10) << 11) |
657 ((p[4] & 0x7e) << 8) |
658 ((p[1] & 0x7f) << 2) |
659 ((p[0] & 0x30) >> 4);
660 f->y_map = ((p[5] & 0x20) << 6) |
661 ((p[3] & 0x70) << 4) |
662 ((p[2] & 0x7f) << 1) |
665 f->st.x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) |
666 ((p[0] & 0x30) >> 4);
667 f->st.y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f);
668 f->pressure = p[5] & 0x7f;
670 alps_decode_buttons_v3(f, p);
676 static int alps_decode_dolphin(struct alps_fields *f, unsigned char *p,
677 struct psmouse *psmouse)
680 struct alps_data *priv = psmouse->private;
682 f->first_mp = !!(p[0] & 0x02);
683 f->is_mp = !!(p[0] & 0x20);
686 f->st.x = ((p[1] & 0x7f) | ((p[4] & 0x0f) << 7));
687 f->st.y = ((p[2] & 0x7f) | ((p[4] & 0xf0) << 3));
688 f->pressure = (p[0] & 4) ? 0 : p[5] & 0x7f;
689 alps_decode_buttons_v3(f, p);
691 f->fingers = ((p[0] & 0x6) >> 1 |
694 palm_data = (p[1] & 0x7f) |
695 ((p[2] & 0x7f) << 7) |
696 ((p[4] & 0x7f) << 14) |
697 ((p[5] & 0x7f) << 21) |
698 ((p[3] & 0x07) << 28) |
699 (((u64)p[3] & 0x70) << 27) |
700 (((u64)p[0] & 0x01) << 34);
702 /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */
703 f->y_map = palm_data & (BIT(priv->y_bits) - 1);
705 /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */
706 f->x_map = (palm_data >> priv->y_bits) &
707 (BIT(priv->x_bits) - 1);
713 static void alps_process_touchpad_packet_v3_v5(struct psmouse *psmouse)
715 struct alps_data *priv = psmouse->private;
716 unsigned char *packet = psmouse->packet;
717 struct input_dev *dev2 = priv->dev2;
718 struct alps_fields *f = &priv->f;
721 memset(f, 0, sizeof(*f));
723 priv->decode_fields(f, packet, psmouse);
726 * There's no single feature of touchpad position and bitmap packets
727 * that can be used to distinguish between them. We rely on the fact
728 * that a bitmap packet should always follow a position packet with
729 * bit 6 of packet[4] set.
731 if (priv->multi_packet) {
733 * Sometimes a position packet will indicate a multi-packet
734 * sequence, but then what follows is another position
735 * packet. Check for this, and when it happens process the
736 * position packet as usual.
739 fingers = f->fingers;
741 * Bitmap processing uses position packet's coordinate
742 * data, so we need to do decode it first.
744 priv->decode_fields(f, priv->multi_data, psmouse);
746 if (priv->proto_version == ALPS_PROTO_V3 ||
747 priv->proto_version == ALPS_PROTO_V3_RUSHMORE) {
748 if (alps_process_bitmap(priv, f) == 0)
749 fingers = 0; /* Use st data */
752 * Since Dolphin's finger number is reliable,
753 * there is no need to compare with bmap_fn.
755 alps_process_bitmap_dolphin(priv, f);
758 priv->multi_packet = 0;
763 * Bit 6 of byte 0 is not usually set in position packets. The only
764 * times it seems to be set is in situations where the data is
765 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
766 * this combined with the fact that this bit is useful for filtering
767 * out misidentified bitmap packets, we reject anything with this
773 if (!priv->multi_packet && f->first_mp) {
774 priv->multi_packet = 1;
775 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
779 priv->multi_packet = 0;
782 * Sometimes the hardware sends a single packet with z = 0
783 * in the middle of a stream. Real releases generate packets
784 * with x, y, and z all zero, so these seem to be flukes.
787 if (f->st.x && f->st.y && !f->pressure)
790 alps_report_semi_mt_data(psmouse, fingers);
792 if ((priv->flags & ALPS_DUALPOINT) &&
793 !(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
794 input_report_key(dev2, BTN_LEFT, f->ts_left);
795 input_report_key(dev2, BTN_RIGHT, f->ts_right);
796 input_report_key(dev2, BTN_MIDDLE, f->ts_middle);
801 static void alps_process_packet_v3(struct psmouse *psmouse)
803 unsigned char *packet = psmouse->packet;
806 * v3 protocol packets come in three types, two representing
807 * touchpad data and one representing trackstick data.
808 * Trackstick packets seem to be distinguished by always
809 * having 0x3f in the last byte. This value has never been
810 * observed in the last byte of either of the other types
813 if (packet[5] == 0x3f) {
814 alps_process_trackstick_packet_v3(psmouse);
818 alps_process_touchpad_packet_v3_v5(psmouse);
821 static void alps_process_packet_v6(struct psmouse *psmouse)
823 struct alps_data *priv = psmouse->private;
824 unsigned char *packet = psmouse->packet;
825 struct input_dev *dev = psmouse->dev;
826 struct input_dev *dev2 = priv->dev2;
827 int x, y, z, left, right, middle;
830 * We can use Byte5 to distinguish if the packet is from Touchpad
835 if (packet[5] == 0x7F) {
836 /* It should be a DualPoint when received Trackpoint packet */
837 if (!(priv->flags & ALPS_DUALPOINT)) {
838 psmouse_warn(psmouse,
839 "Rejected trackstick packet from non DualPoint device");
843 /* Trackpoint packet */
844 x = packet[1] | ((packet[3] & 0x20) << 2);
845 y = packet[2] | ((packet[3] & 0x40) << 1);
847 left = packet[3] & 0x01;
848 right = packet[3] & 0x02;
849 middle = packet[3] & 0x04;
851 /* To prevent the cursor jump when finger lifted */
852 if (x == 0x7F && y == 0x7F && z == 0x7F)
855 /* Divide 4 since trackpoint's speed is too fast */
856 input_report_rel(dev2, REL_X, (char)x / 4);
857 input_report_rel(dev2, REL_Y, -((char)y / 4));
859 input_report_key(dev2, BTN_LEFT, left);
860 input_report_key(dev2, BTN_RIGHT, right);
861 input_report_key(dev2, BTN_MIDDLE, middle);
867 /* Touchpad packet */
868 x = packet[1] | ((packet[3] & 0x78) << 4);
869 y = packet[2] | ((packet[4] & 0x78) << 4);
871 left = packet[3] & 0x01;
872 right = packet[3] & 0x02;
875 input_report_key(dev, BTN_TOUCH, 1);
877 input_report_key(dev, BTN_TOUCH, 0);
880 input_report_abs(dev, ABS_X, x);
881 input_report_abs(dev, ABS_Y, y);
884 input_report_abs(dev, ABS_PRESSURE, z);
885 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
887 /* v6 touchpad does not have middle button */
888 input_report_key(dev, BTN_LEFT, left);
889 input_report_key(dev, BTN_RIGHT, right);
894 static void alps_process_packet_v4(struct psmouse *psmouse)
896 struct alps_data *priv = psmouse->private;
897 unsigned char *packet = psmouse->packet;
898 struct alps_fields *f = &priv->f;
902 * v4 has a 6-byte encoding for bitmap data, but this data is
903 * broken up between 3 normal packets. Use priv->multi_packet to
904 * track our position in the bitmap packet.
906 if (packet[6] & 0x40) {
907 /* sync, reset position */
908 priv->multi_packet = 0;
911 if (WARN_ON_ONCE(priv->multi_packet > 2))
914 offset = 2 * priv->multi_packet;
915 priv->multi_data[offset] = packet[6];
916 priv->multi_data[offset + 1] = packet[7];
918 f->left = !!(packet[4] & 0x01);
919 f->right = !!(packet[4] & 0x02);
921 f->st.x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
922 ((packet[0] & 0x30) >> 4);
923 f->st.y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
924 f->pressure = packet[5] & 0x7f;
926 if (++priv->multi_packet > 2) {
927 priv->multi_packet = 0;
929 f->x_map = ((priv->multi_data[2] & 0x1f) << 10) |
930 ((priv->multi_data[3] & 0x60) << 3) |
931 ((priv->multi_data[0] & 0x3f) << 2) |
932 ((priv->multi_data[1] & 0x60) >> 5);
933 f->y_map = ((priv->multi_data[5] & 0x01) << 10) |
934 ((priv->multi_data[3] & 0x1f) << 5) |
935 (priv->multi_data[1] & 0x1f);
937 f->fingers = alps_process_bitmap(priv, f);
940 alps_report_semi_mt_data(psmouse, f->fingers);
943 static bool alps_is_valid_package_v7(struct psmouse *psmouse)
945 switch (psmouse->pktcnt) {
947 return (psmouse->packet[2] & 0x40) == 0x40;
949 return (psmouse->packet[3] & 0x48) == 0x48;
951 return (psmouse->packet[5] & 0x40) == 0x00;
956 static unsigned char alps_get_packet_id_v7(char *byte)
958 unsigned char packet_id;
961 packet_id = V7_PACKET_ID_TWO;
962 else if (byte[4] & 0x01)
963 packet_id = V7_PACKET_ID_MULTI;
964 else if ((byte[0] & 0x10) && !(byte[4] & 0x43))
965 packet_id = V7_PACKET_ID_NEW;
966 else if (byte[1] == 0x00 && byte[4] == 0x00)
967 packet_id = V7_PACKET_ID_IDLE;
969 packet_id = V7_PACKET_ID_UNKNOWN;
974 static void alps_get_finger_coordinate_v7(struct input_mt_pos *mt,
976 unsigned char pkt_id)
978 mt[0].x = ((pkt[2] & 0x80) << 4);
979 mt[0].x |= ((pkt[2] & 0x3F) << 5);
980 mt[0].x |= ((pkt[3] & 0x30) >> 1);
981 mt[0].x |= (pkt[3] & 0x07);
982 mt[0].y = (pkt[1] << 3) | (pkt[0] & 0x07);
984 mt[1].x = ((pkt[3] & 0x80) << 4);
985 mt[1].x |= ((pkt[4] & 0x80) << 3);
986 mt[1].x |= ((pkt[4] & 0x3F) << 4);
987 mt[1].y = ((pkt[5] & 0x80) << 3);
988 mt[1].y |= ((pkt[5] & 0x3F) << 4);
991 case V7_PACKET_ID_TWO:
996 case V7_PACKET_ID_MULTI:
999 mt[1].y |= ((pkt[4] & 0x02) << 4);
1003 case V7_PACKET_ID_NEW:
1005 mt[1].x |= (pkt[0] & 0x20);
1010 mt[0].y = 0x7FF - mt[0].y;
1011 mt[1].y = 0x7FF - mt[1].y;
1014 static int alps_get_mt_count(struct input_mt_pos *mt)
1018 for (i = 0; i < MAX_TOUCHES; i++) {
1019 if (mt[i].x != 0 || mt[i].y != 0)
1026 static int alps_decode_packet_v7(struct alps_fields *f,
1028 struct psmouse *psmouse)
1030 struct alps_data *priv = psmouse->private;
1031 unsigned char pkt_id;
1033 pkt_id = alps_get_packet_id_v7(p);
1034 if (pkt_id == V7_PACKET_ID_IDLE)
1036 if (pkt_id == V7_PACKET_ID_UNKNOWN)
1039 * NEW packets are send to indicate a discontinuity in the finger
1040 * coordinate reporting. Specifically a finger may have moved from
1041 * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for
1044 * NEW packets have 3 problems:
1045 * 1) They do not contain middle / right button info (on non clickpads)
1046 * this can be worked around by preserving the old button state
1047 * 2) They do not contain an accurate fingercount, and they are
1048 * typically send when the number of fingers changes. We cannot use
1049 * the old finger count as that may mismatch with the amount of
1050 * touch coordinates we've available in the NEW packet
1051 * 3) Their x data for the second touch is inaccurate leading to
1052 * a possible jump of the x coordinate by 16 units when the first
1053 * non NEW packet comes in
1054 * Since problems 2 & 3 cannot be worked around, just ignore them.
1056 if (pkt_id == V7_PACKET_ID_NEW)
1059 alps_get_finger_coordinate_v7(f->mt, p, pkt_id);
1061 if (pkt_id == V7_PACKET_ID_TWO)
1062 f->fingers = alps_get_mt_count(f->mt);
1063 else /* pkt_id == V7_PACKET_ID_MULTI */
1064 f->fingers = 3 + (p[5] & 0x03);
1066 f->left = (p[0] & 0x80) >> 7;
1067 if (priv->flags & ALPS_BUTTONPAD) {
1073 f->right = (p[0] & 0x20) >> 5;
1074 f->middle = (p[0] & 0x10) >> 4;
1077 /* Sometimes a single touch is reported in mt[1] rather then mt[0] */
1078 if (f->fingers == 1 && f->mt[0].x == 0 && f->mt[0].y == 0) {
1079 f->mt[0].x = f->mt[1].x;
1080 f->mt[0].y = f->mt[1].y;
1088 static void alps_process_trackstick_packet_v7(struct psmouse *psmouse)
1090 struct alps_data *priv = psmouse->private;
1091 unsigned char *packet = psmouse->packet;
1092 struct input_dev *dev2 = priv->dev2;
1093 int x, y, z, left, right, middle;
1095 /* It should be a DualPoint when received trackstick packet */
1096 if (!(priv->flags & ALPS_DUALPOINT)) {
1097 psmouse_warn(psmouse,
1098 "Rejected trackstick packet from non DualPoint device");
1102 x = ((packet[2] & 0xbf)) | ((packet[3] & 0x10) << 2);
1103 y = (packet[3] & 0x07) | (packet[4] & 0xb8) |
1104 ((packet[3] & 0x20) << 1);
1105 z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1);
1107 left = (packet[1] & 0x01);
1108 right = (packet[1] & 0x02) >> 1;
1109 middle = (packet[1] & 0x04) >> 2;
1111 /* Divide 2 since trackpoint's speed is too fast */
1112 input_report_rel(dev2, REL_X, (char)x / 2);
1113 input_report_rel(dev2, REL_Y, -((char)y / 2));
1115 input_report_key(dev2, BTN_LEFT, left);
1116 input_report_key(dev2, BTN_RIGHT, right);
1117 input_report_key(dev2, BTN_MIDDLE, middle);
1122 static void alps_process_touchpad_packet_v7(struct psmouse *psmouse)
1124 struct alps_data *priv = psmouse->private;
1125 struct input_dev *dev = psmouse->dev;
1126 struct alps_fields *f = &priv->f;
1128 memset(f, 0, sizeof(*f));
1130 if (priv->decode_fields(f, psmouse->packet, psmouse))
1133 alps_report_mt_data(psmouse, alps_get_mt_count(f->mt));
1135 input_mt_report_finger_count(dev, f->fingers);
1137 input_report_key(dev, BTN_LEFT, f->left);
1138 input_report_key(dev, BTN_RIGHT, f->right);
1139 input_report_key(dev, BTN_MIDDLE, f->middle);
1144 static void alps_process_packet_v7(struct psmouse *psmouse)
1146 unsigned char *packet = psmouse->packet;
1148 if (packet[0] == 0x48 && (packet[4] & 0x47) == 0x06)
1149 alps_process_trackstick_packet_v7(psmouse);
1151 alps_process_touchpad_packet_v7(psmouse);
1154 static unsigned char alps_get_pkt_id_ss4_v2(unsigned char *byte)
1156 unsigned char pkt_id = SS4_PACKET_ID_IDLE;
1158 if (byte[0] == 0x18 && byte[1] == 0x10 && byte[2] == 0x00 &&
1159 (byte[3] & 0x88) == 0x08 && byte[4] == 0x10 && byte[5] == 0x00) {
1160 pkt_id = SS4_PACKET_ID_IDLE;
1161 } else if (!(byte[3] & 0x10)) {
1162 pkt_id = SS4_PACKET_ID_ONE;
1163 } else if (!(byte[3] & 0x20)) {
1164 pkt_id = SS4_PACKET_ID_TWO;
1166 pkt_id = SS4_PACKET_ID_MULTI;
1172 static int alps_decode_ss4_v2(struct alps_fields *f,
1173 unsigned char *p, struct psmouse *psmouse)
1175 struct alps_data *priv = psmouse->private;
1176 unsigned char pkt_id;
1177 unsigned int no_data_x, no_data_y;
1179 pkt_id = alps_get_pkt_id_ss4_v2(p);
1181 /* Current packet is 1Finger coordinate packet */
1183 case SS4_PACKET_ID_ONE:
1184 f->mt[0].x = SS4_1F_X_V2(p);
1185 f->mt[0].y = SS4_1F_Y_V2(p);
1186 f->pressure = ((SS4_1F_Z_V2(p)) * 2) & 0x7f;
1192 case SS4_PACKET_ID_TWO:
1193 if (priv->flags & ALPS_BUTTONPAD) {
1194 f->mt[0].x = SS4_BTL_MF_X_V2(p, 0);
1195 f->mt[0].y = SS4_BTL_MF_Y_V2(p, 0);
1196 f->mt[1].x = SS4_BTL_MF_X_V2(p, 1);
1197 f->mt[1].y = SS4_BTL_MF_Y_V2(p, 1);
1199 f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
1200 f->mt[0].y = SS4_STD_MF_Y_V2(p, 0);
1201 f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
1202 f->mt[1].y = SS4_STD_MF_Y_V2(p, 1);
1204 f->pressure = SS4_MF_Z_V2(p, 0) ? 0x30 : 0;
1206 if (SS4_IS_MF_CONTINUE(p)) {
1216 case SS4_PACKET_ID_MULTI:
1217 if (priv->flags & ALPS_BUTTONPAD) {
1218 f->mt[2].x = SS4_BTL_MF_X_V2(p, 0);
1219 f->mt[2].y = SS4_BTL_MF_Y_V2(p, 0);
1220 f->mt[3].x = SS4_BTL_MF_X_V2(p, 1);
1221 f->mt[3].y = SS4_BTL_MF_Y_V2(p, 1);
1222 no_data_x = SS4_MFPACKET_NO_AX_BL;
1223 no_data_y = SS4_MFPACKET_NO_AY_BL;
1225 f->mt[2].x = SS4_STD_MF_X_V2(p, 0);
1226 f->mt[2].y = SS4_STD_MF_Y_V2(p, 0);
1227 f->mt[3].x = SS4_STD_MF_X_V2(p, 1);
1228 f->mt[3].y = SS4_STD_MF_Y_V2(p, 1);
1229 no_data_x = SS4_MFPACKET_NO_AX;
1230 no_data_y = SS4_MFPACKET_NO_AY;
1236 if (SS4_IS_5F_DETECTED(p)) {
1238 } else if (f->mt[3].x == no_data_x &&
1239 f->mt[3].y == no_data_y) {
1248 case SS4_PACKET_ID_IDLE:
1250 memset(f, 0, sizeof(struct alps_fields));
1254 f->left = !!(SS4_BTN_V2(p) & 0x01);
1255 if (!(priv->flags & ALPS_BUTTONPAD)) {
1256 f->right = !!(SS4_BTN_V2(p) & 0x02);
1257 f->middle = !!(SS4_BTN_V2(p) & 0x04);
1263 static void alps_process_packet_ss4_v2(struct psmouse *psmouse)
1265 struct alps_data *priv = psmouse->private;
1266 unsigned char *packet = psmouse->packet;
1267 struct input_dev *dev = psmouse->dev;
1268 struct alps_fields *f = &priv->f;
1270 memset(f, 0, sizeof(struct alps_fields));
1271 priv->decode_fields(f, packet, psmouse);
1272 if (priv->multi_packet) {
1274 * Sometimes the first packet will indicate a multi-packet
1275 * sequence, but sometimes the next multi-packet would not
1276 * come. Check for this, and when it happens process the
1277 * position packet as usual.
1280 /* Now process the 1st packet */
1281 priv->decode_fields(f, priv->multi_data, psmouse);
1283 priv->multi_packet = 0;
1288 * "f.is_mp" would always be '0' after merging the 1st and 2nd packet.
1289 * When it is set, it means 2nd packet comes without 1st packet come.
1294 /* Save the first packet */
1295 if (!priv->multi_packet && f->first_mp) {
1296 priv->multi_packet = 1;
1297 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
1301 priv->multi_packet = 0;
1303 alps_report_mt_data(psmouse, (f->fingers <= 4) ? f->fingers : 4);
1305 input_mt_report_finger_count(dev, f->fingers);
1307 input_report_key(dev, BTN_LEFT, f->left);
1308 input_report_key(dev, BTN_RIGHT, f->right);
1309 input_report_key(dev, BTN_MIDDLE, f->middle);
1311 input_report_abs(dev, ABS_PRESSURE, f->pressure);
1315 static bool alps_is_valid_package_ss4_v2(struct psmouse *psmouse)
1317 if (psmouse->pktcnt == 4 && ((psmouse->packet[3] & 0x08) != 0x08))
1319 if (psmouse->pktcnt == 6 && ((psmouse->packet[5] & 0x10) != 0x0))
1324 static DEFINE_MUTEX(alps_mutex);
1326 static void alps_register_bare_ps2_mouse(struct work_struct *work)
1328 struct alps_data *priv =
1329 container_of(work, struct alps_data, dev3_register_work.work);
1330 struct psmouse *psmouse = priv->psmouse;
1331 struct input_dev *dev3;
1334 mutex_lock(&alps_mutex);
1339 dev3 = input_allocate_device();
1341 psmouse_err(psmouse, "failed to allocate secondary device\n");
1346 snprintf(priv->phys3, sizeof(priv->phys3), "%s/%s",
1347 psmouse->ps2dev.serio->phys,
1348 (priv->dev2 ? "input2" : "input1"));
1349 dev3->phys = priv->phys3;
1352 * format of input device name is: "protocol vendor name"
1353 * see function psmouse_switch_protocol() in psmouse-base.c
1355 dev3->name = "PS/2 ALPS Mouse";
1357 dev3->id.bustype = BUS_I8042;
1358 dev3->id.vendor = 0x0002;
1359 dev3->id.product = PSMOUSE_PS2;
1360 dev3->id.version = 0x0000;
1361 dev3->dev.parent = &psmouse->ps2dev.serio->dev;
1363 input_set_capability(dev3, EV_REL, REL_X);
1364 input_set_capability(dev3, EV_REL, REL_Y);
1365 input_set_capability(dev3, EV_KEY, BTN_LEFT);
1366 input_set_capability(dev3, EV_KEY, BTN_RIGHT);
1367 input_set_capability(dev3, EV_KEY, BTN_MIDDLE);
1369 __set_bit(INPUT_PROP_POINTER, dev3->propbit);
1371 error = input_register_device(dev3);
1373 psmouse_err(psmouse,
1374 "failed to register secondary device: %d\n",
1376 input_free_device(dev3);
1384 * Save the error code so that we can detect that we
1385 * already tried to create the device.
1388 priv->dev3 = ERR_PTR(error);
1390 mutex_unlock(&alps_mutex);
1393 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
1394 unsigned char packet[],
1395 bool report_buttons)
1397 struct alps_data *priv = psmouse->private;
1398 struct input_dev *dev;
1400 /* Figure out which device to use to report the bare packet */
1401 if (priv->proto_version == ALPS_PROTO_V2 &&
1402 (priv->flags & ALPS_DUALPOINT)) {
1403 /* On V2 devices the DualPoint Stick reports bare packets */
1405 } else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) {
1406 /* Register dev3 mouse if we received PS/2 packet first time */
1407 if (!IS_ERR(priv->dev3))
1408 psmouse_queue_work(psmouse, &priv->dev3_register_work,
1416 alps_report_buttons(dev, NULL,
1417 packet[0] & 1, packet[0] & 2, packet[0] & 4);
1419 input_report_rel(dev, REL_X,
1420 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
1421 input_report_rel(dev, REL_Y,
1422 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
1427 static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
1429 struct alps_data *priv = psmouse->private;
1431 if (psmouse->pktcnt < 6)
1432 return PSMOUSE_GOOD_DATA;
1434 if (psmouse->pktcnt == 6) {
1436 * Start a timer to flush the packet if it ends up last
1437 * 6-byte packet in the stream. Timer needs to fire
1438 * psmouse core times out itself. 20 ms should be enough
1439 * to decide if we are getting more data or not.
1441 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
1442 return PSMOUSE_GOOD_DATA;
1445 del_timer(&priv->timer);
1447 if (psmouse->packet[6] & 0x80) {
1450 * Highest bit is set - that means we either had
1451 * complete ALPS packet and this is start of the
1452 * next packet or we got garbage.
1455 if (((psmouse->packet[3] |
1456 psmouse->packet[4] |
1457 psmouse->packet[5]) & 0x80) ||
1458 (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
1459 psmouse_dbg(psmouse,
1460 "refusing packet %4ph (suspected interleaved ps/2)\n",
1461 psmouse->packet + 3);
1462 return PSMOUSE_BAD_DATA;
1465 priv->process_packet(psmouse);
1467 /* Continue with the next packet */
1468 psmouse->packet[0] = psmouse->packet[6];
1469 psmouse->pktcnt = 1;
1474 * High bit is 0 - that means that we indeed got a PS/2
1475 * packet in the middle of ALPS packet.
1477 * There is also possibility that we got 6-byte ALPS
1478 * packet followed by 3-byte packet from trackpoint. We
1479 * can not distinguish between these 2 scenarios but
1480 * because the latter is unlikely to happen in course of
1481 * normal operation (user would need to press all
1482 * buttons on the pad and start moving trackpoint
1483 * without touching the pad surface) we assume former.
1484 * Even if we are wrong the wost thing that would happen
1485 * the cursor would jump but we should not get protocol
1486 * de-synchronization.
1489 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
1493 * Continue with the standard ALPS protocol handling,
1494 * but make sure we won't process it as an interleaved
1495 * packet again, which may happen if all buttons are
1496 * pressed. To avoid this let's reset the 4th bit which
1499 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
1500 psmouse->pktcnt = 4;
1503 return PSMOUSE_GOOD_DATA;
1506 static void alps_flush_packet(unsigned long data)
1508 struct psmouse *psmouse = (struct psmouse *)data;
1509 struct alps_data *priv = psmouse->private;
1511 serio_pause_rx(psmouse->ps2dev.serio);
1513 if (psmouse->pktcnt == psmouse->pktsize) {
1516 * We did not any more data in reasonable amount of time.
1517 * Validate the last 3 bytes and process as a standard
1520 if ((psmouse->packet[3] |
1521 psmouse->packet[4] |
1522 psmouse->packet[5]) & 0x80) {
1523 psmouse_dbg(psmouse,
1524 "refusing packet %3ph (suspected interleaved ps/2)\n",
1525 psmouse->packet + 3);
1527 priv->process_packet(psmouse);
1529 psmouse->pktcnt = 0;
1532 serio_continue_rx(psmouse->ps2dev.serio);
1535 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
1537 struct alps_data *priv = psmouse->private;
1540 * Check if we are dealing with a bare PS/2 packet, presumably from
1541 * a device connected to the external PS/2 port. Because bare PS/2
1542 * protocol does not have enough constant bits to self-synchronize
1543 * properly we only do this if the device is fully synchronized.
1544 * Can not distinguish V8's first byte from PS/2 packet's
1546 if (priv->proto_version != ALPS_PROTO_V8 &&
1547 !psmouse->out_of_sync_cnt &&
1548 (psmouse->packet[0] & 0xc8) == 0x08) {
1550 if (psmouse->pktcnt == 3) {
1551 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
1553 return PSMOUSE_FULL_PACKET;
1555 return PSMOUSE_GOOD_DATA;
1558 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
1560 if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
1561 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
1562 return alps_handle_interleaved_ps2(psmouse);
1565 if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
1566 psmouse_dbg(psmouse,
1567 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
1568 psmouse->packet[0], priv->mask0, priv->byte0);
1569 return PSMOUSE_BAD_DATA;
1572 /* Bytes 2 - pktsize should have 0 in the highest bit */
1573 if (priv->proto_version < ALPS_PROTO_V5 &&
1574 psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
1575 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
1576 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
1577 psmouse->pktcnt - 1,
1578 psmouse->packet[psmouse->pktcnt - 1]);
1580 if (priv->proto_version == ALPS_PROTO_V3_RUSHMORE &&
1581 psmouse->pktcnt == psmouse->pktsize) {
1583 * Some Dell boxes, such as Latitude E6440 or E7440
1584 * with closed lid, quite often smash last byte of
1585 * otherwise valid packet with 0xff. Given that the
1586 * next packet is very likely to be valid let's
1587 * report PSMOUSE_FULL_PACKET but not process data,
1588 * rather than reporting PSMOUSE_BAD_DATA and
1591 return PSMOUSE_FULL_PACKET;
1594 return PSMOUSE_BAD_DATA;
1597 if ((priv->proto_version == ALPS_PROTO_V7 &&
1598 !alps_is_valid_package_v7(psmouse)) ||
1599 (priv->proto_version == ALPS_PROTO_V8 &&
1600 !alps_is_valid_package_ss4_v2(psmouse))) {
1601 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
1602 psmouse->pktcnt - 1,
1603 psmouse->packet[psmouse->pktcnt - 1]);
1604 return PSMOUSE_BAD_DATA;
1607 if (psmouse->pktcnt == psmouse->pktsize) {
1608 priv->process_packet(psmouse);
1609 return PSMOUSE_FULL_PACKET;
1612 return PSMOUSE_GOOD_DATA;
1615 static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
1617 struct ps2dev *ps2dev = &psmouse->ps2dev;
1618 struct alps_data *priv = psmouse->private;
1620 unsigned char *param;
1621 unsigned char dummy[4];
1623 BUG_ON(nibble > 0xf);
1625 command = priv->nibble_commands[nibble].command;
1626 param = (command & 0x0f00) ?
1627 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
1629 if (ps2_command(ps2dev, param, command))
1635 static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
1637 struct ps2dev *ps2dev = &psmouse->ps2dev;
1638 struct alps_data *priv = psmouse->private;
1641 if (ps2_command(ps2dev, NULL, priv->addr_command))
1644 for (i = 12; i >= 0; i -= 4) {
1645 nibble = (addr >> i) & 0xf;
1646 if (alps_command_mode_send_nibble(psmouse, nibble))
1653 static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
1655 struct ps2dev *ps2dev = &psmouse->ps2dev;
1656 unsigned char param[4];
1658 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1662 * The address being read is returned in the first two bytes
1663 * of the result. Check that this address matches the expected
1666 if (addr != ((param[0] << 8) | param[1]))
1672 static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
1674 if (alps_command_mode_set_addr(psmouse, addr))
1676 return __alps_command_mode_read_reg(psmouse, addr);
1679 static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
1681 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
1683 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
1688 static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
1691 if (alps_command_mode_set_addr(psmouse, addr))
1693 return __alps_command_mode_write_reg(psmouse, value);
1696 static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
1697 int repeated_command, unsigned char *param)
1699 struct ps2dev *ps2dev = &psmouse->ps2dev;
1702 if (init_command && ps2_command(ps2dev, param, init_command))
1705 if (ps2_command(ps2dev, NULL, repeated_command) ||
1706 ps2_command(ps2dev, NULL, repeated_command) ||
1707 ps2_command(ps2dev, NULL, repeated_command))
1710 param[0] = param[1] = param[2] = 0xff;
1711 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1714 psmouse_dbg(psmouse, "%2.2X report: %3ph\n",
1715 repeated_command, param);
1719 static bool alps_check_valid_firmware_id(unsigned char id[])
1724 if (id[0] == 0x88 &&
1727 (id[1] & 0xf0) == 0xb0 ||
1728 (id[1] & 0xf0) == 0xc0)) {
1735 static int alps_enter_command_mode(struct psmouse *psmouse)
1737 unsigned char param[4];
1739 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
1740 psmouse_err(psmouse, "failed to enter command mode\n");
1744 if (!alps_check_valid_firmware_id(param)) {
1745 psmouse_dbg(psmouse,
1746 "unknown response while entering command mode\n");
1752 static inline int alps_exit_command_mode(struct psmouse *psmouse)
1754 struct ps2dev *ps2dev = &psmouse->ps2dev;
1755 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
1761 * For DualPoint devices select the device that should respond to
1762 * subsequent commands. It looks like glidepad is behind stickpointer,
1763 * I'd thought it would be other way around...
1765 static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
1767 struct ps2dev *ps2dev = &psmouse->ps2dev;
1768 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
1770 if (ps2_command(ps2dev, NULL, cmd) ||
1771 ps2_command(ps2dev, NULL, cmd) ||
1772 ps2_command(ps2dev, NULL, cmd) ||
1773 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1776 /* we may get 3 more bytes, just ignore them */
1777 ps2_drain(ps2dev, 3, 100);
1782 static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
1784 struct ps2dev *ps2dev = &psmouse->ps2dev;
1786 /* Try ALPS magic knock - 4 disable before enable */
1787 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1788 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1789 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1790 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1791 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
1795 * Switch mouse to poll (remote) mode so motion data will not
1798 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
1801 static int alps_monitor_mode_send_word(struct psmouse *psmouse, u16 word)
1806 * b0-b11 are valid bits, send sequence is inverse.
1807 * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1
1809 for (i = 0; i <= 8; i += 4) {
1810 nibble = (word >> i) & 0xf;
1811 if (alps_command_mode_send_nibble(psmouse, nibble))
1818 static int alps_monitor_mode_write_reg(struct psmouse *psmouse,
1819 u16 addr, u16 value)
1821 struct ps2dev *ps2dev = &psmouse->ps2dev;
1823 /* 0x0A0 is the command to write the word */
1824 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE) ||
1825 alps_monitor_mode_send_word(psmouse, 0x0A0) ||
1826 alps_monitor_mode_send_word(psmouse, addr) ||
1827 alps_monitor_mode_send_word(psmouse, value) ||
1828 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1834 static int alps_monitor_mode(struct psmouse *psmouse, bool enable)
1836 struct ps2dev *ps2dev = &psmouse->ps2dev;
1839 /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */
1840 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
1841 ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO) ||
1842 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1843 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1844 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1845 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1846 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1847 ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO))
1850 /* EC to exit monitor mode */
1851 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP))
1858 static int alps_absolute_mode_v6(struct psmouse *psmouse)
1860 u16 reg_val = 0x181;
1863 /* enter monitor mode, to write the register */
1864 if (alps_monitor_mode(psmouse, true))
1867 ret = alps_monitor_mode_write_reg(psmouse, 0x000, reg_val);
1869 if (alps_monitor_mode(psmouse, false))
1875 static int alps_get_status(struct psmouse *psmouse, char *param)
1877 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
1878 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
1885 * Turn touchpad tapping on or off. The sequences are:
1886 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1887 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1888 * My guess that 0xE9 (GetInfo) is here as a sync point.
1889 * For models that also have stickpointer (DualPoints) its tapping
1890 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1891 * we don't fiddle with it.
1893 static int alps_tap_mode(struct psmouse *psmouse, int enable)
1895 struct ps2dev *ps2dev = &psmouse->ps2dev;
1896 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
1897 unsigned char tap_arg = enable ? 0x0A : 0x00;
1898 unsigned char param[4];
1900 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
1901 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1902 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1903 ps2_command(ps2dev, &tap_arg, cmd))
1906 if (alps_get_status(psmouse, param))
1913 * alps_poll() - poll the touchpad for current motion packet.
1916 static int alps_poll(struct psmouse *psmouse)
1918 struct alps_data *priv = psmouse->private;
1919 unsigned char buf[sizeof(psmouse->packet)];
1922 if (priv->flags & ALPS_PASS)
1923 alps_passthrough_mode_v2(psmouse, true);
1925 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1926 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1928 if (priv->flags & ALPS_PASS)
1929 alps_passthrough_mode_v2(psmouse, false);
1931 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
1934 if ((psmouse->badbyte & 0xc8) == 0x08) {
1936 * Poll the track stick ...
1938 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
1942 memcpy(psmouse->packet, buf, sizeof(buf));
1946 static int alps_hw_init_v1_v2(struct psmouse *psmouse)
1948 struct alps_data *priv = psmouse->private;
1950 if ((priv->flags & ALPS_PASS) &&
1951 alps_passthrough_mode_v2(psmouse, true)) {
1955 if (alps_tap_mode(psmouse, true)) {
1956 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
1960 if (alps_absolute_mode_v1_v2(psmouse)) {
1961 psmouse_err(psmouse, "Failed to enable absolute mode\n");
1965 if ((priv->flags & ALPS_PASS) &&
1966 alps_passthrough_mode_v2(psmouse, false)) {
1970 /* ALPS needs stream mode, otherwise it won't report any data */
1971 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
1972 psmouse_err(psmouse, "Failed to enable stream mode\n");
1979 static int alps_hw_init_v6(struct psmouse *psmouse)
1981 unsigned char param[2] = {0xC8, 0x14};
1983 /* Enter passthrough mode to let trackpoint enter 6byte raw mode */
1984 if (alps_passthrough_mode_v2(psmouse, true))
1987 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1988 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1989 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1990 ps2_command(&psmouse->ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
1991 ps2_command(&psmouse->ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE))
1994 if (alps_passthrough_mode_v2(psmouse, false))
1997 if (alps_absolute_mode_v6(psmouse)) {
1998 psmouse_err(psmouse, "Failed to enable absolute mode\n");
2006 * Enable or disable passthrough mode to the trackstick.
2008 static int alps_passthrough_mode_v3(struct psmouse *psmouse,
2009 int reg_base, bool enable)
2011 int reg_val, ret = -1;
2013 if (alps_enter_command_mode(psmouse))
2016 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008);
2025 ret = __alps_command_mode_write_reg(psmouse, reg_val);
2028 if (alps_exit_command_mode(psmouse))
2033 /* Must be in command mode when calling this function */
2034 static int alps_absolute_mode_v3(struct psmouse *psmouse)
2038 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
2043 if (__alps_command_mode_write_reg(psmouse, reg_val))
2049 static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base)
2051 int ret = -EIO, reg_val;
2053 if (alps_enter_command_mode(psmouse))
2056 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
2060 /* bit 7: trackstick is present */
2061 ret = reg_val & 0x80 ? 0 : -ENODEV;
2064 alps_exit_command_mode(psmouse);
2068 static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
2070 struct ps2dev *ps2dev = &psmouse->ps2dev;
2072 unsigned char param[4];
2074 if (alps_passthrough_mode_v3(psmouse, reg_base, true))
2078 * E7 report for the trackstick
2080 * There have been reports of failures to seem to trace back
2081 * to the above trackstick check failing. When these occur
2082 * this E7 report fails, so when that happens we continue
2083 * with the assumption that there isn't a trackstick after
2086 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) {
2087 psmouse_warn(psmouse, "Failed to initialize trackstick (E7 report failed)\n");
2090 psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param);
2093 * Not sure what this does, but it is absolutely
2094 * essential. Without it, the touchpad does not
2095 * work at all and the trackstick just emits normal
2098 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
2099 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
2100 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
2101 alps_command_mode_send_nibble(psmouse, 0x9) ||
2102 alps_command_mode_send_nibble(psmouse, 0x4)) {
2103 psmouse_err(psmouse,
2104 "Error sending magic E6 sequence\n");
2110 * This ensures the trackstick packets are in the format
2111 * supported by this driver. If bit 1 isn't set the packet
2112 * format is different.
2114 if (alps_enter_command_mode(psmouse) ||
2115 alps_command_mode_write_reg(psmouse,
2116 reg_base + 0x08, 0x82) ||
2117 alps_exit_command_mode(psmouse))
2122 if (alps_passthrough_mode_v3(psmouse, reg_base, false))
2128 static int alps_hw_init_v3(struct psmouse *psmouse)
2130 struct ps2dev *ps2dev = &psmouse->ps2dev;
2132 unsigned char param[4];
2134 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE);
2135 if (reg_val == -EIO)
2139 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO)
2142 if (alps_enter_command_mode(psmouse) ||
2143 alps_absolute_mode_v3(psmouse)) {
2144 psmouse_err(psmouse, "Failed to enter absolute mode\n");
2148 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
2151 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
2154 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
2157 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
2160 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
2162 if (__alps_command_mode_write_reg(psmouse, 0x04))
2165 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
2167 if (__alps_command_mode_write_reg(psmouse, 0x03))
2170 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
2172 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
2175 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
2177 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
2180 alps_exit_command_mode(psmouse);
2182 /* Set rate and enable data reporting */
2184 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
2185 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
2186 psmouse_err(psmouse, "Failed to enable data reporting\n");
2194 * Leaving the touchpad in command mode will essentially render
2195 * it unusable until the machine reboots, so exit it here just
2198 alps_exit_command_mode(psmouse);
2202 static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
2204 int reg, x_pitch, y_pitch, x_electrode, y_electrode, x_phys, y_phys;
2205 struct alps_data *priv = psmouse->private;
2207 reg = alps_command_mode_read_reg(psmouse, reg_pitch);
2211 x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
2212 x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
2214 y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
2215 y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
2217 reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
2221 x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
2222 x_electrode = 17 + x_electrode;
2224 y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
2225 y_electrode = 13 + y_electrode;
2227 x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */
2228 y_phys = y_pitch * (y_electrode - 1); /* In 0.1 mm units */
2230 priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
2231 priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
2233 psmouse_dbg(psmouse,
2234 "pitch %dx%d num-electrodes %dx%d physical size %dx%d mm res %dx%d\n",
2235 x_pitch, y_pitch, x_electrode, y_electrode,
2236 x_phys / 10, y_phys / 10, priv->x_res, priv->y_res);
2241 static int alps_hw_init_rushmore_v3(struct psmouse *psmouse)
2243 struct alps_data *priv = psmouse->private;
2244 struct ps2dev *ps2dev = &psmouse->ps2dev;
2245 int reg_val, ret = -1;
2247 if (priv->flags & ALPS_DUALPOINT) {
2248 reg_val = alps_setup_trackstick_v3(psmouse,
2249 ALPS_REG_BASE_RUSHMORE);
2250 if (reg_val == -EIO)
2254 if (alps_enter_command_mode(psmouse) ||
2255 alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 ||
2256 alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00))
2259 if (alps_get_v3_v7_resolution(psmouse, 0xc2da))
2262 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6);
2265 if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd))
2268 if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64))
2271 /* enter absolute mode */
2272 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4);
2275 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02))
2278 alps_exit_command_mode(psmouse);
2279 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
2282 alps_exit_command_mode(psmouse);
2286 /* Must be in command mode when calling this function */
2287 static int alps_absolute_mode_v4(struct psmouse *psmouse)
2291 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
2296 if (__alps_command_mode_write_reg(psmouse, reg_val))
2302 static int alps_hw_init_v4(struct psmouse *psmouse)
2304 struct ps2dev *ps2dev = &psmouse->ps2dev;
2305 unsigned char param[4];
2307 if (alps_enter_command_mode(psmouse))
2310 if (alps_absolute_mode_v4(psmouse)) {
2311 psmouse_err(psmouse, "Failed to enter absolute mode\n");
2315 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
2318 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
2321 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
2324 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
2327 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
2330 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
2333 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
2336 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
2339 alps_exit_command_mode(psmouse);
2342 * This sequence changes the output from a 9-byte to an
2343 * 8-byte format. All the same data seems to be present,
2344 * just in a more compact format.
2349 if (ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
2350 ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE) ||
2351 ps2_command(ps2dev, ¶m[2], PSMOUSE_CMD_SETRATE) ||
2352 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
2355 /* Set rate and enable data reporting */
2357 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
2358 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
2359 psmouse_err(psmouse, "Failed to enable data reporting\n");
2367 * Leaving the touchpad in command mode will essentially render
2368 * it unusable until the machine reboots, so exit it here just
2371 alps_exit_command_mode(psmouse);
2375 static int alps_get_otp_values_ss4_v2(struct psmouse *psmouse,
2376 unsigned char index, unsigned char otp[])
2378 struct ps2dev *ps2dev = &psmouse->ps2dev;
2382 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
2383 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
2384 ps2_command(ps2dev, otp, PSMOUSE_CMD_GETINFO))
2390 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
2391 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
2392 ps2_command(ps2dev, otp, PSMOUSE_CMD_GETINFO))
2401 static int alps_update_device_area_ss4_v2(unsigned char otp[][4],
2402 struct alps_data *priv)
2404 int num_x_electrode;
2405 int num_y_electrode;
2406 int x_pitch, y_pitch, x_phys, y_phys;
2408 num_x_electrode = SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
2409 num_y_electrode = SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
2411 priv->x_max = (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
2412 priv->y_max = (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
2414 x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
2415 y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
2417 x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
2418 y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
2420 priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
2421 priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
2426 static int alps_update_btn_info_ss4_v2(unsigned char otp[][4],
2427 struct alps_data *priv)
2429 unsigned char is_btnless;
2431 is_btnless = (otp[1][1] >> 3) & 0x01;
2434 priv->flags |= ALPS_BUTTONPAD;
2439 static int alps_set_defaults_ss4_v2(struct psmouse *psmouse,
2440 struct alps_data *priv)
2442 unsigned char otp[2][4];
2444 memset(otp, 0, sizeof(otp));
2446 if (alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]) ||
2447 alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]))
2450 alps_update_device_area_ss4_v2(otp, priv);
2452 alps_update_btn_info_ss4_v2(otp, priv);
2457 static int alps_dolphin_get_device_area(struct psmouse *psmouse,
2458 struct alps_data *priv)
2460 struct ps2dev *ps2dev = &psmouse->ps2dev;
2461 unsigned char param[4] = {0};
2462 int num_x_electrode, num_y_electrode;
2464 if (alps_enter_command_mode(psmouse))
2468 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
2469 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
2470 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
2471 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
2472 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE))
2475 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
2479 * Dolphin's sensor line number is not fixed. It can be calculated
2480 * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET.
2481 * Further more, we can get device's x_max and y_max by multiplying
2482 * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE.
2484 * e.g. When we get register's sensor_x = 11 & sensor_y = 8,
2485 * real sensor line number X = 11 + 8 = 19, and
2486 * real sensor line number Y = 8 + 1 = 9.
2487 * So, x_max = (19 - 1) * 64 = 1152, and
2488 * y_max = (9 - 1) * 64 = 512.
2490 num_x_electrode = DOLPHIN_PROFILE_XOFFSET + (param[2] & 0x0F);
2491 num_y_electrode = DOLPHIN_PROFILE_YOFFSET + ((param[2] >> 4) & 0x0F);
2492 priv->x_bits = num_x_electrode;
2493 priv->y_bits = num_y_electrode;
2494 priv->x_max = (num_x_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE;
2495 priv->y_max = (num_y_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE;
2497 if (alps_exit_command_mode(psmouse))
2503 static int alps_hw_init_dolphin_v1(struct psmouse *psmouse)
2505 struct ps2dev *ps2dev = &psmouse->ps2dev;
2506 unsigned char param[2];
2508 /* This is dolphin "v1" as empirically defined by florin9doi */
2512 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
2513 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
2514 ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE))
2520 static int alps_hw_init_v7(struct psmouse *psmouse)
2522 struct ps2dev *ps2dev = &psmouse->ps2dev;
2523 int reg_val, ret = -1;
2525 if (alps_enter_command_mode(psmouse) ||
2526 alps_command_mode_read_reg(psmouse, 0xc2d9) == -1)
2529 if (alps_get_v3_v7_resolution(psmouse, 0xc397))
2532 if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64))
2535 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4);
2538 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02))
2541 alps_exit_command_mode(psmouse);
2542 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
2545 alps_exit_command_mode(psmouse);
2549 static int alps_hw_init_ss4_v2(struct psmouse *psmouse)
2551 struct ps2dev *ps2dev = &psmouse->ps2dev;
2552 char param[2] = {0x64, 0x28};
2555 /* enter absolute mode */
2556 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
2557 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
2558 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
2559 ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE)) {
2563 /* T.B.D. Decread noise packet number, delete in the future */
2564 if (alps_exit_command_mode(psmouse) ||
2565 alps_enter_command_mode(psmouse) ||
2566 alps_command_mode_write_reg(psmouse, 0x001D, 0x20)) {
2569 alps_exit_command_mode(psmouse);
2571 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
2574 alps_exit_command_mode(psmouse);
2578 static int alps_set_protocol(struct psmouse *psmouse,
2579 struct alps_data *priv,
2580 const struct alps_protocol_info *protocol)
2582 psmouse->private = priv;
2584 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
2586 priv->proto_version = protocol->version;
2587 priv->byte0 = protocol->byte0;
2588 priv->mask0 = protocol->mask0;
2589 priv->flags = protocol->flags;
2596 switch (priv->proto_version) {
2599 priv->hw_init = alps_hw_init_v1_v2;
2600 priv->process_packet = alps_process_packet_v1_v2;
2601 priv->set_abs_params = alps_set_abs_params_st;
2607 priv->hw_init = alps_hw_init_v3;
2608 priv->process_packet = alps_process_packet_v3;
2609 priv->set_abs_params = alps_set_abs_params_mt;
2610 priv->decode_fields = alps_decode_pinnacle;
2611 priv->nibble_commands = alps_v3_nibble_commands;
2612 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
2615 case ALPS_PROTO_V3_RUSHMORE:
2616 priv->hw_init = alps_hw_init_rushmore_v3;
2617 priv->process_packet = alps_process_packet_v3;
2618 priv->set_abs_params = alps_set_abs_params_mt;
2619 priv->decode_fields = alps_decode_rushmore;
2620 priv->nibble_commands = alps_v3_nibble_commands;
2621 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
2625 if (alps_probe_trackstick_v3(psmouse,
2626 ALPS_REG_BASE_RUSHMORE) < 0)
2627 priv->flags &= ~ALPS_DUALPOINT;
2632 priv->hw_init = alps_hw_init_v4;
2633 priv->process_packet = alps_process_packet_v4;
2634 priv->set_abs_params = alps_set_abs_params_mt;
2635 priv->nibble_commands = alps_v4_nibble_commands;
2636 priv->addr_command = PSMOUSE_CMD_DISABLE;
2640 priv->hw_init = alps_hw_init_dolphin_v1;
2641 priv->process_packet = alps_process_touchpad_packet_v3_v5;
2642 priv->decode_fields = alps_decode_dolphin;
2643 priv->set_abs_params = alps_set_abs_params_mt;
2644 priv->nibble_commands = alps_v3_nibble_commands;
2645 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
2649 if (alps_dolphin_get_device_area(psmouse, priv))
2655 priv->hw_init = alps_hw_init_v6;
2656 priv->process_packet = alps_process_packet_v6;
2657 priv->set_abs_params = alps_set_abs_params_st;
2658 priv->nibble_commands = alps_v6_nibble_commands;
2664 priv->hw_init = alps_hw_init_v7;
2665 priv->process_packet = alps_process_packet_v7;
2666 priv->decode_fields = alps_decode_packet_v7;
2667 priv->set_abs_params = alps_set_abs_params_v7;
2668 priv->nibble_commands = alps_v3_nibble_commands;
2669 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
2670 priv->x_max = 0xfff;
2671 priv->y_max = 0x7ff;
2673 if (priv->fw_ver[1] != 0xba)
2674 priv->flags |= ALPS_BUTTONPAD;
2679 priv->hw_init = alps_hw_init_ss4_v2;
2680 priv->process_packet = alps_process_packet_ss4_v2;
2681 priv->decode_fields = alps_decode_ss4_v2;
2682 priv->set_abs_params = alps_set_abs_params_ss4_v2;
2683 priv->nibble_commands = alps_v3_nibble_commands;
2684 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
2686 if (alps_set_defaults_ss4_v2(psmouse, priv))
2695 static const struct alps_protocol_info *alps_match_table(unsigned char *e7,
2698 const struct alps_model_info *model;
2701 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
2702 model = &alps_model_data[i];
2704 if (!memcmp(e7, model->signature, sizeof(model->signature)) &&
2705 (!model->command_mode_resp ||
2706 model->command_mode_resp == ec[2])) {
2708 return &model->protocol_info;
2715 static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
2717 const struct alps_protocol_info *protocol;
2718 unsigned char e6[4], e7[4], ec[4];
2722 * First try "E6 report".
2723 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
2724 * The bits 0-2 of the first byte will be 1s if some buttons are
2727 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
2728 PSMOUSE_CMD_SETSCALE11, e6))
2731 if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100))
2735 * Now get the "E7" and "EC" reports. These will uniquely identify
2736 * most ALPS touchpads.
2738 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
2739 PSMOUSE_CMD_SETSCALE21, e7) ||
2740 alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
2741 PSMOUSE_CMD_RESET_WRAP, ec) ||
2742 alps_exit_command_mode(psmouse))
2745 protocol = alps_match_table(e7, ec);
2747 if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 &&
2748 ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) {
2749 protocol = &alps_v5_protocol_data;
2750 } else if (ec[0] == 0x88 &&
2751 ((ec[1] & 0xf0) == 0xb0 || (ec[1] & 0xf0) == 0xc0)) {
2752 protocol = &alps_v7_protocol_data;
2753 } else if (ec[0] == 0x88 && ec[1] == 0x08) {
2754 protocol = &alps_v3_rushmore_data;
2755 } else if (ec[0] == 0x88 && ec[1] == 0x07 &&
2756 ec[2] >= 0x90 && ec[2] <= 0x9d) {
2757 protocol = &alps_v3_protocol_data;
2758 } else if (e7[0] == 0x73 && e7[1] == 0x03 &&
2759 e7[2] == 0x14 && ec[1] == 0x02) {
2760 protocol = &alps_v8_protocol_data;
2762 psmouse_dbg(psmouse,
2763 "Likely not an ALPS touchpad: E7=%3ph, EC=%3ph\n", e7, ec);
2769 /* Save the Firmware version */
2770 memcpy(priv->fw_ver, ec, 3);
2771 error = alps_set_protocol(psmouse, priv, protocol);
2779 static int alps_reconnect(struct psmouse *psmouse)
2781 struct alps_data *priv = psmouse->private;
2783 psmouse_reset(psmouse);
2785 if (alps_identify(psmouse, priv) < 0)
2788 return priv->hw_init(psmouse);
2791 static void alps_disconnect(struct psmouse *psmouse)
2793 struct alps_data *priv = psmouse->private;
2795 psmouse_reset(psmouse);
2796 del_timer_sync(&priv->timer);
2798 input_unregister_device(priv->dev2);
2799 if (!IS_ERR_OR_NULL(priv->dev3))
2800 input_unregister_device(priv->dev3);
2804 static void alps_set_abs_params_st(struct alps_data *priv,
2805 struct input_dev *dev1)
2807 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
2808 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
2809 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
2812 static void alps_set_abs_params_mt_common(struct alps_data *priv,
2813 struct input_dev *dev1)
2815 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0);
2816 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0);
2818 input_abs_set_res(dev1, ABS_MT_POSITION_X, priv->x_res);
2819 input_abs_set_res(dev1, ABS_MT_POSITION_Y, priv->y_res);
2821 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
2822 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
2825 static void alps_set_abs_params_mt(struct alps_data *priv,
2826 struct input_dev *dev1)
2828 alps_set_abs_params_mt_common(priv, dev1);
2829 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
2831 input_mt_init_slots(dev1, MAX_TOUCHES,
2832 INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED |
2836 static void alps_set_abs_params_v7(struct alps_data *priv,
2837 struct input_dev *dev1)
2839 alps_set_abs_params_mt_common(priv, dev1);
2840 set_bit(BTN_TOOL_QUINTTAP, dev1->keybit);
2842 input_mt_init_slots(dev1, MAX_TOUCHES,
2843 INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED |
2846 set_bit(BTN_TOOL_QUINTTAP, dev1->keybit);
2849 static void alps_set_abs_params_ss4_v2(struct alps_data *priv,
2850 struct input_dev *dev1)
2852 alps_set_abs_params_mt_common(priv, dev1);
2853 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
2854 set_bit(BTN_TOOL_QUINTTAP, dev1->keybit);
2856 input_mt_init_slots(dev1, MAX_TOUCHES,
2857 INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED |
2861 int alps_init(struct psmouse *psmouse)
2863 struct alps_data *priv = psmouse->private;
2864 struct input_dev *dev1 = psmouse->dev;
2867 error = priv->hw_init(psmouse);
2872 * Undo part of setup done for us by psmouse core since touchpad
2873 * is not a relative device.
2875 __clear_bit(EV_REL, dev1->evbit);
2876 __clear_bit(REL_X, dev1->relbit);
2877 __clear_bit(REL_Y, dev1->relbit);
2880 * Now set up our capabilities.
2882 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
2883 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
2884 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
2885 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
2886 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
2888 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
2890 priv->set_abs_params(priv, dev1);
2892 if (priv->flags & ALPS_WHEEL) {
2893 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
2894 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
2897 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
2898 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
2899 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
2902 if (priv->flags & ALPS_FOUR_BUTTONS) {
2903 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
2904 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
2905 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
2906 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
2907 } else if (priv->flags & ALPS_BUTTONPAD) {
2908 set_bit(INPUT_PROP_BUTTONPAD, dev1->propbit);
2909 clear_bit(BTN_RIGHT, dev1->keybit);
2911 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
2914 if (priv->flags & ALPS_DUALPOINT) {
2915 struct input_dev *dev2;
2917 dev2 = input_allocate_device();
2919 psmouse_err(psmouse,
2920 "failed to allocate trackstick device\n");
2925 snprintf(priv->phys2, sizeof(priv->phys2), "%s/input1",
2926 psmouse->ps2dev.serio->phys);
2927 dev2->phys = priv->phys2;
2930 * format of input device name is: "protocol vendor name"
2931 * see function psmouse_switch_protocol() in psmouse-base.c
2933 dev2->name = "AlpsPS/2 ALPS DualPoint Stick";
2935 dev2->id.bustype = BUS_I8042;
2936 dev2->id.vendor = 0x0002;
2937 dev2->id.product = PSMOUSE_ALPS;
2938 dev2->id.version = priv->proto_version;
2939 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
2941 input_set_capability(dev2, EV_REL, REL_X);
2942 input_set_capability(dev2, EV_REL, REL_Y);
2943 input_set_capability(dev2, EV_KEY, BTN_LEFT);
2944 input_set_capability(dev2, EV_KEY, BTN_RIGHT);
2945 input_set_capability(dev2, EV_KEY, BTN_MIDDLE);
2947 __set_bit(INPUT_PROP_POINTER, dev2->propbit);
2948 __set_bit(INPUT_PROP_POINTING_STICK, dev2->propbit);
2950 error = input_register_device(dev2);
2952 psmouse_err(psmouse,
2953 "failed to register trackstick device: %d\n",
2955 input_free_device(dev2);
2962 priv->psmouse = psmouse;
2964 INIT_DELAYED_WORK(&priv->dev3_register_work,
2965 alps_register_bare_ps2_mouse);
2967 psmouse->protocol_handler = alps_process_byte;
2968 psmouse->poll = alps_poll;
2969 psmouse->disconnect = alps_disconnect;
2970 psmouse->reconnect = alps_reconnect;
2971 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
2973 /* We are having trouble resyncing ALPS touchpads so disable it for now */
2974 psmouse->resync_time = 0;
2976 /* Allow 2 invalid packets without resetting device */
2977 psmouse->resetafter = psmouse->pktsize * 2;
2982 psmouse_reset(psmouse);
2984 * Even though we did not allocate psmouse->private we do free
2987 kfree(psmouse->private);
2988 psmouse->private = NULL;
2992 int alps_detect(struct psmouse *psmouse, bool set_properties)
2994 struct alps_data *priv;
2997 error = alps_identify(psmouse, NULL);
3002 * Reset the device to make sure it is fully operational:
3003 * on some laptops, like certain Dell Latitudes, we may
3004 * fail to properly detect presence of trackstick if device
3005 * has not been reset.
3007 psmouse_reset(psmouse);
3009 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
3013 error = alps_identify(psmouse, priv);
3019 if (set_properties) {
3020 psmouse->vendor = "ALPS";
3021 psmouse->name = priv->flags & ALPS_DUALPOINT ?
3022 "DualPoint TouchPad" : "GlidePoint";
3023 psmouse->model = priv->proto_version;
3026 * Destroy alps_data structure we allocated earlier since
3027 * this was just a "trial run". Otherwise we'll keep it
3028 * to be used by alps_init() which has to be called if
3029 * we succeed and set_properties is true.
3032 psmouse->private = NULL;