Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALPS touchpad PS/2 mouse driver |
| 3 | * |
| 4 | * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au> |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 5 | * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru> |
| 7 | * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 8 | * Copyright (c) 2009 Sebastian Kapfer <sebastian_kapfer@gmx.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * ALPS detection, tap switching and status querying info is taken from |
| 11 | * tpconfig utility (by C. Scott Ananian and Bruce Kall). |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License version 2 as published by |
| 15 | * the Free Software Foundation. |
| 16 | */ |
| 17 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/input.h> |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 20 | #include <linux/input/mt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/serio.h> |
| 22 | #include <linux/libps2.h> |
| 23 | |
| 24 | #include "psmouse.h" |
| 25 | #include "alps.h" |
| 26 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 27 | /* |
| 28 | * Definitions for ALPS version 3 and 4 command mode protocol |
| 29 | */ |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 30 | #define ALPS_V3_X_MAX 2000 |
| 31 | #define ALPS_V3_Y_MAX 1400 |
| 32 | |
| 33 | #define ALPS_BITMAP_X_BITS 15 |
| 34 | #define ALPS_BITMAP_Y_BITS 11 |
| 35 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 36 | #define ALPS_CMD_NIBBLE_10 0x01f2 |
| 37 | |
| 38 | static const struct alps_nibble_commands alps_v3_nibble_commands[] = { |
| 39 | { PSMOUSE_CMD_SETPOLL, 0x00 }, /* 0 */ |
| 40 | { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */ |
| 41 | { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */ |
| 42 | { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */ |
| 43 | { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */ |
| 44 | { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */ |
| 45 | { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */ |
| 46 | { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */ |
| 47 | { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */ |
| 48 | { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */ |
| 49 | { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */ |
| 50 | { PSMOUSE_CMD_SETRES, 0x00 }, /* b */ |
| 51 | { PSMOUSE_CMD_SETRES, 0x01 }, /* c */ |
| 52 | { PSMOUSE_CMD_SETRES, 0x02 }, /* d */ |
| 53 | { PSMOUSE_CMD_SETRES, 0x03 }, /* e */ |
| 54 | { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ |
| 55 | }; |
| 56 | |
| 57 | static const struct alps_nibble_commands alps_v4_nibble_commands[] = { |
| 58 | { PSMOUSE_CMD_ENABLE, 0x00 }, /* 0 */ |
| 59 | { PSMOUSE_CMD_RESET_DIS, 0x00 }, /* 1 */ |
| 60 | { PSMOUSE_CMD_SETSCALE21, 0x00 }, /* 2 */ |
| 61 | { PSMOUSE_CMD_SETRATE, 0x0a }, /* 3 */ |
| 62 | { PSMOUSE_CMD_SETRATE, 0x14 }, /* 4 */ |
| 63 | { PSMOUSE_CMD_SETRATE, 0x28 }, /* 5 */ |
| 64 | { PSMOUSE_CMD_SETRATE, 0x3c }, /* 6 */ |
| 65 | { PSMOUSE_CMD_SETRATE, 0x50 }, /* 7 */ |
| 66 | { PSMOUSE_CMD_SETRATE, 0x64 }, /* 8 */ |
| 67 | { PSMOUSE_CMD_SETRATE, 0xc8 }, /* 9 */ |
| 68 | { ALPS_CMD_NIBBLE_10, 0x00 }, /* a */ |
| 69 | { PSMOUSE_CMD_SETRES, 0x00 }, /* b */ |
| 70 | { PSMOUSE_CMD_SETRES, 0x01 }, /* c */ |
| 71 | { PSMOUSE_CMD_SETRES, 0x02 }, /* d */ |
| 72 | { PSMOUSE_CMD_SETRES, 0x03 }, /* e */ |
| 73 | { PSMOUSE_CMD_SETSCALE11, 0x00 }, /* f */ |
| 74 | }; |
| 75 | |
| 76 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 77 | #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */ |
| 78 | #define ALPS_PASS 0x04 /* device has a pass-through port */ |
| 79 | |
| 80 | #define ALPS_WHEEL 0x08 /* hardware wheel present */ |
| 81 | #define ALPS_FW_BK_1 0x10 /* front & back buttons present */ |
| 82 | #define ALPS_FW_BK_2 0x20 /* front & back buttons present */ |
| 83 | #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 84 | #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with |
| 85 | 6-byte ALPS packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 87 | static const struct alps_model_info alps_model_data[] = { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 88 | { { 0x32, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */ |
| 89 | { { 0x33, 0x02, 0x0a }, 0x00, ALPS_PROTO_V1, 0x88, 0xf8, 0 }, /* UMAX-530T */ |
| 90 | { { 0x53, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, |
| 91 | { { 0x53, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, |
| 92 | { { 0x60, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, /* HP ze1115 */ |
| 93 | { { 0x63, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, |
| 94 | { { 0x63, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, |
| 95 | { { 0x63, 0x02, 0x28 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */ |
| 96 | { { 0x63, 0x02, 0x3c }, 0x00, ALPS_PROTO_V2, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ |
| 97 | { { 0x63, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */ |
| 98 | { { 0x63, 0x02, 0x64 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, |
| 99 | { { 0x63, 0x03, 0xc8 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */ |
| 100 | { { 0x73, 0x00, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */ |
| 101 | { { 0x73, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, 0 }, |
| 102 | { { 0x73, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */ |
| 103 | { { 0x20, 0x02, 0x0e }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ |
| 104 | { { 0x22, 0x02, 0x0a }, 0x00, ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, |
| 105 | { { 0x22, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 106 | /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 107 | { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 108 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 109 | { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ |
| 110 | { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, |
| 111 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ |
| 112 | { { 0x73, 0x02, 0x64 }, 0x9b, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT }, |
| 113 | { { 0x73, 0x02, 0x64 }, 0x9d, ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT }, |
| 114 | { { 0x73, 0x02, 0x64 }, 0x8a, ALPS_PROTO_V4, 0x8f, 0x8f, 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /* |
| 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 Forshee | d4b347b | 2011-11-07 19:53:15 -0800 | [diff] [blame] | 123 | /* Packet formats are described in Documentation/input/alps.txt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 125 | static bool alps_is_valid_first_byte(const struct alps_model_info *model, |
| 126 | unsigned char data) |
| 127 | { |
| 128 | return (data & model->mask0) == model->byte0; |
| 129 | } |
| 130 | |
| 131 | static 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 Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 135 | struct input_dev *dev; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 136 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 137 | /* |
| 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 Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 144 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 145 | dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1; |
| 146 | input_report_key(dev, BTN_RIGHT, right); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 147 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 148 | dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1; |
| 149 | input_report_key(dev, BTN_MIDDLE, middle); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 150 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 151 | /* |
| 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 Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 158 | static void alps_process_packet_v1_v2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 161 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | unsigned char *packet = psmouse->packet; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 163 | struct input_dev *dev = psmouse->dev; |
| 164 | struct input_dev *dev2 = priv->dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | int x, y, z, ges, fin, left, right, middle; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 166 | int back = 0, forward = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Seth Forshee | fa629ef | 2011-11-07 19:53:24 -0800 | [diff] [blame] | 168 | if (model->proto_version == ALPS_PROTO_V1) { |
Yotam Medini | d2f4012 | 2006-05-29 23:30:36 -0400 | [diff] [blame] | 169 | left = packet[2] & 0x10; |
| 170 | right = packet[2] & 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | middle = 0; |
| 172 | x = packet[1] | ((packet[0] & 0x07) << 7); |
| 173 | y = packet[4] | ((packet[3] & 0x07) << 7); |
| 174 | z = packet[5]; |
| 175 | } else { |
| 176 | left = packet[3] & 1; |
| 177 | right = packet[3] & 2; |
| 178 | middle = packet[3] & 4; |
| 179 | x = packet[1] | ((packet[2] & 0x78) << (7 - 3)); |
| 180 | y = packet[4] | ((packet[3] & 0x70) << (7 - 4)); |
| 181 | z = packet[5]; |
| 182 | } |
| 183 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 184 | if (model->flags & ALPS_FW_BK_1) { |
Laszlo Kajan | 3c00bb9 | 2008-03-18 00:39:55 -0400 | [diff] [blame] | 185 | back = packet[0] & 0x10; |
| 186 | forward = packet[2] & 4; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 187 | } |
| 188 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 189 | if (model->flags & ALPS_FW_BK_2) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 190 | back = packet[3] & 4; |
| 191 | forward = packet[2] & 4; |
| 192 | if ((middle = forward && back)) |
| 193 | forward = back = 0; |
| 194 | } |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | ges = packet[2] & 1; |
| 197 | fin = packet[2] & 2; |
| 198 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 199 | if ((model->flags & ALPS_DUALPOINT) && z == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); |
| 201 | input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 202 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 203 | alps_report_buttons(psmouse, dev2, dev, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | input_sync(dev2); |
| 206 | return; |
| 207 | } |
| 208 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 209 | alps_report_buttons(psmouse, dev, dev2, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* Convert hardware tap to a reasonable Z value */ |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 212 | if (ges && !fin) |
| 213 | z = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* |
| 216 | * A "tap and drag" operation is reported by the hardware as a transition |
| 217 | * from (!fin && ges) to (fin && ges). This should be translated to the |
| 218 | * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually. |
| 219 | */ |
| 220 | if (ges && fin && !priv->prev_fin) { |
| 221 | input_report_abs(dev, ABS_X, x); |
| 222 | input_report_abs(dev, ABS_Y, y); |
| 223 | input_report_abs(dev, ABS_PRESSURE, 0); |
| 224 | input_report_key(dev, BTN_TOOL_FINGER, 0); |
| 225 | input_sync(dev); |
| 226 | } |
| 227 | priv->prev_fin = fin; |
| 228 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 229 | if (z > 30) |
| 230 | input_report_key(dev, BTN_TOUCH, 1); |
| 231 | if (z < 25) |
| 232 | input_report_key(dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | if (z > 0) { |
| 235 | input_report_abs(dev, ABS_X, x); |
| 236 | input_report_abs(dev, ABS_Y, y); |
| 237 | } |
| 238 | |
| 239 | input_report_abs(dev, ABS_PRESSURE, z); |
| 240 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 241 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 242 | if (model->flags & ALPS_WHEEL) |
Vojtech Pavlik | e6c047b | 2005-09-04 01:40:43 -0500 | [diff] [blame] | 243 | input_report_rel(dev, REL_WHEEL, ((packet[2] << 1) & 0x08) - ((packet[0] >> 4) & 0x07)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 245 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 246 | input_report_key(dev, BTN_FORWARD, forward); |
| 247 | input_report_key(dev, BTN_BACK, back); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 250 | if (model->flags & ALPS_FOUR_BUTTONS) { |
| 251 | input_report_key(dev, BTN_0, packet[2] & 4); |
| 252 | input_report_key(dev, BTN_1, packet[0] & 0x10); |
| 253 | input_report_key(dev, BTN_2, packet[3] & 4); |
| 254 | input_report_key(dev, BTN_3, packet[0] & 0x20); |
| 255 | } |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | input_sync(dev); |
| 258 | } |
| 259 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 260 | /* |
| 261 | * Process bitmap data from v3 and v4 protocols. Returns the number of |
| 262 | * fingers detected. A return value of 0 means at least one of the |
| 263 | * bitmaps was empty. |
| 264 | * |
| 265 | * The bitmaps don't have enough data to track fingers, so this function |
| 266 | * only generates points representing a bounding box of all contacts. |
| 267 | * These points are returned in x1, y1, x2, and y2 when the return value |
| 268 | * is greater than 0. |
| 269 | */ |
| 270 | static int alps_process_bitmap(unsigned int x_map, unsigned int y_map, |
| 271 | 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 | */ |
| 312 | y_map = y_map << (sizeof(y_map) * BITS_PER_BYTE - ALPS_BITMAP_Y_BITS); |
| 313 | 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 | |
| 358 | *x1 = (ALPS_V3_X_MAX * (2 * x_low.start_bit + x_low.num_bits - 1)) / |
| 359 | (2 * (ALPS_BITMAP_X_BITS - 1)); |
| 360 | *y1 = (ALPS_V3_Y_MAX * (2 * y_low.start_bit + y_low.num_bits - 1)) / |
| 361 | (2 * (ALPS_BITMAP_Y_BITS - 1)); |
| 362 | |
| 363 | if (fingers > 1) { |
| 364 | *x2 = (ALPS_V3_X_MAX * (2 * x_high.start_bit + x_high.num_bits - 1)) / |
| 365 | (2 * (ALPS_BITMAP_X_BITS - 1)); |
| 366 | *y2 = (ALPS_V3_Y_MAX * (2 * y_high.start_bit + y_high.num_bits - 1)) / |
| 367 | (2 * (ALPS_BITMAP_Y_BITS - 1)); |
| 368 | } |
| 369 | |
| 370 | return fingers; |
| 371 | } |
| 372 | |
| 373 | static void alps_set_slot(struct input_dev *dev, int slot, bool active, |
| 374 | int x, int y) |
| 375 | { |
| 376 | input_mt_slot(dev, slot); |
| 377 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); |
| 378 | if (active) { |
| 379 | input_report_abs(dev, ABS_MT_POSITION_X, x); |
| 380 | input_report_abs(dev, ABS_MT_POSITION_Y, y); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | static void alps_report_semi_mt_data(struct input_dev *dev, int num_fingers, |
| 385 | int x1, int y1, int x2, int y2) |
| 386 | { |
| 387 | alps_set_slot(dev, 0, num_fingers != 0, x1, y1); |
| 388 | alps_set_slot(dev, 1, num_fingers == 2, x2, y2); |
| 389 | } |
| 390 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 391 | static void alps_process_trackstick_packet_v3(struct psmouse *psmouse) |
| 392 | { |
| 393 | struct alps_data *priv = psmouse->private; |
| 394 | unsigned char *packet = psmouse->packet; |
| 395 | struct input_dev *dev = priv->dev2; |
| 396 | int x, y, z, left, right, middle; |
| 397 | |
| 398 | /* Sanity check packet */ |
| 399 | if (!(packet[0] & 0x40)) { |
| 400 | psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n"); |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * There's a special packet that seems to indicate the end |
| 406 | * of a stream of trackstick data. Filter these out. |
| 407 | */ |
| 408 | if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f) |
| 409 | return; |
| 410 | |
| 411 | x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f)); |
| 412 | y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f)); |
| 413 | z = (packet[4] & 0x7c) >> 2; |
| 414 | |
| 415 | /* |
| 416 | * The x and y values tend to be quite large, and when used |
| 417 | * alone the trackstick is difficult to use. Scale them down |
| 418 | * to compensate. |
| 419 | */ |
| 420 | x /= 8; |
| 421 | y /= 8; |
| 422 | |
| 423 | input_report_rel(dev, REL_X, x); |
| 424 | input_report_rel(dev, REL_Y, -y); |
| 425 | |
| 426 | /* |
| 427 | * Most ALPS models report the trackstick buttons in the touchpad |
| 428 | * packets, but a few report them here. No reliable way has been |
| 429 | * found to differentiate between the models upfront, so we enable |
| 430 | * the quirk in response to seeing a button press in the trackstick |
| 431 | * packet. |
| 432 | */ |
| 433 | left = packet[3] & 0x01; |
| 434 | right = packet[3] & 0x02; |
| 435 | middle = packet[3] & 0x04; |
| 436 | |
| 437 | if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) && |
| 438 | (left || right || middle)) |
| 439 | priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS; |
| 440 | |
| 441 | if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) { |
| 442 | input_report_key(dev, BTN_LEFT, left); |
| 443 | input_report_key(dev, BTN_RIGHT, right); |
| 444 | input_report_key(dev, BTN_MIDDLE, middle); |
| 445 | } |
| 446 | |
| 447 | input_sync(dev); |
| 448 | return; |
| 449 | } |
| 450 | |
| 451 | static void alps_process_touchpad_packet_v3(struct psmouse *psmouse) |
| 452 | { |
| 453 | struct alps_data *priv = psmouse->private; |
| 454 | unsigned char *packet = psmouse->packet; |
| 455 | struct input_dev *dev = psmouse->dev; |
| 456 | struct input_dev *dev2 = priv->dev2; |
| 457 | int x, y, z; |
| 458 | int left, right, middle; |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 459 | int x1 = 0, y1 = 0, x2 = 0, y2 = 0; |
| 460 | int fingers = 0, bmap_fingers; |
| 461 | unsigned int x_bitmap, y_bitmap; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 462 | |
| 463 | /* |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 464 | * There's no single feature of touchpad position and bitmap packets |
| 465 | * that can be used to distinguish between them. We rely on the fact |
| 466 | * that a bitmap packet should always follow a position packet with |
| 467 | * bit 6 of packet[4] set. |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 468 | */ |
| 469 | if (priv->multi_packet) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 470 | /* |
| 471 | * Sometimes a position packet will indicate a multi-packet |
| 472 | * sequence, but then what follows is another position |
| 473 | * packet. Check for this, and when it happens process the |
| 474 | * position packet as usual. |
| 475 | */ |
| 476 | if (packet[0] & 0x40) { |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 477 | fingers = (packet[5] & 0x3) + 1; |
| 478 | x_bitmap = ((packet[4] & 0x7e) << 8) | |
| 479 | ((packet[1] & 0x7f) << 2) | |
| 480 | ((packet[0] & 0x30) >> 4); |
| 481 | y_bitmap = ((packet[3] & 0x70) << 4) | |
| 482 | ((packet[2] & 0x7f) << 1) | |
| 483 | (packet[4] & 0x01); |
| 484 | |
| 485 | bmap_fingers = alps_process_bitmap(x_bitmap, y_bitmap, |
| 486 | &x1, &y1, &x2, &y2); |
| 487 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 488 | /* |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 489 | * We shouldn't report more than one finger if |
| 490 | * we don't have two coordinates. |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 491 | */ |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 492 | if (fingers > 1 && bmap_fingers < 2) |
| 493 | fingers = bmap_fingers; |
| 494 | |
| 495 | /* Now process position packet */ |
| 496 | packet = priv->multi_data; |
| 497 | } else { |
| 498 | priv->multi_packet = 0; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 502 | /* |
| 503 | * Bit 6 of byte 0 is not usually set in position packets. The only |
| 504 | * times it seems to be set is in situations where the data is |
| 505 | * suspect anyway, e.g. a palm resting flat on the touchpad. Given |
| 506 | * this combined with the fact that this bit is useful for filtering |
| 507 | * out misidentified bitmap packets, we reject anything with this |
| 508 | * bit set. |
| 509 | */ |
| 510 | if (packet[0] & 0x40) |
| 511 | return; |
| 512 | |
| 513 | if (!priv->multi_packet && (packet[4] & 0x40)) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 514 | priv->multi_packet = 1; |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 515 | memcpy(priv->multi_data, packet, sizeof(priv->multi_data)); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | priv->multi_packet = 0; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 520 | |
| 521 | left = packet[3] & 0x01; |
| 522 | right = packet[3] & 0x02; |
| 523 | middle = packet[3] & 0x04; |
| 524 | |
| 525 | x = ((packet[1] & 0x7f) << 4) | ((packet[4] & 0x30) >> 2) | |
| 526 | ((packet[0] & 0x30) >> 4); |
| 527 | y = ((packet[2] & 0x7f) << 4) | (packet[4] & 0x0f); |
| 528 | z = packet[5] & 0x7f; |
| 529 | |
| 530 | /* |
| 531 | * Sometimes the hardware sends a single packet with z = 0 |
| 532 | * in the middle of a stream. Real releases generate packets |
| 533 | * with x, y, and z all zero, so these seem to be flukes. |
| 534 | * Ignore them. |
| 535 | */ |
| 536 | if (x && y && !z) |
| 537 | return; |
| 538 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 539 | /* |
| 540 | * If we don't have MT data or the bitmaps were empty, we have |
| 541 | * to rely on ST data. |
| 542 | */ |
| 543 | if (!fingers) { |
| 544 | x1 = x; |
| 545 | y1 = y; |
| 546 | fingers = z > 0 ? 1 : 0; |
| 547 | } |
| 548 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 549 | if (z >= 64) |
| 550 | input_report_key(dev, BTN_TOUCH, 1); |
| 551 | else |
| 552 | input_report_key(dev, BTN_TOUCH, 0); |
| 553 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 554 | alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2); |
| 555 | |
| 556 | input_report_key(dev, BTN_TOOL_FINGER, fingers == 1); |
| 557 | input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); |
| 558 | input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); |
| 559 | input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4); |
| 560 | |
| 561 | input_report_key(dev, BTN_LEFT, left); |
| 562 | input_report_key(dev, BTN_RIGHT, right); |
| 563 | input_report_key(dev, BTN_MIDDLE, middle); |
| 564 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 565 | if (z > 0) { |
| 566 | input_report_abs(dev, ABS_X, x); |
| 567 | input_report_abs(dev, ABS_Y, y); |
| 568 | } |
| 569 | input_report_abs(dev, ABS_PRESSURE, z); |
| 570 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 571 | input_sync(dev); |
| 572 | |
| 573 | if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) { |
| 574 | left = packet[3] & 0x10; |
| 575 | right = packet[3] & 0x20; |
| 576 | middle = packet[3] & 0x40; |
| 577 | |
| 578 | input_report_key(dev2, BTN_LEFT, left); |
| 579 | input_report_key(dev2, BTN_RIGHT, right); |
| 580 | input_report_key(dev2, BTN_MIDDLE, middle); |
| 581 | input_sync(dev2); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | static void alps_process_packet_v3(struct psmouse *psmouse) |
| 586 | { |
| 587 | unsigned char *packet = psmouse->packet; |
| 588 | |
| 589 | /* |
| 590 | * v3 protocol packets come in three types, two representing |
| 591 | * touchpad data and one representing trackstick data. |
| 592 | * Trackstick packets seem to be distinguished by always |
| 593 | * having 0x3f in the last byte. This value has never been |
| 594 | * observed in the last byte of either of the other types |
| 595 | * of packets. |
| 596 | */ |
| 597 | if (packet[5] == 0x3f) { |
| 598 | alps_process_trackstick_packet_v3(psmouse); |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | alps_process_touchpad_packet_v3(psmouse); |
| 603 | } |
| 604 | |
| 605 | static void alps_process_packet_v4(struct psmouse *psmouse) |
| 606 | { |
| 607 | unsigned char *packet = psmouse->packet; |
| 608 | struct input_dev *dev = psmouse->dev; |
| 609 | int x, y, z; |
| 610 | int left, right; |
| 611 | |
| 612 | left = packet[4] & 0x01; |
| 613 | right = packet[4] & 0x02; |
| 614 | |
| 615 | x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) | |
| 616 | ((packet[0] & 0x30) >> 4); |
| 617 | y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f); |
| 618 | z = packet[5] & 0x7f; |
| 619 | |
| 620 | if (z >= 64) |
| 621 | input_report_key(dev, BTN_TOUCH, 1); |
| 622 | else |
| 623 | input_report_key(dev, BTN_TOUCH, 0); |
| 624 | |
| 625 | if (z > 0) { |
| 626 | input_report_abs(dev, ABS_X, x); |
| 627 | input_report_abs(dev, ABS_Y, y); |
| 628 | } |
| 629 | input_report_abs(dev, ABS_PRESSURE, z); |
| 630 | |
| 631 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 632 | input_report_key(dev, BTN_LEFT, left); |
| 633 | input_report_key(dev, BTN_RIGHT, right); |
| 634 | |
| 635 | input_sync(dev); |
| 636 | } |
| 637 | |
| 638 | static void alps_process_packet(struct psmouse *psmouse) |
| 639 | { |
| 640 | struct alps_data *priv = psmouse->private; |
| 641 | const struct alps_model_info *model = priv->i; |
| 642 | |
| 643 | switch (model->proto_version) { |
| 644 | case ALPS_PROTO_V1: |
| 645 | case ALPS_PROTO_V2: |
| 646 | alps_process_packet_v1_v2(psmouse); |
| 647 | break; |
| 648 | case ALPS_PROTO_V3: |
| 649 | alps_process_packet_v3(psmouse); |
| 650 | break; |
| 651 | case ALPS_PROTO_V4: |
| 652 | alps_process_packet_v4(psmouse); |
| 653 | break; |
| 654 | } |
| 655 | } |
| 656 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 657 | static void alps_report_bare_ps2_packet(struct psmouse *psmouse, |
| 658 | unsigned char packet[], |
| 659 | bool report_buttons) |
| 660 | { |
| 661 | struct alps_data *priv = psmouse->private; |
| 662 | struct input_dev *dev2 = priv->dev2; |
| 663 | |
| 664 | if (report_buttons) |
| 665 | alps_report_buttons(psmouse, dev2, psmouse->dev, |
| 666 | packet[0] & 1, packet[0] & 2, packet[0] & 4); |
| 667 | |
| 668 | input_report_rel(dev2, REL_X, |
| 669 | packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); |
| 670 | input_report_rel(dev2, REL_Y, |
| 671 | packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); |
| 672 | |
| 673 | input_sync(dev2); |
| 674 | } |
| 675 | |
| 676 | static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | { |
| 678 | struct alps_data *priv = psmouse->private; |
| 679 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 680 | if (psmouse->pktcnt < 6) |
| 681 | return PSMOUSE_GOOD_DATA; |
| 682 | |
| 683 | if (psmouse->pktcnt == 6) { |
| 684 | /* |
| 685 | * Start a timer to flush the packet if it ends up last |
| 686 | * 6-byte packet in the stream. Timer needs to fire |
| 687 | * psmouse core times out itself. 20 ms should be enough |
| 688 | * to decide if we are getting more data or not. |
| 689 | */ |
| 690 | mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20)); |
| 691 | return PSMOUSE_GOOD_DATA; |
| 692 | } |
| 693 | |
| 694 | del_timer(&priv->timer); |
| 695 | |
| 696 | if (psmouse->packet[6] & 0x80) { |
| 697 | |
| 698 | /* |
| 699 | * Highest bit is set - that means we either had |
| 700 | * complete ALPS packet and this is start of the |
| 701 | * next packet or we got garbage. |
| 702 | */ |
| 703 | |
| 704 | if (((psmouse->packet[3] | |
| 705 | psmouse->packet[4] | |
| 706 | psmouse->packet[5]) & 0x80) || |
| 707 | (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 708 | psmouse_dbg(psmouse, |
| 709 | "refusing packet %x %x %x %x (suspected interleaved ps/2)\n", |
| 710 | psmouse->packet[3], psmouse->packet[4], |
| 711 | psmouse->packet[5], psmouse->packet[6]); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 712 | return PSMOUSE_BAD_DATA; |
| 713 | } |
| 714 | |
| 715 | alps_process_packet(psmouse); |
| 716 | |
| 717 | /* Continue with the next packet */ |
| 718 | psmouse->packet[0] = psmouse->packet[6]; |
| 719 | psmouse->pktcnt = 1; |
| 720 | |
| 721 | } else { |
| 722 | |
| 723 | /* |
| 724 | * High bit is 0 - that means that we indeed got a PS/2 |
| 725 | * packet in the middle of ALPS packet. |
| 726 | * |
| 727 | * There is also possibility that we got 6-byte ALPS |
| 728 | * packet followed by 3-byte packet from trackpoint. We |
| 729 | * can not distinguish between these 2 scenarios but |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 730 | * because the latter is unlikely to happen in course of |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 731 | * normal operation (user would need to press all |
| 732 | * buttons on the pad and start moving trackpoint |
| 733 | * without touching the pad surface) we assume former. |
| 734 | * Even if we are wrong the wost thing that would happen |
| 735 | * the cursor would jump but we should not get protocol |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 736 | * de-synchronization. |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 737 | */ |
| 738 | |
| 739 | alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3], |
| 740 | false); |
| 741 | |
| 742 | /* |
| 743 | * Continue with the standard ALPS protocol handling, |
| 744 | * but make sure we won't process it as an interleaved |
| 745 | * packet again, which may happen if all buttons are |
| 746 | * pressed. To avoid this let's reset the 4th bit which |
| 747 | * is normally 1. |
| 748 | */ |
| 749 | psmouse->packet[3] = psmouse->packet[6] & 0xf7; |
| 750 | psmouse->pktcnt = 4; |
| 751 | } |
| 752 | |
| 753 | return PSMOUSE_GOOD_DATA; |
| 754 | } |
| 755 | |
| 756 | static void alps_flush_packet(unsigned long data) |
| 757 | { |
| 758 | struct psmouse *psmouse = (struct psmouse *)data; |
| 759 | |
| 760 | serio_pause_rx(psmouse->ps2dev.serio); |
| 761 | |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 762 | if (psmouse->pktcnt == psmouse->pktsize) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 763 | |
| 764 | /* |
| 765 | * We did not any more data in reasonable amount of time. |
| 766 | * Validate the last 3 bytes and process as a standard |
| 767 | * ALPS packet. |
| 768 | */ |
| 769 | if ((psmouse->packet[3] | |
| 770 | psmouse->packet[4] | |
| 771 | psmouse->packet[5]) & 0x80) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 772 | psmouse_dbg(psmouse, |
| 773 | "refusing packet %x %x %x (suspected interleaved ps/2)\n", |
| 774 | psmouse->packet[3], psmouse->packet[4], |
| 775 | psmouse->packet[5]); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 776 | } else { |
| 777 | alps_process_packet(psmouse); |
| 778 | } |
| 779 | psmouse->pktcnt = 0; |
| 780 | } |
| 781 | |
| 782 | serio_continue_rx(psmouse->ps2dev.serio); |
| 783 | } |
| 784 | |
| 785 | static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) |
| 786 | { |
| 787 | struct alps_data *priv = psmouse->private; |
| 788 | const struct alps_model_info *model = priv->i; |
| 789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ |
| 791 | if (psmouse->pktcnt == 3) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 792 | alps_report_bare_ps2_packet(psmouse, psmouse->packet, |
| 793 | true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | return PSMOUSE_FULL_PACKET; |
| 795 | } |
| 796 | return PSMOUSE_GOOD_DATA; |
| 797 | } |
| 798 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 799 | /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ |
| 800 | |
| 801 | if ((model->flags & ALPS_PS2_INTERLEAVED) && |
| 802 | psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { |
| 803 | return alps_handle_interleaved_ps2(psmouse); |
| 804 | } |
| 805 | |
| 806 | if (!alps_is_valid_first_byte(model, psmouse->packet[0])) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 807 | psmouse_dbg(psmouse, |
| 808 | "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n", |
| 809 | psmouse->packet[0], model->mask0, model->byte0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 813 | /* Bytes 2 - pktsize should have 0 in the highest bit */ |
| 814 | if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize && |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 815 | (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 816 | psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", |
| 817 | psmouse->pktcnt - 1, |
| 818 | psmouse->packet[psmouse->pktcnt - 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 820 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 822 | if (psmouse->pktcnt == psmouse->pktsize) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 823 | alps_process_packet(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | return PSMOUSE_FULL_PACKET; |
| 825 | } |
| 826 | |
| 827 | return PSMOUSE_GOOD_DATA; |
| 828 | } |
| 829 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 830 | static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble) |
| 831 | { |
| 832 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 833 | struct alps_data *priv = psmouse->private; |
| 834 | int command; |
| 835 | unsigned char *param; |
| 836 | unsigned char dummy[4]; |
| 837 | |
| 838 | BUG_ON(nibble > 0xf); |
| 839 | |
| 840 | command = priv->nibble_commands[nibble].command; |
| 841 | param = (command & 0x0f00) ? |
| 842 | dummy : (unsigned char *)&priv->nibble_commands[nibble].data; |
| 843 | |
| 844 | if (ps2_command(ps2dev, param, command)) |
| 845 | return -1; |
| 846 | |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr) |
| 851 | { |
| 852 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 853 | struct alps_data *priv = psmouse->private; |
| 854 | int i, nibble; |
| 855 | |
| 856 | if (ps2_command(ps2dev, NULL, priv->addr_command)) |
| 857 | return -1; |
| 858 | |
| 859 | for (i = 12; i >= 0; i -= 4) { |
| 860 | nibble = (addr >> i) & 0xf; |
| 861 | if (alps_command_mode_send_nibble(psmouse, nibble)) |
| 862 | return -1; |
| 863 | } |
| 864 | |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr) |
| 869 | { |
| 870 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 871 | unsigned char param[4]; |
| 872 | |
| 873 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 874 | return -1; |
| 875 | |
| 876 | /* |
| 877 | * The address being read is returned in the first two bytes |
| 878 | * of the result. Check that this address matches the expected |
| 879 | * address. |
| 880 | */ |
| 881 | if (addr != ((param[0] << 8) | param[1])) |
| 882 | return -1; |
| 883 | |
| 884 | return param[2]; |
| 885 | } |
| 886 | |
| 887 | static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr) |
| 888 | { |
| 889 | if (alps_command_mode_set_addr(psmouse, addr)) |
| 890 | return -1; |
| 891 | return __alps_command_mode_read_reg(psmouse, addr); |
| 892 | } |
| 893 | |
| 894 | static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value) |
| 895 | { |
| 896 | if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf)) |
| 897 | return -1; |
| 898 | if (alps_command_mode_send_nibble(psmouse, value & 0xf)) |
| 899 | return -1; |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr, |
| 904 | u8 value) |
| 905 | { |
| 906 | if (alps_command_mode_set_addr(psmouse, addr)) |
| 907 | return -1; |
| 908 | return __alps_command_mode_write_reg(psmouse, value); |
| 909 | } |
| 910 | |
| 911 | static int alps_enter_command_mode(struct psmouse *psmouse, |
| 912 | unsigned char *resp) |
| 913 | { |
| 914 | unsigned char param[4]; |
| 915 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 916 | |
| 917 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || |
| 918 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || |
| 919 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || |
| 920 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) { |
| 921 | psmouse_err(psmouse, "failed to enter command mode\n"); |
| 922 | return -1; |
| 923 | } |
| 924 | |
| 925 | if (param[0] != 0x88 && param[1] != 0x07) { |
| 926 | psmouse_dbg(psmouse, |
| 927 | "unknown response while entering command mode: %2.2x %2.2x %2.2x\n", |
| 928 | param[0], param[1], param[2]); |
| 929 | return -1; |
| 930 | } |
| 931 | |
| 932 | if (resp) |
| 933 | *resp = param[2]; |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | static inline int alps_exit_command_mode(struct psmouse *psmouse) |
| 938 | { |
| 939 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 940 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) |
| 941 | return -1; |
| 942 | return 0; |
| 943 | } |
| 944 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 945 | static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { |
| 947 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 948 | static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | unsigned char param[4]; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 950 | const struct alps_model_info *model = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | int i; |
| 952 | |
| 953 | /* |
| 954 | * First try "E6 report". |
| 955 | * ALPS should return 0,0,10 or 0,0,100 |
| 956 | */ |
| 957 | param[0] = 0; |
| 958 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || |
| 959 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 960 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 961 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) |
| 962 | return NULL; |
| 963 | |
| 964 | param[0] = param[1] = param[2] = 0xff; |
| 965 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 966 | return NULL; |
| 967 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 968 | psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x", |
| 969 | param[0], param[1], param[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100)) |
| 972 | return NULL; |
| 973 | |
| 974 | /* |
| 975 | * Now try "E7 report". Allowed responses are in |
| 976 | * alps_model_data[].signature |
| 977 | */ |
| 978 | param[0] = 0; |
| 979 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || |
| 980 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 981 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 982 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21)) |
| 983 | return NULL; |
| 984 | |
| 985 | param[0] = param[1] = param[2] = 0xff; |
| 986 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 987 | return NULL; |
| 988 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 989 | psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x", |
| 990 | param[0], param[1], param[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 992 | if (version) { |
| 993 | for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++) |
| 994 | /* empty */; |
| 995 | *version = (param[0] << 8) | (param[1] << 4) | i; |
| 996 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 998 | for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) { |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 999 | if (!memcmp(param, alps_model_data[i].signature, |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1000 | sizeof(alps_model_data[i].signature))) { |
| 1001 | model = alps_model_data + i; |
| 1002 | break; |
| 1003 | } |
| 1004 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1006 | if (model && model->proto_version > ALPS_PROTO_V2) { |
| 1007 | /* |
| 1008 | * Need to check command mode response to identify |
| 1009 | * model |
| 1010 | */ |
| 1011 | model = NULL; |
| 1012 | if (alps_enter_command_mode(psmouse, param)) { |
| 1013 | psmouse_warn(psmouse, |
| 1014 | "touchpad failed to enter command mode\n"); |
| 1015 | } else { |
| 1016 | for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) { |
| 1017 | if (alps_model_data[i].proto_version > ALPS_PROTO_V2 && |
| 1018 | alps_model_data[i].command_mode_resp == param[0]) { |
| 1019 | model = alps_model_data + i; |
| 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | alps_exit_command_mode(psmouse); |
| 1024 | |
| 1025 | if (!model) |
| 1026 | psmouse_dbg(psmouse, |
| 1027 | "Unknown command mode response %2.2x\n", |
| 1028 | param[0]); |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | return model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * For DualPoint devices select the device that should respond to |
| 1037 | * subsequent commands. It looks like glidepad is behind stickpointer, |
| 1038 | * I'd thought it would be other way around... |
| 1039 | */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1040 | static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | { |
| 1042 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; |
| 1044 | |
| 1045 | if (ps2_command(ps2dev, NULL, cmd) || |
| 1046 | ps2_command(ps2dev, NULL, cmd) || |
| 1047 | ps2_command(ps2dev, NULL, cmd) || |
| 1048 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 1049 | return -1; |
| 1050 | |
| 1051 | /* we may get 3 more bytes, just ignore them */ |
Dmitry Torokhov | c611763 | 2005-06-01 02:39:51 -0500 | [diff] [blame] | 1052 | ps2_drain(ps2dev, 3, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1057 | static int alps_absolute_mode_v1_v2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | { |
| 1059 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1060 | |
| 1061 | /* Try ALPS magic knock - 4 disable before enable */ |
| 1062 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1063 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1064 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1065 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1066 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) |
| 1067 | return -1; |
| 1068 | |
| 1069 | /* |
| 1070 | * Switch mouse to poll (remote) mode so motion data will not |
| 1071 | * get in our way |
| 1072 | */ |
| 1073 | return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); |
| 1074 | } |
| 1075 | |
| 1076 | static int alps_get_status(struct psmouse *psmouse, char *param) |
| 1077 | { |
| 1078 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1079 | |
| 1080 | /* Get status: 0xF5 0xF5 0xF5 0xE9 */ |
| 1081 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1082 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1083 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1084 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 1085 | return -1; |
| 1086 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1087 | psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x", |
| 1088 | param[0], param[1], param[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | /* |
| 1094 | * Turn touchpad tapping on or off. The sequences are: |
| 1095 | * 0xE9 0xF5 0xF5 0xF3 0x0A to enable, |
| 1096 | * 0xE9 0xF5 0xF5 0xE8 0x00 to disable. |
| 1097 | * My guess that 0xE9 (GetInfo) is here as a sync point. |
| 1098 | * For models that also have stickpointer (DualPoints) its tapping |
| 1099 | * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but |
| 1100 | * we don't fiddle with it. |
| 1101 | */ |
| 1102 | static int alps_tap_mode(struct psmouse *psmouse, int enable) |
| 1103 | { |
| 1104 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1105 | int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES; |
| 1106 | unsigned char tap_arg = enable ? 0x0A : 0x00; |
| 1107 | unsigned char param[4]; |
| 1108 | |
| 1109 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) || |
| 1110 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1111 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1112 | ps2_command(ps2dev, &tap_arg, cmd)) |
| 1113 | return -1; |
| 1114 | |
| 1115 | if (alps_get_status(psmouse, param)) |
| 1116 | return -1; |
| 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1121 | /* |
| 1122 | * alps_poll() - poll the touchpad for current motion packet. |
| 1123 | * Used in resync. |
| 1124 | */ |
| 1125 | static int alps_poll(struct psmouse *psmouse) |
| 1126 | { |
| 1127 | struct alps_data *priv = psmouse->private; |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 1128 | unsigned char buf[sizeof(psmouse->packet)]; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1129 | bool poll_failed; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1130 | |
| 1131 | if (priv->i->flags & ALPS_PASS) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1132 | alps_passthrough_mode_v2(psmouse, true); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1133 | |
| 1134 | poll_failed = ps2_command(&psmouse->ps2dev, buf, |
| 1135 | PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; |
| 1136 | |
| 1137 | if (priv->i->flags & ALPS_PASS) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1138 | alps_passthrough_mode_v2(psmouse, false); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1139 | |
| 1140 | if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) |
| 1141 | return -1; |
| 1142 | |
| 1143 | if ((psmouse->badbyte & 0xc8) == 0x08) { |
| 1144 | /* |
| 1145 | * Poll the track stick ... |
| 1146 | */ |
| 1147 | if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) |
| 1148 | return -1; |
| 1149 | } |
| 1150 | |
| 1151 | memcpy(psmouse->packet, buf, sizeof(buf)); |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1155 | static int alps_hw_init_v1_v2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
| 1157 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1158 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1160 | if ((model->flags & ALPS_PASS) && |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1161 | alps_passthrough_mode_v2(psmouse, true)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1165 | if (alps_tap_mode(psmouse, true)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1166 | psmouse_warn(psmouse, "Failed to enable hardware tapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | return -1; |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 1168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1170 | if (alps_absolute_mode_v1_v2(psmouse)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1171 | psmouse_err(psmouse, "Failed to enable absolute mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | return -1; |
| 1173 | } |
| 1174 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1175 | if ((model->flags & ALPS_PASS) && |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1176 | alps_passthrough_mode_v2(psmouse, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1180 | /* ALPS needs stream mode, otherwise it won't report any data */ |
| 1181 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1182 | psmouse_err(psmouse, "Failed to enable stream mode\n"); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1183 | return -1; |
| 1184 | } |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1189 | /* |
| 1190 | * Enable or disable passthrough mode to the trackstick. Must be in |
| 1191 | * command mode when calling this function. |
| 1192 | */ |
| 1193 | static int alps_passthrough_mode_v3(struct psmouse *psmouse, bool enable) |
| 1194 | { |
| 1195 | int reg_val; |
| 1196 | |
| 1197 | reg_val = alps_command_mode_read_reg(psmouse, 0x0008); |
| 1198 | if (reg_val == -1) |
| 1199 | return -1; |
| 1200 | |
| 1201 | if (enable) |
| 1202 | reg_val |= 0x01; |
| 1203 | else |
| 1204 | reg_val &= ~0x01; |
| 1205 | |
| 1206 | if (__alps_command_mode_write_reg(psmouse, reg_val)) |
| 1207 | return -1; |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
| 1212 | /* Must be in command mode when calling this function */ |
| 1213 | static int alps_absolute_mode_v3(struct psmouse *psmouse) |
| 1214 | { |
| 1215 | int reg_val; |
| 1216 | |
| 1217 | reg_val = alps_command_mode_read_reg(psmouse, 0x0004); |
| 1218 | if (reg_val == -1) |
| 1219 | return -1; |
| 1220 | |
| 1221 | reg_val |= 0x06; |
| 1222 | if (__alps_command_mode_write_reg(psmouse, reg_val)) |
| 1223 | return -1; |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
| 1228 | static int alps_hw_init_v3(struct psmouse *psmouse) |
| 1229 | { |
| 1230 | struct alps_data *priv = psmouse->private; |
| 1231 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1232 | int reg_val; |
| 1233 | unsigned char param[4]; |
| 1234 | |
| 1235 | priv->nibble_commands = alps_v3_nibble_commands; |
| 1236 | priv->addr_command = PSMOUSE_CMD_RESET_WRAP; |
| 1237 | |
| 1238 | if (alps_enter_command_mode(psmouse, NULL)) |
| 1239 | goto error; |
| 1240 | |
| 1241 | /* Check for trackstick */ |
| 1242 | reg_val = alps_command_mode_read_reg(psmouse, 0x0008); |
| 1243 | if (reg_val == -1) |
| 1244 | goto error; |
| 1245 | if (reg_val & 0x80) { |
| 1246 | if (alps_passthrough_mode_v3(psmouse, true)) |
| 1247 | goto error; |
| 1248 | if (alps_exit_command_mode(psmouse)) |
| 1249 | goto error; |
| 1250 | |
| 1251 | /* |
| 1252 | * E7 report for the trackstick |
| 1253 | * |
| 1254 | * There have been reports of failures to seem to trace back |
| 1255 | * to the above trackstick check failing. When these occur |
| 1256 | * this E7 report fails, so when that happens we continue |
| 1257 | * with the assumption that there isn't a trackstick after |
| 1258 | * all. |
| 1259 | */ |
| 1260 | param[0] = 0x64; |
| 1261 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 1262 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 1263 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 1264 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) { |
| 1265 | psmouse_warn(psmouse, "trackstick E7 report failed\n"); |
| 1266 | } else { |
| 1267 | psmouse_dbg(psmouse, |
| 1268 | "trackstick E7 report: %2.2x %2.2x %2.2x\n", |
| 1269 | param[0], param[1], param[2]); |
| 1270 | |
| 1271 | /* |
| 1272 | * Not sure what this does, but it is absolutely |
| 1273 | * essential. Without it, the touchpad does not |
| 1274 | * work at all and the trackstick just emits normal |
| 1275 | * PS/2 packets. |
| 1276 | */ |
| 1277 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1278 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1279 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1280 | alps_command_mode_send_nibble(psmouse, 0x9) || |
| 1281 | alps_command_mode_send_nibble(psmouse, 0x4)) { |
| 1282 | psmouse_err(psmouse, |
| 1283 | "Error sending magic E6 sequence\n"); |
| 1284 | goto error_passthrough; |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | if (alps_enter_command_mode(psmouse, NULL)) |
| 1289 | goto error_passthrough; |
| 1290 | if (alps_passthrough_mode_v3(psmouse, false)) |
| 1291 | goto error; |
| 1292 | } |
| 1293 | |
| 1294 | if (alps_absolute_mode_v3(psmouse)) { |
| 1295 | psmouse_err(psmouse, "Failed to enter absolute mode\n"); |
| 1296 | goto error; |
| 1297 | } |
| 1298 | |
| 1299 | reg_val = alps_command_mode_read_reg(psmouse, 0x0006); |
| 1300 | if (reg_val == -1) |
| 1301 | goto error; |
| 1302 | if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) |
| 1303 | goto error; |
| 1304 | |
| 1305 | reg_val = alps_command_mode_read_reg(psmouse, 0x0007); |
| 1306 | if (reg_val == -1) |
| 1307 | goto error; |
| 1308 | if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) |
| 1309 | goto error; |
| 1310 | |
| 1311 | if (alps_command_mode_read_reg(psmouse, 0x0144) == -1) |
| 1312 | goto error; |
| 1313 | if (__alps_command_mode_write_reg(psmouse, 0x04)) |
| 1314 | goto error; |
| 1315 | |
| 1316 | if (alps_command_mode_read_reg(psmouse, 0x0159) == -1) |
| 1317 | goto error; |
| 1318 | if (__alps_command_mode_write_reg(psmouse, 0x03)) |
| 1319 | goto error; |
| 1320 | |
| 1321 | if (alps_command_mode_read_reg(psmouse, 0x0163) == -1) |
| 1322 | goto error; |
| 1323 | if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03)) |
| 1324 | goto error; |
| 1325 | |
| 1326 | if (alps_command_mode_read_reg(psmouse, 0x0162) == -1) |
| 1327 | goto error; |
| 1328 | if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04)) |
| 1329 | goto error; |
| 1330 | |
| 1331 | /* |
| 1332 | * This ensures the trackstick packets are in the format |
| 1333 | * supported by this driver. If bit 1 isn't set the packet |
| 1334 | * format is different. |
| 1335 | */ |
| 1336 | if (alps_command_mode_write_reg(psmouse, 0x0008, 0x82)) |
| 1337 | goto error; |
| 1338 | |
| 1339 | alps_exit_command_mode(psmouse); |
| 1340 | |
| 1341 | /* Set rate and enable data reporting */ |
| 1342 | param[0] = 0x64; |
| 1343 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || |
| 1344 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { |
| 1345 | psmouse_err(psmouse, "Failed to enable data reporting\n"); |
| 1346 | return -1; |
| 1347 | } |
| 1348 | |
| 1349 | return 0; |
| 1350 | |
| 1351 | error_passthrough: |
| 1352 | /* Something failed while in passthrough mode, so try to get out */ |
| 1353 | if (!alps_enter_command_mode(psmouse, NULL)) |
| 1354 | alps_passthrough_mode_v3(psmouse, false); |
| 1355 | error: |
| 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 | |
| 1365 | /* Must be in command mode when calling this function */ |
| 1366 | static int alps_absolute_mode_v4(struct psmouse *psmouse) |
| 1367 | { |
| 1368 | int reg_val; |
| 1369 | |
| 1370 | reg_val = alps_command_mode_read_reg(psmouse, 0x0004); |
| 1371 | if (reg_val == -1) |
| 1372 | return -1; |
| 1373 | |
| 1374 | reg_val |= 0x02; |
| 1375 | if (__alps_command_mode_write_reg(psmouse, reg_val)) |
| 1376 | return -1; |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
| 1381 | static int alps_hw_init_v4(struct psmouse *psmouse) |
| 1382 | { |
| 1383 | struct alps_data *priv = psmouse->private; |
| 1384 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1385 | unsigned char param[4]; |
| 1386 | |
| 1387 | priv->nibble_commands = alps_v4_nibble_commands; |
| 1388 | priv->addr_command = PSMOUSE_CMD_DISABLE; |
| 1389 | |
| 1390 | if (alps_enter_command_mode(psmouse, NULL)) |
| 1391 | goto error; |
| 1392 | |
| 1393 | if (alps_absolute_mode_v4(psmouse)) { |
| 1394 | psmouse_err(psmouse, "Failed to enter absolute mode\n"); |
| 1395 | goto error; |
| 1396 | } |
| 1397 | |
| 1398 | if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c)) |
| 1399 | goto error; |
| 1400 | |
| 1401 | if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03)) |
| 1402 | goto error; |
| 1403 | |
| 1404 | if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03)) |
| 1405 | goto error; |
| 1406 | |
| 1407 | if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15)) |
| 1408 | goto error; |
| 1409 | |
| 1410 | if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01)) |
| 1411 | goto error; |
| 1412 | |
| 1413 | if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03)) |
| 1414 | goto error; |
| 1415 | |
| 1416 | if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03)) |
| 1417 | goto error; |
| 1418 | |
| 1419 | if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03)) |
| 1420 | goto error; |
| 1421 | |
| 1422 | alps_exit_command_mode(psmouse); |
| 1423 | |
| 1424 | /* |
| 1425 | * This sequence changes the output from a 9-byte to an |
| 1426 | * 8-byte format. All the same data seems to be present, |
| 1427 | * just in a more compact format. |
| 1428 | */ |
| 1429 | param[0] = 0xc8; |
| 1430 | param[1] = 0x64; |
| 1431 | param[2] = 0x50; |
| 1432 | if (ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || |
| 1433 | ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE) || |
| 1434 | ps2_command(ps2dev, ¶m[2], PSMOUSE_CMD_SETRATE) || |
| 1435 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) |
| 1436 | return -1; |
| 1437 | |
| 1438 | /* Set rate and enable data reporting */ |
| 1439 | param[0] = 0x64; |
| 1440 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || |
| 1441 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { |
| 1442 | psmouse_err(psmouse, "Failed to enable data reporting\n"); |
| 1443 | return -1; |
| 1444 | } |
| 1445 | |
| 1446 | return 0; |
| 1447 | |
| 1448 | error: |
| 1449 | /* |
| 1450 | * Leaving the touchpad in command mode will essentially render |
| 1451 | * it unusable until the machine reboots, so exit it here just |
| 1452 | * to be safe |
| 1453 | */ |
| 1454 | alps_exit_command_mode(psmouse); |
| 1455 | return -1; |
| 1456 | } |
| 1457 | |
| 1458 | static int alps_hw_init(struct psmouse *psmouse) |
| 1459 | { |
| 1460 | struct alps_data *priv = psmouse->private; |
| 1461 | const struct alps_model_info *model = priv->i; |
| 1462 | int ret = -1; |
| 1463 | |
| 1464 | switch (model->proto_version) { |
| 1465 | case ALPS_PROTO_V1: |
| 1466 | case ALPS_PROTO_V2: |
| 1467 | ret = alps_hw_init_v1_v2(psmouse); |
| 1468 | break; |
| 1469 | case ALPS_PROTO_V3: |
| 1470 | ret = alps_hw_init_v3(psmouse); |
| 1471 | break; |
| 1472 | case ALPS_PROTO_V4: |
| 1473 | ret = alps_hw_init_v4(psmouse); |
| 1474 | break; |
| 1475 | } |
| 1476 | |
| 1477 | return ret; |
| 1478 | } |
| 1479 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1480 | static int alps_reconnect(struct psmouse *psmouse) |
| 1481 | { |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1482 | const struct alps_model_info *model; |
| 1483 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1484 | psmouse_reset(psmouse); |
| 1485 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1486 | model = alps_get_model(psmouse, NULL); |
| 1487 | if (!model) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1488 | return -1; |
| 1489 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1490 | return alps_hw_init(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | static void alps_disconnect(struct psmouse *psmouse) |
| 1494 | { |
| 1495 | struct alps_data *priv = psmouse->private; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | psmouse_reset(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1498 | del_timer_sync(&priv->timer); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1499 | input_unregister_device(priv->dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | kfree(priv); |
| 1501 | } |
| 1502 | |
| 1503 | int alps_init(struct psmouse *psmouse) |
| 1504 | { |
| 1505 | struct alps_data *priv; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1506 | const struct alps_model_info *model; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1507 | struct input_dev *dev1 = psmouse->dev, *dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | int version; |
| 1509 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 1510 | priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1511 | dev2 = input_allocate_device(); |
| 1512 | if (!priv || !dev2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | goto init_fail; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1514 | |
| 1515 | priv->dev2 = dev2; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1516 | setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse); |
| 1517 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1518 | psmouse->private = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1520 | psmouse_reset(psmouse); |
| 1521 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1522 | model = alps_get_model(psmouse, &version); |
| 1523 | if (!model) |
| 1524 | goto init_fail; |
| 1525 | |
| 1526 | priv->i = model; |
| 1527 | |
| 1528 | if (alps_hw_init(psmouse)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | goto init_fail; |
| 1530 | |
Dmitry Torokhov | 7105d2e | 2009-12-11 23:54:54 -0800 | [diff] [blame] | 1531 | /* |
| 1532 | * Undo part of setup done for us by psmouse core since touchpad |
| 1533 | * is not a relative device. |
| 1534 | */ |
| 1535 | __clear_bit(EV_REL, dev1->evbit); |
| 1536 | __clear_bit(REL_X, dev1->relbit); |
| 1537 | __clear_bit(REL_Y, dev1->relbit); |
| 1538 | |
| 1539 | /* |
| 1540 | * Now set up our capabilities. |
| 1541 | */ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1542 | dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY); |
| 1543 | dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH); |
| 1544 | dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1545 | dev1->keybit[BIT_WORD(BTN_LEFT)] |= |
| 1546 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1548 | dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1549 | |
| 1550 | switch (model->proto_version) { |
| 1551 | case ALPS_PROTO_V1: |
| 1552 | case ALPS_PROTO_V2: |
| 1553 | input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); |
| 1554 | input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0); |
| 1555 | break; |
| 1556 | case ALPS_PROTO_V3: |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 1557 | set_bit(INPUT_PROP_SEMI_MT, dev1->propbit); |
| 1558 | input_mt_init_slots(dev1, 2); |
| 1559 | input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, ALPS_V3_X_MAX, 0, 0); |
| 1560 | input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, ALPS_V3_Y_MAX, 0, 0); |
| 1561 | |
| 1562 | set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit); |
| 1563 | set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit); |
| 1564 | set_bit(BTN_TOOL_QUADTAP, dev1->keybit); |
| 1565 | /* fall through */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1566 | case ALPS_PROTO_V4: |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 1567 | input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0); |
| 1568 | input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1569 | break; |
| 1570 | } |
| 1571 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1572 | input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1574 | if (model->flags & ALPS_WHEEL) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1575 | dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); |
| 1576 | dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1579 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1580 | dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); |
| 1581 | dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1584 | if (model->flags & ALPS_FOUR_BUTTONS) { |
| 1585 | dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0); |
| 1586 | dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1); |
| 1587 | dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2); |
| 1588 | dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3); |
| 1589 | } else { |
| 1590 | dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE); |
| 1591 | } |
| 1592 | |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 1593 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1594 | dev2->phys = priv->phys; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1595 | dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1596 | dev2->id.bustype = BUS_I8042; |
| 1597 | dev2->id.vendor = 0x0002; |
| 1598 | dev2->id.product = PSMOUSE_ALPS; |
| 1599 | dev2->id.version = 0x0000; |
Dmitry Torokhov | 1db3a34 | 2008-03-18 00:29:18 -0400 | [diff] [blame] | 1600 | dev2->dev.parent = &psmouse->ps2dev.serio->dev; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 1601 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1602 | dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 1603 | dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
| 1604 | dev2->keybit[BIT_WORD(BTN_LEFT)] = |
| 1605 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 1607 | if (input_register_device(priv->dev2)) |
| 1608 | goto init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
| 1610 | psmouse->protocol_handler = alps_process_byte; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1611 | psmouse->poll = alps_poll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | psmouse->disconnect = alps_disconnect; |
| 1613 | psmouse->reconnect = alps_reconnect; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1614 | psmouse->pktsize = model->proto_version == ALPS_PROTO_V4 ? 8 : 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1616 | /* We are having trouble resyncing ALPS touchpads so disable it for now */ |
| 1617 | psmouse->resync_time = 0; |
| 1618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | return 0; |
| 1620 | |
| 1621 | init_fail: |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 1622 | psmouse_reset(psmouse); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 1623 | input_free_device(dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | kfree(priv); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1625 | psmouse->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | return -1; |
| 1627 | } |
| 1628 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1629 | int alps_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | { |
| 1631 | int version; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 1632 | const struct alps_model_info *model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 1634 | model = alps_get_model(psmouse, &version); |
| 1635 | if (!model) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | return -1; |
| 1637 | |
| 1638 | if (set_properties) { |
| 1639 | psmouse->vendor = "ALPS"; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 1640 | psmouse->name = model->flags & ALPS_DUALPOINT ? |
| 1641 | "DualPoint TouchPad" : "GlidePoint"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | psmouse->model = version; |
| 1643 | } |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |