[CIFS] Fix minor checkpatch warning and update cifs version
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / input / mouse / alps.c
blob99d58764ef03573e94c624625ae64f710d06ee69
1 /*
2 * ALPS touchpad PS/2 mouse driver
4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
5 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
6 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
8 * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net>
10 * ALPS detection, tap switching and status querying info is taken from
11 * tpconfig utility (by C. Scott Ananian and Bruce Kall).
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License version 2 as published by
15 * the Free Software Foundation.
18 #include <linux/slab.h>
19 #include <linux/input.h>
20 #include <linux/serio.h>
21 #include <linux/libps2.h>
23 #include "psmouse.h"
24 #include "alps.h"
26 #undef DEBUG
27 #ifdef DEBUG
28 #define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg)
29 #else
30 #define dbg(format, arg...) do {} while (0)
31 #endif
33 #define ALPS_OLDPROTO 0x01 /* old style input */
34 #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
35 #define ALPS_PASS 0x04 /* device has a pass-through port */
37 #define ALPS_WHEEL 0x08 /* hardware wheel present */
38 #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
39 #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
40 #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
41 #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
42 6-byte ALPS packet */
44 static const struct alps_model_info alps_model_data[] = {
45 { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
46 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
47 { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
48 { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
49 { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */
50 { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
51 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
52 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
53 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
54 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
55 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
56 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
57 { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
58 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
59 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
60 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
61 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
62 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
63 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
64 { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf,
65 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
66 { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
67 { { 0x52, 0x01, 0x14 }, 0xff, 0xff,
68 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
72 * XXX - this entry is suspicious. First byte has zero lower nibble,
73 * which is what a normal mouse would report. Also, the value 0x0e
74 * isn't valid per PS/2 spec.
78 * PS/2 packet format
80 * byte 0: 0 0 YSGN XSGN 1 M R L
81 * byte 1: X7 X6 X5 X4 X3 X2 X1 X0
82 * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
84 * Note that the device never signals overflow condition.
86 * ALPS absolute Mode - new format
88 * byte 0: 1 ? ? ? 1 ? ? ?
89 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
90 * byte 2: 0 x10 x9 x8 x7 ? fin ges
91 * byte 3: 0 y9 y8 y7 1 M R L
92 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
93 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
95 * Dualpoint device -- interleaved packet format
97 * byte 0: 1 1 0 0 1 1 1 1
98 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
99 * byte 2: 0 x10 x9 x8 x7 0 fin ges
100 * byte 3: 0 0 YSGN XSGN 1 1 1 1
101 * byte 4: X7 X6 X5 X4 X3 X2 X1 X0
102 * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
103 * byte 6: 0 y9 y8 y7 1 m r l
104 * byte 7: 0 y6 y5 y4 y3 y2 y1 y0
105 * byte 8: 0 z6 z5 z4 z3 z2 z1 z0
107 * CAPITALS = stick, miniscules = touchpad
109 * ?'s can have different meanings on different models,
110 * such as wheel rotation, extra buttons, stick buttons
111 * on a dualpoint, etc.
114 static bool alps_is_valid_first_byte(const struct alps_model_info *model,
115 unsigned char data)
117 return (data & model->mask0) == model->byte0;
120 static void alps_report_buttons(struct psmouse *psmouse,
121 struct input_dev *dev1, struct input_dev *dev2,
122 int left, int right, int middle)
124 struct input_dev *dev;
127 * If shared button has already been reported on the
128 * other device (dev2) then this event should be also
129 * sent through that device.
131 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
132 input_report_key(dev, BTN_LEFT, left);
134 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
135 input_report_key(dev, BTN_RIGHT, right);
137 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
138 input_report_key(dev, BTN_MIDDLE, middle);
141 * Sync the _other_ device now, we'll do the first
142 * device later once we report the rest of the events.
144 input_sync(dev2);
147 static void alps_process_packet(struct psmouse *psmouse)
149 struct alps_data *priv = psmouse->private;
150 const struct alps_model_info *model = priv->i;
151 unsigned char *packet = psmouse->packet;
152 struct input_dev *dev = psmouse->dev;
153 struct input_dev *dev2 = priv->dev2;
154 int x, y, z, ges, fin, left, right, middle;
155 int back = 0, forward = 0;
157 if (model->flags & ALPS_OLDPROTO) {
158 left = packet[2] & 0x10;
159 right = packet[2] & 0x08;
160 middle = 0;
161 x = packet[1] | ((packet[0] & 0x07) << 7);
162 y = packet[4] | ((packet[3] & 0x07) << 7);
163 z = packet[5];
164 } else {
165 left = packet[3] & 1;
166 right = packet[3] & 2;
167 middle = packet[3] & 4;
168 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
169 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
170 z = packet[5];
173 if (model->flags & ALPS_FW_BK_1) {
174 back = packet[0] & 0x10;
175 forward = packet[2] & 4;
178 if (model->flags & ALPS_FW_BK_2) {
179 back = packet[3] & 4;
180 forward = packet[2] & 4;
181 if ((middle = forward && back))
182 forward = back = 0;
185 ges = packet[2] & 1;
186 fin = packet[2] & 2;
188 if ((model->flags & ALPS_DUALPOINT) && z == 127) {
189 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
190 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
192 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
194 input_sync(dev2);
195 return;
198 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
200 /* Convert hardware tap to a reasonable Z value */
201 if (ges && !fin)
202 z = 40;
205 * A "tap and drag" operation is reported by the hardware as a transition
206 * from (!fin && ges) to (fin && ges). This should be translated to the
207 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
209 if (ges && fin && !priv->prev_fin) {
210 input_report_abs(dev, ABS_X, x);
211 input_report_abs(dev, ABS_Y, y);
212 input_report_abs(dev, ABS_PRESSURE, 0);
213 input_report_key(dev, BTN_TOOL_FINGER, 0);
214 input_sync(dev);
216 priv->prev_fin = fin;
218 if (z > 30)
219 input_report_key(dev, BTN_TOUCH, 1);
220 if (z < 25)
221 input_report_key(dev, BTN_TOUCH, 0);
223 if (z > 0) {
224 input_report_abs(dev, ABS_X, x);
225 input_report_abs(dev, ABS_Y, y);
228 input_report_abs(dev, ABS_PRESSURE, z);
229 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
231 if (model->flags & ALPS_WHEEL)
232 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
234 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
235 input_report_key(dev, BTN_FORWARD, forward);
236 input_report_key(dev, BTN_BACK, back);
239 if (model->flags & ALPS_FOUR_BUTTONS) {
240 input_report_key(dev, BTN_0, packet[2] & 4);
241 input_report_key(dev, BTN_1, packet[0] & 0x10);
242 input_report_key(dev, BTN_2, packet[3] & 4);
243 input_report_key(dev, BTN_3, packet[0] & 0x20);
246 input_sync(dev);
249 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
250 unsigned char packet[],
251 bool report_buttons)
253 struct alps_data *priv = psmouse->private;
254 struct input_dev *dev2 = priv->dev2;
256 if (report_buttons)
257 alps_report_buttons(psmouse, dev2, psmouse->dev,
258 packet[0] & 1, packet[0] & 2, packet[0] & 4);
260 input_report_rel(dev2, REL_X,
261 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
262 input_report_rel(dev2, REL_Y,
263 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
265 input_sync(dev2);
268 static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
270 struct alps_data *priv = psmouse->private;
272 if (psmouse->pktcnt < 6)
273 return PSMOUSE_GOOD_DATA;
275 if (psmouse->pktcnt == 6) {
277 * Start a timer to flush the packet if it ends up last
278 * 6-byte packet in the stream. Timer needs to fire
279 * psmouse core times out itself. 20 ms should be enough
280 * to decide if we are getting more data or not.
282 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
283 return PSMOUSE_GOOD_DATA;
286 del_timer(&priv->timer);
288 if (psmouse->packet[6] & 0x80) {
291 * Highest bit is set - that means we either had
292 * complete ALPS packet and this is start of the
293 * next packet or we got garbage.
296 if (((psmouse->packet[3] |
297 psmouse->packet[4] |
298 psmouse->packet[5]) & 0x80) ||
299 (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) {
300 dbg("refusing packet %x %x %x %x "
301 "(suspected interleaved ps/2)\n",
302 psmouse->packet[3], psmouse->packet[4],
303 psmouse->packet[5], psmouse->packet[6]);
304 return PSMOUSE_BAD_DATA;
307 alps_process_packet(psmouse);
309 /* Continue with the next packet */
310 psmouse->packet[0] = psmouse->packet[6];
311 psmouse->pktcnt = 1;
313 } else {
316 * High bit is 0 - that means that we indeed got a PS/2
317 * packet in the middle of ALPS packet.
319 * There is also possibility that we got 6-byte ALPS
320 * packet followed by 3-byte packet from trackpoint. We
321 * can not distinguish between these 2 scenarios but
322 * becase the latter is unlikely to happen in course of
323 * normal operation (user would need to press all
324 * buttons on the pad and start moving trackpoint
325 * without touching the pad surface) we assume former.
326 * Even if we are wrong the wost thing that would happen
327 * the cursor would jump but we should not get protocol
328 * desynchronization.
331 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
332 false);
335 * Continue with the standard ALPS protocol handling,
336 * but make sure we won't process it as an interleaved
337 * packet again, which may happen if all buttons are
338 * pressed. To avoid this let's reset the 4th bit which
339 * is normally 1.
341 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
342 psmouse->pktcnt = 4;
345 return PSMOUSE_GOOD_DATA;
348 static void alps_flush_packet(unsigned long data)
350 struct psmouse *psmouse = (struct psmouse *)data;
352 serio_pause_rx(psmouse->ps2dev.serio);
354 if (psmouse->pktcnt == 6) {
357 * We did not any more data in reasonable amount of time.
358 * Validate the last 3 bytes and process as a standard
359 * ALPS packet.
361 if ((psmouse->packet[3] |
362 psmouse->packet[4] |
363 psmouse->packet[5]) & 0x80) {
364 dbg("refusing packet %x %x %x "
365 "(suspected interleaved ps/2)\n",
366 psmouse->packet[3], psmouse->packet[4],
367 psmouse->packet[5]);
368 } else {
369 alps_process_packet(psmouse);
371 psmouse->pktcnt = 0;
374 serio_continue_rx(psmouse->ps2dev.serio);
377 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
379 struct alps_data *priv = psmouse->private;
380 const struct alps_model_info *model = priv->i;
382 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
383 if (psmouse->pktcnt == 3) {
384 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
385 true);
386 return PSMOUSE_FULL_PACKET;
388 return PSMOUSE_GOOD_DATA;
391 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
393 if ((model->flags & ALPS_PS2_INTERLEAVED) &&
394 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
395 return alps_handle_interleaved_ps2(psmouse);
398 if (!alps_is_valid_first_byte(model, psmouse->packet[0])) {
399 dbg("refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
400 psmouse->packet[0], model->mask0, model->byte0);
401 return PSMOUSE_BAD_DATA;
404 /* Bytes 2 - 6 should have 0 in the highest bit */
405 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
406 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
407 dbg("refusing packet[%i] = %x\n",
408 psmouse->pktcnt - 1, psmouse->packet[psmouse->pktcnt - 1]);
409 return PSMOUSE_BAD_DATA;
412 if (psmouse->pktcnt == 6) {
413 alps_process_packet(psmouse);
414 return PSMOUSE_FULL_PACKET;
417 return PSMOUSE_GOOD_DATA;
420 static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
422 struct ps2dev *ps2dev = &psmouse->ps2dev;
423 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
424 unsigned char param[4];
425 int i;
428 * First try "E6 report".
429 * ALPS should return 0,0,10 or 0,0,100
431 param[0] = 0;
432 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
433 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
434 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
435 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
436 return NULL;
438 param[0] = param[1] = param[2] = 0xff;
439 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
440 return NULL;
442 dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
444 if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
445 return NULL;
448 * Now try "E7 report". Allowed responses are in
449 * alps_model_data[].signature
451 param[0] = 0;
452 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
453 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
454 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
455 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
456 return NULL;
458 param[0] = param[1] = param[2] = 0xff;
459 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
460 return NULL;
462 dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
464 if (version) {
465 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
466 /* empty */;
467 *version = (param[0] << 8) | (param[1] << 4) | i;
470 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
471 if (!memcmp(param, alps_model_data[i].signature,
472 sizeof(alps_model_data[i].signature)))
473 return alps_model_data + i;
475 return NULL;
479 * For DualPoint devices select the device that should respond to
480 * subsequent commands. It looks like glidepad is behind stickpointer,
481 * I'd thought it would be other way around...
483 static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
485 struct ps2dev *ps2dev = &psmouse->ps2dev;
486 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
488 if (ps2_command(ps2dev, NULL, cmd) ||
489 ps2_command(ps2dev, NULL, cmd) ||
490 ps2_command(ps2dev, NULL, cmd) ||
491 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
492 return -1;
494 /* we may get 3 more bytes, just ignore them */
495 ps2_drain(ps2dev, 3, 100);
497 return 0;
500 static int alps_absolute_mode(struct psmouse *psmouse)
502 struct ps2dev *ps2dev = &psmouse->ps2dev;
504 /* Try ALPS magic knock - 4 disable before enable */
505 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
506 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
507 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
508 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
509 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
510 return -1;
513 * Switch mouse to poll (remote) mode so motion data will not
514 * get in our way
516 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
519 static int alps_get_status(struct psmouse *psmouse, char *param)
521 struct ps2dev *ps2dev = &psmouse->ps2dev;
523 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
524 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
525 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
526 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
527 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
528 return -1;
530 dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
532 return 0;
536 * Turn touchpad tapping on or off. The sequences are:
537 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
538 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
539 * My guess that 0xE9 (GetInfo) is here as a sync point.
540 * For models that also have stickpointer (DualPoints) its tapping
541 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
542 * we don't fiddle with it.
544 static int alps_tap_mode(struct psmouse *psmouse, int enable)
546 struct ps2dev *ps2dev = &psmouse->ps2dev;
547 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
548 unsigned char tap_arg = enable ? 0x0A : 0x00;
549 unsigned char param[4];
551 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
552 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
553 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
554 ps2_command(ps2dev, &tap_arg, cmd))
555 return -1;
557 if (alps_get_status(psmouse, param))
558 return -1;
560 return 0;
564 * alps_poll() - poll the touchpad for current motion packet.
565 * Used in resync.
567 static int alps_poll(struct psmouse *psmouse)
569 struct alps_data *priv = psmouse->private;
570 unsigned char buf[6];
571 bool poll_failed;
573 if (priv->i->flags & ALPS_PASS)
574 alps_passthrough_mode(psmouse, true);
576 poll_failed = ps2_command(&psmouse->ps2dev, buf,
577 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
579 if (priv->i->flags & ALPS_PASS)
580 alps_passthrough_mode(psmouse, false);
582 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
583 return -1;
585 if ((psmouse->badbyte & 0xc8) == 0x08) {
587 * Poll the track stick ...
589 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
590 return -1;
593 memcpy(psmouse->packet, buf, sizeof(buf));
594 return 0;
597 static int alps_hw_init(struct psmouse *psmouse)
599 struct alps_data *priv = psmouse->private;
600 const struct alps_model_info *model = priv->i;
602 if ((model->flags & ALPS_PASS) &&
603 alps_passthrough_mode(psmouse, true)) {
604 return -1;
607 if (alps_tap_mode(psmouse, true)) {
608 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
609 return -1;
612 if (alps_absolute_mode(psmouse)) {
613 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
614 return -1;
617 if ((model->flags & ALPS_PASS) &&
618 alps_passthrough_mode(psmouse, false)) {
619 return -1;
622 /* ALPS needs stream mode, otherwise it won't report any data */
623 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
624 printk(KERN_ERR "alps.c: Failed to enable stream mode\n");
625 return -1;
628 return 0;
631 static int alps_reconnect(struct psmouse *psmouse)
633 const struct alps_model_info *model;
635 psmouse_reset(psmouse);
637 model = alps_get_model(psmouse, NULL);
638 if (!model)
639 return -1;
641 return alps_hw_init(psmouse);
644 static void alps_disconnect(struct psmouse *psmouse)
646 struct alps_data *priv = psmouse->private;
648 psmouse_reset(psmouse);
649 del_timer_sync(&priv->timer);
650 input_unregister_device(priv->dev2);
651 kfree(priv);
654 int alps_init(struct psmouse *psmouse)
656 struct alps_data *priv;
657 const struct alps_model_info *model;
658 struct input_dev *dev1 = psmouse->dev, *dev2;
659 int version;
661 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
662 dev2 = input_allocate_device();
663 if (!priv || !dev2)
664 goto init_fail;
666 priv->dev2 = dev2;
667 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
669 psmouse->private = priv;
671 model = alps_get_model(psmouse, &version);
672 if (!model)
673 goto init_fail;
675 priv->i = model;
677 if (alps_hw_init(psmouse))
678 goto init_fail;
681 * Undo part of setup done for us by psmouse core since touchpad
682 * is not a relative device.
684 __clear_bit(EV_REL, dev1->evbit);
685 __clear_bit(REL_X, dev1->relbit);
686 __clear_bit(REL_Y, dev1->relbit);
689 * Now set up our capabilities.
691 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
692 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
693 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
694 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
695 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
697 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
698 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
699 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
700 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
702 if (model->flags & ALPS_WHEEL) {
703 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
704 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
707 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
708 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
709 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
712 if (model->flags & ALPS_FOUR_BUTTONS) {
713 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
714 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
715 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
716 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
717 } else {
718 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
721 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
722 dev2->phys = priv->phys;
723 dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
724 dev2->id.bustype = BUS_I8042;
725 dev2->id.vendor = 0x0002;
726 dev2->id.product = PSMOUSE_ALPS;
727 dev2->id.version = 0x0000;
728 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
730 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
731 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
732 dev2->keybit[BIT_WORD(BTN_LEFT)] =
733 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
735 if (input_register_device(priv->dev2))
736 goto init_fail;
738 psmouse->protocol_handler = alps_process_byte;
739 psmouse->poll = alps_poll;
740 psmouse->disconnect = alps_disconnect;
741 psmouse->reconnect = alps_reconnect;
742 psmouse->pktsize = 6;
744 /* We are having trouble resyncing ALPS touchpads so disable it for now */
745 psmouse->resync_time = 0;
747 return 0;
749 init_fail:
750 psmouse_reset(psmouse);
751 input_free_device(dev2);
752 kfree(priv);
753 psmouse->private = NULL;
754 return -1;
757 int alps_detect(struct psmouse *psmouse, bool set_properties)
759 int version;
760 const struct alps_model_info *model;
762 model = alps_get_model(psmouse, &version);
763 if (!model)
764 return -1;
766 if (set_properties) {
767 psmouse->vendor = "ALPS";
768 psmouse->name = model->flags & ALPS_DUALPOINT ?
769 "DualPoint TouchPad" : "GlidePoint";
770 psmouse->model = version;
772 return 0;