blob: 7b99fc7c9438dbcbcc115248403e4b9704611f29 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALPS touchpad PS/2 mouse driver
3 *
4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
Peter Osterlund963f6262005-07-11 01:08:04 -05005 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08008 * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * ALPS detection, tap switching and status querying info is taken from
11 * tpconfig utility (by C. Scott Ananian and Bruce Kall).
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License version 2 as published by
15 * the Free Software Foundation.
16 */
17
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/input.h>
Seth Forshee01ce6612011-11-07 19:54:13 -080020#include <linux/input/mt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/serio.h>
22#include <linux/libps2.h>
23
24#include "psmouse.h"
25#include "alps.h"
26
Seth Forshee25bded72011-11-07 19:53:36 -080027/*
28 * Definitions for ALPS version 3 and 4 command mode protocol
29 */
30#define ALPS_CMD_NIBBLE_10 0x01f2
31
Kevin Cernekeecd401202013-02-13 22:28:07 -080032#define ALPS_REG_BASE_RUSHMORE 0xc2c0
33#define ALPS_REG_BASE_PINNACLE 0x0000
34
Seth Forshee25bded72011-11-07 19:53:36 -080035static const struct alps_nibble_commands alps_v3_nibble_commands[] = {
36 { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */
37 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
38 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
39 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
40 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
41 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
42 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
43 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
44 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
45 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
46 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
47 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
48 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
49 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
50 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
51 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
52};
53
54static const struct alps_nibble_commands alps_v4_nibble_commands[] = {
55 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
56 { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */
57 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */
58 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */
59 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */
60 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */
61 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */
62 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */
63 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */
64 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */
65 { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */
66 { PSMOUSE_CMD_SETRES, 0x00 }, /* b */
67 { PSMOUSE_CMD_SETRES, 0x01 }, /* c */
68 { PSMOUSE_CMD_SETRES, 0x02 }, /* d */
69 { PSMOUSE_CMD_SETRES, 0x03 }, /* e */
70 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
71};
72
73
Maxim Levitsky71bb21b2009-11-16 22:12:22 -080074#define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
75#define ALPS_PASS 0x04 /* device has a pass-through port */
76
77#define ALPS_WHEEL 0x08 /* hardware wheel present */
78#define ALPS_FW_BK_1 0x10 /* front & back buttons present */
79#define ALPS_FW_BK_2 0x20 /* front & back buttons present */
80#define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -080081#define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
82 6-byte ALPS packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Helge Dellere38de672006-09-10 21:54:39 -040084static const struct alps_model_info alps_model_data[] = {
Seth Forshee25bded72011-11-07 19:53:36 -080085 { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
86 { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
87 { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
88 { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
89 { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
90 { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
91 { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
92 { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
93 { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
94 { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
95 { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
96 { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
97 { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
98 { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
99 { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
100 { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
101 { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
102 { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800103 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
Seth Forshee25bded72011-11-07 19:53:36 -0800104 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800105 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
Seth Forshee25bded72011-11-07 19:53:36 -0800106 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
107 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
108 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
Seth Forshee25bded72011-11-07 19:53:36 -0800109 { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800112static void alps_set_abs_params_st(struct alps_data *priv,
113 struct input_dev *dev1);
114static void alps_set_abs_params_mt(struct alps_data *priv,
115 struct input_dev *dev1);
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/*
118 * XXX - this entry is suspicious. First byte has zero lower nibble,
119 * which is what a normal mouse would report. Also, the value 0x0e
120 * isn't valid per PS/2 spec.
121 */
122
Seth Forsheed4b347b2011-11-07 19:53:15 -0800123/* Packet formats are described in Documentation/input/alps.txt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800125static bool alps_is_valid_first_byte(struct alps_data *priv,
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800126 unsigned char data)
127{
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800128 return (data & priv->mask0) == priv->byte0;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800129}
130
131static void alps_report_buttons(struct psmouse *psmouse,
132 struct input_dev *dev1, struct input_dev *dev2,
133 int left, int right, int middle)
134{
Martin Buckc91ed052010-03-13 22:23:58 -0800135 struct input_dev *dev;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800136
Martin Buckc91ed052010-03-13 22:23:58 -0800137 /*
138 * If shared button has already been reported on the
139 * other device (dev2) then this event should be also
140 * sent through that device.
141 */
142 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
143 input_report_key(dev, BTN_LEFT, left);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800144
Martin Buckc91ed052010-03-13 22:23:58 -0800145 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
146 input_report_key(dev, BTN_RIGHT, right);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800147
Martin Buckc91ed052010-03-13 22:23:58 -0800148 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
149 input_report_key(dev, BTN_MIDDLE, middle);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800150
Martin Buckc91ed052010-03-13 22:23:58 -0800151 /*
152 * Sync the _other_ device now, we'll do the first
153 * device later once we report the rest of the events.
154 */
155 input_sync(dev2);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800156}
157
Seth Forshee25bded72011-11-07 19:53:36 -0800158static void alps_process_packet_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 struct alps_data *priv = psmouse->private;
161 unsigned char *packet = psmouse->packet;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500162 struct input_dev *dev = psmouse->dev;
163 struct input_dev *dev2 = priv->dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 int x, y, z, ges, fin, left, right, middle;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500165 int back = 0, forward = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800167 if (priv->proto_version == ALPS_PROTO_V1) {
Yotam Medinid2f40122006-05-29 23:30:36 -0400168 left = packet[2] & 0x10;
169 right = packet[2] & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 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
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800183 if (priv->flags & ALPS_FW_BK_1) {
Laszlo Kajan3c00bb92008-03-18 00:39:55 -0400184 back = packet[0] & 0x10;
185 forward = packet[2] & 4;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500186 }
187
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800188 if (priv->flags & ALPS_FW_BK_2) {
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500189 back = packet[3] & 4;
190 forward = packet[2] & 4;
191 if ((middle = forward && back))
192 forward = back = 0;
193 }
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 ges = packet[2] & 1;
196 fin = packet[2] & 2;
197
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800198 if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
200 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700201
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800202 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 input_sync(dev2);
205 return;
206 }
207
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800208 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 /* Convert hardware tap to a reasonable Z value */
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800211 if (ges && !fin)
212 z = 40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
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 Levitsky71bb21b2009-11-16 22:12:22 -0800228 if (z > 30)
229 input_report_key(dev, BTN_TOUCH, 1);
230 if (z < 25)
231 input_report_key(dev, BTN_TOUCH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
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
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800241 if (priv->flags & ALPS_WHEEL)
Vojtech Pavlike6c047b2005-09-04 01:40:43 -0500242 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800244 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500245 input_report_key(dev, BTN_FORWARD, forward);
246 input_report_key(dev, BTN_BACK, back);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800249 if (priv->flags & ALPS_FOUR_BUTTONS) {
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800250 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 Torvalds1da177e2005-04-16 15:20:36 -0700256 input_sync(dev);
257}
258
Seth Forshee01ce6612011-11-07 19:54:13 -0800259/*
260 * Process bitmap data from v3 and v4 protocols. Returns the number of
261 * fingers detected. A return value of 0 means at least one of the
262 * bitmaps was empty.
263 *
264 * The bitmaps don't have enough data to track fingers, so this function
265 * only generates points representing a bounding box of all contacts.
266 * These points are returned in x1, y1, x2, and y2 when the return value
267 * is greater than 0.
268 */
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800269static int alps_process_bitmap(struct alps_data *priv,
270 unsigned int x_map, unsigned int y_map,
Seth Forshee01ce6612011-11-07 19:54:13 -0800271 int *x1, int *y1, int *x2, int *y2)
272{
273 struct alps_bitmap_point {
274 int start_bit;
275 int num_bits;
276 };
277
278 int fingers_x = 0, fingers_y = 0, fingers;
279 int i, bit, prev_bit;
280 struct alps_bitmap_point x_low = {0,}, x_high = {0,};
281 struct alps_bitmap_point y_low = {0,}, y_high = {0,};
282 struct alps_bitmap_point *point;
283
284 if (!x_map || !y_map)
285 return 0;
286
287 *x1 = *y1 = *x2 = *y2 = 0;
288
289 prev_bit = 0;
290 point = &x_low;
291 for (i = 0; x_map != 0; i++, x_map >>= 1) {
292 bit = x_map & 1;
293 if (bit) {
294 if (!prev_bit) {
295 point->start_bit = i;
296 fingers_x++;
297 }
298 point->num_bits++;
299 } else {
300 if (prev_bit)
301 point = &x_high;
302 else
303 point->num_bits = 0;
304 }
305 prev_bit = bit;
306 }
307
308 /*
309 * y bitmap is reversed for what we need (lower positions are in
310 * higher bits), so we process from the top end.
311 */
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800312 y_map = y_map << (sizeof(y_map) * BITS_PER_BYTE - priv->y_bits);
Seth Forshee01ce6612011-11-07 19:54:13 -0800313 prev_bit = 0;
314 point = &y_low;
315 for (i = 0; y_map != 0; i++, y_map <<= 1) {
316 bit = y_map & (1 << (sizeof(y_map) * BITS_PER_BYTE - 1));
317 if (bit) {
318 if (!prev_bit) {
319 point->start_bit = i;
320 fingers_y++;
321 }
322 point->num_bits++;
323 } else {
324 if (prev_bit)
325 point = &y_high;
326 else
327 point->num_bits = 0;
328 }
329 prev_bit = bit;
330 }
331
332 /*
333 * Fingers can overlap, so we use the maximum count of fingers
334 * on either axis as the finger count.
335 */
336 fingers = max(fingers_x, fingers_y);
337
338 /*
339 * If total fingers is > 1 but either axis reports only a single
340 * contact, we have overlapping or adjacent fingers. For the
341 * purposes of creating a bounding box, divide the single contact
342 * (roughly) equally between the two points.
343 */
344 if (fingers > 1) {
345 if (fingers_x == 1) {
346 i = x_low.num_bits / 2;
347 x_low.num_bits = x_low.num_bits - i;
348 x_high.start_bit = x_low.start_bit + i;
349 x_high.num_bits = max(i, 1);
350 } else if (fingers_y == 1) {
351 i = y_low.num_bits / 2;
352 y_low.num_bits = y_low.num_bits - i;
353 y_high.start_bit = y_low.start_bit + i;
354 y_high.num_bits = max(i, 1);
355 }
356 }
357
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800358 *x1 = (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) /
359 (2 * (priv->x_bits - 1));
360 *y1 = (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) /
361 (2 * (priv->y_bits - 1));
Seth Forshee01ce6612011-11-07 19:54:13 -0800362
363 if (fingers > 1) {
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800364 *x2 = (priv->x_max *
365 (2 * x_high.start_bit + x_high.num_bits - 1)) /
366 (2 * (priv->x_bits - 1));
367 *y2 = (priv->y_max *
368 (2 * y_high.start_bit + y_high.num_bits - 1)) /
369 (2 * (priv->y_bits - 1));
Seth Forshee01ce6612011-11-07 19:54:13 -0800370 }
371
372 return fingers;
373}
374
375static void alps_set_slot(struct input_dev *dev, int slot, bool active,
376 int x, int y)
377{
378 input_mt_slot(dev, slot);
379 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
380 if (active) {
381 input_report_abs(dev, ABS_MT_POSITION_X, x);
382 input_report_abs(dev, ABS_MT_POSITION_Y, y);
383 }
384}
385
386static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers,
387 int x1, int y1, int x2, int y2)
388{
389 alps_set_slot(dev, 0, num_fingers != 0, x1, y1);
390 alps_set_slot(dev, 1, num_fingers == 2, x2, y2);
391}
392
Seth Forshee25bded72011-11-07 19:53:36 -0800393static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
394{
395 struct alps_data *priv = psmouse->private;
396 unsigned char *packet = psmouse->packet;
397 struct input_dev *dev = priv->dev2;
398 int x, y, z, left, right, middle;
399
400 /* Sanity check packet */
401 if (!(packet[0] & 0x40)) {
402 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
403 return;
404 }
405
406 /*
407 * There's a special packet that seems to indicate the end
408 * of a stream of trackstick data. Filter these out.
409 */
410 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
411 return;
412
413 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
414 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
415 z = (packet[4] & 0x7c) >> 2;
416
417 /*
418 * The x and y values tend to be quite large, and when used
419 * alone the trackstick is difficult to use. Scale them down
420 * to compensate.
421 */
422 x /= 8;
423 y /= 8;
424
425 input_report_rel(dev, REL_X, x);
426 input_report_rel(dev, REL_Y, -y);
427
428 /*
429 * Most ALPS models report the trackstick buttons in the touchpad
430 * packets, but a few report them here. No reliable way has been
431 * found to differentiate between the models upfront, so we enable
432 * the quirk in response to seeing a button press in the trackstick
433 * packet.
434 */
435 left = packet[3] & 0x01;
436 right = packet[3] & 0x02;
437 middle = packet[3] & 0x04;
438
439 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
440 (left || right || middle))
441 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
442
443 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
444 input_report_key(dev, BTN_LEFT, left);
445 input_report_key(dev, BTN_RIGHT, right);
446 input_report_key(dev, BTN_MIDDLE, middle);
447 }
448
449 input_sync(dev);
450 return;
451}
452
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800453static void alps_decode_buttons_v3(struct alps_fields *f, unsigned char *p)
454{
455 f->left = !!(p[3] & 0x01);
456 f->right = !!(p[3] & 0x02);
457 f->middle = !!(p[3] & 0x04);
458
459 f->ts_left = !!(p[3] & 0x10);
460 f->ts_right = !!(p[3] & 0x20);
461 f->ts_middle = !!(p[3] & 0x40);
462}
463
464static void alps_decode_pinnacle(struct alps_fields *f, unsigned char *p)
465{
466 f->first_mp = !!(p[4] & 0x40);
467 f->is_mp = !!(p[0] & 0x40);
468
469 f->fingers = (p[5] & 0x3) + 1;
470 f->x_map = ((p[4] & 0x7e) << 8) |
471 ((p[1] & 0x7f) << 2) |
472 ((p[0] & 0x30) >> 4);
473 f->y_map = ((p[3] & 0x70) << 4) |
474 ((p[2] & 0x7f) << 1) |
475 (p[4] & 0x01);
476
477 f->x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) |
478 ((p[0] & 0x30) >> 4);
479 f->y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f);
480 f->z = p[5] & 0x7f;
481
482 alps_decode_buttons_v3(f, p);
483}
484
Kevin Cernekee1302bac2013-02-13 22:27:08 -0800485static void alps_decode_rushmore(struct alps_fields *f, unsigned char *p)
486{
487 alps_decode_pinnacle(f, p);
488
489 f->x_map |= (p[5] & 0x10) << 11;
490 f->y_map |= (p[5] & 0x20) << 6;
491}
492
Seth Forshee25bded72011-11-07 19:53:36 -0800493static void alps_process_touchpad_packet_v3(struct psmouse *psmouse)
494{
495 struct alps_data *priv = psmouse->private;
496 unsigned char *packet = psmouse->packet;
497 struct input_dev *dev = psmouse->dev;
498 struct input_dev *dev2 = priv->dev2;
Seth Forshee01ce6612011-11-07 19:54:13 -0800499 int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
500 int fingers = 0, bmap_fingers;
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800501 struct alps_fields f;
502
503 priv->decode_fields(&f, packet);
Seth Forshee25bded72011-11-07 19:53:36 -0800504
505 /*
Seth Forshee01ce6612011-11-07 19:54:13 -0800506 * There's no single feature of touchpad position and bitmap packets
507 * that can be used to distinguish between them. We rely on the fact
508 * that a bitmap packet should always follow a position packet with
509 * bit 6 of packet[4] set.
Seth Forshee25bded72011-11-07 19:53:36 -0800510 */
511 if (priv->multi_packet) {
Seth Forshee25bded72011-11-07 19:53:36 -0800512 /*
513 * Sometimes a position packet will indicate a multi-packet
514 * sequence, but then what follows is another position
515 * packet. Check for this, and when it happens process the
516 * position packet as usual.
517 */
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800518 if (f.is_mp) {
519 fingers = f.fingers;
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800520 bmap_fingers = alps_process_bitmap(priv,
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800521 f.x_map, f.y_map,
Seth Forshee01ce6612011-11-07 19:54:13 -0800522 &x1, &y1, &x2, &y2);
523
Seth Forshee25bded72011-11-07 19:53:36 -0800524 /*
Seth Forshee01ce6612011-11-07 19:54:13 -0800525 * We shouldn't report more than one finger if
526 * we don't have two coordinates.
Seth Forshee25bded72011-11-07 19:53:36 -0800527 */
Seth Forshee01ce6612011-11-07 19:54:13 -0800528 if (fingers > 1 && bmap_fingers < 2)
529 fingers = bmap_fingers;
530
531 /* Now process position packet */
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800532 priv->decode_fields(&f, priv->multi_data);
Seth Forshee01ce6612011-11-07 19:54:13 -0800533 } else {
534 priv->multi_packet = 0;
Seth Forshee25bded72011-11-07 19:53:36 -0800535 }
536 }
537
Seth Forshee01ce6612011-11-07 19:54:13 -0800538 /*
539 * Bit 6 of byte 0 is not usually set in position packets. The only
540 * times it seems to be set is in situations where the data is
541 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
542 * this combined with the fact that this bit is useful for filtering
543 * out misidentified bitmap packets, we reject anything with this
544 * bit set.
545 */
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800546 if (f.is_mp)
Seth Forshee01ce6612011-11-07 19:54:13 -0800547 return;
548
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800549 if (!priv->multi_packet && f.first_mp) {
Seth Forshee25bded72011-11-07 19:53:36 -0800550 priv->multi_packet = 1;
Seth Forshee01ce6612011-11-07 19:54:13 -0800551 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
552 return;
553 }
554
555 priv->multi_packet = 0;
Seth Forshee25bded72011-11-07 19:53:36 -0800556
Seth Forshee25bded72011-11-07 19:53:36 -0800557 /*
558 * Sometimes the hardware sends a single packet with z = 0
559 * in the middle of a stream. Real releases generate packets
560 * with x, y, and z all zero, so these seem to be flukes.
561 * Ignore them.
562 */
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800563 if (f.x && f.y && !f.z)
Seth Forshee25bded72011-11-07 19:53:36 -0800564 return;
565
Seth Forshee01ce6612011-11-07 19:54:13 -0800566 /*
567 * If we don't have MT data or the bitmaps were empty, we have
568 * to rely on ST data.
569 */
570 if (!fingers) {
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800571 x1 = f.x;
572 y1 = f.y;
573 fingers = f.z > 0 ? 1 : 0;
Seth Forshee01ce6612011-11-07 19:54:13 -0800574 }
575
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800576 if (f.z >= 64)
Seth Forshee25bded72011-11-07 19:53:36 -0800577 input_report_key(dev, BTN_TOUCH, 1);
578 else
579 input_report_key(dev, BTN_TOUCH, 0);
580
Seth Forshee01ce6612011-11-07 19:54:13 -0800581 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
582
Dmitry Torokhov616575c2012-05-10 22:31:59 -0700583 input_mt_report_finger_count(dev, fingers);
Seth Forshee01ce6612011-11-07 19:54:13 -0800584
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800585 input_report_key(dev, BTN_LEFT, f.left);
586 input_report_key(dev, BTN_RIGHT, f.right);
587 input_report_key(dev, BTN_MIDDLE, f.middle);
Seth Forshee01ce6612011-11-07 19:54:13 -0800588
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800589 if (f.z > 0) {
590 input_report_abs(dev, ABS_X, f.x);
591 input_report_abs(dev, ABS_Y, f.y);
Seth Forshee25bded72011-11-07 19:53:36 -0800592 }
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800593 input_report_abs(dev, ABS_PRESSURE, f.z);
Seth Forshee25bded72011-11-07 19:53:36 -0800594
Seth Forshee25bded72011-11-07 19:53:36 -0800595 input_sync(dev);
596
597 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800598 input_report_key(dev2, BTN_LEFT, f.ts_left);
599 input_report_key(dev2, BTN_RIGHT, f.ts_right);
600 input_report_key(dev2, BTN_MIDDLE, f.ts_middle);
Seth Forshee25bded72011-11-07 19:53:36 -0800601 input_sync(dev2);
602 }
603}
604
605static void alps_process_packet_v3(struct psmouse *psmouse)
606{
607 unsigned char *packet = psmouse->packet;
608
609 /*
610 * v3 protocol packets come in three types, two representing
611 * touchpad data and one representing trackstick data.
612 * Trackstick packets seem to be distinguished by always
613 * having 0x3f in the last byte. This value has never been
614 * observed in the last byte of either of the other types
615 * of packets.
616 */
617 if (packet[5] == 0x3f) {
618 alps_process_trackstick_packet_v3(psmouse);
619 return;
620 }
621
622 alps_process_touchpad_packet_v3(psmouse);
623}
624
625static void alps_process_packet_v4(struct psmouse *psmouse)
626{
George Pantalos3b7e09f2012-05-10 22:31:59 -0700627 struct alps_data *priv = psmouse->private;
Seth Forshee25bded72011-11-07 19:53:36 -0800628 unsigned char *packet = psmouse->packet;
629 struct input_dev *dev = psmouse->dev;
George Pantalos3b7e09f2012-05-10 22:31:59 -0700630 int offset;
Seth Forshee25bded72011-11-07 19:53:36 -0800631 int x, y, z;
632 int left, right;
George Pantalos3b7e09f2012-05-10 22:31:59 -0700633 int x1, y1, x2, y2;
634 int fingers = 0;
635 unsigned int x_bitmap, y_bitmap;
636
637 /*
638 * v4 has a 6-byte encoding for bitmap data, but this data is
639 * broken up between 3 normal packets. Use priv->multi_packet to
640 * track our position in the bitmap packet.
641 */
642 if (packet[6] & 0x40) {
643 /* sync, reset position */
644 priv->multi_packet = 0;
645 }
646
647 if (WARN_ON_ONCE(priv->multi_packet > 2))
648 return;
649
650 offset = 2 * priv->multi_packet;
651 priv->multi_data[offset] = packet[6];
652 priv->multi_data[offset + 1] = packet[7];
653
654 if (++priv->multi_packet > 2) {
655 priv->multi_packet = 0;
656
657 x_bitmap = ((priv->multi_data[2] & 0x1f) << 10) |
658 ((priv->multi_data[3] & 0x60) << 3) |
659 ((priv->multi_data[0] & 0x3f) << 2) |
660 ((priv->multi_data[1] & 0x60) >> 5);
661 y_bitmap = ((priv->multi_data[5] & 0x01) << 10) |
662 ((priv->multi_data[3] & 0x1f) << 5) |
663 (priv->multi_data[1] & 0x1f);
664
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800665 fingers = alps_process_bitmap(priv, x_bitmap, y_bitmap,
George Pantalos3b7e09f2012-05-10 22:31:59 -0700666 &x1, &y1, &x2, &y2);
667
668 /* Store MT data.*/
669 priv->fingers = fingers;
670 priv->x1 = x1;
671 priv->x2 = x2;
672 priv->y1 = y1;
673 priv->y2 = y2;
674 }
Seth Forshee25bded72011-11-07 19:53:36 -0800675
676 left = packet[4] & 0x01;
677 right = packet[4] & 0x02;
678
679 x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
680 ((packet[0] & 0x30) >> 4);
681 y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
682 z = packet[5] & 0x7f;
683
George Pantalos3b7e09f2012-05-10 22:31:59 -0700684 /*
685 * If there were no contacts in the bitmap, use ST
686 * points in MT reports.
687 * If there were two contacts or more, report MT data.
688 */
689 if (priv->fingers < 2) {
690 x1 = x;
691 y1 = y;
692 fingers = z > 0 ? 1 : 0;
693 } else {
694 fingers = priv->fingers;
695 x1 = priv->x1;
696 x2 = priv->x2;
697 y1 = priv->y1;
698 y2 = priv->y2;
699 }
700
Seth Forshee25bded72011-11-07 19:53:36 -0800701 if (z >= 64)
702 input_report_key(dev, BTN_TOUCH, 1);
703 else
704 input_report_key(dev, BTN_TOUCH, 0);
705
George Pantalos3b7e09f2012-05-10 22:31:59 -0700706 alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
707
Dmitry Torokhov616575c2012-05-10 22:31:59 -0700708 input_mt_report_finger_count(dev, fingers);
George Pantalos3b7e09f2012-05-10 22:31:59 -0700709
710 input_report_key(dev, BTN_LEFT, left);
711 input_report_key(dev, BTN_RIGHT, right);
712
Seth Forshee25bded72011-11-07 19:53:36 -0800713 if (z > 0) {
714 input_report_abs(dev, ABS_X, x);
715 input_report_abs(dev, ABS_Y, y);
716 }
717 input_report_abs(dev, ABS_PRESSURE, z);
718
Seth Forshee25bded72011-11-07 19:53:36 -0800719 input_sync(dev);
720}
721
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800722static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
723 unsigned char packet[],
724 bool report_buttons)
725{
726 struct alps_data *priv = psmouse->private;
727 struct input_dev *dev2 = priv->dev2;
728
729 if (report_buttons)
730 alps_report_buttons(psmouse, dev2, psmouse->dev,
731 packet[0] & 1, packet[0] & 2, packet[0] & 4);
732
733 input_report_rel(dev2, REL_X,
734 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
735 input_report_rel(dev2, REL_Y,
736 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
737
738 input_sync(dev2);
739}
740
741static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
743 struct alps_data *priv = psmouse->private;
744
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800745 if (psmouse->pktcnt < 6)
746 return PSMOUSE_GOOD_DATA;
747
748 if (psmouse->pktcnt == 6) {
749 /*
750 * Start a timer to flush the packet if it ends up last
751 * 6-byte packet in the stream. Timer needs to fire
752 * psmouse core times out itself. 20 ms should be enough
753 * to decide if we are getting more data or not.
754 */
755 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
756 return PSMOUSE_GOOD_DATA;
757 }
758
759 del_timer(&priv->timer);
760
761 if (psmouse->packet[6] & 0x80) {
762
763 /*
764 * Highest bit is set - that means we either had
765 * complete ALPS packet and this is start of the
766 * next packet or we got garbage.
767 */
768
769 if (((psmouse->packet[3] |
770 psmouse->packet[4] |
771 psmouse->packet[5]) & 0x80) ||
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800772 (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700773 psmouse_dbg(psmouse,
Andy Shevchenko3b112922012-10-30 00:24:41 -0700774 "refusing packet %4ph (suspected interleaved ps/2)\n",
775 psmouse->packet + 3);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800776 return PSMOUSE_BAD_DATA;
777 }
778
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800779 priv->process_packet(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800780
781 /* Continue with the next packet */
782 psmouse->packet[0] = psmouse->packet[6];
783 psmouse->pktcnt = 1;
784
785 } else {
786
787 /*
788 * High bit is 0 - that means that we indeed got a PS/2
789 * packet in the middle of ALPS packet.
790 *
791 * There is also possibility that we got 6-byte ALPS
792 * packet followed by 3-byte packet from trackpoint. We
793 * can not distinguish between these 2 scenarios but
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700794 * because the latter is unlikely to happen in course of
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800795 * normal operation (user would need to press all
796 * buttons on the pad and start moving trackpoint
797 * without touching the pad surface) we assume former.
798 * Even if we are wrong the wost thing that would happen
799 * the cursor would jump but we should not get protocol
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700800 * de-synchronization.
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800801 */
802
803 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
804 false);
805
806 /*
807 * Continue with the standard ALPS protocol handling,
808 * but make sure we won't process it as an interleaved
809 * packet again, which may happen if all buttons are
810 * pressed. To avoid this let's reset the 4th bit which
811 * is normally 1.
812 */
813 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
814 psmouse->pktcnt = 4;
815 }
816
817 return PSMOUSE_GOOD_DATA;
818}
819
820static void alps_flush_packet(unsigned long data)
821{
822 struct psmouse *psmouse = (struct psmouse *)data;
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800823 struct alps_data *priv = psmouse->private;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800824
825 serio_pause_rx(psmouse->ps2dev.serio);
826
Seth Forsheeb46615f2011-11-07 19:53:30 -0800827 if (psmouse->pktcnt == psmouse->pktsize) {
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800828
829 /*
830 * We did not any more data in reasonable amount of time.
831 * Validate the last 3 bytes and process as a standard
832 * ALPS packet.
833 */
834 if ((psmouse->packet[3] |
835 psmouse->packet[4] |
836 psmouse->packet[5]) & 0x80) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700837 psmouse_dbg(psmouse,
Andy Shevchenko3b112922012-10-30 00:24:41 -0700838 "refusing packet %3ph (suspected interleaved ps/2)\n",
839 psmouse->packet + 3);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800840 } else {
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800841 priv->process_packet(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800842 }
843 psmouse->pktcnt = 0;
844 }
845
846 serio_continue_rx(psmouse->ps2dev.serio);
847}
848
849static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
850{
851 struct alps_data *priv = psmouse->private;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
854 if (psmouse->pktcnt == 3) {
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800855 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
856 true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 return PSMOUSE_FULL_PACKET;
858 }
859 return PSMOUSE_GOOD_DATA;
860 }
861
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800862 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
863
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800864 if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800865 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
866 return alps_handle_interleaved_ps2(psmouse);
867 }
868
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800869 if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700870 psmouse_dbg(psmouse,
871 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800872 psmouse->packet[0], priv->mask0, priv->byte0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 return PSMOUSE_BAD_DATA;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Seth Forsheeb46615f2011-11-07 19:53:30 -0800876 /* Bytes 2 - pktsize should have 0 in the highest bit */
877 if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800878 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700879 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
880 psmouse->pktcnt - 1,
881 psmouse->packet[psmouse->pktcnt - 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return PSMOUSE_BAD_DATA;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Seth Forsheeb46615f2011-11-07 19:53:30 -0800885 if (psmouse->pktcnt == psmouse->pktsize) {
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800886 priv->process_packet(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 return PSMOUSE_FULL_PACKET;
888 }
889
890 return PSMOUSE_GOOD_DATA;
891}
892
Seth Forshee25bded72011-11-07 19:53:36 -0800893static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
894{
895 struct ps2dev *ps2dev = &psmouse->ps2dev;
896 struct alps_data *priv = psmouse->private;
897 int command;
898 unsigned char *param;
899 unsigned char dummy[4];
900
901 BUG_ON(nibble > 0xf);
902
903 command = priv->nibble_commands[nibble].command;
904 param = (command & 0x0f00) ?
905 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
906
907 if (ps2_command(ps2dev, param, command))
908 return -1;
909
910 return 0;
911}
912
913static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
914{
915 struct ps2dev *ps2dev = &psmouse->ps2dev;
916 struct alps_data *priv = psmouse->private;
917 int i, nibble;
918
919 if (ps2_command(ps2dev, NULL, priv->addr_command))
920 return -1;
921
922 for (i = 12; i >= 0; i -= 4) {
923 nibble = (addr >> i) & 0xf;
924 if (alps_command_mode_send_nibble(psmouse, nibble))
925 return -1;
926 }
927
928 return 0;
929}
930
931static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
932{
933 struct ps2dev *ps2dev = &psmouse->ps2dev;
934 unsigned char param[4];
935
936 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
937 return -1;
938
939 /*
940 * The address being read is returned in the first two bytes
941 * of the result. Check that this address matches the expected
942 * address.
943 */
944 if (addr != ((param[0] << 8) | param[1]))
945 return -1;
946
947 return param[2];
948}
949
950static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
951{
952 if (alps_command_mode_set_addr(psmouse, addr))
953 return -1;
954 return __alps_command_mode_read_reg(psmouse, addr);
955}
956
957static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
958{
959 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
960 return -1;
961 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
962 return -1;
963 return 0;
964}
965
966static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
967 u8 value)
968{
969 if (alps_command_mode_set_addr(psmouse, addr))
970 return -1;
971 return __alps_command_mode_write_reg(psmouse, value);
972}
973
Kevin Cernekee24ba9702013-02-13 22:19:01 -0800974static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
975 int repeated_command, unsigned char *param)
976{
977 struct ps2dev *ps2dev = &psmouse->ps2dev;
978
979 param[0] = 0;
980 if (init_command && ps2_command(ps2dev, param, init_command))
981 return -EIO;
982
983 if (ps2_command(ps2dev, NULL, repeated_command) ||
984 ps2_command(ps2dev, NULL, repeated_command) ||
985 ps2_command(ps2dev, NULL, repeated_command))
986 return -EIO;
987
988 param[0] = param[1] = param[2] = 0xff;
989 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
990 return -EIO;
991
992 psmouse_dbg(psmouse, "%2.2X report: %2.2x %2.2x %2.2x\n",
993 repeated_command, param[0], param[1], param[2]);
994 return 0;
995}
996
Seth Forshee25bded72011-11-07 19:53:36 -0800997static int alps_enter_command_mode(struct psmouse *psmouse,
998 unsigned char *resp)
999{
1000 unsigned char param[4];
Seth Forshee25bded72011-11-07 19:53:36 -08001001
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001002 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001003 psmouse_err(psmouse, "failed to enter command mode\n");
1004 return -1;
1005 }
1006
Kevin Cernekee56fd3402013-02-13 22:24:22 -08001007 if (param[0] != 0x88 || (param[1] != 0x07 && param[1] != 0x08)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001008 psmouse_dbg(psmouse,
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001009 "unknown response while entering command mode\n");
Seth Forshee25bded72011-11-07 19:53:36 -08001010 return -1;
1011 }
1012
1013 if (resp)
1014 *resp = param[2];
1015 return 0;
1016}
1017
1018static inline int alps_exit_command_mode(struct psmouse *psmouse)
1019{
1020 struct ps2dev *ps2dev = &psmouse->ps2dev;
1021 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
1022 return -1;
1023 return 0;
1024}
1025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026/*
1027 * For DualPoint devices select the device that should respond to
1028 * subsequent commands. It looks like glidepad is behind stickpointer,
1029 * I'd thought it would be other way around...
1030 */
Seth Forshee25bded72011-11-07 19:53:36 -08001031static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 struct ps2dev *ps2dev = &psmouse->ps2dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
1035
1036 if (ps2_command(ps2dev, NULL, cmd) ||
1037 ps2_command(ps2dev, NULL, cmd) ||
1038 ps2_command(ps2dev, NULL, cmd) ||
1039 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1040 return -1;
1041
1042 /* we may get 3 more bytes, just ignore them */
Dmitry Torokhovc6117632005-06-01 02:39:51 -05001043 ps2_drain(ps2dev, 3, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 return 0;
1046}
1047
Seth Forshee25bded72011-11-07 19:53:36 -08001048static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
1050 struct ps2dev *ps2dev = &psmouse->ps2dev;
1051
1052 /* Try ALPS magic knock - 4 disable before enable */
1053 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1054 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1055 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1056 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1057 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
1058 return -1;
1059
1060 /*
1061 * Switch mouse to poll (remote) mode so motion data will not
1062 * get in our way
1063 */
1064 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
1065}
1066
1067static int alps_get_status(struct psmouse *psmouse, char *param)
1068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001070 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 return -1;
1072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 return 0;
1074}
1075
1076/*
1077 * Turn touchpad tapping on or off. The sequences are:
1078 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1079 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1080 * My guess that 0xE9 (GetInfo) is here as a sync point.
1081 * For models that also have stickpointer (DualPoints) its tapping
1082 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1083 * we don't fiddle with it.
1084 */
1085static int alps_tap_mode(struct psmouse *psmouse, int enable)
1086{
1087 struct ps2dev *ps2dev = &psmouse->ps2dev;
1088 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
1089 unsigned char tap_arg = enable ? 0x0A : 0x00;
1090 unsigned char param[4];
1091
1092 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
1093 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1094 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1095 ps2_command(ps2dev, &tap_arg, cmd))
1096 return -1;
1097
1098 if (alps_get_status(psmouse, param))
1099 return -1;
1100
1101 return 0;
1102}
1103
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001104/*
1105 * alps_poll() - poll the touchpad for current motion packet.
1106 * Used in resync.
1107 */
1108static int alps_poll(struct psmouse *psmouse)
1109{
1110 struct alps_data *priv = psmouse->private;
Seth Forsheeb46615f2011-11-07 19:53:30 -08001111 unsigned char buf[sizeof(psmouse->packet)];
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001112 bool poll_failed;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001113
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001114 if (priv->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -08001115 alps_passthrough_mode_v2(psmouse, true);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001116
1117 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1118 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1119
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001120 if (priv->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -08001121 alps_passthrough_mode_v2(psmouse, false);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001122
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001123 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001124 return -1;
1125
1126 if ((psmouse->badbyte & 0xc8) == 0x08) {
1127/*
1128 * Poll the track stick ...
1129 */
1130 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
1131 return -1;
1132 }
1133
1134 memcpy(psmouse->packet, buf, sizeof(buf));
1135 return 0;
1136}
1137
Seth Forshee25bded72011-11-07 19:53:36 -08001138static int alps_hw_init_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
1140 struct alps_data *priv = psmouse->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001142 if ((priv->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -08001143 alps_passthrough_mode_v2(psmouse, true)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001147 if (alps_tap_mode(psmouse, true)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001148 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 return -1;
Peter Osterlund963f6262005-07-11 01:08:04 -05001150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Seth Forshee25bded72011-11-07 19:53:36 -08001152 if (alps_absolute_mode_v1_v2(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001153 psmouse_err(psmouse, "Failed to enable absolute mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 return -1;
1155 }
1156
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001157 if ((priv->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -08001158 alps_passthrough_mode_v2(psmouse, false)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001162 /* ALPS needs stream mode, otherwise it won't report any data */
1163 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001164 psmouse_err(psmouse, "Failed to enable stream mode\n");
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001165 return -1;
1166 }
1167
1168 return 0;
1169}
1170
Seth Forshee25bded72011-11-07 19:53:36 -08001171/*
Kevin Cernekeecd401202013-02-13 22:28:07 -08001172 * Enable or disable passthrough mode to the trackstick.
Seth Forshee25bded72011-11-07 19:53:36 -08001173 */
Kevin Cernekeecd401202013-02-13 22:28:07 -08001174static int alps_passthrough_mode_v3(struct psmouse *psmouse,
1175 int reg_base, bool enable)
Seth Forshee25bded72011-11-07 19:53:36 -08001176{
Kevin Cernekeecd401202013-02-13 22:28:07 -08001177 int reg_val, ret = -1;
Seth Forshee25bded72011-11-07 19:53:36 -08001178
Kevin Cernekeecd401202013-02-13 22:28:07 -08001179 if (alps_enter_command_mode(psmouse, NULL))
Seth Forshee25bded72011-11-07 19:53:36 -08001180 return -1;
1181
Kevin Cernekeecd401202013-02-13 22:28:07 -08001182 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008);
1183 if (reg_val == -1)
1184 goto error;
1185
Seth Forshee25bded72011-11-07 19:53:36 -08001186 if (enable)
1187 reg_val |= 0x01;
1188 else
1189 reg_val &= ~0x01;
1190
Kevin Cernekeecd401202013-02-13 22:28:07 -08001191 ret = __alps_command_mode_write_reg(psmouse, reg_val);
Seth Forshee25bded72011-11-07 19:53:36 -08001192
Kevin Cernekeecd401202013-02-13 22:28:07 -08001193error:
1194 if (alps_exit_command_mode(psmouse))
1195 ret = -1;
1196 return ret;
Seth Forshee25bded72011-11-07 19:53:36 -08001197}
1198
1199/* Must be in command mode when calling this function */
1200static int alps_absolute_mode_v3(struct psmouse *psmouse)
1201{
1202 int reg_val;
1203
1204 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1205 if (reg_val == -1)
1206 return -1;
1207
1208 reg_val |= 0x06;
1209 if (__alps_command_mode_write_reg(psmouse, reg_val))
1210 return -1;
1211
1212 return 0;
1213}
1214
Kevin Cernekeecd401202013-02-13 22:28:07 -08001215static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base)
1216{
1217 int ret = -EIO, reg_val;
1218
1219 if (alps_enter_command_mode(psmouse, NULL))
1220 goto error;
1221
1222 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
1223 if (reg_val == -1)
1224 goto error;
1225
1226 /* bit 7: trackstick is present */
1227 ret = reg_val & 0x80 ? 0 : -ENODEV;
1228
1229error:
1230 alps_exit_command_mode(psmouse);
1231 return ret;
1232}
1233
1234static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
1235{
1236 struct ps2dev *ps2dev = &psmouse->ps2dev;
1237 int ret = 0;
1238 unsigned char param[4];
1239
1240 if (alps_passthrough_mode_v3(psmouse, reg_base, true))
1241 return -EIO;
1242
1243 /*
1244 * E7 report for the trackstick
1245 *
1246 * There have been reports of failures to seem to trace back
1247 * to the above trackstick check failing. When these occur
1248 * this E7 report fails, so when that happens we continue
1249 * with the assumption that there isn't a trackstick after
1250 * all.
1251 */
1252 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) {
1253 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1254 ret = -ENODEV;
1255 } else {
1256 psmouse_dbg(psmouse,
1257 "trackstick E7 report: %2.2x %2.2x %2.2x\n",
1258 param[0], param[1], param[2]);
1259
1260 /*
1261 * Not sure what this does, but it is absolutely
1262 * essential. Without it, the touchpad does not
1263 * work at all and the trackstick just emits normal
1264 * PS/2 packets.
1265 */
1266 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1267 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1268 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1269 alps_command_mode_send_nibble(psmouse, 0x9) ||
1270 alps_command_mode_send_nibble(psmouse, 0x4)) {
1271 psmouse_err(psmouse,
1272 "Error sending magic E6 sequence\n");
1273 ret = -EIO;
1274 goto error;
1275 }
1276
1277 /*
1278 * This ensures the trackstick packets are in the format
1279 * supported by this driver. If bit 1 isn't set the packet
1280 * format is different.
1281 */
1282 if (alps_enter_command_mode(psmouse, NULL) ||
1283 alps_command_mode_write_reg(psmouse,
1284 reg_base + 0x08, 0x82) ||
1285 alps_exit_command_mode(psmouse))
1286 ret = -EIO;
1287 }
1288
1289error:
1290 if (alps_passthrough_mode_v3(psmouse, reg_base, false))
1291 ret = -EIO;
1292
1293 return ret;
1294}
1295
Seth Forshee25bded72011-11-07 19:53:36 -08001296static int alps_hw_init_v3(struct psmouse *psmouse)
1297{
Seth Forshee25bded72011-11-07 19:53:36 -08001298 struct ps2dev *ps2dev = &psmouse->ps2dev;
1299 int reg_val;
1300 unsigned char param[4];
1301
Kevin Cernekeecd401202013-02-13 22:28:07 -08001302 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE);
1303 if (reg_val == -EIO)
1304 goto error;
1305 if (reg_val == 0 &&
1306 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO)
Seth Forshee25bded72011-11-07 19:53:36 -08001307 goto error;
1308
Kevin Cernekeecd401202013-02-13 22:28:07 -08001309 if (alps_enter_command_mode(psmouse, NULL) ||
1310 alps_absolute_mode_v3(psmouse)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001311 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1312 goto error;
1313 }
1314
1315 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1316 if (reg_val == -1)
1317 goto error;
1318 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1319 goto error;
1320
1321 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1322 if (reg_val == -1)
1323 goto error;
1324 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1325 goto error;
1326
1327 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1328 goto error;
1329 if (__alps_command_mode_write_reg(psmouse, 0x04))
1330 goto error;
1331
1332 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1333 goto error;
1334 if (__alps_command_mode_write_reg(psmouse, 0x03))
1335 goto error;
1336
1337 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1338 goto error;
1339 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1340 goto error;
1341
1342 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1343 goto error;
1344 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1345 goto error;
1346
Seth Forshee25bded72011-11-07 19:53:36 -08001347 alps_exit_command_mode(psmouse);
1348
1349 /* Set rate and enable data reporting */
1350 param[0] = 0x64;
1351 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1352 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1353 psmouse_err(psmouse, "Failed to enable data reporting\n");
1354 return -1;
1355 }
1356
1357 return 0;
1358
Seth Forshee25bded72011-11-07 19:53:36 -08001359error:
1360 /*
1361 * Leaving the touchpad in command mode will essentially render
1362 * it unusable until the machine reboots, so exit it here just
1363 * to be safe
1364 */
1365 alps_exit_command_mode(psmouse);
1366 return -1;
1367}
1368
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001369static int alps_hw_init_rushmore_v3(struct psmouse *psmouse)
1370{
Kevin Cernekeecd401202013-02-13 22:28:07 -08001371 struct alps_data *priv = psmouse->private;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001372 struct ps2dev *ps2dev = &psmouse->ps2dev;
1373 int reg_val, ret = -1;
1374
Kevin Cernekeecd401202013-02-13 22:28:07 -08001375 if (priv->flags & ALPS_DUALPOINT) {
1376 reg_val = alps_setup_trackstick_v3(psmouse,
1377 ALPS_REG_BASE_RUSHMORE);
1378 if (reg_val == -EIO)
1379 goto error;
1380 if (reg_val == -ENODEV)
1381 priv->flags &= ~ALPS_DUALPOINT;
1382 }
1383
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001384 if (alps_enter_command_mode(psmouse, NULL) ||
1385 alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 ||
1386 alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00))
1387 goto error;
1388
1389 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6);
1390 if (reg_val == -1)
1391 goto error;
1392 if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd))
1393 goto error;
1394
1395 if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64))
1396 goto error;
1397
1398 /* enter absolute mode */
1399 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4);
1400 if (reg_val == -1)
1401 goto error;
1402 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02))
1403 goto error;
1404
1405 alps_exit_command_mode(psmouse);
1406 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1407
1408error:
1409 alps_exit_command_mode(psmouse);
1410 return ret;
1411}
1412
Seth Forshee25bded72011-11-07 19:53:36 -08001413/* Must be in command mode when calling this function */
1414static int alps_absolute_mode_v4(struct psmouse *psmouse)
1415{
1416 int reg_val;
1417
1418 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1419 if (reg_val == -1)
1420 return -1;
1421
1422 reg_val |= 0x02;
1423 if (__alps_command_mode_write_reg(psmouse, reg_val))
1424 return -1;
1425
1426 return 0;
1427}
1428
1429static int alps_hw_init_v4(struct psmouse *psmouse)
1430{
Seth Forshee25bded72011-11-07 19:53:36 -08001431 struct ps2dev *ps2dev = &psmouse->ps2dev;
1432 unsigned char param[4];
1433
Seth Forshee25bded72011-11-07 19:53:36 -08001434 if (alps_enter_command_mode(psmouse, NULL))
1435 goto error;
1436
1437 if (alps_absolute_mode_v4(psmouse)) {
1438 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1439 goto error;
1440 }
1441
1442 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1443 goto error;
1444
1445 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1446 goto error;
1447
1448 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1449 goto error;
1450
1451 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1452 goto error;
1453
1454 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1455 goto error;
1456
1457 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1458 goto error;
1459
1460 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1461 goto error;
1462
1463 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1464 goto error;
1465
1466 alps_exit_command_mode(psmouse);
1467
1468 /*
1469 * This sequence changes the output from a 9-byte to an
1470 * 8-byte format. All the same data seems to be present,
1471 * just in a more compact format.
1472 */
1473 param[0] = 0xc8;
1474 param[1] = 0x64;
1475 param[2] = 0x50;
1476 if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1477 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1478 ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1479 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1480 return -1;
1481
1482 /* Set rate and enable data reporting */
1483 param[0] = 0x64;
1484 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1485 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1486 psmouse_err(psmouse, "Failed to enable data reporting\n");
1487 return -1;
1488 }
1489
1490 return 0;
1491
1492error:
1493 /*
1494 * Leaving the touchpad in command mode will essentially render
1495 * it unusable until the machine reboots, so exit it here just
1496 * to be safe
1497 */
1498 alps_exit_command_mode(psmouse);
1499 return -1;
1500}
1501
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001502static void alps_set_defaults(struct alps_data *priv)
Seth Forshee25bded72011-11-07 19:53:36 -08001503{
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001504 priv->byte0 = 0x8f;
1505 priv->mask0 = 0x8f;
1506 priv->flags = ALPS_DUALPOINT;
1507
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001508 priv->x_max = 2000;
1509 priv->y_max = 1400;
1510 priv->x_bits = 15;
1511 priv->y_bits = 11;
1512
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001513 switch (priv->proto_version) {
Seth Forshee25bded72011-11-07 19:53:36 -08001514 case ALPS_PROTO_V1:
1515 case ALPS_PROTO_V2:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001516 priv->hw_init = alps_hw_init_v1_v2;
1517 priv->process_packet = alps_process_packet_v1_v2;
1518 priv->set_abs_params = alps_set_abs_params_st;
Seth Forshee25bded72011-11-07 19:53:36 -08001519 break;
1520 case ALPS_PROTO_V3:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001521 priv->hw_init = alps_hw_init_v3;
1522 priv->process_packet = alps_process_packet_v3;
1523 priv->set_abs_params = alps_set_abs_params_mt;
Kevin Cernekeef85e5002013-02-13 22:26:11 -08001524 priv->decode_fields = alps_decode_pinnacle;
Kevin Cernekee50e8b212013-02-13 22:23:04 -08001525 priv->nibble_commands = alps_v3_nibble_commands;
1526 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
Seth Forshee25bded72011-11-07 19:53:36 -08001527 break;
1528 case ALPS_PROTO_V4:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001529 priv->hw_init = alps_hw_init_v4;
1530 priv->process_packet = alps_process_packet_v4;
1531 priv->set_abs_params = alps_set_abs_params_mt;
Kevin Cernekee50e8b212013-02-13 22:23:04 -08001532 priv->nibble_commands = alps_v4_nibble_commands;
1533 priv->addr_command = PSMOUSE_CMD_DISABLE;
Seth Forshee25bded72011-11-07 19:53:36 -08001534 break;
1535 }
Seth Forshee25bded72011-11-07 19:53:36 -08001536}
1537
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001538static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv,
1539 unsigned char *e7, unsigned char *ec)
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001540{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001541 const struct alps_model_info *model;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001542 int i;
1543
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001544 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1545 model = &alps_model_data[i];
1546
1547 if (!memcmp(e7, model->signature, sizeof(model->signature)) &&
1548 (!model->command_mode_resp ||
1549 model->command_mode_resp == ec[2])) {
1550
1551 priv->proto_version = model->proto_version;
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001552 alps_set_defaults(priv);
1553
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001554 priv->flags = model->flags;
1555 priv->byte0 = model->byte0;
1556 priv->mask0 = model->mask0;
1557
1558 return 0;
1559 }
1560 }
1561
1562 return -EINVAL;
1563}
1564
1565static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
1566{
1567 unsigned char e6[4], e7[4], ec[4];
1568
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001569 /*
1570 * First try "E6 report".
1571 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
1572 * The bits 0-2 of the first byte will be 1s if some buttons are
1573 * pressed.
1574 */
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001575 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1576 PSMOUSE_CMD_SETSCALE11, e6))
1577 return -EIO;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001578
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001579 if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100))
1580 return -EINVAL;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001581
1582 /*
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001583 * Now get the "E7" and "EC" reports. These will uniquely identify
1584 * most ALPS touchpads.
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001585 */
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001586 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1587 PSMOUSE_CMD_SETSCALE21, e7) ||
1588 alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1589 PSMOUSE_CMD_RESET_WRAP, ec) ||
1590 alps_exit_command_mode(psmouse))
1591 return -EIO;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001592
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001593 if (alps_match_table(psmouse, priv, e7, ec) == 0) {
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001594 return 0;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001595 } else if (ec[0] == 0x88 && ec[1] == 0x08) {
1596 priv->proto_version = ALPS_PROTO_V3;
1597 alps_set_defaults(priv);
1598
1599 priv->hw_init = alps_hw_init_rushmore_v3;
1600 priv->decode_fields = alps_decode_rushmore;
1601 priv->x_bits = 16;
1602 priv->y_bits = 12;
1603
Kevin Cernekeecd401202013-02-13 22:28:07 -08001604 /* hack to make addr_command, nibble_command available */
1605 psmouse->private = priv;
1606
1607 if (alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_RUSHMORE))
1608 priv->flags &= ~ALPS_DUALPOINT;
1609
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001610 return 0;
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001611 } else if (ec[0] == 0x88 && ec[1] == 0x07 &&
1612 ec[2] >= 0x90 && ec[2] <= 0x9d) {
1613 priv->proto_version = ALPS_PROTO_V3;
1614 alps_set_defaults(priv);
1615
1616 return 0;
1617 }
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001618
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001619 psmouse_info(psmouse,
1620 "Unknown ALPS touchpad: E7=%2.2x %2.2x %2.2x, EC=%2.2x %2.2x %2.2x\n",
1621 e7[0], e7[1], e7[2], ec[0], ec[1], ec[2]);
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001622
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001623 return -EINVAL;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001624}
1625
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001626static int alps_reconnect(struct psmouse *psmouse)
1627{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001628 struct alps_data *priv = psmouse->private;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001629
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001630 psmouse_reset(psmouse);
1631
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001632 if (alps_identify(psmouse, priv) < 0)
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001633 return -1;
1634
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001635 return priv->hw_init(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
1638static void alps_disconnect(struct psmouse *psmouse)
1639{
1640 struct alps_data *priv = psmouse->private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 psmouse_reset(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001643 del_timer_sync(&priv->timer);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001644 input_unregister_device(priv->dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 kfree(priv);
1646}
1647
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001648static void alps_set_abs_params_st(struct alps_data *priv,
1649 struct input_dev *dev1)
1650{
1651 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1652 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1653}
1654
1655static void alps_set_abs_params_mt(struct alps_data *priv,
1656 struct input_dev *dev1)
1657{
1658 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
1659 input_mt_init_slots(dev1, 2, 0);
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001660 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0);
1661 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001662
1663 set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
1664 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
1665 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
1666
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001667 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
1668 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001669}
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671int alps_init(struct psmouse *psmouse)
1672{
1673 struct alps_data *priv;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001674 struct input_dev *dev1 = psmouse->dev, *dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001676 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001677 dev2 = input_allocate_device();
1678 if (!priv || !dev2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 goto init_fail;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001680
1681 priv->dev2 = dev2;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001682 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
1683
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001684 psmouse->private = priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Seth Forshee25bded72011-11-07 19:53:36 -08001686 psmouse_reset(psmouse);
1687
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001688 if (alps_identify(psmouse, priv) < 0)
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001689 goto init_fail;
1690
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001691 if (priv->hw_init(psmouse))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 goto init_fail;
1693
Dmitry Torokhov7105d2e2009-12-11 23:54:54 -08001694 /*
1695 * Undo part of setup done for us by psmouse core since touchpad
1696 * is not a relative device.
1697 */
1698 __clear_bit(EV_REL, dev1->evbit);
1699 __clear_bit(REL_X, dev1->relbit);
1700 __clear_bit(REL_Y, dev1->relbit);
1701
1702 /*
1703 * Now set up our capabilities.
1704 */
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001705 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
1706 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
1707 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001708 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
1709 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001711 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
Seth Forshee25bded72011-11-07 19:53:36 -08001712
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001713 priv->set_abs_params(priv, dev1);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001714 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001716 if (priv->flags & ALPS_WHEEL) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001717 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
1718 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 }
1720
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001721 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001722 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
1723 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 }
1725
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001726 if (priv->flags & ALPS_FOUR_BUTTONS) {
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001727 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
1728 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
1729 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
1730 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
1731 } else {
1732 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
1733 }
1734
Dmitry Torokhov08ffce42006-06-26 01:45:10 -04001735 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001736 dev2->phys = priv->phys;
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001737 dev2->name = (priv->flags & ALPS_DUALPOINT) ?
1738 "DualPoint Stick" : "PS/2 Mouse";
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001739 dev2->id.bustype = BUS_I8042;
1740 dev2->id.vendor = 0x0002;
1741 dev2->id.product = PSMOUSE_ALPS;
1742 dev2->id.version = 0x0000;
Dmitry Torokhov1db3a342008-03-18 00:29:18 -04001743 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
Dmitry Torokhov968ac842005-05-29 02:28:29 -05001744
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001745 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001746 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1747 dev2->keybit[BIT_WORD(BTN_LEFT)] =
1748 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001750 if (input_register_device(priv->dev2))
1751 goto init_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 psmouse->protocol_handler = alps_process_byte;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001754 psmouse->poll = alps_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 psmouse->disconnect = alps_disconnect;
1756 psmouse->reconnect = alps_reconnect;
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001757 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001759 /* We are having trouble resyncing ALPS touchpads so disable it for now */
1760 psmouse->resync_time = 0;
1761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 return 0;
1763
1764init_fail:
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001765 psmouse_reset(psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001766 input_free_device(dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 kfree(priv);
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001768 psmouse->private = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return -1;
1770}
1771
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001772int alps_detect(struct psmouse *psmouse, bool set_properties)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001774 struct alps_data dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001776 if (alps_identify(psmouse, &dummy) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 return -1;
1778
1779 if (set_properties) {
1780 psmouse->vendor = "ALPS";
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001781 psmouse->name = dummy.flags & ALPS_DUALPOINT ?
Dmitry Torokhov968ac842005-05-29 02:28:29 -05001782 "DualPoint TouchPad" : "GlidePoint";
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001783 psmouse->model = dummy.proto_version << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 }
1785 return 0;
1786}
1787