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> |
| 20 | #include <linux/serio.h> |
| 21 | #include <linux/libps2.h> |
| 22 | |
| 23 | #include "psmouse.h" |
| 24 | #include "alps.h" |
| 25 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 26 | #define ALPS_OLDPROTO 0x01 /* old style input */ |
| 27 | #define ALPS_DUALPOINT 0x02 /* touchpad has trackstick */ |
| 28 | #define ALPS_PASS 0x04 /* device has a pass-through port */ |
| 29 | |
| 30 | #define ALPS_WHEEL 0x08 /* hardware wheel present */ |
| 31 | #define ALPS_FW_BK_1 0x10 /* front & back buttons present */ |
| 32 | #define ALPS_FW_BK_2 0x20 /* front & back buttons present */ |
| 33 | #define ALPS_FOUR_BUTTONS 0x40 /* 4 direction button present */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 34 | #define ALPS_PS2_INTERLEAVED 0x80 /* 3-byte PS/2 packet interleaved with |
| 35 | 6-byte ALPS packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 37 | static const struct alps_model_info alps_model_data[] = { |
Dmitry Torokhov | b75d172 | 2009-04-23 19:25:51 -0700 | [diff] [blame] | 38 | { { 0x32, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Toshiba Salellite Pro M10 */ |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 39 | { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
| 41 | { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 42 | { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
| 44 | { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 45 | { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */ |
| 46 | { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ |
| 47 | { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 49 | { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D800 */ |
| 50 | { { 0x73, 0x00, 0x0a }, 0xf8, 0xf8, ALPS_DUALPOINT }, /* ThinkPad R61 8918-5QG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, |
Dmitry Torokhov | af27a69 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 52 | { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ |
| 54 | { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, |
| 55 | { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 56 | /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ |
| 57 | { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, |
| 58 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 59 | { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ |
Thomas Bächler | eb8bff8 | 2010-03-09 20:38:48 -0800 | [diff] [blame] | 60 | { { 0x52, 0x01, 0x14 }, 0xff, 0xff, |
| 61 | ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* |
| 65 | * XXX - this entry is suspicious. First byte has zero lower nibble, |
| 66 | * which is what a normal mouse would report. Also, the value 0x0e |
| 67 | * isn't valid per PS/2 spec. |
| 68 | */ |
| 69 | |
Seth Forshee | d4b347b | 2011-11-07 19:53:15 -0800 | [diff] [blame^] | 70 | /* Packet formats are described in Documentation/input/alps.txt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 72 | static bool alps_is_valid_first_byte(const struct alps_model_info *model, |
| 73 | unsigned char data) |
| 74 | { |
| 75 | return (data & model->mask0) == model->byte0; |
| 76 | } |
| 77 | |
| 78 | static void alps_report_buttons(struct psmouse *psmouse, |
| 79 | struct input_dev *dev1, struct input_dev *dev2, |
| 80 | int left, int right, int middle) |
| 81 | { |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 82 | struct input_dev *dev; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 83 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 84 | /* |
| 85 | * If shared button has already been reported on the |
| 86 | * other device (dev2) then this event should be also |
| 87 | * sent through that device. |
| 88 | */ |
| 89 | dev = test_bit(BTN_LEFT, dev2->key) ? dev2 : dev1; |
| 90 | input_report_key(dev, BTN_LEFT, left); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 91 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 92 | dev = test_bit(BTN_RIGHT, dev2->key) ? dev2 : dev1; |
| 93 | input_report_key(dev, BTN_RIGHT, right); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 94 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 95 | dev = test_bit(BTN_MIDDLE, dev2->key) ? dev2 : dev1; |
| 96 | input_report_key(dev, BTN_MIDDLE, middle); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 97 | |
Martin Buck | c91ed05 | 2010-03-13 22:23:58 -0800 | [diff] [blame] | 98 | /* |
| 99 | * Sync the _other_ device now, we'll do the first |
| 100 | * device later once we report the rest of the events. |
| 101 | */ |
| 102 | input_sync(dev2); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 103 | } |
| 104 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 105 | static void alps_process_packet(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 108 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | unsigned char *packet = psmouse->packet; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 110 | struct input_dev *dev = psmouse->dev; |
| 111 | struct input_dev *dev2 = priv->dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int x, y, z, ges, fin, left, right, middle; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 113 | int back = 0, forward = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 115 | if (model->flags & ALPS_OLDPROTO) { |
Yotam Medini | d2f4012 | 2006-05-29 23:30:36 -0400 | [diff] [blame] | 116 | left = packet[2] & 0x10; |
| 117 | right = packet[2] & 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | middle = 0; |
| 119 | x = packet[1] | ((packet[0] & 0x07) << 7); |
| 120 | y = packet[4] | ((packet[3] & 0x07) << 7); |
| 121 | z = packet[5]; |
| 122 | } else { |
| 123 | left = packet[3] & 1; |
| 124 | right = packet[3] & 2; |
| 125 | middle = packet[3] & 4; |
| 126 | x = packet[1] | ((packet[2] & 0x78) << (7 - 3)); |
| 127 | y = packet[4] | ((packet[3] & 0x70) << (7 - 4)); |
| 128 | z = packet[5]; |
| 129 | } |
| 130 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 131 | if (model->flags & ALPS_FW_BK_1) { |
Laszlo Kajan | 3c00bb9 | 2008-03-18 00:39:55 -0400 | [diff] [blame] | 132 | back = packet[0] & 0x10; |
| 133 | forward = packet[2] & 4; |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 134 | } |
| 135 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 136 | if (model->flags & ALPS_FW_BK_2) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 137 | back = packet[3] & 4; |
| 138 | forward = packet[2] & 4; |
| 139 | if ((middle = forward && back)) |
| 140 | forward = back = 0; |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | ges = packet[2] & 1; |
| 144 | fin = packet[2] & 2; |
| 145 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 146 | if ((model->flags & ALPS_DUALPOINT) && z == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x)); |
| 148 | input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y)); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 149 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 150 | alps_report_buttons(psmouse, dev2, dev, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | input_sync(dev2); |
| 153 | return; |
| 154 | } |
| 155 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 156 | alps_report_buttons(psmouse, dev, dev2, left, right, middle); |
Ulrich Dangel | d7ed5d8 | 2009-06-11 00:15:09 -0700 | [diff] [blame] | 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | /* Convert hardware tap to a reasonable Z value */ |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 159 | if (ges && !fin) |
| 160 | z = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | /* |
| 163 | * A "tap and drag" operation is reported by the hardware as a transition |
| 164 | * from (!fin && ges) to (fin && ges). This should be translated to the |
| 165 | * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually. |
| 166 | */ |
| 167 | if (ges && fin && !priv->prev_fin) { |
| 168 | input_report_abs(dev, ABS_X, x); |
| 169 | input_report_abs(dev, ABS_Y, y); |
| 170 | input_report_abs(dev, ABS_PRESSURE, 0); |
| 171 | input_report_key(dev, BTN_TOOL_FINGER, 0); |
| 172 | input_sync(dev); |
| 173 | } |
| 174 | priv->prev_fin = fin; |
| 175 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 176 | if (z > 30) |
| 177 | input_report_key(dev, BTN_TOUCH, 1); |
| 178 | if (z < 25) |
| 179 | input_report_key(dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | if (z > 0) { |
| 182 | input_report_abs(dev, ABS_X, x); |
| 183 | input_report_abs(dev, ABS_Y, y); |
| 184 | } |
| 185 | |
| 186 | input_report_abs(dev, ABS_PRESSURE, z); |
| 187 | input_report_key(dev, BTN_TOOL_FINGER, z > 0); |
| 188 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 189 | if (model->flags & ALPS_WHEEL) |
Vojtech Pavlik | e6c047b | 2005-09-04 01:40:43 -0500 | [diff] [blame] | 190 | 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] | 191 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 192 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Ivan Casado Ruiz | c30b4c1 | 2005-06-01 02:39:18 -0500 | [diff] [blame] | 193 | input_report_key(dev, BTN_FORWARD, forward); |
| 194 | input_report_key(dev, BTN_BACK, back); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 197 | if (model->flags & ALPS_FOUR_BUTTONS) { |
| 198 | input_report_key(dev, BTN_0, packet[2] & 4); |
| 199 | input_report_key(dev, BTN_1, packet[0] & 0x10); |
| 200 | input_report_key(dev, BTN_2, packet[3] & 4); |
| 201 | input_report_key(dev, BTN_3, packet[0] & 0x20); |
| 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | input_sync(dev); |
| 205 | } |
| 206 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 207 | static void alps_report_bare_ps2_packet(struct psmouse *psmouse, |
| 208 | unsigned char packet[], |
| 209 | bool report_buttons) |
| 210 | { |
| 211 | struct alps_data *priv = psmouse->private; |
| 212 | struct input_dev *dev2 = priv->dev2; |
| 213 | |
| 214 | if (report_buttons) |
| 215 | alps_report_buttons(psmouse, dev2, psmouse->dev, |
| 216 | packet[0] & 1, packet[0] & 2, packet[0] & 4); |
| 217 | |
| 218 | input_report_rel(dev2, REL_X, |
| 219 | packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); |
| 220 | input_report_rel(dev2, REL_Y, |
| 221 | packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); |
| 222 | |
| 223 | input_sync(dev2); |
| 224 | } |
| 225 | |
| 226 | static psmouse_ret_t alps_handle_interleaved_ps2(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | struct alps_data *priv = psmouse->private; |
| 229 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 230 | if (psmouse->pktcnt < 6) |
| 231 | return PSMOUSE_GOOD_DATA; |
| 232 | |
| 233 | if (psmouse->pktcnt == 6) { |
| 234 | /* |
| 235 | * Start a timer to flush the packet if it ends up last |
| 236 | * 6-byte packet in the stream. Timer needs to fire |
| 237 | * psmouse core times out itself. 20 ms should be enough |
| 238 | * to decide if we are getting more data or not. |
| 239 | */ |
| 240 | mod_timer(&priv->timer, jiffies + msecs_to_jiffies(20)); |
| 241 | return PSMOUSE_GOOD_DATA; |
| 242 | } |
| 243 | |
| 244 | del_timer(&priv->timer); |
| 245 | |
| 246 | if (psmouse->packet[6] & 0x80) { |
| 247 | |
| 248 | /* |
| 249 | * Highest bit is set - that means we either had |
| 250 | * complete ALPS packet and this is start of the |
| 251 | * next packet or we got garbage. |
| 252 | */ |
| 253 | |
| 254 | if (((psmouse->packet[3] | |
| 255 | psmouse->packet[4] | |
| 256 | psmouse->packet[5]) & 0x80) || |
| 257 | (!alps_is_valid_first_byte(priv->i, psmouse->packet[6]))) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 258 | psmouse_dbg(psmouse, |
| 259 | "refusing packet %x %x %x %x (suspected interleaved ps/2)\n", |
| 260 | psmouse->packet[3], psmouse->packet[4], |
| 261 | psmouse->packet[5], psmouse->packet[6]); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 262 | return PSMOUSE_BAD_DATA; |
| 263 | } |
| 264 | |
| 265 | alps_process_packet(psmouse); |
| 266 | |
| 267 | /* Continue with the next packet */ |
| 268 | psmouse->packet[0] = psmouse->packet[6]; |
| 269 | psmouse->pktcnt = 1; |
| 270 | |
| 271 | } else { |
| 272 | |
| 273 | /* |
| 274 | * High bit is 0 - that means that we indeed got a PS/2 |
| 275 | * packet in the middle of ALPS packet. |
| 276 | * |
| 277 | * There is also possibility that we got 6-byte ALPS |
| 278 | * packet followed by 3-byte packet from trackpoint. We |
| 279 | * can not distinguish between these 2 scenarios but |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 280 | * because the latter is unlikely to happen in course of |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 281 | * normal operation (user would need to press all |
| 282 | * buttons on the pad and start moving trackpoint |
| 283 | * without touching the pad surface) we assume former. |
| 284 | * Even if we are wrong the wost thing that would happen |
| 285 | * the cursor would jump but we should not get protocol |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 286 | * de-synchronization. |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 287 | */ |
| 288 | |
| 289 | alps_report_bare_ps2_packet(psmouse, &psmouse->packet[3], |
| 290 | false); |
| 291 | |
| 292 | /* |
| 293 | * Continue with the standard ALPS protocol handling, |
| 294 | * but make sure we won't process it as an interleaved |
| 295 | * packet again, which may happen if all buttons are |
| 296 | * pressed. To avoid this let's reset the 4th bit which |
| 297 | * is normally 1. |
| 298 | */ |
| 299 | psmouse->packet[3] = psmouse->packet[6] & 0xf7; |
| 300 | psmouse->pktcnt = 4; |
| 301 | } |
| 302 | |
| 303 | return PSMOUSE_GOOD_DATA; |
| 304 | } |
| 305 | |
| 306 | static void alps_flush_packet(unsigned long data) |
| 307 | { |
| 308 | struct psmouse *psmouse = (struct psmouse *)data; |
| 309 | |
| 310 | serio_pause_rx(psmouse->ps2dev.serio); |
| 311 | |
| 312 | if (psmouse->pktcnt == 6) { |
| 313 | |
| 314 | /* |
| 315 | * We did not any more data in reasonable amount of time. |
| 316 | * Validate the last 3 bytes and process as a standard |
| 317 | * ALPS packet. |
| 318 | */ |
| 319 | if ((psmouse->packet[3] | |
| 320 | psmouse->packet[4] | |
| 321 | psmouse->packet[5]) & 0x80) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 322 | psmouse_dbg(psmouse, |
| 323 | "refusing packet %x %x %x (suspected interleaved ps/2)\n", |
| 324 | psmouse->packet[3], psmouse->packet[4], |
| 325 | psmouse->packet[5]); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 326 | } else { |
| 327 | alps_process_packet(psmouse); |
| 328 | } |
| 329 | psmouse->pktcnt = 0; |
| 330 | } |
| 331 | |
| 332 | serio_continue_rx(psmouse->ps2dev.serio); |
| 333 | } |
| 334 | |
| 335 | static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) |
| 336 | { |
| 337 | struct alps_data *priv = psmouse->private; |
| 338 | const struct alps_model_info *model = priv->i; |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ |
| 341 | if (psmouse->pktcnt == 3) { |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 342 | alps_report_bare_ps2_packet(psmouse, psmouse->packet, |
| 343 | true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | return PSMOUSE_FULL_PACKET; |
| 345 | } |
| 346 | return PSMOUSE_GOOD_DATA; |
| 347 | } |
| 348 | |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 349 | /* Check for PS/2 packet stuffed in the middle of ALPS packet. */ |
| 350 | |
| 351 | if ((model->flags & ALPS_PS2_INTERLEAVED) && |
| 352 | psmouse->pktcnt >= 4 && (psmouse->packet[3] & 0x0f) == 0x0f) { |
| 353 | return alps_handle_interleaved_ps2(psmouse); |
| 354 | } |
| 355 | |
| 356 | if (!alps_is_valid_first_byte(model, psmouse->packet[0])) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 357 | psmouse_dbg(psmouse, |
| 358 | "refusing packet[0] = %x (mask0 = %x, byte0 = %x)\n", |
| 359 | psmouse->packet[0], model->mask0, model->byte0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 361 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* Bytes 2 - 6 should have 0 in the highest bit */ |
| 364 | if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 && |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 365 | (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 366 | psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", |
| 367 | psmouse->pktcnt - 1, |
| 368 | psmouse->packet[psmouse->pktcnt - 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return PSMOUSE_BAD_DATA; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | if (psmouse->pktcnt == 6) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 373 | alps_process_packet(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | return PSMOUSE_FULL_PACKET; |
| 375 | } |
| 376 | |
| 377 | return PSMOUSE_GOOD_DATA; |
| 378 | } |
| 379 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 380 | static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
| 382 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 383 | static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | unsigned char param[4]; |
| 385 | int i; |
| 386 | |
| 387 | /* |
| 388 | * First try "E6 report". |
| 389 | * ALPS should return 0,0,10 or 0,0,100 |
| 390 | */ |
| 391 | param[0] = 0; |
| 392 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || |
| 393 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 394 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || |
| 395 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) |
| 396 | return NULL; |
| 397 | |
| 398 | param[0] = param[1] = param[2] = 0xff; |
| 399 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 400 | return NULL; |
| 401 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 402 | psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x", |
| 403 | param[0], param[1], param[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100)) |
| 406 | return NULL; |
| 407 | |
| 408 | /* |
| 409 | * Now try "E7 report". Allowed responses are in |
| 410 | * alps_model_data[].signature |
| 411 | */ |
| 412 | param[0] = 0; |
| 413 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || |
| 414 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 415 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || |
| 416 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21)) |
| 417 | return NULL; |
| 418 | |
| 419 | param[0] = param[1] = param[2] = 0xff; |
| 420 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 421 | return NULL; |
| 422 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 423 | psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x", |
| 424 | param[0], param[1], param[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 426 | if (version) { |
| 427 | for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++) |
| 428 | /* empty */; |
| 429 | *version = (param[0] << 8) | (param[1] << 4) | i; |
| 430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | for (i = 0; i < ARRAY_SIZE(alps_model_data); i++) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 433 | if (!memcmp(param, alps_model_data[i].signature, |
| 434 | sizeof(alps_model_data[i].signature))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return alps_model_data + i; |
| 436 | |
| 437 | return NULL; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * For DualPoint devices select the device that should respond to |
| 442 | * subsequent commands. It looks like glidepad is behind stickpointer, |
| 443 | * I'd thought it would be other way around... |
| 444 | */ |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 445 | static int alps_passthrough_mode(struct psmouse *psmouse, bool enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; |
| 449 | |
| 450 | if (ps2_command(ps2dev, NULL, cmd) || |
| 451 | ps2_command(ps2dev, NULL, cmd) || |
| 452 | ps2_command(ps2dev, NULL, cmd) || |
| 453 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE)) |
| 454 | return -1; |
| 455 | |
| 456 | /* we may get 3 more bytes, just ignore them */ |
Dmitry Torokhov | c611763 | 2005-06-01 02:39:51 -0500 | [diff] [blame] | 457 | ps2_drain(ps2dev, 3, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int alps_absolute_mode(struct psmouse *psmouse) |
| 463 | { |
| 464 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 465 | |
| 466 | /* Try ALPS magic knock - 4 disable before enable */ |
| 467 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 468 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 469 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 470 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 471 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE)) |
| 472 | return -1; |
| 473 | |
| 474 | /* |
| 475 | * Switch mouse to poll (remote) mode so motion data will not |
| 476 | * get in our way |
| 477 | */ |
| 478 | return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); |
| 479 | } |
| 480 | |
| 481 | static int alps_get_status(struct psmouse *psmouse, char *param) |
| 482 | { |
| 483 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 484 | |
| 485 | /* Get status: 0xF5 0xF5 0xF5 0xE9 */ |
| 486 | if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 487 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 488 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 489 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) |
| 490 | return -1; |
| 491 | |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 492 | psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x", |
| 493 | param[0], param[1], param[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Turn touchpad tapping on or off. The sequences are: |
| 500 | * 0xE9 0xF5 0xF5 0xF3 0x0A to enable, |
| 501 | * 0xE9 0xF5 0xF5 0xE8 0x00 to disable. |
| 502 | * My guess that 0xE9 (GetInfo) is here as a sync point. |
| 503 | * For models that also have stickpointer (DualPoints) its tapping |
| 504 | * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but |
| 505 | * we don't fiddle with it. |
| 506 | */ |
| 507 | static int alps_tap_mode(struct psmouse *psmouse, int enable) |
| 508 | { |
| 509 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 510 | int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES; |
| 511 | unsigned char tap_arg = enable ? 0x0A : 0x00; |
| 512 | unsigned char param[4]; |
| 513 | |
| 514 | if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) || |
| 515 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 516 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || |
| 517 | ps2_command(ps2dev, &tap_arg, cmd)) |
| 518 | return -1; |
| 519 | |
| 520 | if (alps_get_status(psmouse, param)) |
| 521 | return -1; |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 526 | /* |
| 527 | * alps_poll() - poll the touchpad for current motion packet. |
| 528 | * Used in resync. |
| 529 | */ |
| 530 | static int alps_poll(struct psmouse *psmouse) |
| 531 | { |
| 532 | struct alps_data *priv = psmouse->private; |
| 533 | unsigned char buf[6]; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 534 | bool poll_failed; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 535 | |
| 536 | if (priv->i->flags & ALPS_PASS) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 537 | alps_passthrough_mode(psmouse, true); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 538 | |
| 539 | poll_failed = ps2_command(&psmouse->ps2dev, buf, |
| 540 | PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; |
| 541 | |
| 542 | if (priv->i->flags & ALPS_PASS) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 543 | alps_passthrough_mode(psmouse, false); |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 544 | |
| 545 | if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) |
| 546 | return -1; |
| 547 | |
| 548 | if ((psmouse->badbyte & 0xc8) == 0x08) { |
| 549 | /* |
| 550 | * Poll the track stick ... |
| 551 | */ |
| 552 | if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) |
| 553 | return -1; |
| 554 | } |
| 555 | |
| 556 | memcpy(psmouse->packet, buf, sizeof(buf)); |
| 557 | return 0; |
| 558 | } |
| 559 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 560 | static int alps_hw_init(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
| 562 | struct alps_data *priv = psmouse->private; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 563 | const struct alps_model_info *model = priv->i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 565 | if ((model->flags & ALPS_PASS) && |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 566 | alps_passthrough_mode(psmouse, true)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 568 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 570 | if (alps_tap_mode(psmouse, true)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 571 | psmouse_warn(psmouse, "Failed to enable hardware tapping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return -1; |
Peter Osterlund | 963f626 | 2005-07-11 01:08:04 -0500 | [diff] [blame] | 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | if (alps_absolute_mode(psmouse)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 576 | psmouse_err(psmouse, "Failed to enable absolute mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return -1; |
| 578 | } |
| 579 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 580 | if ((model->flags & ALPS_PASS) && |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 581 | alps_passthrough_mode(psmouse, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | return -1; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 583 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 585 | /* ALPS needs stream mode, otherwise it won't report any data */ |
| 586 | if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM)) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 587 | psmouse_err(psmouse, "Failed to enable stream mode\n"); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 588 | return -1; |
| 589 | } |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static int alps_reconnect(struct psmouse *psmouse) |
| 595 | { |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 596 | const struct alps_model_info *model; |
| 597 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 598 | psmouse_reset(psmouse); |
| 599 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 600 | model = alps_get_model(psmouse, NULL); |
| 601 | if (!model) |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 602 | return -1; |
| 603 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 604 | return alps_hw_init(psmouse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void alps_disconnect(struct psmouse *psmouse) |
| 608 | { |
| 609 | struct alps_data *priv = psmouse->private; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | psmouse_reset(psmouse); |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 612 | del_timer_sync(&priv->timer); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 613 | input_unregister_device(priv->dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | kfree(priv); |
| 615 | } |
| 616 | |
| 617 | int alps_init(struct psmouse *psmouse) |
| 618 | { |
| 619 | struct alps_data *priv; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 620 | const struct alps_model_info *model; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 621 | struct input_dev *dev1 = psmouse->dev, *dev2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | int version; |
| 623 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 624 | priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 625 | dev2 = input_allocate_device(); |
| 626 | if (!priv || !dev2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | goto init_fail; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 628 | |
| 629 | priv->dev2 = dev2; |
Sebastian Kapfer | 1d9f262 | 2009-12-15 08:39:50 -0800 | [diff] [blame] | 630 | setup_timer(&priv->timer, alps_flush_packet, (unsigned long)psmouse); |
| 631 | |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 632 | psmouse->private = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 634 | model = alps_get_model(psmouse, &version); |
| 635 | if (!model) |
| 636 | goto init_fail; |
| 637 | |
| 638 | priv->i = model; |
| 639 | |
| 640 | if (alps_hw_init(psmouse)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | goto init_fail; |
| 642 | |
Dmitry Torokhov | 7105d2e | 2009-12-11 23:54:54 -0800 | [diff] [blame] | 643 | /* |
| 644 | * Undo part of setup done for us by psmouse core since touchpad |
| 645 | * is not a relative device. |
| 646 | */ |
| 647 | __clear_bit(EV_REL, dev1->evbit); |
| 648 | __clear_bit(REL_X, dev1->relbit); |
| 649 | __clear_bit(REL_Y, dev1->relbit); |
| 650 | |
| 651 | /* |
| 652 | * Now set up our capabilities. |
| 653 | */ |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 654 | dev1->evbit[BIT_WORD(EV_KEY)] |= BIT_MASK(EV_KEY); |
| 655 | dev1->keybit[BIT_WORD(BTN_TOUCH)] |= BIT_MASK(BTN_TOUCH); |
| 656 | dev1->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 657 | dev1->keybit[BIT_WORD(BTN_LEFT)] |= |
| 658 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 660 | dev1->evbit[BIT_WORD(EV_ABS)] |= BIT_MASK(EV_ABS); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 661 | input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0); |
| 662 | input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0); |
| 663 | input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 665 | if (model->flags & ALPS_WHEEL) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 666 | dev1->evbit[BIT_WORD(EV_REL)] |= BIT_MASK(EV_REL); |
| 667 | dev1->relbit[BIT_WORD(REL_WHEEL)] |= BIT_MASK(REL_WHEEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 670 | if (model->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 671 | dev1->keybit[BIT_WORD(BTN_FORWARD)] |= BIT_MASK(BTN_FORWARD); |
| 672 | dev1->keybit[BIT_WORD(BTN_BACK)] |= BIT_MASK(BTN_BACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 675 | if (model->flags & ALPS_FOUR_BUTTONS) { |
| 676 | dev1->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0); |
| 677 | dev1->keybit[BIT_WORD(BTN_1)] |= BIT_MASK(BTN_1); |
| 678 | dev1->keybit[BIT_WORD(BTN_2)] |= BIT_MASK(BTN_2); |
| 679 | dev1->keybit[BIT_WORD(BTN_3)] |= BIT_MASK(BTN_3); |
| 680 | } else { |
| 681 | dev1->keybit[BIT_WORD(BTN_MIDDLE)] |= BIT_MASK(BTN_MIDDLE); |
| 682 | } |
| 683 | |
Dmitry Torokhov | 08ffce4 | 2006-06-26 01:45:10 -0400 | [diff] [blame] | 684 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 685 | dev2->phys = priv->phys; |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 686 | dev2->name = (model->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 687 | dev2->id.bustype = BUS_I8042; |
| 688 | dev2->id.vendor = 0x0002; |
| 689 | dev2->id.product = PSMOUSE_ALPS; |
| 690 | dev2->id.version = 0x0000; |
Dmitry Torokhov | 1db3a34 | 2008-03-18 00:29:18 -0400 | [diff] [blame] | 691 | dev2->dev.parent = &psmouse->ps2dev.serio->dev; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 692 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 693 | dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
Maxim Levitsky | 71bb21b | 2009-11-16 22:12:22 -0800 | [diff] [blame] | 694 | dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
| 695 | dev2->keybit[BIT_WORD(BTN_LEFT)] = |
| 696 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 698 | if (input_register_device(priv->dev2)) |
| 699 | goto init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | psmouse->protocol_handler = alps_process_byte; |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 702 | psmouse->poll = alps_poll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | psmouse->disconnect = alps_disconnect; |
| 704 | psmouse->reconnect = alps_reconnect; |
| 705 | psmouse->pktsize = 6; |
| 706 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 707 | /* We are having trouble resyncing ALPS touchpads so disable it for now */ |
| 708 | psmouse->resync_time = 0; |
| 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | return 0; |
| 711 | |
| 712 | init_fail: |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 713 | psmouse_reset(psmouse); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 714 | input_free_device(dev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | kfree(priv); |
Dmitry Torokhov | 1e0c5b1 | 2007-05-14 23:51:54 -0400 | [diff] [blame] | 716 | psmouse->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | return -1; |
| 718 | } |
| 719 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 720 | int alps_detect(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
| 722 | int version; |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 723 | const struct alps_model_info *model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Dmitry Torokhov | f42649e | 2007-04-12 01:31:13 -0400 | [diff] [blame] | 725 | model = alps_get_model(psmouse, &version); |
| 726 | if (!model) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | return -1; |
| 728 | |
| 729 | if (set_properties) { |
| 730 | psmouse->vendor = "ALPS"; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 731 | psmouse->name = model->flags & ALPS_DUALPOINT ? |
| 732 | "DualPoint TouchPad" : "GlidePoint"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | psmouse->model = version; |
| 734 | } |
| 735 | return 0; |
| 736 | } |
| 737 | |