blob: a810ff8d2c005d73d347bb39f8e1c891a81d74d4 [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>
8 *
9 * ALPS detection, tap switching and status querying info is taken from
10 * tpconfig utility (by C. Scott Ananian and Bruce Kall).
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published by
14 * the Free Software Foundation.
15 */
16
17#include <linux/input.h>
18#include <linux/serio.h>
19#include <linux/libps2.h>
20
21#include "psmouse.h"
22#include "alps.h"
23
24#undef DEBUG
25#ifdef DEBUG
26#define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg)
27#else
28#define dbg(format, arg...) do {} while (0)
29#endif
30
31#define ALPS_DUALPOINT 0x01
32#define ALPS_WHEEL 0x02
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -050033#define ALPS_FW_BK_1 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define ALPS_4BTN 0x08
35#define ALPS_OLDPROTO 0x10
36#define ALPS_PASS 0x20
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -050037#define ALPS_FW_BK_2 0x40
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Helge Dellere38de672006-09-10 21:54:39 -040039static const struct alps_model_info alps_model_data[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
41 { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
42 { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
Larry Fingerf5e9c9c2005-12-21 00:51:13 -050043 { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
45 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
Vojtech Pavlikea54c962005-12-14 21:47:00 -050046 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -050048 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
50 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS }, /* Dell Latitude D800 */
51 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -050052 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
54 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
55 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
William Petterssondac4ae02007-09-05 00:18:44 -040056 { { 0x73, 0x02, 0x50 }, 0xcf, 0xff, ALPS_FW_BK_1 } /* Dell Vostro 1400 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
59/*
60 * XXX - this entry is suspicious. First byte has zero lower nibble,
61 * which is what a normal mouse would report. Also, the value 0x0e
62 * isn't valid per PS/2 spec.
63 */
64
65/*
66 * ALPS abolute Mode - new format
Dmitry Torokhov968ac842005-05-29 02:28:29 -050067 *
68 * byte 0: 1 ? ? ? 1 ? ? ?
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
70 * byte 2: 0 x10 x9 x8 x7 ? fin ges
Dmitry Torokhov968ac842005-05-29 02:28:29 -050071 * byte 3: 0 y9 y8 y7 1 M R L
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
73 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
74 *
75 * ?'s can have different meanings on different models,
76 * such as wheel rotation, extra buttons, stick buttons
77 * on a dualpoint, etc.
78 */
79
David Howells7d12e782006-10-05 14:55:46 +010080static void alps_process_packet(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 struct alps_data *priv = psmouse->private;
83 unsigned char *packet = psmouse->packet;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050084 struct input_dev *dev = psmouse->dev;
85 struct input_dev *dev2 = priv->dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int x, y, z, ges, fin, left, right, middle;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -050087 int back = 0, forward = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */
Dmitry Torokhov968ac842005-05-29 02:28:29 -050090 input_report_key(dev2, BTN_LEFT, packet[0] & 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 input_report_key(dev2, BTN_RIGHT, packet[0] & 2);
92 input_report_key(dev2, BTN_MIDDLE, packet[0] & 4);
93 input_report_rel(dev2, REL_X,
94 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
95 input_report_rel(dev2, REL_Y,
96 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
97 input_sync(dev2);
98 return;
99 }
100
101 if (priv->i->flags & ALPS_OLDPROTO) {
Yotam Medinid2f40122006-05-29 23:30:36 -0400102 left = packet[2] & 0x10;
103 right = packet[2] & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 middle = 0;
105 x = packet[1] | ((packet[0] & 0x07) << 7);
106 y = packet[4] | ((packet[3] & 0x07) << 7);
107 z = packet[5];
108 } else {
109 left = packet[3] & 1;
110 right = packet[3] & 2;
111 middle = packet[3] & 4;
112 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
113 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
114 z = packet[5];
115 }
116
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500117 if (priv->i->flags & ALPS_FW_BK_1) {
118 back = packet[2] & 4;
119 forward = packet[0] & 0x10;
120 }
121
122 if (priv->i->flags & ALPS_FW_BK_2) {
123 back = packet[3] & 4;
124 forward = packet[2] & 4;
125 if ((middle = forward && back))
126 forward = back = 0;
127 }
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 ges = packet[2] & 1;
130 fin = packet[2] & 2;
131
132 input_report_key(dev, BTN_LEFT, left);
133 input_report_key(dev, BTN_RIGHT, right);
134 input_report_key(dev, BTN_MIDDLE, middle);
135
136 if ((priv->i->flags & ALPS_DUALPOINT) && z == 127) {
137 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
138 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
139 input_sync(dev);
140 input_sync(dev2);
141 return;
142 }
143
144 /* Convert hardware tap to a reasonable Z value */
145 if (ges && !fin) z = 40;
146
147 /*
148 * A "tap and drag" operation is reported by the hardware as a transition
149 * from (!fin && ges) to (fin && ges). This should be translated to the
150 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
151 */
152 if (ges && fin && !priv->prev_fin) {
153 input_report_abs(dev, ABS_X, x);
154 input_report_abs(dev, ABS_Y, y);
155 input_report_abs(dev, ABS_PRESSURE, 0);
156 input_report_key(dev, BTN_TOOL_FINGER, 0);
157 input_sync(dev);
158 }
159 priv->prev_fin = fin;
160
161 if (z > 30) input_report_key(dev, BTN_TOUCH, 1);
162 if (z < 25) input_report_key(dev, BTN_TOUCH, 0);
163
164 if (z > 0) {
165 input_report_abs(dev, ABS_X, x);
166 input_report_abs(dev, ABS_Y, y);
167 }
168
169 input_report_abs(dev, ABS_PRESSURE, z);
170 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 if (priv->i->flags & ALPS_WHEEL)
Vojtech Pavlike6c047b2005-09-04 01:40:43 -0500173 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500175 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
176 input_report_key(dev, BTN_FORWARD, forward);
177 input_report_key(dev, BTN_BACK, back);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179
180 input_sync(dev);
181}
182
David Howells7d12e782006-10-05 14:55:46 +0100183static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 struct alps_data *priv = psmouse->private;
186
187 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
188 if (psmouse->pktcnt == 3) {
David Howells7d12e782006-10-05 14:55:46 +0100189 alps_process_packet(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 return PSMOUSE_FULL_PACKET;
191 }
192 return PSMOUSE_GOOD_DATA;
193 }
194
195 if ((psmouse->packet[0] & priv->i->mask0) != priv->i->byte0)
196 return PSMOUSE_BAD_DATA;
197
198 /* Bytes 2 - 6 should have 0 in the highest bit */
199 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
200 (psmouse->packet[psmouse->pktcnt - 1] & 0x80))
201 return PSMOUSE_BAD_DATA;
202
203 if (psmouse->pktcnt == 6) {
David Howells7d12e782006-10-05 14:55:46 +0100204 alps_process_packet(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return PSMOUSE_FULL_PACKET;
206 }
207
208 return PSMOUSE_GOOD_DATA;
209}
210
Helge Dellere38de672006-09-10 21:54:39 -0400211static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 struct ps2dev *ps2dev = &psmouse->ps2dev;
Helge Dellere38de672006-09-10 21:54:39 -0400214 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 unsigned char param[4];
216 int i;
217
218 /*
219 * First try "E6 report".
220 * ALPS should return 0,0,10 or 0,0,100
221 */
222 param[0] = 0;
223 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
224 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
225 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
226 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
227 return NULL;
228
229 param[0] = param[1] = param[2] = 0xff;
230 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
231 return NULL;
232
233 dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
234
235 if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
236 return NULL;
237
238 /*
239 * Now try "E7 report". Allowed responses are in
240 * alps_model_data[].signature
241 */
242 param[0] = 0;
243 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
244 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
245 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
246 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
247 return NULL;
248
249 param[0] = param[1] = param[2] = 0xff;
250 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
251 return NULL;
252
253 dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
254
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400255 if (version) {
256 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
257 /* empty */;
258 *version = (param[0] << 8) | (param[1] << 4) | i;
259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400262 if (!memcmp(param, alps_model_data[i].signature,
263 sizeof(alps_model_data[i].signature)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return alps_model_data + i;
265
266 return NULL;
267}
268
269/*
270 * For DualPoint devices select the device that should respond to
271 * subsequent commands. It looks like glidepad is behind stickpointer,
272 * I'd thought it would be other way around...
273 */
274static int alps_passthrough_mode(struct psmouse *psmouse, int enable)
275{
276 struct ps2dev *ps2dev = &psmouse->ps2dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
278
279 if (ps2_command(ps2dev, NULL, cmd) ||
280 ps2_command(ps2dev, NULL, cmd) ||
281 ps2_command(ps2dev, NULL, cmd) ||
282 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
283 return -1;
284
285 /* we may get 3 more bytes, just ignore them */
Dmitry Torokhovc6117632005-06-01 02:39:51 -0500286 ps2_drain(ps2dev, 3, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 return 0;
289}
290
291static int alps_absolute_mode(struct psmouse *psmouse)
292{
293 struct ps2dev *ps2dev = &psmouse->ps2dev;
294
295 /* Try ALPS magic knock - 4 disable before enable */
296 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
297 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
298 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
299 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
300 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
301 return -1;
302
303 /*
304 * Switch mouse to poll (remote) mode so motion data will not
305 * get in our way
306 */
307 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
308}
309
310static int alps_get_status(struct psmouse *psmouse, char *param)
311{
312 struct ps2dev *ps2dev = &psmouse->ps2dev;
313
314 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
315 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
316 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
317 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
318 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
319 return -1;
320
321 dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
322
323 return 0;
324}
325
326/*
327 * Turn touchpad tapping on or off. The sequences are:
328 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
329 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
330 * My guess that 0xE9 (GetInfo) is here as a sync point.
331 * For models that also have stickpointer (DualPoints) its tapping
332 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
333 * we don't fiddle with it.
334 */
335static int alps_tap_mode(struct psmouse *psmouse, int enable)
336{
337 struct ps2dev *ps2dev = &psmouse->ps2dev;
338 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
339 unsigned char tap_arg = enable ? 0x0A : 0x00;
340 unsigned char param[4];
341
342 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
343 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
344 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
345 ps2_command(ps2dev, &tap_arg, cmd))
346 return -1;
347
348 if (alps_get_status(psmouse, param))
349 return -1;
350
351 return 0;
352}
353
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500354/*
355 * alps_poll() - poll the touchpad for current motion packet.
356 * Used in resync.
357 */
358static int alps_poll(struct psmouse *psmouse)
359{
360 struct alps_data *priv = psmouse->private;
361 unsigned char buf[6];
362 int poll_failed;
363
364 if (priv->i->flags & ALPS_PASS)
365 alps_passthrough_mode(psmouse, 1);
366
367 poll_failed = ps2_command(&psmouse->ps2dev, buf,
368 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
369
370 if (priv->i->flags & ALPS_PASS)
371 alps_passthrough_mode(psmouse, 0);
372
373 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
374 return -1;
375
376 if ((psmouse->badbyte & 0xc8) == 0x08) {
377/*
378 * Poll the track stick ...
379 */
380 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
381 return -1;
382 }
383
384 memcpy(psmouse->packet, buf, sizeof(buf));
385 return 0;
386}
387
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400388static int alps_hw_init(struct psmouse *psmouse, int *version)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 struct alps_data *priv = psmouse->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400392 priv->i = alps_get_model(psmouse, version);
393 if (!priv->i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return -1;
395
David Mooreb30dc1202005-07-11 01:07:48 -0500396 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return -1;
398
Peter Osterlund963f6262005-07-11 01:08:04 -0500399 if (alps_tap_mode(psmouse, 1)) {
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400400 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return -1;
Peter Osterlund963f6262005-07-11 01:08:04 -0500402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 if (alps_absolute_mode(psmouse)) {
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400405 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return -1;
407 }
408
David Mooreb30dc1202005-07-11 01:07:48 -0500409 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return -1;
411
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400412 /* ALPS needs stream mode, otherwise it won't report any data */
413 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
414 printk(KERN_ERR "alps.c: Failed to enable stream mode\n");
415 return -1;
416 }
417
418 return 0;
419}
420
421static int alps_reconnect(struct psmouse *psmouse)
422{
423 psmouse_reset(psmouse);
424
425 if (alps_hw_init(psmouse, NULL))
426 return -1;
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return 0;
429}
430
431static void alps_disconnect(struct psmouse *psmouse)
432{
433 struct alps_data *priv = psmouse->private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 psmouse_reset(psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500436 input_unregister_device(priv->dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 kfree(priv);
438}
439
440int alps_init(struct psmouse *psmouse)
441{
442 struct alps_data *priv;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500443 struct input_dev *dev1 = psmouse->dev, *dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 int version;
445
Dmitry Torokhovf42649e2007-04-12 01:31:13 -0400446 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500447 dev2 = input_allocate_device();
448 if (!priv || !dev2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 goto init_fail;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500450
451 priv->dev2 = dev2;
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400452 psmouse->private = priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400454 if (alps_hw_init(psmouse, &version))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 goto init_fail;
456
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500457 dev1->evbit[LONG(EV_KEY)] |= BIT(EV_KEY);
458 dev1->keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
459 dev1->keybit[LONG(BTN_TOOL_FINGER)] |= BIT(BTN_TOOL_FINGER);
460 dev1->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500462 dev1->evbit[LONG(EV_ABS)] |= BIT(EV_ABS);
463 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
464 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
465 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 if (priv->i->flags & ALPS_WHEEL) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500468 dev1->evbit[LONG(EV_REL)] |= BIT(EV_REL);
469 dev1->relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 }
471
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500472 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500473 dev1->keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD);
474 dev1->keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
476
Dmitry Torokhov08ffce42006-06-26 01:45:10 -0400477 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500478 dev2->phys = priv->phys;
479 dev2->name = (priv->i->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
480 dev2->id.bustype = BUS_I8042;
481 dev2->id.vendor = 0x0002;
482 dev2->id.product = PSMOUSE_ALPS;
483 dev2->id.version = 0x0000;
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500484
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500485 dev2->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
486 dev2->relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
487 dev2->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Dmitry Torokhovf42649e2007-04-12 01:31:13 -0400489 if (input_register_device(priv->dev2))
490 goto init_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 psmouse->protocol_handler = alps_process_byte;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500493 psmouse->poll = alps_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 psmouse->disconnect = alps_disconnect;
495 psmouse->reconnect = alps_reconnect;
496 psmouse->pktsize = 6;
497
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -0500498 /* We are having trouble resyncing ALPS touchpads so disable it for now */
499 psmouse->resync_time = 0;
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return 0;
502
503init_fail:
Dmitry Torokhovf42649e2007-04-12 01:31:13 -0400504 psmouse_reset(psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500505 input_free_device(dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 kfree(priv);
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -0400507 psmouse->private = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return -1;
509}
510
511int alps_detect(struct psmouse *psmouse, int set_properties)
512{
513 int version;
Helge Dellere38de672006-09-10 21:54:39 -0400514 const struct alps_model_info *model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Dmitry Torokhovf42649e2007-04-12 01:31:13 -0400516 model = alps_get_model(psmouse, &version);
517 if (!model)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return -1;
519
520 if (set_properties) {
521 psmouse->vendor = "ALPS";
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500522 psmouse->name = model->flags & ALPS_DUALPOINT ?
523 "DualPoint TouchPad" : "GlidePoint";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 psmouse->model = version;
525 }
526 return 0;
527}
528