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