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_IS_RUSHMORE 0x100 /* device is a rushmore */
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 */
120 { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
121 { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
122 { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
123 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
124 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
125 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
126 { { 0x73, 0x00, 0x14 }, 0x00, ALPS_PROTO_V6, 0xff, 0xff, ALPS_DUALPOINT }, /* Dell XT2 */
127 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
128 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
129 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
130 { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
133 static void alps_set_abs_params_st(struct alps_data *priv,
134 struct input_dev *dev1);
135 static void alps_set_abs_params_mt(struct alps_data *priv,
136 struct input_dev *dev1);
139 * XXX - this entry is suspicious. First byte has zero lower nibble,
140 * which is what a normal mouse would report. Also, the value 0x0e
141 * isn't valid per PS/2 spec.
144 /* Packet formats are described in Documentation/input/alps.txt */
146 static bool alps_is_valid_first_byte(struct alps_data *priv,
149 return (data & priv->mask0) == priv->byte0;
152 static void alps_report_buttons(struct psmouse *psmouse,
153 struct input_dev *dev1, struct input_dev *dev2,
154 int left, int right, int middle)
156 struct input_dev *dev;
159 * If shared button has already been reported on the
160 * other device (dev2) then this event should be also
161 * sent through that device.
163 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
164 input_report_key(dev, BTN_LEFT, left);
166 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
167 input_report_key(dev, BTN_RIGHT, right);
169 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
170 input_report_key(dev, BTN_MIDDLE, middle);
173 * Sync the _other_ device now, we'll do the first
174 * device later once we report the rest of the events.
179 static void alps_process_packet_v1_v2(struct psmouse *psmouse)
181 struct alps_data *priv = psmouse->private;
182 unsigned char *packet = psmouse->packet;
183 struct input_dev *dev = psmouse->dev;
184 struct input_dev *dev2 = priv->dev2;
185 int x, y, z, ges, fin, left, right, middle;
186 int back = 0, forward = 0;
188 if (priv->proto_version == ALPS_PROTO_V1) {
189 left = packet[2] & 0x10;
190 right = packet[2] & 0x08;
192 x = packet[1] | ((packet[0] & 0x07) << 7);
193 y = packet[4] | ((packet[3] & 0x07) << 7);
196 left = packet[3] & 1;
197 right = packet[3] & 2;
198 middle = packet[3] & 4;
199 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
200 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
204 if (priv->flags & ALPS_FW_BK_1) {
205 back = packet[0] & 0x10;
206 forward = packet[2] & 4;
209 if (priv->flags & ALPS_FW_BK_2) {
210 back = packet[3] & 4;
211 forward = packet[2] & 4;
212 if ((middle = forward && back))
219 if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
220 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
221 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
223 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
229 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
231 /* Convert hardware tap to a reasonable Z value */
236 * A "tap and drag" operation is reported by the hardware as a transition
237 * from (!fin && ges) to (fin && ges). This should be translated to the
238 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
240 if (ges && fin && !priv->prev_fin) {
241 input_report_abs(dev, ABS_X, x);
242 input_report_abs(dev, ABS_Y, y);
243 input_report_abs(dev, ABS_PRESSURE, 0);
244 input_report_key(dev, BTN_TOOL_FINGER, 0);
247 priv->prev_fin = fin;
250 input_report_key(dev, BTN_TOUCH, 1);
252 input_report_key(dev, BTN_TOUCH, 0);
255 input_report_abs(dev, ABS_X, x);
256 input_report_abs(dev, ABS_Y, y);
259 input_report_abs(dev, ABS_PRESSURE, z);
260 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
262 if (priv->flags & ALPS_WHEEL)
263 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
265 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
266 input_report_key(dev, BTN_FORWARD, forward);
267 input_report_key(dev, BTN_BACK, back);
270 if (priv->flags & ALPS_FOUR_BUTTONS) {
271 input_report_key(dev, BTN_0, packet[2] & 4);
272 input_report_key(dev, BTN_1, packet[0] & 0x10);
273 input_report_key(dev, BTN_2, packet[3] & 4);
274 input_report_key(dev, BTN_3, packet[0] & 0x20);
281 * Process bitmap data for V5 protocols. Return value is null.
283 * The bitmaps don't have enough data to track fingers, so this function
284 * only generates points representing a bounding box of at most two contacts.
285 * These two points are returned in x1, y1, x2, and y2.
287 static void alps_process_bitmap_dolphin(struct alps_data *priv,
288 struct alps_fields *fields,
289 int *x1, int *y1, int *x2, int *y2)
291 int box_middle_x, box_middle_y;
292 unsigned int x_map, y_map;
293 unsigned char start_bit, end_bit;
294 unsigned char x_msb, x_lsb, y_msb, y_lsb;
296 x_map = fields->x_map;
297 y_map = fields->y_map;
299 if (!x_map || !y_map)
302 /* Get Most-significant and Least-significant bit */
308 /* Most-significant bit should never exceed max sensor line number */
309 if (x_msb > priv->x_bits || y_msb > priv->y_bits)
312 *x1 = *y1 = *x2 = *y2 = 0;
314 if (fields->fingers > 1) {
315 start_bit = priv->x_bits - x_msb;
316 end_bit = priv->x_bits - x_lsb;
317 box_middle_x = (priv->x_max * (start_bit + end_bit)) /
318 (2 * (priv->x_bits - 1));
320 start_bit = y_lsb - 1;
322 box_middle_y = (priv->y_max * (start_bit + end_bit)) /
323 (2 * (priv->y_bits - 1));
326 *x2 = 2 * box_middle_x - *x1;
327 *y2 = 2 * box_middle_y - *y1;
331 static void alps_get_bitmap_points(unsigned int map,
332 struct alps_bitmap_point *low,
333 struct alps_bitmap_point *high,
336 struct alps_bitmap_point *point;
337 int i, bit, prev_bit = 0;
340 for (i = 0; map != 0; i++, map >>= 1) {
344 point->start_bit = i;
358 * Process bitmap data from v3 and v4 protocols. Returns the number of
359 * fingers detected. A return value of 0 means at least one of the
362 * The bitmaps don't have enough data to track fingers, so this function
363 * only generates points representing a bounding box of all contacts.
364 * These points are returned in x1, y1, x2, and y2 when the return value
367 static int alps_process_bitmap(struct alps_data *priv,
368 unsigned int x_map, unsigned int y_map,
369 int *x1, int *y1, int *x2, int *y2)
371 int i, fingers_x = 0, fingers_y = 0, fingers;
372 struct alps_bitmap_point x_low = {0,}, x_high = {0,};
373 struct alps_bitmap_point y_low = {0,}, y_high = {0,};
375 if (!x_map || !y_map)
378 *x1 = *y1 = *x2 = *y2 = 0;
380 alps_get_bitmap_points(x_map, &x_low, &x_high, &fingers_x);
381 alps_get_bitmap_points(y_map, &y_low, &y_high, &fingers_y);
384 * Fingers can overlap, so we use the maximum count of fingers
385 * on either axis as the finger count.
387 fingers = max(fingers_x, fingers_y);
390 * If an axis reports only a single contact, we have overlapping or
391 * adjacent fingers. Divide the single contact between the two points.
393 if (fingers_x == 1) {
394 i = (x_low.num_bits - 1) / 2;
395 x_low.num_bits = x_low.num_bits - i;
396 x_high.start_bit = x_low.start_bit + i;
397 x_high.num_bits = max(i, 1);
399 if (fingers_y == 1) {
400 i = (y_low.num_bits - 1) / 2;
401 y_low.num_bits = y_low.num_bits - i;
402 y_high.start_bit = y_low.start_bit + i;
403 y_high.num_bits = max(i, 1);
406 *x1 = (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) /
407 (2 * (priv->x_bits - 1));
408 *y1 = (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) /
409 (2 * (priv->y_bits - 1));
412 (2 * x_high.start_bit + x_high.num_bits - 1)) /
413 (2 * (priv->x_bits - 1));
415 (2 * y_high.start_bit + y_high.num_bits - 1)) /
416 (2 * (priv->y_bits - 1));
418 /* y-bitmap order is reversed, except on rushmore */
419 if (!(priv->flags & ALPS_IS_RUSHMORE)) {
420 *y1 = priv->y_max - *y1;
421 *y2 = priv->y_max - *y2;
427 static void alps_set_slot(struct input_dev *dev, int slot, bool active,
430 input_mt_slot(dev, slot);
431 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
433 input_report_abs(dev, ABS_MT_POSITION_X, x);
434 input_report_abs(dev, ABS_MT_POSITION_Y, y);
438 static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers,
439 int x1, int y1, int x2, int y2)
441 alps_set_slot(dev, 0, num_fingers != 0, x1, y1);
442 alps_set_slot(dev, 1, num_fingers == 2, x2, y2);
445 static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
447 struct alps_data *priv = psmouse->private;
448 unsigned char *packet = psmouse->packet;
449 struct input_dev *dev = priv->dev2;
450 int x, y, z, left, right, middle;
452 /* Sanity check packet */
453 if (!(packet[0] & 0x40)) {
454 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
459 * There's a special packet that seems to indicate the end
460 * of a stream of trackstick data. Filter these out.
462 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
465 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
466 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
467 z = (packet[4] & 0x7c) >> 2;
470 * The x and y values tend to be quite large, and when used
471 * alone the trackstick is difficult to use. Scale them down
477 input_report_rel(dev, REL_X, x);
478 input_report_rel(dev, REL_Y, -y);
481 * Most ALPS models report the trackstick buttons in the touchpad
482 * packets, but a few report them here. No reliable way has been
483 * found to differentiate between the models upfront, so we enable
484 * the quirk in response to seeing a button press in the trackstick
487 left = packet[3] & 0x01;
488 right = packet[3] & 0x02;
489 middle = packet[3] & 0x04;
491 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
492 (left || right || middle))
493 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
495 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
496 input_report_key(dev, BTN_LEFT, left);
497 input_report_key(dev, BTN_RIGHT, right);
498 input_report_key(dev, BTN_MIDDLE, middle);
505 static void alps_decode_buttons_v3(struct alps_fields *f, unsigned char *p)
507 f->left = !!(p[3] & 0x01);
508 f->right = !!(p[3] & 0x02);
509 f->middle = !!(p[3] & 0x04);
511 f->ts_left = !!(p[3] & 0x10);
512 f->ts_right = !!(p[3] & 0x20);
513 f->ts_middle = !!(p[3] & 0x40);
516 static void alps_decode_pinnacle(struct alps_fields *f, unsigned char *p,
517 struct psmouse *psmouse)
519 f->first_mp = !!(p[4] & 0x40);
520 f->is_mp = !!(p[0] & 0x40);
522 f->fingers = (p[5] & 0x3) + 1;
523 f->x_map = ((p[4] & 0x7e) << 8) |
524 ((p[1] & 0x7f) << 2) |
525 ((p[0] & 0x30) >> 4);
526 f->y_map = ((p[3] & 0x70) << 4) |
527 ((p[2] & 0x7f) << 1) |
530 f->x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) |
531 ((p[0] & 0x30) >> 4);
532 f->y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f);
535 alps_decode_buttons_v3(f, p);
538 static void alps_decode_rushmore(struct alps_fields *f, unsigned char *p,
539 struct psmouse *psmouse)
541 alps_decode_pinnacle(f, p, psmouse);
543 /* Rushmore's packet decode has a bit difference with Pinnacle's */
544 f->is_mp = !!(p[5] & 0x40);
545 f->fingers = max((p[5] & 0x3), ((p[5] >> 2) & 0x3)) + 1;
546 f->x_map |= (p[5] & 0x10) << 11;
547 f->y_map |= (p[5] & 0x20) << 6;
550 static void alps_decode_dolphin(struct alps_fields *f, unsigned char *p,
551 struct psmouse *psmouse)
554 struct alps_data *priv = psmouse->private;
556 f->first_mp = !!(p[0] & 0x02);
557 f->is_mp = !!(p[0] & 0x20);
560 f->x = ((p[1] & 0x7f) | ((p[4] & 0x0f) << 7));
561 f->y = ((p[2] & 0x7f) | ((p[4] & 0xf0) << 3));
562 f->z = (p[0] & 4) ? 0 : p[5] & 0x7f;
563 alps_decode_buttons_v3(f, p);
565 f->fingers = ((p[0] & 0x6) >> 1 |
568 palm_data = (p[1] & 0x7f) |
569 ((p[2] & 0x7f) << 7) |
570 ((p[4] & 0x7f) << 14) |
571 ((p[5] & 0x7f) << 21) |
572 ((p[3] & 0x07) << 28) |
573 (((u64)p[3] & 0x70) << 27) |
574 (((u64)p[0] & 0x01) << 34);
576 /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */
577 f->y_map = palm_data & (BIT(priv->y_bits) - 1);
579 /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */
580 f->x_map = (palm_data >> priv->y_bits) &
581 (BIT(priv->x_bits) - 1);
585 static void alps_process_touchpad_packet_v3_v5(struct psmouse *psmouse)
587 struct alps_data *priv = psmouse->private;
588 unsigned char *packet = psmouse->packet;
589 struct input_dev *dev = psmouse->dev;
590 struct input_dev *dev2 = priv->dev2;
591 int x1 = 0, y1 = 0, x2 = 0, y2 = 0, fingers = 0;
592 struct alps_fields f = {0};
594 priv->decode_fields(&f, packet, psmouse);
597 * There's no single feature of touchpad position and bitmap packets
598 * that can be used to distinguish between them. We rely on the fact
599 * that a bitmap packet should always follow a position packet with
600 * bit 6 of packet[4] set.
602 if (priv->multi_packet) {
604 * Sometimes a position packet will indicate a multi-packet
605 * sequence, but then what follows is another position
606 * packet. Check for this, and when it happens process the
607 * position packet as usual.
611 if (priv->proto_version == ALPS_PROTO_V3) {
612 if (alps_process_bitmap(priv, f.x_map,
615 fingers = 0; /* Use st data */
617 /* Now process position packet */
618 priv->decode_fields(&f, priv->multi_data,
622 * Because Dolphin uses position packet's
623 * coordinate data as Pt1 and uses it to
624 * calculate Pt2, so we need to do position
625 * packet decode first.
627 priv->decode_fields(&f, priv->multi_data,
631 * Since Dolphin's finger number is reliable,
632 * there is no need to compare with bmap_fn.
634 alps_process_bitmap_dolphin(priv, &f, &x1, &y1,
638 priv->multi_packet = 0;
643 * Bit 6 of byte 0 is not usually set in position packets. The only
644 * times it seems to be set is in situations where the data is
645 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
646 * this combined with the fact that this bit is useful for filtering
647 * out misidentified bitmap packets, we reject anything with this
653 if (!priv->multi_packet && f.first_mp) {
654 priv->multi_packet = 1;
655 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
659 priv->multi_packet = 0;
662 * Sometimes the hardware sends a single packet with z = 0
663 * in the middle of a stream. Real releases generate packets
664 * with x, y, and z all zero, so these seem to be flukes.
667 if (f.x && f.y && !f.z)
671 * If we don't have MT data or the bitmaps were empty, we have
672 * to rely on ST data.
677 fingers = f.z > 0 ? 1 : 0;
681 input_report_key(dev, BTN_TOUCH, 1);
683 input_report_key(dev, BTN_TOUCH, 0);
685 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
687 input_mt_report_finger_count(dev, fingers);
689 input_report_key(dev, BTN_LEFT, f.left);
690 input_report_key(dev, BTN_RIGHT, f.right);
691 input_report_key(dev, BTN_MIDDLE, f.middle);
694 input_report_abs(dev, ABS_X, f.x);
695 input_report_abs(dev, ABS_Y, f.y);
697 input_report_abs(dev, ABS_PRESSURE, f.z);
701 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
702 input_report_key(dev2, BTN_LEFT, f.ts_left);
703 input_report_key(dev2, BTN_RIGHT, f.ts_right);
704 input_report_key(dev2, BTN_MIDDLE, f.ts_middle);
709 static void alps_process_packet_v3(struct psmouse *psmouse)
711 unsigned char *packet = psmouse->packet;
714 * v3 protocol packets come in three types, two representing
715 * touchpad data and one representing trackstick data.
716 * Trackstick packets seem to be distinguished by always
717 * having 0x3f in the last byte. This value has never been
718 * observed in the last byte of either of the other types
721 if (packet[5] == 0x3f) {
722 alps_process_trackstick_packet_v3(psmouse);
726 alps_process_touchpad_packet_v3_v5(psmouse);
729 static void alps_process_packet_v6(struct psmouse *psmouse)
731 struct alps_data *priv = psmouse->private;
732 unsigned char *packet = psmouse->packet;
733 struct input_dev *dev = psmouse->dev;
734 struct input_dev *dev2 = priv->dev2;
735 int x, y, z, left, right, middle;
738 * We can use Byte5 to distinguish if the packet is from Touchpad
743 if (packet[5] == 0x7F) {
744 /* It should be a DualPoint when received Trackpoint packet */
745 if (!(priv->flags & ALPS_DUALPOINT))
748 /* Trackpoint packet */
749 x = packet[1] | ((packet[3] & 0x20) << 2);
750 y = packet[2] | ((packet[3] & 0x40) << 1);
752 left = packet[3] & 0x01;
753 right = packet[3] & 0x02;
754 middle = packet[3] & 0x04;
756 /* To prevent the cursor jump when finger lifted */
757 if (x == 0x7F && y == 0x7F && z == 0x7F)
760 /* Divide 4 since trackpoint's speed is too fast */
761 input_report_rel(dev2, REL_X, (char)x / 4);
762 input_report_rel(dev2, REL_Y, -((char)y / 4));
764 input_report_key(dev2, BTN_LEFT, left);
765 input_report_key(dev2, BTN_RIGHT, right);
766 input_report_key(dev2, BTN_MIDDLE, middle);
772 /* Touchpad packet */
773 x = packet[1] | ((packet[3] & 0x78) << 4);
774 y = packet[2] | ((packet[4] & 0x78) << 4);
776 left = packet[3] & 0x01;
777 right = packet[3] & 0x02;
780 input_report_key(dev, BTN_TOUCH, 1);
782 input_report_key(dev, BTN_TOUCH, 0);
785 input_report_abs(dev, ABS_X, x);
786 input_report_abs(dev, ABS_Y, y);
789 input_report_abs(dev, ABS_PRESSURE, z);
790 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
792 /* v6 touchpad does not have middle button */
793 input_report_key(dev, BTN_LEFT, left);
794 input_report_key(dev, BTN_RIGHT, right);
799 static void alps_process_packet_v4(struct psmouse *psmouse)
801 struct alps_data *priv = psmouse->private;
802 unsigned char *packet = psmouse->packet;
803 struct input_dev *dev = psmouse->dev;
809 unsigned int x_bitmap, y_bitmap;
812 * v4 has a 6-byte encoding for bitmap data, but this data is
813 * broken up between 3 normal packets. Use priv->multi_packet to
814 * track our position in the bitmap packet.
816 if (packet[6] & 0x40) {
817 /* sync, reset position */
818 priv->multi_packet = 0;
821 if (WARN_ON_ONCE(priv->multi_packet > 2))
824 offset = 2 * priv->multi_packet;
825 priv->multi_data[offset] = packet[6];
826 priv->multi_data[offset + 1] = packet[7];
828 if (++priv->multi_packet > 2) {
829 priv->multi_packet = 0;
831 x_bitmap = ((priv->multi_data[2] & 0x1f) << 10) |
832 ((priv->multi_data[3] & 0x60) << 3) |
833 ((priv->multi_data[0] & 0x3f) << 2) |
834 ((priv->multi_data[1] & 0x60) >> 5);
835 y_bitmap = ((priv->multi_data[5] & 0x01) << 10) |
836 ((priv->multi_data[3] & 0x1f) << 5) |
837 (priv->multi_data[1] & 0x1f);
839 fingers = alps_process_bitmap(priv, x_bitmap, y_bitmap,
843 priv->fingers = fingers;
850 left = packet[4] & 0x01;
851 right = packet[4] & 0x02;
853 x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
854 ((packet[0] & 0x30) >> 4);
855 y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
856 z = packet[5] & 0x7f;
859 * If there were no contacts in the bitmap, use ST
860 * points in MT reports.
861 * If there were two contacts or more, report MT data.
863 if (priv->fingers < 2) {
866 fingers = z > 0 ? 1 : 0;
868 fingers = priv->fingers;
876 input_report_key(dev, BTN_TOUCH, 1);
878 input_report_key(dev, BTN_TOUCH, 0);
880 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
882 input_mt_report_finger_count(dev, fingers);
884 input_report_key(dev, BTN_LEFT, left);
885 input_report_key(dev, BTN_RIGHT, right);
888 input_report_abs(dev, ABS_X, x);
889 input_report_abs(dev, ABS_Y, y);
891 input_report_abs(dev, ABS_PRESSURE, z);
896 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
897 unsigned char packet[],
900 struct alps_data *priv = psmouse->private;
901 struct input_dev *dev2 = priv->dev2;
904 alps_report_buttons(psmouse, dev2, psmouse->dev,
905 packet[0] & 1, packet[0] & 2, packet[0] & 4);
907 input_report_rel(dev2, REL_X,
908 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
909 input_report_rel(dev2, REL_Y,
910 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
915 static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
917 struct alps_data *priv = psmouse->private;
919 if (psmouse->pktcnt < 6)
920 return PSMOUSE_GOOD_DATA;
922 if (psmouse->pktcnt == 6) {
924 * Start a timer to flush the packet if it ends up last
925 * 6-byte packet in the stream. Timer needs to fire
926 * psmouse core times out itself. 20 ms should be enough
927 * to decide if we are getting more data or not.
929 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
930 return PSMOUSE_GOOD_DATA;
933 del_timer(&priv->timer);
935 if (psmouse->packet[6] & 0x80) {
938 * Highest bit is set - that means we either had
939 * complete ALPS packet and this is start of the
940 * next packet or we got garbage.
943 if (((psmouse->packet[3] |
945 psmouse->packet[5]) & 0x80) ||
946 (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
948 "refusing packet %4ph (suspected interleaved ps/2)\n",
949 psmouse->packet + 3);
950 return PSMOUSE_BAD_DATA;
953 priv->process_packet(psmouse);
955 /* Continue with the next packet */
956 psmouse->packet[0] = psmouse->packet[6];
962 * High bit is 0 - that means that we indeed got a PS/2
963 * packet in the middle of ALPS packet.
965 * There is also possibility that we got 6-byte ALPS
966 * packet followed by 3-byte packet from trackpoint. We
967 * can not distinguish between these 2 scenarios but
968 * because the latter is unlikely to happen in course of
969 * normal operation (user would need to press all
970 * buttons on the pad and start moving trackpoint
971 * without touching the pad surface) we assume former.
972 * Even if we are wrong the wost thing that would happen
973 * the cursor would jump but we should not get protocol
974 * de-synchronization.
977 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
981 * Continue with the standard ALPS protocol handling,
982 * but make sure we won't process it as an interleaved
983 * packet again, which may happen if all buttons are
984 * pressed. To avoid this let's reset the 4th bit which
987 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
991 return PSMOUSE_GOOD_DATA;
994 static void alps_flush_packet(unsigned long data)
996 struct psmouse *psmouse = (struct psmouse *)data;
997 struct alps_data *priv = psmouse->private;
999 serio_pause_rx(psmouse->ps2dev.serio);
1001 if (psmouse->pktcnt == psmouse->pktsize) {
1004 * We did not any more data in reasonable amount of time.
1005 * Validate the last 3 bytes and process as a standard
1008 if ((psmouse->packet[3] |
1009 psmouse->packet[4] |
1010 psmouse->packet[5]) & 0x80) {
1011 psmouse_dbg(psmouse,
1012 "refusing packet %3ph (suspected interleaved ps/2)\n",
1013 psmouse->packet + 3);
1015 priv->process_packet(psmouse);
1017 psmouse->pktcnt = 0;
1020 serio_continue_rx(psmouse->ps2dev.serio);
1023 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
1025 struct alps_data *priv = psmouse->private;
1027 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
1028 if (psmouse->pktcnt == 3) {
1029 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
1031 return PSMOUSE_FULL_PACKET;
1033 return PSMOUSE_GOOD_DATA;
1036 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
1038 if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
1039 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
1040 return alps_handle_interleaved_ps2(psmouse);
1043 if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
1044 psmouse_dbg(psmouse,
1045 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
1046 psmouse->packet[0], priv->mask0, priv->byte0);
1047 return PSMOUSE_BAD_DATA;
1050 /* Bytes 2 - pktsize should have 0 in the highest bit */
1051 if ((priv->proto_version < ALPS_PROTO_V5) &&
1052 psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
1053 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
1054 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
1055 psmouse->pktcnt - 1,
1056 psmouse->packet[psmouse->pktcnt - 1]);
1057 return PSMOUSE_BAD_DATA;
1060 if (psmouse->pktcnt == psmouse->pktsize) {
1061 priv->process_packet(psmouse);
1062 return PSMOUSE_FULL_PACKET;
1065 return PSMOUSE_GOOD_DATA;
1068 static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
1070 struct ps2dev *ps2dev = &psmouse->ps2dev;
1071 struct alps_data *priv = psmouse->private;
1073 unsigned char *param;
1074 unsigned char dummy[4];
1076 BUG_ON(nibble > 0xf);
1078 command = priv->nibble_commands[nibble].command;
1079 param = (command & 0x0f00) ?
1080 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
1082 if (ps2_command(ps2dev, param, command))
1088 static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
1090 struct ps2dev *ps2dev = &psmouse->ps2dev;
1091 struct alps_data *priv = psmouse->private;
1094 if (ps2_command(ps2dev, NULL, priv->addr_command))
1097 for (i = 12; i >= 0; i -= 4) {
1098 nibble = (addr >> i) & 0xf;
1099 if (alps_command_mode_send_nibble(psmouse, nibble))
1106 static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
1108 struct ps2dev *ps2dev = &psmouse->ps2dev;
1109 unsigned char param[4];
1111 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1115 * The address being read is returned in the first two bytes
1116 * of the result. Check that this address matches the expected
1119 if (addr != ((param[0] << 8) | param[1]))
1125 static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
1127 if (alps_command_mode_set_addr(psmouse, addr))
1129 return __alps_command_mode_read_reg(psmouse, addr);
1132 static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
1134 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
1136 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
1141 static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
1144 if (alps_command_mode_set_addr(psmouse, addr))
1146 return __alps_command_mode_write_reg(psmouse, value);
1149 static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
1150 int repeated_command, unsigned char *param)
1152 struct ps2dev *ps2dev = &psmouse->ps2dev;
1155 if (init_command && ps2_command(ps2dev, param, init_command))
1158 if (ps2_command(ps2dev, NULL, repeated_command) ||
1159 ps2_command(ps2dev, NULL, repeated_command) ||
1160 ps2_command(ps2dev, NULL, repeated_command))
1163 param[0] = param[1] = param[2] = 0xff;
1164 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1167 psmouse_dbg(psmouse, "%2.2X report: %3ph\n",
1168 repeated_command, param);
1172 static int alps_enter_command_mode(struct psmouse *psmouse)
1174 unsigned char param[4];
1176 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
1177 psmouse_err(psmouse, "failed to enter command mode\n");
1181 if ((param[0] != 0x88 || (param[1] != 0x07 && param[1] != 0x08)) &&
1183 psmouse_dbg(psmouse,
1184 "unknown response while entering command mode\n");
1190 static inline int alps_exit_command_mode(struct psmouse *psmouse)
1192 struct ps2dev *ps2dev = &psmouse->ps2dev;
1193 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
1199 * For DualPoint devices select the device that should respond to
1200 * subsequent commands. It looks like glidepad is behind stickpointer,
1201 * I'd thought it would be other way around...
1203 static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
1205 struct ps2dev *ps2dev = &psmouse->ps2dev;
1206 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
1208 if (ps2_command(ps2dev, NULL, cmd) ||
1209 ps2_command(ps2dev, NULL, cmd) ||
1210 ps2_command(ps2dev, NULL, cmd) ||
1211 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1214 /* we may get 3 more bytes, just ignore them */
1215 ps2_drain(ps2dev, 3, 100);
1220 static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
1222 struct ps2dev *ps2dev = &psmouse->ps2dev;
1224 /* Try ALPS magic knock - 4 disable before enable */
1225 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1226 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1227 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1228 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1229 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
1233 * Switch mouse to poll (remote) mode so motion data will not
1236 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
1239 static int alps_monitor_mode_send_word(struct psmouse *psmouse, u16 word)
1244 * b0-b11 are valid bits, send sequence is inverse.
1245 * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1
1247 for (i = 0; i <= 8; i += 4) {
1248 nibble = (word >> i) & 0xf;
1249 if (alps_command_mode_send_nibble(psmouse, nibble))
1256 static int alps_monitor_mode_write_reg(struct psmouse *psmouse,
1257 u16 addr, u16 value)
1259 struct ps2dev *ps2dev = &psmouse->ps2dev;
1261 /* 0x0A0 is the command to write the word */
1262 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE) ||
1263 alps_monitor_mode_send_word(psmouse, 0x0A0) ||
1264 alps_monitor_mode_send_word(psmouse, addr) ||
1265 alps_monitor_mode_send_word(psmouse, value) ||
1266 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1272 static int alps_monitor_mode(struct psmouse *psmouse, bool enable)
1274 struct ps2dev *ps2dev = &psmouse->ps2dev;
1277 /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */
1278 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
1279 ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO) ||
1280 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1281 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1282 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1283 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1284 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1285 ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO))
1288 /* EC to exit monitor mode */
1289 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP))
1296 static int alps_absolute_mode_v6(struct psmouse *psmouse)
1298 u16 reg_val = 0x181;
1301 /* enter monitor mode, to write the register */
1302 if (alps_monitor_mode(psmouse, true))
1305 ret = alps_monitor_mode_write_reg(psmouse, 0x000, reg_val);
1307 if (alps_monitor_mode(psmouse, false))
1313 static int alps_get_status(struct psmouse *psmouse, char *param)
1315 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
1316 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
1323 * Turn touchpad tapping on or off. The sequences are:
1324 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1325 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1326 * My guess that 0xE9 (GetInfo) is here as a sync point.
1327 * For models that also have stickpointer (DualPoints) its tapping
1328 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1329 * we don't fiddle with it.
1331 static int alps_tap_mode(struct psmouse *psmouse, int enable)
1333 struct ps2dev *ps2dev = &psmouse->ps2dev;
1334 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
1335 unsigned char tap_arg = enable ? 0x0A : 0x00;
1336 unsigned char param[4];
1338 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
1339 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1340 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1341 ps2_command(ps2dev, &tap_arg, cmd))
1344 if (alps_get_status(psmouse, param))
1351 * alps_poll() - poll the touchpad for current motion packet.
1354 static int alps_poll(struct psmouse *psmouse)
1356 struct alps_data *priv = psmouse->private;
1357 unsigned char buf[sizeof(psmouse->packet)];
1360 if (priv->flags & ALPS_PASS)
1361 alps_passthrough_mode_v2(psmouse, true);
1363 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1364 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1366 if (priv->flags & ALPS_PASS)
1367 alps_passthrough_mode_v2(psmouse, false);
1369 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
1372 if ((psmouse->badbyte & 0xc8) == 0x08) {
1374 * Poll the track stick ...
1376 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
1380 memcpy(psmouse->packet, buf, sizeof(buf));
1384 static int alps_hw_init_v1_v2(struct psmouse *psmouse)
1386 struct alps_data *priv = psmouse->private;
1388 if ((priv->flags & ALPS_PASS) &&
1389 alps_passthrough_mode_v2(psmouse, true)) {
1393 if (alps_tap_mode(psmouse, true)) {
1394 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
1398 if (alps_absolute_mode_v1_v2(psmouse)) {
1399 psmouse_err(psmouse, "Failed to enable absolute mode\n");
1403 if ((priv->flags & ALPS_PASS) &&
1404 alps_passthrough_mode_v2(psmouse, false)) {
1408 /* ALPS needs stream mode, otherwise it won't report any data */
1409 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
1410 psmouse_err(psmouse, "Failed to enable stream mode\n");
1417 static int alps_hw_init_v6(struct psmouse *psmouse)
1419 unsigned char param[2] = {0xC8, 0x14};
1421 /* Enter passthrough mode to let trackpoint enter 6byte raw mode */
1422 if (alps_passthrough_mode_v2(psmouse, true))
1425 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1426 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1427 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1428 ps2_command(&psmouse->ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
1429 ps2_command(&psmouse->ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE))
1432 if (alps_passthrough_mode_v2(psmouse, false))
1435 if (alps_absolute_mode_v6(psmouse)) {
1436 psmouse_err(psmouse, "Failed to enable absolute mode\n");
1444 * Enable or disable passthrough mode to the trackstick.
1446 static int alps_passthrough_mode_v3(struct psmouse *psmouse,
1447 int reg_base, bool enable)
1449 int reg_val, ret = -1;
1451 if (alps_enter_command_mode(psmouse))
1454 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008);
1463 ret = __alps_command_mode_write_reg(psmouse, reg_val);
1466 if (alps_exit_command_mode(psmouse))
1471 /* Must be in command mode when calling this function */
1472 static int alps_absolute_mode_v3(struct psmouse *psmouse)
1476 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1481 if (__alps_command_mode_write_reg(psmouse, reg_val))
1487 static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base)
1489 int ret = -EIO, reg_val;
1491 if (alps_enter_command_mode(psmouse))
1494 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
1498 /* bit 7: trackstick is present */
1499 ret = reg_val & 0x80 ? 0 : -ENODEV;
1502 alps_exit_command_mode(psmouse);
1506 static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
1508 struct ps2dev *ps2dev = &psmouse->ps2dev;
1510 unsigned char param[4];
1512 if (alps_passthrough_mode_v3(psmouse, reg_base, true))
1516 * E7 report for the trackstick
1518 * There have been reports of failures to seem to trace back
1519 * to the above trackstick check failing. When these occur
1520 * this E7 report fails, so when that happens we continue
1521 * with the assumption that there isn't a trackstick after
1524 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) {
1525 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1528 psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param);
1531 * Not sure what this does, but it is absolutely
1532 * essential. Without it, the touchpad does not
1533 * work at all and the trackstick just emits normal
1536 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1537 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1538 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1539 alps_command_mode_send_nibble(psmouse, 0x9) ||
1540 alps_command_mode_send_nibble(psmouse, 0x4)) {
1541 psmouse_err(psmouse,
1542 "Error sending magic E6 sequence\n");
1548 * This ensures the trackstick packets are in the format
1549 * supported by this driver. If bit 1 isn't set the packet
1550 * format is different.
1552 if (alps_enter_command_mode(psmouse) ||
1553 alps_command_mode_write_reg(psmouse,
1554 reg_base + 0x08, 0x82) ||
1555 alps_exit_command_mode(psmouse))
1560 if (alps_passthrough_mode_v3(psmouse, reg_base, false))
1566 static int alps_hw_init_v3(struct psmouse *psmouse)
1568 struct ps2dev *ps2dev = &psmouse->ps2dev;
1570 unsigned char param[4];
1572 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE);
1573 if (reg_val == -EIO)
1577 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO)
1580 if (alps_enter_command_mode(psmouse) ||
1581 alps_absolute_mode_v3(psmouse)) {
1582 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1586 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1589 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1592 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1595 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1598 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1600 if (__alps_command_mode_write_reg(psmouse, 0x04))
1603 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1605 if (__alps_command_mode_write_reg(psmouse, 0x03))
1608 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1610 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1613 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1615 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1618 alps_exit_command_mode(psmouse);
1620 /* Set rate and enable data reporting */
1622 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1623 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1624 psmouse_err(psmouse, "Failed to enable data reporting\n");
1632 * Leaving the touchpad in command mode will essentially render
1633 * it unusable until the machine reboots, so exit it here just
1636 alps_exit_command_mode(psmouse);
1640 static int alps_hw_init_rushmore_v3(struct psmouse *psmouse)
1642 struct alps_data *priv = psmouse->private;
1643 struct ps2dev *ps2dev = &psmouse->ps2dev;
1644 int reg_val, ret = -1;
1646 if (priv->flags & ALPS_DUALPOINT) {
1647 reg_val = alps_setup_trackstick_v3(psmouse,
1648 ALPS_REG_BASE_RUSHMORE);
1649 if (reg_val == -EIO)
1651 if (reg_val == -ENODEV)
1652 priv->flags &= ~ALPS_DUALPOINT;
1655 if (alps_enter_command_mode(psmouse) ||
1656 alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 ||
1657 alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00))
1660 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6);
1663 if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd))
1666 if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64))
1669 /* enter absolute mode */
1670 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4);
1673 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02))
1676 alps_exit_command_mode(psmouse);
1677 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1680 alps_exit_command_mode(psmouse);
1684 /* Must be in command mode when calling this function */
1685 static int alps_absolute_mode_v4(struct psmouse *psmouse)
1689 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1694 if (__alps_command_mode_write_reg(psmouse, reg_val))
1700 static int alps_hw_init_v4(struct psmouse *psmouse)
1702 struct ps2dev *ps2dev = &psmouse->ps2dev;
1703 unsigned char param[4];
1705 if (alps_enter_command_mode(psmouse))
1708 if (alps_absolute_mode_v4(psmouse)) {
1709 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1713 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1716 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1719 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1722 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1725 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1728 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1731 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1734 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1737 alps_exit_command_mode(psmouse);
1740 * This sequence changes the output from a 9-byte to an
1741 * 8-byte format. All the same data seems to be present,
1742 * just in a more compact format.
1747 if (ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
1748 ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE) ||
1749 ps2_command(ps2dev, ¶m[2], PSMOUSE_CMD_SETRATE) ||
1750 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1753 /* Set rate and enable data reporting */
1755 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1756 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1757 psmouse_err(psmouse, "Failed to enable data reporting\n");
1765 * Leaving the touchpad in command mode will essentially render
1766 * it unusable until the machine reboots, so exit it here just
1769 alps_exit_command_mode(psmouse);
1773 static int alps_dolphin_get_device_area(struct psmouse *psmouse,
1774 struct alps_data *priv)
1776 struct ps2dev *ps2dev = &psmouse->ps2dev;
1777 unsigned char param[4] = {0};
1778 int num_x_electrode, num_y_electrode;
1780 if (alps_enter_command_mode(psmouse))
1784 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
1785 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
1786 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
1787 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
1788 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE))
1791 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1795 * Dolphin's sensor line number is not fixed. It can be calculated
1796 * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET.
1797 * Further more, we can get device's x_max and y_max by multiplying
1798 * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE.
1800 * e.g. When we get register's sensor_x = 11 & sensor_y = 8,
1801 * real sensor line number X = 11 + 8 = 19, and
1802 * real sensor line number Y = 8 + 1 = 9.
1803 * So, x_max = (19 - 1) * 64 = 1152, and
1804 * y_max = (9 - 1) * 64 = 512.
1806 num_x_electrode = DOLPHIN_PROFILE_XOFFSET + (param[2] & 0x0F);
1807 num_y_electrode = DOLPHIN_PROFILE_YOFFSET + ((param[2] >> 4) & 0x0F);
1808 priv->x_bits = num_x_electrode;
1809 priv->y_bits = num_y_electrode;
1810 priv->x_max = (num_x_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE;
1811 priv->y_max = (num_y_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE;
1813 if (alps_exit_command_mode(psmouse))
1819 static int alps_hw_init_dolphin_v1(struct psmouse *psmouse)
1821 struct ps2dev *ps2dev = &psmouse->ps2dev;
1822 unsigned char param[2];
1824 /* This is dolphin "v1" as empirically defined by florin9doi */
1828 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
1829 ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) ||
1830 ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE))
1836 static void alps_set_defaults(struct alps_data *priv)
1840 priv->flags = ALPS_DUALPOINT;
1847 switch (priv->proto_version) {
1850 priv->hw_init = alps_hw_init_v1_v2;
1851 priv->process_packet = alps_process_packet_v1_v2;
1852 priv->set_abs_params = alps_set_abs_params_st;
1857 priv->hw_init = alps_hw_init_v3;
1858 priv->process_packet = alps_process_packet_v3;
1859 priv->set_abs_params = alps_set_abs_params_mt;
1860 priv->decode_fields = alps_decode_pinnacle;
1861 priv->nibble_commands = alps_v3_nibble_commands;
1862 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
1865 priv->hw_init = alps_hw_init_v4;
1866 priv->process_packet = alps_process_packet_v4;
1867 priv->set_abs_params = alps_set_abs_params_mt;
1868 priv->nibble_commands = alps_v4_nibble_commands;
1869 priv->addr_command = PSMOUSE_CMD_DISABLE;
1872 priv->hw_init = alps_hw_init_dolphin_v1;
1873 priv->process_packet = alps_process_touchpad_packet_v3_v5;
1874 priv->decode_fields = alps_decode_dolphin;
1875 priv->set_abs_params = alps_set_abs_params_mt;
1876 priv->nibble_commands = alps_v3_nibble_commands;
1877 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
1887 priv->hw_init = alps_hw_init_v6;
1888 priv->process_packet = alps_process_packet_v6;
1889 priv->set_abs_params = alps_set_abs_params_st;
1890 priv->nibble_commands = alps_v6_nibble_commands;
1897 static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv,
1898 unsigned char *e7, unsigned char *ec)
1900 const struct alps_model_info *model;
1903 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1904 model = &alps_model_data[i];
1906 if (!memcmp(e7, model->signature, sizeof(model->signature)) &&
1907 (!model->command_mode_resp ||
1908 model->command_mode_resp == ec[2])) {
1910 priv->proto_version = model->proto_version;
1911 alps_set_defaults(priv);
1913 priv->flags = model->flags;
1914 priv->byte0 = model->byte0;
1915 priv->mask0 = model->mask0;
1924 static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
1926 unsigned char e6[4], e7[4], ec[4];
1929 * First try "E6 report".
1930 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
1931 * The bits 0-2 of the first byte will be 1s if some buttons are
1934 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1935 PSMOUSE_CMD_SETSCALE11, e6))
1938 if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100))
1942 * Now get the "E7" and "EC" reports. These will uniquely identify
1943 * most ALPS touchpads.
1945 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1946 PSMOUSE_CMD_SETSCALE21, e7) ||
1947 alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1948 PSMOUSE_CMD_RESET_WRAP, ec) ||
1949 alps_exit_command_mode(psmouse))
1952 if (alps_match_table(psmouse, priv, e7, ec) == 0) {
1954 } else if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 &&
1955 ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) {
1956 priv->proto_version = ALPS_PROTO_V5;
1957 alps_set_defaults(priv);
1958 if (alps_dolphin_get_device_area(psmouse, priv))
1962 } else if (ec[0] == 0x88 && ec[1] == 0x08) {
1963 priv->proto_version = ALPS_PROTO_V3;
1964 alps_set_defaults(priv);
1966 priv->hw_init = alps_hw_init_rushmore_v3;
1967 priv->decode_fields = alps_decode_rushmore;
1970 priv->flags |= ALPS_IS_RUSHMORE;
1972 /* hack to make addr_command, nibble_command available */
1973 psmouse->private = priv;
1975 if (alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_RUSHMORE))
1976 priv->flags &= ~ALPS_DUALPOINT;
1979 } else if (ec[0] == 0x88 && ec[1] == 0x07 &&
1980 ec[2] >= 0x90 && ec[2] <= 0x9d) {
1981 priv->proto_version = ALPS_PROTO_V3;
1982 alps_set_defaults(priv);
1987 psmouse_info(psmouse,
1988 "Unknown ALPS touchpad: E7=%3ph, EC=%3ph\n", e7, ec);
1993 static int alps_reconnect(struct psmouse *psmouse)
1995 struct alps_data *priv = psmouse->private;
1997 psmouse_reset(psmouse);
1999 if (alps_identify(psmouse, priv) < 0)
2002 return priv->hw_init(psmouse);
2005 static void alps_disconnect(struct psmouse *psmouse)
2007 struct alps_data *priv = psmouse->private;
2009 psmouse_reset(psmouse);
2010 del_timer_sync(&priv->timer);
2011 input_unregister_device(priv->dev2);
2015 static void alps_set_abs_params_st(struct alps_data *priv,
2016 struct input_dev *dev1)
2018 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
2019 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
2022 static void alps_set_abs_params_mt(struct alps_data *priv,
2023 struct input_dev *dev1)
2025 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
2026 input_mt_init_slots(dev1, 2, 0);
2027 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0);
2028 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0);
2030 set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
2031 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
2032 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
2034 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
2035 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
2038 int alps_init(struct psmouse *psmouse)
2040 struct alps_data *priv;
2041 struct input_dev *dev1 = psmouse->dev, *dev2;
2043 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
2044 dev2 = input_allocate_device();
2049 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
2051 psmouse->private = priv;
2053 psmouse_reset(psmouse);
2055 if (alps_identify(psmouse, priv) < 0)
2058 if (priv->hw_init(psmouse))
2062 * Undo part of setup done for us by psmouse core since touchpad
2063 * is not a relative device.
2065 __clear_bit(EV_REL, dev1->evbit);
2066 __clear_bit(REL_X, dev1->relbit);
2067 __clear_bit(REL_Y, dev1->relbit);
2070 * Now set up our capabilities.
2072 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
2073 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
2074 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
2075 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
2076 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
2078 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
2080 priv->set_abs_params(priv, dev1);
2081 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
2083 if (priv->flags & ALPS_WHEEL) {
2084 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
2085 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
2088 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
2089 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
2090 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
2093 if (priv->flags & ALPS_FOUR_BUTTONS) {
2094 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
2095 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
2096 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
2097 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
2099 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
2102 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
2103 dev2->phys = priv->phys;
2104 dev2->name = (priv->flags & ALPS_DUALPOINT) ?
2105 "DualPoint Stick" : "ALPS PS/2 Device";
2106 dev2->id.bustype = BUS_I8042;
2107 dev2->id.vendor = 0x0002;
2108 dev2->id.product = PSMOUSE_ALPS;
2109 dev2->id.version = 0x0000;
2110 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
2112 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
2113 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
2114 dev2->keybit[BIT_WORD(BTN_LEFT)] =
2115 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
2117 if (input_register_device(priv->dev2))
2120 psmouse->protocol_handler = alps_process_byte;
2121 psmouse->poll = alps_poll;
2122 psmouse->disconnect = alps_disconnect;
2123 psmouse->reconnect = alps_reconnect;
2124 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
2126 /* We are having trouble resyncing ALPS touchpads so disable it for now */
2127 psmouse->resync_time = 0;
2132 psmouse_reset(psmouse);
2133 input_free_device(dev2);
2135 psmouse->private = NULL;
2139 int alps_detect(struct psmouse *psmouse, bool set_properties)
2141 struct alps_data dummy;
2143 if (alps_identify(psmouse, &dummy) < 0)
2146 if (set_properties) {
2147 psmouse->vendor = "ALPS";
2148 psmouse->name = dummy.flags & ALPS_DUALPOINT ?
2149 "DualPoint TouchPad" : "GlidePoint";
2150 psmouse->model = dummy.proto_version << 8;