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