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