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 | */ |
| 30 | #define ALPS_CMD_NIBBLE_10 0x01f2 |
| 31 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 32 | #define ALPS_REG_BASE_RUSHMORE 0xc2c0 |
| 33 | #define ALPS_REG_BASE_PINNACLE 0x0000 |
| 34 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 35 | static 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 | |
| 54 | static 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 Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 73 | static 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 Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 92 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 93 | #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 Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 100 | #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with |
| 101 | 6-byte ALPS packet */ |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 102 | #define ALPS_BUTTONPAD 0x200 /* device is a clickpad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 104 | static const struct alps_model_info alps_model_data[] = { |
Dmitry Torokhov | 8326bb5 | 2015-01-13 21:08:00 -0800 | [diff] [blame] | 105 | { { 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 Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 123 | /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ |
Dmitry Torokhov | 8326bb5 | 2015-01-13 21:08:00 -0800 | [diff] [blame] | 124 | { { 0x62, 0x02, 0x14 }, 0x00, { ALPS_PROTO_V2, 0xcf, 0xcf, |
| 125 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED } }, |
| 126 | { { 0x73, 0x00, 0x14 }, 0x00, { ALPS_PROTO_V6, 0xff, 0xff, ALPS_DUALPOINT } }, /* Dell XT2 */ |
| 127 | { { 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 */ |
| 130 | { { 0x73, 0x02, 0x64 }, 0x8a, { ALPS_PROTO_V4, 0x8f, 0x8f, 0 } }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 133 | static const struct alps_protocol_info alps_v3_protocol_data = { |
| 134 | ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT |
| 135 | }; |
| 136 | |
| 137 | static const struct alps_protocol_info alps_v3_rushmore_data = { |
| 138 | ALPS_PROTO_V3_RUSHMORE, 0x8f, 0x8f, ALPS_DUALPOINT |
| 139 | }; |
| 140 | |
| 141 | static const struct alps_protocol_info alps_v5_protocol_data = { |
| 142 | ALPS_PROTO_V5, 0xc8, 0xd8, 0 |
| 143 | }; |
| 144 | |
| 145 | static const struct alps_protocol_info alps_v7_protocol_data = { |
| 146 | ALPS_PROTO_V7, 0x48, 0x48, ALPS_DUALPOINT |
| 147 | }; |
| 148 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 149 | static void alps_set_abs_params_st(struct alps_data *priv, |
| 150 | struct input_dev *dev1); |
| 151 | static void alps_set_abs_params_mt(struct alps_data *priv, |
| 152 | struct input_dev *dev1); |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /* |
| 155 | * XXX - this entry is suspicious. First byte has zero lower nibble, |
| 156 | * which is what a normal mouse would report. Also, the value 0x0e |
| 157 | * isn't valid per PS/2 spec. |
| 158 | */ |
| 159 | |
Seth Forshee | d4b347b | 2011-11-07 19:53:15 -0800 | [diff] [blame] | 160 | /* Packet formats are described in Documentation/input/alps.txt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 162 | static bool alps_is_valid_first_byte(struct alps_data *priv, |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 163 | unsigned char data) |
| 164 | { |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 165 | return (data & priv->mask0) == priv->byte0; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static void alps_report_buttons(struct psmouse *psmouse, |
| 169 | struct input_dev *dev1, struct input_dev *dev2, |
| 170 | int left, int right, int middle) |
| 171 | { |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 172 | struct input_dev *dev; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 173 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 174 | /* |
| 175 | * If shared button has already been reported on the |
| 176 | * other device (dev2) then this event should be also |
| 177 | * sent through that device. |
| 178 | */ |
| 179 | dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1; |
| 180 | input_report_key(dev, BTN_LEFT, left); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 181 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 182 | dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1; |
| 183 | input_report_key(dev, BTN_RIGHT, right); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 184 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 185 | dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1; |
| 186 | input_report_key(dev, BTN_MIDDLE, middle); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 187 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 188 | /* |
| 189 | * Sync the _other_ device now, we'll do the first |
| 190 | * device later once we report the rest of the events. |
| 191 | */ |
| 192 | input_sync(dev2); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 195 | static void alps_process_packet_v1_v2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | struct alps_data *priv = psmouse->private; |
| 198 | unsigned char *packet = psmouse->packet; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 199 | struct input_dev *dev = psmouse->dev; |
| 200 | struct input_dev *dev2 = priv->dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | int x, y, z, ges, fin, left, right, middle; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 202 | int back = 0, forward = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 204 | if (priv->proto_version == ALPS_PROTO_V1) { |
Yotam Medini | d2f4012 | 2006-05-29 23:30:36 -0400 | [diff] [blame] | 205 | left = packet[2] & 0x10; |
| 206 | right = packet[2] & 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | middle = 0; |
| 208 | x = packet[1] | ((packet[0] & 0x07) << 7); |
| 209 | y = packet[4] | ((packet[3] & 0x07) << 7); |
| 210 | z = packet[5]; |
| 211 | } else { |
| 212 | left = packet[3] & 1; |
| 213 | right = packet[3] & 2; |
| 214 | middle = packet[3] & 4; |
| 215 | x = packet[1] | ((packet[2] & 0x78) << (7 - 3)); |
| 216 | y = packet[4] | ((packet[3] & 0x70) << (7 - 4)); |
| 217 | z = packet[5]; |
| 218 | } |
| 219 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 220 | if (priv->flags & ALPS_FW_BK_1) { |
Laszlo Kajan | 3c00bb9 | 2008-03-18 00:39:55 -0400 | [diff] [blame] | 221 | back = packet[0] & 0x10; |
| 222 | forward = packet[2] & 4; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 225 | if (priv->flags & ALPS_FW_BK_2) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 226 | back = packet[3] & 4; |
| 227 | forward = packet[2] & 4; |
| 228 | if ((middle = forward && back)) |
| 229 | forward = back = 0; |
| 230 | } |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | ges = packet[2] & 1; |
| 233 | fin = packet[2] & 2; |
| 234 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 235 | if ((priv->flags & ALPS_DUALPOINT) && z == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); |
| 237 | input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 238 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 239 | alps_report_buttons(psmouse, dev2, dev, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | input_sync(dev2); |
| 242 | return; |
| 243 | } |
| 244 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 245 | alps_report_buttons(psmouse, dev, dev2, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | /* Convert hardware tap to a reasonable Z value */ |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 248 | if (ges && !fin) |
| 249 | z = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * A "tap and drag" operation is reported by the hardware as a transition |
| 253 | * from (!fin && ges) to (fin && ges). This should be translated to the |
| 254 | * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually. |
| 255 | */ |
| 256 | if (ges && fin && !priv->prev_fin) { |
| 257 | input_report_abs(dev, ABS_X, x); |
| 258 | input_report_abs(dev, ABS_Y, y); |
| 259 | input_report_abs(dev, ABS_PRESSURE, 0); |
| 260 | input_report_key(dev, BTN_TOOL_FINGER, 0); |
| 261 | input_sync(dev); |
| 262 | } |
| 263 | priv->prev_fin = fin; |
| 264 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 265 | if (z > 30) |
| 266 | input_report_key(dev, BTN_TOUCH, 1); |
| 267 | if (z < 25) |
| 268 | input_report_key(dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | if (z > 0) { |
| 271 | input_report_abs(dev, ABS_X, x); |
| 272 | input_report_abs(dev, ABS_Y, y); |
| 273 | } |
| 274 | |
| 275 | input_report_abs(dev, ABS_PRESSURE, z); |
| 276 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 277 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 278 | if (priv->flags & ALPS_WHEEL) |
Vojtech Pavlik | e6c047b | 2005-09-04 01:40:43 -0500 | [diff] [blame] | 279 | 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] | 280 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 281 | if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 282 | input_report_key(dev, BTN_FORWARD, forward); |
| 283 | input_report_key(dev, BTN_BACK, back); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 286 | if (priv->flags & ALPS_FOUR_BUTTONS) { |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 287 | input_report_key(dev, BTN_0, packet[2] & 4); |
| 288 | input_report_key(dev, BTN_1, packet[0] & 0x10); |
| 289 | input_report_key(dev, BTN_2, packet[3] & 4); |
| 290 | input_report_key(dev, BTN_3, packet[0] & 0x20); |
| 291 | } |
| 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | input_sync(dev); |
| 294 | } |
| 295 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 296 | /* |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 297 | * Process bitmap data for V5 protocols. Return value is null. |
| 298 | * |
| 299 | * The bitmaps don't have enough data to track fingers, so this function |
| 300 | * only generates points representing a bounding box of at most two contacts. |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 301 | * These two points are returned in fields->mt. |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 302 | */ |
| 303 | static void alps_process_bitmap_dolphin(struct alps_data *priv, |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 304 | struct alps_fields *fields) |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 305 | { |
| 306 | int box_middle_x, box_middle_y; |
| 307 | unsigned int x_map, y_map; |
| 308 | unsigned char start_bit, end_bit; |
| 309 | unsigned char x_msb, x_lsb, y_msb, y_lsb; |
| 310 | |
| 311 | x_map = fields->x_map; |
| 312 | y_map = fields->y_map; |
| 313 | |
| 314 | if (!x_map || !y_map) |
| 315 | return; |
| 316 | |
| 317 | /* Get Most-significant and Least-significant bit */ |
| 318 | x_msb = fls(x_map); |
| 319 | x_lsb = ffs(x_map); |
| 320 | y_msb = fls(y_map); |
| 321 | y_lsb = ffs(y_map); |
| 322 | |
| 323 | /* Most-significant bit should never exceed max sensor line number */ |
| 324 | if (x_msb > priv->x_bits || y_msb > priv->y_bits) |
| 325 | return; |
| 326 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 327 | if (fields->fingers > 1) { |
| 328 | start_bit = priv->x_bits - x_msb; |
| 329 | end_bit = priv->x_bits - x_lsb; |
| 330 | box_middle_x = (priv->x_max * (start_bit + end_bit)) / |
| 331 | (2 * (priv->x_bits - 1)); |
| 332 | |
| 333 | start_bit = y_lsb - 1; |
| 334 | end_bit = y_msb - 1; |
| 335 | box_middle_y = (priv->y_max * (start_bit + end_bit)) / |
| 336 | (2 * (priv->y_bits - 1)); |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 337 | fields->mt[0] = fields->st; |
| 338 | fields->mt[1].x = 2 * box_middle_x - fields->mt[0].x; |
| 339 | fields->mt[1].y = 2 * box_middle_y - fields->mt[0].y; |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Hans de Goede | 036e6c7 | 2014-07-25 22:38:51 -0700 | [diff] [blame] | 343 | static void alps_get_bitmap_points(unsigned int map, |
| 344 | struct alps_bitmap_point *low, |
| 345 | struct alps_bitmap_point *high, |
| 346 | int *fingers) |
| 347 | { |
| 348 | struct alps_bitmap_point *point; |
| 349 | int i, bit, prev_bit = 0; |
| 350 | |
| 351 | point = low; |
| 352 | for (i = 0; map != 0; i++, map >>= 1) { |
| 353 | bit = map & 1; |
| 354 | if (bit) { |
| 355 | if (!prev_bit) { |
| 356 | point->start_bit = i; |
Hans de Goede | 105affb | 2014-07-25 22:41:51 -0700 | [diff] [blame] | 357 | point->num_bits = 0; |
Hans de Goede | 036e6c7 | 2014-07-25 22:38:51 -0700 | [diff] [blame] | 358 | (*fingers)++; |
| 359 | } |
| 360 | point->num_bits++; |
| 361 | } else { |
| 362 | if (prev_bit) |
| 363 | point = high; |
Hans de Goede | 036e6c7 | 2014-07-25 22:38:51 -0700 | [diff] [blame] | 364 | } |
| 365 | prev_bit = bit; |
| 366 | } |
| 367 | } |
| 368 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 369 | /* |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 370 | * Process bitmap data from v3 and v4 protocols. Returns the number of |
| 371 | * fingers detected. A return value of 0 means at least one of the |
| 372 | * bitmaps was empty. |
| 373 | * |
| 374 | * The bitmaps don't have enough data to track fingers, so this function |
| 375 | * only generates points representing a bounding box of all contacts. |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 376 | * These points are returned in fields->mt when the return value |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 377 | * is greater than 0. |
| 378 | */ |
Kevin Cernekee | 7a9f73e | 2013-02-13 22:24:55 -0800 | [diff] [blame] | 379 | static int alps_process_bitmap(struct alps_data *priv, |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 380 | struct alps_fields *fields) |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 381 | { |
Hans de Goede | 036e6c7 | 2014-07-25 22:38:51 -0700 | [diff] [blame] | 382 | int i, fingers_x = 0, fingers_y = 0, fingers; |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 383 | struct alps_bitmap_point x_low = {0,}, x_high = {0,}; |
| 384 | struct alps_bitmap_point y_low = {0,}, y_high = {0,}; |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 385 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 386 | if (!fields->x_map || !fields->y_map) |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 387 | return 0; |
| 388 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 389 | alps_get_bitmap_points(fields->x_map, &x_low, &x_high, &fingers_x); |
| 390 | alps_get_bitmap_points(fields->y_map, &y_low, &y_high, &fingers_y); |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 391 | |
| 392 | /* |
| 393 | * Fingers can overlap, so we use the maximum count of fingers |
| 394 | * on either axis as the finger count. |
| 395 | */ |
| 396 | fingers = max(fingers_x, fingers_y); |
| 397 | |
| 398 | /* |
Hans de Goede | 20bea68 | 2014-07-25 22:33:33 -0700 | [diff] [blame] | 399 | * If an axis reports only a single contact, we have overlapping or |
| 400 | * adjacent fingers. Divide the single contact between the two points. |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 401 | */ |
Hans de Goede | 20bea68 | 2014-07-25 22:33:33 -0700 | [diff] [blame] | 402 | if (fingers_x == 1) { |
Hans de Goede | 28835f4 | 2014-07-25 22:42:53 -0700 | [diff] [blame] | 403 | i = (x_low.num_bits - 1) / 2; |
Hans de Goede | 20bea68 | 2014-07-25 22:33:33 -0700 | [diff] [blame] | 404 | x_low.num_bits = x_low.num_bits - i; |
| 405 | x_high.start_bit = x_low.start_bit + i; |
| 406 | x_high.num_bits = max(i, 1); |
| 407 | } |
| 408 | if (fingers_y == 1) { |
Hans de Goede | 28835f4 | 2014-07-25 22:42:53 -0700 | [diff] [blame] | 409 | i = (y_low.num_bits - 1) / 2; |
Hans de Goede | 20bea68 | 2014-07-25 22:33:33 -0700 | [diff] [blame] | 410 | y_low.num_bits = y_low.num_bits - i; |
| 411 | y_high.start_bit = y_low.start_bit + i; |
| 412 | y_high.num_bits = max(i, 1); |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 415 | fields->mt[0].x = |
| 416 | (priv->x_max * (2 * x_low.start_bit + x_low.num_bits - 1)) / |
| 417 | (2 * (priv->x_bits - 1)); |
| 418 | fields->mt[0].y = |
| 419 | (priv->y_max * (2 * y_low.start_bit + y_low.num_bits - 1)) / |
| 420 | (2 * (priv->y_bits - 1)); |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 421 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 422 | fields->mt[1].x = |
| 423 | (priv->x_max * (2 * x_high.start_bit + x_high.num_bits - 1)) / |
| 424 | (2 * (priv->x_bits - 1)); |
| 425 | fields->mt[1].y = |
| 426 | (priv->y_max * (2 * y_high.start_bit + y_high.num_bits - 1)) / |
| 427 | (2 * (priv->y_bits - 1)); |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 428 | |
Hans de Goede | 40e8f53 | 2014-07-25 22:37:15 -0700 | [diff] [blame] | 429 | /* y-bitmap order is reversed, except on rushmore */ |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 430 | if (priv->proto_version != ALPS_PROTO_V3_RUSHMORE) { |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 431 | fields->mt[0].y = priv->y_max - fields->mt[0].y; |
| 432 | fields->mt[1].y = priv->y_max - fields->mt[1].y; |
Hans de Goede | 40e8f53 | 2014-07-25 22:37:15 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 435 | return fingers; |
| 436 | } |
| 437 | |
Hans de Goede | cdf333e | 2014-07-25 22:44:42 -0700 | [diff] [blame] | 438 | static void alps_set_slot(struct input_dev *dev, int slot, int x, int y) |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 439 | { |
| 440 | input_mt_slot(dev, slot); |
Hans de Goede | cdf333e | 2014-07-25 22:44:42 -0700 | [diff] [blame] | 441 | input_mt_report_slot_state(dev, MT_TOOL_FINGER, true); |
| 442 | input_report_abs(dev, ABS_MT_POSITION_X, x); |
| 443 | input_report_abs(dev, ABS_MT_POSITION_Y, y); |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Hans de Goede | cdf333e | 2014-07-25 22:44:42 -0700 | [diff] [blame] | 446 | static void alps_report_mt_data(struct psmouse *psmouse, int n) |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 447 | { |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 448 | struct alps_data *priv = psmouse->private; |
| 449 | struct input_dev *dev = psmouse->dev; |
| 450 | struct alps_fields *f = &priv->f; |
Hans de Goede | cdf333e | 2014-07-25 22:44:42 -0700 | [diff] [blame] | 451 | int i, slot[MAX_TOUCHES]; |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 452 | |
Henrik Rydberg | 448c7f38 | 2015-02-01 11:25:14 -0800 | [diff] [blame] | 453 | input_mt_assign_slots(dev, slot, f->mt, n, 0); |
Hans de Goede | cdf333e | 2014-07-25 22:44:42 -0700 | [diff] [blame] | 454 | for (i = 0; i < n; i++) |
| 455 | alps_set_slot(dev, slot[i], f->mt[i].x, f->mt[i].y); |
| 456 | |
| 457 | input_mt_sync_frame(dev); |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 458 | } |
| 459 | |
Hans de Goede | 68c2187 | 2014-07-25 22:47:25 -0700 | [diff] [blame] | 460 | static void alps_report_semi_mt_data(struct psmouse *psmouse, int fingers) |
| 461 | { |
| 462 | struct alps_data *priv = psmouse->private; |
| 463 | struct input_dev *dev = psmouse->dev; |
| 464 | struct alps_fields *f = &priv->f; |
| 465 | |
| 466 | /* Use st data when we don't have mt data */ |
| 467 | if (fingers < 2) { |
| 468 | f->mt[0].x = f->st.x; |
| 469 | f->mt[0].y = f->st.y; |
| 470 | fingers = f->pressure > 0 ? 1 : 0; |
| 471 | } |
| 472 | |
Hans de Goede | 99d9996 | 2014-07-25 22:48:02 -0700 | [diff] [blame] | 473 | alps_report_mt_data(psmouse, (fingers <= 2) ? fingers : 2); |
Hans de Goede | 68c2187 | 2014-07-25 22:47:25 -0700 | [diff] [blame] | 474 | |
| 475 | input_mt_report_finger_count(dev, fingers); |
| 476 | |
| 477 | input_report_key(dev, BTN_LEFT, f->left); |
| 478 | input_report_key(dev, BTN_RIGHT, f->right); |
| 479 | input_report_key(dev, BTN_MIDDLE, f->middle); |
| 480 | |
| 481 | input_report_abs(dev, ABS_PRESSURE, f->pressure); |
| 482 | |
| 483 | input_sync(dev); |
| 484 | } |
| 485 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 486 | static void alps_process_trackstick_packet_v3(struct psmouse *psmouse) |
| 487 | { |
| 488 | struct alps_data *priv = psmouse->private; |
| 489 | unsigned char *packet = psmouse->packet; |
| 490 | struct input_dev *dev = priv->dev2; |
| 491 | int x, y, z, left, right, middle; |
| 492 | |
Pali Rohár | 34412ba | 2015-01-09 12:48:58 -0800 | [diff] [blame] | 493 | /* It should be a DualPoint when received trackstick packet */ |
| 494 | if (!(priv->flags & ALPS_DUALPOINT)) { |
| 495 | psmouse_warn(psmouse, |
| 496 | "Rejected trackstick packet from non DualPoint device"); |
| 497 | return; |
| 498 | } |
| 499 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 500 | /* Sanity check packet */ |
| 501 | if (!(packet[0] & 0x40)) { |
| 502 | psmouse_dbg(psmouse, "Bad trackstick packet, discarding\n"); |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * There's a special packet that seems to indicate the end |
| 508 | * of a stream of trackstick data. Filter these out. |
| 509 | */ |
| 510 | if (packet[1] == 0x7f && packet[2] == 0x7f && packet[4] == 0x7f) |
| 511 | return; |
| 512 | |
| 513 | x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f)); |
| 514 | y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f)); |
| 515 | z = (packet[4] & 0x7c) >> 2; |
| 516 | |
| 517 | /* |
| 518 | * The x and y values tend to be quite large, and when used |
| 519 | * alone the trackstick is difficult to use. Scale them down |
| 520 | * to compensate. |
| 521 | */ |
| 522 | x /= 8; |
| 523 | y /= 8; |
| 524 | |
| 525 | input_report_rel(dev, REL_X, x); |
| 526 | input_report_rel(dev, REL_Y, -y); |
| 527 | |
| 528 | /* |
| 529 | * Most ALPS models report the trackstick buttons in the touchpad |
| 530 | * packets, but a few report them here. No reliable way has been |
| 531 | * found to differentiate between the models upfront, so we enable |
| 532 | * the quirk in response to seeing a button press in the trackstick |
| 533 | * packet. |
| 534 | */ |
| 535 | left = packet[3] & 0x01; |
| 536 | right = packet[3] & 0x02; |
| 537 | middle = packet[3] & 0x04; |
| 538 | |
| 539 | if (!(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) && |
| 540 | (left || right || middle)) |
| 541 | priv->quirks |= ALPS_QUIRK_TRACKSTICK_BUTTONS; |
| 542 | |
| 543 | if (priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS) { |
| 544 | input_report_key(dev, BTN_LEFT, left); |
| 545 | input_report_key(dev, BTN_RIGHT, right); |
| 546 | input_report_key(dev, BTN_MIDDLE, middle); |
| 547 | } |
| 548 | |
| 549 | input_sync(dev); |
| 550 | return; |
| 551 | } |
| 552 | |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 553 | static void alps_decode_buttons_v3(struct alps_fields *f, unsigned char *p) |
| 554 | { |
| 555 | f->left = !!(p[3] & 0x01); |
| 556 | f->right = !!(p[3] & 0x02); |
| 557 | f->middle = !!(p[3] & 0x04); |
| 558 | |
| 559 | f->ts_left = !!(p[3] & 0x10); |
| 560 | f->ts_right = !!(p[3] & 0x20); |
| 561 | f->ts_middle = !!(p[3] & 0x40); |
| 562 | } |
| 563 | |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 564 | static int alps_decode_pinnacle(struct alps_fields *f, unsigned char *p, |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 565 | struct psmouse *psmouse) |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 566 | { |
| 567 | f->first_mp = !!(p[4] & 0x40); |
| 568 | f->is_mp = !!(p[0] & 0x40); |
| 569 | |
| 570 | f->fingers = (p[5] & 0x3) + 1; |
| 571 | f->x_map = ((p[4] & 0x7e) << 8) | |
| 572 | ((p[1] & 0x7f) << 2) | |
| 573 | ((p[0] & 0x30) >> 4); |
| 574 | f->y_map = ((p[3] & 0x70) << 4) | |
| 575 | ((p[2] & 0x7f) << 1) | |
| 576 | (p[4] & 0x01); |
| 577 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 578 | f->st.x = ((p[1] & 0x7f) << 4) | ((p[4] & 0x30) >> 2) | |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 579 | ((p[0] & 0x30) >> 4); |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 580 | f->st.y = ((p[2] & 0x7f) << 4) | (p[4] & 0x0f); |
| 581 | f->pressure = p[5] & 0x7f; |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 582 | |
| 583 | alps_decode_buttons_v3(f, p); |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 584 | |
| 585 | return 0; |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 588 | static int alps_decode_rushmore(struct alps_fields *f, unsigned char *p, |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 589 | struct psmouse *psmouse) |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 590 | { |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 591 | alps_decode_pinnacle(f, p, psmouse); |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 592 | |
Yunkang Tang | f105e34 | 2014-07-25 22:29:24 -0700 | [diff] [blame] | 593 | /* Rushmore's packet decode has a bit difference with Pinnacle's */ |
| 594 | f->is_mp = !!(p[5] & 0x40); |
| 595 | f->fingers = max((p[5] & 0x3), ((p[5] >> 2) & 0x3)) + 1; |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 596 | f->x_map |= (p[5] & 0x10) << 11; |
| 597 | f->y_map |= (p[5] & 0x20) << 6; |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 598 | |
| 599 | return 0; |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 600 | } |
| 601 | |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 602 | static int alps_decode_dolphin(struct alps_fields *f, unsigned char *p, |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 603 | struct psmouse *psmouse) |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 604 | { |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 605 | u64 palm_data = 0; |
| 606 | struct alps_data *priv = psmouse->private; |
| 607 | |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 608 | f->first_mp = !!(p[0] & 0x02); |
| 609 | f->is_mp = !!(p[0] & 0x20); |
| 610 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 611 | if (!f->is_mp) { |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 612 | f->st.x = ((p[1] & 0x7f) | ((p[4] & 0x0f) << 7)); |
| 613 | f->st.y = ((p[2] & 0x7f) | ((p[4] & 0xf0) << 3)); |
| 614 | f->pressure = (p[0] & 4) ? 0 : p[5] & 0x7f; |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 615 | alps_decode_buttons_v3(f, p); |
| 616 | } else { |
| 617 | f->fingers = ((p[0] & 0x6) >> 1 | |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 618 | (p[0] & 0x10) >> 2); |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 619 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 620 | palm_data = (p[1] & 0x7f) | |
| 621 | ((p[2] & 0x7f) << 7) | |
| 622 | ((p[4] & 0x7f) << 14) | |
| 623 | ((p[5] & 0x7f) << 21) | |
| 624 | ((p[3] & 0x07) << 28) | |
| 625 | (((u64)p[3] & 0x70) << 27) | |
| 626 | (((u64)p[0] & 0x01) << 34); |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 627 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 628 | /* Y-profile is stored in P(0) to p(n-1), n = y_bits; */ |
| 629 | f->y_map = palm_data & (BIT(priv->y_bits) - 1); |
| 630 | |
| 631 | /* X-profile is stored in p(n) to p(n+m-1), m = x_bits; */ |
| 632 | f->x_map = (palm_data >> priv->y_bits) & |
| 633 | (BIT(priv->x_bits) - 1); |
| 634 | } |
Hans de Goede | 38c11eaa | 2014-07-25 22:48:44 -0700 | [diff] [blame] | 635 | |
| 636 | return 0; |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 637 | } |
| 638 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 639 | static void alps_process_touchpad_packet_v3_v5(struct psmouse *psmouse) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 640 | { |
| 641 | struct alps_data *priv = psmouse->private; |
| 642 | unsigned char *packet = psmouse->packet; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 643 | struct input_dev *dev2 = priv->dev2; |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 644 | struct alps_fields *f = &priv->f; |
| 645 | int fingers = 0; |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 646 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 647 | memset(f, 0, sizeof(*f)); |
| 648 | |
| 649 | priv->decode_fields(f, packet, psmouse); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 650 | |
| 651 | /* |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 652 | * There's no single feature of touchpad position and bitmap packets |
| 653 | * that can be used to distinguish between them. We rely on the fact |
| 654 | * that a bitmap packet should always follow a position packet with |
| 655 | * bit 6 of packet[4] set. |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 656 | */ |
| 657 | if (priv->multi_packet) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 658 | /* |
| 659 | * Sometimes a position packet will indicate a multi-packet |
| 660 | * sequence, but then what follows is another position |
| 661 | * packet. Check for this, and when it happens process the |
| 662 | * position packet as usual. |
| 663 | */ |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 664 | if (f->is_mp) { |
| 665 | fingers = f->fingers; |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 666 | if (priv->proto_version == ALPS_PROTO_V3 || |
| 667 | priv->proto_version == ALPS_PROTO_V3_RUSHMORE) { |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 668 | if (alps_process_bitmap(priv, f) == 0) |
Hans de Goede | 20bea68 | 2014-07-25 22:33:33 -0700 | [diff] [blame] | 669 | fingers = 0; /* Use st data */ |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 670 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 671 | /* Now process position packet */ |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 672 | priv->decode_fields(f, priv->multi_data, |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 673 | psmouse); |
| 674 | } else { |
| 675 | /* |
| 676 | * Because Dolphin uses position packet's |
| 677 | * coordinate data as Pt1 and uses it to |
| 678 | * calculate Pt2, so we need to do position |
| 679 | * packet decode first. |
| 680 | */ |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 681 | priv->decode_fields(f, priv->multi_data, |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 682 | psmouse); |
| 683 | |
| 684 | /* |
| 685 | * Since Dolphin's finger number is reliable, |
| 686 | * there is no need to compare with bmap_fn. |
| 687 | */ |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 688 | alps_process_bitmap_dolphin(priv, f); |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 689 | } |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 690 | } else { |
| 691 | priv->multi_packet = 0; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 695 | /* |
| 696 | * Bit 6 of byte 0 is not usually set in position packets. The only |
| 697 | * times it seems to be set is in situations where the data is |
| 698 | * suspect anyway, e.g. a palm resting flat on the touchpad. Given |
| 699 | * this combined with the fact that this bit is useful for filtering |
| 700 | * out misidentified bitmap packets, we reject anything with this |
| 701 | * bit set. |
| 702 | */ |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 703 | if (f->is_mp) |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 704 | return; |
| 705 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 706 | if (!priv->multi_packet && f->first_mp) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 707 | priv->multi_packet = 1; |
Seth Forshee | 01ce661 | 2011-11-07 19:54:13 -0800 | [diff] [blame] | 708 | memcpy(priv->multi_data, packet, sizeof(priv->multi_data)); |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | priv->multi_packet = 0; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 713 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 714 | /* |
| 715 | * Sometimes the hardware sends a single packet with z = 0 |
| 716 | * in the middle of a stream. Real releases generate packets |
| 717 | * with x, y, and z all zero, so these seem to be flukes. |
| 718 | * Ignore them. |
| 719 | */ |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 720 | if (f->st.x && f->st.y && !f->pressure) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 721 | return; |
| 722 | |
Hans de Goede | 68c2187 | 2014-07-25 22:47:25 -0700 | [diff] [blame] | 723 | alps_report_semi_mt_data(psmouse, fingers); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 724 | |
Pali Rohár | 34412ba | 2015-01-09 12:48:58 -0800 | [diff] [blame] | 725 | if ((priv->flags & ALPS_DUALPOINT) && |
| 726 | !(priv->quirks & ALPS_QUIRK_TRACKSTICK_BUTTONS)) { |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 727 | input_report_key(dev2, BTN_LEFT, f->ts_left); |
| 728 | input_report_key(dev2, BTN_RIGHT, f->ts_right); |
| 729 | input_report_key(dev2, BTN_MIDDLE, f->ts_middle); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 730 | input_sync(dev2); |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | static void alps_process_packet_v3(struct psmouse *psmouse) |
| 735 | { |
| 736 | unsigned char *packet = psmouse->packet; |
| 737 | |
| 738 | /* |
| 739 | * v3 protocol packets come in three types, two representing |
| 740 | * touchpad data and one representing trackstick data. |
| 741 | * Trackstick packets seem to be distinguished by always |
| 742 | * having 0x3f in the last byte. This value has never been |
| 743 | * observed in the last byte of either of the other types |
| 744 | * of packets. |
| 745 | */ |
| 746 | if (packet[5] == 0x3f) { |
| 747 | alps_process_trackstick_packet_v3(psmouse); |
| 748 | return; |
| 749 | } |
| 750 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 751 | alps_process_touchpad_packet_v3_v5(psmouse); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 754 | static void alps_process_packet_v6(struct psmouse *psmouse) |
| 755 | { |
| 756 | struct alps_data *priv = psmouse->private; |
| 757 | unsigned char *packet = psmouse->packet; |
| 758 | struct input_dev *dev = psmouse->dev; |
| 759 | struct input_dev *dev2 = priv->dev2; |
| 760 | int x, y, z, left, right, middle; |
| 761 | |
| 762 | /* |
| 763 | * We can use Byte5 to distinguish if the packet is from Touchpad |
| 764 | * or Trackpoint. |
| 765 | * Touchpad: 0 - 0x7E |
| 766 | * Trackpoint: 0x7F |
| 767 | */ |
| 768 | if (packet[5] == 0x7F) { |
| 769 | /* It should be a DualPoint when received Trackpoint packet */ |
Pali Rohár | 34412ba | 2015-01-09 12:48:58 -0800 | [diff] [blame] | 770 | if (!(priv->flags & ALPS_DUALPOINT)) { |
| 771 | psmouse_warn(psmouse, |
| 772 | "Rejected trackstick packet from non DualPoint device"); |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 773 | return; |
Pali Rohár | 34412ba | 2015-01-09 12:48:58 -0800 | [diff] [blame] | 774 | } |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 775 | |
| 776 | /* Trackpoint packet */ |
| 777 | x = packet[1] | ((packet[3] & 0x20) << 2); |
| 778 | y = packet[2] | ((packet[3] & 0x40) << 1); |
| 779 | z = packet[4]; |
| 780 | left = packet[3] & 0x01; |
| 781 | right = packet[3] & 0x02; |
| 782 | middle = packet[3] & 0x04; |
| 783 | |
| 784 | /* To prevent the cursor jump when finger lifted */ |
| 785 | if (x == 0x7F && y == 0x7F && z == 0x7F) |
| 786 | x = y = z = 0; |
| 787 | |
| 788 | /* Divide 4 since trackpoint's speed is too fast */ |
| 789 | input_report_rel(dev2, REL_X, (char)x / 4); |
| 790 | input_report_rel(dev2, REL_Y, -((char)y / 4)); |
| 791 | |
| 792 | input_report_key(dev2, BTN_LEFT, left); |
| 793 | input_report_key(dev2, BTN_RIGHT, right); |
| 794 | input_report_key(dev2, BTN_MIDDLE, middle); |
| 795 | |
| 796 | input_sync(dev2); |
| 797 | return; |
| 798 | } |
| 799 | |
| 800 | /* Touchpad packet */ |
| 801 | x = packet[1] | ((packet[3] & 0x78) << 4); |
| 802 | y = packet[2] | ((packet[4] & 0x78) << 4); |
| 803 | z = packet[5]; |
| 804 | left = packet[3] & 0x01; |
| 805 | right = packet[3] & 0x02; |
| 806 | |
| 807 | if (z > 30) |
| 808 | input_report_key(dev, BTN_TOUCH, 1); |
| 809 | if (z < 25) |
| 810 | input_report_key(dev, BTN_TOUCH, 0); |
| 811 | |
| 812 | if (z > 0) { |
| 813 | input_report_abs(dev, ABS_X, x); |
| 814 | input_report_abs(dev, ABS_Y, y); |
| 815 | } |
| 816 | |
| 817 | input_report_abs(dev, ABS_PRESSURE, z); |
| 818 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 819 | |
| 820 | /* v6 touchpad does not have middle button */ |
| 821 | input_report_key(dev, BTN_LEFT, left); |
| 822 | input_report_key(dev, BTN_RIGHT, right); |
| 823 | |
| 824 | input_sync(dev); |
| 825 | } |
| 826 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 827 | static void alps_process_packet_v4(struct psmouse *psmouse) |
| 828 | { |
George Pantalos | 3b7e09f | 2012-05-10 22:31:59 -0700 | [diff] [blame] | 829 | struct alps_data *priv = psmouse->private; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 830 | unsigned char *packet = psmouse->packet; |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 831 | struct alps_fields *f = &priv->f; |
Hans de Goede | 68c2187 | 2014-07-25 22:47:25 -0700 | [diff] [blame] | 832 | int offset; |
George Pantalos | 3b7e09f | 2012-05-10 22:31:59 -0700 | [diff] [blame] | 833 | |
| 834 | /* |
| 835 | * v4 has a 6-byte encoding for bitmap data, but this data is |
| 836 | * broken up between 3 normal packets. Use priv->multi_packet to |
| 837 | * track our position in the bitmap packet. |
| 838 | */ |
| 839 | if (packet[6] & 0x40) { |
| 840 | /* sync, reset position */ |
| 841 | priv->multi_packet = 0; |
| 842 | } |
| 843 | |
| 844 | if (WARN_ON_ONCE(priv->multi_packet > 2)) |
| 845 | return; |
| 846 | |
| 847 | offset = 2 * priv->multi_packet; |
| 848 | priv->multi_data[offset] = packet[6]; |
| 849 | priv->multi_data[offset + 1] = packet[7]; |
| 850 | |
| 851 | if (++priv->multi_packet > 2) { |
| 852 | priv->multi_packet = 0; |
| 853 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 854 | f->x_map = ((priv->multi_data[2] & 0x1f) << 10) | |
George Pantalos | 3b7e09f | 2012-05-10 22:31:59 -0700 | [diff] [blame] | 855 | ((priv->multi_data[3] & 0x60) << 3) | |
| 856 | ((priv->multi_data[0] & 0x3f) << 2) | |
| 857 | ((priv->multi_data[1] & 0x60) >> 5); |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 858 | f->y_map = ((priv->multi_data[5] & 0x01) << 10) | |
George Pantalos | 3b7e09f | 2012-05-10 22:31:59 -0700 | [diff] [blame] | 859 | ((priv->multi_data[3] & 0x1f) << 5) | |
| 860 | (priv->multi_data[1] & 0x1f); |
| 861 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 862 | f->fingers = alps_process_bitmap(priv, f); |
George Pantalos | 3b7e09f | 2012-05-10 22:31:59 -0700 | [diff] [blame] | 863 | } |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 864 | |
Andreas Bosch | b0cfb79 | 2014-10-15 10:44:50 -0700 | [diff] [blame] | 865 | f->left = !!(packet[4] & 0x01); |
| 866 | f->right = !!(packet[4] & 0x02); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 867 | |
Hans de Goede | 02d0425 | 2014-07-25 22:43:35 -0700 | [diff] [blame] | 868 | f->st.x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) | |
| 869 | ((packet[0] & 0x30) >> 4); |
| 870 | f->st.y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f); |
| 871 | f->pressure = packet[5] & 0x7f; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 872 | |
Hans de Goede | 68c2187 | 2014-07-25 22:47:25 -0700 | [diff] [blame] | 873 | alps_report_semi_mt_data(psmouse, f->fingers); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 876 | static bool alps_is_valid_package_v7(struct psmouse *psmouse) |
| 877 | { |
| 878 | switch (psmouse->pktcnt) { |
| 879 | case 3: |
| 880 | return (psmouse->packet[2] & 0x40) == 0x40; |
| 881 | case 4: |
| 882 | return (psmouse->packet[3] & 0x48) == 0x48; |
| 883 | case 6: |
| 884 | return (psmouse->packet[5] & 0x40) == 0x00; |
| 885 | } |
| 886 | return true; |
| 887 | } |
| 888 | |
| 889 | static unsigned char alps_get_packet_id_v7(char *byte) |
| 890 | { |
| 891 | unsigned char packet_id; |
| 892 | |
| 893 | if (byte[4] & 0x40) |
| 894 | packet_id = V7_PACKET_ID_TWO; |
| 895 | else if (byte[4] & 0x01) |
| 896 | packet_id = V7_PACKET_ID_MULTI; |
| 897 | else if ((byte[0] & 0x10) && !(byte[4] & 0x43)) |
| 898 | packet_id = V7_PACKET_ID_NEW; |
| 899 | else if (byte[1] == 0x00 && byte[4] == 0x00) |
| 900 | packet_id = V7_PACKET_ID_IDLE; |
| 901 | else |
| 902 | packet_id = V7_PACKET_ID_UNKNOWN; |
| 903 | |
| 904 | return packet_id; |
| 905 | } |
| 906 | |
| 907 | static void alps_get_finger_coordinate_v7(struct input_mt_pos *mt, |
| 908 | unsigned char *pkt, |
| 909 | unsigned char pkt_id) |
| 910 | { |
Hans de Goede | 27a560b | 2014-12-18 09:54:50 -0800 | [diff] [blame] | 911 | /* |
| 912 | * packet-fmt b7 b6 b5 b4 b3 b2 b1 b0 |
| 913 | * Byte0 TWO & MULTI L 1 R M 1 Y0-2 Y0-1 Y0-0 |
| 914 | * Byte0 NEW L 1 X1-5 1 1 Y0-2 Y0-1 Y0-0 |
| 915 | * Byte1 Y0-10 Y0-9 Y0-8 Y0-7 Y0-6 Y0-5 Y0-4 Y0-3 |
| 916 | * Byte2 X0-11 1 X0-10 X0-9 X0-8 X0-7 X0-6 X0-5 |
| 917 | * Byte3 X1-11 1 X0-4 X0-3 1 X0-2 X0-1 X0-0 |
| 918 | * Byte4 TWO X1-10 TWO X1-9 X1-8 X1-7 X1-6 X1-5 X1-4 |
| 919 | * Byte4 MULTI X1-10 TWO X1-9 X1-8 X1-7 X1-6 Y1-5 1 |
| 920 | * Byte4 NEW X1-10 TWO X1-9 X1-8 X1-7 X1-6 0 0 |
| 921 | * Byte5 TWO & NEW Y1-10 0 Y1-9 Y1-8 Y1-7 Y1-6 Y1-5 Y1-4 |
| 922 | * Byte5 MULTI Y1-10 0 Y1-9 Y1-8 Y1-7 Y1-6 F-1 F-0 |
| 923 | * L: Left button |
| 924 | * R / M: Non-clickpads: Right / Middle button |
| 925 | * Clickpads: When > 2 fingers are down, and some fingers |
| 926 | * are in the button area, then the 2 coordinates reported |
| 927 | * are for fingers outside the button area and these report |
| 928 | * extra fingers being present in the right / left button |
| 929 | * area. Note these fingers are not added to the F field! |
| 930 | * so if a TWO packet is received and R = 1 then there are |
| 931 | * 3 fingers down, etc. |
| 932 | * TWO: 1: Two touches present, byte 0/4/5 are in TWO fmt |
| 933 | * 0: If byte 4 bit 0 is 1, then byte 0/4/5 are in MULTI fmt |
| 934 | * otherwise byte 0 bit 4 must be set and byte 0/4/5 are |
| 935 | * in NEW fmt |
| 936 | * F: Number of fingers - 3, 0 means 3 fingers, 1 means 4 ... |
| 937 | */ |
| 938 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 939 | mt[0].x = ((pkt[2] & 0x80) << 4); |
| 940 | mt[0].x |= ((pkt[2] & 0x3F) << 5); |
| 941 | mt[0].x |= ((pkt[3] & 0x30) >> 1); |
| 942 | mt[0].x |= (pkt[3] & 0x07); |
| 943 | mt[0].y = (pkt[1] << 3) | (pkt[0] & 0x07); |
| 944 | |
| 945 | mt[1].x = ((pkt[3] & 0x80) << 4); |
| 946 | mt[1].x |= ((pkt[4] & 0x80) << 3); |
| 947 | mt[1].x |= ((pkt[4] & 0x3F) << 4); |
| 948 | mt[1].y = ((pkt[5] & 0x80) << 3); |
| 949 | mt[1].y |= ((pkt[5] & 0x3F) << 4); |
| 950 | |
| 951 | switch (pkt_id) { |
| 952 | case V7_PACKET_ID_TWO: |
| 953 | mt[1].x &= ~0x000F; |
| 954 | mt[1].y |= 0x000F; |
| 955 | break; |
| 956 | |
| 957 | case V7_PACKET_ID_MULTI: |
| 958 | mt[1].x &= ~0x003F; |
| 959 | mt[1].y &= ~0x0020; |
| 960 | mt[1].y |= ((pkt[4] & 0x02) << 4); |
| 961 | mt[1].y |= 0x001F; |
| 962 | break; |
| 963 | |
| 964 | case V7_PACKET_ID_NEW: |
| 965 | mt[1].x &= ~0x003F; |
| 966 | mt[1].x |= (pkt[0] & 0x20); |
| 967 | mt[1].y |= 0x000F; |
| 968 | break; |
| 969 | } |
| 970 | |
| 971 | mt[0].y = 0x7FF - mt[0].y; |
| 972 | mt[1].y = 0x7FF - mt[1].y; |
| 973 | } |
| 974 | |
| 975 | static int alps_get_mt_count(struct input_mt_pos *mt) |
| 976 | { |
Hans de Goede | 7091c44 | 2014-12-18 09:53:34 -0800 | [diff] [blame] | 977 | int i, fingers = 0; |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 978 | |
Hans de Goede | 7091c44 | 2014-12-18 09:53:34 -0800 | [diff] [blame] | 979 | for (i = 0; i < MAX_TOUCHES; i++) { |
| 980 | if (mt[i].x != 0 || mt[i].y != 0) |
| 981 | fingers++; |
| 982 | } |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 983 | |
Hans de Goede | 7091c44 | 2014-12-18 09:53:34 -0800 | [diff] [blame] | 984 | return fingers; |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static int alps_decode_packet_v7(struct alps_fields *f, |
| 988 | unsigned char *p, |
| 989 | struct psmouse *psmouse) |
| 990 | { |
Hans de Goede | d27eb79 | 2014-12-18 09:55:14 -0800 | [diff] [blame] | 991 | struct alps_data *priv = psmouse->private; |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 992 | unsigned char pkt_id; |
| 993 | |
| 994 | pkt_id = alps_get_packet_id_v7(p); |
| 995 | if (pkt_id == V7_PACKET_ID_IDLE) |
| 996 | return 0; |
| 997 | if (pkt_id == V7_PACKET_ID_UNKNOWN) |
| 998 | return -1; |
Hans de Goede | 8b23811 | 2014-12-18 09:52:59 -0800 | [diff] [blame] | 999 | /* |
| 1000 | * NEW packets are send to indicate a discontinuity in the finger |
| 1001 | * coordinate reporting. Specifically a finger may have moved from |
| 1002 | * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for |
| 1003 | * us. |
| 1004 | * |
| 1005 | * NEW packets have 3 problems: |
| 1006 | * 1) They do not contain middle / right button info (on non clickpads) |
| 1007 | * this can be worked around by preserving the old button state |
| 1008 | * 2) They do not contain an accurate fingercount, and they are |
| 1009 | * typically send when the number of fingers changes. We cannot use |
| 1010 | * the old finger count as that may mismatch with the amount of |
| 1011 | * touch coordinates we've available in the NEW packet |
| 1012 | * 3) Their x data for the second touch is inaccurate leading to |
| 1013 | * a possible jump of the x coordinate by 16 units when the first |
| 1014 | * non NEW packet comes in |
| 1015 | * Since problems 2 & 3 cannot be worked around, just ignore them. |
| 1016 | */ |
| 1017 | if (pkt_id == V7_PACKET_ID_NEW) |
| 1018 | return 1; |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1019 | |
| 1020 | alps_get_finger_coordinate_v7(f->mt, p, pkt_id); |
| 1021 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1022 | if (pkt_id == V7_PACKET_ID_TWO) |
| 1023 | f->fingers = alps_get_mt_count(f->mt); |
Hans de Goede | 8b23811 | 2014-12-18 09:52:59 -0800 | [diff] [blame] | 1024 | else /* pkt_id == V7_PACKET_ID_MULTI */ |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1025 | f->fingers = 3 + (p[5] & 0x03); |
| 1026 | |
Hans de Goede | d27eb79 | 2014-12-18 09:55:14 -0800 | [diff] [blame] | 1027 | f->left = (p[0] & 0x80) >> 7; |
| 1028 | if (priv->flags & ALPS_BUTTONPAD) { |
| 1029 | if (p[0] & 0x20) |
| 1030 | f->fingers++; |
| 1031 | if (p[0] & 0x10) |
| 1032 | f->fingers++; |
| 1033 | } else { |
| 1034 | f->right = (p[0] & 0x20) >> 5; |
| 1035 | f->middle = (p[0] & 0x10) >> 4; |
| 1036 | } |
| 1037 | |
Hans de Goede | 7091c44 | 2014-12-18 09:53:34 -0800 | [diff] [blame] | 1038 | /* Sometimes a single touch is reported in mt[1] rather then mt[0] */ |
| 1039 | if (f->fingers == 1 && f->mt[0].x == 0 && f->mt[0].y == 0) { |
| 1040 | f->mt[0].x = f->mt[1].x; |
| 1041 | f->mt[0].y = f->mt[1].y; |
| 1042 | f->mt[1].x = 0; |
| 1043 | f->mt[1].y = 0; |
| 1044 | } |
| 1045 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1046 | return 0; |
| 1047 | } |
| 1048 | |
| 1049 | static void alps_process_trackstick_packet_v7(struct psmouse *psmouse) |
| 1050 | { |
| 1051 | struct alps_data *priv = psmouse->private; |
| 1052 | unsigned char *packet = psmouse->packet; |
| 1053 | struct input_dev *dev2 = priv->dev2; |
| 1054 | int x, y, z, left, right, middle; |
| 1055 | |
Pali Rohár | 34412ba | 2015-01-09 12:48:58 -0800 | [diff] [blame] | 1056 | /* It should be a DualPoint when received trackstick packet */ |
| 1057 | if (!(priv->flags & ALPS_DUALPOINT)) { |
| 1058 | psmouse_warn(psmouse, |
| 1059 | "Rejected trackstick packet from non DualPoint device"); |
| 1060 | return; |
| 1061 | } |
| 1062 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1063 | /* |
| 1064 | * b7 b6 b5 b4 b3 b2 b1 b0 |
| 1065 | * Byte0 0 1 0 0 1 0 0 0 |
| 1066 | * Byte1 1 1 * * 1 M R L |
| 1067 | * Byte2 X7 1 X5 X4 X3 X2 X1 X0 |
| 1068 | * Byte3 Z6 1 Y6 X6 1 Y2 Y1 Y0 |
| 1069 | * Byte4 Y7 0 Y5 Y4 Y3 1 1 0 |
| 1070 | * Byte5 T&P 0 Z5 Z4 Z3 Z2 Z1 Z0 |
| 1071 | * M / R / L: Middle / Right / Left button |
| 1072 | */ |
| 1073 | |
| 1074 | x = ((packet[2] & 0xbf)) | ((packet[3] & 0x10) << 2); |
| 1075 | y = (packet[3] & 0x07) | (packet[4] & 0xb8) | |
| 1076 | ((packet[3] & 0x20) << 1); |
| 1077 | z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1); |
| 1078 | |
| 1079 | left = (packet[1] & 0x01); |
| 1080 | right = (packet[1] & 0x02) >> 1; |
| 1081 | middle = (packet[1] & 0x04) >> 2; |
| 1082 | |
| 1083 | /* Divide 2 since trackpoint's speed is too fast */ |
| 1084 | input_report_rel(dev2, REL_X, (char)x / 2); |
| 1085 | input_report_rel(dev2, REL_Y, -((char)y / 2)); |
| 1086 | |
| 1087 | input_report_key(dev2, BTN_LEFT, left); |
| 1088 | input_report_key(dev2, BTN_RIGHT, right); |
| 1089 | input_report_key(dev2, BTN_MIDDLE, middle); |
| 1090 | |
| 1091 | input_sync(dev2); |
| 1092 | } |
| 1093 | |
| 1094 | static void alps_process_touchpad_packet_v7(struct psmouse *psmouse) |
| 1095 | { |
| 1096 | struct alps_data *priv = psmouse->private; |
| 1097 | struct input_dev *dev = psmouse->dev; |
| 1098 | struct alps_fields *f = &priv->f; |
| 1099 | |
| 1100 | memset(f, 0, sizeof(*f)); |
| 1101 | |
| 1102 | if (priv->decode_fields(f, psmouse->packet, psmouse)) |
| 1103 | return; |
| 1104 | |
| 1105 | alps_report_mt_data(psmouse, alps_get_mt_count(f->mt)); |
| 1106 | |
| 1107 | input_mt_report_finger_count(dev, f->fingers); |
| 1108 | |
| 1109 | input_report_key(dev, BTN_LEFT, f->left); |
| 1110 | input_report_key(dev, BTN_RIGHT, f->right); |
| 1111 | input_report_key(dev, BTN_MIDDLE, f->middle); |
| 1112 | |
| 1113 | input_sync(dev); |
| 1114 | } |
| 1115 | |
| 1116 | static void alps_process_packet_v7(struct psmouse *psmouse) |
| 1117 | { |
| 1118 | unsigned char *packet = psmouse->packet; |
| 1119 | |
| 1120 | if (packet[0] == 0x48 && (packet[4] & 0x47) == 0x06) |
| 1121 | alps_process_trackstick_packet_v7(psmouse); |
| 1122 | else |
| 1123 | alps_process_touchpad_packet_v7(psmouse); |
| 1124 | } |
| 1125 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1126 | static void alps_report_bare_ps2_packet(struct psmouse *psmouse, |
| 1127 | unsigned char packet[], |
| 1128 | bool report_buttons) |
| 1129 | { |
| 1130 | struct alps_data *priv = psmouse->private; |
| 1131 | struct input_dev *dev2 = priv->dev2; |
| 1132 | |
| 1133 | if (report_buttons) |
| 1134 | alps_report_buttons(psmouse, dev2, psmouse->dev, |
| 1135 | packet[0] & 1, packet[0] & 2, packet[0] & 4); |
| 1136 | |
| 1137 | input_report_rel(dev2, REL_X, |
| 1138 | packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); |
| 1139 | input_report_rel(dev2, REL_Y, |
| 1140 | packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); |
| 1141 | |
| 1142 | input_sync(dev2); |
| 1143 | } |
| 1144 | |
| 1145 | static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | { |
| 1147 | struct alps_data *priv = psmouse->private; |
| 1148 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1149 | if (psmouse->pktcnt < 6) |
| 1150 | return PSMOUSE_GOOD_DATA; |
| 1151 | |
| 1152 | if (psmouse->pktcnt == 6) { |
| 1153 | /* |
| 1154 | * Start a timer to flush the packet if it ends up last |
| 1155 | * 6-byte packet in the stream. Timer needs to fire |
| 1156 | * psmouse core times out itself. 20 ms should be enough |
| 1157 | * to decide if we are getting more data or not. |
| 1158 | */ |
| 1159 | mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20)); |
| 1160 | return PSMOUSE_GOOD_DATA; |
| 1161 | } |
| 1162 | |
| 1163 | del_timer(&priv->timer); |
| 1164 | |
| 1165 | if (psmouse->packet[6] & 0x80) { |
| 1166 | |
| 1167 | /* |
| 1168 | * Highest bit is set - that means we either had |
| 1169 | * complete ALPS packet and this is start of the |
| 1170 | * next packet or we got garbage. |
| 1171 | */ |
| 1172 | |
| 1173 | if (((psmouse->packet[3] | |
| 1174 | psmouse->packet[4] | |
| 1175 | psmouse->packet[5]) & 0x80) || |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1176 | (!alps_is_valid_first_byte(priv, psmouse->packet[6]))) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1177 | psmouse_dbg(psmouse, |
Andy Shevchenko | 3b11292 | 2012-10-30 00:24:41 -0700 | [diff] [blame] | 1178 | "refusing packet %4ph (suspected interleaved ps/2)\n", |
| 1179 | psmouse->packet + 3); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1180 | return PSMOUSE_BAD_DATA; |
| 1181 | } |
| 1182 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 1183 | priv->process_packet(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1184 | |
| 1185 | /* Continue with the next packet */ |
| 1186 | psmouse->packet[0] = psmouse->packet[6]; |
| 1187 | psmouse->pktcnt = 1; |
| 1188 | |
| 1189 | } else { |
| 1190 | |
| 1191 | /* |
| 1192 | * High bit is 0 - that means that we indeed got a PS/2 |
| 1193 | * packet in the middle of ALPS packet. |
| 1194 | * |
| 1195 | * There is also possibility that we got 6-byte ALPS |
| 1196 | * packet followed by 3-byte packet from trackpoint. We |
| 1197 | * can not distinguish between these 2 scenarios but |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1198 | * because the latter is unlikely to happen in course of |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1199 | * normal operation (user would need to press all |
| 1200 | * buttons on the pad and start moving trackpoint |
| 1201 | * without touching the pad surface) we assume former. |
| 1202 | * Even if we are wrong the wost thing that would happen |
| 1203 | * the cursor would jump but we should not get protocol |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1204 | * de-synchronization. |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1205 | */ |
| 1206 | |
| 1207 | alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3], |
| 1208 | false); |
| 1209 | |
| 1210 | /* |
| 1211 | * Continue with the standard ALPS protocol handling, |
| 1212 | * but make sure we won't process it as an interleaved |
| 1213 | * packet again, which may happen if all buttons are |
| 1214 | * pressed. To avoid this let's reset the 4th bit which |
| 1215 | * is normally 1. |
| 1216 | */ |
| 1217 | psmouse->packet[3] = psmouse->packet[6] & 0xf7; |
| 1218 | psmouse->pktcnt = 4; |
| 1219 | } |
| 1220 | |
| 1221 | return PSMOUSE_GOOD_DATA; |
| 1222 | } |
| 1223 | |
| 1224 | static void alps_flush_packet(unsigned long data) |
| 1225 | { |
| 1226 | struct psmouse *psmouse = (struct psmouse *)data; |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 1227 | struct alps_data *priv = psmouse->private; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1228 | |
| 1229 | serio_pause_rx(psmouse->ps2dev.serio); |
| 1230 | |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 1231 | if (psmouse->pktcnt == psmouse->pktsize) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1232 | |
| 1233 | /* |
| 1234 | * We did not any more data in reasonable amount of time. |
| 1235 | * Validate the last 3 bytes and process as a standard |
| 1236 | * ALPS packet. |
| 1237 | */ |
| 1238 | if ((psmouse->packet[3] | |
| 1239 | psmouse->packet[4] | |
| 1240 | psmouse->packet[5]) & 0x80) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1241 | psmouse_dbg(psmouse, |
Andy Shevchenko | 3b11292 | 2012-10-30 00:24:41 -0700 | [diff] [blame] | 1242 | "refusing packet %3ph (suspected interleaved ps/2)\n", |
| 1243 | psmouse->packet + 3); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1244 | } else { |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 1245 | priv->process_packet(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1246 | } |
| 1247 | psmouse->pktcnt = 0; |
| 1248 | } |
| 1249 | |
| 1250 | serio_continue_rx(psmouse->ps2dev.serio); |
| 1251 | } |
| 1252 | |
| 1253 | static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) |
| 1254 | { |
| 1255 | struct alps_data *priv = psmouse->private; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1256 | |
Pali Rohár | 4ab8f7f | 2014-11-08 12:45:23 -0800 | [diff] [blame] | 1257 | /* |
| 1258 | * Check if we are dealing with a bare PS/2 packet, presumably from |
| 1259 | * a device connected to the external PS/2 port. Because bare PS/2 |
| 1260 | * protocol does not have enough constant bits to self-synchronize |
| 1261 | * properly we only do this if the device is fully synchronized. |
| 1262 | */ |
| 1263 | if (!psmouse->out_of_sync_cnt && (psmouse->packet[0] & 0xc8) == 0x08) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | if (psmouse->pktcnt == 3) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1265 | alps_report_bare_ps2_packet(psmouse, psmouse->packet, |
| 1266 | true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | return PSMOUSE_FULL_PACKET; |
| 1268 | } |
| 1269 | return PSMOUSE_GOOD_DATA; |
| 1270 | } |
| 1271 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1272 | /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ |
| 1273 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1274 | if ((priv->flags & ALPS_PS2_INTERLEAVED) && |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1275 | psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { |
| 1276 | return alps_handle_interleaved_ps2(psmouse); |
| 1277 | } |
| 1278 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1279 | if (!alps_is_valid_first_byte(priv, psmouse->packet[0])) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1280 | psmouse_dbg(psmouse, |
| 1281 | "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n", |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1282 | psmouse->packet[0], priv->mask0, priv->byte0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 1286 | /* Bytes 2 - pktsize should have 0 in the highest bit */ |
Pali Rohár | a7ef82a | 2014-11-08 23:36:09 -0800 | [diff] [blame] | 1287 | if (priv->proto_version < ALPS_PROTO_V5 && |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 1288 | psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize && |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1289 | (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1290 | psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", |
| 1291 | psmouse->pktcnt - 1, |
| 1292 | psmouse->packet[psmouse->pktcnt - 1]); |
Pali Rohár | a7ef82a | 2014-11-08 23:36:09 -0800 | [diff] [blame] | 1293 | |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 1294 | if (priv->proto_version == ALPS_PROTO_V3_RUSHMORE && |
Pali Rohár | a7ef82a | 2014-11-08 23:36:09 -0800 | [diff] [blame] | 1295 | psmouse->pktcnt == psmouse->pktsize) { |
| 1296 | /* |
| 1297 | * Some Dell boxes, such as Latitude E6440 or E7440 |
| 1298 | * with closed lid, quite often smash last byte of |
| 1299 | * otherwise valid packet with 0xff. Given that the |
| 1300 | * next packet is very likely to be valid let's |
| 1301 | * report PSMOUSE_FULL_PACKET but not process data, |
| 1302 | * rather than reporting PSMOUSE_BAD_DATA and |
| 1303 | * filling the logs. |
| 1304 | */ |
| 1305 | return PSMOUSE_FULL_PACKET; |
| 1306 | } |
| 1307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 1309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1311 | if (priv->proto_version == ALPS_PROTO_V7 && |
| 1312 | !alps_is_valid_package_v7(psmouse)) { |
| 1313 | psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", |
| 1314 | psmouse->pktcnt - 1, |
| 1315 | psmouse->packet[psmouse->pktcnt - 1]); |
| 1316 | return PSMOUSE_BAD_DATA; |
| 1317 | } |
| 1318 | |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 1319 | if (psmouse->pktcnt == psmouse->pktsize) { |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 1320 | priv->process_packet(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | return PSMOUSE_FULL_PACKET; |
| 1322 | } |
| 1323 | |
| 1324 | return PSMOUSE_GOOD_DATA; |
| 1325 | } |
| 1326 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1327 | static int alps_command_mode_send_nibble(struct psmouse *psmouse, int nibble) |
| 1328 | { |
| 1329 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1330 | struct alps_data *priv = psmouse->private; |
| 1331 | int command; |
| 1332 | unsigned char *param; |
| 1333 | unsigned char dummy[4]; |
| 1334 | |
| 1335 | BUG_ON(nibble > 0xf); |
| 1336 | |
| 1337 | command = priv->nibble_commands[nibble].command; |
| 1338 | param = (command & 0x0f00) ? |
| 1339 | dummy : (unsigned char *)&priv->nibble_commands[nibble].data; |
| 1340 | |
| 1341 | if (ps2_command(ps2dev, param, command)) |
| 1342 | return -1; |
| 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | static int alps_command_mode_set_addr(struct psmouse *psmouse, int addr) |
| 1348 | { |
| 1349 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1350 | struct alps_data *priv = psmouse->private; |
| 1351 | int i, nibble; |
| 1352 | |
| 1353 | if (ps2_command(ps2dev, NULL, priv->addr_command)) |
| 1354 | return -1; |
| 1355 | |
| 1356 | for (i = 12; i >= 0; i -= 4) { |
| 1357 | nibble = (addr >> i) & 0xf; |
| 1358 | if (alps_command_mode_send_nibble(psmouse, nibble)) |
| 1359 | return -1; |
| 1360 | } |
| 1361 | |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | static int __alps_command_mode_read_reg(struct psmouse *psmouse, int addr) |
| 1366 | { |
| 1367 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1368 | unsigned char param[4]; |
| 1369 | |
| 1370 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 1371 | return -1; |
| 1372 | |
| 1373 | /* |
| 1374 | * The address being read is returned in the first two bytes |
| 1375 | * of the result. Check that this address matches the expected |
| 1376 | * address. |
| 1377 | */ |
| 1378 | if (addr != ((param[0] << 8) | param[1])) |
| 1379 | return -1; |
| 1380 | |
| 1381 | return param[2]; |
| 1382 | } |
| 1383 | |
| 1384 | static int alps_command_mode_read_reg(struct psmouse *psmouse, int addr) |
| 1385 | { |
| 1386 | if (alps_command_mode_set_addr(psmouse, addr)) |
| 1387 | return -1; |
| 1388 | return __alps_command_mode_read_reg(psmouse, addr); |
| 1389 | } |
| 1390 | |
| 1391 | static int __alps_command_mode_write_reg(struct psmouse *psmouse, u8 value) |
| 1392 | { |
| 1393 | if (alps_command_mode_send_nibble(psmouse, (value >> 4) & 0xf)) |
| 1394 | return -1; |
| 1395 | if (alps_command_mode_send_nibble(psmouse, value & 0xf)) |
| 1396 | return -1; |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
| 1400 | static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr, |
| 1401 | u8 value) |
| 1402 | { |
| 1403 | if (alps_command_mode_set_addr(psmouse, addr)) |
| 1404 | return -1; |
| 1405 | return __alps_command_mode_write_reg(psmouse, value); |
| 1406 | } |
| 1407 | |
Kevin Cernekee | 24ba970 | 2013-02-13 22:19:01 -0800 | [diff] [blame] | 1408 | static int alps_rpt_cmd(struct psmouse *psmouse, int init_command, |
| 1409 | int repeated_command, unsigned char *param) |
| 1410 | { |
| 1411 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1412 | |
| 1413 | param[0] = 0; |
| 1414 | if (init_command && ps2_command(ps2dev, param, init_command)) |
| 1415 | return -EIO; |
| 1416 | |
| 1417 | if (ps2_command(ps2dev, NULL, repeated_command) || |
| 1418 | ps2_command(ps2dev, NULL, repeated_command) || |
| 1419 | ps2_command(ps2dev, NULL, repeated_command)) |
| 1420 | return -EIO; |
| 1421 | |
| 1422 | param[0] = param[1] = param[2] = 0xff; |
| 1423 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 1424 | return -EIO; |
| 1425 | |
Dmitry Torokhov | 39fbe58 | 2013-02-14 09:04:24 -0800 | [diff] [blame] | 1426 | psmouse_dbg(psmouse, "%2.2X report: %3ph\n", |
| 1427 | repeated_command, param); |
Kevin Cernekee | 24ba970 | 2013-02-13 22:19:01 -0800 | [diff] [blame] | 1428 | return 0; |
| 1429 | } |
| 1430 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1431 | static bool alps_check_valid_firmware_id(unsigned char id[]) |
| 1432 | { |
| 1433 | if (id[0] == 0x73) |
| 1434 | return true; |
| 1435 | |
| 1436 | if (id[0] == 0x88 && |
| 1437 | (id[1] == 0x07 || |
| 1438 | id[1] == 0x08 || |
| 1439 | (id[1] & 0xf0) == 0xb0 || |
| 1440 | (id[1] & 0xf0) == 0xc0)) { |
| 1441 | return true; |
| 1442 | } |
| 1443 | |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 1447 | static int alps_enter_command_mode(struct psmouse *psmouse) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1448 | { |
| 1449 | unsigned char param[4]; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1450 | |
Kevin Cernekee | 24ba970 | 2013-02-13 22:19:01 -0800 | [diff] [blame] | 1451 | if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1452 | psmouse_err(psmouse, "failed to enter command mode\n"); |
| 1453 | return -1; |
| 1454 | } |
| 1455 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 1456 | if (!alps_check_valid_firmware_id(param)) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1457 | psmouse_dbg(psmouse, |
Kevin Cernekee | 24ba970 | 2013-02-13 22:19:01 -0800 | [diff] [blame] | 1458 | "unknown response while entering command mode\n"); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1459 | return -1; |
| 1460 | } |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | static inline int alps_exit_command_mode(struct psmouse *psmouse) |
| 1465 | { |
| 1466 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1467 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) |
| 1468 | return -1; |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | /* |
| 1473 | * For DualPoint devices select the device that should respond to |
| 1474 | * subsequent commands. It looks like glidepad is behind stickpointer, |
| 1475 | * I'd thought it would be other way around... |
| 1476 | */ |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1477 | static int alps_passthrough_mode_v2(struct psmouse *psmouse, bool enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | { |
| 1479 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; |
| 1481 | |
| 1482 | if (ps2_command(ps2dev, NULL, cmd) || |
| 1483 | ps2_command(ps2dev, NULL, cmd) || |
| 1484 | ps2_command(ps2dev, NULL, cmd) || |
| 1485 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 1486 | return -1; |
| 1487 | |
| 1488 | /* we may get 3 more bytes, just ignore them */ |
Dmitry Torokhov | c611763 | 2005-06-01 02:39:51 -0500 | [diff] [blame] | 1489 | ps2_drain(ps2dev, 3, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1494 | static int alps_absolute_mode_v1_v2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | { |
| 1496 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1497 | |
| 1498 | /* Try ALPS magic knock - 4 disable before enable */ |
| 1499 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1500 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1501 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1502 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1503 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) |
| 1504 | return -1; |
| 1505 | |
| 1506 | /* |
| 1507 | * Switch mouse to poll (remote) mode so motion data will not |
| 1508 | * get in our way |
| 1509 | */ |
| 1510 | return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); |
| 1511 | } |
| 1512 | |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 1513 | static int alps_monitor_mode_send_word(struct psmouse *psmouse, u16 word) |
| 1514 | { |
| 1515 | int i, nibble; |
| 1516 | |
| 1517 | /* |
| 1518 | * b0-b11 are valid bits, send sequence is inverse. |
| 1519 | * e.g. when word = 0x0123, nibble send sequence is 3, 2, 1 |
| 1520 | */ |
| 1521 | for (i = 0; i <= 8; i += 4) { |
| 1522 | nibble = (word >> i) & 0xf; |
| 1523 | if (alps_command_mode_send_nibble(psmouse, nibble)) |
| 1524 | return -1; |
| 1525 | } |
| 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static int alps_monitor_mode_write_reg(struct psmouse *psmouse, |
| 1531 | u16 addr, u16 value) |
| 1532 | { |
| 1533 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1534 | |
| 1535 | /* 0x0A0 is the command to write the word */ |
| 1536 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE) || |
| 1537 | alps_monitor_mode_send_word(psmouse, 0x0A0) || |
| 1538 | alps_monitor_mode_send_word(psmouse, addr) || |
| 1539 | alps_monitor_mode_send_word(psmouse, value) || |
| 1540 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 1541 | return -1; |
| 1542 | |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
| 1546 | static int alps_monitor_mode(struct psmouse *psmouse, bool enable) |
| 1547 | { |
| 1548 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1549 | |
| 1550 | if (enable) { |
| 1551 | /* EC E9 F5 F5 E7 E6 E7 E9 to enter monitor mode */ |
| 1552 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || |
| 1553 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO) || |
| 1554 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1555 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1556 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 1557 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1558 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 1559 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_GETINFO)) |
| 1560 | return -1; |
| 1561 | } else { |
| 1562 | /* EC to exit monitor mode */ |
| 1563 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP)) |
| 1564 | return -1; |
| 1565 | } |
| 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | static int alps_absolute_mode_v6(struct psmouse *psmouse) |
| 1571 | { |
| 1572 | u16 reg_val = 0x181; |
| 1573 | int ret = -1; |
| 1574 | |
| 1575 | /* enter monitor mode, to write the register */ |
| 1576 | if (alps_monitor_mode(psmouse, true)) |
| 1577 | return -1; |
| 1578 | |
| 1579 | ret = alps_monitor_mode_write_reg(psmouse, 0x000, reg_val); |
| 1580 | |
| 1581 | if (alps_monitor_mode(psmouse, false)) |
| 1582 | ret = -1; |
| 1583 | |
| 1584 | return ret; |
| 1585 | } |
| 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | static int alps_get_status(struct psmouse *psmouse, char *param) |
| 1588 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | /* Get status: 0xF5 0xF5 0xF5 0xE9 */ |
Kevin Cernekee | 24ba970 | 2013-02-13 22:19:01 -0800 | [diff] [blame] | 1590 | if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | return -1; |
| 1592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | return 0; |
| 1594 | } |
| 1595 | |
| 1596 | /* |
| 1597 | * Turn touchpad tapping on or off. The sequences are: |
| 1598 | * 0xE9 0xF5 0xF5 0xF3 0x0A to enable, |
| 1599 | * 0xE9 0xF5 0xF5 0xE8 0x00 to disable. |
| 1600 | * My guess that 0xE9 (GetInfo) is here as a sync point. |
| 1601 | * For models that also have stickpointer (DualPoints) its tapping |
| 1602 | * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but |
| 1603 | * we don't fiddle with it. |
| 1604 | */ |
| 1605 | static int alps_tap_mode(struct psmouse *psmouse, int enable) |
| 1606 | { |
| 1607 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1608 | int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES; |
| 1609 | unsigned char tap_arg = enable ? 0x0A : 0x00; |
| 1610 | unsigned char param[4]; |
| 1611 | |
| 1612 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) || |
| 1613 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1614 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 1615 | ps2_command(ps2dev, &tap_arg, cmd)) |
| 1616 | return -1; |
| 1617 | |
| 1618 | if (alps_get_status(psmouse, param)) |
| 1619 | return -1; |
| 1620 | |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1624 | /* |
| 1625 | * alps_poll() - poll the touchpad for current motion packet. |
| 1626 | * Used in resync. |
| 1627 | */ |
| 1628 | static int alps_poll(struct psmouse *psmouse) |
| 1629 | { |
| 1630 | struct alps_data *priv = psmouse->private; |
Seth Forshee | b46615f | 2011-11-07 19:53:30 -0800 | [diff] [blame] | 1631 | unsigned char buf[sizeof(psmouse->packet)]; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1632 | bool poll_failed; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1633 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1634 | if (priv->flags & ALPS_PASS) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1635 | alps_passthrough_mode_v2(psmouse, true); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1636 | |
| 1637 | poll_failed = ps2_command(&psmouse->ps2dev, buf, |
| 1638 | PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; |
| 1639 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1640 | if (priv->flags & ALPS_PASS) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1641 | alps_passthrough_mode_v2(psmouse, false); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1642 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1643 | if (poll_failed || (buf[0] & priv->mask0) != priv->byte0) |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 1644 | return -1; |
| 1645 | |
| 1646 | if ((psmouse->badbyte & 0xc8) == 0x08) { |
| 1647 | /* |
| 1648 | * Poll the track stick ... |
| 1649 | */ |
| 1650 | if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) |
| 1651 | return -1; |
| 1652 | } |
| 1653 | |
| 1654 | memcpy(psmouse->packet, buf, sizeof(buf)); |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1658 | static int alps_hw_init_v1_v2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | { |
| 1660 | struct alps_data *priv = psmouse->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1662 | if ((priv->flags & ALPS_PASS) && |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1663 | alps_passthrough_mode_v2(psmouse, true)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1667 | if (alps_tap_mode(psmouse, true)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1668 | psmouse_warn(psmouse, "Failed to enable hardware tapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | return -1; |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 1670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1672 | if (alps_absolute_mode_v1_v2(psmouse)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1673 | psmouse_err(psmouse, "Failed to enable absolute mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | return -1; |
| 1675 | } |
| 1676 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 1677 | if ((priv->flags & ALPS_PASS) && |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1678 | alps_passthrough_mode_v2(psmouse, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 1680 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1682 | /* ALPS needs stream mode, otherwise it won't report any data */ |
| 1683 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 1684 | psmouse_err(psmouse, "Failed to enable stream mode\n"); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 1685 | return -1; |
| 1686 | } |
| 1687 | |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 1691 | static int alps_hw_init_v6(struct psmouse *psmouse) |
| 1692 | { |
| 1693 | unsigned char param[2] = {0xC8, 0x14}; |
| 1694 | |
| 1695 | /* Enter passthrough mode to let trackpoint enter 6byte raw mode */ |
| 1696 | if (alps_passthrough_mode_v2(psmouse, true)) |
| 1697 | return -1; |
| 1698 | |
| 1699 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1700 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1701 | ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1702 | ps2_command(&psmouse->ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || |
| 1703 | ps2_command(&psmouse->ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE)) |
| 1704 | return -1; |
| 1705 | |
| 1706 | if (alps_passthrough_mode_v2(psmouse, false)) |
| 1707 | return -1; |
| 1708 | |
| 1709 | if (alps_absolute_mode_v6(psmouse)) { |
| 1710 | psmouse_err(psmouse, "Failed to enable absolute mode\n"); |
| 1711 | return -1; |
| 1712 | } |
| 1713 | |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1717 | /* |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1718 | * Enable or disable passthrough mode to the trackstick. |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1719 | */ |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1720 | static int alps_passthrough_mode_v3(struct psmouse *psmouse, |
| 1721 | int reg_base, bool enable) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1722 | { |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1723 | int reg_val, ret = -1; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1724 | |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 1725 | if (alps_enter_command_mode(psmouse)) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1726 | return -1; |
| 1727 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1728 | reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x0008); |
| 1729 | if (reg_val == -1) |
| 1730 | goto error; |
| 1731 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1732 | if (enable) |
| 1733 | reg_val |= 0x01; |
| 1734 | else |
| 1735 | reg_val &= ~0x01; |
| 1736 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1737 | ret = __alps_command_mode_write_reg(psmouse, reg_val); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1738 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1739 | error: |
| 1740 | if (alps_exit_command_mode(psmouse)) |
| 1741 | ret = -1; |
| 1742 | return ret; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /* Must be in command mode when calling this function */ |
| 1746 | static int alps_absolute_mode_v3(struct psmouse *psmouse) |
| 1747 | { |
| 1748 | int reg_val; |
| 1749 | |
| 1750 | reg_val = alps_command_mode_read_reg(psmouse, 0x0004); |
| 1751 | if (reg_val == -1) |
| 1752 | return -1; |
| 1753 | |
| 1754 | reg_val |= 0x06; |
| 1755 | if (__alps_command_mode_write_reg(psmouse, reg_val)) |
| 1756 | return -1; |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1761 | static int alps_probe_trackstick_v3(struct psmouse *psmouse, int reg_base) |
| 1762 | { |
| 1763 | int ret = -EIO, reg_val; |
| 1764 | |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 1765 | if (alps_enter_command_mode(psmouse)) |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1766 | goto error; |
| 1767 | |
| 1768 | reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08); |
| 1769 | if (reg_val == -1) |
| 1770 | goto error; |
| 1771 | |
| 1772 | /* bit 7: trackstick is present */ |
| 1773 | ret = reg_val & 0x80 ? 0 : -ENODEV; |
| 1774 | |
| 1775 | error: |
| 1776 | alps_exit_command_mode(psmouse); |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
| 1780 | static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base) |
| 1781 | { |
| 1782 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1783 | int ret = 0; |
| 1784 | unsigned char param[4]; |
| 1785 | |
| 1786 | if (alps_passthrough_mode_v3(psmouse, reg_base, true)) |
| 1787 | return -EIO; |
| 1788 | |
| 1789 | /* |
| 1790 | * E7 report for the trackstick |
| 1791 | * |
| 1792 | * There have been reports of failures to seem to trace back |
| 1793 | * to the above trackstick check failing. When these occur |
| 1794 | * this E7 report fails, so when that happens we continue |
| 1795 | * with the assumption that there isn't a trackstick after |
| 1796 | * all. |
| 1797 | */ |
| 1798 | if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_SETSCALE21, param)) { |
| 1799 | psmouse_warn(psmouse, "trackstick E7 report failed\n"); |
| 1800 | ret = -ENODEV; |
| 1801 | } else { |
Dmitry Torokhov | 39fbe58 | 2013-02-14 09:04:24 -0800 | [diff] [blame] | 1802 | psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param); |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1803 | |
| 1804 | /* |
| 1805 | * Not sure what this does, but it is absolutely |
| 1806 | * essential. Without it, the touchpad does not |
| 1807 | * work at all and the trackstick just emits normal |
| 1808 | * PS/2 packets. |
| 1809 | */ |
| 1810 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1811 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1812 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 1813 | alps_command_mode_send_nibble(psmouse, 0x9) || |
| 1814 | alps_command_mode_send_nibble(psmouse, 0x4)) { |
| 1815 | psmouse_err(psmouse, |
| 1816 | "Error sending magic E6 sequence\n"); |
| 1817 | ret = -EIO; |
| 1818 | goto error; |
| 1819 | } |
| 1820 | |
| 1821 | /* |
| 1822 | * This ensures the trackstick packets are in the format |
| 1823 | * supported by this driver. If bit 1 isn't set the packet |
| 1824 | * format is different. |
| 1825 | */ |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 1826 | if (alps_enter_command_mode(psmouse) || |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1827 | alps_command_mode_write_reg(psmouse, |
| 1828 | reg_base + 0x08, 0x82) || |
| 1829 | alps_exit_command_mode(psmouse)) |
| 1830 | ret = -EIO; |
| 1831 | } |
| 1832 | |
| 1833 | error: |
| 1834 | if (alps_passthrough_mode_v3(psmouse, reg_base, false)) |
| 1835 | ret = -EIO; |
| 1836 | |
| 1837 | return ret; |
| 1838 | } |
| 1839 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1840 | static int alps_hw_init_v3(struct psmouse *psmouse) |
| 1841 | { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1842 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1843 | int reg_val; |
| 1844 | unsigned char param[4]; |
| 1845 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1846 | reg_val = alps_probe_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE); |
| 1847 | if (reg_val == -EIO) |
| 1848 | goto error; |
Dmitry Torokhov | 39fbe58 | 2013-02-14 09:04:24 -0800 | [diff] [blame] | 1849 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1850 | if (reg_val == 0 && |
| 1851 | alps_setup_trackstick_v3(psmouse, ALPS_REG_BASE_PINNACLE) == -EIO) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1852 | goto error; |
| 1853 | |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 1854 | if (alps_enter_command_mode(psmouse) || |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1855 | alps_absolute_mode_v3(psmouse)) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1856 | psmouse_err(psmouse, "Failed to enter absolute mode\n"); |
| 1857 | goto error; |
| 1858 | } |
| 1859 | |
| 1860 | reg_val = alps_command_mode_read_reg(psmouse, 0x0006); |
| 1861 | if (reg_val == -1) |
| 1862 | goto error; |
| 1863 | if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) |
| 1864 | goto error; |
| 1865 | |
| 1866 | reg_val = alps_command_mode_read_reg(psmouse, 0x0007); |
| 1867 | if (reg_val == -1) |
| 1868 | goto error; |
| 1869 | if (__alps_command_mode_write_reg(psmouse, reg_val | 0x01)) |
| 1870 | goto error; |
| 1871 | |
| 1872 | if (alps_command_mode_read_reg(psmouse, 0x0144) == -1) |
| 1873 | goto error; |
| 1874 | if (__alps_command_mode_write_reg(psmouse, 0x04)) |
| 1875 | goto error; |
| 1876 | |
| 1877 | if (alps_command_mode_read_reg(psmouse, 0x0159) == -1) |
| 1878 | goto error; |
| 1879 | if (__alps_command_mode_write_reg(psmouse, 0x03)) |
| 1880 | goto error; |
| 1881 | |
| 1882 | if (alps_command_mode_read_reg(psmouse, 0x0163) == -1) |
| 1883 | goto error; |
| 1884 | if (alps_command_mode_write_reg(psmouse, 0x0163, 0x03)) |
| 1885 | goto error; |
| 1886 | |
| 1887 | if (alps_command_mode_read_reg(psmouse, 0x0162) == -1) |
| 1888 | goto error; |
| 1889 | if (alps_command_mode_write_reg(psmouse, 0x0162, 0x04)) |
| 1890 | goto error; |
| 1891 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1892 | alps_exit_command_mode(psmouse); |
| 1893 | |
| 1894 | /* Set rate and enable data reporting */ |
| 1895 | param[0] = 0x64; |
| 1896 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || |
| 1897 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { |
| 1898 | psmouse_err(psmouse, "Failed to enable data reporting\n"); |
| 1899 | return -1; |
| 1900 | } |
| 1901 | |
| 1902 | return 0; |
| 1903 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 1904 | error: |
| 1905 | /* |
| 1906 | * Leaving the touchpad in command mode will essentially render |
| 1907 | * it unusable until the machine reboots, so exit it here just |
| 1908 | * to be safe |
| 1909 | */ |
| 1910 | alps_exit_command_mode(psmouse); |
| 1911 | return -1; |
| 1912 | } |
| 1913 | |
Hans de Goede | f3f33c6 | 2014-07-29 11:22:07 -0700 | [diff] [blame] | 1914 | static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch) |
| 1915 | { |
| 1916 | int reg, x_pitch, y_pitch, x_electrode, y_electrode, x_phys, y_phys; |
| 1917 | struct alps_data *priv = psmouse->private; |
| 1918 | |
| 1919 | reg = alps_command_mode_read_reg(psmouse, reg_pitch); |
| 1920 | if (reg < 0) |
| 1921 | return reg; |
| 1922 | |
| 1923 | x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */ |
| 1924 | x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */ |
| 1925 | |
| 1926 | y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */ |
| 1927 | y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */ |
| 1928 | |
| 1929 | reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1); |
| 1930 | if (reg < 0) |
| 1931 | return reg; |
| 1932 | |
| 1933 | x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */ |
| 1934 | x_electrode = 17 + x_electrode; |
| 1935 | |
| 1936 | y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */ |
| 1937 | y_electrode = 13 + y_electrode; |
| 1938 | |
| 1939 | x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */ |
| 1940 | y_phys = y_pitch * (y_electrode - 1); /* In 0.1 mm units */ |
| 1941 | |
| 1942 | priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */ |
| 1943 | priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */ |
| 1944 | |
| 1945 | psmouse_dbg(psmouse, |
| 1946 | "pitch %dx%d num-electrodes %dx%d physical size %dx%d mm res %dx%d\n", |
| 1947 | x_pitch, y_pitch, x_electrode, y_electrode, |
| 1948 | x_phys / 10, y_phys / 10, priv->x_res, priv->y_res); |
| 1949 | |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 1953 | static int alps_hw_init_rushmore_v3(struct psmouse *psmouse) |
| 1954 | { |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1955 | struct alps_data *priv = psmouse->private; |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 1956 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 1957 | int reg_val, ret = -1; |
| 1958 | |
Kevin Cernekee | cd40120 | 2013-02-13 22:28:07 -0800 | [diff] [blame] | 1959 | if (priv->flags & ALPS_DUALPOINT) { |
| 1960 | reg_val = alps_setup_trackstick_v3(psmouse, |
| 1961 | ALPS_REG_BASE_RUSHMORE); |
| 1962 | if (reg_val == -EIO) |
| 1963 | goto error; |
| 1964 | if (reg_val == -ENODEV) |
| 1965 | priv->flags &= ~ALPS_DUALPOINT; |
| 1966 | } |
| 1967 | |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 1968 | if (alps_enter_command_mode(psmouse) || |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 1969 | alps_command_mode_read_reg(psmouse, 0xc2d9) == -1 || |
| 1970 | alps_command_mode_write_reg(psmouse, 0xc2cb, 0x00)) |
| 1971 | goto error; |
| 1972 | |
Hans de Goede | f3f33c6 | 2014-07-29 11:22:07 -0700 | [diff] [blame] | 1973 | if (alps_get_v3_v7_resolution(psmouse, 0xc2da)) |
| 1974 | goto error; |
| 1975 | |
Kevin Cernekee | 1302bac | 2013-02-13 22:27:08 -0800 | [diff] [blame] | 1976 | reg_val = alps_command_mode_read_reg(psmouse, 0xc2c6); |
| 1977 | if (reg_val == -1) |
| 1978 | goto error; |
| 1979 | if (__alps_command_mode_write_reg(psmouse, reg_val & 0xfd)) |
| 1980 | goto error; |
| 1981 | |
| 1982 | if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64)) |
| 1983 | goto error; |
| 1984 | |
| 1985 | /* enter absolute mode */ |
| 1986 | reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4); |
| 1987 | if (reg_val == -1) |
| 1988 | goto error; |
| 1989 | if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02)) |
| 1990 | goto error; |
| 1991 | |
| 1992 | alps_exit_command_mode(psmouse); |
| 1993 | return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE); |
| 1994 | |
| 1995 | error: |
| 1996 | alps_exit_command_mode(psmouse); |
| 1997 | return ret; |
| 1998 | } |
| 1999 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2000 | /* Must be in command mode when calling this function */ |
| 2001 | static int alps_absolute_mode_v4(struct psmouse *psmouse) |
| 2002 | { |
| 2003 | int reg_val; |
| 2004 | |
| 2005 | reg_val = alps_command_mode_read_reg(psmouse, 0x0004); |
| 2006 | if (reg_val == -1) |
| 2007 | return -1; |
| 2008 | |
| 2009 | reg_val |= 0x02; |
| 2010 | if (__alps_command_mode_write_reg(psmouse, reg_val)) |
| 2011 | return -1; |
| 2012 | |
| 2013 | return 0; |
| 2014 | } |
| 2015 | |
| 2016 | static int alps_hw_init_v4(struct psmouse *psmouse) |
| 2017 | { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2018 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 2019 | unsigned char param[4]; |
| 2020 | |
Kevin Cernekee | d18e53f | 2013-02-21 22:58:20 -0800 | [diff] [blame] | 2021 | if (alps_enter_command_mode(psmouse)) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2022 | goto error; |
| 2023 | |
| 2024 | if (alps_absolute_mode_v4(psmouse)) { |
| 2025 | psmouse_err(psmouse, "Failed to enter absolute mode\n"); |
| 2026 | goto error; |
| 2027 | } |
| 2028 | |
| 2029 | if (alps_command_mode_write_reg(psmouse, 0x0007, 0x8c)) |
| 2030 | goto error; |
| 2031 | |
| 2032 | if (alps_command_mode_write_reg(psmouse, 0x0149, 0x03)) |
| 2033 | goto error; |
| 2034 | |
| 2035 | if (alps_command_mode_write_reg(psmouse, 0x0160, 0x03)) |
| 2036 | goto error; |
| 2037 | |
| 2038 | if (alps_command_mode_write_reg(psmouse, 0x017f, 0x15)) |
| 2039 | goto error; |
| 2040 | |
| 2041 | if (alps_command_mode_write_reg(psmouse, 0x0151, 0x01)) |
| 2042 | goto error; |
| 2043 | |
| 2044 | if (alps_command_mode_write_reg(psmouse, 0x0168, 0x03)) |
| 2045 | goto error; |
| 2046 | |
| 2047 | if (alps_command_mode_write_reg(psmouse, 0x014a, 0x03)) |
| 2048 | goto error; |
| 2049 | |
| 2050 | if (alps_command_mode_write_reg(psmouse, 0x0161, 0x03)) |
| 2051 | goto error; |
| 2052 | |
| 2053 | alps_exit_command_mode(psmouse); |
| 2054 | |
| 2055 | /* |
| 2056 | * This sequence changes the output from a 9-byte to an |
| 2057 | * 8-byte format. All the same data seems to be present, |
| 2058 | * just in a more compact format. |
| 2059 | */ |
| 2060 | param[0] = 0xc8; |
| 2061 | param[1] = 0x64; |
| 2062 | param[2] = 0x50; |
| 2063 | if (ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || |
| 2064 | ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE) || |
| 2065 | ps2_command(ps2dev, ¶m[2], PSMOUSE_CMD_SETRATE) || |
| 2066 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) |
| 2067 | return -1; |
| 2068 | |
| 2069 | /* Set rate and enable data reporting */ |
| 2070 | param[0] = 0x64; |
| 2071 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE) || |
| 2072 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { |
| 2073 | psmouse_err(psmouse, "Failed to enable data reporting\n"); |
| 2074 | return -1; |
| 2075 | } |
| 2076 | |
| 2077 | return 0; |
| 2078 | |
| 2079 | error: |
| 2080 | /* |
| 2081 | * Leaving the touchpad in command mode will essentially render |
| 2082 | * it unusable until the machine reboots, so exit it here just |
| 2083 | * to be safe |
| 2084 | */ |
| 2085 | alps_exit_command_mode(psmouse); |
| 2086 | return -1; |
| 2087 | } |
| 2088 | |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 2089 | static int alps_dolphin_get_device_area(struct psmouse *psmouse, |
| 2090 | struct alps_data *priv) |
| 2091 | { |
| 2092 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 2093 | unsigned char param[4] = {0}; |
| 2094 | int num_x_electrode, num_y_electrode; |
| 2095 | |
| 2096 | if (alps_enter_command_mode(psmouse)) |
| 2097 | return -1; |
| 2098 | |
| 2099 | param[0] = 0x0a; |
| 2100 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || |
| 2101 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) || |
| 2102 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL) || |
| 2103 | ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || |
| 2104 | ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE)) |
| 2105 | return -1; |
| 2106 | |
| 2107 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 2108 | return -1; |
| 2109 | |
| 2110 | /* |
| 2111 | * Dolphin's sensor line number is not fixed. It can be calculated |
| 2112 | * by adding the device's register value with DOLPHIN_PROFILE_X/YOFFSET. |
| 2113 | * Further more, we can get device's x_max and y_max by multiplying |
| 2114 | * sensor line number with DOLPHIN_COUNT_PER_ELECTRODE. |
| 2115 | * |
| 2116 | * e.g. When we get register's sensor_x = 11 & sensor_y = 8, |
| 2117 | * real sensor line number X = 11 + 8 = 19, and |
| 2118 | * real sensor line number Y = 8 + 1 = 9. |
| 2119 | * So, x_max = (19 - 1) * 64 = 1152, and |
| 2120 | * y_max = (9 - 1) * 64 = 512. |
| 2121 | */ |
| 2122 | num_x_electrode = DOLPHIN_PROFILE_XOFFSET + (param[2] & 0x0F); |
| 2123 | num_y_electrode = DOLPHIN_PROFILE_YOFFSET + ((param[2] >> 4) & 0x0F); |
| 2124 | priv->x_bits = num_x_electrode; |
| 2125 | priv->y_bits = num_y_electrode; |
| 2126 | priv->x_max = (num_x_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE; |
| 2127 | priv->y_max = (num_y_electrode - 1) * DOLPHIN_COUNT_PER_ELECTRODE; |
| 2128 | |
| 2129 | if (alps_exit_command_mode(psmouse)) |
| 2130 | return -1; |
| 2131 | |
| 2132 | return 0; |
| 2133 | } |
| 2134 | |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 2135 | static int alps_hw_init_dolphin_v1(struct psmouse *psmouse) |
| 2136 | { |
| 2137 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 2138 | unsigned char param[2]; |
| 2139 | |
| 2140 | /* This is dolphin "v1" as empirically defined by florin9doi */ |
| 2141 | param[0] = 0x64; |
| 2142 | param[1] = 0x28; |
| 2143 | |
| 2144 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSTREAM) || |
| 2145 | ps2_command(ps2dev, ¶m[0], PSMOUSE_CMD_SETRATE) || |
| 2146 | ps2_command(ps2dev, ¶m[1], PSMOUSE_CMD_SETRATE)) |
| 2147 | return -1; |
| 2148 | |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2152 | static int alps_hw_init_v7(struct psmouse *psmouse) |
| 2153 | { |
| 2154 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 2155 | int reg_val, ret = -1; |
| 2156 | |
| 2157 | if (alps_enter_command_mode(psmouse) || |
| 2158 | alps_command_mode_read_reg(psmouse, 0xc2d9) == -1) |
| 2159 | goto error; |
| 2160 | |
Hans de Goede | f3f33c6 | 2014-07-29 11:22:07 -0700 | [diff] [blame] | 2161 | if (alps_get_v3_v7_resolution(psmouse, 0xc397)) |
| 2162 | goto error; |
| 2163 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2164 | if (alps_command_mode_write_reg(psmouse, 0xc2c9, 0x64)) |
| 2165 | goto error; |
| 2166 | |
| 2167 | reg_val = alps_command_mode_read_reg(psmouse, 0xc2c4); |
| 2168 | if (reg_val == -1) |
| 2169 | goto error; |
| 2170 | if (__alps_command_mode_write_reg(psmouse, reg_val | 0x02)) |
| 2171 | goto error; |
| 2172 | |
| 2173 | alps_exit_command_mode(psmouse); |
| 2174 | return ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE); |
| 2175 | |
| 2176 | error: |
| 2177 | alps_exit_command_mode(psmouse); |
| 2178 | return ret; |
| 2179 | } |
| 2180 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2181 | static int alps_set_protocol(struct psmouse *psmouse, |
| 2182 | struct alps_data *priv, |
| 2183 | const struct alps_protocol_info *protocol) |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2184 | { |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2185 | psmouse->private = priv; |
| 2186 | |
| 2187 | setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse); |
| 2188 | |
| 2189 | priv->proto_version = protocol->version; |
| 2190 | priv->byte0 = protocol->byte0; |
| 2191 | priv->mask0 = protocol->mask0; |
| 2192 | priv->flags = protocol->flags; |
Kevin Cernekee | f673ceb | 2013-02-13 22:23:34 -0800 | [diff] [blame] | 2193 | |
Kevin Cernekee | 7a9f73e | 2013-02-13 22:24:55 -0800 | [diff] [blame] | 2194 | priv->x_max = 2000; |
| 2195 | priv->y_max = 1400; |
| 2196 | priv->x_bits = 15; |
| 2197 | priv->y_bits = 11; |
| 2198 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 2199 | switch (priv->proto_version) { |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2200 | case ALPS_PROTO_V1: |
| 2201 | case ALPS_PROTO_V2: |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2202 | priv->hw_init = alps_hw_init_v1_v2; |
| 2203 | priv->process_packet = alps_process_packet_v1_v2; |
| 2204 | priv->set_abs_params = alps_set_abs_params_st; |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 2205 | priv->x_max = 1023; |
| 2206 | priv->y_max = 767; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2207 | break; |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 2208 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2209 | case ALPS_PROTO_V3: |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2210 | priv->hw_init = alps_hw_init_v3; |
| 2211 | priv->process_packet = alps_process_packet_v3; |
| 2212 | priv->set_abs_params = alps_set_abs_params_mt; |
Kevin Cernekee | f85e500 | 2013-02-13 22:26:11 -0800 | [diff] [blame] | 2213 | priv->decode_fields = alps_decode_pinnacle; |
Kevin Cernekee | 50e8b21 | 2013-02-13 22:23:04 -0800 | [diff] [blame] | 2214 | priv->nibble_commands = alps_v3_nibble_commands; |
| 2215 | priv->addr_command = PSMOUSE_CMD_RESET_WRAP; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2216 | break; |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 2217 | |
| 2218 | case ALPS_PROTO_V3_RUSHMORE: |
| 2219 | priv->hw_init = alps_hw_init_rushmore_v3; |
| 2220 | priv->process_packet = alps_process_packet_v3; |
| 2221 | priv->set_abs_params = alps_set_abs_params_mt; |
| 2222 | priv->decode_fields = alps_decode_rushmore; |
| 2223 | priv->nibble_commands = alps_v3_nibble_commands; |
| 2224 | priv->addr_command = PSMOUSE_CMD_RESET_WRAP; |
| 2225 | priv->x_bits = 16; |
| 2226 | priv->y_bits = 12; |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2227 | |
| 2228 | if (alps_probe_trackstick_v3(psmouse, |
| 2229 | ALPS_REG_BASE_RUSHMORE) < 0) |
| 2230 | priv->flags &= ~ALPS_DUALPOINT; |
| 2231 | |
Dmitry Torokhov | fb2dd7a | 2015-01-14 10:39:52 -0800 | [diff] [blame] | 2232 | break; |
| 2233 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2234 | case ALPS_PROTO_V4: |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2235 | priv->hw_init = alps_hw_init_v4; |
| 2236 | priv->process_packet = alps_process_packet_v4; |
| 2237 | priv->set_abs_params = alps_set_abs_params_mt; |
Kevin Cernekee | 50e8b21 | 2013-02-13 22:23:04 -0800 | [diff] [blame] | 2238 | priv->nibble_commands = alps_v4_nibble_commands; |
| 2239 | priv->addr_command = PSMOUSE_CMD_DISABLE; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2240 | break; |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2241 | |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 2242 | case ALPS_PROTO_V5: |
| 2243 | priv->hw_init = alps_hw_init_dolphin_v1; |
Yunkang Tang | ee65d4b | 2013-12-26 14:54:19 -0800 | [diff] [blame] | 2244 | priv->process_packet = alps_process_touchpad_packet_v3_v5; |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 2245 | priv->decode_fields = alps_decode_dolphin; |
| 2246 | priv->set_abs_params = alps_set_abs_params_mt; |
| 2247 | priv->nibble_commands = alps_v3_nibble_commands; |
| 2248 | priv->addr_command = PSMOUSE_CMD_RESET_WRAP; |
Dave Turvene | 75af9e5 | 2013-02-21 22:58:28 -0800 | [diff] [blame] | 2249 | priv->x_max = 1360; |
| 2250 | priv->y_max = 660; |
| 2251 | priv->x_bits = 23; |
| 2252 | priv->y_bits = 12; |
| 2253 | break; |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2254 | |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 2255 | case ALPS_PROTO_V6: |
| 2256 | priv->hw_init = alps_hw_init_v6; |
| 2257 | priv->process_packet = alps_process_packet_v6; |
| 2258 | priv->set_abs_params = alps_set_abs_params_st; |
| 2259 | priv->nibble_commands = alps_v6_nibble_commands; |
| 2260 | priv->x_max = 2047; |
| 2261 | priv->y_max = 1535; |
| 2262 | break; |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2263 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2264 | case ALPS_PROTO_V7: |
| 2265 | priv->hw_init = alps_hw_init_v7; |
| 2266 | priv->process_packet = alps_process_packet_v7; |
| 2267 | priv->decode_fields = alps_decode_packet_v7; |
| 2268 | priv->set_abs_params = alps_set_abs_params_mt; |
| 2269 | priv->nibble_commands = alps_v3_nibble_commands; |
| 2270 | priv->addr_command = PSMOUSE_CMD_RESET_WRAP; |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2271 | |
| 2272 | if (alps_dolphin_get_device_area(psmouse, priv)) |
| 2273 | return -EIO; |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2274 | |
| 2275 | if (priv->fw_ver[1] != 0xba) |
| 2276 | priv->flags |= ALPS_BUTTONPAD; |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2277 | |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2278 | break; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2279 | } |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2280 | |
| 2281 | return 0; |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2282 | } |
| 2283 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2284 | static const struct alps_protocol_info *alps_match_table(unsigned char *e7, |
| 2285 | unsigned char *ec) |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2286 | { |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2287 | const struct alps_model_info *model; |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2288 | int i; |
| 2289 | |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2290 | for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) { |
| 2291 | model = &alps_model_data[i]; |
| 2292 | |
| 2293 | if (!memcmp(e7, model->signature, sizeof(model->signature)) && |
| 2294 | (!model->command_mode_resp || |
| 2295 | model->command_mode_resp == ec[2])) { |
| 2296 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2297 | return &model->protocol_info; |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2301 | return NULL; |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | static int alps_identify(struct psmouse *psmouse, struct alps_data *priv) |
| 2305 | { |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2306 | const struct alps_protocol_info *protocol; |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2307 | unsigned char e6[4], e7[4], ec[4]; |
| 2308 | |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2309 | /* |
| 2310 | * First try "E6 report". |
| 2311 | * ALPS should return 0,0,10 or 0,0,100 if no buttons are pressed. |
| 2312 | * The bits 0-2 of the first byte will be 1s if some buttons are |
| 2313 | * pressed. |
| 2314 | */ |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2315 | if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, |
| 2316 | PSMOUSE_CMD_SETSCALE11, e6)) |
| 2317 | return -EIO; |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2318 | |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2319 | if ((e6[0] & 0xf8) != 0 || e6[1] != 0 || (e6[2] != 10 && e6[2] != 100)) |
| 2320 | return -EINVAL; |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2321 | |
| 2322 | /* |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2323 | * Now get the "E7" and "EC" reports. These will uniquely identify |
| 2324 | * most ALPS touchpads. |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2325 | */ |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2326 | if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, |
| 2327 | PSMOUSE_CMD_SETSCALE21, e7) || |
| 2328 | alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, |
| 2329 | PSMOUSE_CMD_RESET_WRAP, ec) || |
| 2330 | alps_exit_command_mode(psmouse)) |
| 2331 | return -EIO; |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2332 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2333 | protocol = alps_match_table(e7, ec); |
| 2334 | if (!protocol) { |
| 2335 | if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 && |
| 2336 | ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) { |
| 2337 | protocol = &alps_v5_protocol_data; |
| 2338 | } else if (ec[0] == 0x88 && |
| 2339 | ((ec[1] & 0xf0) == 0xb0 || (ec[1] & 0xf0) == 0xc0)) { |
| 2340 | protocol = &alps_v7_protocol_data; |
| 2341 | } else if (ec[0] == 0x88 && ec[1] == 0x08) { |
| 2342 | protocol = &alps_v3_rushmore_data; |
| 2343 | } else if (ec[0] == 0x88 && ec[1] == 0x07 && |
| 2344 | ec[2] >= 0x90 && ec[2] <= 0x9d) { |
| 2345 | protocol = &alps_v3_protocol_data; |
| 2346 | } else { |
| 2347 | psmouse_dbg(psmouse, |
| 2348 | "Likely not an ALPS touchpad: E7=%3ph, EC=%3ph\n", e7, ec); |
| 2349 | return -EINVAL; |
| 2350 | } |
| 2351 | } |
| 2352 | |
Hans de Goede | c0cd17f | 2014-07-25 22:49:14 -0700 | [diff] [blame] | 2353 | /* Save the Firmware version */ |
| 2354 | memcpy(priv->fw_ver, ec, 3); |
| 2355 | |
Dmitry Torokhov | 3296f71 | 2015-01-12 00:30:32 -0800 | [diff] [blame^] | 2356 | return alps_set_protocol(psmouse, priv, protocol); |
Kevin Cernekee | 2e992cc | 2013-02-13 20:57:04 -0800 | [diff] [blame] | 2357 | } |
| 2358 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 2359 | static int alps_reconnect(struct psmouse *psmouse) |
| 2360 | { |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2361 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 2362 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 2363 | psmouse_reset(psmouse); |
| 2364 | |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2365 | if (alps_identify(psmouse, priv) < 0) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 2366 | return -1; |
| 2367 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2368 | return priv->hw_init(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | static void alps_disconnect(struct psmouse *psmouse) |
| 2372 | { |
| 2373 | struct alps_data *priv = psmouse->private; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | psmouse_reset(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 2376 | del_timer_sync(&priv->timer); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2377 | input_unregister_device(priv->dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | kfree(priv); |
| 2379 | } |
| 2380 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2381 | static void alps_set_abs_params_st(struct alps_data *priv, |
| 2382 | struct input_dev *dev1) |
| 2383 | { |
Yunkang Tang | 95f75e9 | 2013-12-01 22:33:52 -0800 | [diff] [blame] | 2384 | input_set_abs_params(dev1, ABS_X, 0, priv->x_max, 0, 0); |
| 2385 | input_set_abs_params(dev1, ABS_Y, 0, priv->y_max, 0, 0); |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | static void alps_set_abs_params_mt(struct alps_data *priv, |
| 2389 | struct input_dev *dev1) |
| 2390 | { |
Kevin Cernekee | 7a9f73e | 2013-02-13 22:24:55 -0800 | [diff] [blame] | 2391 | input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0); |
| 2392 | input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0); |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2393 | |
Hans de Goede | f3f33c6 | 2014-07-29 11:22:07 -0700 | [diff] [blame] | 2394 | input_abs_set_res(dev1, ABS_MT_POSITION_X, priv->x_res); |
| 2395 | input_abs_set_res(dev1, ABS_MT_POSITION_Y, priv->y_res); |
| 2396 | |
Hans de Goede | cdf333e | 2014-07-25 22:44:42 -0700 | [diff] [blame] | 2397 | input_mt_init_slots(dev1, MAX_TOUCHES, INPUT_MT_POINTER | |
| 2398 | INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK | INPUT_MT_SEMI_MT); |
| 2399 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2400 | set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit); |
| 2401 | set_bit(BTN_TOOL_QUADTAP, dev1->keybit); |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2402 | |
| 2403 | /* V7 is real multi-touch */ |
| 2404 | if (priv->proto_version == ALPS_PROTO_V7) |
| 2405 | clear_bit(INPUT_PROP_SEMI_MT, dev1->propbit); |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2406 | } |
| 2407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | int alps_init(struct psmouse *psmouse) |
| 2409 | { |
| 2410 | struct alps_data *priv; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2411 | struct input_dev *dev1 = psmouse->dev, *dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 2413 | priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2414 | dev2 = input_allocate_device(); |
| 2415 | if (!priv || !dev2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | goto init_fail; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2417 | |
| 2418 | priv->dev2 = dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2420 | psmouse_reset(psmouse); |
| 2421 | |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2422 | if (alps_identify(psmouse, priv) < 0) |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 2423 | goto init_fail; |
| 2424 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2425 | if (priv->hw_init(psmouse)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | goto init_fail; |
| 2427 | |
Dmitry Torokhov | 7105d2e | 2009-12-11 23:54:54 -0800 | [diff] [blame] | 2428 | /* |
| 2429 | * Undo part of setup done for us by psmouse core since touchpad |
| 2430 | * is not a relative device. |
| 2431 | */ |
| 2432 | __clear_bit(EV_REL, dev1->evbit); |
| 2433 | __clear_bit(REL_X, dev1->relbit); |
| 2434 | __clear_bit(REL_Y, dev1->relbit); |
| 2435 | |
| 2436 | /* |
| 2437 | * Now set up our capabilities. |
| 2438 | */ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 2439 | dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY); |
| 2440 | dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH); |
| 2441 | dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 2442 | dev1->keybit[BIT_WORD(BTN_LEFT)] |= |
| 2443 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 2445 | dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); |
Seth Forshee | 25bded7 | 2011-11-07 19:53:36 -0800 | [diff] [blame] | 2446 | |
Kevin Cernekee | 24af5cb | 2013-02-13 22:22:08 -0800 | [diff] [blame] | 2447 | priv->set_abs_params(priv, dev1); |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2448 | /* No pressure on V7 */ |
| 2449 | if (priv->proto_version != ALPS_PROTO_V7) |
| 2450 | input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 2452 | if (priv->flags & ALPS_WHEEL) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 2453 | dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); |
| 2454 | dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 2457 | if (priv->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 2458 | dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); |
| 2459 | dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 2462 | if (priv->flags & ALPS_FOUR_BUTTONS) { |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 2463 | dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0); |
| 2464 | dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1); |
| 2465 | dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2); |
| 2466 | dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3); |
Yunkang Tang | 3808843 | 2014-07-26 13:51:41 -0700 | [diff] [blame] | 2467 | } else if (priv->flags & ALPS_BUTTONPAD) { |
| 2468 | set_bit(INPUT_PROP_BUTTONPAD, dev1->propbit); |
| 2469 | clear_bit(BTN_RIGHT, dev1->keybit); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 2470 | } else { |
| 2471 | dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE); |
| 2472 | } |
| 2473 | |
Pali Rohár | dfba860 | 2015-01-09 12:48:44 -0800 | [diff] [blame] | 2474 | if (priv->flags & ALPS_DUALPOINT) { |
| 2475 | /* |
| 2476 | * format of input device name is: "protocol vendor name" |
| 2477 | * see function psmouse_switch_protocol() in psmouse-base.c |
| 2478 | */ |
| 2479 | dev2->name = "AlpsPS/2 ALPS DualPoint Stick"; |
| 2480 | dev2->id.product = PSMOUSE_ALPS; |
| 2481 | dev2->id.version = priv->proto_version; |
| 2482 | } else { |
| 2483 | dev2->name = "PS/2 ALPS Mouse"; |
| 2484 | dev2->id.product = PSMOUSE_PS2; |
| 2485 | dev2->id.version = 0x0000; |
| 2486 | } |
| 2487 | |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 2488 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2489 | dev2->phys = priv->phys; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2490 | dev2->id.bustype = BUS_I8042; |
| 2491 | dev2->id.vendor = 0x0002; |
Dmitry Torokhov | 1db3a34 | 2008-03-18 00:29:18 -0400 | [diff] [blame] | 2492 | dev2->dev.parent = &psmouse->ps2dev.serio->dev; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 2493 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 2494 | dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 2495 | dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
| 2496 | dev2->keybit[BIT_WORD(BTN_LEFT)] = |
| 2497 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | |
Hans de Goede | 01d4cd5 | 2014-09-08 14:44:05 -0700 | [diff] [blame] | 2499 | __set_bit(INPUT_PROP_POINTER, dev2->propbit); |
Hans de Goede | 7611392 | 2014-09-08 14:42:12 -0700 | [diff] [blame] | 2500 | if (priv->flags & ALPS_DUALPOINT) |
| 2501 | __set_bit(INPUT_PROP_POINTING_STICK, dev2->propbit); |
| 2502 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 2503 | if (input_register_device(priv->dev2)) |
| 2504 | goto init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | |
| 2506 | psmouse->protocol_handler = alps_process_byte; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 2507 | psmouse->poll = alps_poll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | psmouse->disconnect = alps_disconnect; |
| 2509 | psmouse->reconnect = alps_reconnect; |
Kevin Cernekee | 99df65e | 2013-02-13 20:56:33 -0800 | [diff] [blame] | 2510 | psmouse->pktsize = priv->proto_version == ALPS_PROTO_V4 ? 8 : 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 2512 | /* We are having trouble resyncing ALPS touchpads so disable it for now */ |
| 2513 | psmouse->resync_time = 0; |
| 2514 | |
Pali Rohár | 9d720b3 | 2014-11-08 12:58:57 -0800 | [diff] [blame] | 2515 | /* Allow 2 invalid packets without resetting device */ |
| 2516 | psmouse->resetafter = psmouse->pktsize * 2; |
| 2517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | return 0; |
| 2519 | |
| 2520 | init_fail: |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 2521 | psmouse_reset(psmouse); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 2522 | input_free_device(dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | kfree(priv); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 2524 | psmouse->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | return -1; |
| 2526 | } |
| 2527 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 2528 | int alps_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | { |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2530 | struct alps_data dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2532 | if (alps_identify(psmouse, &dummy) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | return -1; |
| 2534 | |
| 2535 | if (set_properties) { |
| 2536 | psmouse->vendor = "ALPS"; |
Kevin Cernekee | b5d6b85 | 2013-02-13 22:19:59 -0800 | [diff] [blame] | 2537 | psmouse->name = dummy.flags & ALPS_DUALPOINT ? |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 2538 | "DualPoint TouchPad" : "GlidePoint"; |
Dmitry Torokhov | d7c13d3 | 2015-01-13 20:53:22 -0800 | [diff] [blame] | 2539 | psmouse->model = dummy.proto_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | } |
| 2541 | return 0; |
| 2542 | } |
| 2543 | |