blob: 9c97531bd2cd9932e6910401dd96eb50462dfbd6 [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
Kevin Cernekeed18e53f2013-02-21 22:58:20 -0800997static int alps_enter_command_mode(struct psmouse *psmouse)
Seth Forshee25bded72011-11-07 19:53:36 -0800998{
999 unsigned char param[4];
Seth Forshee25bded72011-11-07 19:53:36 -08001000
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001001 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001002 psmouse_err(psmouse, "failed to enter command mode\n");
1003 return -1;
1004 }
1005
Kevin Cernekee56fd3402013-02-13 22:24:22 -08001006 if (param[0] != 0x88 || (param[1] != 0x07 && param[1] != 0x08)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001007 psmouse_dbg(psmouse,
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001008 "unknown response while entering command mode\n");
Seth Forshee25bded72011-11-07 19:53:36 -08001009 return -1;
1010 }
Seth Forshee25bded72011-11-07 19:53:36 -08001011 return 0;
1012}
1013
1014static inline int alps_exit_command_mode(struct psmouse *psmouse)
1015{
1016 struct ps2dev *ps2dev = &psmouse->ps2dev;
1017 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
1018 return -1;
1019 return 0;
1020}
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022/*
1023 * For DualPoint devices select the device that should respond to
1024 * subsequent commands. It looks like glidepad is behind stickpointer,
1025 * I'd thought it would be other way around...
1026 */
Seth Forshee25bded72011-11-07 19:53:36 -08001027static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
1029 struct ps2dev *ps2dev = &psmouse->ps2dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
1031
1032 if (ps2_command(ps2dev, NULL, cmd) ||
1033 ps2_command(ps2dev, NULL, cmd) ||
1034 ps2_command(ps2dev, NULL, cmd) ||
1035 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1036 return -1;
1037
1038 /* we may get 3 more bytes, just ignore them */
Dmitry Torokhovc6117632005-06-01 02:39:51 -05001039 ps2_drain(ps2dev, 3, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041 return 0;
1042}
1043
Seth Forshee25bded72011-11-07 19:53:36 -08001044static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045{
1046 struct ps2dev *ps2dev = &psmouse->ps2dev;
1047
1048 /* Try ALPS magic knock - 4 disable before enable */
1049 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1050 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1051 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1052 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1053 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
1054 return -1;
1055
1056 /*
1057 * Switch mouse to poll (remote) mode so motion data will not
1058 * get in our way
1059 */
1060 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
1061}
1062
1063static int alps_get_status(struct psmouse *psmouse, char *param)
1064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001066 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return -1;
1068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return 0;
1070}
1071
1072/*
1073 * Turn touchpad tapping on or off. The sequences are:
1074 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1075 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1076 * My guess that 0xE9 (GetInfo) is here as a sync point.
1077 * For models that also have stickpointer (DualPoints) its tapping
1078 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1079 * we don't fiddle with it.
1080 */
1081static int alps_tap_mode(struct psmouse *psmouse, int enable)
1082{
1083 struct ps2dev *ps2dev = &psmouse->ps2dev;
1084 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
1085 unsigned char tap_arg = enable ? 0x0A : 0x00;
1086 unsigned char param[4];
1087
1088 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
1089 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1090 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1091 ps2_command(ps2dev, &tap_arg, cmd))
1092 return -1;
1093
1094 if (alps_get_status(psmouse, param))
1095 return -1;
1096
1097 return 0;
1098}
1099
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001100/*
1101 * alps_poll() - poll the touchpad for current motion packet.
1102 * Used in resync.
1103 */
1104static int alps_poll(struct psmouse *psmouse)
1105{
1106 struct alps_data *priv = psmouse->private;
Seth Forsheeb46615f2011-11-07 19:53:30 -08001107 unsigned char buf[sizeof(psmouse->packet)];
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001108 bool poll_failed;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001109
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001110 if (priv->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -08001111 alps_passthrough_mode_v2(psmouse, true);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001112
1113 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1114 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1115
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001116 if (priv->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -08001117 alps_passthrough_mode_v2(psmouse, false);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001118
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001119 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001120 return -1;
1121
1122 if ((psmouse->badbyte & 0xc8) == 0x08) {
1123/*
1124 * Poll the track stick ...
1125 */
1126 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
1127 return -1;
1128 }
1129
1130 memcpy(psmouse->packet, buf, sizeof(buf));
1131 return 0;
1132}
1133
Seth Forshee25bded72011-11-07 19:53:36 -08001134static int alps_hw_init_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
1136 struct alps_data *priv = psmouse->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001138 if ((priv->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -08001139 alps_passthrough_mode_v2(psmouse, true)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001143 if (alps_tap_mode(psmouse, true)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001144 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 return -1;
Peter Osterlund963f6262005-07-11 01:08:04 -05001146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Seth Forshee25bded72011-11-07 19:53:36 -08001148 if (alps_absolute_mode_v1_v2(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001149 psmouse_err(psmouse, "Failed to enable absolute mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 return -1;
1151 }
1152
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001153 if ((priv->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -08001154 alps_passthrough_mode_v2(psmouse, false)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001158 /* ALPS needs stream mode, otherwise it won't report any data */
1159 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001160 psmouse_err(psmouse, "Failed to enable stream mode\n");
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001161 return -1;
1162 }
1163
1164 return 0;
1165}
1166
Seth Forshee25bded72011-11-07 19:53:36 -08001167/*
Kevin Cernekeecd401202013-02-13 22:28:07 -08001168 * Enable or disable passthrough mode to the trackstick.
Seth Forshee25bded72011-11-07 19:53:36 -08001169 */
Kevin Cernekeecd401202013-02-13 22:28:07 -08001170static int alps_passthrough_mode_v3(struct psmouse *psmouse,
1171 int reg_base, bool enable)
Seth Forshee25bded72011-11-07 19:53:36 -08001172{
Kevin Cernekeecd401202013-02-13 22:28:07 -08001173 int reg_val, ret = -1;
Seth Forshee25bded72011-11-07 19:53:36 -08001174
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001175 if (alps_enter_command_mode(psmouse))
Seth Forshee25bded72011-11-07 19:53:36 -08001176 return -1;
1177
Kevin Cernekeecd401202013-02-13 22:28:07 -08001178 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008);
1179 if (reg_val == -1)
1180 goto error;
1181
Seth Forshee25bded72011-11-07 19:53:36 -08001182 if (enable)
1183 reg_val |= 0x01;
1184 else
1185 reg_val &= ~0x01;
1186
Kevin Cernekeecd401202013-02-13 22:28:07 -08001187 ret = __alps_command_mode_write_reg(psmouse, reg_val);
Seth Forshee25bded72011-11-07 19:53:36 -08001188
Kevin Cernekeecd401202013-02-13 22:28:07 -08001189error:
1190 if (alps_exit_command_mode(psmouse))
1191 ret = -1;
1192 return ret;
Seth Forshee25bded72011-11-07 19:53:36 -08001193}
1194
1195/* Must be in command mode when calling this function */
1196static int alps_absolute_mode_v3(struct psmouse *psmouse)
1197{
1198 int reg_val;
1199
1200 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1201 if (reg_val == -1)
1202 return -1;
1203
1204 reg_val |= 0x06;
1205 if (__alps_command_mode_write_reg(psmouse, reg_val))
1206 return -1;
1207
1208 return 0;
1209}
1210
Kevin Cernekeecd401202013-02-13 22:28:07 -08001211static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base)
1212{
1213 int ret = -EIO, reg_val;
1214
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001215 if (alps_enter_command_mode(psmouse))
Kevin Cernekeecd401202013-02-13 22:28:07 -08001216 goto error;
1217
1218 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
1219 if (reg_val == -1)
1220 goto error;
1221
1222 /* bit 7: trackstick is present */
1223 ret = reg_val & 0x80 ? 0 : -ENODEV;
1224
1225error:
1226 alps_exit_command_mode(psmouse);
1227 return ret;
1228}
1229
1230static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
1231{
1232 struct ps2dev *ps2dev = &psmouse->ps2dev;
1233 int ret = 0;
1234 unsigned char param[4];
1235
1236 if (alps_passthrough_mode_v3(psmouse, reg_base, true))
1237 return -EIO;
1238
1239 /*
1240 * E7 report for the trackstick
1241 *
1242 * There have been reports of failures to seem to trace back
1243 * to the above trackstick check failing. When these occur
1244 * this E7 report fails, so when that happens we continue
1245 * with the assumption that there isn't a trackstick after
1246 * all.
1247 */
1248 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) {
1249 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1250 ret = -ENODEV;
1251 } else {
1252 psmouse_dbg(psmouse,
1253 "trackstick E7 report: %2.2x %2.2x %2.2x\n",
1254 param[0], param[1], param[2]);
1255
1256 /*
1257 * Not sure what this does, but it is absolutely
1258 * essential. Without it, the touchpad does not
1259 * work at all and the trackstick just emits normal
1260 * PS/2 packets.
1261 */
1262 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1263 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1264 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1265 alps_command_mode_send_nibble(psmouse, 0x9) ||
1266 alps_command_mode_send_nibble(psmouse, 0x4)) {
1267 psmouse_err(psmouse,
1268 "Error sending magic E6 sequence\n");
1269 ret = -EIO;
1270 goto error;
1271 }
1272
1273 /*
1274 * This ensures the trackstick packets are in the format
1275 * supported by this driver. If bit 1 isn't set the packet
1276 * format is different.
1277 */
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001278 if (alps_enter_command_mode(psmouse) ||
Kevin Cernekeecd401202013-02-13 22:28:07 -08001279 alps_command_mode_write_reg(psmouse,
1280 reg_base + 0x08, 0x82) ||
1281 alps_exit_command_mode(psmouse))
1282 ret = -EIO;
1283 }
1284
1285error:
1286 if (alps_passthrough_mode_v3(psmouse, reg_base, false))
1287 ret = -EIO;
1288
1289 return ret;
1290}
1291
Seth Forshee25bded72011-11-07 19:53:36 -08001292static int alps_hw_init_v3(struct psmouse *psmouse)
1293{
Seth Forshee25bded72011-11-07 19:53:36 -08001294 struct ps2dev *ps2dev = &psmouse->ps2dev;
1295 int reg_val;
1296 unsigned char param[4];
1297
Kevin Cernekeecd401202013-02-13 22:28:07 -08001298 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE);
1299 if (reg_val == -EIO)
1300 goto error;
1301 if (reg_val == 0 &&
1302 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO)
Seth Forshee25bded72011-11-07 19:53:36 -08001303 goto error;
1304
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001305 if (alps_enter_command_mode(psmouse) ||
Kevin Cernekeecd401202013-02-13 22:28:07 -08001306 alps_absolute_mode_v3(psmouse)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001307 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1308 goto error;
1309 }
1310
1311 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1312 if (reg_val == -1)
1313 goto error;
1314 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1315 goto error;
1316
1317 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1318 if (reg_val == -1)
1319 goto error;
1320 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1321 goto error;
1322
1323 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1324 goto error;
1325 if (__alps_command_mode_write_reg(psmouse, 0x04))
1326 goto error;
1327
1328 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1329 goto error;
1330 if (__alps_command_mode_write_reg(psmouse, 0x03))
1331 goto error;
1332
1333 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1334 goto error;
1335 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1336 goto error;
1337
1338 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1339 goto error;
1340 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1341 goto error;
1342
Seth Forshee25bded72011-11-07 19:53:36 -08001343 alps_exit_command_mode(psmouse);
1344
1345 /* Set rate and enable data reporting */
1346 param[0] = 0x64;
1347 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1348 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1349 psmouse_err(psmouse, "Failed to enable data reporting\n");
1350 return -1;
1351 }
1352
1353 return 0;
1354
Seth Forshee25bded72011-11-07 19:53:36 -08001355error:
1356 /*
1357 * Leaving the touchpad in command mode will essentially render
1358 * it unusable until the machine reboots, so exit it here just
1359 * to be safe
1360 */
1361 alps_exit_command_mode(psmouse);
1362 return -1;
1363}
1364
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001365static int alps_hw_init_rushmore_v3(struct psmouse *psmouse)
1366{
Kevin Cernekeecd401202013-02-13 22:28:07 -08001367 struct alps_data *priv = psmouse->private;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001368 struct ps2dev *ps2dev = &psmouse->ps2dev;
1369 int reg_val, ret = -1;
1370
Kevin Cernekeecd401202013-02-13 22:28:07 -08001371 if (priv->flags & ALPS_DUALPOINT) {
1372 reg_val = alps_setup_trackstick_v3(psmouse,
1373 ALPS_REG_BASE_RUSHMORE);
1374 if (reg_val == -EIO)
1375 goto error;
1376 if (reg_val == -ENODEV)
1377 priv->flags &= ~ALPS_DUALPOINT;
1378 }
1379
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001380 if (alps_enter_command_mode(psmouse) ||
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001381 alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 ||
1382 alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00))
1383 goto error;
1384
1385 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6);
1386 if (reg_val == -1)
1387 goto error;
1388 if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd))
1389 goto error;
1390
1391 if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64))
1392 goto error;
1393
1394 /* enter absolute mode */
1395 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4);
1396 if (reg_val == -1)
1397 goto error;
1398 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02))
1399 goto error;
1400
1401 alps_exit_command_mode(psmouse);
1402 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1403
1404error:
1405 alps_exit_command_mode(psmouse);
1406 return ret;
1407}
1408
Seth Forshee25bded72011-11-07 19:53:36 -08001409/* Must be in command mode when calling this function */
1410static int alps_absolute_mode_v4(struct psmouse *psmouse)
1411{
1412 int reg_val;
1413
1414 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1415 if (reg_val == -1)
1416 return -1;
1417
1418 reg_val |= 0x02;
1419 if (__alps_command_mode_write_reg(psmouse, reg_val))
1420 return -1;
1421
1422 return 0;
1423}
1424
1425static int alps_hw_init_v4(struct psmouse *psmouse)
1426{
Seth Forshee25bded72011-11-07 19:53:36 -08001427 struct ps2dev *ps2dev = &psmouse->ps2dev;
1428 unsigned char param[4];
1429
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001430 if (alps_enter_command_mode(psmouse))
Seth Forshee25bded72011-11-07 19:53:36 -08001431 goto error;
1432
1433 if (alps_absolute_mode_v4(psmouse)) {
1434 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1435 goto error;
1436 }
1437
1438 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1439 goto error;
1440
1441 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1442 goto error;
1443
1444 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1445 goto error;
1446
1447 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1448 goto error;
1449
1450 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1451 goto error;
1452
1453 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1454 goto error;
1455
1456 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1457 goto error;
1458
1459 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1460 goto error;
1461
1462 alps_exit_command_mode(psmouse);
1463
1464 /*
1465 * This sequence changes the output from a 9-byte to an
1466 * 8-byte format. All the same data seems to be present,
1467 * just in a more compact format.
1468 */
1469 param[0] = 0xc8;
1470 param[1] = 0x64;
1471 param[2] = 0x50;
1472 if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1473 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1474 ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1475 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1476 return -1;
1477
1478 /* Set rate and enable data reporting */
1479 param[0] = 0x64;
1480 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1481 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1482 psmouse_err(psmouse, "Failed to enable data reporting\n");
1483 return -1;
1484 }
1485
1486 return 0;
1487
1488error:
1489 /*
1490 * Leaving the touchpad in command mode will essentially render
1491 * it unusable until the machine reboots, so exit it here just
1492 * to be safe
1493 */
1494 alps_exit_command_mode(psmouse);
1495 return -1;
1496}
1497
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001498static void alps_set_defaults(struct alps_data *priv)
Seth Forshee25bded72011-11-07 19:53:36 -08001499{
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001500 priv->byte0 = 0x8f;
1501 priv->mask0 = 0x8f;
1502 priv->flags = ALPS_DUALPOINT;
1503
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001504 priv->x_max = 2000;
1505 priv->y_max = 1400;
1506 priv->x_bits = 15;
1507 priv->y_bits = 11;
1508
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001509 switch (priv->proto_version) {
Seth Forshee25bded72011-11-07 19:53:36 -08001510 case ALPS_PROTO_V1:
1511 case ALPS_PROTO_V2:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001512 priv->hw_init = alps_hw_init_v1_v2;
1513 priv->process_packet = alps_process_packet_v1_v2;
1514 priv->set_abs_params = alps_set_abs_params_st;
Seth Forshee25bded72011-11-07 19:53:36 -08001515 break;
1516 case ALPS_PROTO_V3:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001517 priv->hw_init = alps_hw_init_v3;
1518 priv->process_packet = alps_process_packet_v3;
1519 priv->set_abs_params = alps_set_abs_params_mt;
Kevin Cernekeef85e5002013-02-13 22:26:11 -08001520 priv->decode_fields = alps_decode_pinnacle;
Kevin Cernekee50e8b212013-02-13 22:23:04 -08001521 priv->nibble_commands = alps_v3_nibble_commands;
1522 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
Seth Forshee25bded72011-11-07 19:53:36 -08001523 break;
1524 case ALPS_PROTO_V4:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001525 priv->hw_init = alps_hw_init_v4;
1526 priv->process_packet = alps_process_packet_v4;
1527 priv->set_abs_params = alps_set_abs_params_mt;
Kevin Cernekee50e8b212013-02-13 22:23:04 -08001528 priv->nibble_commands = alps_v4_nibble_commands;
1529 priv->addr_command = PSMOUSE_CMD_DISABLE;
Seth Forshee25bded72011-11-07 19:53:36 -08001530 break;
1531 }
Seth Forshee25bded72011-11-07 19:53:36 -08001532}
1533
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001534static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv,
1535 unsigned char *e7, unsigned char *ec)
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001536{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001537 const struct alps_model_info *model;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001538 int i;
1539
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001540 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1541 model = &alps_model_data[i];
1542
1543 if (!memcmp(e7, model->signature, sizeof(model->signature)) &&
1544 (!model->command_mode_resp ||
1545 model->command_mode_resp == ec[2])) {
1546
1547 priv->proto_version = model->proto_version;
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001548 alps_set_defaults(priv);
1549
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001550 priv->flags = model->flags;
1551 priv->byte0 = model->byte0;
1552 priv->mask0 = model->mask0;
1553
1554 return 0;
1555 }
1556 }
1557
1558 return -EINVAL;
1559}
1560
1561static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
1562{
1563 unsigned char e6[4], e7[4], ec[4];
1564
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001565 /*
1566 * First try "E6 report".
1567 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
1568 * The bits 0-2 of the first byte will be 1s if some buttons are
1569 * pressed.
1570 */
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001571 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1572 PSMOUSE_CMD_SETSCALE11, e6))
1573 return -EIO;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001574
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001575 if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100))
1576 return -EINVAL;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001577
1578 /*
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001579 * Now get the "E7" and "EC" reports. These will uniquely identify
1580 * most ALPS touchpads.
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001581 */
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001582 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1583 PSMOUSE_CMD_SETSCALE21, e7) ||
1584 alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1585 PSMOUSE_CMD_RESET_WRAP, ec) ||
1586 alps_exit_command_mode(psmouse))
1587 return -EIO;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001588
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001589 if (alps_match_table(psmouse, priv, e7, ec) == 0) {
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001590 return 0;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001591 } else if (ec[0] == 0x88 && ec[1] == 0x08) {
1592 priv->proto_version = ALPS_PROTO_V3;
1593 alps_set_defaults(priv);
1594
1595 priv->hw_init = alps_hw_init_rushmore_v3;
1596 priv->decode_fields = alps_decode_rushmore;
1597 priv->x_bits = 16;
1598 priv->y_bits = 12;
1599
Kevin Cernekeecd401202013-02-13 22:28:07 -08001600 /* hack to make addr_command, nibble_command available */
1601 psmouse->private = priv;
1602
1603 if (alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_RUSHMORE))
1604 priv->flags &= ~ALPS_DUALPOINT;
1605
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001606 return 0;
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001607 } else if (ec[0] == 0x88 && ec[1] == 0x07 &&
1608 ec[2] >= 0x90 && ec[2] <= 0x9d) {
1609 priv->proto_version = ALPS_PROTO_V3;
1610 alps_set_defaults(priv);
1611
1612 return 0;
1613 }
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001614
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001615 psmouse_info(psmouse,
1616 "Unknown ALPS touchpad: E7=%2.2x %2.2x %2.2x, EC=%2.2x %2.2x %2.2x\n",
1617 e7[0], e7[1], e7[2], ec[0], ec[1], ec[2]);
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001618
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001619 return -EINVAL;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001620}
1621
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001622static int alps_reconnect(struct psmouse *psmouse)
1623{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001624 struct alps_data *priv = psmouse->private;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001625
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001626 psmouse_reset(psmouse);
1627
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001628 if (alps_identify(psmouse, priv) < 0)
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001629 return -1;
1630
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001631 return priv->hw_init(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
1634static void alps_disconnect(struct psmouse *psmouse)
1635{
1636 struct alps_data *priv = psmouse->private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001637
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 psmouse_reset(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001639 del_timer_sync(&priv->timer);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001640 input_unregister_device(priv->dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 kfree(priv);
1642}
1643
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001644static void alps_set_abs_params_st(struct alps_data *priv,
1645 struct input_dev *dev1)
1646{
1647 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
1648 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
1649}
1650
1651static void alps_set_abs_params_mt(struct alps_data *priv,
1652 struct input_dev *dev1)
1653{
1654 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
1655 input_mt_init_slots(dev1, 2, 0);
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001656 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0);
1657 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001658
1659 set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
1660 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
1661 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
1662
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001663 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
1664 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001665}
1666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667int alps_init(struct psmouse *psmouse)
1668{
1669 struct alps_data *priv;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001670 struct input_dev *dev1 = psmouse->dev, *dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001672 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001673 dev2 = input_allocate_device();
1674 if (!priv || !dev2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 goto init_fail;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001676
1677 priv->dev2 = dev2;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001678 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
1679
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001680 psmouse->private = priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Seth Forshee25bded72011-11-07 19:53:36 -08001682 psmouse_reset(psmouse);
1683
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001684 if (alps_identify(psmouse, priv) < 0)
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001685 goto init_fail;
1686
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001687 if (priv->hw_init(psmouse))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 goto init_fail;
1689
Dmitry Torokhov7105d2e2009-12-11 23:54:54 -08001690 /*
1691 * Undo part of setup done for us by psmouse core since touchpad
1692 * is not a relative device.
1693 */
1694 __clear_bit(EV_REL, dev1->evbit);
1695 __clear_bit(REL_X, dev1->relbit);
1696 __clear_bit(REL_Y, dev1->relbit);
1697
1698 /*
1699 * Now set up our capabilities.
1700 */
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001701 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
1702 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
1703 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001704 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
1705 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001707 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
Seth Forshee25bded72011-11-07 19:53:36 -08001708
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001709 priv->set_abs_params(priv, dev1);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001710 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001712 if (priv->flags & ALPS_WHEEL) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001713 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
1714 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
1716
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001717 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001718 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
1719 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 }
1721
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001722 if (priv->flags & ALPS_FOUR_BUTTONS) {
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001723 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
1724 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
1725 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
1726 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
1727 } else {
1728 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
1729 }
1730
Dmitry Torokhov08ffce42006-06-26 01:45:10 -04001731 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001732 dev2->phys = priv->phys;
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001733 dev2->name = (priv->flags & ALPS_DUALPOINT) ?
1734 "DualPoint Stick" : "PS/2 Mouse";
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001735 dev2->id.bustype = BUS_I8042;
1736 dev2->id.vendor = 0x0002;
1737 dev2->id.product = PSMOUSE_ALPS;
1738 dev2->id.version = 0x0000;
Dmitry Torokhov1db3a342008-03-18 00:29:18 -04001739 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
Dmitry Torokhov968ac842005-05-29 02:28:29 -05001740
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001741 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001742 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1743 dev2->keybit[BIT_WORD(BTN_LEFT)] =
1744 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001746 if (input_register_device(priv->dev2))
1747 goto init_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
1749 psmouse->protocol_handler = alps_process_byte;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001750 psmouse->poll = alps_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 psmouse->disconnect = alps_disconnect;
1752 psmouse->reconnect = alps_reconnect;
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001753 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001755 /* We are having trouble resyncing ALPS touchpads so disable it for now */
1756 psmouse->resync_time = 0;
1757
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 return 0;
1759
1760init_fail:
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04001761 psmouse_reset(psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001762 input_free_device(dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 kfree(priv);
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001764 psmouse->private = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return -1;
1766}
1767
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001768int alps_detect(struct psmouse *psmouse, bool set_properties)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001770 struct alps_data dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001772 if (alps_identify(psmouse, &dummy) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 return -1;
1774
1775 if (set_properties) {
1776 psmouse->vendor = "ALPS";
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001777 psmouse->name = dummy.flags & ALPS_DUALPOINT ?
Dmitry Torokhov968ac842005-05-29 02:28:29 -05001778 "DualPoint TouchPad" : "GlidePoint";
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001779 psmouse->model = dummy.proto_version << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 }
1781 return 0;
1782}
1783