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