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