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 | |
| 18 | #include <linux/input.h> |
| 19 | #include <linux/serio.h> |
| 20 | #include <linux/libps2.h> |
| 21 | |
| 22 | #include "psmouse.h" |
| 23 | #include "alps.h" |
| 24 | |
| 25 | #undef DEBUG |
| 26 | #ifdef DEBUG |
| 27 | #define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg) |
| 28 | #else |
| 29 | #define dbg(format, arg...) do {} while (0) |
| 30 | #endif |
| 31 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 32 | #define ALPS_OLDPROTO 0x01 /* old style input */ |
| 33 | #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */ |
| 34 | #define ALPS_PASS 0x04 /* device has a pass-through port */ |
| 35 | |
| 36 | #define ALPS_WHEEL 0x08 /* hardware wheel present */ |
| 37 | #define ALPS_FW_BK_1 0x10 /* front & back buttons present */ |
| 38 | #define ALPS_FW_BK_2 0x20 /* front & back buttons present */ |
| 39 | #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 40 | #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with |
| 41 | 6-byte ALPS packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 43 | static const struct alps_model_info alps_model_data[] = { |
Dmitry Torokhov | b75d172 | 2009-04-23 19:25:51 -0700 | [diff] [blame] | 44 | { { 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] | 45 | { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
| 47 | { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 48 | { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
| 50 | { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 51 | { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */ |
| 52 | { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ |
| 53 | { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 55 | { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */ |
| 56 | { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 58 | { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ |
| 60 | { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, |
| 61 | { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 62 | /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ |
| 63 | { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, |
| 64 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 65 | { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ |
Thomas Bächler | eb8bff8 | 2010-03-09 20:38:48 -0800 | [diff] [blame^] | 66 | { { 0x52, 0x01, 0x14 }, 0xff, 0xff, |
| 67 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * XXX - this entry is suspicious. First byte has zero lower nibble, |
| 72 | * which is what a normal mouse would report. Also, the value 0x0e |
| 73 | * isn't valid per PS/2 spec. |
| 74 | */ |
| 75 | |
| 76 | /* |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 77 | * PS/2 packet format |
| 78 | * |
| 79 | * byte 0: 0 0 YSGN XSGN 1 M R L |
| 80 | * byte 1: X7 X6 X5 X4 X3 X2 X1 X0 |
| 81 | * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 |
| 82 | * |
| 83 | * Note that the device never signals overflow condition. |
| 84 | * |
| 85 | * ALPS absolute Mode - new format |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 86 | * |
| 87 | * byte 0: 1 ? ? ? 1 ? ? ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 89 | * byte 2: 0 x10 x9 x8 x7 ? fin ges |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 90 | * byte 3: 0 y9 y8 y7 1 M R L |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | * byte 4: 0 y6 y5 y4 y3 y2 y1 y0 |
| 92 | * byte 5: 0 z6 z5 z4 z3 z2 z1 z0 |
| 93 | * |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 94 | * Dualpoint device -- interleaved packet format |
| 95 | * |
| 96 | * byte 0: 1 1 0 0 1 1 1 1 |
| 97 | * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 |
| 98 | * byte 2: 0 x10 x9 x8 x7 0 fin ges |
| 99 | * byte 3: 0 0 YSGN XSGN 1 1 1 1 |
| 100 | * byte 4: X7 X6 X5 X4 X3 X2 X1 X0 |
| 101 | * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 |
| 102 | * byte 6: 0 y9 y8 y7 1 m r l |
| 103 | * byte 7: 0 y6 y5 y4 y3 y2 y1 y0 |
| 104 | * byte 8: 0 z6 z5 z4 z3 z2 z1 z0 |
| 105 | * |
| 106 | * CAPITALS = stick, miniscules = touchpad |
| 107 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * ?'s can have different meanings on different models, |
| 109 | * such as wheel rotation, extra buttons, stick buttons |
| 110 | * on a dualpoint, etc. |
| 111 | */ |
| 112 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 113 | static bool alps_is_valid_first_byte(const struct alps_model_info *model, |
| 114 | unsigned char data) |
| 115 | { |
| 116 | return (data & model->mask0) == model->byte0; |
| 117 | } |
| 118 | |
| 119 | static void alps_report_buttons(struct psmouse *psmouse, |
| 120 | struct input_dev *dev1, struct input_dev *dev2, |
| 121 | int left, int right, int middle) |
| 122 | { |
| 123 | struct alps_data *priv = psmouse->private; |
| 124 | const struct alps_model_info *model = priv->i; |
| 125 | |
| 126 | if (model->flags & ALPS_PS2_INTERLEAVED) { |
| 127 | struct input_dev *dev; |
| 128 | |
| 129 | /* |
| 130 | * If shared button has already been reported on the |
| 131 | * other device (dev2) then this event should be also |
| 132 | * sent through that device. |
| 133 | */ |
| 134 | dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1; |
| 135 | input_report_key(dev, BTN_LEFT, left); |
| 136 | |
| 137 | dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1; |
| 138 | input_report_key(dev, BTN_RIGHT, right); |
| 139 | |
| 140 | dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1; |
| 141 | input_report_key(dev, BTN_MIDDLE, middle); |
| 142 | |
| 143 | /* |
| 144 | * Sync the _other_ device now, we'll do the first |
| 145 | * device later once we report the rest of the events. |
| 146 | */ |
| 147 | input_sync(dev2); |
| 148 | } else { |
| 149 | /* |
| 150 | * For devices with non-interleaved packets we know what |
| 151 | * device buttons belong to so we can simply report them. |
| 152 | */ |
| 153 | input_report_key(dev1, BTN_LEFT, left); |
| 154 | input_report_key(dev1, BTN_RIGHT, right); |
| 155 | input_report_key(dev1, BTN_MIDDLE, middle); |
| 156 | } |
| 157 | } |
| 158 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 159 | static void alps_process_packet(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 162 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | unsigned char *packet = psmouse->packet; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 164 | struct input_dev *dev = psmouse->dev; |
| 165 | struct input_dev *dev2 = priv->dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | int x, y, z, ges, fin, left, right, middle; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 167 | int back = 0, forward = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 169 | if (model->flags & ALPS_OLDPROTO) { |
Yotam Medini | d2f4012 | 2006-05-29 23:30:36 -0400 | [diff] [blame] | 170 | left = packet[2] & 0x10; |
| 171 | right = packet[2] & 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | middle = 0; |
| 173 | x = packet[1] | ((packet[0] & 0x07) << 7); |
| 174 | y = packet[4] | ((packet[3] & 0x07) << 7); |
| 175 | z = packet[5]; |
| 176 | } else { |
| 177 | left = packet[3] & 1; |
| 178 | right = packet[3] & 2; |
| 179 | middle = packet[3] & 4; |
| 180 | x = packet[1] | ((packet[2] & 0x78) << (7 - 3)); |
| 181 | y = packet[4] | ((packet[3] & 0x70) << (7 - 4)); |
| 182 | z = packet[5]; |
| 183 | } |
| 184 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 185 | if (model->flags & ALPS_FW_BK_1) { |
Laszlo Kajan | 3c00bb9 | 2008-03-18 00:39:55 -0400 | [diff] [blame] | 186 | back = packet[0] & 0x10; |
| 187 | forward = packet[2] & 4; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 190 | if (model->flags & ALPS_FW_BK_2) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 191 | back = packet[3] & 4; |
| 192 | forward = packet[2] & 4; |
| 193 | if ((middle = forward && back)) |
| 194 | forward = back = 0; |
| 195 | } |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | ges = packet[2] & 1; |
| 198 | fin = packet[2] & 2; |
| 199 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 200 | if ((model->flags & ALPS_DUALPOINT) && z == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); |
| 202 | input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 203 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 204 | alps_report_buttons(psmouse, dev2, dev, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | input_sync(dev2); |
| 207 | return; |
| 208 | } |
| 209 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 210 | alps_report_buttons(psmouse, dev, dev2, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* Convert hardware tap to a reasonable Z value */ |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 213 | if (ges && !fin) |
| 214 | z = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | * A "tap and drag" operation is reported by the hardware as a transition |
| 218 | * from (!fin && ges) to (fin && ges). This should be translated to the |
| 219 | * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually. |
| 220 | */ |
| 221 | if (ges && fin && !priv->prev_fin) { |
| 222 | input_report_abs(dev, ABS_X, x); |
| 223 | input_report_abs(dev, ABS_Y, y); |
| 224 | input_report_abs(dev, ABS_PRESSURE, 0); |
| 225 | input_report_key(dev, BTN_TOOL_FINGER, 0); |
| 226 | input_sync(dev); |
| 227 | } |
| 228 | priv->prev_fin = fin; |
| 229 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 230 | if (z > 30) |
| 231 | input_report_key(dev, BTN_TOUCH, 1); |
| 232 | if (z < 25) |
| 233 | input_report_key(dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | if (z > 0) { |
| 236 | input_report_abs(dev, ABS_X, x); |
| 237 | input_report_abs(dev, ABS_Y, y); |
| 238 | } |
| 239 | |
| 240 | input_report_abs(dev, ABS_PRESSURE, z); |
| 241 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 242 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 243 | if (model->flags & ALPS_WHEEL) |
Vojtech Pavlik | e6c047b | 2005-09-04 01:40:43 -0500 | [diff] [blame] | 244 | 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] | 245 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 246 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 247 | input_report_key(dev, BTN_FORWARD, forward); |
| 248 | input_report_key(dev, BTN_BACK, back); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 251 | if (model->flags & ALPS_FOUR_BUTTONS) { |
| 252 | input_report_key(dev, BTN_0, packet[2] & 4); |
| 253 | input_report_key(dev, BTN_1, packet[0] & 0x10); |
| 254 | input_report_key(dev, BTN_2, packet[3] & 4); |
| 255 | input_report_key(dev, BTN_3, packet[0] & 0x20); |
| 256 | } |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | input_sync(dev); |
| 259 | } |
| 260 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 261 | static void alps_report_bare_ps2_packet(struct psmouse *psmouse, |
| 262 | unsigned char packet[], |
| 263 | bool report_buttons) |
| 264 | { |
| 265 | struct alps_data *priv = psmouse->private; |
| 266 | struct input_dev *dev2 = priv->dev2; |
| 267 | |
| 268 | if (report_buttons) |
| 269 | alps_report_buttons(psmouse, dev2, psmouse->dev, |
| 270 | packet[0] & 1, packet[0] & 2, packet[0] & 4); |
| 271 | |
| 272 | input_report_rel(dev2, REL_X, |
| 273 | packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); |
| 274 | input_report_rel(dev2, REL_Y, |
| 275 | packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); |
| 276 | |
| 277 | input_sync(dev2); |
| 278 | } |
| 279 | |
| 280 | static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | struct alps_data *priv = psmouse->private; |
| 283 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 284 | if (psmouse->pktcnt < 6) |
| 285 | return PSMOUSE_GOOD_DATA; |
| 286 | |
| 287 | if (psmouse->pktcnt == 6) { |
| 288 | /* |
| 289 | * Start a timer to flush the packet if it ends up last |
| 290 | * 6-byte packet in the stream. Timer needs to fire |
| 291 | * psmouse core times out itself. 20 ms should be enough |
| 292 | * to decide if we are getting more data or not. |
| 293 | */ |
| 294 | mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20)); |
| 295 | return PSMOUSE_GOOD_DATA; |
| 296 | } |
| 297 | |
| 298 | del_timer(&priv->timer); |
| 299 | |
| 300 | if (psmouse->packet[6] & 0x80) { |
| 301 | |
| 302 | /* |
| 303 | * Highest bit is set - that means we either had |
| 304 | * complete ALPS packet and this is start of the |
| 305 | * next packet or we got garbage. |
| 306 | */ |
| 307 | |
| 308 | if (((psmouse->packet[3] | |
| 309 | psmouse->packet[4] | |
| 310 | psmouse->packet[5]) & 0x80) || |
| 311 | (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) { |
| 312 | dbg("refusing packet %x %x %x %x " |
| 313 | "(suspected interleaved ps/2)\n", |
| 314 | psmouse->packet[3], psmouse->packet[4], |
| 315 | psmouse->packet[5], psmouse->packet[6]); |
| 316 | return PSMOUSE_BAD_DATA; |
| 317 | } |
| 318 | |
| 319 | alps_process_packet(psmouse); |
| 320 | |
| 321 | /* Continue with the next packet */ |
| 322 | psmouse->packet[0] = psmouse->packet[6]; |
| 323 | psmouse->pktcnt = 1; |
| 324 | |
| 325 | } else { |
| 326 | |
| 327 | /* |
| 328 | * High bit is 0 - that means that we indeed got a PS/2 |
| 329 | * packet in the middle of ALPS packet. |
| 330 | * |
| 331 | * There is also possibility that we got 6-byte ALPS |
| 332 | * packet followed by 3-byte packet from trackpoint. We |
| 333 | * can not distinguish between these 2 scenarios but |
| 334 | * becase the latter is unlikely to happen in course of |
| 335 | * normal operation (user would need to press all |
| 336 | * buttons on the pad and start moving trackpoint |
| 337 | * without touching the pad surface) we assume former. |
| 338 | * Even if we are wrong the wost thing that would happen |
| 339 | * the cursor would jump but we should not get protocol |
| 340 | * desynchronization. |
| 341 | */ |
| 342 | |
| 343 | alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3], |
| 344 | false); |
| 345 | |
| 346 | /* |
| 347 | * Continue with the standard ALPS protocol handling, |
| 348 | * but make sure we won't process it as an interleaved |
| 349 | * packet again, which may happen if all buttons are |
| 350 | * pressed. To avoid this let's reset the 4th bit which |
| 351 | * is normally 1. |
| 352 | */ |
| 353 | psmouse->packet[3] = psmouse->packet[6] & 0xf7; |
| 354 | psmouse->pktcnt = 4; |
| 355 | } |
| 356 | |
| 357 | return PSMOUSE_GOOD_DATA; |
| 358 | } |
| 359 | |
| 360 | static void alps_flush_packet(unsigned long data) |
| 361 | { |
| 362 | struct psmouse *psmouse = (struct psmouse *)data; |
| 363 | |
| 364 | serio_pause_rx(psmouse->ps2dev.serio); |
| 365 | |
| 366 | if (psmouse->pktcnt == 6) { |
| 367 | |
| 368 | /* |
| 369 | * We did not any more data in reasonable amount of time. |
| 370 | * Validate the last 3 bytes and process as a standard |
| 371 | * ALPS packet. |
| 372 | */ |
| 373 | if ((psmouse->packet[3] | |
| 374 | psmouse->packet[4] | |
| 375 | psmouse->packet[5]) & 0x80) { |
| 376 | dbg("refusing packet %x %x %x " |
| 377 | "(suspected interleaved ps/2)\n", |
| 378 | psmouse->packet[3], psmouse->packet[4], |
| 379 | psmouse->packet[5]); |
| 380 | } else { |
| 381 | alps_process_packet(psmouse); |
| 382 | } |
| 383 | psmouse->pktcnt = 0; |
| 384 | } |
| 385 | |
| 386 | serio_continue_rx(psmouse->ps2dev.serio); |
| 387 | } |
| 388 | |
| 389 | static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) |
| 390 | { |
| 391 | struct alps_data *priv = psmouse->private; |
| 392 | const struct alps_model_info *model = priv->i; |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ |
| 395 | if (psmouse->pktcnt == 3) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 396 | alps_report_bare_ps2_packet(psmouse, psmouse->packet, |
| 397 | true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return PSMOUSE_FULL_PACKET; |
| 399 | } |
| 400 | return PSMOUSE_GOOD_DATA; |
| 401 | } |
| 402 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 403 | /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ |
| 404 | |
| 405 | if ((model->flags & ALPS_PS2_INTERLEAVED) && |
| 406 | psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { |
| 407 | return alps_handle_interleaved_ps2(psmouse); |
| 408 | } |
| 409 | |
| 410 | if (!alps_is_valid_first_byte(model, psmouse->packet[0])) { |
| 411 | dbg("refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n", |
| 412 | psmouse->packet[0], model->mask0, model->byte0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | /* Bytes 2 - 6 should have 0 in the highest bit */ |
| 417 | if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 && |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 418 | (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { |
| 419 | dbg("refusing packet[%i] = %x\n", |
| 420 | psmouse->pktcnt - 1, psmouse->packet[psmouse->pktcnt - 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | if (psmouse->pktcnt == 6) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 425 | alps_process_packet(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return PSMOUSE_FULL_PACKET; |
| 427 | } |
| 428 | |
| 429 | return PSMOUSE_GOOD_DATA; |
| 430 | } |
| 431 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 432 | 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] | 433 | { |
| 434 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 435 | 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] | 436 | unsigned char param[4]; |
| 437 | int i; |
| 438 | |
| 439 | /* |
| 440 | * First try "E6 report". |
| 441 | * ALPS should return 0,0,10 or 0,0,100 |
| 442 | */ |
| 443 | param[0] = 0; |
| 444 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || |
| 445 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 446 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 447 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) |
| 448 | return NULL; |
| 449 | |
| 450 | param[0] = param[1] = param[2] = 0xff; |
| 451 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 452 | return NULL; |
| 453 | |
| 454 | dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]); |
| 455 | |
| 456 | if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100)) |
| 457 | return NULL; |
| 458 | |
| 459 | /* |
| 460 | * Now try "E7 report". Allowed responses are in |
| 461 | * alps_model_data[].signature |
| 462 | */ |
| 463 | param[0] = 0; |
| 464 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || |
| 465 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 466 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 467 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21)) |
| 468 | return NULL; |
| 469 | |
| 470 | param[0] = param[1] = param[2] = 0xff; |
| 471 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 472 | return NULL; |
| 473 | |
| 474 | dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]); |
| 475 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 476 | if (version) { |
| 477 | for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++) |
| 478 | /* empty */; |
| 479 | *version = (param[0] << 8) | (param[1] << 4) | i; |
| 480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 483 | if (!memcmp(param, alps_model_data[i].signature, |
| 484 | sizeof(alps_model_data[i].signature))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | return alps_model_data + i; |
| 486 | |
| 487 | return NULL; |
| 488 | } |
| 489 | |
| 490 | /* |
| 491 | * For DualPoint devices select the device that should respond to |
| 492 | * subsequent commands. It looks like glidepad is behind stickpointer, |
| 493 | * I'd thought it would be other way around... |
| 494 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 495 | static int alps_passthrough_mode(struct psmouse *psmouse, bool enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
| 497 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; |
| 499 | |
| 500 | if (ps2_command(ps2dev, NULL, cmd) || |
| 501 | ps2_command(ps2dev, NULL, cmd) || |
| 502 | ps2_command(ps2dev, NULL, cmd) || |
| 503 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 504 | return -1; |
| 505 | |
| 506 | /* we may get 3 more bytes, just ignore them */ |
Dmitry Torokhov | c611763 | 2005-06-01 02:39:51 -0500 | [diff] [blame] | 507 | ps2_drain(ps2dev, 3, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static int alps_absolute_mode(struct psmouse *psmouse) |
| 513 | { |
| 514 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 515 | |
| 516 | /* Try ALPS magic knock - 4 disable before enable */ |
| 517 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 518 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 519 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 520 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 521 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) |
| 522 | return -1; |
| 523 | |
| 524 | /* |
| 525 | * Switch mouse to poll (remote) mode so motion data will not |
| 526 | * get in our way |
| 527 | */ |
| 528 | return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); |
| 529 | } |
| 530 | |
| 531 | static int alps_get_status(struct psmouse *psmouse, char *param) |
| 532 | { |
| 533 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 534 | |
| 535 | /* Get status: 0xF5 0xF5 0xF5 0xE9 */ |
| 536 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 537 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 538 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 539 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 540 | return -1; |
| 541 | |
| 542 | dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Turn touchpad tapping on or off. The sequences are: |
| 549 | * 0xE9 0xF5 0xF5 0xF3 0x0A to enable, |
| 550 | * 0xE9 0xF5 0xF5 0xE8 0x00 to disable. |
| 551 | * My guess that 0xE9 (GetInfo) is here as a sync point. |
| 552 | * For models that also have stickpointer (DualPoints) its tapping |
| 553 | * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but |
| 554 | * we don't fiddle with it. |
| 555 | */ |
| 556 | static int alps_tap_mode(struct psmouse *psmouse, int enable) |
| 557 | { |
| 558 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 559 | int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES; |
| 560 | unsigned char tap_arg = enable ? 0x0A : 0x00; |
| 561 | unsigned char param[4]; |
| 562 | |
| 563 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) || |
| 564 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 565 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 566 | ps2_command(ps2dev, &tap_arg, cmd)) |
| 567 | return -1; |
| 568 | |
| 569 | if (alps_get_status(psmouse, param)) |
| 570 | return -1; |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Dmitry Torokhov | f0d5c6f | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 575 | /* |
| 576 | * alps_poll() - poll the touchpad for current motion packet. |
| 577 | * Used in resync. |
| 578 | */ |
| 579 | static int alps_poll(struct psmouse *psmouse) |
| 580 | { |
| 581 | struct alps_data *priv = psmouse->private; |
| 582 | unsigned char buf[6]; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 583 | bool poll_failed; |
Dmitry Torokhov | f0d5c6f | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 584 | |
| 585 | if (priv->i->flags & ALPS_PASS) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 586 | alps_passthrough_mode(psmouse, true); |
Dmitry Torokhov | f0d5c6f | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 587 | |
| 588 | poll_failed = ps2_command(&psmouse->ps2dev, buf, |
| 589 | PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; |
| 590 | |
| 591 | if (priv->i->flags & ALPS_PASS) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 592 | alps_passthrough_mode(psmouse, false); |
Dmitry Torokhov | f0d5c6f | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 593 | |
| 594 | if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) |
| 595 | return -1; |
| 596 | |
| 597 | if ((psmouse->badbyte & 0xc8) == 0x08) { |
| 598 | /* |
| 599 | * Poll the track stick ... |
| 600 | */ |
| 601 | if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) |
| 602 | return -1; |
| 603 | } |
| 604 | |
| 605 | memcpy(psmouse->packet, buf, sizeof(buf)); |
| 606 | return 0; |
| 607 | } |
| 608 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 609 | static int alps_hw_init(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 612 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 614 | if ((model->flags & ALPS_PASS) && |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 615 | alps_passthrough_mode(psmouse, true)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 619 | if (alps_tap_mode(psmouse, true)) { |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 620 | printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | return -1; |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | if (alps_absolute_mode(psmouse)) { |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 625 | printk(KERN_ERR "alps.c: Failed to enable absolute mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return -1; |
| 627 | } |
| 628 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 629 | if ((model->flags & ALPS_PASS) && |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 630 | alps_passthrough_mode(psmouse, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 632 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 634 | /* ALPS needs stream mode, otherwise it won't report any data */ |
| 635 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) { |
| 636 | printk(KERN_ERR "alps.c: Failed to enable stream mode\n"); |
| 637 | return -1; |
| 638 | } |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int alps_reconnect(struct psmouse *psmouse) |
| 644 | { |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 645 | const struct alps_model_info *model; |
| 646 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 647 | psmouse_reset(psmouse); |
| 648 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 649 | model = alps_get_model(psmouse, NULL); |
| 650 | if (!model) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 651 | return -1; |
| 652 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 653 | return alps_hw_init(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void alps_disconnect(struct psmouse *psmouse) |
| 657 | { |
| 658 | struct alps_data *priv = psmouse->private; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | psmouse_reset(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 661 | del_timer_sync(&priv->timer); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 662 | input_unregister_device(priv->dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | kfree(priv); |
| 664 | } |
| 665 | |
| 666 | int alps_init(struct psmouse *psmouse) |
| 667 | { |
| 668 | struct alps_data *priv; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 669 | const struct alps_model_info *model; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 670 | struct input_dev *dev1 = psmouse->dev, *dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | int version; |
| 672 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 673 | priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 674 | dev2 = input_allocate_device(); |
| 675 | if (!priv || !dev2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | goto init_fail; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 677 | |
| 678 | priv->dev2 = dev2; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 679 | setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse); |
| 680 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 681 | psmouse->private = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 683 | model = alps_get_model(psmouse, &version); |
| 684 | if (!model) |
| 685 | goto init_fail; |
| 686 | |
| 687 | priv->i = model; |
| 688 | |
| 689 | if (alps_hw_init(psmouse)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | goto init_fail; |
| 691 | |
Dmitry Torokhov | 7105d2e | 2009-12-11 23:54:54 -0800 | [diff] [blame] | 692 | /* |
| 693 | * Undo part of setup done for us by psmouse core since touchpad |
| 694 | * is not a relative device. |
| 695 | */ |
| 696 | __clear_bit(EV_REL, dev1->evbit); |
| 697 | __clear_bit(REL_X, dev1->relbit); |
| 698 | __clear_bit(REL_Y, dev1->relbit); |
| 699 | |
| 700 | /* |
| 701 | * Now set up our capabilities. |
| 702 | */ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 703 | dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY); |
| 704 | dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH); |
| 705 | dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 706 | dev1->keybit[BIT_WORD(BTN_LEFT)] |= |
| 707 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 709 | dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 710 | input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); |
| 711 | input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0); |
| 712 | input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 714 | if (model->flags & ALPS_WHEEL) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 715 | dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); |
| 716 | dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 719 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 720 | dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); |
| 721 | dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 724 | if (model->flags & ALPS_FOUR_BUTTONS) { |
| 725 | dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0); |
| 726 | dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1); |
| 727 | dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2); |
| 728 | dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3); |
| 729 | } else { |
| 730 | dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE); |
| 731 | } |
| 732 | |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 733 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 734 | dev2->phys = priv->phys; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 735 | dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 736 | dev2->id.bustype = BUS_I8042; |
| 737 | dev2->id.vendor = 0x0002; |
| 738 | dev2->id.product = PSMOUSE_ALPS; |
| 739 | dev2->id.version = 0x0000; |
Dmitry Torokhov | 1db3a34 | 2008-03-18 00:29:18 -0400 | [diff] [blame] | 740 | dev2->dev.parent = &psmouse->ps2dev.serio->dev; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 741 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 742 | dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 743 | dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
| 744 | dev2->keybit[BIT_WORD(BTN_LEFT)] = |
| 745 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 747 | if (input_register_device(priv->dev2)) |
| 748 | goto init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | psmouse->protocol_handler = alps_process_byte; |
Dmitry Torokhov | f0d5c6f | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 751 | psmouse->poll = alps_poll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | psmouse->disconnect = alps_disconnect; |
| 753 | psmouse->reconnect = alps_reconnect; |
| 754 | psmouse->pktsize = 6; |
| 755 | |
Dmitry Torokhov | f0d5c6f | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 756 | /* We are having trouble resyncing ALPS touchpads so disable it for now */ |
| 757 | psmouse->resync_time = 0; |
| 758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | return 0; |
| 760 | |
| 761 | init_fail: |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 762 | psmouse_reset(psmouse); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 763 | input_free_device(dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | kfree(priv); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 765 | psmouse->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | return -1; |
| 767 | } |
| 768 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 769 | int alps_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
| 771 | int version; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 772 | const struct alps_model_info *model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 774 | model = alps_get_model(psmouse, &version); |
| 775 | if (!model) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return -1; |
| 777 | |
| 778 | if (set_properties) { |
| 779 | psmouse->vendor = "ALPS"; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 780 | psmouse->name = model->flags & ALPS_DUALPOINT ? |
| 781 | "DualPoint TouchPad" : "GlidePoint"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | psmouse->model = version; |
| 783 | } |
| 784 | return 0; |
| 785 | } |
| 786 | |