/[linux-patches]/genpatches-2.6/tags/3.2-6/2600_Input-ALPS-synaptics-touchpad.patch
Gentoo

Contents of /genpatches-2.6/tags/3.2-6/2600_Input-ALPS-synaptics-touchpad.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2076 - (show annotations) (download)
Thu Feb 2 11:46:07 2012 UTC (2 years, 2 months ago) by mpagano
File size: 38270 byte(s)
3.2-6 release
1 Only in linux-3.2/Documentation/input: alps.txt
2 diff -ur linux-3.2.old/drivers/input/mouse/alps.c linux-3.2/drivers/input/mouse/alps.c
3 --- linux-3.2.old/drivers/input/mouse/alps.c 2012-01-04 17:55:44.000000000 -0600
4 +++ linux-3.2/drivers/input/mouse/alps.c 2012-01-05 18:53:42.231275880 -0600
5 @@ -17,13 +17,63 @@
6
7 #include <linux/slab.h>
8 #include <linux/input.h>
9 +#include <linux/input/mt.h>
10 #include <linux/serio.h>
11 #include <linux/libps2.h>
12
13 #include "psmouse.h"
14 #include "alps.h"
15
16 -#define ALPS_OLDPROTO 0x01 /* old style input */
17 +/*
18 + * Definitions for ALPS version 3 and 4 command mode protocol
19 + */
20 +#define ALPS_V3_X_MAX 2000
21 +#define ALPS_V3_Y_MAX 1400
22 +
23 +#define ALPS_BITMAP_X_BITS 15
24 +#define ALPS_BITMAP_Y_BITS 11
25 +
26 +#define ALPS_CMD_NIBBLE_10 0x01f2
27 +
28 +static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
29 + { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
30 + { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
31 + { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
32 + { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
33 + { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
34 + { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
35 + { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
36 + { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
37 + { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
38 + { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
39 + { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
40 + { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
41 + { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
42 + { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
43 + { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
44 + { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
45 +};
46 +
47 +static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
48 + { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
49 + { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
50 + { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
51 + { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
52 + { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
53 + { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
54 + { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
55 + { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
56 + { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
57 + { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
58 + { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
59 + { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
60 + { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
61 + { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
62 + { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
63 + { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
64 +};
65 +
66 +
67 #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
68 #define ALPS_PASS 0x04 /* device has a pass-through port */
69
70 @@ -35,30 +85,33 @@
71 6-byte ALPS packet */
72
73 static const struct alps_model_info alps_model_data[] = {
74 - { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
75 - { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
76 - { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
77 - { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
78 - { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */
79 - { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
80 - { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
81 - { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
82 - { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
83 - { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
84 - { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
85 - { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
86 - { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
87 - { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
88 - { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
89 - { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
90 - { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
91 - { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
92 + { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
93 + { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
94 + { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
95 + { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
96 + { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
97 + { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
98 + { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
99 + { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
100 + { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
101 + { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
102 + { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
103 + { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
104 + { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
105 + { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
106 + { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
107 + { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
108 + { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
109 + { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
110 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
111 - { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf,
112 + { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
113 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
114 - { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
115 - { { 0x52, 0x01, 0x14 }, 0xff, 0xff,
116 - ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
117 + { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
118 + { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
119 + ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
120 + { { 0x73, 0x02, 0x64 }, 0x9b, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
121 + { { 0x73, 0x02, 0x64 }, 0x9d, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT },
122 + { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
123 };
124
125 /*
126 @@ -67,42 +120,7 @@
127 * isn't valid per PS/2 spec.
128 */
129
130 -/*
131 - * PS/2 packet format
132 - *
133 - * byte 0: 0 0 YSGN XSGN 1 M R L
134 - * byte 1: X7 X6 X5 X4 X3 X2 X1 X0
135 - * byte 2: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
136 - *
137 - * Note that the device never signals overflow condition.
138 - *
139 - * ALPS absolute Mode - new format
140 - *
141 - * byte 0: 1 ? ? ? 1 ? ? ?
142 - * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
143 - * byte 2: 0 x10 x9 x8 x7 ? fin ges
144 - * byte 3: 0 y9 y8 y7 1 M R L
145 - * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
146 - * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
147 - *
148 - * Dualpoint device -- interleaved packet format
149 - *
150 - * byte 0: 1 1 0 0 1 1 1 1
151 - * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
152 - * byte 2: 0 x10 x9 x8 x7 0 fin ges
153 - * byte 3: 0 0 YSGN XSGN 1 1 1 1
154 - * byte 4: X7 X6 X5 X4 X3 X2 X1 X0
155 - * byte 5: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
156 - * byte 6: 0 y9 y8 y7 1 m r l
157 - * byte 7: 0 y6 y5 y4 y3 y2 y1 y0
158 - * byte 8: 0 z6 z5 z4 z3 z2 z1 z0
159 - *
160 - * CAPITALS = stick, miniscules = touchpad
161 - *
162 - * ?'s can have different meanings on different models,
163 - * such as wheel rotation, extra buttons, stick buttons
164 - * on a dualpoint, etc.
165 - */
166 +/* Packet formats are described in Documentation/input/alps.txt */
167
168 static bool alps_is_valid_first_byte(const struct alps_model_info *model,
169 unsigned char data)
170 @@ -137,7 +155,7 @@
171 input_sync(dev2);
172 }
173
174 -static void alps_process_packet(struct psmouse *psmouse)
175 +static void alps_process_packet_v1_v2(struct psmouse *psmouse)
176 {
177 struct alps_data *priv = psmouse->private;
178 const struct alps_model_info *model = priv->i;
179 @@ -147,7 +165,7 @@
180 int x, y, z, ges, fin, left, right, middle;
181 int back = 0, forward = 0;
182
183 - if (model->flags & ALPS_OLDPROTO) {
184 + if (model->proto_version == ALPS_PROTO_V1) {
185 left = packet[2] & 0x10;
186 right = packet[2] & 0x08;
187 middle = 0;
188 @@ -239,6 +257,403 @@
189 input_sync(dev);
190 }
191
192 +/*
193 + * Process bitmap data from v3 and v4 protocols. Returns the number of
194 + * fingers detected. A return value of 0 means at least one of the
195 + * bitmaps was empty.
196 + *
197 + * The bitmaps don't have enough data to track fingers, so this function
198 + * only generates points representing a bounding box of all contacts.
199 + * These points are returned in x1, y1, x2, and y2 when the return value
200 + * is greater than 0.
201 + */
202 +static int alps_process_bitmap(unsigned int x_map, unsigned int y_map,
203 + int *x1, int *y1, int *x2, int *y2)
204 +{
205 + struct alps_bitmap_point {
206 + int start_bit;
207 + int num_bits;
208 + };
209 +
210 + int fingers_x = 0, fingers_y = 0, fingers;
211 + int i, bit, prev_bit;
212 + struct alps_bitmap_point x_low = {0,}, x_high = {0,};
213 + struct alps_bitmap_point y_low = {0,}, y_high = {0,};
214 + struct alps_bitmap_point *point;
215 +
216 + if (!x_map || !y_map)
217 + return 0;
218 +
219 + *x1 = *y1 = *x2 = *y2 = 0;
220 +
221 + prev_bit = 0;
222 + point = &x_low;
223 + for (i = 0; x_map != 0; i++, x_map >>= 1) {
224 + bit = x_map & 1;
225 + if (bit) {
226 + if (!prev_bit) {
227 + point->start_bit = i;
228 + fingers_x++;
229 + }
230 + point->num_bits++;
231 + } else {
232 + if (prev_bit)
233 + point = &x_high;
234 + else
235 + point->num_bits = 0;
236 + }
237 + prev_bit = bit;
238 + }
239 +
240 + /*
241 + * y bitmap is reversed for what we need (lower positions are in
242 + * higher bits), so we process from the top end.
243 + */
244 + y_map = y_map << (sizeof(y_map) * BITS_PER_BYTE - ALPS_BITMAP_Y_BITS);
245 + prev_bit = 0;
246 + point = &y_low;
247 + for (i = 0; y_map != 0; i++, y_map <<= 1) {
248 + bit = y_map & (1 << (sizeof(y_map) * BITS_PER_BYTE - 1));
249 + if (bit) {
250 + if (!prev_bit) {
251 + point->start_bit = i;
252 + fingers_y++;
253 + }
254 + point->num_bits++;
255 + } else {
256 + if (prev_bit)
257 + point = &y_high;
258 + else
259 + point->num_bits = 0;
260 + }
261 + prev_bit = bit;
262 + }
263 +
264 + /*
265 + * Fingers can overlap, so we use the maximum count of fingers
266 + * on either axis as the finger count.
267 + */
268 + fingers = max(fingers_x, fingers_y);
269 +
270 + /*
271 + * If total fingers is > 1 but either axis reports only a single
272 + * contact, we have overlapping or adjacent fingers. For the
273 + * purposes of creating a bounding box, divide the single contact
274 + * (roughly) equally between the two points.
275 + */
276 + if (fingers > 1) {
277 + if (fingers_x == 1) {
278 + i = x_low.num_bits / 2;
279 + x_low.num_bits = x_low.num_bits - i;
280 + x_high.start_bit = x_low.start_bit + i;
281 + x_high.num_bits = max(i, 1);
282 + } else if (fingers_y == 1) {
283 + i = y_low.num_bits / 2;
284 + y_low.num_bits = y_low.num_bits - i;
285 + y_high.start_bit = y_low.start_bit + i;
286 + y_high.num_bits = max(i, 1);
287 + }
288 + }
289 +
290 + *x1 = (ALPS_V3_X_MAX * (2 * x_low.start_bit + x_low.num_bits - 1)) /
291 + (2 * (ALPS_BITMAP_X_BITS - 1));
292 + *y1 = (ALPS_V3_Y_MAX * (2 * y_low.start_bit + y_low.num_bits - 1)) /
293 + (2 * (ALPS_BITMAP_Y_BITS - 1));
294 +
295 + if (fingers > 1) {
296 + *x2 = (ALPS_V3_X_MAX * (2 * x_high.start_bit + x_high.num_bits - 1)) /
297 + (2 * (ALPS_BITMAP_X_BITS - 1));
298 + *y2 = (ALPS_V3_Y_MAX * (2 * y_high.start_bit + y_high.num_bits - 1)) /
299 + (2 * (ALPS_BITMAP_Y_BITS - 1));
300 + }
301 +
302 + return fingers;
303 +}
304 +
305 +static void alps_set_slot(struct input_dev *dev, int slot, bool active,
306 + int x, int y)
307 +{
308 + input_mt_slot(dev, slot);
309 + input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
310 + if (active) {
311 + input_report_abs(dev, ABS_MT_POSITION_X, x);
312 + input_report_abs(dev, ABS_MT_POSITION_Y, y);
313 + }
314 +}
315 +
316 +static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers,
317 + int x1, int y1, int x2, int y2)
318 +{
319 + alps_set_slot(dev, 0, num_fingers != 0, x1, y1);
320 + alps_set_slot(dev, 1, num_fingers == 2, x2, y2);
321 +}
322 +
323 +static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
324 +{
325 + struct alps_data *priv = psmouse->private;
326 + unsigned char *packet = psmouse->packet;
327 + struct input_dev *dev = priv->dev2;
328 + int x, y, z, left, right, middle;
329 +
330 + /* Sanity check packet */
331 + if (!(packet[0] & 0x40)) {
332 + psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
333 + return;
334 + }
335 +
336 + /*
337 + * There's a special packet that seems to indicate the end
338 + * of a stream of trackstick data. Filter these out.
339 + */
340 + if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
341 + return;
342 +
343 + x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
344 + y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
345 + z = (packet[4] & 0x7c) >> 2;
346 +
347 + /*
348 + * The x and y values tend to be quite large, and when used
349 + * alone the trackstick is difficult to use. Scale them down
350 + * to compensate.
351 + */
352 + x /= 8;
353 + y /= 8;
354 +
355 + input_report_rel(dev, REL_X, x);
356 + input_report_rel(dev, REL_Y, -y);
357 +
358 + /*
359 + * Most ALPS models report the trackstick buttons in the touchpad
360 + * packets, but a few report them here. No reliable way has been
361 + * found to differentiate between the models upfront, so we enable
362 + * the quirk in response to seeing a button press in the trackstick
363 + * packet.
364 + */
365 + left = packet[3] & 0x01;
366 + right = packet[3] & 0x02;
367 + middle = packet[3] & 0x04;
368 +
369 + if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
370 + (left || right || middle))
371 + priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
372 +
373 + if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
374 + input_report_key(dev, BTN_LEFT, left);
375 + input_report_key(dev, BTN_RIGHT, right);
376 + input_report_key(dev, BTN_MIDDLE, middle);
377 + }
378 +
379 + input_sync(dev);
380 + return;
381 +}
382 +
383 +static void alps_process_touchpad_packet_v3(struct psmouse *psmouse)
384 +{
385 + struct alps_data *priv = psmouse->private;
386 + unsigned char *packet = psmouse->packet;
387 + struct input_dev *dev = psmouse->dev;
388 + struct input_dev *dev2 = priv->dev2;
389 + int x, y, z;
390 + int left, right, middle;
391 + int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
392 + int fingers = 0, bmap_fingers;
393 + unsigned int x_bitmap, y_bitmap;
394 +
395 + /*
396 + * There's no single feature of touchpad position and bitmap packets
397 + * that can be used to distinguish between them. We rely on the fact
398 + * that a bitmap packet should always follow a position packet with
399 + * bit 6 of packet[4] set.
400 + */
401 + if (priv->multi_packet) {
402 + /*
403 + * Sometimes a position packet will indicate a multi-packet
404 + * sequence, but then what follows is another position
405 + * packet. Check for this, and when it happens process the
406 + * position packet as usual.
407 + */
408 + if (packet[0] & 0x40) {
409 + fingers = (packet[5] & 0x3) + 1;
410 + x_bitmap = ((packet[4] & 0x7e) << 8) |
411 + ((packet[1] & 0x7f) << 2) |
412 + ((packet[0] & 0x30) >> 4);
413 + y_bitmap = ((packet[3] & 0x70) << 4) |
414 + ((packet[2] & 0x7f) << 1) |
415 + (packet[4] & 0x01);
416 +
417 + bmap_fingers = alps_process_bitmap(x_bitmap, y_bitmap,
418 + &x1, &y1, &x2, &y2);
419 +
420 + /*
421 + * We shouldn't report more than one finger if
422 + * we don't have two coordinates.
423 + */
424 + if (fingers > 1 && bmap_fingers < 2)
425 + fingers = bmap_fingers;
426 +
427 + /* Now process position packet */
428 + packet = priv->multi_data;
429 + } else {
430 + priv->multi_packet = 0;
431 + }
432 + }
433 +
434 + /*
435 + * Bit 6 of byte 0 is not usually set in position packets. The only
436 + * times it seems to be set is in situations where the data is
437 + * suspect anyway, e.g. a palm resting flat on the touchpad. Given
438 + * this combined with the fact that this bit is useful for filtering
439 + * out misidentified bitmap packets, we reject anything with this
440 + * bit set.
441 + */
442 + if (packet[0] & 0x40)
443 + return;
444 +
445 + if (!priv->multi_packet && (packet[4] & 0x40)) {
446 + priv->multi_packet = 1;
447 + memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
448 + return;
449 + }
450 +
451 + priv->multi_packet = 0;
452 +
453 + left = packet[3] & 0x01;
454 + right = packet[3] & 0x02;
455 + middle = packet[3] & 0x04;
456 +
457 + x = ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) |
458 + ((packet[0] & 0x30) >> 4);
459 + y = ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f);
460 + z = packet[5] & 0x7f;
461 +
462 + /*
463 + * Sometimes the hardware sends a single packet with z = 0
464 + * in the middle of a stream. Real releases generate packets
465 + * with x, y, and z all zero, so these seem to be flukes.
466 + * Ignore them.
467 + */
468 + if (x && y && !z)
469 + return;
470 +
471 + /*
472 + * If we don't have MT data or the bitmaps were empty, we have
473 + * to rely on ST data.
474 + */
475 + if (!fingers) {
476 + x1 = x;
477 + y1 = y;
478 + fingers = z > 0 ? 1 : 0;
479 + }
480 +
481 + if (z >= 64)
482 + input_report_key(dev, BTN_TOUCH, 1);
483 + else
484 + input_report_key(dev, BTN_TOUCH, 0);
485 +
486 + alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
487 +
488 + input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
489 + input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
490 + input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
491 + input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
492 +
493 + input_report_key(dev, BTN_LEFT, left);
494 + input_report_key(dev, BTN_RIGHT, right);
495 + input_report_key(dev, BTN_MIDDLE, middle);
496 +
497 + if (z > 0) {
498 + input_report_abs(dev, ABS_X, x);
499 + input_report_abs(dev, ABS_Y, y);
500 + }
501 + input_report_abs(dev, ABS_PRESSURE, z);
502 +
503 + input_sync(dev);
504 +
505 + if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
506 + left = packet[3] & 0x10;
507 + right = packet[3] & 0x20;
508 + middle = packet[3] & 0x40;
509 +
510 + input_report_key(dev2, BTN_LEFT, left);
511 + input_report_key(dev2, BTN_RIGHT, right);
512 + input_report_key(dev2, BTN_MIDDLE, middle);
513 + input_sync(dev2);
514 + }
515 +}
516 +
517 +static void alps_process_packet_v3(struct psmouse *psmouse)
518 +{
519 + unsigned char *packet = psmouse->packet;
520 +
521 + /*
522 + * v3 protocol packets come in three types, two representing
523 + * touchpad data and one representing trackstick data.
524 + * Trackstick packets seem to be distinguished by always
525 + * having 0x3f in the last byte. This value has never been
526 + * observed in the last byte of either of the other types
527 + * of packets.
528 + */
529 + if (packet[5] == 0x3f) {
530 + alps_process_trackstick_packet_v3(psmouse);
531 + return;
532 + }
533 +
534 + alps_process_touchpad_packet_v3(psmouse);
535 +}
536 +
537 +static void alps_process_packet_v4(struct psmouse *psmouse)
538 +{
539 + unsigned char *packet = psmouse->packet;
540 + struct input_dev *dev = psmouse->dev;
541 + int x, y, z;
542 + int left, right;
543 +
544 + left = packet[4] & 0x01;
545 + right = packet[4] & 0x02;
546 +
547 + x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
548 + ((packet[0] & 0x30) >> 4);
549 + y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
550 + z = packet[5] & 0x7f;
551 +
552 + if (z >= 64)
553 + input_report_key(dev, BTN_TOUCH, 1);
554 + else
555 + input_report_key(dev, BTN_TOUCH, 0);
556 +
557 + if (z > 0) {
558 + input_report_abs(dev, ABS_X, x);
559 + input_report_abs(dev, ABS_Y, y);
560 + }
561 + input_report_abs(dev, ABS_PRESSURE, z);
562 +
563 + input_report_key(dev, BTN_TOOL_FINGER, z > 0);
564 + input_report_key(dev, BTN_LEFT, left);
565 + input_report_key(dev, BTN_RIGHT, right);
566 +
567 + input_sync(dev);
568 +}
569 +
570 +static void alps_process_packet(struct psmouse *psmouse)
571 +{
572 + struct alps_data *priv = psmouse->private;
573 + const struct alps_model_info *model = priv->i;
574 +
575 + switch (model->proto_version) {
576 + case ALPS_PROTO_V1:
577 + case ALPS_PROTO_V2:
578 + alps_process_packet_v1_v2(psmouse);
579 + break;
580 + case ALPS_PROTO_V3:
581 + alps_process_packet_v3(psmouse);
582 + break;
583 + case ALPS_PROTO_V4:
584 + alps_process_packet_v4(psmouse);
585 + break;
586 + }
587 +}
588 +
589 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
590 unsigned char packet[],
591 bool report_buttons)
592 @@ -344,7 +759,7 @@
593
594 serio_pause_rx(psmouse->ps2dev.serio);
595
596 - if (psmouse->pktcnt == 6) {
597 + if (psmouse->pktcnt == psmouse->pktsize) {
598
599 /*
600 * We did not any more data in reasonable amount of time.
601 @@ -395,8 +810,8 @@
602 return PSMOUSE_BAD_DATA;
603 }
604
605 - /* Bytes 2 - 6 should have 0 in the highest bit */
606 - if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
607 + /* Bytes 2 - pktsize should have 0 in the highest bit */
608 + if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
609 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
610 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
611 psmouse->pktcnt - 1,
612 @@ -404,7 +819,7 @@
613 return PSMOUSE_BAD_DATA;
614 }
615
616 - if (psmouse->pktcnt == 6) {
617 + if (psmouse->pktcnt == psmouse->pktsize) {
618 alps_process_packet(psmouse);
619 return PSMOUSE_FULL_PACKET;
620 }
621 @@ -412,11 +827,127 @@
622 return PSMOUSE_GOOD_DATA;
623 }
624
625 +static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
626 +{
627 + struct ps2dev *ps2dev = &psmouse->ps2dev;
628 + struct alps_data *priv = psmouse->private;
629 + int command;
630 + unsigned char *param;
631 + unsigned char dummy[4];
632 +
633 + BUG_ON(nibble > 0xf);
634 +
635 + command = priv->nibble_commands[nibble].command;
636 + param = (command & 0x0f00) ?
637 + dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
638 +
639 + if (ps2_command(ps2dev, param, command))
640 + return -1;
641 +
642 + return 0;
643 +}
644 +
645 +static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
646 +{
647 + struct ps2dev *ps2dev = &psmouse->ps2dev;
648 + struct alps_data *priv = psmouse->private;
649 + int i, nibble;
650 +
651 + if (ps2_command(ps2dev, NULL, priv->addr_command))
652 + return -1;
653 +
654 + for (i = 12; i >= 0; i -= 4) {
655 + nibble = (addr >> i) & 0xf;
656 + if (alps_command_mode_send_nibble(psmouse, nibble))
657 + return -1;
658 + }
659 +
660 + return 0;
661 +}
662 +
663 +static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
664 +{
665 + struct ps2dev *ps2dev = &psmouse->ps2dev;
666 + unsigned char param[4];
667 +
668 + if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
669 + return -1;
670 +
671 + /*
672 + * The address being read is returned in the first two bytes
673 + * of the result. Check that this address matches the expected
674 + * address.
675 + */
676 + if (addr != ((param[0] << 8) | param[1]))
677 + return -1;
678 +
679 + return param[2];
680 +}
681 +
682 +static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
683 +{
684 + if (alps_command_mode_set_addr(psmouse, addr))
685 + return -1;
686 + return __alps_command_mode_read_reg(psmouse, addr);
687 +}
688 +
689 +static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
690 +{
691 + if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
692 + return -1;
693 + if (alps_command_mode_send_nibble(psmouse, value & 0xf))
694 + return -1;
695 + return 0;
696 +}
697 +
698 +static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
699 + u8 value)
700 +{
701 + if (alps_command_mode_set_addr(psmouse, addr))
702 + return -1;
703 + return __alps_command_mode_write_reg(psmouse, value);
704 +}
705 +
706 +static int alps_enter_command_mode(struct psmouse *psmouse,
707 + unsigned char *resp)
708 +{
709 + unsigned char param[4];
710 + struct ps2dev *ps2dev = &psmouse->ps2dev;
711 +
712 + if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
713 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
714 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
715 + ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
716 + psmouse_err(psmouse, "failed to enter command mode\n");
717 + return -1;
718 + }
719 +
720 + if (param[0] != 0x88 && param[1] != 0x07) {
721 + psmouse_dbg(psmouse,
722 + "unknown response while entering command mode: %2.2x %2.2x %2.2x\n",
723 + param[0], param[1], param[2]);
724 + return -1;
725 + }
726 +
727 + if (resp)
728 + *resp = param[2];
729 + return 0;
730 +}
731 +
732 +static inline int alps_exit_command_mode(struct psmouse *psmouse)
733 +{
734 + struct ps2dev *ps2dev = &psmouse->ps2dev;
735 + if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
736 + return -1;
737 + return 0;
738 +}
739 +
740 static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
741 {
742 struct ps2dev *ps2dev = &psmouse->ps2dev;
743 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
744 unsigned char param[4];
745 + const struct alps_model_info *model = NULL;
746 int i;
747
748 /*
749 @@ -464,12 +995,41 @@
750 *version = (param[0] << 8) | (param[1] << 4) | i;
751 }
752
753 - for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
754 + for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
755 if (!memcmp(param, alps_model_data[i].signature,
756 - sizeof(alps_model_data[i].signature)))
757 - return alps_model_data + i;
758 + sizeof(alps_model_data[i].signature))) {
759 + model = alps_model_data + i;
760 + break;
761 + }
762 + }
763 +
764 + if (model && model->proto_version > ALPS_PROTO_V2) {
765 + /*
766 + * Need to check command mode response to identify
767 + * model
768 + */
769 + model = NULL;
770 + if (alps_enter_command_mode(psmouse, param)) {
771 + psmouse_warn(psmouse,
772 + "touchpad failed to enter command mode\n");
773 + } else {
774 + for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
775 + if (alps_model_data[i].proto_version > ALPS_PROTO_V2 &&
776 + alps_model_data[i].command_mode_resp == param[0]) {
777 + model = alps_model_data + i;
778 + break;
779 + }
780 + }
781 + alps_exit_command_mode(psmouse);
782 +
783 + if (!model)
784 + psmouse_dbg(psmouse,
785 + "Unknown command mode response %2.2x\n",
786 + param[0]);
787 + }
788 + }
789
790 - return NULL;
791 + return model;
792 }
793
794 /*
795 @@ -477,7 +1037,7 @@
796 * subsequent commands. It looks like glidepad is behind stickpointer,
797 * I'd thought it would be other way around...
798 */
799 -static int alps_passthrough_mode(struct psmouse *psmouse, bool enable)
800 +static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
801 {
802 struct ps2dev *ps2dev = &psmouse->ps2dev;
803 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
804 @@ -494,7 +1054,7 @@
805 return 0;
806 }
807
808 -static int alps_absolute_mode(struct psmouse *psmouse)
809 +static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
810 {
811 struct ps2dev *ps2dev = &psmouse->ps2dev;
812
813 @@ -565,17 +1125,17 @@
814 static int alps_poll(struct psmouse *psmouse)
815 {
816 struct alps_data *priv = psmouse->private;
817 - unsigned char buf[6];
818 + unsigned char buf[sizeof(psmouse->packet)];
819 bool poll_failed;
820
821 if (priv->i->flags & ALPS_PASS)
822 - alps_passthrough_mode(psmouse, true);
823 + alps_passthrough_mode_v2(psmouse, true);
824
825 poll_failed = ps2_command(&psmouse->ps2dev, buf,
826 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
827
828 if (priv->i->flags & ALPS_PASS)
829 - alps_passthrough_mode(psmouse, false);
830 + alps_passthrough_mode_v2(psmouse, false);
831
832 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
833 return -1;
834 @@ -592,13 +1152,13 @@
835 return 0;
836 }
837
838 -static int alps_hw_init(struct psmouse *psmouse)
839 +static int alps_hw_init_v1_v2(struct psmouse *psmouse)
840 {
841 struct alps_data *priv = psmouse->private;
842 const struct alps_model_info *model = priv->i;
843
844 if ((model->flags & ALPS_PASS) &&
845 - alps_passthrough_mode(psmouse, true)) {
846 + alps_passthrough_mode_v2(psmouse, true)) {
847 return -1;
848 }
849
850 @@ -607,13 +1167,13 @@
851 return -1;
852 }
853
854 - if (alps_absolute_mode(psmouse)) {
855 + if (alps_absolute_mode_v1_v2(psmouse)) {
856 psmouse_err(psmouse, "Failed to enable absolute mode\n");
857 return -1;
858 }
859
860 if ((model->flags & ALPS_PASS) &&
861 - alps_passthrough_mode(psmouse, false)) {
862 + alps_passthrough_mode_v2(psmouse, false)) {
863 return -1;
864 }
865
866 @@ -626,6 +1186,297 @@
867 return 0;
868 }
869
870 +/*
871 + * Enable or disable passthrough mode to the trackstick. Must be in
872 + * command mode when calling this function.
873 + */
874 +static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable)
875 +{
876 + int reg_val;
877 +
878 + reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
879 + if (reg_val == -1)
880 + return -1;
881 +
882 + if (enable)
883 + reg_val |= 0x01;
884 + else
885 + reg_val &= ~0x01;
886 +
887 + if (__alps_command_mode_write_reg(psmouse, reg_val))
888 + return -1;
889 +
890 + return 0;
891 +}
892 +
893 +/* Must be in command mode when calling this function */
894 +static int alps_absolute_mode_v3(struct psmouse *psmouse)
895 +{
896 + int reg_val;
897 +
898 + reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
899 + if (reg_val == -1)
900 + return -1;
901 +
902 + reg_val |= 0x06;
903 + if (__alps_command_mode_write_reg(psmouse, reg_val))
904 + return -1;
905 +
906 + return 0;
907 +}
908 +
909 +static int alps_hw_init_v3(struct psmouse *psmouse)
910 +{
911 + struct alps_data *priv = psmouse->private;
912 + struct ps2dev *ps2dev = &psmouse->ps2dev;
913 + int reg_val;
914 + unsigned char param[4];
915 +
916 + priv->nibble_commands = alps_v3_nibble_commands;
917 + priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
918 +
919 + if (alps_enter_command_mode(psmouse, NULL))
920 + goto error;
921 +
922 + /* Check for trackstick */
923 + reg_val = alps_command_mode_read_reg(psmouse, 0x0008);
924 + if (reg_val == -1)
925 + goto error;
926 + if (reg_val & 0x80) {
927 + if (alps_passthrough_mode_v3(psmouse, true))
928 + goto error;
929 + if (alps_exit_command_mode(psmouse))
930 + goto error;
931 +
932 + /*
933 + * E7 report for the trackstick
934 + *
935 + * There have been reports of failures to seem to trace back
936 + * to the above trackstick check failing. When these occur
937 + * this E7 report fails, so when that happens we continue
938 + * with the assumption that there isn't a trackstick after
939 + * all.
940 + */
941 + param[0] = 0x64;
942 + if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
943 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
944 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
945 + ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
946 + psmouse_warn(psmouse, "trackstick E7 report failed\n");
947 + } else {
948 + psmouse_dbg(psmouse,
949 + "trackstick E7 report: %2.2x %2.2x %2.2x\n",
950 + param[0], param[1], param[2]);
951 +
952 + /*
953 + * Not sure what this does, but it is absolutely
954 + * essential. Without it, the touchpad does not
955 + * work at all and the trackstick just emits normal
956 + * PS/2 packets.
957 + */
958 + if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
959 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
960 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
961 + alps_command_mode_send_nibble(psmouse, 0x9) ||
962 + alps_command_mode_send_nibble(psmouse, 0x4)) {
963 + psmouse_err(psmouse,
964 + "Error sending magic E6 sequence\n");
965 + goto error_passthrough;
966 + }
967 + }
968 +
969 + if (alps_enter_command_mode(psmouse, NULL))
970 + goto error_passthrough;
971 + if (alps_passthrough_mode_v3(psmouse, false))
972 + goto error;
973 + }
974 +
975 + if (alps_absolute_mode_v3(psmouse)) {
976 + psmouse_err(psmouse, "Failed to enter absolute mode\n");
977 + goto error;
978 + }
979 +
980 + reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
981 + if (reg_val == -1)
982 + goto error;
983 + if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
984 + goto error;
985 +
986 + reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
987 + if (reg_val == -1)
988 + goto error;
989 + if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
990 + goto error;
991 +
992 + if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
993 + goto error;
994 + if (__alps_command_mode_write_reg(psmouse, 0x04))
995 + goto error;
996 +
997 + if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
998 + goto error;
999 + if (__alps_command_mode_write_reg(psmouse, 0x03))
1000 + goto error;
1001 +
1002 + if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1003 + goto error;
1004 + if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1005 + goto error;
1006 +
1007 + if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1008 + goto error;
1009 + if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1010 + goto error;
1011 +
1012 + /*
1013 + * This ensures the trackstick packets are in the format
1014 + * supported by this driver. If bit 1 isn't set the packet
1015 + * format is different.
1016 + */
1017 + if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82))
1018 + goto error;
1019 +
1020 + alps_exit_command_mode(psmouse);
1021 +
1022 + /* Set rate and enable data reporting */
1023 + param[0] = 0x64;
1024 + if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1025 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1026 + psmouse_err(psmouse, "Failed to enable data reporting\n");
1027 + return -1;
1028 + }
1029 +
1030 + return 0;
1031 +
1032 +error_passthrough:
1033 + /* Something failed while in passthrough mode, so try to get out */
1034 + if (!alps_enter_command_mode(psmouse, NULL))
1035 + alps_passthrough_mode_v3(psmouse, false);
1036 +error:
1037 + /*
1038 + * Leaving the touchpad in command mode will essentially render
1039 + * it unusable until the machine reboots, so exit it here just
1040 + * to be safe
1041 + */
1042 + alps_exit_command_mode(psmouse);
1043 + return -1;
1044 +}
1045 +
1046 +/* Must be in command mode when calling this function */
1047 +static int alps_absolute_mode_v4(struct psmouse *psmouse)
1048 +{
1049 + int reg_val;
1050 +
1051 + reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1052 + if (reg_val == -1)
1053 + return -1;
1054 +
1055 + reg_val |= 0x02;
1056 + if (__alps_command_mode_write_reg(psmouse, reg_val))
1057 + return -1;
1058 +
1059 + return 0;
1060 +}
1061 +
1062 +static int alps_hw_init_v4(struct psmouse *psmouse)
1063 +{
1064 + struct alps_data *priv = psmouse->private;
1065 + struct ps2dev *ps2dev = &psmouse->ps2dev;
1066 + unsigned char param[4];
1067 +
1068 + priv->nibble_commands = alps_v4_nibble_commands;
1069 + priv->addr_command = PSMOUSE_CMD_DISABLE;
1070 +
1071 + if (alps_enter_command_mode(psmouse, NULL))
1072 + goto error;
1073 +
1074 + if (alps_absolute_mode_v4(psmouse)) {
1075 + psmouse_err(psmouse, "Failed to enter absolute mode\n");
1076 + goto error;
1077 + }
1078 +
1079 + if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1080 + goto error;
1081 +
1082 + if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1083 + goto error;
1084 +
1085 + if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1086 + goto error;
1087 +
1088 + if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1089 + goto error;
1090 +
1091 + if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1092 + goto error;
1093 +
1094 + if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1095 + goto error;
1096 +
1097 + if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1098 + goto error;
1099 +
1100 + if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1101 + goto error;
1102 +
1103 + alps_exit_command_mode(psmouse);
1104 +
1105 + /*
1106 + * This sequence changes the output from a 9-byte to an
1107 + * 8-byte format. All the same data seems to be present,
1108 + * just in a more compact format.
1109 + */
1110 + param[0] = 0xc8;
1111 + param[1] = 0x64;
1112 + param[2] = 0x50;
1113 + if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1114 + ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1115 + ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1116 + ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1117 + return -1;
1118 +
1119 + /* Set rate and enable data reporting */
1120 + param[0] = 0x64;
1121 + if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1122 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1123 + psmouse_err(psmouse, "Failed to enable data reporting\n");
1124 + return -1;
1125 + }
1126 +
1127 + return 0;
1128 +
1129 +error:
1130 + /*
1131 + * Leaving the touchpad in command mode will essentially render
1132 + * it unusable until the machine reboots, so exit it here just
1133 + * to be safe
1134 + */
1135 + alps_exit_command_mode(psmouse);
1136 + return -1;
1137 +}
1138 +
1139 +static int alps_hw_init(struct psmouse *psmouse)
1140 +{
1141 + struct alps_data *priv = psmouse->private;
1142 + const struct alps_model_info *model = priv->i;
1143 + int ret = -1;
1144 +
1145 + switch (model->proto_version) {
1146 + case ALPS_PROTO_V1:
1147 + case ALPS_PROTO_V2:
1148 + ret = alps_hw_init_v1_v2(psmouse);
1149 + break;
1150 + case ALPS_PROTO_V3:
1151 + ret = alps_hw_init_v3(psmouse);
1152 + break;
1153 + case ALPS_PROTO_V4:
1154 + ret = alps_hw_init_v4(psmouse);
1155 + break;
1156 + }
1157 +
1158 + return ret;
1159 +}
1160 +
1161 static int alps_reconnect(struct psmouse *psmouse)
1162 {
1163 const struct alps_model_info *model;
1164 @@ -666,6 +1517,8 @@
1165
1166 psmouse->private = priv;
1167
1168 + psmouse_reset(psmouse);
1169 +
1170 model = alps_get_model(psmouse, &version);
1171 if (!model)
1172 goto init_fail;
1173 @@ -693,8 +1546,29 @@
1174 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
1175
1176 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
1177 - input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1178 - input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1179 +
1180 + switch (model->proto_version) {
1181 + case ALPS_PROTO_V1:
1182 + case ALPS_PROTO_V2:
1183 + input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1184 + input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1185 + break;
1186 + case ALPS_PROTO_V3:
1187 + set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
1188 + input_mt_init_slots(dev1, 2);
1189 + input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0);
1190 + input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0);
1191 +
1192 + set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
1193 + set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
1194 + set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
1195 + /* fall through */
1196 + case ALPS_PROTO_V4:
1197 + input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
1198 + input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
1199 + break;
1200 + }
1201 +
1202 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
1203
1204 if (model->flags & ALPS_WHEEL) {
1205 @@ -737,7 +1611,7 @@
1206 psmouse->poll = alps_poll;
1207 psmouse->disconnect = alps_disconnect;
1208 psmouse->reconnect = alps_reconnect;
1209 - psmouse->pktsize = 6;
1210 + psmouse->pktsize = model->proto_version == ALPS_PROTO_V4 ? 8 : 6;
1211
1212 /* We are having trouble resyncing ALPS touchpads so disable it for now */
1213 psmouse->resync_time = 0;
1214 diff -ur linux-3.2.old/drivers/input/mouse/alps.h linux-3.2/drivers/input/mouse/alps.h
1215 --- linux-3.2.old/drivers/input/mouse/alps.h 2012-01-04 17:55:44.000000000 -0600
1216 +++ linux-3.2/drivers/input/mouse/alps.h 2012-01-05 18:53:42.235275879 -0600
1217 @@ -12,20 +12,39 @@
1218 #ifndef _ALPS_H
1219 #define _ALPS_H
1220
1221 +#define ALPS_PROTO_V1 0
1222 +#define ALPS_PROTO_V2 1
1223 +#define ALPS_PROTO_V3 2
1224 +#define ALPS_PROTO_V4 3
1225 +
1226 struct alps_model_info {
1227 unsigned char signature[3];
1228 + unsigned char command_mode_resp; /* v3/v4 only */
1229 + unsigned char proto_version;
1230 unsigned char byte0, mask0;
1231 unsigned char flags;
1232 };
1233
1234 +struct alps_nibble_commands {
1235 + int command;
1236 + unsigned char data;
1237 +};
1238 +
1239 struct alps_data {
1240 struct input_dev *dev2; /* Relative device */
1241 char phys[32]; /* Phys */
1242 const struct alps_model_info *i;/* Info */
1243 + const struct alps_nibble_commands *nibble_commands;
1244 + int addr_command; /* Command to set register address */
1245 int prev_fin; /* Finger bit from previous packet */
1246 + int multi_packet; /* Multi-packet data in progress */
1247 + unsigned char multi_data[6]; /* Saved multi-packet data */
1248 + u8 quirks;
1249 struct timer_list timer;
1250 };
1251
1252 +#define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */
1253 +
1254 #ifdef CONFIG_MOUSE_PS2_ALPS
1255 int alps_detect(struct psmouse *psmouse, bool set_properties);
1256 int alps_init(struct psmouse *psmouse);
1257 diff -ur linux-3.2.old/drivers/input/mouse/psmouse.h linux-3.2/drivers/input/mouse/psmouse.h
1258 --- linux-3.2.old/drivers/input/mouse/psmouse.h 2012-01-04 17:55:44.000000000 -0600
1259 +++ linux-3.2/drivers/input/mouse/psmouse.h 2012-01-05 18:53:42.231275880 -0600
1260 @@ -8,6 +8,7 @@
1261 #define PSMOUSE_CMD_SETSTREAM 0x00ea
1262 #define PSMOUSE_CMD_SETPOLL 0x00f0
1263 #define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */
1264 +#define PSMOUSE_CMD_RESET_WRAP 0x00ec
1265 #define PSMOUSE_CMD_GETID 0x02f2
1266 #define PSMOUSE_CMD_SETRATE 0x10f3
1267 #define PSMOUSE_CMD_ENABLE 0x00f4

  ViewVC Help
Powered by ViewVC 1.1.20