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