blob: a0248fd62ef86075dfb6abed7d681a5d6ff1426f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALPS touchpad PS/2 mouse driver
3 *
4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
Peter Osterlund963f6262005-07-11 01:08:04 -05005 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08008 * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/input.h>
20#include <linux/serio.h>
21#include <linux/libps2.h>
22
23#include "psmouse.h"
24#include "alps.h"
25
Seth Forshee25bded72011-11-07 19:53:36 -080026/*
27 * Definitions for ALPS version 3 and 4 command mode protocol
28 */
29#define ALPS_CMD_NIBBLE_10 0x01f2
30
31static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
32 { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
33 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
34 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
35 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
36 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
37 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
38 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
39 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
40 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
41 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
42 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
43 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
44 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
45 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
46 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
47 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
48};
49
50static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
51 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
52 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
53 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
54 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
55 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
56 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
57 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
58 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
59 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
60 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
61 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
62 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
63 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
64 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
65 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
66 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
67};
68
69
Maxim Levitsky71bb21b2009-11-16 22:12:22 -080070#define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
71#define ALPS_PASS 0x04 /* device has a pass-through port */
72
73#define ALPS_WHEEL 0x08 /* hardware wheel present */
74#define ALPS_FW_BK_1 0x10 /* front & back buttons present */
75#define ALPS_FW_BK_2 0x20 /* front & back buttons present */
76#define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -080077#define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
78 6-byte ALPS packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Helge Dellere38de672006-09-10 21:54:39 -040080static const struct alps_model_info alps_model_data[] = {
Seth Forshee25bded72011-11-07 19:53:36 -080081 { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
82 { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
83 { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
84 { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
85 { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
86 { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
87 { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
88 { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
89 { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
90 { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
91 { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
92 { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
93 { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
94 { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
95 { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
96 { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
97 { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
98 { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -080099 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
Seth Forshee25bded72011-11-07 19:53:36 -0800100 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800101 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
Seth Forshee25bded72011-11-07 19:53:36 -0800102 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
103 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
104 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
105 { { 0x73, 0x02, 0x64 }, 0x9b, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
106 { { 0x73, 0x02, 0x64 }, 0x9d, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
107 { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
110/*
111 * XXX - this entry is suspicious. First byte has zero lower nibble,
112 * which is what a normal mouse would report. Also, the value 0x0e
113 * isn't valid per PS/2 spec.
114 */
115
Seth Forsheed4b347b2011-11-07 19:53:15 -0800116/* Packet formats are described in Documentation/input/alps.txt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800118static bool alps_is_valid_first_byte(const struct alps_model_info *model,
119 unsigned char data)
120{
121 return (data & model->mask0) == model->byte0;
122}
123
124static void alps_report_buttons(struct psmouse *psmouse,
125 struct input_dev *dev1, struct input_dev *dev2,
126 int left, int right, int middle)
127{
Martin Buckc91ed052010-03-13 22:23:58 -0800128 struct input_dev *dev;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800129
Martin Buckc91ed052010-03-13 22:23:58 -0800130 /*
131 * If shared button has already been reported on the
132 * other device (dev2) then this event should be also
133 * sent through that device.
134 */
135 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
136 input_report_key(dev, BTN_LEFT, left);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800137
Martin Buckc91ed052010-03-13 22:23:58 -0800138 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
139 input_report_key(dev, BTN_RIGHT, right);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800140
Martin Buckc91ed052010-03-13 22:23:58 -0800141 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
142 input_report_key(dev, BTN_MIDDLE, middle);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800143
Martin Buckc91ed052010-03-13 22:23:58 -0800144 /*
145 * Sync the _other_ device now, we'll do the first
146 * device later once we report the rest of the events.
147 */
148 input_sync(dev2);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800149}
150
Seth Forshee25bded72011-11-07 19:53:36 -0800151static void alps_process_packet_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 struct alps_data *priv = psmouse->private;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800154 const struct alps_model_info *model = priv->i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned char *packet = psmouse->packet;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500156 struct input_dev *dev = psmouse->dev;
157 struct input_dev *dev2 = priv->dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int x, y, z, ges, fin, left, right, middle;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500159 int back = 0, forward = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Seth Forsheefa629ef2011-11-07 19:53:24 -0800161 if (model->proto_version == ALPS_PROTO_V1) {
Yotam Medinid2f40122006-05-29 23:30:36 -0400162 left = packet[2] & 0x10;
163 right = packet[2] & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 middle = 0;
165 x = packet[1] | ((packet[0] & 0x07) << 7);
166 y = packet[4] | ((packet[3] & 0x07) << 7);
167 z = packet[5];
168 } else {
169 left = packet[3] & 1;
170 right = packet[3] & 2;
171 middle = packet[3] & 4;
172 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
173 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
174 z = packet[5];
175 }
176
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800177 if (model->flags & ALPS_FW_BK_1) {
Laszlo Kajan3c00bb92008-03-18 00:39:55 -0400178 back = packet[0] & 0x10;
179 forward = packet[2] & 4;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500180 }
181
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800182 if (model->flags & ALPS_FW_BK_2) {
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500183 back = packet[3] & 4;
184 forward = packet[2] & 4;
185 if ((middle = forward && back))
186 forward = back = 0;
187 }
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 ges = packet[2] & 1;
190 fin = packet[2] & 2;
191
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800192 if ((model->flags & ALPS_DUALPOINT) && z == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
194 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700195
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800196 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 input_sync(dev2);
199 return;
200 }
201
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800202 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 /* Convert hardware tap to a reasonable Z value */
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800205 if (ges && !fin)
206 z = 40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /*
209 * A "tap and drag" operation is reported by the hardware as a transition
210 * from (!fin && ges) to (fin && ges). This should be translated to the
211 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
212 */
213 if (ges && fin && !priv->prev_fin) {
214 input_report_abs(dev, ABS_X, x);
215 input_report_abs(dev, ABS_Y, y);
216 input_report_abs(dev, ABS_PRESSURE, 0);
217 input_report_key(dev, BTN_TOOL_FINGER, 0);
218 input_sync(dev);
219 }
220 priv->prev_fin = fin;
221
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800222 if (z > 30)
223 input_report_key(dev, BTN_TOUCH, 1);
224 if (z < 25)
225 input_report_key(dev, BTN_TOUCH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 if (z > 0) {
228 input_report_abs(dev, ABS_X, x);
229 input_report_abs(dev, ABS_Y, y);
230 }
231
232 input_report_abs(dev, ABS_PRESSURE, z);
233 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
234
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800235 if (model->flags & ALPS_WHEEL)
Vojtech Pavlike6c047b2005-09-04 01:40:43 -0500236 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800238 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500239 input_report_key(dev, BTN_FORWARD, forward);
240 input_report_key(dev, BTN_BACK, back);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800243 if (model->flags & ALPS_FOUR_BUTTONS) {
244 input_report_key(dev, BTN_0, packet[2] & 4);
245 input_report_key(dev, BTN_1, packet[0] & 0x10);
246 input_report_key(dev, BTN_2, packet[3] & 4);
247 input_report_key(dev, BTN_3, packet[0] & 0x20);
248 }
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 input_sync(dev);
251}
252
Seth Forshee25bded72011-11-07 19:53:36 -0800253static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
254{
255 struct alps_data *priv = psmouse->private;
256 unsigned char *packet = psmouse->packet;
257 struct input_dev *dev = priv->dev2;
258 int x, y, z, left, right, middle;
259
260 /* Sanity check packet */
261 if (!(packet[0] & 0x40)) {
262 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
263 return;
264 }
265
266 /*
267 * There's a special packet that seems to indicate the end
268 * of a stream of trackstick data. Filter these out.
269 */
270 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
271 return;
272
273 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
274 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
275 z = (packet[4] & 0x7c) >> 2;
276
277 /*
278 * The x and y values tend to be quite large, and when used
279 * alone the trackstick is difficult to use. Scale them down
280 * to compensate.
281 */
282 x /= 8;
283 y /= 8;
284
285 input_report_rel(dev, REL_X, x);
286 input_report_rel(dev, REL_Y, -y);
287
288 /*
289 * Most ALPS models report the trackstick buttons in the touchpad
290 * packets, but a few report them here. No reliable way has been
291 * found to differentiate between the models upfront, so we enable
292 * the quirk in response to seeing a button press in the trackstick
293 * packet.
294 */
295 left = packet[3] & 0x01;
296 right = packet[3] & 0x02;
297 middle = packet[3] & 0x04;
298
299 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
300 (left || right || middle))
301 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
302
303 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
304 input_report_key(dev, BTN_LEFT, left);
305 input_report_key(dev, BTN_RIGHT, right);
306 input_report_key(dev, BTN_MIDDLE, middle);
307 }
308
309 input_sync(dev);
310 return;
311}
312
313static void alps_process_touchpad_packet_v3(struct psmouse *psmouse)
314{
315 struct alps_data *priv = psmouse->private;
316 unsigned char *packet = psmouse->packet;
317 struct input_dev *dev = psmouse->dev;
318 struct input_dev *dev2 = priv->dev2;
319 int x, y, z;
320 int left, right, middle;
321
322 /*
323 * There's no single feature of touchpad position and bitmap
324 * packets that can be used to distinguish between them. We
325 * rely on the fact that a bitmap packet should always follow
326 * a position packet with bit 6 of packet[4] set.
327 */
328 if (priv->multi_packet) {
329 priv->multi_packet = 0;
330
331 /*
332 * Sometimes a position packet will indicate a multi-packet
333 * sequence, but then what follows is another position
334 * packet. Check for this, and when it happens process the
335 * position packet as usual.
336 */
337 if (packet[0] & 0x40) {
338 /*
339 * Bitmap packets are not yet supported, so for now
340 * just ignore them.
341 */
342 return;
343 }
344 }
345
346 if (!priv->multi_packet && (packet[4] & 0x40))
347 priv->multi_packet = 1;
348 else
349 priv->multi_packet = 0;
350
351 left = packet[3] & 0x01;
352 right = packet[3] & 0x02;
353 middle = packet[3] & 0x04;
354
355 x = ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) |
356 ((packet[0] & 0x30) >> 4);
357 y = ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f);
358 z = packet[5] & 0x7f;
359
360 /*
361 * Sometimes the hardware sends a single packet with z = 0
362 * in the middle of a stream. Real releases generate packets
363 * with x, y, and z all zero, so these seem to be flukes.
364 * Ignore them.
365 */
366 if (x && y && !z)
367 return;
368
369 if (z >= 64)
370 input_report_key(dev, BTN_TOUCH, 1);
371 else
372 input_report_key(dev, BTN_TOUCH, 0);
373
374 if (z > 0) {
375 input_report_abs(dev, ABS_X, x);
376 input_report_abs(dev, ABS_Y, y);
377 }
378 input_report_abs(dev, ABS_PRESSURE, z);
379
380 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
381 input_report_key(dev, BTN_LEFT, left);
382 input_report_key(dev, BTN_RIGHT, right);
383 input_report_key(dev, BTN_MIDDLE, middle);
384
385 input_sync(dev);
386
387 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
388 left = packet[3] & 0x10;
389 right = packet[3] & 0x20;
390 middle = packet[3] & 0x40;
391
392 input_report_key(dev2, BTN_LEFT, left);
393 input_report_key(dev2, BTN_RIGHT, right);
394 input_report_key(dev2, BTN_MIDDLE, middle);
395 input_sync(dev2);
396 }
397}
398
399static void alps_process_packet_v3(struct psmouse *psmouse)
400{
401 unsigned char *packet = psmouse->packet;
402
403 /*
404 * v3 protocol packets come in three types, two representing
405 * touchpad data and one representing trackstick data.
406 * Trackstick packets seem to be distinguished by always
407 * having 0x3f in the last byte. This value has never been
408 * observed in the last byte of either of the other types
409 * of packets.
410 */
411 if (packet[5] == 0x3f) {
412 alps_process_trackstick_packet_v3(psmouse);
413 return;
414 }
415
416 alps_process_touchpad_packet_v3(psmouse);
417}
418
419static void alps_process_packet_v4(struct psmouse *psmouse)
420{
421 unsigned char *packet = psmouse->packet;
422 struct input_dev *dev = psmouse->dev;
423 int x, y, z;
424 int left, right;
425
426 left = packet[4] & 0x01;
427 right = packet[4] & 0x02;
428
429 x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
430 ((packet[0] & 0x30) >> 4);
431 y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
432 z = packet[5] & 0x7f;
433
434 if (z >= 64)
435 input_report_key(dev, BTN_TOUCH, 1);
436 else
437 input_report_key(dev, BTN_TOUCH, 0);
438
439 if (z > 0) {
440 input_report_abs(dev, ABS_X, x);
441 input_report_abs(dev, ABS_Y, y);
442 }
443 input_report_abs(dev, ABS_PRESSURE, z);
444
445 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
446 input_report_key(dev, BTN_LEFT, left);
447 input_report_key(dev, BTN_RIGHT, right);
448
449 input_sync(dev);
450}
451
452static void alps_process_packet(struct psmouse *psmouse)
453{
454 struct alps_data *priv = psmouse->private;
455 const struct alps_model_info *model = priv->i;
456
457 switch (model->proto_version) {
458 case ALPS_PROTO_V1:
459 case ALPS_PROTO_V2:
460 alps_process_packet_v1_v2(psmouse);
461 break;
462 case ALPS_PROTO_V3:
463 alps_process_packet_v3(psmouse);
464 break;
465 case ALPS_PROTO_V4:
466 alps_process_packet_v4(psmouse);
467 break;
468 }
469}
470
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800471static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
472 unsigned char packet[],
473 bool report_buttons)
474{
475 struct alps_data *priv = psmouse->private;
476 struct input_dev *dev2 = priv->dev2;
477
478 if (report_buttons)
479 alps_report_buttons(psmouse, dev2, psmouse->dev,
480 packet[0] & 1, packet[0] & 2, packet[0] & 4);
481
482 input_report_rel(dev2, REL_X,
483 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
484 input_report_rel(dev2, REL_Y,
485 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
486
487 input_sync(dev2);
488}
489
490static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 struct alps_data *priv = psmouse->private;
493
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800494 if (psmouse->pktcnt < 6)
495 return PSMOUSE_GOOD_DATA;
496
497 if (psmouse->pktcnt == 6) {
498 /*
499 * Start a timer to flush the packet if it ends up last
500 * 6-byte packet in the stream. Timer needs to fire
501 * psmouse core times out itself. 20 ms should be enough
502 * to decide if we are getting more data or not.
503 */
504 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
505 return PSMOUSE_GOOD_DATA;
506 }
507
508 del_timer(&priv->timer);
509
510 if (psmouse->packet[6] & 0x80) {
511
512 /*
513 * Highest bit is set - that means we either had
514 * complete ALPS packet and this is start of the
515 * next packet or we got garbage.
516 */
517
518 if (((psmouse->packet[3] |
519 psmouse->packet[4] |
520 psmouse->packet[5]) & 0x80) ||
521 (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700522 psmouse_dbg(psmouse,
523 "refusing packet %x %x %x %x (suspected interleaved ps/2)\n",
524 psmouse->packet[3], psmouse->packet[4],
525 psmouse->packet[5], psmouse->packet[6]);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800526 return PSMOUSE_BAD_DATA;
527 }
528
529 alps_process_packet(psmouse);
530
531 /* Continue with the next packet */
532 psmouse->packet[0] = psmouse->packet[6];
533 psmouse->pktcnt = 1;
534
535 } else {
536
537 /*
538 * High bit is 0 - that means that we indeed got a PS/2
539 * packet in the middle of ALPS packet.
540 *
541 * There is also possibility that we got 6-byte ALPS
542 * packet followed by 3-byte packet from trackpoint. We
543 * can not distinguish between these 2 scenarios but
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700544 * because the latter is unlikely to happen in course of
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800545 * normal operation (user would need to press all
546 * buttons on the pad and start moving trackpoint
547 * without touching the pad surface) we assume former.
548 * Even if we are wrong the wost thing that would happen
549 * the cursor would jump but we should not get protocol
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700550 * de-synchronization.
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800551 */
552
553 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
554 false);
555
556 /*
557 * Continue with the standard ALPS protocol handling,
558 * but make sure we won't process it as an interleaved
559 * packet again, which may happen if all buttons are
560 * pressed. To avoid this let's reset the 4th bit which
561 * is normally 1.
562 */
563 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
564 psmouse->pktcnt = 4;
565 }
566
567 return PSMOUSE_GOOD_DATA;
568}
569
570static void alps_flush_packet(unsigned long data)
571{
572 struct psmouse *psmouse = (struct psmouse *)data;
573
574 serio_pause_rx(psmouse->ps2dev.serio);
575
Seth Forsheeb46615f2011-11-07 19:53:30 -0800576 if (psmouse->pktcnt == psmouse->pktsize) {
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800577
578 /*
579 * We did not any more data in reasonable amount of time.
580 * Validate the last 3 bytes and process as a standard
581 * ALPS packet.
582 */
583 if ((psmouse->packet[3] |
584 psmouse->packet[4] |
585 psmouse->packet[5]) & 0x80) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700586 psmouse_dbg(psmouse,
587 "refusing packet %x %x %x (suspected interleaved ps/2)\n",
588 psmouse->packet[3], psmouse->packet[4],
589 psmouse->packet[5]);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800590 } else {
591 alps_process_packet(psmouse);
592 }
593 psmouse->pktcnt = 0;
594 }
595
596 serio_continue_rx(psmouse->ps2dev.serio);
597}
598
599static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
600{
601 struct alps_data *priv = psmouse->private;
602 const struct alps_model_info *model = priv->i;
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
605 if (psmouse->pktcnt == 3) {
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800606 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
607 true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 return PSMOUSE_FULL_PACKET;
609 }
610 return PSMOUSE_GOOD_DATA;
611 }
612
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800613 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
614
615 if ((model->flags & ALPS_PS2_INTERLEAVED) &&
616 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
617 return alps_handle_interleaved_ps2(psmouse);
618 }
619
620 if (!alps_is_valid_first_byte(model, psmouse->packet[0])) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700621 psmouse_dbg(psmouse,
622 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
623 psmouse->packet[0], model->mask0, model->byte0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return PSMOUSE_BAD_DATA;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Seth Forsheeb46615f2011-11-07 19:53:30 -0800627 /* Bytes 2 - pktsize should have 0 in the highest bit */
628 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800629 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700630 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
631 psmouse->pktcnt - 1,
632 psmouse->packet[psmouse->pktcnt - 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 return PSMOUSE_BAD_DATA;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Seth Forsheeb46615f2011-11-07 19:53:30 -0800636 if (psmouse->pktcnt == psmouse->pktsize) {
David Howells7d12e782006-10-05 14:55:46 +0100637 alps_process_packet(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 return PSMOUSE_FULL_PACKET;
639 }
640
641 return PSMOUSE_GOOD_DATA;
642}
643
Seth Forshee25bded72011-11-07 19:53:36 -0800644static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
645{
646 struct ps2dev *ps2dev = &psmouse->ps2dev;
647 struct alps_data *priv = psmouse->private;
648 int command;
649 unsigned char *param;
650 unsigned char dummy[4];
651
652 BUG_ON(nibble > 0xf);
653
654 command = priv->nibble_commands[nibble].command;
655 param = (command & 0x0f00) ?
656 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
657
658 if (ps2_command(ps2dev, param, command))
659 return -1;
660
661 return 0;
662}
663
664static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
665{
666 struct ps2dev *ps2dev = &psmouse->ps2dev;
667 struct alps_data *priv = psmouse->private;
668 int i, nibble;
669
670 if (ps2_command(ps2dev, NULL, priv->addr_command))
671 return -1;
672
673 for (i = 12; i >= 0; i -= 4) {
674 nibble = (addr >> i) & 0xf;
675 if (alps_command_mode_send_nibble(psmouse, nibble))
676 return -1;
677 }
678
679 return 0;
680}
681
682static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
683{
684 struct ps2dev *ps2dev = &psmouse->ps2dev;
685 unsigned char param[4];
686
687 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
688 return -1;
689
690 /*
691 * The address being read is returned in the first two bytes
692 * of the result. Check that this address matches the expected
693 * address.
694 */
695 if (addr != ((param[0] << 8) | param[1]))
696 return -1;
697
698 return param[2];
699}
700
701static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
702{
703 if (alps_command_mode_set_addr(psmouse, addr))
704 return -1;
705 return __alps_command_mode_read_reg(psmouse, addr);
706}
707
708static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
709{
710 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
711 return -1;
712 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
713 return -1;
714 return 0;
715}
716
717static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
718 u8 value)
719{
720 if (alps_command_mode_set_addr(psmouse, addr))
721 return -1;
722 return __alps_command_mode_write_reg(psmouse, value);
723}
724
725static int alps_enter_command_mode(struct psmouse *psmouse,
726 unsigned char *resp)
727{
728 unsigned char param[4];
729 struct ps2dev *ps2dev = &psmouse->ps2dev;
730
731 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
732 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
733 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
734 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
735 psmouse_err(psmouse, "failed to enter command mode\n");
736 return -1;
737 }
738
739 if (param[0] != 0x88 && param[1] != 0x07) {
740 psmouse_dbg(psmouse,
741 "unknown response while entering command mode: %2.2x %2.2x %2.2x\n",
742 param[0], param[1], param[2]);
743 return -1;
744 }
745
746 if (resp)
747 *resp = param[2];
748 return 0;
749}
750
751static inline int alps_exit_command_mode(struct psmouse *psmouse)
752{
753 struct ps2dev *ps2dev = &psmouse->ps2dev;
754 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
755 return -1;
756 return 0;
757}
758
Helge Dellere38de672006-09-10 21:54:39 -0400759static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760{
761 struct ps2dev *ps2dev = &psmouse->ps2dev;
Helge Dellere38de672006-09-10 21:54:39 -0400762 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 unsigned char param[4];
Seth Forshee25bded72011-11-07 19:53:36 -0800764 const struct alps_model_info *model = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 int i;
766
767 /*
768 * First try "E6 report".
769 * ALPS should return 0,0,10 or 0,0,100
770 */
771 param[0] = 0;
772 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
773 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
774 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
775 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
776 return NULL;
777
778 param[0] = param[1] = param[2] = 0xff;
779 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
780 return NULL;
781
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700782 psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x",
783 param[0], param[1], param[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
786 return NULL;
787
788 /*
789 * Now try "E7 report". Allowed responses are in
790 * alps_model_data[].signature
791 */
792 param[0] = 0;
793 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
794 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
795 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
796 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
797 return NULL;
798
799 param[0] = param[1] = param[2] = 0xff;
800 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
801 return NULL;
802
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700803 psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x",
804 param[0], param[1], param[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400806 if (version) {
807 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
808 /* empty */;
809 *version = (param[0] << 8) | (param[1] << 4) | i;
810 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Seth Forshee25bded72011-11-07 19:53:36 -0800812 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400813 if (!memcmp(param, alps_model_data[i].signature,
Seth Forshee25bded72011-11-07 19:53:36 -0800814 sizeof(alps_model_data[i].signature))) {
815 model = alps_model_data + i;
816 break;
817 }
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Seth Forshee25bded72011-11-07 19:53:36 -0800820 if (model && model->proto_version > ALPS_PROTO_V2) {
821 /*
822 * Need to check command mode response to identify
823 * model
824 */
825 model = NULL;
826 if (alps_enter_command_mode(psmouse, param)) {
827 psmouse_warn(psmouse,
828 "touchpad failed to enter command mode\n");
829 } else {
830 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
831 if (alps_model_data[i].proto_version > ALPS_PROTO_V2 &&
832 alps_model_data[i].command_mode_resp == param[0]) {
833 model = alps_model_data + i;
834 break;
835 }
836 }
837 alps_exit_command_mode(psmouse);
838
839 if (!model)
840 psmouse_dbg(psmouse,
841 "Unknown command mode response %2.2x\n",
842 param[0]);
843 }
844 }
845
846 return model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849/*
850 * For DualPoint devices select the device that should respond to
851 * subsequent commands. It looks like glidepad is behind stickpointer,
852 * I'd thought it would be other way around...
853 */
Seth Forshee25bded72011-11-07 19:53:36 -0800854static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 struct ps2dev *ps2dev = &psmouse->ps2dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
858
859 if (ps2_command(ps2dev, NULL, cmd) ||
860 ps2_command(ps2dev, NULL, cmd) ||
861 ps2_command(ps2dev, NULL, cmd) ||
862 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
863 return -1;
864
865 /* we may get 3 more bytes, just ignore them */
Dmitry Torokhovc6117632005-06-01 02:39:51 -0500866 ps2_drain(ps2dev, 3, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 return 0;
869}
870
Seth Forshee25bded72011-11-07 19:53:36 -0800871static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
873 struct ps2dev *ps2dev = &psmouse->ps2dev;
874
875 /* Try ALPS magic knock - 4 disable before enable */
876 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
877 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
878 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
879 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
880 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
881 return -1;
882
883 /*
884 * Switch mouse to poll (remote) mode so motion data will not
885 * get in our way
886 */
887 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
888}
889
890static int alps_get_status(struct psmouse *psmouse, char *param)
891{
892 struct ps2dev *ps2dev = &psmouse->ps2dev;
893
894 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
895 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
896 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
897 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
898 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
899 return -1;
900
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700901 psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x",
902 param[0], param[1], param[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 return 0;
905}
906
907/*
908 * Turn touchpad tapping on or off. The sequences are:
909 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
910 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
911 * My guess that 0xE9 (GetInfo) is here as a sync point.
912 * For models that also have stickpointer (DualPoints) its tapping
913 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
914 * we don't fiddle with it.
915 */
916static int alps_tap_mode(struct psmouse *psmouse, int enable)
917{
918 struct ps2dev *ps2dev = &psmouse->ps2dev;
919 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
920 unsigned char tap_arg = enable ? 0x0A : 0x00;
921 unsigned char param[4];
922
923 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
924 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
925 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
926 ps2_command(ps2dev, &tap_arg, cmd))
927 return -1;
928
929 if (alps_get_status(psmouse, param))
930 return -1;
931
932 return 0;
933}
934
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500935/*
936 * alps_poll() - poll the touchpad for current motion packet.
937 * Used in resync.
938 */
939static int alps_poll(struct psmouse *psmouse)
940{
941 struct alps_data *priv = psmouse->private;
Seth Forsheeb46615f2011-11-07 19:53:30 -0800942 unsigned char buf[sizeof(psmouse->packet)];
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700943 bool poll_failed;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500944
945 if (priv->i->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -0800946 alps_passthrough_mode_v2(psmouse, true);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500947
948 poll_failed = ps2_command(&psmouse->ps2dev, buf,
949 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
950
951 if (priv->i->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -0800952 alps_passthrough_mode_v2(psmouse, false);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500953
954 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
955 return -1;
956
957 if ((psmouse->badbyte & 0xc8) == 0x08) {
958/*
959 * Poll the track stick ...
960 */
961 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
962 return -1;
963 }
964
965 memcpy(psmouse->packet, buf, sizeof(buf));
966 return 0;
967}
968
Seth Forshee25bded72011-11-07 19:53:36 -0800969static int alps_hw_init_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 struct alps_data *priv = psmouse->private;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800972 const struct alps_model_info *model = priv->i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800974 if ((model->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -0800975 alps_passthrough_mode_v2(psmouse, true)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700979 if (alps_tap_mode(psmouse, true)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700980 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 return -1;
Peter Osterlund963f6262005-07-11 01:08:04 -0500982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Seth Forshee25bded72011-11-07 19:53:36 -0800984 if (alps_absolute_mode_v1_v2(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700985 psmouse_err(psmouse, "Failed to enable absolute mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 return -1;
987 }
988
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800989 if ((model->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -0800990 alps_passthrough_mode_v2(psmouse, false)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400994 /* ALPS needs stream mode, otherwise it won't report any data */
995 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700996 psmouse_err(psmouse, "Failed to enable stream mode\n");
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400997 return -1;
998 }
999
1000 return 0;
1001}
1002
Seth Forshee25bded72011-11-07 19:53:36 -08001003/*
1004 * Enable or disable passthrough mode to the trackstick. Must be in
1005 * command mode when calling this function.
1006 */
1007static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable)
1008{
1009 int reg_val;
1010
1011 reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
1012 if (reg_val == -1)
1013 return -1;
1014
1015 if (enable)
1016 reg_val |= 0x01;
1017 else
1018 reg_val &= ~0x01;
1019
1020 if (__alps_command_mode_write_reg(psmouse, reg_val))
1021 return -1;
1022
1023 return 0;
1024}
1025
1026/* Must be in command mode when calling this function */
1027static int alps_absolute_mode_v3(struct psmouse *psmouse)
1028{
1029 int reg_val;
1030
1031 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1032 if (reg_val == -1)
1033 return -1;
1034
1035 reg_val |= 0x06;
1036 if (__alps_command_mode_write_reg(psmouse, reg_val))
1037 return -1;
1038
1039 return 0;
1040}
1041
1042static int alps_hw_init_v3(struct psmouse *psmouse)
1043{
1044 struct alps_data *priv = psmouse->private;
1045 struct ps2dev *ps2dev = &psmouse->ps2dev;
1046 int reg_val;
1047 unsigned char param[4];
1048
1049 priv->nibble_commands = alps_v3_nibble_commands;
1050 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
1051
1052 if (alps_enter_command_mode(psmouse, NULL))
1053 goto error;
1054
1055 /* Check for trackstick */
1056 reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
1057 if (reg_val == -1)
1058 goto error;
1059 if (reg_val & 0x80) {
1060 if (alps_passthrough_mode_v3(psmouse, true))
1061 goto error;
1062 if (alps_exit_command_mode(psmouse))
1063 goto error;
1064
1065 /*
1066 * E7 report for the trackstick
1067 *
1068 * There have been reports of failures to seem to trace back
1069 * to the above trackstick check failing. When these occur
1070 * this E7 report fails, so when that happens we continue
1071 * with the assumption that there isn't a trackstick after
1072 * all.
1073 */
1074 param[0] = 0x64;
1075 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1076 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1077 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1078 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
1079 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1080 } else {
1081 psmouse_dbg(psmouse,
1082 "trackstick E7 report: %2.2x %2.2x %2.2x\n",
1083 param[0], param[1], param[2]);
1084
1085 /*
1086 * Not sure what this does, but it is absolutely
1087 * essential. Without it, the touchpad does not
1088 * work at all and the trackstick just emits normal
1089 * PS/2 packets.
1090 */
1091 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1092 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1093 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1094 alps_command_mode_send_nibble(psmouse, 0x9) ||
1095 alps_command_mode_send_nibble(psmouse, 0x4)) {
1096 psmouse_err(psmouse,
1097 "Error sending magic E6 sequence\n");
1098 goto error_passthrough;
1099 }
1100 }
1101
1102 if (alps_enter_command_mode(psmouse, NULL))
1103 goto error_passthrough;
1104 if (alps_passthrough_mode_v3(psmouse, false))
1105 goto error;
1106 }
1107
1108 if (alps_absolute_mode_v3(psmouse)) {
1109 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1110 goto error;
1111 }
1112
1113 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1114 if (reg_val == -1)
1115 goto error;
1116 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1117 goto error;
1118
1119 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1120 if (reg_val == -1)
1121 goto error;
1122 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1123 goto error;
1124
1125 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1126 goto error;
1127 if (__alps_command_mode_write_reg(psmouse, 0x04))
1128 goto error;
1129
1130 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1131 goto error;
1132 if (__alps_command_mode_write_reg(psmouse, 0x03))
1133 goto error;
1134
1135 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1136 goto error;
1137 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1138 goto error;
1139
1140 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1141 goto error;
1142 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1143 goto error;
1144
1145 /*
1146 * This ensures the trackstick packets are in the format
1147 * supported by this driver. If bit 1 isn't set the packet
1148 * format is different.
1149 */
1150 if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82))
1151 goto error;
1152
1153 alps_exit_command_mode(psmouse);
1154
1155 /* Set rate and enable data reporting */
1156 param[0] = 0x64;
1157 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1158 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1159 psmouse_err(psmouse, "Failed to enable data reporting\n");
1160 return -1;
1161 }
1162
1163 return 0;
1164
1165error_passthrough:
1166 /* Something failed while in passthrough mode, so try to get out */
1167 if (!alps_enter_command_mode(psmouse, NULL))
1168 alps_passthrough_mode_v3(psmouse, false);
1169error:
1170 /*
1171 * Leaving the touchpad in command mode will essentially render
1172 * it unusable until the machine reboots, so exit it here just
1173 * to be safe
1174 */
1175 alps_exit_command_mode(psmouse);
1176 return -1;
1177}
1178
1179/* Must be in command mode when calling this function */
1180static int alps_absolute_mode_v4(struct psmouse *psmouse)
1181{
1182 int reg_val;
1183
1184 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1185 if (reg_val == -1)
1186 return -1;
1187
1188 reg_val |= 0x02;
1189 if (__alps_command_mode_write_reg(psmouse, reg_val))
1190 return -1;
1191
1192 return 0;
1193}
1194
1195static int alps_hw_init_v4(struct psmouse *psmouse)
1196{
1197 struct alps_data *priv = psmouse->private;
1198 struct ps2dev *ps2dev = &psmouse->ps2dev;
1199 unsigned char param[4];
1200
1201 priv->nibble_commands = alps_v4_nibble_commands;
1202 priv->addr_command = PSMOUSE_CMD_DISABLE;
1203
1204 if (alps_enter_command_mode(psmouse, NULL))
1205 goto error;
1206
1207 if (alps_absolute_mode_v4(psmouse)) {
1208 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1209 goto error;
1210 }
1211
1212 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1213 goto error;
1214
1215 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1216 goto error;
1217
1218 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1219 goto error;
1220
1221 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1222 goto error;
1223
1224 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1225 goto error;
1226
1227 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1228 goto error;
1229
1230 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1231 goto error;
1232
1233 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1234 goto error;
1235
1236 alps_exit_command_mode(psmouse);
1237
1238 /*
1239 * This sequence changes the output from a 9-byte to an
1240 * 8-byte format. All the same data seems to be present,
1241 * just in a more compact format.
1242 */
1243 param[0] = 0xc8;
1244 param[1] = 0x64;
1245 param[2] = 0x50;
1246 if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1247 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1248 ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1249 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1250 return -1;
1251
1252 /* Set rate and enable data reporting */
1253 param[0] = 0x64;
1254 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1255 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1256 psmouse_err(psmouse, "Failed to enable data reporting\n");
1257 return -1;
1258 }
1259
1260 return 0;
1261
1262error:
1263 /*
1264 * Leaving the touchpad in command mode will essentially render
1265 * it unusable until the machine reboots, so exit it here just
1266 * to be safe
1267 */
1268 alps_exit_command_mode(psmouse);
1269 return -1;
1270}
1271
1272static int alps_hw_init(struct psmouse *psmouse)
1273{
1274 struct alps_data *priv = psmouse->private;
1275 const struct alps_model_info *model = priv->i;
1276 int ret = -1;
1277
1278 switch (model->proto_version) {
1279 case ALPS_PROTO_V1:
1280 case ALPS_PROTO_V2:
1281 ret = alps_hw_init_v1_v2(psmouse);
1282 break;
1283 case ALPS_PROTO_V3:
1284 ret = alps_hw_init_v3(psmouse);
1285 break;
1286 case ALPS_PROTO_V4:
1287 ret = alps_hw_init_v4(psmouse);
1288 break;
1289 }
1290
1291 return ret;
1292}
1293
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001294static int alps_reconnect(struct psmouse *psmouse)
1295{
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001296 const struct alps_model_info *model;
1297
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001298 psmouse_reset(psmouse);
1299
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001300 model = alps_get_model(psmouse, NULL);
1301 if (!model)
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001302 return -1;
1303
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001304 return alps_hw_init(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
1307static void alps_disconnect(struct psmouse *psmouse)
1308{
1309 struct alps_data *priv = psmouse->private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001310
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 psmouse_reset(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001312 del_timer_sync(&priv->timer);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001313 input_unregister_device(priv->dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 kfree(priv);
1315}
1316
1317int alps_init(struct psmouse *psmouse)
1318{
1319 struct alps_data *priv;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001320 const struct alps_model_info *model;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001321 struct input_dev *dev1 = psmouse->dev, *dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 int version;
1323
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001324 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001325 dev2 = input_allocate_device();
1326 if (!priv || !dev2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 goto init_fail;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001328
1329 priv->dev2 = dev2;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001330 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
1331
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001332 psmouse->private = priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Seth Forshee25bded72011-11-07 19:53:36 -08001334 psmouse_reset(psmouse);
1335
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001336 model = alps_get_model(psmouse, &version);
1337 if (!model)
1338 goto init_fail;
1339
1340 priv->i = model;
1341
1342 if (alps_hw_init(psmouse))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 goto init_fail;
1344
Dmitry Torokhov7105d2e2009-12-11 23:54:54 -08001345 /*
1346 * Undo part of setup done for us by psmouse core since touchpad
1347 * is not a relative device.
1348 */
1349 __clear_bit(EV_REL, dev1->evbit);
1350 __clear_bit(REL_X, dev1->relbit);
1351 __clear_bit(REL_Y, dev1->relbit);
1352
1353 /*
1354 * Now set up our capabilities.
1355 */
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001356 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
1357 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
1358 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001359 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
1360 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001362 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
Seth Forshee25bded72011-11-07 19:53:36 -08001363
1364 switch (model->proto_version) {
1365 case ALPS_PROTO_V1:
1366 case ALPS_PROTO_V2:
1367 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1368 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1369 break;
1370 case ALPS_PROTO_V3:
1371 case ALPS_PROTO_V4:
1372 input_set_abs_params(dev1, ABS_X, 0, 2000, 0, 0);
1373 input_set_abs_params(dev1, ABS_Y, 0, 1400, 0, 0);
1374 break;
1375 }
1376
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001377 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001379 if (model->flags & ALPS_WHEEL) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001380 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
1381 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 }
1383
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001384 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001385 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
1386 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 }
1388
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001389 if (model->flags & ALPS_FOUR_BUTTONS) {
1390 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
1391 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
1392 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
1393 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
1394 } else {
1395 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
1396 }
1397
Dmitry Torokhov08ffce42006-06-26 01:45:10 -04001398 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001399 dev2->phys = priv->phys;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001400 dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001401 dev2->id.bustype = BUS_I8042;
1402 dev2->id.vendor = 0x0002;
1403 dev2->id.product = PSMOUSE_ALPS;
1404 dev2->id.version = 0x0000;
Dmitry Torokhov1db3a342008-03-18 00:29:18 -04001405 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
Dmitry Torokhov968ac842005-05-29 02:28:29 -05001406
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001407 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001408 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1409 dev2->keybit[BIT_WORD(BTN_LEFT)] =
1410 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001412 if (input_register_device(priv->dev2))
1413 goto init_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 psmouse->protocol_handler = alps_process_byte;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001416 psmouse->poll = alps_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 psmouse->disconnect = alps_disconnect;
1418 psmouse->reconnect = alps_reconnect;
Seth Forshee25bded72011-11-07 19:53:36 -08001419 psmouse->pktsize = model->proto_version == ALPS_PROTO_V4 ? 8 : 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001421 /* We are having trouble resyncing ALPS touchpads so disable it for now */
1422 psmouse->resync_time = 0;
1423
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 return 0;
1425
1426init_fail:
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001427 psmouse_reset(psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001428 input_free_device(dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 kfree(priv);
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001430 psmouse->private = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 return -1;
1432}
1433
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001434int alps_detect(struct psmouse *psmouse, bool set_properties)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
1436 int version;
Helge Dellere38de672006-09-10 21:54:39 -04001437 const struct alps_model_info *model;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001439 model = alps_get_model(psmouse, &version);
1440 if (!model)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 return -1;
1442
1443 if (set_properties) {
1444 psmouse->vendor = "ALPS";
Dmitry Torokhov968ac842005-05-29 02:28:29 -05001445 psmouse->name = model->flags & ALPS_DUALPOINT ?
1446 "DualPoint TouchPad" : "GlidePoint";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 psmouse->model = version;
1448 }
1449 return 0;
1450}
1451