Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALPS touchpad PS/2 mouse driver |
| 3 | * |
| 4 | * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au> |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 5 | * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru> |
| 7 | * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 8 | * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * ALPS detection, tap switching and status querying info is taken from |
| 11 | * tpconfig utility (by C. Scott Ananian and Bruce Kall). |
| 12 | * |
| 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. |
| 16 | */ |
| 17 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/input.h> |
| 20 | #include <linux/serio.h> |
| 21 | #include <linux/libps2.h> |
| 22 | |
| 23 | #include "psmouse.h" |
| 24 | #include "alps.h" |
| 25 | |
| 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 |
| 32 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 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 */ |
| 36 | |
| 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 */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 41 | #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with |
| 42 | 6-byte ALPS packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 44 | static const struct alps_model_info alps_model_data[] = { |
Dmitry Torokhov | b75d172 | 2009-04-23 19:25:51 -0700 | [diff] [blame] | 45 | { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */ |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 46 | { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
| 48 | { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 49 | { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
| 51 | { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 59 | { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 63 | /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ |
| 64 | { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, |
| 65 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 66 | { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ |
Thomas Bächler | eb8bff8 | 2010-03-09 20:38:48 -0800 | [diff] [blame] | 67 | { { 0x52, 0x01, 0x14 }, 0xff, 0xff, |
| 68 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* |
| 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. |
| 75 | */ |
| 76 | |
| 77 | /* |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 78 | * PS/2 packet format |
| 79 | * |
| 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 |
| 83 | * |
| 84 | * Note that the device never signals overflow condition. |
| 85 | * |
| 86 | * ALPS absolute Mode - new format |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 87 | * |
| 88 | * byte 0: 1 ? ? ? 1 ? ? ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 90 | * byte 2: 0 x10 x9 x8 x7 ? fin ges |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 91 | * byte 3: 0 y9 y8 y7 1 M R L |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | * byte 4: 0 y6 y5 y4 y3 y2 y1 y0 |
| 93 | * byte 5: 0 z6 z5 z4 z3 z2 z1 z0 |
| 94 | * |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 95 | * Dualpoint device -- interleaved packet format |
| 96 | * |
| 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 |
| 106 | * |
| 107 | * CAPITALS = stick, miniscules = touchpad |
| 108 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | * ?'s can have different meanings on different models, |
| 110 | * such as wheel rotation, extra buttons, stick buttons |
| 111 | * on a dualpoint, etc. |
| 112 | */ |
| 113 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 114 | static bool alps_is_valid_first_byte(const struct alps_model_info *model, |
| 115 | unsigned char data) |
| 116 | { |
| 117 | return (data & model->mask0) == model->byte0; |
| 118 | } |
| 119 | |
| 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) |
| 123 | { |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 124 | struct input_dev *dev; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 125 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 126 | /* |
| 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. |
| 130 | */ |
| 131 | dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1; |
| 132 | input_report_key(dev, BTN_LEFT, left); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 133 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 134 | dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1; |
| 135 | input_report_key(dev, BTN_RIGHT, right); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 136 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 137 | dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1; |
| 138 | input_report_key(dev, BTN_MIDDLE, middle); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 139 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 140 | /* |
| 141 | * Sync the _other_ device now, we'll do the first |
| 142 | * device later once we report the rest of the events. |
| 143 | */ |
| 144 | input_sync(dev2); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 145 | } |
| 146 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 147 | static void alps_process_packet(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 149 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 150 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | unsigned char *packet = psmouse->packet; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 152 | struct input_dev *dev = psmouse->dev; |
| 153 | struct input_dev *dev2 = priv->dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | int x, y, z, ges, fin, left, right, middle; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 155 | int back = 0, forward = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 157 | if (model->flags & ALPS_OLDPROTO) { |
Yotam Medini | d2f4012 | 2006-05-29 23:30:36 -0400 | [diff] [blame] | 158 | left = packet[2] & 0x10; |
| 159 | right = packet[2] & 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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]; |
| 171 | } |
| 172 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 173 | if (model->flags & ALPS_FW_BK_1) { |
Laszlo Kajan | 3c00bb9 | 2008-03-18 00:39:55 -0400 | [diff] [blame] | 174 | back = packet[0] & 0x10; |
| 175 | forward = packet[2] & 4; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 178 | if (model->flags & ALPS_FW_BK_2) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 179 | back = packet[3] & 4; |
| 180 | forward = packet[2] & 4; |
| 181 | if ((middle = forward && back)) |
| 182 | forward = back = 0; |
| 183 | } |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | ges = packet[2] & 1; |
| 186 | fin = packet[2] & 2; |
| 187 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 188 | if ((model->flags & ALPS_DUALPOINT) && z == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); |
| 190 | input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 191 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 192 | alps_report_buttons(psmouse, dev2, dev, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | input_sync(dev2); |
| 195 | return; |
| 196 | } |
| 197 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 198 | alps_report_buttons(psmouse, dev, dev2, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /* Convert hardware tap to a reasonable Z value */ |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 201 | if (ges && !fin) |
| 202 | z = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 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. |
| 208 | */ |
| 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); |
| 215 | } |
| 216 | priv->prev_fin = fin; |
| 217 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 218 | if (z > 30) |
| 219 | input_report_key(dev, BTN_TOUCH, 1); |
| 220 | if (z < 25) |
| 221 | input_report_key(dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | if (z > 0) { |
| 224 | input_report_abs(dev, ABS_X, x); |
| 225 | input_report_abs(dev, ABS_Y, y); |
| 226 | } |
| 227 | |
| 228 | input_report_abs(dev, ABS_PRESSURE, z); |
| 229 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 230 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 231 | if (model->flags & ALPS_WHEEL) |
Vojtech Pavlik | e6c047b | 2005-09-04 01:40:43 -0500 | [diff] [blame] | 232 | input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 234 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 235 | input_report_key(dev, BTN_FORWARD, forward); |
| 236 | input_report_key(dev, BTN_BACK, back); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 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); |
| 244 | } |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | input_sync(dev); |
| 247 | } |
| 248 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 249 | static void alps_report_bare_ps2_packet(struct psmouse *psmouse, |
| 250 | unsigned char packet[], |
| 251 | bool report_buttons) |
| 252 | { |
| 253 | struct alps_data *priv = psmouse->private; |
| 254 | struct input_dev *dev2 = priv->dev2; |
| 255 | |
| 256 | if (report_buttons) |
| 257 | alps_report_buttons(psmouse, dev2, psmouse->dev, |
| 258 | packet[0] & 1, packet[0] & 2, packet[0] & 4); |
| 259 | |
| 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); |
| 264 | |
| 265 | input_sync(dev2); |
| 266 | } |
| 267 | |
| 268 | static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | struct alps_data *priv = psmouse->private; |
| 271 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 272 | if (psmouse->pktcnt < 6) |
| 273 | return PSMOUSE_GOOD_DATA; |
| 274 | |
| 275 | if (psmouse->pktcnt == 6) { |
| 276 | /* |
| 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. |
| 281 | */ |
| 282 | mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20)); |
| 283 | return PSMOUSE_GOOD_DATA; |
| 284 | } |
| 285 | |
| 286 | del_timer(&priv->timer); |
| 287 | |
| 288 | if (psmouse->packet[6] & 0x80) { |
| 289 | |
| 290 | /* |
| 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. |
| 294 | */ |
| 295 | |
| 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; |
| 305 | } |
| 306 | |
| 307 | alps_process_packet(psmouse); |
| 308 | |
| 309 | /* Continue with the next packet */ |
| 310 | psmouse->packet[0] = psmouse->packet[6]; |
| 311 | psmouse->pktcnt = 1; |
| 312 | |
| 313 | } else { |
| 314 | |
| 315 | /* |
| 316 | * High bit is 0 - that means that we indeed got a PS/2 |
| 317 | * packet in the middle of ALPS packet. |
| 318 | * |
| 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. |
| 329 | */ |
| 330 | |
| 331 | alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3], |
| 332 | false); |
| 333 | |
| 334 | /* |
| 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. |
| 340 | */ |
| 341 | psmouse->packet[3] = psmouse->packet[6] & 0xf7; |
| 342 | psmouse->pktcnt = 4; |
| 343 | } |
| 344 | |
| 345 | return PSMOUSE_GOOD_DATA; |
| 346 | } |
| 347 | |
| 348 | static void alps_flush_packet(unsigned long data) |
| 349 | { |
| 350 | struct psmouse *psmouse = (struct psmouse *)data; |
| 351 | |
| 352 | serio_pause_rx(psmouse->ps2dev.serio); |
| 353 | |
| 354 | if (psmouse->pktcnt == 6) { |
| 355 | |
| 356 | /* |
| 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. |
| 360 | */ |
| 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); |
| 370 | } |
| 371 | psmouse->pktcnt = 0; |
| 372 | } |
| 373 | |
| 374 | serio_continue_rx(psmouse->ps2dev.serio); |
| 375 | } |
| 376 | |
| 377 | static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) |
| 378 | { |
| 379 | struct alps_data *priv = psmouse->private; |
| 380 | const struct alps_model_info *model = priv->i; |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ |
| 383 | if (psmouse->pktcnt == 3) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 384 | alps_report_bare_ps2_packet(psmouse, psmouse->packet, |
| 385 | true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | return PSMOUSE_FULL_PACKET; |
| 387 | } |
| 388 | return PSMOUSE_GOOD_DATA; |
| 389 | } |
| 390 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 391 | /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ |
| 392 | |
| 393 | if ((model->flags & ALPS_PS2_INTERLEAVED) && |
| 394 | psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { |
| 395 | return alps_handle_interleaved_ps2(psmouse); |
| 396 | } |
| 397 | |
| 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | /* Bytes 2 - 6 should have 0 in the highest bit */ |
| 405 | if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 && |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 406 | (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { |
| 407 | dbg("refusing packet[%i] = %x\n", |
| 408 | psmouse->pktcnt - 1, psmouse->packet[psmouse->pktcnt - 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | if (psmouse->pktcnt == 6) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 413 | alps_process_packet(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | return PSMOUSE_FULL_PACKET; |
| 415 | } |
| 416 | |
| 417 | return PSMOUSE_GOOD_DATA; |
| 418 | } |
| 419 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 420 | static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 423 | static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | unsigned char param[4]; |
| 425 | int i; |
| 426 | |
| 427 | /* |
| 428 | * First try "E6 report". |
| 429 | * ALPS should return 0,0,10 or 0,0,100 |
| 430 | */ |
| 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; |
| 437 | |
| 438 | param[0] = param[1] = param[2] = 0xff; |
| 439 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 440 | return NULL; |
| 441 | |
| 442 | dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]); |
| 443 | |
| 444 | if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100)) |
| 445 | return NULL; |
| 446 | |
| 447 | /* |
| 448 | * Now try "E7 report". Allowed responses are in |
| 449 | * alps_model_data[].signature |
| 450 | */ |
| 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; |
| 457 | |
| 458 | param[0] = param[1] = param[2] = 0xff; |
| 459 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 460 | return NULL; |
| 461 | |
| 462 | dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]); |
| 463 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 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; |
| 468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 471 | if (!memcmp(param, alps_model_data[i].signature, |
| 472 | sizeof(alps_model_data[i].signature))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | return alps_model_data + i; |
| 474 | |
| 475 | return NULL; |
| 476 | } |
| 477 | |
| 478 | /* |
| 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... |
| 482 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 483 | static int alps_passthrough_mode(struct psmouse *psmouse, bool enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { |
| 485 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; |
| 487 | |
| 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; |
| 493 | |
| 494 | /* we may get 3 more bytes, just ignore them */ |
Dmitry Torokhov | c611763 | 2005-06-01 02:39:51 -0500 | [diff] [blame] | 495 | ps2_drain(ps2dev, 3, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int alps_absolute_mode(struct psmouse *psmouse) |
| 501 | { |
| 502 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 503 | |
| 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; |
| 511 | |
| 512 | /* |
| 513 | * Switch mouse to poll (remote) mode so motion data will not |
| 514 | * get in our way |
| 515 | */ |
| 516 | return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); |
| 517 | } |
| 518 | |
| 519 | static int alps_get_status(struct psmouse *psmouse, char *param) |
| 520 | { |
| 521 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 522 | |
| 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; |
| 529 | |
| 530 | dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]); |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | /* |
| 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. |
| 543 | */ |
| 544 | static int alps_tap_mode(struct psmouse *psmouse, int enable) |
| 545 | { |
| 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]; |
| 550 | |
| 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; |
| 556 | |
| 557 | if (alps_get_status(psmouse, param)) |
| 558 | return -1; |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 563 | /* |
| 564 | * alps_poll() - poll the touchpad for current motion packet. |
| 565 | * Used in resync. |
| 566 | */ |
| 567 | static int alps_poll(struct psmouse *psmouse) |
| 568 | { |
| 569 | struct alps_data *priv = psmouse->private; |
| 570 | unsigned char buf[6]; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 571 | bool poll_failed; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 572 | |
| 573 | if (priv->i->flags & ALPS_PASS) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 574 | alps_passthrough_mode(psmouse, true); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 575 | |
| 576 | poll_failed = ps2_command(&psmouse->ps2dev, buf, |
| 577 | PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; |
| 578 | |
| 579 | if (priv->i->flags & ALPS_PASS) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 580 | alps_passthrough_mode(psmouse, false); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 581 | |
| 582 | if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) |
| 583 | return -1; |
| 584 | |
| 585 | if ((psmouse->badbyte & 0xc8) == 0x08) { |
| 586 | /* |
| 587 | * Poll the track stick ... |
| 588 | */ |
| 589 | if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) |
| 590 | return -1; |
| 591 | } |
| 592 | |
| 593 | memcpy(psmouse->packet, buf, sizeof(buf)); |
| 594 | return 0; |
| 595 | } |
| 596 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 597 | static int alps_hw_init(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
| 599 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 600 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 602 | if ((model->flags & ALPS_PASS) && |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 603 | alps_passthrough_mode(psmouse, true)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 607 | if (alps_tap_mode(psmouse, true)) { |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 608 | printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return -1; |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | if (alps_absolute_mode(psmouse)) { |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 613 | printk(KERN_ERR "alps.c: Failed to enable absolute mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | return -1; |
| 615 | } |
| 616 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 617 | if ((model->flags & ALPS_PASS) && |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 618 | alps_passthrough_mode(psmouse, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 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; |
| 626 | } |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | static int alps_reconnect(struct psmouse *psmouse) |
| 632 | { |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 633 | const struct alps_model_info *model; |
| 634 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 635 | psmouse_reset(psmouse); |
| 636 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 637 | model = alps_get_model(psmouse, NULL); |
| 638 | if (!model) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 639 | return -1; |
| 640 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 641 | return alps_hw_init(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | static void alps_disconnect(struct psmouse *psmouse) |
| 645 | { |
| 646 | struct alps_data *priv = psmouse->private; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | psmouse_reset(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 649 | del_timer_sync(&priv->timer); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 650 | input_unregister_device(priv->dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | kfree(priv); |
| 652 | } |
| 653 | |
| 654 | int alps_init(struct psmouse *psmouse) |
| 655 | { |
| 656 | struct alps_data *priv; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 657 | const struct alps_model_info *model; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 658 | struct input_dev *dev1 = psmouse->dev, *dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | int version; |
| 660 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 661 | priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 662 | dev2 = input_allocate_device(); |
| 663 | if (!priv || !dev2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | goto init_fail; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 665 | |
| 666 | priv->dev2 = dev2; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 667 | setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse); |
| 668 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 669 | psmouse->private = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 671 | model = alps_get_model(psmouse, &version); |
| 672 | if (!model) |
| 673 | goto init_fail; |
| 674 | |
| 675 | priv->i = model; |
| 676 | |
| 677 | if (alps_hw_init(psmouse)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | goto init_fail; |
| 679 | |
Dmitry Torokhov | 7105d2e | 2009-12-11 23:54:54 -0800 | [diff] [blame] | 680 | /* |
| 681 | * Undo part of setup done for us by psmouse core since touchpad |
| 682 | * is not a relative device. |
| 683 | */ |
| 684 | __clear_bit(EV_REL, dev1->evbit); |
| 685 | __clear_bit(REL_X, dev1->relbit); |
| 686 | __clear_bit(REL_Y, dev1->relbit); |
| 687 | |
| 688 | /* |
| 689 | * Now set up our capabilities. |
| 690 | */ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 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); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 694 | dev1->keybit[BIT_WORD(BTN_LEFT)] |= |
| 695 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 697 | dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 702 | if (model->flags & ALPS_WHEEL) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 703 | dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); |
| 704 | dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 707 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 708 | dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); |
| 709 | dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 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); |
| 719 | } |
| 720 | |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 721 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 722 | dev2->phys = priv->phys; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 723 | dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 724 | dev2->id.bustype = BUS_I8042; |
| 725 | dev2->id.vendor = 0x0002; |
| 726 | dev2->id.product = PSMOUSE_ALPS; |
| 727 | dev2->id.version = 0x0000; |
Dmitry Torokhov | 1db3a34 | 2008-03-18 00:29:18 -0400 | [diff] [blame] | 728 | dev2->dev.parent = &psmouse->ps2dev.serio->dev; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 729 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 730 | dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 735 | if (input_register_device(priv->dev2)) |
| 736 | goto init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | psmouse->protocol_handler = alps_process_byte; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 739 | psmouse->poll = alps_poll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | psmouse->disconnect = alps_disconnect; |
| 741 | psmouse->reconnect = alps_reconnect; |
| 742 | psmouse->pktsize = 6; |
| 743 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 744 | /* We are having trouble resyncing ALPS touchpads so disable it for now */ |
| 745 | psmouse->resync_time = 0; |
| 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return 0; |
| 748 | |
| 749 | init_fail: |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 750 | psmouse_reset(psmouse); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 751 | input_free_device(dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | kfree(priv); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 753 | psmouse->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | return -1; |
| 755 | } |
| 756 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 757 | int alps_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
| 759 | int version; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 760 | const struct alps_model_info *model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 762 | model = alps_get_model(psmouse, &version); |
| 763 | if (!model) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | return -1; |
| 765 | |
| 766 | if (set_properties) { |
| 767 | psmouse->vendor = "ALPS"; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 768 | psmouse->name = model->flags & ALPS_DUALPOINT ? |
| 769 | "DualPoint TouchPad" : "GlidePoint"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | psmouse->model = version; |
| 771 | } |
| 772 | return 0; |
| 773 | } |
| 774 | |