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/dmi.h>
19 #include <linux/slab.h>
20 #include <linux/input.h>
21 #include <linux/serio.h>
22 #include <linux/libps2.h>
29 #define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg)
31 #define dbg(format, arg...) do {} while (0)
34 #define ALPS_OLDPROTO 0x01 /* old style input */
35 #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
36 #define ALPS_PASS 0x04 /* device has a pass-through port */
38 #define ALPS_WHEEL 0x08 /* hardware wheel present */
39 #define ALPS_FW_BK_1 0x10 /* front & back buttons present */
40 #define ALPS_FW_BK_2 0x20 /* front & back buttons present */
41 #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
42 #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
45 static const struct alps_model_info alps_model_data[] = {
46 { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
47 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
48 { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
49 { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
50 { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */
51 { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
52 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
53 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
54 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
55 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
56 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
57 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
58 { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
59 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
60 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
61 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
62 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
63 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
64 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
65 { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf,
66 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
67 /* Dell Precision 4500 */
68 { { 0x73, 0x02, 0x64 }, 0x80, 0x80, 0 },
69 { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
70 { { 0x52, 0x01, 0x14 }, 0xff, 0xff,
71 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
75 * XXX - this entry is suspicious. First byte has zero lower nibble,
76 * which is what a normal mouse would report. Also, the value 0x0e
77 * isn't valid per PS/2 spec.
83 * byte 0: 0 0 YSGN XSGN 1 M R L
84 * byte 1: X7 X6 X5 X4 X3 X2 X1 X0
85 * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
87 * Note that the device never signals overflow condition.
89 * ALPS absolute Mode - new format
91 * byte 0: 1 ? ? ? 1 ? ? ?
92 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
93 * byte 2: 0 x10 x9 x8 x7 ? fin ges
94 * byte 3: 0 y9 y8 y7 1 M R L
95 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
96 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
98 * Dualpoint device -- interleaved packet format
100 * byte 0: 1 1 0 0 1 1 1 1
101 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
102 * byte 2: 0 x10 x9 x8 x7 0 fin ges
103 * byte 3: 0 0 YSGN XSGN 1 1 1 1
104 * byte 4: X7 X6 X5 X4 X3 X2 X1 X0
105 * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
106 * byte 6: 0 y9 y8 y7 1 m r l
107 * byte 7: 0 y6 y5 y4 y3 y2 y1 y0
108 * byte 8: 0 z6 z5 z4 z3 z2 z1 z0
110 * CAPITALS = stick, miniscules = touchpad
112 * ?'s can have different meanings on different models,
113 * such as wheel rotation, extra buttons, stick buttons
114 * on a dualpoint, etc.
117 static const struct dmi_system_id dell_quirk_table[] = {
120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
121 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
126 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
127 DMI_MATCH(DMI_CHASSIS_TYPE, "9"),
133 int alps_model_quirk_enabled;
134 static void dell_e2_model_init(void *data);
136 /* Magic Sequence to enable Intellimouse Mode on Dell E2 Touchpads*/
138 static int dell_e2_setup_intellimouse_mode(void *data)
140 struct psmouse *psmouse = (struct psmouse *)(data);
141 struct ps2dev *ps2dev = &psmouse->ps2dev;
142 unsigned char param[] = {0, 0, 0};
144 if (!dmi_check_system(dell_quirk_table))
147 if (ps2_command(ps2dev, param, 0x00f5) ||
148 ps2_command(ps2dev, param, 0x00ea) ||
149 ps2_command(ps2dev, param, 0x00ec) ||
150 ps2_command(ps2dev, param, 0x00ec) ||
151 ps2_command(ps2dev, param, 0x00ec) ||
152 ps2_command(ps2dev, param, 0x03e9))
155 dbg("alps:dell_e2_setup: param[0]: %x,"
156 "param[1]: %x, param[2]: %x\n", param[0],
158 /* Check for supported model to continue */
160 if (!((param[0] == 0x88) && (param[1] == 0x07)
161 && ((param[2] == 0x9D) || (param[2] == 0x9B))))
164 if (ps2_command(ps2dev, NULL, 0x00ec) ||
165 ps2_command(ps2dev, NULL, 0x00f0) ||
166 ps2_command(ps2dev, NULL, 0x00f0) ||
167 ps2_command(ps2dev, NULL, 0x00f0) ||
168 ps2_command(ps2dev, NULL, 0x00f3) ||
169 ps2_command(ps2dev, NULL, 0x0028) ||
170 ps2_command(ps2dev, NULL, 0x00f0) ||
171 ps2_command(ps2dev, NULL, 0x00f6) ||
172 ps2_command(ps2dev, NULL, 0x00ea) ||
173 ps2_command(ps2dev, NULL, 0x00f4))
179 static const struct alps_model_quirk alps_model_init_quirk_tbl[] = {
181 { {0x73, 0x02, 0x64}, dell_e2_setup_intellimouse_mode, dell_e2_model_init }
184 static int alps_model_hw_init_quirk(struct psmouse *psmouse,
185 const struct alps_model_info *model)
190 for (i = 0; i < ARRAY_SIZE(alps_model_init_quirk_tbl); i++) {
191 if (!memcmp(model->signature,
192 alps_model_init_quirk_tbl[i].signature,
193 sizeof(alps_model_init_quirk_tbl[i].signature))) {
194 rc = alps_model_init_quirk_tbl[i].alps_model_quirk_hw_init(psmouse);
195 alps_model_quirk_enabled = i + 1;
203 static bool alps_is_valid_first_byte(const struct alps_model_info *model,
206 return (data & model->mask0) == model->byte0;
209 static void alps_report_buttons(struct psmouse *psmouse,
210 struct input_dev *dev1, struct input_dev *dev2,
211 int left, int right, int middle)
213 struct input_dev *dev;
216 * If shared button has already been reported on the
217 * other device (dev2) then this event should be also
218 * sent through that device.
220 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
221 input_report_key(dev, BTN_LEFT, left);
223 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
224 input_report_key(dev, BTN_RIGHT, right);
226 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
227 input_report_key(dev, BTN_MIDDLE, middle);
230 * Sync the _other_ device now, we'll do the first
231 * device later once we report the rest of the events.
236 static void alps_process_packet(struct psmouse *psmouse)
238 struct alps_data *priv = psmouse->private;
239 const struct alps_model_info *model = priv->i;
240 unsigned char *packet = psmouse->packet;
241 struct input_dev *dev = psmouse->dev;
242 struct input_dev *dev2 = priv->dev2;
243 int x, y, z, ges, fin, left, right, middle;
244 int back = 0, forward = 0;
246 if (model->flags & ALPS_OLDPROTO) {
247 left = packet[2] & 0x10;
248 right = packet[2] & 0x08;
250 x = packet[1] | ((packet[0] & 0x07) << 7);
251 y = packet[4] | ((packet[3] & 0x07) << 7);
254 left = packet[3] & 1;
255 right = packet[3] & 2;
256 middle = packet[3] & 4;
257 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
258 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
262 if (model->flags & ALPS_FW_BK_1) {
263 back = packet[0] & 0x10;
264 forward = packet[2] & 4;
267 if (model->flags & ALPS_FW_BK_2) {
268 back = packet[3] & 4;
269 forward = packet[2] & 4;
270 if ((middle = forward && back))
277 if ((model->flags & ALPS_DUALPOINT) && z == 127) {
278 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
279 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
281 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
287 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
289 /* Convert hardware tap to a reasonable Z value */
294 * A "tap and drag" operation is reported by the hardware as a transition
295 * from (!fin && ges) to (fin && ges). This should be translated to the
296 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
298 if (ges && fin && !priv->prev_fin) {
299 input_report_abs(dev, ABS_X, x);
300 input_report_abs(dev, ABS_Y, y);
301 input_report_abs(dev, ABS_PRESSURE, 0);
302 input_report_key(dev, BTN_TOOL_FINGER, 0);
305 priv->prev_fin = fin;
308 input_report_key(dev, BTN_TOUCH, 1);
310 input_report_key(dev, BTN_TOUCH, 0);
313 input_report_abs(dev, ABS_X, x);
314 input_report_abs(dev, ABS_Y, y);
317 input_report_abs(dev, ABS_PRESSURE, z);
318 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
320 if (model->flags & ALPS_WHEEL)
321 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
323 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
324 input_report_key(dev, BTN_FORWARD, forward);
325 input_report_key(dev, BTN_BACK, back);
328 if (model->flags & ALPS_FOUR_BUTTONS) {
329 input_report_key(dev, BTN_0, packet[2] & 4);
330 input_report_key(dev, BTN_1, packet[0] & 0x10);
331 input_report_key(dev, BTN_2, packet[3] & 4);
332 input_report_key(dev, BTN_3, packet[0] & 0x20);
338 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
339 unsigned char packet[],
342 struct alps_data *priv = psmouse->private;
343 struct input_dev *dev2 = priv->dev2;
346 alps_report_buttons(psmouse, dev2, psmouse->dev,
347 packet[0] & 1, packet[0] & 2, packet[0] & 4);
349 input_report_rel(dev2, REL_X,
350 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
351 input_report_rel(dev2, REL_Y,
352 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
357 static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
359 struct alps_data *priv = psmouse->private;
361 if (psmouse->pktcnt < 6)
362 return PSMOUSE_GOOD_DATA;
364 if (psmouse->pktcnt == 6) {
366 * Start a timer to flush the packet if it ends up last
367 * 6-byte packet in the stream. Timer needs to fire
368 * psmouse core times out itself. 20 ms should be enough
369 * to decide if we are getting more data or not.
371 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
372 return PSMOUSE_GOOD_DATA;
375 del_timer(&priv->timer);
377 if (psmouse->packet[6] & 0x80) {
380 * Highest bit is set - that means we either had
381 * complete ALPS packet and this is start of the
382 * next packet or we got garbage.
385 if (((psmouse->packet[3] |
387 psmouse->packet[5]) & 0x80) ||
388 (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) {
389 dbg("refusing packet %x %x %x %x "
390 "(suspected interleaved ps/2)\n",
391 psmouse->packet[3], psmouse->packet[4],
392 psmouse->packet[5], psmouse->packet[6]);
393 return PSMOUSE_BAD_DATA;
396 alps_process_packet(psmouse);
398 /* Continue with the next packet */
399 psmouse->packet[0] = psmouse->packet[6];
405 * High bit is 0 - that means that we indeed got a PS/2
406 * packet in the middle of ALPS packet.
408 * There is also possibility that we got 6-byte ALPS
409 * packet followed by 3-byte packet from trackpoint. We
410 * can not distinguish between these 2 scenarios but
411 * becase the latter is unlikely to happen in course of
412 * normal operation (user would need to press all
413 * buttons on the pad and start moving trackpoint
414 * without touching the pad surface) we assume former.
415 * Even if we are wrong the wost thing that would happen
416 * the cursor would jump but we should not get protocol
420 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
424 * Continue with the standard ALPS protocol handling,
425 * but make sure we won't process it as an interleaved
426 * packet again, which may happen if all buttons are
427 * pressed. To avoid this let's reset the 4th bit which
430 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
434 return PSMOUSE_GOOD_DATA;
437 static void alps_flush_packet(unsigned long data)
439 struct psmouse *psmouse = (struct psmouse *)data;
441 serio_pause_rx(psmouse->ps2dev.serio);
443 if (psmouse->pktcnt == 6) {
446 * We did not any more data in reasonable amount of time.
447 * Validate the last 3 bytes and process as a standard
450 if ((psmouse->packet[3] |
452 psmouse->packet[5]) & 0x80) {
453 dbg("refusing packet %x %x %x "
454 "(suspected interleaved ps/2)\n",
455 psmouse->packet[3], psmouse->packet[4],
458 alps_process_packet(psmouse);
463 serio_continue_rx(psmouse->ps2dev.serio);
466 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
468 struct alps_data *priv = psmouse->private;
469 const struct alps_model_info *model = priv->i;
471 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
472 if (psmouse->pktcnt == 3) {
473 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
475 return PSMOUSE_FULL_PACKET;
477 return PSMOUSE_GOOD_DATA;
480 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
482 if ((model->flags & ALPS_PS2_INTERLEAVED) &&
483 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
484 return alps_handle_interleaved_ps2(psmouse);
487 if (!alps_is_valid_first_byte(model, psmouse->packet[0])) {
488 dbg("refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
489 psmouse->packet[0], model->mask0, model->byte0);
490 return PSMOUSE_BAD_DATA;
493 /* Bytes 2 - 6 should have 0 in the highest bit */
494 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
495 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
496 dbg("refusing packet[%i] = %x\n",
497 psmouse->pktcnt - 1, psmouse->packet[psmouse->pktcnt - 1]);
498 return PSMOUSE_BAD_DATA;
501 if (psmouse->pktcnt == 6) {
502 alps_process_packet(psmouse);
503 return PSMOUSE_FULL_PACKET;
506 return PSMOUSE_GOOD_DATA;
509 static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
511 struct ps2dev *ps2dev = &psmouse->ps2dev;
512 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
513 unsigned char param[4];
517 * First try "E6 report".
518 * ALPS should return 0,0,10 or 0,0,100
521 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
522 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
523 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
524 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
527 param[0] = param[1] = param[2] = 0xff;
528 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
531 dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
533 if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
537 * Now try "E7 report". Allowed responses are in
538 * alps_model_data[].signature
541 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
542 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
543 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
544 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
547 param[0] = param[1] = param[2] = 0xff;
548 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
551 dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
554 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
556 *version = (param[0] << 8) | (param[1] << 4) | i;
559 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
560 if (!memcmp(param, alps_model_data[i].signature,
561 sizeof(alps_model_data[i].signature)))
562 return alps_model_data + i;
568 * For DualPoint devices select the device that should respond to
569 * subsequent commands. It looks like glidepad is behind stickpointer,
570 * I'd thought it would be other way around...
572 static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
574 struct ps2dev *ps2dev = &psmouse->ps2dev;
575 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
577 if (ps2_command(ps2dev, NULL, cmd) ||
578 ps2_command(ps2dev, NULL, cmd) ||
579 ps2_command(ps2dev, NULL, cmd) ||
580 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
583 /* we may get 3 more bytes, just ignore them */
584 ps2_drain(ps2dev, 3, 100);
589 static int alps_absolute_mode(struct psmouse *psmouse)
591 struct ps2dev *ps2dev = &psmouse->ps2dev;
593 /* Try ALPS magic knock - 4 disable before enable */
594 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
595 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
596 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
597 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
598 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
602 * Switch mouse to poll (remote) mode so motion data will not
605 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
608 static int alps_get_status(struct psmouse *psmouse, char *param)
610 struct ps2dev *ps2dev = &psmouse->ps2dev;
612 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
613 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
614 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
615 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
616 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
619 dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
625 * Turn touchpad tapping on or off. The sequences are:
626 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
627 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
628 * My guess that 0xE9 (GetInfo) is here as a sync point.
629 * For models that also have stickpointer (DualPoints) its tapping
630 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
631 * we don't fiddle with it.
633 static int alps_tap_mode(struct psmouse *psmouse, int enable)
635 struct ps2dev *ps2dev = &psmouse->ps2dev;
636 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
637 unsigned char tap_arg = enable ? 0x0A : 0x00;
638 unsigned char param[4];
640 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
641 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
642 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
643 ps2_command(ps2dev, &tap_arg, cmd))
646 if (alps_get_status(psmouse, param))
653 * alps_poll() - poll the touchpad for current motion packet.
656 static int alps_poll(struct psmouse *psmouse)
658 struct alps_data *priv = psmouse->private;
659 unsigned char buf[6];
662 if (priv->i->flags & ALPS_PASS)
663 alps_passthrough_mode(psmouse, true);
665 poll_failed = ps2_command(&psmouse->ps2dev, buf,
666 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
668 if (priv->i->flags & ALPS_PASS)
669 alps_passthrough_mode(psmouse, false);
671 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
674 if ((psmouse->badbyte & 0xc8) == 0x08) {
676 * Poll the track stick ...
678 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
682 memcpy(psmouse->packet, buf, sizeof(buf));
686 static int alps_hw_init(struct psmouse *psmouse)
688 struct alps_data *priv = psmouse->private;
689 const struct alps_model_info *model = priv->i;
691 if (alps_model_hw_init_quirk(psmouse, model)) {
692 alps_model_quirk_enabled = 0;
695 if ((model->flags & ALPS_PASS) &&
696 alps_passthrough_mode(psmouse, true)) {
700 if (alps_tap_mode(psmouse, true)) {
701 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
705 if (alps_absolute_mode(psmouse)) {
706 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
710 if ((model->flags & ALPS_PASS) &&
711 alps_passthrough_mode(psmouse, false)) {
715 /* ALPS needs stream mode, otherwise it won't report any data */
716 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
717 printk(KERN_ERR "alps.c: Failed to enable stream mode\n");
724 static int alps_reconnect(struct psmouse *psmouse)
726 const struct alps_model_info *model;
728 psmouse_reset(psmouse);
730 model = alps_get_model(psmouse, NULL);
734 return alps_hw_init(psmouse);
737 static void alps_disconnect(struct psmouse *psmouse)
739 struct alps_data *priv = psmouse->private;
741 psmouse_reset(psmouse);
742 del_timer_sync(&priv->timer);
743 input_unregister_device(priv->dev2);
747 static void dell_e2_model_init(void *data)
749 struct psmouse *psmouse = (struct psmouse *)(data);
750 struct input_dev *dev = psmouse->dev;
752 __set_bit(BTN_MIDDLE, dev->keybit);
753 __set_bit(REL_WHEEL, dev->relbit);
755 psmouse->pktsize = 4;
756 psmouse->type = PSMOUSE_IMPS;
757 psmouse->disconnect = alps_disconnect;
758 psmouse->reconnect = alps_reconnect;
762 int alps_init(struct psmouse *psmouse)
764 struct alps_data *priv;
765 const struct alps_model_info *model;
766 struct input_dev *dev1 = psmouse->dev, *dev2;
769 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
770 dev2 = input_allocate_device();
775 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
777 psmouse->private = priv;
779 model = alps_get_model(psmouse, &version);
785 if (alps_hw_init(psmouse))
788 if (alps_model_quirk_enabled) {
789 printk(KERN_WARNING "alps.c: Enabled hardware quirk, falling back to psmouse-core\n");
790 alps_model_init_quirk_tbl[alps_model_quirk_enabled-1].alps_model_quirk_init(psmouse);
795 * Undo part of setup done for us by psmouse core since touchpad
796 * is not a relative device.
798 __clear_bit(EV_REL, dev1->evbit);
799 __clear_bit(REL_X, dev1->relbit);
800 __clear_bit(REL_Y, dev1->relbit);
803 * Now set up our capabilities.
805 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
806 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
807 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
808 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
809 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
811 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
812 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
813 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
814 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
816 if (model->flags & ALPS_WHEEL) {
817 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
818 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
821 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
822 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
823 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
826 if (model->flags & ALPS_FOUR_BUTTONS) {
827 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
828 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
829 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
830 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
832 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
835 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
836 dev2->phys = priv->phys;
837 dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
838 dev2->id.bustype = BUS_I8042;
839 dev2->id.vendor = 0x0002;
840 dev2->id.product = PSMOUSE_ALPS;
841 dev2->id.version = 0x0000;
842 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
844 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
845 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
846 dev2->keybit[BIT_WORD(BTN_LEFT)] =
847 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
849 if (input_register_device(priv->dev2))
852 psmouse->protocol_handler = alps_process_byte;
853 psmouse->poll = alps_poll;
854 psmouse->disconnect = alps_disconnect;
855 psmouse->reconnect = alps_reconnect;
856 psmouse->pktsize = 6;
858 /* We are having trouble resyncing ALPS touchpads so disable it for now */
859 psmouse->resync_time = 0;
864 psmouse_reset(psmouse);
865 input_free_device(dev2);
867 psmouse->private = NULL;
871 int alps_detect(struct psmouse *psmouse, bool set_properties)
874 const struct alps_model_info *model;
876 model = alps_get_model(psmouse, &version);
880 if (set_properties) {
881 psmouse->vendor = "ALPS";
882 psmouse->name = model->flags & ALPS_DUALPOINT ?
883 "DualPoint TouchPad" : "GlidePoint";
884 psmouse->model = version;