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>
28 #define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg)
30 #define dbg(format, arg...) do {} while (0)
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
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 { { 0x73, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, /* HP Pavilion dm3 */
68 { { 0x52, 0x01, 0x14 }, 0xff, 0xff,
69 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
73 * XXX - this entry is suspicious. First byte has zero lower nibble,
74 * which is what a normal mouse would report. Also, the value 0x0e
75 * isn't valid per PS/2 spec.
81 * byte 0: 0 0 YSGN XSGN 1 M R L
82 * byte 1: X7 X6 X5 X4 X3 X2 X1 X0
83 * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
85 * Note that the device never signals overflow condition.
87 * ALPS absolute Mode - new format
89 * byte 0: 1 ? ? ? 1 ? ? ?
90 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
91 * byte 2: 0 x10 x9 x8 x7 ? fin ges
92 * byte 3: 0 y9 y8 y7 1 M R L
93 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
94 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
96 * Dualpoint device -- interleaved packet format
98 * byte 0: 1 1 0 0 1 1 1 1
99 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
100 * byte 2: 0 x10 x9 x8 x7 0 fin ges
101 * byte 3: 0 0 YSGN XSGN 1 1 1 1
102 * byte 4: X7 X6 X5 X4 X3 X2 X1 X0
103 * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
104 * byte 6: 0 y9 y8 y7 1 m r l
105 * byte 7: 0 y6 y5 y4 y3 y2 y1 y0
106 * byte 8: 0 z6 z5 z4 z3 z2 z1 z0
108 * CAPITALS = stick, miniscules = touchpad
110 * ?'s can have different meanings on different models,
111 * such as wheel rotation, extra buttons, stick buttons
112 * on a dualpoint, etc.
115 static bool alps_is_valid_first_byte(const struct alps_model_info *model,
118 return (data & model->mask0) == model->byte0;
121 static void alps_report_buttons(struct psmouse *psmouse,
122 struct input_dev *dev1, struct input_dev *dev2,
123 int left, int right, int middle)
125 struct input_dev *dev;
128 * If shared button has already been reported on the
129 * other device (dev2) then this event should be also
130 * sent through that device.
132 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
133 input_report_key(dev, BTN_LEFT, left);
135 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
136 input_report_key(dev, BTN_RIGHT, right);
138 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
139 input_report_key(dev, BTN_MIDDLE, middle);
142 * Sync the _other_ device now, we'll do the first
143 * device later once we report the rest of the events.
148 static void alps_process_packet(struct psmouse *psmouse)
150 struct alps_data *priv = psmouse->private;
151 const struct alps_model_info *model = priv->i;
152 unsigned char *packet = psmouse->packet;
153 struct input_dev *dev = psmouse->dev;
154 struct input_dev *dev2 = priv->dev2;
155 int x, y, z, ges, fin, left, right, middle;
156 int back = 0, forward = 0;
158 if (model->flags & ALPS_OLDPROTO) {
159 left = packet[2] & 0x10;
160 right = packet[2] & 0x08;
162 x = packet[1] | ((packet[0] & 0x07) << 7);
163 y = packet[4] | ((packet[3] & 0x07) << 7);
166 left = packet[3] & 1;
167 right = packet[3] & 2;
168 middle = packet[3] & 4;
169 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
170 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
174 if (model->flags & ALPS_FW_BK_1) {
175 back = packet[0] & 0x10;
176 forward = packet[2] & 4;
179 if (model->flags & ALPS_FW_BK_2) {
180 back = packet[3] & 4;
181 forward = packet[2] & 4;
182 if ((middle = forward && back))
189 if ((model->flags & ALPS_DUALPOINT) && z == 127) {
190 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
191 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
193 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
199 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
201 /* Convert hardware tap to a reasonable Z value */
206 * A "tap and drag" operation is reported by the hardware as a transition
207 * from (!fin && ges) to (fin && ges). This should be translated to the
208 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
210 if (ges && fin && !priv->prev_fin) {
211 input_report_abs(dev, ABS_X, x);
212 input_report_abs(dev, ABS_Y, y);
213 input_report_abs(dev, ABS_PRESSURE, 0);
214 input_report_key(dev, BTN_TOOL_FINGER, 0);
217 priv->prev_fin = fin;
220 input_report_key(dev, BTN_TOUCH, 1);
222 input_report_key(dev, BTN_TOUCH, 0);
225 input_report_abs(dev, ABS_X, x);
226 input_report_abs(dev, ABS_Y, y);
229 input_report_abs(dev, ABS_PRESSURE, z);
230 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
232 if (model->flags & ALPS_WHEEL)
233 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
235 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
236 input_report_key(dev, BTN_FORWARD, forward);
237 input_report_key(dev, BTN_BACK, back);
240 if (model->flags & ALPS_FOUR_BUTTONS) {
241 input_report_key(dev, BTN_0, packet[2] & 4);
242 input_report_key(dev, BTN_1, packet[0] & 0x10);
243 input_report_key(dev, BTN_2, packet[3] & 4);
244 input_report_key(dev, BTN_3, packet[0] & 0x20);
250 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
251 unsigned char packet[],
254 struct alps_data *priv = psmouse->private;
255 struct input_dev *dev2 = priv->dev2;
258 alps_report_buttons(psmouse, dev2, psmouse->dev,
259 packet[0] & 1, packet[0] & 2, packet[0] & 4);
261 input_report_rel(dev2, REL_X,
262 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
263 input_report_rel(dev2, REL_Y,
264 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
269 static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
271 struct alps_data *priv = psmouse->private;
273 if (psmouse->pktcnt < 6)
274 return PSMOUSE_GOOD_DATA;
276 if (psmouse->pktcnt == 6) {
278 * Start a timer to flush the packet if it ends up last
279 * 6-byte packet in the stream. Timer needs to fire
280 * psmouse core times out itself. 20 ms should be enough
281 * to decide if we are getting more data or not.
283 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
284 return PSMOUSE_GOOD_DATA;
287 del_timer(&priv->timer);
289 if (psmouse->packet[6] & 0x80) {
292 * Highest bit is set - that means we either had
293 * complete ALPS packet and this is start of the
294 * next packet or we got garbage.
297 if (((psmouse->packet[3] |
299 psmouse->packet[5]) & 0x80) ||
300 (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) {
301 dbg("refusing packet %x %x %x %x "
302 "(suspected interleaved ps/2)\n",
303 psmouse->packet[3], psmouse->packet[4],
304 psmouse->packet[5], psmouse->packet[6]);
305 return PSMOUSE_BAD_DATA;
308 alps_process_packet(psmouse);
310 /* Continue with the next packet */
311 psmouse->packet[0] = psmouse->packet[6];
317 * High bit is 0 - that means that we indeed got a PS/2
318 * packet in the middle of ALPS packet.
320 * There is also possibility that we got 6-byte ALPS
321 * packet followed by 3-byte packet from trackpoint. We
322 * can not distinguish between these 2 scenarios but
323 * becase the latter is unlikely to happen in course of
324 * normal operation (user would need to press all
325 * buttons on the pad and start moving trackpoint
326 * without touching the pad surface) we assume former.
327 * Even if we are wrong the wost thing that would happen
328 * the cursor would jump but we should not get protocol
332 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
336 * Continue with the standard ALPS protocol handling,
337 * but make sure we won't process it as an interleaved
338 * packet again, which may happen if all buttons are
339 * pressed. To avoid this let's reset the 4th bit which
342 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
346 return PSMOUSE_GOOD_DATA;
349 static void alps_flush_packet(unsigned long data)
351 struct psmouse *psmouse = (struct psmouse *)data;
353 serio_pause_rx(psmouse->ps2dev.serio);
355 if (psmouse->pktcnt == 6) {
358 * We did not any more data in reasonable amount of time.
359 * Validate the last 3 bytes and process as a standard
362 if ((psmouse->packet[3] |
364 psmouse->packet[5]) & 0x80) {
365 dbg("refusing packet %x %x %x "
366 "(suspected interleaved ps/2)\n",
367 psmouse->packet[3], psmouse->packet[4],
370 alps_process_packet(psmouse);
375 serio_continue_rx(psmouse->ps2dev.serio);
378 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
380 struct alps_data *priv = psmouse->private;
381 const struct alps_model_info *model = priv->i;
383 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
384 if (psmouse->pktcnt == 3) {
385 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
387 return PSMOUSE_FULL_PACKET;
389 return PSMOUSE_GOOD_DATA;
392 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
394 if ((model->flags & ALPS_PS2_INTERLEAVED) &&
395 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
396 return alps_handle_interleaved_ps2(psmouse);
399 if (!alps_is_valid_first_byte(model, psmouse->packet[0])) {
400 dbg("refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
401 psmouse->packet[0], model->mask0, model->byte0);
402 return PSMOUSE_BAD_DATA;
405 /* Bytes 2 - 6 should have 0 in the highest bit */
406 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
407 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
408 dbg("refusing packet[%i] = %x\n",
409 psmouse->pktcnt - 1, psmouse->packet[psmouse->pktcnt - 1]);
410 return PSMOUSE_BAD_DATA;
413 if (psmouse->pktcnt == 6) {
414 alps_process_packet(psmouse);
415 return PSMOUSE_FULL_PACKET;
418 return PSMOUSE_GOOD_DATA;
421 static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
423 struct ps2dev *ps2dev = &psmouse->ps2dev;
424 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
425 unsigned char param[4];
429 * First try "E6 report".
430 * ALPS should return 0,0,10 or 0,0,100
433 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
434 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
435 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
436 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
439 param[0] = param[1] = param[2] = 0xff;
440 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
443 dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
445 if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
449 * Now try "E7 report". Allowed responses are in
450 * alps_model_data[].signature
453 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
454 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
455 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
456 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
459 param[0] = param[1] = param[2] = 0xff;
460 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
463 dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
466 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
468 *version = (param[0] << 8) | (param[1] << 4) | i;
471 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
472 if (!memcmp(param, alps_model_data[i].signature,
473 sizeof(alps_model_data[i].signature)))
474 return alps_model_data + i;
480 * For DualPoint devices select the device that should respond to
481 * subsequent commands. It looks like glidepad is behind stickpointer,
482 * I'd thought it would be other way around...
484 static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
486 struct ps2dev *ps2dev = &psmouse->ps2dev;
487 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
489 if (ps2_command(ps2dev, NULL, cmd) ||
490 ps2_command(ps2dev, NULL, cmd) ||
491 ps2_command(ps2dev, NULL, cmd) ||
492 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
495 /* we may get 3 more bytes, just ignore them */
496 ps2_drain(ps2dev, 3, 100);
501 static int alps_absolute_mode(struct psmouse *psmouse)
503 struct ps2dev *ps2dev = &psmouse->ps2dev;
505 /* Try ALPS magic knock - 4 disable before enable */
506 if (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_DISABLE) ||
510 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
514 * Switch mouse to poll (remote) mode so motion data will not
517 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
520 static int alps_get_status(struct psmouse *psmouse, char *param)
522 struct ps2dev *ps2dev = &psmouse->ps2dev;
524 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
525 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
526 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
527 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
528 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
531 dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
537 * Turn touchpad tapping on or off. The sequences are:
538 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
539 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
540 * My guess that 0xE9 (GetInfo) is here as a sync point.
541 * For models that also have stickpointer (DualPoints) its tapping
542 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
543 * we don't fiddle with it.
545 static int alps_tap_mode(struct psmouse *psmouse, int enable)
547 struct ps2dev *ps2dev = &psmouse->ps2dev;
548 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
549 unsigned char tap_arg = enable ? 0x0A : 0x00;
550 unsigned char param[4];
552 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
553 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
554 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
555 ps2_command(ps2dev, &tap_arg, cmd))
558 if (alps_get_status(psmouse, param))
565 * alps_poll() - poll the touchpad for current motion packet.
568 static int alps_poll(struct psmouse *psmouse)
570 struct alps_data *priv = psmouse->private;
571 unsigned char buf[6];
574 if (priv->i->flags & ALPS_PASS)
575 alps_passthrough_mode(psmouse, true);
577 poll_failed = ps2_command(&psmouse->ps2dev, buf,
578 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
580 if (priv->i->flags & ALPS_PASS)
581 alps_passthrough_mode(psmouse, false);
583 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
586 if ((psmouse->badbyte & 0xc8) == 0x08) {
588 * Poll the track stick ...
590 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
594 memcpy(psmouse->packet, buf, sizeof(buf));
598 static int alps_hw_init(struct psmouse *psmouse)
600 struct alps_data *priv = psmouse->private;
601 const struct alps_model_info *model = priv->i;
603 if ((model->flags & ALPS_PASS) &&
604 alps_passthrough_mode(psmouse, true)) {
608 if (alps_tap_mode(psmouse, true)) {
609 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
613 if (alps_absolute_mode(psmouse)) {
614 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
618 if ((model->flags & ALPS_PASS) &&
619 alps_passthrough_mode(psmouse, false)) {
623 /* ALPS needs stream mode, otherwise it won't report any data */
624 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
625 printk(KERN_ERR "alps.c: Failed to enable stream mode\n");
632 static int alps_reconnect(struct psmouse *psmouse)
634 const struct alps_model_info *model;
636 psmouse_reset(psmouse);
638 model = alps_get_model(psmouse, NULL);
642 return alps_hw_init(psmouse);
645 static void alps_disconnect(struct psmouse *psmouse)
647 struct alps_data *priv = psmouse->private;
649 psmouse_reset(psmouse);
650 del_timer_sync(&priv->timer);
651 input_unregister_device(priv->dev2);
655 int alps_init(struct psmouse *psmouse)
657 struct alps_data *priv;
658 const struct alps_model_info *model;
659 struct input_dev *dev1 = psmouse->dev, *dev2;
662 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
663 dev2 = input_allocate_device();
668 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
670 psmouse->private = priv;
672 model = alps_get_model(psmouse, &version);
678 if (alps_hw_init(psmouse))
682 * Undo part of setup done for us by psmouse core since touchpad
683 * is not a relative device.
685 __clear_bit(EV_REL, dev1->evbit);
686 __clear_bit(REL_X, dev1->relbit);
687 __clear_bit(REL_Y, dev1->relbit);
690 * Now set up our capabilities.
692 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
693 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
694 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
695 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
696 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
698 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
699 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
700 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
701 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
703 if (model->flags & ALPS_WHEEL) {
704 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
705 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
708 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
709 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
710 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
713 if (model->flags & ALPS_FOUR_BUTTONS) {
714 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
715 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
716 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
717 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
719 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
722 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
723 dev2->phys = priv->phys;
724 dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
725 dev2->id.bustype = BUS_I8042;
726 dev2->id.vendor = 0x0002;
727 dev2->id.product = PSMOUSE_ALPS;
728 dev2->id.version = 0x0000;
729 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
731 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
732 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
733 dev2->keybit[BIT_WORD(BTN_LEFT)] =
734 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
736 if (input_register_device(priv->dev2))
739 psmouse->protocol_handler = alps_process_byte;
740 psmouse->poll = alps_poll;
741 psmouse->disconnect = alps_disconnect;
742 psmouse->reconnect = alps_reconnect;
743 psmouse->pktsize = 6;
745 /* We are having trouble resyncing ALPS touchpads so disable it for now */
746 psmouse->resync_time = 0;
751 psmouse_reset(psmouse);
752 input_free_device(dev2);
754 psmouse->private = NULL;
758 int alps_detect(struct psmouse *psmouse, bool set_properties)
761 const struct alps_model_info *model;
763 model = alps_get_model(psmouse, &version);
767 if (set_properties) {
768 psmouse->vendor = "ALPS";
769 psmouse->name = model->flags & ALPS_DUALPOINT ?
770 "DualPoint TouchPad" : "GlidePoint";
771 psmouse->model = version;