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