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