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