]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/input/mouse/alps.c
Input: ALPS - copy "model" info into alps_data struct
[mirror_ubuntu-zesty-kernel.git] / drivers / input / mouse / alps.c
CommitLineData
1da177e4
LT
1/*
2 * ALPS touchpad PS/2 mouse driver
3 *
4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
963f626d 5 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
1da177e4
LT
6 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
1d9f2626 8 * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net>
1da177e4
LT
9 *
10 * ALPS detection, tap switching and status querying info is taken from
11 * tpconfig utility (by C. Scott Ananian and Bruce Kall).
12 *
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.
16 */
17
5a0e3ad6 18#include <linux/slab.h>
1da177e4 19#include <linux/input.h>
01ce661f 20#include <linux/input/mt.h>
1da177e4
LT
21#include <linux/serio.h>
22#include <linux/libps2.h>
23
24#include "psmouse.h"
25#include "alps.h"
26
25bded7c
SF
27/*
28 * Definitions for ALPS version 3 and 4 command mode protocol
29 */
01ce661f
SF
30#define ALPS_V3_X_MAX 2000
31#define ALPS_V3_Y_MAX 1400
32
33#define ALPS_BITMAP_X_BITS 15
34#define ALPS_BITMAP_Y_BITS 11
35
25bded7c
SF
36#define ALPS_CMD_NIBBLE_10 0x01f2
37
38static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
39 { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
40 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
41 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
42 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
43 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
44 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
45 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
46 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
47 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
48 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
49 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
50 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
51 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
52 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
53 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
54 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
55};
56
57static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
58 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
59 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
60 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
61 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
62 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
63 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
64 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
65 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
66 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
67 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
68 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
69 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
70 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
71 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
72 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
73 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
74};
75
76
71bb21b6
ML
77#define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
78#define ALPS_PASS 0x04 /* device has a pass-through port */
79
80#define ALPS_WHEEL 0x08 /* hardware wheel present */
81#define ALPS_FW_BK_1 0x10 /* front & back buttons present */
82#define ALPS_FW_BK_2 0x20 /* front & back buttons present */
83#define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
1d9f2626
SK
84#define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
85 6-byte ALPS packet */
1da177e4 86
e38de678 87static const struct alps_model_info alps_model_data[] = {
25bded7c
SF
88 { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
89 { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
90 { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
91 { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
92 { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
93 { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
94 { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
95 { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
96 { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
97 { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
98 { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
99 { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
100 { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
101 { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
102 { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
103 { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
104 { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
105 { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
1d9f2626 106 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
25bded7c 107 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
1d9f2626 108 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
25bded7c
SF
109 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
110 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
111 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
112 { { 0x73, 0x02, 0x64 }, 0x9b, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
113 { { 0x73, 0x02, 0x64 }, 0x9d, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
114 { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
1da177e4
LT
115};
116
117/*
118 * XXX - this entry is suspicious. First byte has zero lower nibble,
119 * which is what a normal mouse would report. Also, the value 0x0e
120 * isn't valid per PS/2 spec.
121 */
122
d4b347b2 123/* Packet formats are described in Documentation/input/alps.txt */
1da177e4 124
99df65e7 125static bool alps_is_valid_first_byte(struct alps_data *priv,
1d9f2626
SK
126 unsigned char data)
127{
99df65e7 128 return (data & priv->mask0) == priv->byte0;
1d9f2626
SK
129}
130
131static void alps_report_buttons(struct psmouse *psmouse,
132 struct input_dev *dev1, struct input_dev *dev2,
133 int left, int right, int middle)
134{
c91ed059
MB
135 struct input_dev *dev;
136
137 /*
138 * If shared button has already been reported on the
139 * other device (dev2) then this event should be also
140 * sent through that device.
141 */
142 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
143 input_report_key(dev, BTN_LEFT, left);
144
145 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
146 input_report_key(dev, BTN_RIGHT, right);
147
148 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
149 input_report_key(dev, BTN_MIDDLE, middle);
150
151 /*
152 * Sync the _other_ device now, we'll do the first
153 * device later once we report the rest of the events.
154 */
155 input_sync(dev2);
1d9f2626
SK
156}
157
25bded7c 158static void alps_process_packet_v1_v2(struct psmouse *psmouse)
1da177e4
LT
159{
160 struct alps_data *priv = psmouse->private;
161 unsigned char *packet = psmouse->packet;
2e5b636b
DT
162 struct input_dev *dev = psmouse->dev;
163 struct input_dev *dev2 = priv->dev2;
1da177e4 164 int x, y, z, ges, fin, left, right, middle;
c30b4c10 165 int back = 0, forward = 0;
1da177e4 166
99df65e7 167 if (priv->proto_version == ALPS_PROTO_V1) {
d2f4012f
YM
168 left = packet[2] & 0x10;
169 right = packet[2] & 0x08;
1da177e4
LT
170 middle = 0;
171 x = packet[1] | ((packet[0] & 0x07) << 7);
172 y = packet[4] | ((packet[3] & 0x07) << 7);
173 z = packet[5];
174 } else {
175 left = packet[3] & 1;
176 right = packet[3] & 2;
177 middle = packet[3] & 4;
178 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
179 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
180 z = packet[5];
181 }
182
99df65e7 183 if (priv->flags & ALPS_FW_BK_1) {
3c00bb96
LK
184 back = packet[0] & 0x10;
185 forward = packet[2] & 4;
c30b4c10
ICR
186 }
187
99df65e7 188 if (priv->flags & ALPS_FW_BK_2) {
c30b4c10
ICR
189 back = packet[3] & 4;
190 forward = packet[2] & 4;
191 if ((middle = forward && back))
192 forward = back = 0;
193 }
194
1da177e4
LT
195 ges = packet[2] & 1;
196 fin = packet[2] & 2;
197
99df65e7 198 if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
1da177e4
LT
199 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
200 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
d7ed5d88 201
1d9f2626 202 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
d7ed5d88 203
1da177e4
LT
204 input_sync(dev2);
205 return;
206 }
207
1d9f2626 208 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
d7ed5d88 209
1da177e4 210 /* Convert hardware tap to a reasonable Z value */
71bb21b6
ML
211 if (ges && !fin)
212 z = 40;
1da177e4
LT
213
214 /*
215 * A "tap and drag" operation is reported by the hardware as a transition
216 * from (!fin && ges) to (fin && ges). This should be translated to the
217 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
218 */
219 if (ges && fin && !priv->prev_fin) {
220 input_report_abs(dev, ABS_X, x);
221 input_report_abs(dev, ABS_Y, y);
222 input_report_abs(dev, ABS_PRESSURE, 0);
223 input_report_key(dev, BTN_TOOL_FINGER, 0);
224 input_sync(dev);
225 }
226 priv->prev_fin = fin;
227
71bb21b6
ML
228 if (z > 30)
229 input_report_key(dev, BTN_TOUCH, 1);
230 if (z < 25)
231 input_report_key(dev, BTN_TOUCH, 0);
1da177e4
LT
232
233 if (z > 0) {
234 input_report_abs(dev, ABS_X, x);
235 input_report_abs(dev, ABS_Y, y);
236 }
237
238 input_report_abs(dev, ABS_PRESSURE, z);
239 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
240
99df65e7 241 if (priv->flags & ALPS_WHEEL)
e6c047b9 242 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
1da177e4 243
99df65e7 244 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
c30b4c10
ICR
245 input_report_key(dev, BTN_FORWARD, forward);
246 input_report_key(dev, BTN_BACK, back);
1da177e4
LT
247 }
248
99df65e7 249 if (priv->flags & ALPS_FOUR_BUTTONS) {
71bb21b6
ML
250 input_report_key(dev, BTN_0, packet[2] & 4);
251 input_report_key(dev, BTN_1, packet[0] & 0x10);
252 input_report_key(dev, BTN_2, packet[3] & 4);
253 input_report_key(dev, BTN_3, packet[0] & 0x20);
254 }
255
1da177e4
LT
256 input_sync(dev);
257}
258
01ce661f
SF
259/*
260 * Process bitmap data from v3 and v4 protocols. Returns the number of
261 * fingers detected. A return value of 0 means at least one of the
262 * bitmaps was empty.
263 *
264 * The bitmaps don't have enough data to track fingers, so this function
265 * only generates points representing a bounding box of all contacts.
266 * These points are returned in x1, y1, x2, and y2 when the return value
267 * is greater than 0.
268 */
269static int alps_process_bitmap(unsigned int x_map, unsigned int y_map,
270 int *x1, int *y1, int *x2, int *y2)
271{
272 struct alps_bitmap_point {
273 int start_bit;
274 int num_bits;
275 };
276
277 int fingers_x = 0, fingers_y = 0, fingers;
278 int i, bit, prev_bit;
279 struct alps_bitmap_point x_low = {0,}, x_high = {0,};
280 struct alps_bitmap_point y_low = {0,}, y_high = {0,};
281 struct alps_bitmap_point *point;
282
283 if (!x_map || !y_map)
284 return 0;
285
286 *x1 = *y1 = *x2 = *y2 = 0;
287
288 prev_bit = 0;
289 point = &x_low;
290 for (i = 0; x_map != 0; i++, x_map >>= 1) {
291 bit = x_map & 1;
292 if (bit) {
293 if (!prev_bit) {
294 point->start_bit = i;
295 fingers_x++;
296 }
297 point->num_bits++;
298 } else {
299 if (prev_bit)
300 point = &x_high;
301 else
302 point->num_bits = 0;
303 }
304 prev_bit = bit;
305 }
306
307 /*
308 * y bitmap is reversed for what we need (lower positions are in
309 * higher bits), so we process from the top end.
310 */
311 y_map = y_map << (sizeof(y_map) * BITS_PER_BYTE - ALPS_BITMAP_Y_BITS);
312 prev_bit = 0;
313 point = &y_low;
314 for (i = 0; y_map != 0; i++, y_map <<= 1) {
315 bit = y_map & (1 << (sizeof(y_map) * BITS_PER_BYTE - 1));
316 if (bit) {
317 if (!prev_bit) {
318 point->start_bit = i;
319 fingers_y++;
320 }
321 point->num_bits++;
322 } else {
323 if (prev_bit)
324 point = &y_high;
325 else
326 point->num_bits = 0;
327 }
328 prev_bit = bit;
329 }
330
331 /*
332 * Fingers can overlap, so we use the maximum count of fingers
333 * on either axis as the finger count.
334 */
335 fingers = max(fingers_x, fingers_y);
336
337 /*
338 * If total fingers is > 1 but either axis reports only a single
339 * contact, we have overlapping or adjacent fingers. For the
340 * purposes of creating a bounding box, divide the single contact
341 * (roughly) equally between the two points.
342 */
343 if (fingers > 1) {
344 if (fingers_x == 1) {
345 i = x_low.num_bits / 2;
346 x_low.num_bits = x_low.num_bits - i;
347 x_high.start_bit = x_low.start_bit + i;
348 x_high.num_bits = max(i, 1);
349 } else if (fingers_y == 1) {
350 i = y_low.num_bits / 2;
351 y_low.num_bits = y_low.num_bits - i;
352 y_high.start_bit = y_low.start_bit + i;
353 y_high.num_bits = max(i, 1);
354 }
355 }
356
357 *x1 = (ALPS_V3_X_MAX * (2 * x_low.start_bit + x_low.num_bits - 1)) /
358 (2 * (ALPS_BITMAP_X_BITS - 1));
359 *y1 = (ALPS_V3_Y_MAX * (2 * y_low.start_bit + y_low.num_bits - 1)) /
360 (2 * (ALPS_BITMAP_Y_BITS - 1));
361
362 if (fingers > 1) {
363 *x2 = (ALPS_V3_X_MAX * (2 * x_high.start_bit + x_high.num_bits - 1)) /
364 (2 * (ALPS_BITMAP_X_BITS - 1));
365 *y2 = (ALPS_V3_Y_MAX * (2 * y_high.start_bit + y_high.num_bits - 1)) /
366 (2 * (ALPS_BITMAP_Y_BITS - 1));
367 }
368
369 return fingers;
370}
371
372static void alps_set_slot(struct input_dev *dev, int slot, bool active,
373 int x, int y)
374{
375 input_mt_slot(dev, slot);
376 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
377 if (active) {
378 input_report_abs(dev, ABS_MT_POSITION_X, x);
379 input_report_abs(dev, ABS_MT_POSITION_Y, y);
380 }
381}
382
383static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers,
384 int x1, int y1, int x2, int y2)
385{
386 alps_set_slot(dev, 0, num_fingers != 0, x1, y1);
387 alps_set_slot(dev, 1, num_fingers == 2, x2, y2);
388}
389
25bded7c
SF
390static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
391{
392 struct alps_data *priv = psmouse->private;
393 unsigned char *packet = psmouse->packet;
394 struct input_dev *dev = priv->dev2;
395 int x, y, z, left, right, middle;
396
397 /* Sanity check packet */
398 if (!(packet[0] & 0x40)) {
399 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
400 return;
401 }
402
403 /*
404 * There's a special packet that seems to indicate the end
405 * of a stream of trackstick data. Filter these out.
406 */
407 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
408 return;
409
410 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
411 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
412 z = (packet[4] & 0x7c) >> 2;
413
414 /*
415 * The x and y values tend to be quite large, and when used
416 * alone the trackstick is difficult to use. Scale them down
417 * to compensate.
418 */
419 x /= 8;
420 y /= 8;
421
422 input_report_rel(dev, REL_X, x);
423 input_report_rel(dev, REL_Y, -y);
424
425 /*
426 * Most ALPS models report the trackstick buttons in the touchpad
427 * packets, but a few report them here. No reliable way has been
428 * found to differentiate between the models upfront, so we enable
429 * the quirk in response to seeing a button press in the trackstick
430 * packet.
431 */
432 left = packet[3] & 0x01;
433 right = packet[3] & 0x02;
434 middle = packet[3] & 0x04;
435
436 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
437 (left || right || middle))
438 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
439
440 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
441 input_report_key(dev, BTN_LEFT, left);
442 input_report_key(dev, BTN_RIGHT, right);
443 input_report_key(dev, BTN_MIDDLE, middle);
444 }
445
446 input_sync(dev);
447 return;
448}
449
450static void alps_process_touchpad_packet_v3(struct psmouse *psmouse)
451{
452 struct alps_data *priv = psmouse->private;
453 unsigned char *packet = psmouse->packet;
454 struct input_dev *dev = psmouse->dev;
455 struct input_dev *dev2 = priv->dev2;
456 int x, y, z;
457 int left, right, middle;
01ce661f
SF
458 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
459 int fingers = 0, bmap_fingers;
460 unsigned int x_bitmap, y_bitmap;
25bded7c
SF
461
462 /*
01ce661f
SF
463 * There's no single feature of touchpad position and bitmap packets
464 * that can be used to distinguish between them. We rely on the fact
465 * that a bitmap packet should always follow a position packet with
466 * bit 6 of packet[4] set.
25bded7c
SF
467 */
468 if (priv->multi_packet) {
25bded7c
SF
469 /*
470 * Sometimes a position packet will indicate a multi-packet
471 * sequence, but then what follows is another position
472 * packet. Check for this, and when it happens process the
473 * position packet as usual.
474 */
475 if (packet[0] & 0x40) {
01ce661f
SF
476 fingers = (packet[5] & 0x3) + 1;
477 x_bitmap = ((packet[4] & 0x7e) << 8) |
478 ((packet[1] & 0x7f) << 2) |
479 ((packet[0] & 0x30) >> 4);
480 y_bitmap = ((packet[3] & 0x70) << 4) |
481 ((packet[2] & 0x7f) << 1) |
482 (packet[4] & 0x01);
483
484 bmap_fingers = alps_process_bitmap(x_bitmap, y_bitmap,
485 &x1, &y1, &x2, &y2);
486
25bded7c 487 /*
01ce661f
SF
488 * We shouldn't report more than one finger if
489 * we don't have two coordinates.
25bded7c 490 */
01ce661f
SF
491 if (fingers > 1 && bmap_fingers < 2)
492 fingers = bmap_fingers;
493
494 /* Now process position packet */
495 packet = priv->multi_data;
496 } else {
497 priv->multi_packet = 0;
25bded7c
SF
498 }
499 }
500
01ce661f
SF
501 /*
502 * Bit 6 of byte 0 is not usually set in position packets. The only
503 * times it seems to be set is in situations where the data is
504 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
505 * this combined with the fact that this bit is useful for filtering
506 * out misidentified bitmap packets, we reject anything with this
507 * bit set.
508 */
509 if (packet[0] & 0x40)
510 return;
511
512 if (!priv->multi_packet && (packet[4] & 0x40)) {
25bded7c 513 priv->multi_packet = 1;
01ce661f
SF
514 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
515 return;
516 }
517
518 priv->multi_packet = 0;
25bded7c
SF
519
520 left = packet[3] & 0x01;
521 right = packet[3] & 0x02;
522 middle = packet[3] & 0x04;
523
524 x = ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) |
525 ((packet[0] & 0x30) >> 4);
526 y = ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f);
527 z = packet[5] & 0x7f;
528
529 /*
530 * Sometimes the hardware sends a single packet with z = 0
531 * in the middle of a stream. Real releases generate packets
532 * with x, y, and z all zero, so these seem to be flukes.
533 * Ignore them.
534 */
535 if (x && y && !z)
536 return;
537
01ce661f
SF
538 /*
539 * If we don't have MT data or the bitmaps were empty, we have
540 * to rely on ST data.
541 */
542 if (!fingers) {
543 x1 = x;
544 y1 = y;
545 fingers = z > 0 ? 1 : 0;
546 }
547
25bded7c
SF
548 if (z >= 64)
549 input_report_key(dev, BTN_TOUCH, 1);
550 else
551 input_report_key(dev, BTN_TOUCH, 0);
552
01ce661f
SF
553 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
554
616575c2 555 input_mt_report_finger_count(dev, fingers);
01ce661f
SF
556
557 input_report_key(dev, BTN_LEFT, left);
558 input_report_key(dev, BTN_RIGHT, right);
559 input_report_key(dev, BTN_MIDDLE, middle);
560
25bded7c
SF
561 if (z > 0) {
562 input_report_abs(dev, ABS_X, x);
563 input_report_abs(dev, ABS_Y, y);
564 }
565 input_report_abs(dev, ABS_PRESSURE, z);
566
25bded7c
SF
567 input_sync(dev);
568
569 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
570 left = packet[3] & 0x10;
571 right = packet[3] & 0x20;
572 middle = packet[3] & 0x40;
573
574 input_report_key(dev2, BTN_LEFT, left);
575 input_report_key(dev2, BTN_RIGHT, right);
576 input_report_key(dev2, BTN_MIDDLE, middle);
577 input_sync(dev2);
578 }
579}
580
581static void alps_process_packet_v3(struct psmouse *psmouse)
582{
583 unsigned char *packet = psmouse->packet;
584
585 /*
586 * v3 protocol packets come in three types, two representing
587 * touchpad data and one representing trackstick data.
588 * Trackstick packets seem to be distinguished by always
589 * having 0x3f in the last byte. This value has never been
590 * observed in the last byte of either of the other types
591 * of packets.
592 */
593 if (packet[5] == 0x3f) {
594 alps_process_trackstick_packet_v3(psmouse);
595 return;
596 }
597
598 alps_process_touchpad_packet_v3(psmouse);
599}
600
601static void alps_process_packet_v4(struct psmouse *psmouse)
602{
3b7e09fa 603 struct alps_data *priv = psmouse->private;
25bded7c
SF
604 unsigned char *packet = psmouse->packet;
605 struct input_dev *dev = psmouse->dev;
3b7e09fa 606 int offset;
25bded7c
SF
607 int x, y, z;
608 int left, right;
3b7e09fa
GP
609 int x1, y1, x2, y2;
610 int fingers = 0;
611 unsigned int x_bitmap, y_bitmap;
612
613 /*
614 * v4 has a 6-byte encoding for bitmap data, but this data is
615 * broken up between 3 normal packets. Use priv->multi_packet to
616 * track our position in the bitmap packet.
617 */
618 if (packet[6] & 0x40) {
619 /* sync, reset position */
620 priv->multi_packet = 0;
621 }
622
623 if (WARN_ON_ONCE(priv->multi_packet > 2))
624 return;
625
626 offset = 2 * priv->multi_packet;
627 priv->multi_data[offset] = packet[6];
628 priv->multi_data[offset + 1] = packet[7];
629
630 if (++priv->multi_packet > 2) {
631 priv->multi_packet = 0;
632
633 x_bitmap = ((priv->multi_data[2] & 0x1f) << 10) |
634 ((priv->multi_data[3] & 0x60) << 3) |
635 ((priv->multi_data[0] & 0x3f) << 2) |
636 ((priv->multi_data[1] & 0x60) >> 5);
637 y_bitmap = ((priv->multi_data[5] & 0x01) << 10) |
638 ((priv->multi_data[3] & 0x1f) << 5) |
639 (priv->multi_data[1] & 0x1f);
640
641 fingers = alps_process_bitmap(x_bitmap, y_bitmap,
642 &x1, &y1, &x2, &y2);
643
644 /* Store MT data.*/
645 priv->fingers = fingers;
646 priv->x1 = x1;
647 priv->x2 = x2;
648 priv->y1 = y1;
649 priv->y2 = y2;
650 }
25bded7c
SF
651
652 left = packet[4] & 0x01;
653 right = packet[4] & 0x02;
654
655 x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
656 ((packet[0] & 0x30) >> 4);
657 y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
658 z = packet[5] & 0x7f;
659
3b7e09fa
GP
660 /*
661 * If there were no contacts in the bitmap, use ST
662 * points in MT reports.
663 * If there were two contacts or more, report MT data.
664 */
665 if (priv->fingers < 2) {
666 x1 = x;
667 y1 = y;
668 fingers = z > 0 ? 1 : 0;
669 } else {
670 fingers = priv->fingers;
671 x1 = priv->x1;
672 x2 = priv->x2;
673 y1 = priv->y1;
674 y2 = priv->y2;
675 }
676
25bded7c
SF
677 if (z >= 64)
678 input_report_key(dev, BTN_TOUCH, 1);
679 else
680 input_report_key(dev, BTN_TOUCH, 0);
681
3b7e09fa
GP
682 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
683
616575c2 684 input_mt_report_finger_count(dev, fingers);
3b7e09fa
GP
685
686 input_report_key(dev, BTN_LEFT, left);
687 input_report_key(dev, BTN_RIGHT, right);
688
25bded7c
SF
689 if (z > 0) {
690 input_report_abs(dev, ABS_X, x);
691 input_report_abs(dev, ABS_Y, y);
692 }
693 input_report_abs(dev, ABS_PRESSURE, z);
694
25bded7c
SF
695 input_sync(dev);
696}
697
698static void alps_process_packet(struct psmouse *psmouse)
699{
700 struct alps_data *priv = psmouse->private;
25bded7c 701
99df65e7 702 switch (priv->proto_version) {
25bded7c
SF
703 case ALPS_PROTO_V1:
704 case ALPS_PROTO_V2:
705 alps_process_packet_v1_v2(psmouse);
706 break;
707 case ALPS_PROTO_V3:
708 alps_process_packet_v3(psmouse);
709 break;
710 case ALPS_PROTO_V4:
711 alps_process_packet_v4(psmouse);
712 break;
713 }
714}
715
1d9f2626
SK
716static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
717 unsigned char packet[],
718 bool report_buttons)
719{
720 struct alps_data *priv = psmouse->private;
721 struct input_dev *dev2 = priv->dev2;
722
723 if (report_buttons)
724 alps_report_buttons(psmouse, dev2, psmouse->dev,
725 packet[0] & 1, packet[0] & 2, packet[0] & 4);
726
727 input_report_rel(dev2, REL_X,
728 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
729 input_report_rel(dev2, REL_Y,
730 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
731
732 input_sync(dev2);
733}
734
735static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
736{
737 struct alps_data *priv = psmouse->private;
738
739 if (psmouse->pktcnt < 6)
740 return PSMOUSE_GOOD_DATA;
741
742 if (psmouse->pktcnt == 6) {
743 /*
744 * Start a timer to flush the packet if it ends up last
745 * 6-byte packet in the stream. Timer needs to fire
746 * psmouse core times out itself. 20 ms should be enough
747 * to decide if we are getting more data or not.
748 */
749 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
750 return PSMOUSE_GOOD_DATA;
751 }
752
753 del_timer(&priv->timer);
754
755 if (psmouse->packet[6] & 0x80) {
756
757 /*
758 * Highest bit is set - that means we either had
759 * complete ALPS packet and this is start of the
760 * next packet or we got garbage.
761 */
762
763 if (((psmouse->packet[3] |
764 psmouse->packet[4] |
765 psmouse->packet[5]) & 0x80) ||
99df65e7 766 (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
b5d21704 767 psmouse_dbg(psmouse,
3b112923
AS
768 "refusing packet %4ph (suspected interleaved ps/2)\n",
769 psmouse->packet + 3);
1d9f2626
SK
770 return PSMOUSE_BAD_DATA;
771 }
772
773 alps_process_packet(psmouse);
774
775 /* Continue with the next packet */
776 psmouse->packet[0] = psmouse->packet[6];
777 psmouse->pktcnt = 1;
778
779 } else {
780
781 /*
782 * High bit is 0 - that means that we indeed got a PS/2
783 * packet in the middle of ALPS packet.
784 *
785 * There is also possibility that we got 6-byte ALPS
786 * packet followed by 3-byte packet from trackpoint. We
787 * can not distinguish between these 2 scenarios but
b5d21704 788 * because the latter is unlikely to happen in course of
1d9f2626
SK
789 * normal operation (user would need to press all
790 * buttons on the pad and start moving trackpoint
791 * without touching the pad surface) we assume former.
792 * Even if we are wrong the wost thing that would happen
793 * the cursor would jump but we should not get protocol
b5d21704 794 * de-synchronization.
1d9f2626
SK
795 */
796
797 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
798 false);
799
800 /*
801 * Continue with the standard ALPS protocol handling,
802 * but make sure we won't process it as an interleaved
803 * packet again, which may happen if all buttons are
804 * pressed. To avoid this let's reset the 4th bit which
805 * is normally 1.
806 */
807 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
808 psmouse->pktcnt = 4;
809 }
810
811 return PSMOUSE_GOOD_DATA;
812}
813
814static void alps_flush_packet(unsigned long data)
815{
816 struct psmouse *psmouse = (struct psmouse *)data;
817
818 serio_pause_rx(psmouse->ps2dev.serio);
819
b46615fe 820 if (psmouse->pktcnt == psmouse->pktsize) {
1d9f2626
SK
821
822 /*
823 * We did not any more data in reasonable amount of time.
824 * Validate the last 3 bytes and process as a standard
825 * ALPS packet.
826 */
827 if ((psmouse->packet[3] |
828 psmouse->packet[4] |
829 psmouse->packet[5]) & 0x80) {
b5d21704 830 psmouse_dbg(psmouse,
3b112923
AS
831 "refusing packet %3ph (suspected interleaved ps/2)\n",
832 psmouse->packet + 3);
1d9f2626
SK
833 } else {
834 alps_process_packet(psmouse);
835 }
836 psmouse->pktcnt = 0;
837 }
838
839 serio_continue_rx(psmouse->ps2dev.serio);
840}
841
7d12e780 842static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
1da177e4
LT
843{
844 struct alps_data *priv = psmouse->private;
845
846 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
847 if (psmouse->pktcnt == 3) {
1d9f2626
SK
848 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
849 true);
1da177e4
LT
850 return PSMOUSE_FULL_PACKET;
851 }
852 return PSMOUSE_GOOD_DATA;
853 }
854
1d9f2626
SK
855 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
856
99df65e7 857 if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
1d9f2626
SK
858 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
859 return alps_handle_interleaved_ps2(psmouse);
860 }
861
99df65e7 862 if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
b5d21704
DT
863 psmouse_dbg(psmouse,
864 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
99df65e7 865 psmouse->packet[0], priv->mask0, priv->byte0);
1da177e4 866 return PSMOUSE_BAD_DATA;
1d9f2626 867 }
1da177e4 868
b46615fe
SF
869 /* Bytes 2 - pktsize should have 0 in the highest bit */
870 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
1d9f2626 871 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
b5d21704
DT
872 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
873 psmouse->pktcnt - 1,
874 psmouse->packet[psmouse->pktcnt - 1]);
1da177e4 875 return PSMOUSE_BAD_DATA;
1d9f2626 876 }
1da177e4 877
b46615fe 878 if (psmouse->pktcnt == psmouse->pktsize) {
7d12e780 879 alps_process_packet(psmouse);
1da177e4
LT
880 return PSMOUSE_FULL_PACKET;
881 }
882
883 return PSMOUSE_GOOD_DATA;
884}
885
25bded7c
SF
886static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
887{
888 struct ps2dev *ps2dev = &psmouse->ps2dev;
889 struct alps_data *priv = psmouse->private;
890 int command;
891 unsigned char *param;
892 unsigned char dummy[4];
893
894 BUG_ON(nibble > 0xf);
895
896 command = priv->nibble_commands[nibble].command;
897 param = (command & 0x0f00) ?
898 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
899
900 if (ps2_command(ps2dev, param, command))
901 return -1;
902
903 return 0;
904}
905
906static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
907{
908 struct ps2dev *ps2dev = &psmouse->ps2dev;
909 struct alps_data *priv = psmouse->private;
910 int i, nibble;
911
912 if (ps2_command(ps2dev, NULL, priv->addr_command))
913 return -1;
914
915 for (i = 12; i >= 0; i -= 4) {
916 nibble = (addr >> i) & 0xf;
917 if (alps_command_mode_send_nibble(psmouse, nibble))
918 return -1;
919 }
920
921 return 0;
922}
923
924static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
925{
926 struct ps2dev *ps2dev = &psmouse->ps2dev;
927 unsigned char param[4];
928
929 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
930 return -1;
931
932 /*
933 * The address being read is returned in the first two bytes
934 * of the result. Check that this address matches the expected
935 * address.
936 */
937 if (addr != ((param[0] << 8) | param[1]))
938 return -1;
939
940 return param[2];
941}
942
943static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
944{
945 if (alps_command_mode_set_addr(psmouse, addr))
946 return -1;
947 return __alps_command_mode_read_reg(psmouse, addr);
948}
949
950static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
951{
952 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
953 return -1;
954 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
955 return -1;
956 return 0;
957}
958
959static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
960 u8 value)
961{
962 if (alps_command_mode_set_addr(psmouse, addr))
963 return -1;
964 return __alps_command_mode_write_reg(psmouse, value);
965}
966
967static int alps_enter_command_mode(struct psmouse *psmouse,
968 unsigned char *resp)
969{
970 unsigned char param[4];
971 struct ps2dev *ps2dev = &psmouse->ps2dev;
972
973 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
974 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
975 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
976 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
977 psmouse_err(psmouse, "failed to enter command mode\n");
978 return -1;
979 }
980
981 if (param[0] != 0x88 && param[1] != 0x07) {
982 psmouse_dbg(psmouse,
983 "unknown response while entering command mode: %2.2x %2.2x %2.2x\n",
984 param[0], param[1], param[2]);
985 return -1;
986 }
987
988 if (resp)
989 *resp = param[2];
990 return 0;
991}
992
993static inline int alps_exit_command_mode(struct psmouse *psmouse)
994{
995 struct ps2dev *ps2dev = &psmouse->ps2dev;
996 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
997 return -1;
998 return 0;
999}
1000
e38de678 1001static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
1da177e4
LT
1002{
1003 struct ps2dev *ps2dev = &psmouse->ps2dev;
e38de678 1004 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
1da177e4 1005 unsigned char param[4];
25bded7c 1006 const struct alps_model_info *model = NULL;
1da177e4
LT
1007 int i;
1008
1009 /*
1010 * First try "E6 report".
99c90ab3
AI
1011 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
1012 * The bits 0-2 of the first byte will be 1s if some buttons are
1013 * pressed.
1da177e4
LT
1014 */
1015 param[0] = 0;
1016 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
1017 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1018 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1019 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
1020 return NULL;
1021
1022 param[0] = param[1] = param[2] = 0xff;
1023 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1024 return NULL;
1025
b5d21704
DT
1026 psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x",
1027 param[0], param[1], param[2]);
1da177e4 1028
99c90ab3
AI
1029 if ((param[0] & 0xf8) != 0 || param[1] != 0 ||
1030 (param[2] != 10 && param[2] != 100))
1da177e4
LT
1031 return NULL;
1032
1033 /*
1034 * Now try "E7 report". Allowed responses are in
1035 * alps_model_data[].signature
1036 */
1037 param[0] = 0;
1038 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
1039 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1040 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1041 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
1042 return NULL;
1043
1044 param[0] = param[1] = param[2] = 0xff;
1045 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1046 return NULL;
1047
b5d21704
DT
1048 psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x",
1049 param[0], param[1], param[2]);
1da177e4 1050
1e0c5b12
DT
1051 if (version) {
1052 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
1053 /* empty */;
1054 *version = (param[0] << 8) | (param[1] << 4) | i;
1055 }
1da177e4 1056
25bded7c 1057 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1e0c5b12 1058 if (!memcmp(param, alps_model_data[i].signature,
25bded7c
SF
1059 sizeof(alps_model_data[i].signature))) {
1060 model = alps_model_data + i;
1061 break;
1062 }
1063 }
1da177e4 1064
25bded7c
SF
1065 if (model && model->proto_version > ALPS_PROTO_V2) {
1066 /*
1067 * Need to check command mode response to identify
1068 * model
1069 */
1070 model = NULL;
1071 if (alps_enter_command_mode(psmouse, param)) {
1072 psmouse_warn(psmouse,
1073 "touchpad failed to enter command mode\n");
1074 } else {
1075 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1076 if (alps_model_data[i].proto_version > ALPS_PROTO_V2 &&
1077 alps_model_data[i].command_mode_resp == param[0]) {
1078 model = alps_model_data + i;
1079 break;
1080 }
1081 }
1082 alps_exit_command_mode(psmouse);
1083
1084 if (!model)
1085 psmouse_dbg(psmouse,
1086 "Unknown command mode response %2.2x\n",
1087 param[0]);
1088 }
1089 }
1090
1091 return model;
1da177e4
LT
1092}
1093
1094/*
1095 * For DualPoint devices select the device that should respond to
1096 * subsequent commands. It looks like glidepad is behind stickpointer,
1097 * I'd thought it would be other way around...
1098 */
25bded7c 1099static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
1da177e4
LT
1100{
1101 struct ps2dev *ps2dev = &psmouse->ps2dev;
1da177e4
LT
1102 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
1103
1104 if (ps2_command(ps2dev, NULL, cmd) ||
1105 ps2_command(ps2dev, NULL, cmd) ||
1106 ps2_command(ps2dev, NULL, cmd) ||
1107 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1108 return -1;
1109
1110 /* we may get 3 more bytes, just ignore them */
c611763d 1111 ps2_drain(ps2dev, 3, 100);
1da177e4
LT
1112
1113 return 0;
1114}
1115
25bded7c 1116static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
1da177e4
LT
1117{
1118 struct ps2dev *ps2dev = &psmouse->ps2dev;
1119
1120 /* Try ALPS magic knock - 4 disable before enable */
1121 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1122 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1123 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1124 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1125 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
1126 return -1;
1127
1128 /*
1129 * Switch mouse to poll (remote) mode so motion data will not
1130 * get in our way
1131 */
1132 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
1133}
1134
1135static int alps_get_status(struct psmouse *psmouse, char *param)
1136{
1137 struct ps2dev *ps2dev = &psmouse->ps2dev;
1138
1139 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
1140 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1141 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1142 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1143 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1144 return -1;
1145
b5d21704
DT
1146 psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x",
1147 param[0], param[1], param[2]);
1da177e4
LT
1148
1149 return 0;
1150}
1151
1152/*
1153 * Turn touchpad tapping on or off. The sequences are:
1154 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1155 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1156 * My guess that 0xE9 (GetInfo) is here as a sync point.
1157 * For models that also have stickpointer (DualPoints) its tapping
1158 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1159 * we don't fiddle with it.
1160 */
1161static int alps_tap_mode(struct psmouse *psmouse, int enable)
1162{
1163 struct ps2dev *ps2dev = &psmouse->ps2dev;
1164 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
1165 unsigned char tap_arg = enable ? 0x0A : 0x00;
1166 unsigned char param[4];
1167
1168 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
1169 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1170 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1171 ps2_command(ps2dev, &tap_arg, cmd))
1172 return -1;
1173
1174 if (alps_get_status(psmouse, param))
1175 return -1;
1176
1177 return 0;
1178}
1179
f0d5c6f4
DT
1180/*
1181 * alps_poll() - poll the touchpad for current motion packet.
1182 * Used in resync.
1183 */
1184static int alps_poll(struct psmouse *psmouse)
1185{
1186 struct alps_data *priv = psmouse->private;
b46615fe 1187 unsigned char buf[sizeof(psmouse->packet)];
b7802c5c 1188 bool poll_failed;
f0d5c6f4 1189
99df65e7 1190 if (priv->flags & ALPS_PASS)
25bded7c 1191 alps_passthrough_mode_v2(psmouse, true);
f0d5c6f4
DT
1192
1193 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1194 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1195
99df65e7 1196 if (priv->flags & ALPS_PASS)
25bded7c 1197 alps_passthrough_mode_v2(psmouse, false);
f0d5c6f4 1198
99df65e7 1199 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
f0d5c6f4
DT
1200 return -1;
1201
1202 if ((psmouse->badbyte & 0xc8) == 0x08) {
1203/*
1204 * Poll the track stick ...
1205 */
1206 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
1207 return -1;
1208 }
1209
1210 memcpy(psmouse->packet, buf, sizeof(buf));
1211 return 0;
1212}
1213
25bded7c 1214static int alps_hw_init_v1_v2(struct psmouse *psmouse)
1da177e4
LT
1215{
1216 struct alps_data *priv = psmouse->private;
f3a5c73d 1217
99df65e7 1218 if ((priv->flags & ALPS_PASS) &&
25bded7c 1219 alps_passthrough_mode_v2(psmouse, true)) {
1da177e4 1220 return -1;
b7802c5c 1221 }
1da177e4 1222
b7802c5c 1223 if (alps_tap_mode(psmouse, true)) {
b5d21704 1224 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
1da177e4 1225 return -1;
963f626d 1226 }
1da177e4 1227
25bded7c 1228 if (alps_absolute_mode_v1_v2(psmouse)) {
b5d21704 1229 psmouse_err(psmouse, "Failed to enable absolute mode\n");
1da177e4
LT
1230 return -1;
1231 }
1232
99df65e7 1233 if ((priv->flags & ALPS_PASS) &&
25bded7c 1234 alps_passthrough_mode_v2(psmouse, false)) {
1da177e4 1235 return -1;
b7802c5c 1236 }
1da177e4 1237
1e0c5b12
DT
1238 /* ALPS needs stream mode, otherwise it won't report any data */
1239 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
b5d21704 1240 psmouse_err(psmouse, "Failed to enable stream mode\n");
1e0c5b12
DT
1241 return -1;
1242 }
1243
1244 return 0;
1245}
1246
25bded7c
SF
1247/*
1248 * Enable or disable passthrough mode to the trackstick. Must be in
1249 * command mode when calling this function.
1250 */
1251static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable)
1252{
1253 int reg_val;
1254
1255 reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
1256 if (reg_val == -1)
1257 return -1;
1258
1259 if (enable)
1260 reg_val |= 0x01;
1261 else
1262 reg_val &= ~0x01;
1263
1264 if (__alps_command_mode_write_reg(psmouse, reg_val))
1265 return -1;
1266
1267 return 0;
1268}
1269
1270/* Must be in command mode when calling this function */
1271static int alps_absolute_mode_v3(struct psmouse *psmouse)
1272{
1273 int reg_val;
1274
1275 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1276 if (reg_val == -1)
1277 return -1;
1278
1279 reg_val |= 0x06;
1280 if (__alps_command_mode_write_reg(psmouse, reg_val))
1281 return -1;
1282
1283 return 0;
1284}
1285
1286static int alps_hw_init_v3(struct psmouse *psmouse)
1287{
1288 struct alps_data *priv = psmouse->private;
1289 struct ps2dev *ps2dev = &psmouse->ps2dev;
1290 int reg_val;
1291 unsigned char param[4];
1292
1293 priv->nibble_commands = alps_v3_nibble_commands;
1294 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
1295
1296 if (alps_enter_command_mode(psmouse, NULL))
1297 goto error;
1298
1299 /* Check for trackstick */
1300 reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
1301 if (reg_val == -1)
1302 goto error;
1303 if (reg_val & 0x80) {
1304 if (alps_passthrough_mode_v3(psmouse, true))
1305 goto error;
1306 if (alps_exit_command_mode(psmouse))
1307 goto error;
1308
1309 /*
1310 * E7 report for the trackstick
1311 *
1312 * There have been reports of failures to seem to trace back
1313 * to the above trackstick check failing. When these occur
1314 * this E7 report fails, so when that happens we continue
1315 * with the assumption that there isn't a trackstick after
1316 * all.
1317 */
1318 param[0] = 0x64;
1319 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1320 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1321 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1322 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
1323 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1324 } else {
1325 psmouse_dbg(psmouse,
1326 "trackstick E7 report: %2.2x %2.2x %2.2x\n",
1327 param[0], param[1], param[2]);
1328
1329 /*
1330 * Not sure what this does, but it is absolutely
1331 * essential. Without it, the touchpad does not
1332 * work at all and the trackstick just emits normal
1333 * PS/2 packets.
1334 */
1335 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1336 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1337 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1338 alps_command_mode_send_nibble(psmouse, 0x9) ||
1339 alps_command_mode_send_nibble(psmouse, 0x4)) {
1340 psmouse_err(psmouse,
1341 "Error sending magic E6 sequence\n");
1342 goto error_passthrough;
1343 }
1344 }
1345
1346 if (alps_enter_command_mode(psmouse, NULL))
1347 goto error_passthrough;
1348 if (alps_passthrough_mode_v3(psmouse, false))
1349 goto error;
1350 }
1351
1352 if (alps_absolute_mode_v3(psmouse)) {
1353 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1354 goto error;
1355 }
1356
1357 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1358 if (reg_val == -1)
1359 goto error;
1360 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1361 goto error;
1362
1363 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1364 if (reg_val == -1)
1365 goto error;
1366 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1367 goto error;
1368
1369 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1370 goto error;
1371 if (__alps_command_mode_write_reg(psmouse, 0x04))
1372 goto error;
1373
1374 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1375 goto error;
1376 if (__alps_command_mode_write_reg(psmouse, 0x03))
1377 goto error;
1378
1379 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1380 goto error;
1381 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1382 goto error;
1383
1384 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1385 goto error;
1386 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1387 goto error;
1388
1389 /*
1390 * This ensures the trackstick packets are in the format
1391 * supported by this driver. If bit 1 isn't set the packet
1392 * format is different.
1393 */
1394 if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82))
1395 goto error;
1396
1397 alps_exit_command_mode(psmouse);
1398
1399 /* Set rate and enable data reporting */
1400 param[0] = 0x64;
1401 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1402 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1403 psmouse_err(psmouse, "Failed to enable data reporting\n");
1404 return -1;
1405 }
1406
1407 return 0;
1408
1409error_passthrough:
1410 /* Something failed while in passthrough mode, so try to get out */
1411 if (!alps_enter_command_mode(psmouse, NULL))
1412 alps_passthrough_mode_v3(psmouse, false);
1413error:
1414 /*
1415 * Leaving the touchpad in command mode will essentially render
1416 * it unusable until the machine reboots, so exit it here just
1417 * to be safe
1418 */
1419 alps_exit_command_mode(psmouse);
1420 return -1;
1421}
1422
1423/* Must be in command mode when calling this function */
1424static int alps_absolute_mode_v4(struct psmouse *psmouse)
1425{
1426 int reg_val;
1427
1428 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1429 if (reg_val == -1)
1430 return -1;
1431
1432 reg_val |= 0x02;
1433 if (__alps_command_mode_write_reg(psmouse, reg_val))
1434 return -1;
1435
1436 return 0;
1437}
1438
1439static int alps_hw_init_v4(struct psmouse *psmouse)
1440{
1441 struct alps_data *priv = psmouse->private;
1442 struct ps2dev *ps2dev = &psmouse->ps2dev;
1443 unsigned char param[4];
1444
1445 priv->nibble_commands = alps_v4_nibble_commands;
1446 priv->addr_command = PSMOUSE_CMD_DISABLE;
1447
1448 if (alps_enter_command_mode(psmouse, NULL))
1449 goto error;
1450
1451 if (alps_absolute_mode_v4(psmouse)) {
1452 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1453 goto error;
1454 }
1455
1456 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1457 goto error;
1458
1459 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1460 goto error;
1461
1462 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1463 goto error;
1464
1465 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1466 goto error;
1467
1468 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1469 goto error;
1470
1471 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1472 goto error;
1473
1474 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1475 goto error;
1476
1477 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1478 goto error;
1479
1480 alps_exit_command_mode(psmouse);
1481
1482 /*
1483 * This sequence changes the output from a 9-byte to an
1484 * 8-byte format. All the same data seems to be present,
1485 * just in a more compact format.
1486 */
1487 param[0] = 0xc8;
1488 param[1] = 0x64;
1489 param[2] = 0x50;
1490 if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1491 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1492 ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1493 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1494 return -1;
1495
1496 /* Set rate and enable data reporting */
1497 param[0] = 0x64;
1498 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1499 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1500 psmouse_err(psmouse, "Failed to enable data reporting\n");
1501 return -1;
1502 }
1503
1504 return 0;
1505
1506error:
1507 /*
1508 * Leaving the touchpad in command mode will essentially render
1509 * it unusable until the machine reboots, so exit it here just
1510 * to be safe
1511 */
1512 alps_exit_command_mode(psmouse);
1513 return -1;
1514}
1515
1516static int alps_hw_init(struct psmouse *psmouse)
1517{
1518 struct alps_data *priv = psmouse->private;
25bded7c
SF
1519 int ret = -1;
1520
99df65e7 1521 switch (priv->proto_version) {
25bded7c
SF
1522 case ALPS_PROTO_V1:
1523 case ALPS_PROTO_V2:
1524 ret = alps_hw_init_v1_v2(psmouse);
1525 break;
1526 case ALPS_PROTO_V3:
1527 ret = alps_hw_init_v3(psmouse);
1528 break;
1529 case ALPS_PROTO_V4:
1530 ret = alps_hw_init_v4(psmouse);
1531 break;
1532 }
1533
1534 return ret;
1535}
1536
1e0c5b12
DT
1537static int alps_reconnect(struct psmouse *psmouse)
1538{
71bb21b6
ML
1539 const struct alps_model_info *model;
1540
1e0c5b12
DT
1541 psmouse_reset(psmouse);
1542
71bb21b6
ML
1543 model = alps_get_model(psmouse, NULL);
1544 if (!model)
1e0c5b12
DT
1545 return -1;
1546
71bb21b6 1547 return alps_hw_init(psmouse);
1da177e4
LT
1548}
1549
1550static void alps_disconnect(struct psmouse *psmouse)
1551{
1552 struct alps_data *priv = psmouse->private;
2e5b636b 1553
1da177e4 1554 psmouse_reset(psmouse);
1d9f2626 1555 del_timer_sync(&priv->timer);
2e5b636b 1556 input_unregister_device(priv->dev2);
1da177e4
LT
1557 kfree(priv);
1558}
1559
1560int alps_init(struct psmouse *psmouse)
1561{
1562 struct alps_data *priv;
71bb21b6 1563 const struct alps_model_info *model;
2e5b636b 1564 struct input_dev *dev1 = psmouse->dev, *dev2;
1da177e4
LT
1565 int version;
1566
f42649e8 1567 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
2e5b636b
DT
1568 dev2 = input_allocate_device();
1569 if (!priv || !dev2)
1da177e4 1570 goto init_fail;
2e5b636b
DT
1571
1572 priv->dev2 = dev2;
1d9f2626
SK
1573 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
1574
1e0c5b12 1575 psmouse->private = priv;
1da177e4 1576
25bded7c
SF
1577 psmouse_reset(psmouse);
1578
71bb21b6
ML
1579 model = alps_get_model(psmouse, &version);
1580 if (!model)
1581 goto init_fail;
1582
99df65e7
KC
1583 priv->proto_version = model->proto_version;
1584 priv->byte0 = model->byte0;
1585 priv->mask0 = model->mask0;
1586 priv->flags = model->flags;
71bb21b6
ML
1587
1588 if (alps_hw_init(psmouse))
1da177e4
LT
1589 goto init_fail;
1590
7105d2ea
DT
1591 /*
1592 * Undo part of setup done for us by psmouse core since touchpad
1593 * is not a relative device.
1594 */
1595 __clear_bit(EV_REL, dev1->evbit);
1596 __clear_bit(REL_X, dev1->relbit);
1597 __clear_bit(REL_Y, dev1->relbit);
1598
1599 /*
1600 * Now set up our capabilities.
1601 */
7b19ada2
JS
1602 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
1603 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
1604 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
71bb21b6
ML
1605 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
1606 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
1da177e4 1607
7b19ada2 1608 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
25bded7c 1609
99df65e7 1610 switch (priv->proto_version) {
25bded7c
SF
1611 case ALPS_PROTO_V1:
1612 case ALPS_PROTO_V2:
1613 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1614 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1615 break;
1616 case ALPS_PROTO_V3:
3b7e09fa 1617 case ALPS_PROTO_V4:
01ce661f 1618 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
b4adbbef 1619 input_mt_init_slots(dev1, 2, 0);
01ce661f
SF
1620 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0);
1621 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0);
1622
1623 set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
1624 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
1625 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
3b7e09fa 1626
01ce661f
SF
1627 input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
1628 input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
25bded7c
SF
1629 break;
1630 }
1631
2e5b636b 1632 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
1da177e4 1633
99df65e7 1634 if (priv->flags & ALPS_WHEEL) {
7b19ada2
JS
1635 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
1636 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
1da177e4
LT
1637 }
1638
99df65e7 1639 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
7b19ada2
JS
1640 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
1641 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
1da177e4
LT
1642 }
1643
99df65e7 1644 if (priv->flags & ALPS_FOUR_BUTTONS) {
71bb21b6
ML
1645 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
1646 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
1647 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
1648 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
1649 } else {
1650 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
1651 }
1652
08ffce45 1653 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
2e5b636b 1654 dev2->phys = priv->phys;
99df65e7
KC
1655 dev2->name = (priv->flags & ALPS_DUALPOINT) ?
1656 "DualPoint Stick" : "PS/2 Mouse";
2e5b636b
DT
1657 dev2->id.bustype = BUS_I8042;
1658 dev2->id.vendor = 0x0002;
1659 dev2->id.product = PSMOUSE_ALPS;
1660 dev2->id.version = 0x0000;
1db3a345 1661 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
1da177e4 1662
7b19ada2 1663 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
71bb21b6
ML
1664 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1665 dev2->keybit[BIT_WORD(BTN_LEFT)] =
1666 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
1da177e4 1667
f42649e8
DT
1668 if (input_register_device(priv->dev2))
1669 goto init_fail;
1da177e4
LT
1670
1671 psmouse->protocol_handler = alps_process_byte;
f0d5c6f4 1672 psmouse->poll = alps_poll;
1da177e4
LT
1673 psmouse->disconnect = alps_disconnect;
1674 psmouse->reconnect = alps_reconnect;
99df65e7 1675 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
1da177e4 1676
f0d5c6f4
DT
1677 /* We are having trouble resyncing ALPS touchpads so disable it for now */
1678 psmouse->resync_time = 0;
1679
1da177e4
LT
1680 return 0;
1681
1682init_fail:
f42649e8 1683 psmouse_reset(psmouse);
2e5b636b 1684 input_free_device(dev2);
1da177e4 1685 kfree(priv);
1e0c5b12 1686 psmouse->private = NULL;
1da177e4
LT
1687 return -1;
1688}
1689
b7802c5c 1690int alps_detect(struct psmouse *psmouse, bool set_properties)
1da177e4
LT
1691{
1692 int version;
e38de678 1693 const struct alps_model_info *model;
1da177e4 1694
f42649e8
DT
1695 model = alps_get_model(psmouse, &version);
1696 if (!model)
1da177e4
LT
1697 return -1;
1698
1699 if (set_properties) {
1700 psmouse->vendor = "ALPS";
968ac842
DT
1701 psmouse->name = model->flags & ALPS_DUALPOINT ?
1702 "DualPoint TouchPad" : "GlidePoint";
1da177e4
LT
1703 psmouse->model = version;
1704 }
1705 return 0;
1706}
1707