blob: 8c3017a92788738cd1c4348d13e5e6940a73b4ba [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
Yunkang Tang95f75e92013-12-01 22:33:52 -080073static const struct alps_nibble_commands alps_v6_nibble_commands[] = {
74 { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */
75 { PSMOUSE_CMD_SETRATE, 0x0a }, /* 1 */
76 { PSMOUSE_CMD_SETRATE, 0x14 }, /* 2 */
77 { PSMOUSE_CMD_SETRATE, 0x28 }, /* 3 */
78 { PSMOUSE_CMD_SETRATE, 0x3c }, /* 4 */
79 { PSMOUSE_CMD_SETRATE, 0x50 }, /* 5 */
80 { PSMOUSE_CMD_SETRATE, 0x64 }, /* 6 */
81 { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 7 */
82 { PSMOUSE_CMD_GETID, 0x00 }, /* 8 */
83 { PSMOUSE_CMD_GETINFO, 0x00 }, /* 9 */
84 { PSMOUSE_CMD_SETRES, 0x00 }, /* a */
85 { PSMOUSE_CMD_SETRES, 0x01 }, /* b */
86 { PSMOUSE_CMD_SETRES, 0x02 }, /* c */
87 { PSMOUSE_CMD_SETRES, 0x03 }, /* d */
88 { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* e */
89 { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */
90};
91
Seth Forshee25bded72011-11-07 19:53:36 -080092
Maxim Levitsky71bb21b2009-11-16 22:12:22 -080093#define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */
94#define ALPS_PASS 0x04 /* device has a pass-through port */
95
96#define ALPS_WHEEL 0x08 /* hardware wheel present */
97#define ALPS_FW_BK_1 0x10 /* front & back buttons present */
98#define ALPS_FW_BK_2 0x20 /* front & back buttons present */
99#define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800100#define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with
101 6-byte ALPS packet */
Hans de Goede40e8f532014-07-25 22:37:15 -0700102#define ALPS_IS_RUSHMORE 0x100 /* device is a rushmore */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Helge Dellere38de672006-09-10 21:54:39 -0400104static const struct alps_model_info alps_model_data[] = {
Seth Forshee25bded72011-11-07 19:53:36 -0800105 { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */
106 { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */
107 { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
108 { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
109 { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */
110 { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
111 { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
112 { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */
113 { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
114 { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
115 { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
116 { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */
117 { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */
118 { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 },
119 { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
120 { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
121 { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
122 { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800123 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
Seth Forshee25bded72011-11-07 19:53:36 -0800124 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800125 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
Yunkang Tang95f75e92013-12-01 22:33:52 -0800126 { { 0x73, 0x00, 0x14 }, 0x00, ALPS_PROTO_V6, 0xff, 0xff, ALPS_DUALPOINT }, /* Dell XT2 */
Seth Forshee25bded72011-11-07 19:53:36 -0800127 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
128 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
129 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
Seth Forshee25bded72011-11-07 19:53:36 -0800130 { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800133static void alps_set_abs_params_st(struct alps_data *priv,
134 struct input_dev *dev1);
135static void alps_set_abs_params_mt(struct alps_data *priv,
136 struct input_dev *dev1);
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*
139 * XXX - this entry is suspicious. First byte has zero lower nibble,
140 * which is what a normal mouse would report. Also, the value 0x0e
141 * isn't valid per PS/2 spec.
142 */
143
Seth Forsheed4b347b2011-11-07 19:53:15 -0800144/* Packet formats are described in Documentation/input/alps.txt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800146static bool alps_is_valid_first_byte(struct alps_data *priv,
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800147 unsigned char data)
148{
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800149 return (data & priv->mask0) == priv->byte0;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800150}
151
152static void alps_report_buttons(struct psmouse *psmouse,
153 struct input_dev *dev1, struct input_dev *dev2,
154 int left, int right, int middle)
155{
Martin Buckc91ed052010-03-13 22:23:58 -0800156 struct input_dev *dev;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800157
Martin Buckc91ed052010-03-13 22:23:58 -0800158 /*
159 * If shared button has already been reported on the
160 * other device (dev2) then this event should be also
161 * sent through that device.
162 */
163 dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1;
164 input_report_key(dev, BTN_LEFT, left);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800165
Martin Buckc91ed052010-03-13 22:23:58 -0800166 dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1;
167 input_report_key(dev, BTN_RIGHT, right);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800168
Martin Buckc91ed052010-03-13 22:23:58 -0800169 dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1;
170 input_report_key(dev, BTN_MIDDLE, middle);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800171
Martin Buckc91ed052010-03-13 22:23:58 -0800172 /*
173 * Sync the _other_ device now, we'll do the first
174 * device later once we report the rest of the events.
175 */
176 input_sync(dev2);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800177}
178
Seth Forshee25bded72011-11-07 19:53:36 -0800179static void alps_process_packet_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 struct alps_data *priv = psmouse->private;
182 unsigned char *packet = psmouse->packet;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500183 struct input_dev *dev = psmouse->dev;
184 struct input_dev *dev2 = priv->dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 int x, y, z, ges, fin, left, right, middle;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500186 int back = 0, forward = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800188 if (priv->proto_version == ALPS_PROTO_V1) {
Yotam Medinid2f40122006-05-29 23:30:36 -0400189 left = packet[2] & 0x10;
190 right = packet[2] & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 middle = 0;
192 x = packet[1] | ((packet[0] & 0x07) << 7);
193 y = packet[4] | ((packet[3] & 0x07) << 7);
194 z = packet[5];
195 } else {
196 left = packet[3] & 1;
197 right = packet[3] & 2;
198 middle = packet[3] & 4;
199 x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
200 y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
201 z = packet[5];
202 }
203
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800204 if (priv->flags & ALPS_FW_BK_1) {
Laszlo Kajan3c00bb92008-03-18 00:39:55 -0400205 back = packet[0] & 0x10;
206 forward = packet[2] & 4;
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500207 }
208
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800209 if (priv->flags & ALPS_FW_BK_2) {
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500210 back = packet[3] & 4;
211 forward = packet[2] & 4;
212 if ((middle = forward && back))
213 forward = back = 0;
214 }
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 ges = packet[2] & 1;
217 fin = packet[2] & 2;
218
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800219 if ((priv->flags & ALPS_DUALPOINT) && z == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
221 input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700222
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800223 alps_report_buttons(psmouse, dev2, dev, left, right, middle);
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 input_sync(dev2);
226 return;
227 }
228
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800229 alps_report_buttons(psmouse, dev, dev2, left, right, middle);
Ulrich Dangeld7ed5d82009-06-11 00:15:09 -0700230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* Convert hardware tap to a reasonable Z value */
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800232 if (ges && !fin)
233 z = 40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /*
236 * A "tap and drag" operation is reported by the hardware as a transition
237 * from (!fin && ges) to (fin && ges). This should be translated to the
238 * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
239 */
240 if (ges && fin && !priv->prev_fin) {
241 input_report_abs(dev, ABS_X, x);
242 input_report_abs(dev, ABS_Y, y);
243 input_report_abs(dev, ABS_PRESSURE, 0);
244 input_report_key(dev, BTN_TOOL_FINGER, 0);
245 input_sync(dev);
246 }
247 priv->prev_fin = fin;
248
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800249 if (z > 30)
250 input_report_key(dev, BTN_TOUCH, 1);
251 if (z < 25)
252 input_report_key(dev, BTN_TOUCH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 if (z > 0) {
255 input_report_abs(dev, ABS_X, x);
256 input_report_abs(dev, ABS_Y, y);
257 }
258
259 input_report_abs(dev, ABS_PRESSURE, z);
260 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
261
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800262 if (priv->flags & ALPS_WHEEL)
Vojtech Pavlike6c047b2005-09-04 01:40:43 -0500263 input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800265 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Ivan Casado Ruizc30b4c12005-06-01 02:39:18 -0500266 input_report_key(dev, BTN_FORWARD, forward);
267 input_report_key(dev, BTN_BACK, back);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800270 if (priv->flags & ALPS_FOUR_BUTTONS) {
Maxim Levitsky71bb21b2009-11-16 22:12:22 -0800271 input_report_key(dev, BTN_0, packet[2] & 4);
272 input_report_key(dev, BTN_1, packet[0] & 0x10);
273 input_report_key(dev, BTN_2, packet[3] & 4);
274 input_report_key(dev, BTN_3, packet[0] & 0x20);
275 }
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 input_sync(dev);
278}
279
Seth Forshee01ce6612011-11-07 19:54:13 -0800280/*
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800281 * Process bitmap data for V5 protocols. Return value is null.
282 *
283 * The bitmaps don't have enough data to track fingers, so this function
284 * only generates points representing a bounding box of at most two contacts.
Hans de Goede02d04252014-07-25 22:43:35 -0700285 * These two points are returned in fields->mt.
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800286 */
287static void alps_process_bitmap_dolphin(struct alps_data *priv,
Hans de Goede02d04252014-07-25 22:43:35 -0700288 struct alps_fields *fields)
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800289{
290 int box_middle_x, box_middle_y;
291 unsigned int x_map, y_map;
292 unsigned char start_bit, end_bit;
293 unsigned char x_msb, x_lsb, y_msb, y_lsb;
294
295 x_map = fields->x_map;
296 y_map = fields->y_map;
297
298 if (!x_map || !y_map)
299 return;
300
301 /* Get Most-significant and Least-significant bit */
302 x_msb = fls(x_map);
303 x_lsb = ffs(x_map);
304 y_msb = fls(y_map);
305 y_lsb = ffs(y_map);
306
307 /* Most-significant bit should never exceed max sensor line number */
308 if (x_msb > priv->x_bits || y_msb > priv->y_bits)
309 return;
310
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800311 if (fields->fingers > 1) {
312 start_bit = priv->x_bits - x_msb;
313 end_bit = priv->x_bits - x_lsb;
314 box_middle_x = (priv->x_max * (start_bit + end_bit)) /
315 (2 * (priv->x_bits - 1));
316
317 start_bit = y_lsb - 1;
318 end_bit = y_msb - 1;
319 box_middle_y = (priv->y_max * (start_bit + end_bit)) /
320 (2 * (priv->y_bits - 1));
Hans de Goede02d04252014-07-25 22:43:35 -0700321 fields->mt[0] = fields->st;
322 fields->mt[1].x = 2 * box_middle_x - fields->mt[0].x;
323 fields->mt[1].y = 2 * box_middle_y - fields->mt[0].y;
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800324 }
325}
326
Hans de Goede036e6c72014-07-25 22:38:51 -0700327static void alps_get_bitmap_points(unsigned int map,
328 struct alps_bitmap_point *low,
329 struct alps_bitmap_point *high,
330 int *fingers)
331{
332 struct alps_bitmap_point *point;
333 int i, bit, prev_bit = 0;
334
335 point = low;
336 for (i = 0; map != 0; i++, map >>= 1) {
337 bit = map & 1;
338 if (bit) {
339 if (!prev_bit) {
340 point->start_bit = i;
Hans de Goede105affb2014-07-25 22:41:51 -0700341 point->num_bits = 0;
Hans de Goede036e6c72014-07-25 22:38:51 -0700342 (*fingers)++;
343 }
344 point->num_bits++;
345 } else {
346 if (prev_bit)
347 point = high;
Hans de Goede036e6c72014-07-25 22:38:51 -0700348 }
349 prev_bit = bit;
350 }
351}
352
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800353/*
Seth Forshee01ce6612011-11-07 19:54:13 -0800354 * Process bitmap data from v3 and v4 protocols. Returns the number of
355 * fingers detected. A return value of 0 means at least one of the
356 * bitmaps was empty.
357 *
358 * The bitmaps don't have enough data to track fingers, so this function
359 * only generates points representing a bounding box of all contacts.
Hans de Goede02d04252014-07-25 22:43:35 -0700360 * These points are returned in fields->mt when the return value
Seth Forshee01ce6612011-11-07 19:54:13 -0800361 * is greater than 0.
362 */
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -0800363static int alps_process_bitmap(struct alps_data *priv,
Hans de Goede02d04252014-07-25 22:43:35 -0700364 struct alps_fields *fields)
Seth Forshee01ce6612011-11-07 19:54:13 -0800365{
Hans de Goede036e6c72014-07-25 22:38:51 -0700366 int i, fingers_x = 0, fingers_y = 0, fingers;
Seth Forshee01ce6612011-11-07 19:54:13 -0800367 struct alps_bitmap_point x_low = {0,}, x_high = {0,};
368 struct alps_bitmap_point y_low = {0,}, y_high = {0,};
Seth Forshee01ce6612011-11-07 19:54:13 -0800369
Hans de Goede02d04252014-07-25 22:43:35 -0700370 if (!fields->x_map || !fields->y_map)
Seth Forshee01ce6612011-11-07 19:54:13 -0800371 return 0;
372
Hans de Goede02d04252014-07-25 22:43:35 -0700373 alps_get_bitmap_points(fields->x_map, &x_low, &x_high, &fingers_x);
374 alps_get_bitmap_points(fields->y_map, &y_low, &y_high, &fingers_y);
Seth Forshee01ce6612011-11-07 19:54:13 -0800375
376 /*
377 * Fingers can overlap, so we use the maximum count of fingers
378 * on either axis as the finger count.
379 */
380 fingers = max(fingers_x, fingers_y);
381
382 /*
Hans de Goede20bea682014-07-25 22:33:33 -0700383 * If an axis reports only a single contact, we have overlapping or
384 * adjacent fingers. Divide the single contact between the two points.
Seth Forshee01ce6612011-11-07 19:54:13 -0800385 */
Hans de Goede20bea682014-07-25 22:33:33 -0700386 if (fingers_x == 1) {
Hans de Goede28835f42014-07-25 22:42:53 -0700387 i = (x_low.num_bits - 1) / 2;
Hans de Goede20bea682014-07-25 22:33:33 -0700388 x_low.num_bits = x_low.num_bits - i;
389 x_high.start_bit = x_low.start_bit + i;
390 x_high.num_bits = max(i, 1);
391 }
392 if (fingers_y == 1) {
Hans de Goede28835f42014-07-25 22:42:53 -0700393 i = (y_low.num_bits - 1) / 2;
Hans de Goede20bea682014-07-25 22:33:33 -0700394 y_low.num_bits = y_low.num_bits - i;
395 y_high.start_bit = y_low.start_bit + i;
396 y_high.num_bits = max(i, 1);
Seth Forshee01ce6612011-11-07 19:54:13 -0800397 }
398
Hans de Goede02d04252014-07-25 22:43:35 -0700399 fields->mt[0].x =
400 (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) /
401 (2 * (priv->x_bits - 1));
402 fields->mt[0].y =
403 (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) /
404 (2 * (priv->y_bits - 1));
Seth Forshee01ce6612011-11-07 19:54:13 -0800405
Hans de Goede02d04252014-07-25 22:43:35 -0700406 fields->mt[1].x =
407 (priv->x_max * (2 * x_high.start_bit + x_high.num_bits - 1)) /
408 (2 * (priv->x_bits - 1));
409 fields->mt[1].y =
410 (priv->y_max * (2 * y_high.start_bit + y_high.num_bits - 1)) /
411 (2 * (priv->y_bits - 1));
Seth Forshee01ce6612011-11-07 19:54:13 -0800412
Hans de Goede40e8f532014-07-25 22:37:15 -0700413 /* y-bitmap order is reversed, except on rushmore */
414 if (!(priv->flags & ALPS_IS_RUSHMORE)) {
Hans de Goede02d04252014-07-25 22:43:35 -0700415 fields->mt[0].y = priv->y_max - fields->mt[0].y;
416 fields->mt[1].y = priv->y_max - fields->mt[1].y;
Hans de Goede40e8f532014-07-25 22:37:15 -0700417 }
418
Seth Forshee01ce6612011-11-07 19:54:13 -0800419 return fingers;
420}
421
422static void alps_set_slot(struct input_dev *dev, int slot, bool active,
423 int x, int y)
424{
425 input_mt_slot(dev, slot);
426 input_mt_report_slot_state(dev, MT_TOOL_FINGER, active);
427 if (active) {
428 input_report_abs(dev, ABS_MT_POSITION_X, x);
429 input_report_abs(dev, ABS_MT_POSITION_Y, y);
430 }
431}
432
Hans de Goede02d04252014-07-25 22:43:35 -0700433static void alps_report_semi_mt_data(struct psmouse *psmouse, int num_fingers)
Seth Forshee01ce6612011-11-07 19:54:13 -0800434{
Hans de Goede02d04252014-07-25 22:43:35 -0700435 struct alps_data *priv = psmouse->private;
436 struct input_dev *dev = psmouse->dev;
437 struct alps_fields *f = &priv->f;
438
439 alps_set_slot(dev, 0, num_fingers != 0, f->mt[0].x, f->mt[0].y);
440 alps_set_slot(dev, 1, num_fingers == 2, f->mt[1].x, f->mt[1].y);
Seth Forshee01ce6612011-11-07 19:54:13 -0800441}
442
Seth Forshee25bded72011-11-07 19:53:36 -0800443static void alps_process_trackstick_packet_v3(struct psmouse *psmouse)
444{
445 struct alps_data *priv = psmouse->private;
446 unsigned char *packet = psmouse->packet;
447 struct input_dev *dev = priv->dev2;
448 int x, y, z, left, right, middle;
449
450 /* Sanity check packet */
451 if (!(packet[0] & 0x40)) {
452 psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n");
453 return;
454 }
455
456 /*
457 * There's a special packet that seems to indicate the end
458 * of a stream of trackstick data. Filter these out.
459 */
460 if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f)
461 return;
462
463 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f));
464 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f));
465 z = (packet[4] & 0x7c) >> 2;
466
467 /*
468 * The x and y values tend to be quite large, and when used
469 * alone the trackstick is difficult to use. Scale them down
470 * to compensate.
471 */
472 x /= 8;
473 y /= 8;
474
475 input_report_rel(dev, REL_X, x);
476 input_report_rel(dev, REL_Y, -y);
477
478 /*
479 * Most ALPS models report the trackstick buttons in the touchpad
480 * packets, but a few report them here. No reliable way has been
481 * found to differentiate between the models upfront, so we enable
482 * the quirk in response to seeing a button press in the trackstick
483 * packet.
484 */
485 left = packet[3] & 0x01;
486 right = packet[3] & 0x02;
487 middle = packet[3] & 0x04;
488
489 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) &&
490 (left || right || middle))
491 priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS;
492
493 if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) {
494 input_report_key(dev, BTN_LEFT, left);
495 input_report_key(dev, BTN_RIGHT, right);
496 input_report_key(dev, BTN_MIDDLE, middle);
497 }
498
499 input_sync(dev);
500 return;
501}
502
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800503static void alps_decode_buttons_v3(struct alps_fields *f, unsigned char *p)
504{
505 f->left = !!(p[3] & 0x01);
506 f->right = !!(p[3] & 0x02);
507 f->middle = !!(p[3] & 0x04);
508
509 f->ts_left = !!(p[3] & 0x10);
510 f->ts_right = !!(p[3] & 0x20);
511 f->ts_middle = !!(p[3] & 0x40);
512}
513
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800514static void alps_decode_pinnacle(struct alps_fields *f, unsigned char *p,
515 struct psmouse *psmouse)
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800516{
517 f->first_mp = !!(p[4] & 0x40);
518 f->is_mp = !!(p[0] & 0x40);
519
520 f->fingers = (p[5] & 0x3) + 1;
521 f->x_map = ((p[4] & 0x7e) << 8) |
522 ((p[1] & 0x7f) << 2) |
523 ((p[0] & 0x30) >> 4);
524 f->y_map = ((p[3] & 0x70) << 4) |
525 ((p[2] & 0x7f) << 1) |
526 (p[4] & 0x01);
527
Hans de Goede02d04252014-07-25 22:43:35 -0700528 f->st.x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) |
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800529 ((p[0] & 0x30) >> 4);
Hans de Goede02d04252014-07-25 22:43:35 -0700530 f->st.y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f);
531 f->pressure = p[5] & 0x7f;
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800532
533 alps_decode_buttons_v3(f, p);
534}
535
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800536static void alps_decode_rushmore(struct alps_fields *f, unsigned char *p,
537 struct psmouse *psmouse)
Kevin Cernekee1302bac2013-02-13 22:27:08 -0800538{
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800539 alps_decode_pinnacle(f, p, psmouse);
Kevin Cernekee1302bac2013-02-13 22:27:08 -0800540
Yunkang Tangf105e342014-07-25 22:29:24 -0700541 /* Rushmore's packet decode has a bit difference with Pinnacle's */
542 f->is_mp = !!(p[5] & 0x40);
543 f->fingers = max((p[5] & 0x3), ((p[5] >> 2) & 0x3)) + 1;
Kevin Cernekee1302bac2013-02-13 22:27:08 -0800544 f->x_map |= (p[5] & 0x10) << 11;
545 f->y_map |= (p[5] & 0x20) << 6;
546}
547
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800548static void alps_decode_dolphin(struct alps_fields *f, unsigned char *p,
549 struct psmouse *psmouse)
Dave Turvene75af9e52013-02-21 22:58:28 -0800550{
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800551 u64 palm_data = 0;
552 struct alps_data *priv = psmouse->private;
553
Dave Turvene75af9e52013-02-21 22:58:28 -0800554 f->first_mp = !!(p[0] & 0x02);
555 f->is_mp = !!(p[0] & 0x20);
556
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800557 if (!f->is_mp) {
Hans de Goede02d04252014-07-25 22:43:35 -0700558 f->st.x = ((p[1] & 0x7f) | ((p[4] & 0x0f) << 7));
559 f->st.y = ((p[2] & 0x7f) | ((p[4] & 0xf0) << 3));
560 f->pressure = (p[0] & 4) ? 0 : p[5] & 0x7f;
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800561 alps_decode_buttons_v3(f, p);
562 } else {
563 f->fingers = ((p[0] & 0x6) >> 1 |
Dave Turvene75af9e52013-02-21 22:58:28 -0800564 (p[0] & 0x10) >> 2);
Dave Turvene75af9e52013-02-21 22:58:28 -0800565
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800566 palm_data = (p[1] & 0x7f) |
567 ((p[2] & 0x7f) << 7) |
568 ((p[4] & 0x7f) << 14) |
569 ((p[5] & 0x7f) << 21) |
570 ((p[3] & 0x07) << 28) |
571 (((u64)p[3] & 0x70) << 27) |
572 (((u64)p[0] & 0x01) << 34);
Dave Turvene75af9e52013-02-21 22:58:28 -0800573
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800574 /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */
575 f->y_map = palm_data & (BIT(priv->y_bits) - 1);
576
577 /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */
578 f->x_map = (palm_data >> priv->y_bits) &
579 (BIT(priv->x_bits) - 1);
580 }
Dave Turvene75af9e52013-02-21 22:58:28 -0800581}
582
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800583static void alps_process_touchpad_packet_v3_v5(struct psmouse *psmouse)
Seth Forshee25bded72011-11-07 19:53:36 -0800584{
585 struct alps_data *priv = psmouse->private;
586 unsigned char *packet = psmouse->packet;
587 struct input_dev *dev = psmouse->dev;
588 struct input_dev *dev2 = priv->dev2;
Hans de Goede02d04252014-07-25 22:43:35 -0700589 struct alps_fields *f = &priv->f;
590 int fingers = 0;
Kevin Cernekeef85e5002013-02-13 22:26:11 -0800591
Hans de Goede02d04252014-07-25 22:43:35 -0700592 memset(f, 0, sizeof(*f));
593
594 priv->decode_fields(f, packet, psmouse);
Seth Forshee25bded72011-11-07 19:53:36 -0800595
596 /*
Seth Forshee01ce6612011-11-07 19:54:13 -0800597 * There's no single feature of touchpad position and bitmap packets
598 * that can be used to distinguish between them. We rely on the fact
599 * that a bitmap packet should always follow a position packet with
600 * bit 6 of packet[4] set.
Seth Forshee25bded72011-11-07 19:53:36 -0800601 */
602 if (priv->multi_packet) {
Seth Forshee25bded72011-11-07 19:53:36 -0800603 /*
604 * Sometimes a position packet will indicate a multi-packet
605 * sequence, but then what follows is another position
606 * packet. Check for this, and when it happens process the
607 * position packet as usual.
608 */
Hans de Goede02d04252014-07-25 22:43:35 -0700609 if (f->is_mp) {
610 fingers = f->fingers;
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800611 if (priv->proto_version == ALPS_PROTO_V3) {
Hans de Goede02d04252014-07-25 22:43:35 -0700612 if (alps_process_bitmap(priv, f) == 0)
Hans de Goede20bea682014-07-25 22:33:33 -0700613 fingers = 0; /* Use st data */
Seth Forshee01ce6612011-11-07 19:54:13 -0800614
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800615 /* Now process position packet */
Hans de Goede02d04252014-07-25 22:43:35 -0700616 priv->decode_fields(f, priv->multi_data,
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800617 psmouse);
618 } else {
619 /*
620 * Because Dolphin uses position packet's
621 * coordinate data as Pt1 and uses it to
622 * calculate Pt2, so we need to do position
623 * packet decode first.
624 */
Hans de Goede02d04252014-07-25 22:43:35 -0700625 priv->decode_fields(f, priv->multi_data,
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800626 psmouse);
627
628 /*
629 * Since Dolphin's finger number is reliable,
630 * there is no need to compare with bmap_fn.
631 */
Hans de Goede02d04252014-07-25 22:43:35 -0700632 alps_process_bitmap_dolphin(priv, f);
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800633 }
Seth Forshee01ce6612011-11-07 19:54:13 -0800634 } else {
635 priv->multi_packet = 0;
Seth Forshee25bded72011-11-07 19:53:36 -0800636 }
637 }
638
Seth Forshee01ce6612011-11-07 19:54:13 -0800639 /*
640 * Bit 6 of byte 0 is not usually set in position packets. The only
641 * times it seems to be set is in situations where the data is
642 * suspect anyway, e.g. a palm resting flat on the touchpad. Given
643 * this combined with the fact that this bit is useful for filtering
644 * out misidentified bitmap packets, we reject anything with this
645 * bit set.
646 */
Hans de Goede02d04252014-07-25 22:43:35 -0700647 if (f->is_mp)
Seth Forshee01ce6612011-11-07 19:54:13 -0800648 return;
649
Hans de Goede02d04252014-07-25 22:43:35 -0700650 if (!priv->multi_packet && f->first_mp) {
Seth Forshee25bded72011-11-07 19:53:36 -0800651 priv->multi_packet = 1;
Seth Forshee01ce6612011-11-07 19:54:13 -0800652 memcpy(priv->multi_data, packet, sizeof(priv->multi_data));
653 return;
654 }
655
656 priv->multi_packet = 0;
Seth Forshee25bded72011-11-07 19:53:36 -0800657
Seth Forshee25bded72011-11-07 19:53:36 -0800658 /*
659 * Sometimes the hardware sends a single packet with z = 0
660 * in the middle of a stream. Real releases generate packets
661 * with x, y, and z all zero, so these seem to be flukes.
662 * Ignore them.
663 */
Hans de Goede02d04252014-07-25 22:43:35 -0700664 if (f->st.x && f->st.y && !f->pressure)
Seth Forshee25bded72011-11-07 19:53:36 -0800665 return;
666
Seth Forshee01ce6612011-11-07 19:54:13 -0800667 /*
668 * If we don't have MT data or the bitmaps were empty, we have
669 * to rely on ST data.
670 */
671 if (!fingers) {
Hans de Goede02d04252014-07-25 22:43:35 -0700672 f->mt[0].x = f->st.x;
673 f->mt[0].y = f->st.y;
674 fingers = f->pressure > 0 ? 1 : 0;
Seth Forshee01ce6612011-11-07 19:54:13 -0800675 }
676
Hans de Goede02d04252014-07-25 22:43:35 -0700677 if (f->pressure >= 64)
Seth Forshee25bded72011-11-07 19:53:36 -0800678 input_report_key(dev, BTN_TOUCH, 1);
679 else
680 input_report_key(dev, BTN_TOUCH, 0);
681
Hans de Goede02d04252014-07-25 22:43:35 -0700682 alps_report_semi_mt_data(psmouse, fingers);
Seth Forshee01ce6612011-11-07 19:54:13 -0800683
Dmitry Torokhov616575c2012-05-10 22:31:59 -0700684 input_mt_report_finger_count(dev, fingers);
Seth Forshee01ce6612011-11-07 19:54:13 -0800685
Hans de Goede02d04252014-07-25 22:43:35 -0700686 input_report_key(dev, BTN_LEFT, f->left);
687 input_report_key(dev, BTN_RIGHT, f->right);
688 input_report_key(dev, BTN_MIDDLE, f->middle);
Seth Forshee01ce6612011-11-07 19:54:13 -0800689
Hans de Goede02d04252014-07-25 22:43:35 -0700690 if (f->pressure > 0) {
691 input_report_abs(dev, ABS_X, f->st.x);
692 input_report_abs(dev, ABS_Y, f->st.y);
Seth Forshee25bded72011-11-07 19:53:36 -0800693 }
Hans de Goede02d04252014-07-25 22:43:35 -0700694 input_report_abs(dev, ABS_PRESSURE, f->pressure);
Seth Forshee25bded72011-11-07 19:53:36 -0800695
Seth Forshee25bded72011-11-07 19:53:36 -0800696 input_sync(dev);
697
698 if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) {
Hans de Goede02d04252014-07-25 22:43:35 -0700699 input_report_key(dev2, BTN_LEFT, f->ts_left);
700 input_report_key(dev2, BTN_RIGHT, f->ts_right);
701 input_report_key(dev2, BTN_MIDDLE, f->ts_middle);
Seth Forshee25bded72011-11-07 19:53:36 -0800702 input_sync(dev2);
703 }
704}
705
706static void alps_process_packet_v3(struct psmouse *psmouse)
707{
708 unsigned char *packet = psmouse->packet;
709
710 /*
711 * v3 protocol packets come in three types, two representing
712 * touchpad data and one representing trackstick data.
713 * Trackstick packets seem to be distinguished by always
714 * having 0x3f in the last byte. This value has never been
715 * observed in the last byte of either of the other types
716 * of packets.
717 */
718 if (packet[5] == 0x3f) {
719 alps_process_trackstick_packet_v3(psmouse);
720 return;
721 }
722
Yunkang Tangee65d4b2013-12-26 14:54:19 -0800723 alps_process_touchpad_packet_v3_v5(psmouse);
Seth Forshee25bded72011-11-07 19:53:36 -0800724}
725
Yunkang Tang95f75e92013-12-01 22:33:52 -0800726static void alps_process_packet_v6(struct psmouse *psmouse)
727{
728 struct alps_data *priv = psmouse->private;
729 unsigned char *packet = psmouse->packet;
730 struct input_dev *dev = psmouse->dev;
731 struct input_dev *dev2 = priv->dev2;
732 int x, y, z, left, right, middle;
733
734 /*
735 * We can use Byte5 to distinguish if the packet is from Touchpad
736 * or Trackpoint.
737 * Touchpad: 0 - 0x7E
738 * Trackpoint: 0x7F
739 */
740 if (packet[5] == 0x7F) {
741 /* It should be a DualPoint when received Trackpoint packet */
742 if (!(priv->flags & ALPS_DUALPOINT))
743 return;
744
745 /* Trackpoint packet */
746 x = packet[1] | ((packet[3] & 0x20) << 2);
747 y = packet[2] | ((packet[3] & 0x40) << 1);
748 z = packet[4];
749 left = packet[3] & 0x01;
750 right = packet[3] & 0x02;
751 middle = packet[3] & 0x04;
752
753 /* To prevent the cursor jump when finger lifted */
754 if (x == 0x7F && y == 0x7F && z == 0x7F)
755 x = y = z = 0;
756
757 /* Divide 4 since trackpoint's speed is too fast */
758 input_report_rel(dev2, REL_X, (char)x / 4);
759 input_report_rel(dev2, REL_Y, -((char)y / 4));
760
761 input_report_key(dev2, BTN_LEFT, left);
762 input_report_key(dev2, BTN_RIGHT, right);
763 input_report_key(dev2, BTN_MIDDLE, middle);
764
765 input_sync(dev2);
766 return;
767 }
768
769 /* Touchpad packet */
770 x = packet[1] | ((packet[3] & 0x78) << 4);
771 y = packet[2] | ((packet[4] & 0x78) << 4);
772 z = packet[5];
773 left = packet[3] & 0x01;
774 right = packet[3] & 0x02;
775
776 if (z > 30)
777 input_report_key(dev, BTN_TOUCH, 1);
778 if (z < 25)
779 input_report_key(dev, BTN_TOUCH, 0);
780
781 if (z > 0) {
782 input_report_abs(dev, ABS_X, x);
783 input_report_abs(dev, ABS_Y, y);
784 }
785
786 input_report_abs(dev, ABS_PRESSURE, z);
787 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
788
789 /* v6 touchpad does not have middle button */
790 input_report_key(dev, BTN_LEFT, left);
791 input_report_key(dev, BTN_RIGHT, right);
792
793 input_sync(dev);
794}
795
Seth Forshee25bded72011-11-07 19:53:36 -0800796static void alps_process_packet_v4(struct psmouse *psmouse)
797{
George Pantalos3b7e09f2012-05-10 22:31:59 -0700798 struct alps_data *priv = psmouse->private;
Seth Forshee25bded72011-11-07 19:53:36 -0800799 unsigned char *packet = psmouse->packet;
800 struct input_dev *dev = psmouse->dev;
Hans de Goede02d04252014-07-25 22:43:35 -0700801 struct alps_fields *f = &priv->f;
802 int offset, fingers = 0;
George Pantalos3b7e09f2012-05-10 22:31:59 -0700803
804 /*
805 * v4 has a 6-byte encoding for bitmap data, but this data is
806 * broken up between 3 normal packets. Use priv->multi_packet to
807 * track our position in the bitmap packet.
808 */
809 if (packet[6] & 0x40) {
810 /* sync, reset position */
811 priv->multi_packet = 0;
812 }
813
814 if (WARN_ON_ONCE(priv->multi_packet > 2))
815 return;
816
817 offset = 2 * priv->multi_packet;
818 priv->multi_data[offset] = packet[6];
819 priv->multi_data[offset + 1] = packet[7];
820
821 if (++priv->multi_packet > 2) {
822 priv->multi_packet = 0;
823
Hans de Goede02d04252014-07-25 22:43:35 -0700824 f->x_map = ((priv->multi_data[2] & 0x1f) << 10) |
George Pantalos3b7e09f2012-05-10 22:31:59 -0700825 ((priv->multi_data[3] & 0x60) << 3) |
826 ((priv->multi_data[0] & 0x3f) << 2) |
827 ((priv->multi_data[1] & 0x60) >> 5);
Hans de Goede02d04252014-07-25 22:43:35 -0700828 f->y_map = ((priv->multi_data[5] & 0x01) << 10) |
George Pantalos3b7e09f2012-05-10 22:31:59 -0700829 ((priv->multi_data[3] & 0x1f) << 5) |
830 (priv->multi_data[1] & 0x1f);
831
Hans de Goede02d04252014-07-25 22:43:35 -0700832 f->fingers = alps_process_bitmap(priv, f);
George Pantalos3b7e09f2012-05-10 22:31:59 -0700833 }
Seth Forshee25bded72011-11-07 19:53:36 -0800834
Hans de Goede02d04252014-07-25 22:43:35 -0700835 f->left = packet[4] & 0x01;
836 f->right = packet[4] & 0x02;
Seth Forshee25bded72011-11-07 19:53:36 -0800837
Hans de Goede02d04252014-07-25 22:43:35 -0700838 f->st.x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
839 ((packet[0] & 0x30) >> 4);
840 f->st.y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
841 f->pressure = packet[5] & 0x7f;
Seth Forshee25bded72011-11-07 19:53:36 -0800842
George Pantalos3b7e09f2012-05-10 22:31:59 -0700843 /*
844 * If there were no contacts in the bitmap, use ST
845 * points in MT reports.
846 * If there were two contacts or more, report MT data.
847 */
Hans de Goede02d04252014-07-25 22:43:35 -0700848 if (f->fingers < 2) {
849 f->mt[0].x = f->st.x;
850 f->mt[0].y = f->st.y;
851 fingers = f->pressure > 0 ? 1 : 0;
George Pantalos3b7e09f2012-05-10 22:31:59 -0700852 } else {
Hans de Goede02d04252014-07-25 22:43:35 -0700853 fingers = f->fingers;
George Pantalos3b7e09f2012-05-10 22:31:59 -0700854 }
855
Hans de Goede02d04252014-07-25 22:43:35 -0700856 if (f->pressure >= 64)
Seth Forshee25bded72011-11-07 19:53:36 -0800857 input_report_key(dev, BTN_TOUCH, 1);
858 else
859 input_report_key(dev, BTN_TOUCH, 0);
860
Hans de Goede02d04252014-07-25 22:43:35 -0700861 alps_report_semi_mt_data(psmouse, fingers);
George Pantalos3b7e09f2012-05-10 22:31:59 -0700862
Dmitry Torokhov616575c2012-05-10 22:31:59 -0700863 input_mt_report_finger_count(dev, fingers);
George Pantalos3b7e09f2012-05-10 22:31:59 -0700864
Hans de Goede02d04252014-07-25 22:43:35 -0700865 input_report_key(dev, BTN_LEFT, f->left);
866 input_report_key(dev, BTN_RIGHT, f->right);
George Pantalos3b7e09f2012-05-10 22:31:59 -0700867
Hans de Goede02d04252014-07-25 22:43:35 -0700868 if (f->pressure > 0) {
869 input_report_abs(dev, ABS_X, f->st.x);
870 input_report_abs(dev, ABS_Y, f->st.y);
Seth Forshee25bded72011-11-07 19:53:36 -0800871 }
Hans de Goede02d04252014-07-25 22:43:35 -0700872 input_report_abs(dev, ABS_PRESSURE, f->pressure);
Seth Forshee25bded72011-11-07 19:53:36 -0800873
Seth Forshee25bded72011-11-07 19:53:36 -0800874 input_sync(dev);
875}
876
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800877static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
878 unsigned char packet[],
879 bool report_buttons)
880{
881 struct alps_data *priv = psmouse->private;
882 struct input_dev *dev2 = priv->dev2;
883
884 if (report_buttons)
885 alps_report_buttons(psmouse, dev2, psmouse->dev,
886 packet[0] & 1, packet[0] & 2, packet[0] & 4);
887
888 input_report_rel(dev2, REL_X,
889 packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
890 input_report_rel(dev2, REL_Y,
891 packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
892
893 input_sync(dev2);
894}
895
896static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
898 struct alps_data *priv = psmouse->private;
899
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800900 if (psmouse->pktcnt < 6)
901 return PSMOUSE_GOOD_DATA;
902
903 if (psmouse->pktcnt == 6) {
904 /*
905 * Start a timer to flush the packet if it ends up last
906 * 6-byte packet in the stream. Timer needs to fire
907 * psmouse core times out itself. 20 ms should be enough
908 * to decide if we are getting more data or not.
909 */
910 mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20));
911 return PSMOUSE_GOOD_DATA;
912 }
913
914 del_timer(&priv->timer);
915
916 if (psmouse->packet[6] & 0x80) {
917
918 /*
919 * Highest bit is set - that means we either had
920 * complete ALPS packet and this is start of the
921 * next packet or we got garbage.
922 */
923
924 if (((psmouse->packet[3] |
925 psmouse->packet[4] |
926 psmouse->packet[5]) & 0x80) ||
Kevin Cernekee99df65e2013-02-13 20:56:33 -0800927 (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700928 psmouse_dbg(psmouse,
Andy Shevchenko3b112922012-10-30 00:24:41 -0700929 "refusing packet %4ph (suspected interleaved ps/2)\n",
930 psmouse->packet + 3);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800931 return PSMOUSE_BAD_DATA;
932 }
933
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800934 priv->process_packet(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800935
936 /* Continue with the next packet */
937 psmouse->packet[0] = psmouse->packet[6];
938 psmouse->pktcnt = 1;
939
940 } else {
941
942 /*
943 * High bit is 0 - that means that we indeed got a PS/2
944 * packet in the middle of ALPS packet.
945 *
946 * There is also possibility that we got 6-byte ALPS
947 * packet followed by 3-byte packet from trackpoint. We
948 * can not distinguish between these 2 scenarios but
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700949 * because the latter is unlikely to happen in course of
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800950 * normal operation (user would need to press all
951 * buttons on the pad and start moving trackpoint
952 * without touching the pad surface) we assume former.
953 * Even if we are wrong the wost thing that would happen
954 * the cursor would jump but we should not get protocol
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700955 * de-synchronization.
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800956 */
957
958 alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3],
959 false);
960
961 /*
962 * Continue with the standard ALPS protocol handling,
963 * but make sure we won't process it as an interleaved
964 * packet again, which may happen if all buttons are
965 * pressed. To avoid this let's reset the 4th bit which
966 * is normally 1.
967 */
968 psmouse->packet[3] = psmouse->packet[6] & 0xf7;
969 psmouse->pktcnt = 4;
970 }
971
972 return PSMOUSE_GOOD_DATA;
973}
974
975static void alps_flush_packet(unsigned long data)
976{
977 struct psmouse *psmouse = (struct psmouse *)data;
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800978 struct alps_data *priv = psmouse->private;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800979
980 serio_pause_rx(psmouse->ps2dev.serio);
981
Seth Forsheeb46615f2011-11-07 19:53:30 -0800982 if (psmouse->pktcnt == psmouse->pktsize) {
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800983
984 /*
985 * We did not any more data in reasonable amount of time.
986 * Validate the last 3 bytes and process as a standard
987 * ALPS packet.
988 */
989 if ((psmouse->packet[3] |
990 psmouse->packet[4] |
991 psmouse->packet[5]) & 0x80) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700992 psmouse_dbg(psmouse,
Andy Shevchenko3b112922012-10-30 00:24:41 -0700993 "refusing packet %3ph (suspected interleaved ps/2)\n",
994 psmouse->packet + 3);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800995 } else {
Kevin Cernekee24af5cb2013-02-13 22:22:08 -0800996 priv->process_packet(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -0800997 }
998 psmouse->pktcnt = 0;
999 }
1000
1001 serio_continue_rx(psmouse->ps2dev.serio);
1002}
1003
1004static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
1005{
1006 struct alps_data *priv = psmouse->private;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
1009 if (psmouse->pktcnt == 3) {
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001010 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
1011 true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 return PSMOUSE_FULL_PACKET;
1013 }
1014 return PSMOUSE_GOOD_DATA;
1015 }
1016
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001017 /* Check for PS/2 packet stuffed in the middle of ALPS packet. */
1018
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001019 if ((priv->flags & ALPS_PS2_INTERLEAVED) &&
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001020 psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) {
1021 return alps_handle_interleaved_ps2(psmouse);
1022 }
1023
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001024 if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001025 psmouse_dbg(psmouse,
1026 "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n",
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001027 psmouse->packet[0], priv->mask0, priv->byte0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 return PSMOUSE_BAD_DATA;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Seth Forsheeb46615f2011-11-07 19:53:30 -08001031 /* Bytes 2 - pktsize should have 0 in the highest bit */
Yunkang Tang95f75e92013-12-01 22:33:52 -08001032 if ((priv->proto_version < ALPS_PROTO_V5) &&
Dave Turvene75af9e52013-02-21 22:58:28 -08001033 psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001034 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001035 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
1036 psmouse->pktcnt - 1,
1037 psmouse->packet[psmouse->pktcnt - 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 return PSMOUSE_BAD_DATA;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Seth Forsheeb46615f2011-11-07 19:53:30 -08001041 if (psmouse->pktcnt == psmouse->pktsize) {
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001042 priv->process_packet(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 return PSMOUSE_FULL_PACKET;
1044 }
1045
1046 return PSMOUSE_GOOD_DATA;
1047}
1048
Seth Forshee25bded72011-11-07 19:53:36 -08001049static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble)
1050{
1051 struct ps2dev *ps2dev = &psmouse->ps2dev;
1052 struct alps_data *priv = psmouse->private;
1053 int command;
1054 unsigned char *param;
1055 unsigned char dummy[4];
1056
1057 BUG_ON(nibble > 0xf);
1058
1059 command = priv->nibble_commands[nibble].command;
1060 param = (command & 0x0f00) ?
1061 dummy : (unsigned char *)&priv->nibble_commands[nibble].data;
1062
1063 if (ps2_command(ps2dev, param, command))
1064 return -1;
1065
1066 return 0;
1067}
1068
1069static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr)
1070{
1071 struct ps2dev *ps2dev = &psmouse->ps2dev;
1072 struct alps_data *priv = psmouse->private;
1073 int i, nibble;
1074
1075 if (ps2_command(ps2dev, NULL, priv->addr_command))
1076 return -1;
1077
1078 for (i = 12; i >= 0; i -= 4) {
1079 nibble = (addr >> i) & 0xf;
1080 if (alps_command_mode_send_nibble(psmouse, nibble))
1081 return -1;
1082 }
1083
1084 return 0;
1085}
1086
1087static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
1088{
1089 struct ps2dev *ps2dev = &psmouse->ps2dev;
1090 unsigned char param[4];
1091
1092 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1093 return -1;
1094
1095 /*
1096 * The address being read is returned in the first two bytes
1097 * of the result. Check that this address matches the expected
1098 * address.
1099 */
1100 if (addr != ((param[0] << 8) | param[1]))
1101 return -1;
1102
1103 return param[2];
1104}
1105
1106static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr)
1107{
1108 if (alps_command_mode_set_addr(psmouse, addr))
1109 return -1;
1110 return __alps_command_mode_read_reg(psmouse, addr);
1111}
1112
1113static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value)
1114{
1115 if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf))
1116 return -1;
1117 if (alps_command_mode_send_nibble(psmouse, value & 0xf))
1118 return -1;
1119 return 0;
1120}
1121
1122static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
1123 u8 value)
1124{
1125 if (alps_command_mode_set_addr(psmouse, addr))
1126 return -1;
1127 return __alps_command_mode_write_reg(psmouse, value);
1128}
1129
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001130static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
1131 int repeated_command, unsigned char *param)
1132{
1133 struct ps2dev *ps2dev = &psmouse->ps2dev;
1134
1135 param[0] = 0;
1136 if (init_command && ps2_command(ps2dev, param, init_command))
1137 return -EIO;
1138
1139 if (ps2_command(ps2dev, NULL, repeated_command) ||
1140 ps2_command(ps2dev, NULL, repeated_command) ||
1141 ps2_command(ps2dev, NULL, repeated_command))
1142 return -EIO;
1143
1144 param[0] = param[1] = param[2] = 0xff;
1145 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1146 return -EIO;
1147
Dmitry Torokhov39fbe582013-02-14 09:04:24 -08001148 psmouse_dbg(psmouse, "%2.2X report: %3ph\n",
1149 repeated_command, param);
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001150 return 0;
1151}
1152
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001153static int alps_enter_command_mode(struct psmouse *psmouse)
Seth Forshee25bded72011-11-07 19:53:36 -08001154{
1155 unsigned char param[4];
Seth Forshee25bded72011-11-07 19:53:36 -08001156
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001157 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001158 psmouse_err(psmouse, "failed to enter command mode\n");
1159 return -1;
1160 }
1161
Dave Turvene75af9e52013-02-21 22:58:28 -08001162 if ((param[0] != 0x88 || (param[1] != 0x07 && param[1] != 0x08)) &&
1163 param[0] != 0x73) {
Seth Forshee25bded72011-11-07 19:53:36 -08001164 psmouse_dbg(psmouse,
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001165 "unknown response while entering command mode\n");
Seth Forshee25bded72011-11-07 19:53:36 -08001166 return -1;
1167 }
Seth Forshee25bded72011-11-07 19:53:36 -08001168 return 0;
1169}
1170
1171static inline int alps_exit_command_mode(struct psmouse *psmouse)
1172{
1173 struct ps2dev *ps2dev = &psmouse->ps2dev;
1174 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM))
1175 return -1;
1176 return 0;
1177}
1178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179/*
1180 * For DualPoint devices select the device that should respond to
1181 * subsequent commands. It looks like glidepad is behind stickpointer,
1182 * I'd thought it would be other way around...
1183 */
Seth Forshee25bded72011-11-07 19:53:36 -08001184static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
1186 struct ps2dev *ps2dev = &psmouse->ps2dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
1188
1189 if (ps2_command(ps2dev, NULL, cmd) ||
1190 ps2_command(ps2dev, NULL, cmd) ||
1191 ps2_command(ps2dev, NULL, cmd) ||
1192 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1193 return -1;
1194
1195 /* we may get 3 more bytes, just ignore them */
Dmitry Torokhovc6117632005-06-01 02:39:51 -05001196 ps2_drain(ps2dev, 3, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 return 0;
1199}
1200
Seth Forshee25bded72011-11-07 19:53:36 -08001201static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
1203 struct ps2dev *ps2dev = &psmouse->ps2dev;
1204
1205 /* Try ALPS magic knock - 4 disable before enable */
1206 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1207 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1208 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1209 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1210 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
1211 return -1;
1212
1213 /*
1214 * Switch mouse to poll (remote) mode so motion data will not
1215 * get in our way
1216 */
1217 return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
1218}
1219
Yunkang Tang95f75e92013-12-01 22:33:52 -08001220static int alps_monitor_mode_send_word(struct psmouse *psmouse, u16 word)
1221{
1222 int i, nibble;
1223
1224 /*
1225 * b0-b11 are valid bits, send sequence is inverse.
1226 * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1
1227 */
1228 for (i = 0; i <= 8; i += 4) {
1229 nibble = (word >> i) & 0xf;
1230 if (alps_command_mode_send_nibble(psmouse, nibble))
1231 return -1;
1232 }
1233
1234 return 0;
1235}
1236
1237static int alps_monitor_mode_write_reg(struct psmouse *psmouse,
1238 u16 addr, u16 value)
1239{
1240 struct ps2dev *ps2dev = &psmouse->ps2dev;
1241
1242 /* 0x0A0 is the command to write the word */
1243 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE) ||
1244 alps_monitor_mode_send_word(psmouse, 0x0A0) ||
1245 alps_monitor_mode_send_word(psmouse, addr) ||
1246 alps_monitor_mode_send_word(psmouse, value) ||
1247 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
1248 return -1;
1249
1250 return 0;
1251}
1252
1253static int alps_monitor_mode(struct psmouse *psmouse, bool enable)
1254{
1255 struct ps2dev *ps2dev = &psmouse->ps2dev;
1256
1257 if (enable) {
1258 /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */
1259 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
1260 ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO) ||
1261 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1262 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1263 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1264 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1265 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1266 ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO))
1267 return -1;
1268 } else {
1269 /* EC to exit monitor mode */
1270 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP))
1271 return -1;
1272 }
1273
1274 return 0;
1275}
1276
1277static int alps_absolute_mode_v6(struct psmouse *psmouse)
1278{
1279 u16 reg_val = 0x181;
1280 int ret = -1;
1281
1282 /* enter monitor mode, to write the register */
1283 if (alps_monitor_mode(psmouse, true))
1284 return -1;
1285
1286 ret = alps_monitor_mode_write_reg(psmouse, 0x000, reg_val);
1287
1288 if (alps_monitor_mode(psmouse, false))
1289 ret = -1;
1290
1291 return ret;
1292}
1293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294static int alps_get_status(struct psmouse *psmouse, char *param)
1295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
Kevin Cernekee24ba9702013-02-13 22:19:01 -08001297 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 return -1;
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 return 0;
1301}
1302
1303/*
1304 * Turn touchpad tapping on or off. The sequences are:
1305 * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
1306 * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
1307 * My guess that 0xE9 (GetInfo) is here as a sync point.
1308 * For models that also have stickpointer (DualPoints) its tapping
1309 * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
1310 * we don't fiddle with it.
1311 */
1312static int alps_tap_mode(struct psmouse *psmouse, int enable)
1313{
1314 struct ps2dev *ps2dev = &psmouse->ps2dev;
1315 int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
1316 unsigned char tap_arg = enable ? 0x0A : 0x00;
1317 unsigned char param[4];
1318
1319 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
1320 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1321 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1322 ps2_command(ps2dev, &tap_arg, cmd))
1323 return -1;
1324
1325 if (alps_get_status(psmouse, param))
1326 return -1;
1327
1328 return 0;
1329}
1330
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001331/*
1332 * alps_poll() - poll the touchpad for current motion packet.
1333 * Used in resync.
1334 */
1335static int alps_poll(struct psmouse *psmouse)
1336{
1337 struct alps_data *priv = psmouse->private;
Seth Forsheeb46615f2011-11-07 19:53:30 -08001338 unsigned char buf[sizeof(psmouse->packet)];
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001339 bool poll_failed;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001340
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001341 if (priv->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -08001342 alps_passthrough_mode_v2(psmouse, true);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001343
1344 poll_failed = ps2_command(&psmouse->ps2dev, buf,
1345 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
1346
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001347 if (priv->flags & ALPS_PASS)
Seth Forshee25bded72011-11-07 19:53:36 -08001348 alps_passthrough_mode_v2(psmouse, false);
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001349
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001350 if (poll_failed || (buf[0] & priv->mask0) != priv->byte0)
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05001351 return -1;
1352
1353 if ((psmouse->badbyte & 0xc8) == 0x08) {
1354/*
1355 * Poll the track stick ...
1356 */
1357 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
1358 return -1;
1359 }
1360
1361 memcpy(psmouse->packet, buf, sizeof(buf));
1362 return 0;
1363}
1364
Seth Forshee25bded72011-11-07 19:53:36 -08001365static int alps_hw_init_v1_v2(struct psmouse *psmouse)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 struct alps_data *priv = psmouse->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001369 if ((priv->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -08001370 alps_passthrough_mode_v2(psmouse, true)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001374 if (alps_tap_mode(psmouse, true)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001375 psmouse_warn(psmouse, "Failed to enable hardware tapping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 return -1;
Peter Osterlund963f6262005-07-11 01:08:04 -05001377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Seth Forshee25bded72011-11-07 19:53:36 -08001379 if (alps_absolute_mode_v1_v2(psmouse)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001380 psmouse_err(psmouse, "Failed to enable absolute mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 return -1;
1382 }
1383
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001384 if ((priv->flags & ALPS_PASS) &&
Seth Forshee25bded72011-11-07 19:53:36 -08001385 alps_passthrough_mode_v2(psmouse, false)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 return -1;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07001387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001389 /* ALPS needs stream mode, otherwise it won't report any data */
1390 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) {
Dmitry Torokhovb5d21702011-10-10 18:27:03 -07001391 psmouse_err(psmouse, "Failed to enable stream mode\n");
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001392 return -1;
1393 }
1394
1395 return 0;
1396}
1397
Yunkang Tang95f75e92013-12-01 22:33:52 -08001398static int alps_hw_init_v6(struct psmouse *psmouse)
1399{
1400 unsigned char param[2] = {0xC8, 0x14};
1401
1402 /* Enter passthrough mode to let trackpoint enter 6byte raw mode */
1403 if (alps_passthrough_mode_v2(psmouse, true))
1404 return -1;
1405
1406 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1407 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1408 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1409 ps2_command(&psmouse->ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1410 ps2_command(&psmouse->ps2dev, &param[1], PSMOUSE_CMD_SETRATE))
1411 return -1;
1412
1413 if (alps_passthrough_mode_v2(psmouse, false))
1414 return -1;
1415
1416 if (alps_absolute_mode_v6(psmouse)) {
1417 psmouse_err(psmouse, "Failed to enable absolute mode\n");
1418 return -1;
1419 }
1420
1421 return 0;
1422}
1423
Seth Forshee25bded72011-11-07 19:53:36 -08001424/*
Kevin Cernekeecd401202013-02-13 22:28:07 -08001425 * Enable or disable passthrough mode to the trackstick.
Seth Forshee25bded72011-11-07 19:53:36 -08001426 */
Kevin Cernekeecd401202013-02-13 22:28:07 -08001427static int alps_passthrough_mode_v3(struct psmouse *psmouse,
1428 int reg_base, bool enable)
Seth Forshee25bded72011-11-07 19:53:36 -08001429{
Kevin Cernekeecd401202013-02-13 22:28:07 -08001430 int reg_val, ret = -1;
Seth Forshee25bded72011-11-07 19:53:36 -08001431
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001432 if (alps_enter_command_mode(psmouse))
Seth Forshee25bded72011-11-07 19:53:36 -08001433 return -1;
1434
Kevin Cernekeecd401202013-02-13 22:28:07 -08001435 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008);
1436 if (reg_val == -1)
1437 goto error;
1438
Seth Forshee25bded72011-11-07 19:53:36 -08001439 if (enable)
1440 reg_val |= 0x01;
1441 else
1442 reg_val &= ~0x01;
1443
Kevin Cernekeecd401202013-02-13 22:28:07 -08001444 ret = __alps_command_mode_write_reg(psmouse, reg_val);
Seth Forshee25bded72011-11-07 19:53:36 -08001445
Kevin Cernekeecd401202013-02-13 22:28:07 -08001446error:
1447 if (alps_exit_command_mode(psmouse))
1448 ret = -1;
1449 return ret;
Seth Forshee25bded72011-11-07 19:53:36 -08001450}
1451
1452/* Must be in command mode when calling this function */
1453static int alps_absolute_mode_v3(struct psmouse *psmouse)
1454{
1455 int reg_val;
1456
1457 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1458 if (reg_val == -1)
1459 return -1;
1460
1461 reg_val |= 0x06;
1462 if (__alps_command_mode_write_reg(psmouse, reg_val))
1463 return -1;
1464
1465 return 0;
1466}
1467
Kevin Cernekeecd401202013-02-13 22:28:07 -08001468static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base)
1469{
1470 int ret = -EIO, reg_val;
1471
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001472 if (alps_enter_command_mode(psmouse))
Kevin Cernekeecd401202013-02-13 22:28:07 -08001473 goto error;
1474
1475 reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
1476 if (reg_val == -1)
1477 goto error;
1478
1479 /* bit 7: trackstick is present */
1480 ret = reg_val & 0x80 ? 0 : -ENODEV;
1481
1482error:
1483 alps_exit_command_mode(psmouse);
1484 return ret;
1485}
1486
1487static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
1488{
1489 struct ps2dev *ps2dev = &psmouse->ps2dev;
1490 int ret = 0;
1491 unsigned char param[4];
1492
1493 if (alps_passthrough_mode_v3(psmouse, reg_base, true))
1494 return -EIO;
1495
1496 /*
1497 * E7 report for the trackstick
1498 *
1499 * There have been reports of failures to seem to trace back
1500 * to the above trackstick check failing. When these occur
1501 * this E7 report fails, so when that happens we continue
1502 * with the assumption that there isn't a trackstick after
1503 * all.
1504 */
1505 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) {
1506 psmouse_warn(psmouse, "trackstick E7 report failed\n");
1507 ret = -ENODEV;
1508 } else {
Dmitry Torokhov39fbe582013-02-14 09:04:24 -08001509 psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param);
Kevin Cernekeecd401202013-02-13 22:28:07 -08001510
1511 /*
1512 * Not sure what this does, but it is absolutely
1513 * essential. Without it, the touchpad does not
1514 * work at all and the trackstick just emits normal
1515 * PS/2 packets.
1516 */
1517 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1518 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1519 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1520 alps_command_mode_send_nibble(psmouse, 0x9) ||
1521 alps_command_mode_send_nibble(psmouse, 0x4)) {
1522 psmouse_err(psmouse,
1523 "Error sending magic E6 sequence\n");
1524 ret = -EIO;
1525 goto error;
1526 }
1527
1528 /*
1529 * This ensures the trackstick packets are in the format
1530 * supported by this driver. If bit 1 isn't set the packet
1531 * format is different.
1532 */
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001533 if (alps_enter_command_mode(psmouse) ||
Kevin Cernekeecd401202013-02-13 22:28:07 -08001534 alps_command_mode_write_reg(psmouse,
1535 reg_base + 0x08, 0x82) ||
1536 alps_exit_command_mode(psmouse))
1537 ret = -EIO;
1538 }
1539
1540error:
1541 if (alps_passthrough_mode_v3(psmouse, reg_base, false))
1542 ret = -EIO;
1543
1544 return ret;
1545}
1546
Seth Forshee25bded72011-11-07 19:53:36 -08001547static int alps_hw_init_v3(struct psmouse *psmouse)
1548{
Seth Forshee25bded72011-11-07 19:53:36 -08001549 struct ps2dev *ps2dev = &psmouse->ps2dev;
1550 int reg_val;
1551 unsigned char param[4];
1552
Kevin Cernekeecd401202013-02-13 22:28:07 -08001553 reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE);
1554 if (reg_val == -EIO)
1555 goto error;
Dmitry Torokhov39fbe582013-02-14 09:04:24 -08001556
Kevin Cernekeecd401202013-02-13 22:28:07 -08001557 if (reg_val == 0 &&
1558 alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO)
Seth Forshee25bded72011-11-07 19:53:36 -08001559 goto error;
1560
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001561 if (alps_enter_command_mode(psmouse) ||
Kevin Cernekeecd401202013-02-13 22:28:07 -08001562 alps_absolute_mode_v3(psmouse)) {
Seth Forshee25bded72011-11-07 19:53:36 -08001563 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1564 goto error;
1565 }
1566
1567 reg_val = alps_command_mode_read_reg(psmouse, 0x0006);
1568 if (reg_val == -1)
1569 goto error;
1570 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1571 goto error;
1572
1573 reg_val = alps_command_mode_read_reg(psmouse, 0x0007);
1574 if (reg_val == -1)
1575 goto error;
1576 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01))
1577 goto error;
1578
1579 if (alps_command_mode_read_reg(psmouse, 0x0144) == -1)
1580 goto error;
1581 if (__alps_command_mode_write_reg(psmouse, 0x04))
1582 goto error;
1583
1584 if (alps_command_mode_read_reg(psmouse, 0x0159) == -1)
1585 goto error;
1586 if (__alps_command_mode_write_reg(psmouse, 0x03))
1587 goto error;
1588
1589 if (alps_command_mode_read_reg(psmouse, 0x0163) == -1)
1590 goto error;
1591 if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03))
1592 goto error;
1593
1594 if (alps_command_mode_read_reg(psmouse, 0x0162) == -1)
1595 goto error;
1596 if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04))
1597 goto error;
1598
Seth Forshee25bded72011-11-07 19:53:36 -08001599 alps_exit_command_mode(psmouse);
1600
1601 /* Set rate and enable data reporting */
1602 param[0] = 0x64;
1603 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1604 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1605 psmouse_err(psmouse, "Failed to enable data reporting\n");
1606 return -1;
1607 }
1608
1609 return 0;
1610
Seth Forshee25bded72011-11-07 19:53:36 -08001611error:
1612 /*
1613 * Leaving the touchpad in command mode will essentially render
1614 * it unusable until the machine reboots, so exit it here just
1615 * to be safe
1616 */
1617 alps_exit_command_mode(psmouse);
1618 return -1;
1619}
1620
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001621static int alps_hw_init_rushmore_v3(struct psmouse *psmouse)
1622{
Kevin Cernekeecd401202013-02-13 22:28:07 -08001623 struct alps_data *priv = psmouse->private;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001624 struct ps2dev *ps2dev = &psmouse->ps2dev;
1625 int reg_val, ret = -1;
1626
Kevin Cernekeecd401202013-02-13 22:28:07 -08001627 if (priv->flags & ALPS_DUALPOINT) {
1628 reg_val = alps_setup_trackstick_v3(psmouse,
1629 ALPS_REG_BASE_RUSHMORE);
1630 if (reg_val == -EIO)
1631 goto error;
1632 if (reg_val == -ENODEV)
1633 priv->flags &= ~ALPS_DUALPOINT;
1634 }
1635
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001636 if (alps_enter_command_mode(psmouse) ||
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001637 alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 ||
1638 alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00))
1639 goto error;
1640
1641 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6);
1642 if (reg_val == -1)
1643 goto error;
1644 if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd))
1645 goto error;
1646
1647 if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64))
1648 goto error;
1649
1650 /* enter absolute mode */
1651 reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4);
1652 if (reg_val == -1)
1653 goto error;
1654 if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02))
1655 goto error;
1656
1657 alps_exit_command_mode(psmouse);
1658 return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1659
1660error:
1661 alps_exit_command_mode(psmouse);
1662 return ret;
1663}
1664
Seth Forshee25bded72011-11-07 19:53:36 -08001665/* Must be in command mode when calling this function */
1666static int alps_absolute_mode_v4(struct psmouse *psmouse)
1667{
1668 int reg_val;
1669
1670 reg_val = alps_command_mode_read_reg(psmouse, 0x0004);
1671 if (reg_val == -1)
1672 return -1;
1673
1674 reg_val |= 0x02;
1675 if (__alps_command_mode_write_reg(psmouse, reg_val))
1676 return -1;
1677
1678 return 0;
1679}
1680
1681static int alps_hw_init_v4(struct psmouse *psmouse)
1682{
Seth Forshee25bded72011-11-07 19:53:36 -08001683 struct ps2dev *ps2dev = &psmouse->ps2dev;
1684 unsigned char param[4];
1685
Kevin Cernekeed18e53f2013-02-21 22:58:20 -08001686 if (alps_enter_command_mode(psmouse))
Seth Forshee25bded72011-11-07 19:53:36 -08001687 goto error;
1688
1689 if (alps_absolute_mode_v4(psmouse)) {
1690 psmouse_err(psmouse, "Failed to enter absolute mode\n");
1691 goto error;
1692 }
1693
1694 if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c))
1695 goto error;
1696
1697 if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03))
1698 goto error;
1699
1700 if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03))
1701 goto error;
1702
1703 if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15))
1704 goto error;
1705
1706 if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01))
1707 goto error;
1708
1709 if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03))
1710 goto error;
1711
1712 if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03))
1713 goto error;
1714
1715 if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03))
1716 goto error;
1717
1718 alps_exit_command_mode(psmouse);
1719
1720 /*
1721 * This sequence changes the output from a 9-byte to an
1722 * 8-byte format. All the same data seems to be present,
1723 * just in a more compact format.
1724 */
1725 param[0] = 0xc8;
1726 param[1] = 0x64;
1727 param[2] = 0x50;
1728 if (ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1729 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE) ||
1730 ps2_command(ps2dev, &param[2], PSMOUSE_CMD_SETRATE) ||
1731 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
1732 return -1;
1733
1734 /* Set rate and enable data reporting */
1735 param[0] = 0x64;
1736 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) ||
1737 ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
1738 psmouse_err(psmouse, "Failed to enable data reporting\n");
1739 return -1;
1740 }
1741
1742 return 0;
1743
1744error:
1745 /*
1746 * Leaving the touchpad in command mode will essentially render
1747 * it unusable until the machine reboots, so exit it here just
1748 * to be safe
1749 */
1750 alps_exit_command_mode(psmouse);
1751 return -1;
1752}
1753
Yunkang Tangee65d4b2013-12-26 14:54:19 -08001754static int alps_dolphin_get_device_area(struct psmouse *psmouse,
1755 struct alps_data *priv)
1756{
1757 struct ps2dev *ps2dev = &psmouse->ps2dev;
1758 unsigned char param[4] = {0};
1759 int num_x_electrode, num_y_electrode;
1760
1761 if (alps_enter_command_mode(psmouse))
1762 return -1;
1763
1764 param[0] = 0x0a;
1765 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
1766 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
1767 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) ||
1768 ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1769 ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE))
1770 return -1;
1771
1772 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1773 return -1;
1774
1775 /*
1776 * Dolphin's sensor line number is not fixed. It can be calculated
1777 * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET.
1778 * Further more, we can get device's x_max and y_max by multiplying
1779 * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE.
1780 *
1781 * e.g. When we get register's sensor_x = 11 & sensor_y = 8,
1782 * real sensor line number X = 11 + 8 = 19, and
1783 * real sensor line number Y = 8 + 1 = 9.
1784 * So, x_max = (19 - 1) * 64 = 1152, and
1785 * y_max = (9 - 1) * 64 = 512.
1786 */
1787 num_x_electrode = DOLPHIN_PROFILE_XOFFSET + (param[2] & 0x0F);
1788 num_y_electrode = DOLPHIN_PROFILE_YOFFSET + ((param[2] >> 4) & 0x0F);
1789 priv->x_bits = num_x_electrode;
1790 priv->y_bits = num_y_electrode;
1791 priv->x_max = (num_x_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE;
1792 priv->y_max = (num_y_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE;
1793
1794 if (alps_exit_command_mode(psmouse))
1795 return -1;
1796
1797 return 0;
1798}
1799
Dave Turvene75af9e52013-02-21 22:58:28 -08001800static int alps_hw_init_dolphin_v1(struct psmouse *psmouse)
1801{
1802 struct ps2dev *ps2dev = &psmouse->ps2dev;
1803 unsigned char param[2];
1804
1805 /* This is dolphin "v1" as empirically defined by florin9doi */
1806 param[0] = 0x64;
1807 param[1] = 0x28;
1808
1809 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) ||
1810 ps2_command(ps2dev, &param[0], PSMOUSE_CMD_SETRATE) ||
1811 ps2_command(ps2dev, &param[1], PSMOUSE_CMD_SETRATE))
1812 return -1;
1813
1814 return 0;
1815}
1816
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001817static void alps_set_defaults(struct alps_data *priv)
Seth Forshee25bded72011-11-07 19:53:36 -08001818{
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001819 priv->byte0 = 0x8f;
1820 priv->mask0 = 0x8f;
1821 priv->flags = ALPS_DUALPOINT;
1822
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08001823 priv->x_max = 2000;
1824 priv->y_max = 1400;
1825 priv->x_bits = 15;
1826 priv->y_bits = 11;
1827
Kevin Cernekee99df65e2013-02-13 20:56:33 -08001828 switch (priv->proto_version) {
Seth Forshee25bded72011-11-07 19:53:36 -08001829 case ALPS_PROTO_V1:
1830 case ALPS_PROTO_V2:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001831 priv->hw_init = alps_hw_init_v1_v2;
1832 priv->process_packet = alps_process_packet_v1_v2;
1833 priv->set_abs_params = alps_set_abs_params_st;
Yunkang Tang95f75e92013-12-01 22:33:52 -08001834 priv->x_max = 1023;
1835 priv->y_max = 767;
Seth Forshee25bded72011-11-07 19:53:36 -08001836 break;
1837 case ALPS_PROTO_V3:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001838 priv->hw_init = alps_hw_init_v3;
1839 priv->process_packet = alps_process_packet_v3;
1840 priv->set_abs_params = alps_set_abs_params_mt;
Kevin Cernekeef85e5002013-02-13 22:26:11 -08001841 priv->decode_fields = alps_decode_pinnacle;
Kevin Cernekee50e8b212013-02-13 22:23:04 -08001842 priv->nibble_commands = alps_v3_nibble_commands;
1843 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
Seth Forshee25bded72011-11-07 19:53:36 -08001844 break;
1845 case ALPS_PROTO_V4:
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001846 priv->hw_init = alps_hw_init_v4;
1847 priv->process_packet = alps_process_packet_v4;
1848 priv->set_abs_params = alps_set_abs_params_mt;
Kevin Cernekee50e8b212013-02-13 22:23:04 -08001849 priv->nibble_commands = alps_v4_nibble_commands;
1850 priv->addr_command = PSMOUSE_CMD_DISABLE;
Seth Forshee25bded72011-11-07 19:53:36 -08001851 break;
Dave Turvene75af9e52013-02-21 22:58:28 -08001852 case ALPS_PROTO_V5:
1853 priv->hw_init = alps_hw_init_dolphin_v1;
Yunkang Tangee65d4b2013-12-26 14:54:19 -08001854 priv->process_packet = alps_process_touchpad_packet_v3_v5;
Dave Turvene75af9e52013-02-21 22:58:28 -08001855 priv->decode_fields = alps_decode_dolphin;
1856 priv->set_abs_params = alps_set_abs_params_mt;
1857 priv->nibble_commands = alps_v3_nibble_commands;
1858 priv->addr_command = PSMOUSE_CMD_RESET_WRAP;
1859 priv->byte0 = 0xc8;
Yunkang Tangee65d4b2013-12-26 14:54:19 -08001860 priv->mask0 = 0xd8;
Dave Turvene75af9e52013-02-21 22:58:28 -08001861 priv->flags = 0;
1862 priv->x_max = 1360;
1863 priv->y_max = 660;
1864 priv->x_bits = 23;
1865 priv->y_bits = 12;
1866 break;
Yunkang Tang95f75e92013-12-01 22:33:52 -08001867 case ALPS_PROTO_V6:
1868 priv->hw_init = alps_hw_init_v6;
1869 priv->process_packet = alps_process_packet_v6;
1870 priv->set_abs_params = alps_set_abs_params_st;
1871 priv->nibble_commands = alps_v6_nibble_commands;
1872 priv->x_max = 2047;
1873 priv->y_max = 1535;
1874 break;
Seth Forshee25bded72011-11-07 19:53:36 -08001875 }
Seth Forshee25bded72011-11-07 19:53:36 -08001876}
1877
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001878static int alps_match_table(struct psmouse *psmouse, struct alps_data *priv,
1879 unsigned char *e7, unsigned char *ec)
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001880{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001881 const struct alps_model_info *model;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001882 int i;
1883
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001884 for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) {
1885 model = &alps_model_data[i];
1886
1887 if (!memcmp(e7, model->signature, sizeof(model->signature)) &&
1888 (!model->command_mode_resp ||
1889 model->command_mode_resp == ec[2])) {
1890
1891 priv->proto_version = model->proto_version;
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001892 alps_set_defaults(priv);
1893
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001894 priv->flags = model->flags;
1895 priv->byte0 = model->byte0;
1896 priv->mask0 = model->mask0;
1897
1898 return 0;
1899 }
1900 }
1901
1902 return -EINVAL;
1903}
1904
1905static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
1906{
1907 unsigned char e6[4], e7[4], ec[4];
1908
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001909 /*
1910 * First try "E6 report".
1911 * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed.
1912 * The bits 0-2 of the first byte will be 1s if some buttons are
1913 * pressed.
1914 */
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001915 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1916 PSMOUSE_CMD_SETSCALE11, e6))
1917 return -EIO;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001918
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001919 if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100))
1920 return -EINVAL;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001921
1922 /*
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001923 * Now get the "E7" and "EC" reports. These will uniquely identify
1924 * most ALPS touchpads.
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001925 */
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001926 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1927 PSMOUSE_CMD_SETSCALE21, e7) ||
1928 alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES,
1929 PSMOUSE_CMD_RESET_WRAP, ec) ||
1930 alps_exit_command_mode(psmouse))
1931 return -EIO;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001932
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001933 if (alps_match_table(psmouse, priv, e7, ec) == 0) {
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001934 return 0;
Dave Turvene75af9e52013-02-21 22:58:28 -08001935 } else if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 &&
Yunkang Tangee65d4b2013-12-26 14:54:19 -08001936 ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) {
Dave Turvene75af9e52013-02-21 22:58:28 -08001937 priv->proto_version = ALPS_PROTO_V5;
1938 alps_set_defaults(priv);
Yunkang Tangee65d4b2013-12-26 14:54:19 -08001939 if (alps_dolphin_get_device_area(psmouse, priv))
1940 return -EIO;
1941 else
1942 return 0;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001943 } else if (ec[0] == 0x88 && ec[1] == 0x08) {
1944 priv->proto_version = ALPS_PROTO_V3;
1945 alps_set_defaults(priv);
1946
1947 priv->hw_init = alps_hw_init_rushmore_v3;
1948 priv->decode_fields = alps_decode_rushmore;
1949 priv->x_bits = 16;
1950 priv->y_bits = 12;
Hans de Goede40e8f532014-07-25 22:37:15 -07001951 priv->flags |= ALPS_IS_RUSHMORE;
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001952
Kevin Cernekeecd401202013-02-13 22:28:07 -08001953 /* hack to make addr_command, nibble_command available */
1954 psmouse->private = priv;
1955
1956 if (alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_RUSHMORE))
1957 priv->flags &= ~ALPS_DUALPOINT;
1958
Kevin Cernekee1302bac2013-02-13 22:27:08 -08001959 return 0;
Kevin Cernekeef673ceb2013-02-13 22:23:34 -08001960 } else if (ec[0] == 0x88 && ec[1] == 0x07 &&
1961 ec[2] >= 0x90 && ec[2] <= 0x9d) {
1962 priv->proto_version = ALPS_PROTO_V3;
1963 alps_set_defaults(priv);
1964
1965 return 0;
1966 }
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001967
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001968 psmouse_info(psmouse,
Dmitry Torokhov39fbe582013-02-14 09:04:24 -08001969 "Unknown ALPS touchpad: E7=%3ph, EC=%3ph\n", e7, ec);
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001970
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001971 return -EINVAL;
Kevin Cernekee2e992cc2013-02-13 20:57:04 -08001972}
1973
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001974static int alps_reconnect(struct psmouse *psmouse)
1975{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001976 struct alps_data *priv = psmouse->private;
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08001977
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001978 psmouse_reset(psmouse);
1979
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08001980 if (alps_identify(psmouse, priv) < 0)
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04001981 return -1;
1982
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001983 return priv->hw_init(psmouse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984}
1985
1986static void alps_disconnect(struct psmouse *psmouse)
1987{
1988 struct alps_data *priv = psmouse->private;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 psmouse_reset(psmouse);
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08001991 del_timer_sync(&priv->timer);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05001992 input_unregister_device(priv->dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 kfree(priv);
1994}
1995
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08001996static void alps_set_abs_params_st(struct alps_data *priv,
1997 struct input_dev *dev1)
1998{
Yunkang Tang95f75e92013-12-01 22:33:52 -08001999 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
2000 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08002001}
2002
2003static void alps_set_abs_params_mt(struct alps_data *priv,
2004 struct input_dev *dev1)
2005{
2006 set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
2007 input_mt_init_slots(dev1, 2, 0);
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08002008 input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0);
2009 input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08002010
2011 set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
2012 set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
2013 set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
2014
Kevin Cernekee7a9f73e2013-02-13 22:24:55 -08002015 input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0);
2016 input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0);
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08002017}
2018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019int alps_init(struct psmouse *psmouse)
2020{
2021 struct alps_data *priv;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002022 struct input_dev *dev1 = psmouse->dev, *dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04002024 priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002025 dev2 = input_allocate_device();
2026 if (!priv || !dev2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 goto init_fail;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002028
2029 priv->dev2 = dev2;
Sebastian Kapfer1d9f2622009-12-15 08:39:50 -08002030 setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse);
2031
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04002032 psmouse->private = priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Seth Forshee25bded72011-11-07 19:53:36 -08002034 psmouse_reset(psmouse);
2035
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08002036 if (alps_identify(psmouse, priv) < 0)
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08002037 goto init_fail;
2038
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08002039 if (priv->hw_init(psmouse))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 goto init_fail;
2041
Dmitry Torokhov7105d2e2009-12-11 23:54:54 -08002042 /*
2043 * Undo part of setup done for us by psmouse core since touchpad
2044 * is not a relative device.
2045 */
2046 __clear_bit(EV_REL, dev1->evbit);
2047 __clear_bit(REL_X, dev1->relbit);
2048 __clear_bit(REL_Y, dev1->relbit);
2049
2050 /*
2051 * Now set up our capabilities.
2052 */
Jiri Slaby7b19ada2007-10-18 23:40:32 -07002053 dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY);
2054 dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH);
2055 dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08002056 dev1->keybit[BIT_WORD(BTN_LEFT)] |=
2057 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Jiri Slaby7b19ada2007-10-18 23:40:32 -07002059 dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS);
Seth Forshee25bded72011-11-07 19:53:36 -08002060
Kevin Cernekee24af5cb2013-02-13 22:22:08 -08002061 priv->set_abs_params(priv, dev1);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002062 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Kevin Cernekee99df65e2013-02-13 20:56:33 -08002064 if (priv->flags & ALPS_WHEEL) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07002065 dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL);
2066 dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 }
2068
Kevin Cernekee99df65e2013-02-13 20:56:33 -08002069 if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
Jiri Slaby7b19ada2007-10-18 23:40:32 -07002070 dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD);
2071 dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 }
2073
Kevin Cernekee99df65e2013-02-13 20:56:33 -08002074 if (priv->flags & ALPS_FOUR_BUTTONS) {
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08002075 dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0);
2076 dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1);
2077 dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2);
2078 dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3);
2079 } else {
2080 dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE);
2081 }
2082
Dmitry Torokhov08ffce42006-06-26 01:45:10 -04002083 snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002084 dev2->phys = priv->phys;
Kevin Cernekee99df65e2013-02-13 20:56:33 -08002085 dev2->name = (priv->flags & ALPS_DUALPOINT) ?
Yunkang Tang9354f262013-10-15 23:50:38 -07002086 "DualPoint Stick" : "ALPS PS/2 Device";
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002087 dev2->id.bustype = BUS_I8042;
2088 dev2->id.vendor = 0x0002;
2089 dev2->id.product = PSMOUSE_ALPS;
2090 dev2->id.version = 0x0000;
Dmitry Torokhov1db3a342008-03-18 00:29:18 -04002091 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
Dmitry Torokhov968ac842005-05-29 02:28:29 -05002092
Jiri Slaby7b19ada2007-10-18 23:40:32 -07002093 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
Maxim Levitsky71bb21b2009-11-16 22:12:22 -08002094 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
2095 dev2->keybit[BIT_WORD(BTN_LEFT)] =
2096 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04002098 if (input_register_device(priv->dev2))
2099 goto init_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
2101 psmouse->protocol_handler = alps_process_byte;
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05002102 psmouse->poll = alps_poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 psmouse->disconnect = alps_disconnect;
2104 psmouse->reconnect = alps_reconnect;
Kevin Cernekee99df65e2013-02-13 20:56:33 -08002105 psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Dmitry Torokhovf0d5c6f42006-01-14 00:27:37 -05002107 /* We are having trouble resyncing ALPS touchpads so disable it for now */
2108 psmouse->resync_time = 0;
2109
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 return 0;
2111
2112init_fail:
Dmitry Torokhovf42649e2007-04-12 01:31:13 -04002113 psmouse_reset(psmouse);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -05002114 input_free_device(dev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 kfree(priv);
Dmitry Torokhov1e0c5b12007-05-14 23:51:54 -04002116 psmouse->private = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 return -1;
2118}
2119
Dmitry Torokhovb7802c52009-09-09 19:13:20 -07002120int alps_detect(struct psmouse *psmouse, bool set_properties)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08002122 struct alps_data dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08002124 if (alps_identify(psmouse, &dummy) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 return -1;
2126
2127 if (set_properties) {
2128 psmouse->vendor = "ALPS";
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08002129 psmouse->name = dummy.flags & ALPS_DUALPOINT ?
Dmitry Torokhov968ac842005-05-29 02:28:29 -05002130 "DualPoint TouchPad" : "GlidePoint";
Kevin Cernekeeb5d6b852013-02-13 22:19:59 -08002131 psmouse->model = dummy.proto_version << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 }
2133 return 0;
2134}
2135