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"),
132 DMI_MATCH(DMI_PRODUCT_NAME, "ZHAOYANG E47"),
138 int alps_model_quirk_enabled;
139 static void dell_e2_model_init(void *data);
141 /* Magic Sequence to enable Intellimouse Mode on Dell E2 Touchpads*/
143 static int dell_e2_setup_intellimouse_mode(void *data)
145 struct psmouse *psmouse = (struct psmouse *)(data);
146 struct ps2dev *ps2dev = &psmouse->ps2dev;
147 unsigned char param[] = {0, 0, 0};
149 if (!dmi_check_system(dell_quirk_table))
152 if (ps2_command(ps2dev, param, 0x00f5) ||
153 ps2_command(ps2dev, param, 0x00ea) ||
154 ps2_command(ps2dev, param, 0x00ec) ||
155 ps2_command(ps2dev, param, 0x00ec) ||
156 ps2_command(ps2dev, param, 0x00ec) ||
157 ps2_command(ps2dev, param, 0x03e9))
160 dbg("alps:dell_e2_setup: param[0]: %x,"
161 "param[1]: %x, param[2]: %x\n", param[0],
163 /* Check for supported model to continue */
165 if (!((param[0] == 0x88) && (param[1] == 0x07)
166 && ((param[2] == 0x9D) || (param[2] == 0x9B))))
169 if (ps2_command(ps2dev, NULL, 0x00ec) ||
170 ps2_command(ps2dev, NULL, 0x00f0) ||
171 ps2_command(ps2dev, NULL, 0x00f0) ||
172 ps2_command(ps2dev, NULL, 0x00f0) ||
173 ps2_command(ps2dev, NULL, 0x00f3) ||
174 ps2_command(ps2dev, NULL, 0x0028) ||
175 ps2_command(ps2dev, NULL, 0x00f0) ||
176 ps2_command(ps2dev, NULL, 0x00f6) ||
177 ps2_command(ps2dev, NULL, 0x00ea) ||
178 ps2_command(ps2dev, NULL, 0x00f4))
184 static const struct alps_model_quirk alps_model_init_quirk_tbl[] = {
186 { {0x73, 0x02, 0x64}, dell_e2_setup_intellimouse_mode, dell_e2_model_init }
189 static int alps_model_hw_init_quirk(struct psmouse *psmouse,
190 const struct alps_model_info *model)
195 for (i = 0; i < ARRAY_SIZE(alps_model_init_quirk_tbl); i++) {
196 if (!memcmp(model->signature,
197 alps_model_init_quirk_tbl[i].signature,
198 sizeof(alps_model_init_quirk_tbl[i].signature))) {
199 rc = alps_model_init_quirk_tbl[i].alps_model_quirk_hw_init(psmouse);
200 alps_model_quirk_enabled = i + 1;
208 static bool alps_is_valid_first_byte(const struct alps_model_info *model,
211 return (data & model->mask0) == model->byte0;
214 static void alps_report_buttons(struct psmouse *psmouse,
215 struct input_dev *dev1, struct input_dev *dev2,
216 int left, int right, int middle)
218 struct input_dev *dev;
221 * If shared button has already been reported on the
222 * other device (dev2) then this event should be also
223 * sent through that device.
225 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
226 input_report_key(dev, BTN_LEFT, left);
228 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
229 input_report_key(dev, BTN_RIGHT, right);
231 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
232 input_report_key(dev, BTN_MIDDLE, middle);
235 * Sync the _other_ device now, we'll do the first
236 * device later once we report the rest of the events.
241 static void alps_process_packet(struct psmouse *psmouse)
243 struct alps_data *priv = psmouse->private;
244 const struct alps_model_info *model = priv->i;
245 unsigned char *packet = psmouse->packet;
246 struct input_dev *dev = psmouse->dev;
247 struct input_dev *dev2 = priv->dev2;
248 int x, y, z, ges, fin, left, right, middle;
249 int back = 0, forward = 0;
251 if (model->flags & ALPS_OLDPROTO) {
252 left = packet[2] & 0x10;
253 right = packet[2] & 0x08;
255 x = packet[1] | ((packet[0] & 0x07) << 7);
256 y = packet[4] | ((packet[3] & 0x07) << 7);
259 left = packet[3] & 1;
260 right = packet[3] & 2;
261 middle = packet[3] & 4;
262 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
263 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
267 if (model->flags & ALPS_FW_BK_1) {
268 back = packet[0] & 0x10;
269 forward = packet[2] & 4;
272 if (model->flags & ALPS_FW_BK_2) {
273 back = packet[3] & 4;
274 forward = packet[2] & 4;
275 if ((middle = forward && back))
282 if ((model->flags & ALPS_DUALPOINT) && z == 127) {
283 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
284 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
286 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
292 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
294 /* Convert hardware tap to a reasonable Z value */
299 * A "tap and drag" operation is reported by the hardware as a transition
300 * from (!fin && ges) to (fin && ges). This should be translated to the
301 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
303 if (ges && fin && !priv->prev_fin) {
304 input_report_abs(dev, ABS_X, x);
305 input_report_abs(dev, ABS_Y, y);
306 input_report_abs(dev, ABS_PRESSURE, 0);
307 input_report_key(dev, BTN_TOOL_FINGER, 0);
310 priv->prev_fin = fin;
313 input_report_key(dev, BTN_TOUCH, 1);
315 input_report_key(dev, BTN_TOUCH, 0);
318 input_report_abs(dev, ABS_X, x);
319 input_report_abs(dev, ABS_Y, y);
322 input_report_abs(dev, ABS_PRESSURE, z);
323 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
325 if (model->flags & ALPS_WHEEL)
326 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
328 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
329 input_report_key(dev, BTN_FORWARD, forward);
330 input_report_key(dev, BTN_BACK, back);
333 if (model->flags & ALPS_FOUR_BUTTONS) {
334 input_report_key(dev, BTN_0, packet[2] & 4);
335 input_report_key(dev, BTN_1, packet[0] & 0x10);
336 input_report_key(dev, BTN_2, packet[3] & 4);
337 input_report_key(dev, BTN_3, packet[0] & 0x20);
343 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
344 unsigned char packet[],
347 struct alps_data *priv = psmouse->private;
348 struct input_dev *dev2 = priv->dev2;
351 alps_report_buttons(psmouse, dev2, psmouse->dev,
352 packet[0] & 1, packet[0] & 2, packet[0] & 4);
354 input_report_rel(dev2, REL_X,
355 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
356 input_report_rel(dev2, REL_Y,
357 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
362 static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
364 struct alps_data *priv = psmouse->private;
366 if (psmouse->pktcnt < 6)
367 return PSMOUSE_GOOD_DATA;
369 if (psmouse->pktcnt == 6) {
371 * Start a timer to flush the packet if it ends up last
372 * 6-byte packet in the stream. Timer needs to fire
373 * psmouse core times out itself. 20 ms should be enough
374 * to decide if we are getting more data or not.
376 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
377 return PSMOUSE_GOOD_DATA;
380 del_timer(&priv->timer);
382 if (psmouse->packet[6] & 0x80) {
385 * Highest bit is set - that means we either had
386 * complete ALPS packet and this is start of the
387 * next packet or we got garbage.
390 if (((psmouse->packet[3] |
392 psmouse->packet[5]) & 0x80) ||
393 (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) {
394 dbg("refusing packet %x %x %x %x "
395 "(suspected interleaved ps/2)\n",
396 psmouse->packet[3], psmouse->packet[4],
397 psmouse->packet[5], psmouse->packet[6]);
398 return PSMOUSE_BAD_DATA;
401 alps_process_packet(psmouse);
403 /* Continue with the next packet */
404 psmouse->packet[0] = psmouse->packet[6];
410 * High bit is 0 - that means that we indeed got a PS/2
411 * packet in the middle of ALPS packet.
413 * There is also possibility that we got 6-byte ALPS
414 * packet followed by 3-byte packet from trackpoint. We
415 * can not distinguish between these 2 scenarios but
416 * becase the latter is unlikely to happen in course of
417 * normal operation (user would need to press all
418 * buttons on the pad and start moving trackpoint
419 * without touching the pad surface) we assume former.
420 * Even if we are wrong the wost thing that would happen
421 * the cursor would jump but we should not get protocol
425 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
429 * Continue with the standard ALPS protocol handling,
430 * but make sure we won't process it as an interleaved
431 * packet again, which may happen if all buttons are
432 * pressed. To avoid this let's reset the 4th bit which
435 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
439 return PSMOUSE_GOOD_DATA;
442 static void alps_flush_packet(unsigned long data)
444 struct psmouse *psmouse = (struct psmouse *)data;
446 serio_pause_rx(psmouse->ps2dev.serio);
448 if (psmouse->pktcnt == 6) {
451 * We did not any more data in reasonable amount of time.
452 * Validate the last 3 bytes and process as a standard
455 if ((psmouse->packet[3] |
457 psmouse->packet[5]) & 0x80) {
458 dbg("refusing packet %x %x %x "
459 "(suspected interleaved ps/2)\n",
460 psmouse->packet[3], psmouse->packet[4],
463 alps_process_packet(psmouse);
468 serio_continue_rx(psmouse->ps2dev.serio);
471 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
473 struct alps_data *priv = psmouse->private;
474 const struct alps_model_info *model = priv->i;
476 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
477 if (psmouse->pktcnt == 3) {
478 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
480 return PSMOUSE_FULL_PACKET;
482 return PSMOUSE_GOOD_DATA;
485 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
487 if ((model->flags & ALPS_PS2_INTERLEAVED) &&
488 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
489 return alps_handle_interleaved_ps2(psmouse);
492 if (!alps_is_valid_first_byte(model, psmouse->packet[0])) {
493 dbg("refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
494 psmouse->packet[0], model->mask0, model->byte0);
495 return PSMOUSE_BAD_DATA;
498 /* Bytes 2 - 6 should have 0 in the highest bit */
499 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
500 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
501 dbg("refusing packet[%i] = %x\n",
502 psmouse->pktcnt - 1, psmouse->packet[psmouse->pktcnt - 1]);
503 return PSMOUSE_BAD_DATA;
506 if (psmouse->pktcnt == 6) {
507 alps_process_packet(psmouse);
508 return PSMOUSE_FULL_PACKET;
511 return PSMOUSE_GOOD_DATA;
514 static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
516 struct ps2dev *ps2dev = &psmouse->ps2dev;
517 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
518 unsigned char param[4];
522 * First try "E6 report".
523 * ALPS should return 0,0,10 or 0,0,100
526 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
527 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
528 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
529 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
532 param[0] = param[1] = param[2] = 0xff;
533 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
536 dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
538 if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
542 * Now try "E7 report". Allowed responses are in
543 * alps_model_data[].signature
546 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
547 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
548 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
549 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
552 param[0] = param[1] = param[2] = 0xff;
553 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
556 dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
559 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
561 *version = (param[0] << 8) | (param[1] << 4) | i;
564 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
565 if (!memcmp(param, alps_model_data[i].signature,
566 sizeof(alps_model_data[i].signature)))
567 return alps_model_data + i;
573 * For DualPoint devices select the device that should respond to
574 * subsequent commands. It looks like glidepad is behind stickpointer,
575 * I'd thought it would be other way around...
577 static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
579 struct ps2dev *ps2dev = &psmouse->ps2dev;
580 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
582 if (ps2_command(ps2dev, NULL, cmd) ||
583 ps2_command(ps2dev, NULL, cmd) ||
584 ps2_command(ps2dev, NULL, cmd) ||
585 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
588 /* we may get 3 more bytes, just ignore them */
589 ps2_drain(ps2dev, 3, 100);
594 static int alps_absolute_mode(struct psmouse *psmouse)
596 struct ps2dev *ps2dev = &psmouse->ps2dev;
598 /* Try ALPS magic knock - 4 disable before enable */
599 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
600 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
601 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
602 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
603 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
607 * Switch mouse to poll (remote) mode so motion data will not
610 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
613 static int alps_get_status(struct psmouse *psmouse, char *param)
615 struct ps2dev *ps2dev = &psmouse->ps2dev;
617 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
618 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
619 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
620 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
621 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
624 dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
630 * Turn touchpad tapping on or off. The sequences are:
631 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
632 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
633 * My guess that 0xE9 (GetInfo) is here as a sync point.
634 * For models that also have stickpointer (DualPoints) its tapping
635 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
636 * we don't fiddle with it.
638 static int alps_tap_mode(struct psmouse *psmouse, int enable)
640 struct ps2dev *ps2dev = &psmouse->ps2dev;
641 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
642 unsigned char tap_arg = enable ? 0x0A : 0x00;
643 unsigned char param[4];
645 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
646 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
647 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
648 ps2_command(ps2dev, &tap_arg, cmd))
651 if (alps_get_status(psmouse, param))
658 * alps_poll() - poll the touchpad for current motion packet.
661 static int alps_poll(struct psmouse *psmouse)
663 struct alps_data *priv = psmouse->private;
664 unsigned char buf[6];
667 if (priv->i->flags & ALPS_PASS)
668 alps_passthrough_mode(psmouse, true);
670 poll_failed = ps2_command(&psmouse->ps2dev, buf,
671 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
673 if (priv->i->flags & ALPS_PASS)
674 alps_passthrough_mode(psmouse, false);
676 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
679 if ((psmouse->badbyte & 0xc8) == 0x08) {
681 * Poll the track stick ...
683 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
687 memcpy(psmouse->packet, buf, sizeof(buf));
691 static int alps_hw_init(struct psmouse *psmouse)
693 struct alps_data *priv = psmouse->private;
694 const struct alps_model_info *model = priv->i;
696 if (alps_model_hw_init_quirk(psmouse, model)) {
697 alps_model_quirk_enabled = 0;
700 if ((model->flags & ALPS_PASS) &&
701 alps_passthrough_mode(psmouse, true)) {
705 if (alps_tap_mode(psmouse, true)) {
706 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
710 if (alps_absolute_mode(psmouse)) {
711 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
715 if ((model->flags & ALPS_PASS) &&
716 alps_passthrough_mode(psmouse, false)) {
720 /* ALPS needs stream mode, otherwise it won't report any data */
721 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
722 printk(KERN_ERR "alps.c: Failed to enable stream mode\n");
729 static int alps_reconnect(struct psmouse *psmouse)
731 const struct alps_model_info *model;
733 psmouse_reset(psmouse);
735 model = alps_get_model(psmouse, NULL);
739 return alps_hw_init(psmouse);
742 static void alps_disconnect(struct psmouse *psmouse)
744 struct alps_data *priv = psmouse->private;
746 psmouse_reset(psmouse);
747 del_timer_sync(&priv->timer);
748 input_unregister_device(priv->dev2);
752 static void dell_e2_model_init(void *data)
754 struct psmouse *psmouse = (struct psmouse *)(data);
755 struct input_dev *dev = psmouse->dev;
757 __set_bit(BTN_MIDDLE, dev->keybit);
758 __set_bit(REL_WHEEL, dev->relbit);
760 psmouse->pktsize = 4;
761 psmouse->type = PSMOUSE_IMPS;
762 psmouse->disconnect = alps_disconnect;
763 psmouse->reconnect = alps_reconnect;
767 int alps_init(struct psmouse *psmouse)
769 struct alps_data *priv;
770 const struct alps_model_info *model;
771 struct input_dev *dev1 = psmouse->dev, *dev2;
774 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
775 dev2 = input_allocate_device();
780 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
782 psmouse->private = priv;
784 model = alps_get_model(psmouse, &version);
790 if (alps_hw_init(psmouse))
793 if (alps_model_quirk_enabled) {
794 printk(KERN_WARNING "alps.c: Enabled hardware quirk, falling back to psmouse-core\n");
795 alps_model_init_quirk_tbl[alps_model_quirk_enabled-1].alps_model_quirk_init(psmouse);
800 * Undo part of setup done for us by psmouse core since touchpad
801 * is not a relative device.
803 __clear_bit(EV_REL, dev1->evbit);
804 __clear_bit(REL_X, dev1->relbit);
805 __clear_bit(REL_Y, dev1->relbit);
808 * Now set up our capabilities.
810 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
811 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
812 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
813 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
814 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
816 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
817 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
818 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
819 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
821 if (model->flags & ALPS_WHEEL) {
822 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
823 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
826 if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
827 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
828 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
831 if (model->flags & ALPS_FOUR_BUTTONS) {
832 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
833 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
834 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
835 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
837 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
840 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
841 dev2->phys = priv->phys;
842 dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
843 dev2->id.bustype = BUS_I8042;
844 dev2->id.vendor = 0x0002;
845 dev2->id.product = PSMOUSE_ALPS;
846 dev2->id.version = 0x0000;
847 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
849 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
850 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
851 dev2->keybit[BIT_WORD(BTN_LEFT)] =
852 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
854 if (input_register_device(priv->dev2))
857 psmouse->protocol_handler = alps_process_byte;
858 psmouse->poll = alps_poll;
859 psmouse->disconnect = alps_disconnect;
860 psmouse->reconnect = alps_reconnect;
861 psmouse->pktsize = 6;
863 /* We are having trouble resyncing ALPS touchpads so disable it for now */
864 psmouse->resync_time = 0;
869 psmouse_reset(psmouse);
870 input_free_device(dev2);
872 psmouse->private = NULL;
876 int alps_detect(struct psmouse *psmouse, bool set_properties)
879 const struct alps_model_info *model;
881 model = alps_get_model(psmouse, &version);
885 if (set_properties) {
886 psmouse->vendor = "ALPS";
887 psmouse->name = model->flags & ALPS_DUALPOINT ?
888 "DualPoint TouchPad" : "GlidePoint";
889 psmouse->model = version;