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