Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Logitech PS/2++ mouse driver |
| 3 | * |
| 4 | * Copyright (c) 1999-2003 Vojtech Pavlik <vojtech@suse.cz> |
| 5 | * Copyright (c) 2003 Eric Wong <eric@yhbt.net> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/input.h> |
| 13 | #include <linux/serio.h> |
| 14 | #include <linux/libps2.h> |
| 15 | #include "psmouse.h" |
| 16 | #include "logips2pp.h" |
| 17 | |
| 18 | /* Logitech mouse types */ |
| 19 | #define PS2PP_KIND_WHEEL 1 |
| 20 | #define PS2PP_KIND_MX 2 |
| 21 | #define PS2PP_KIND_TP3 3 |
Zbigniew Luszpinski | 4f8b05e | 2006-05-29 23:29:19 -0400 | [diff] [blame] | 22 | #define PS2PP_KIND_TRACKMAN 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /* Logitech mouse features */ |
| 25 | #define PS2PP_WHEEL 0x01 |
| 26 | #define PS2PP_HWHEEL 0x02 |
| 27 | #define PS2PP_SIDE_BTN 0x04 |
| 28 | #define PS2PP_EXTRA_BTN 0x08 |
| 29 | #define PS2PP_TASK_BTN 0x10 |
| 30 | #define PS2PP_NAV_BTN 0x20 |
| 31 | |
| 32 | struct ps2pp_info { |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 33 | u8 model; |
| 34 | u8 kind; |
| 35 | u16 features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * Process a PS2++ or PS2T++ packet. |
| 40 | */ |
| 41 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 42 | static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 44 | struct input_dev *dev = psmouse->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | unsigned char *packet = psmouse->packet; |
| 46 | |
| 47 | if (psmouse->pktcnt < 3) |
| 48 | return PSMOUSE_GOOD_DATA; |
| 49 | |
| 50 | /* |
| 51 | * Full packet accumulated, process it |
| 52 | */ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if ((packet[0] & 0x48) == 0x48 && (packet[1] & 0x02) == 0x02) { |
| 55 | |
| 56 | /* Logitech extended packet */ |
| 57 | switch ((packet[1] >> 4) | (packet[0] & 0x30)) { |
| 58 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 59 | case 0x0d: /* Mouse extra info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 61 | input_report_rel(dev, packet[2] & 0x80 ? REL_HWHEEL : REL_WHEEL, |
| 62 | (int) (packet[2] & 8) - (int) (packet[2] & 7)); |
| 63 | input_report_key(dev, BTN_SIDE, (packet[2] >> 4) & 1); |
| 64 | input_report_key(dev, BTN_EXTRA, (packet[2] >> 5) & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 66 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 68 | case 0x0e: /* buttons 4, 5, 6, 7, 8, 9, 10 info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 70 | input_report_key(dev, BTN_SIDE, (packet[2]) & 1); |
| 71 | input_report_key(dev, BTN_EXTRA, (packet[2] >> 1) & 1); |
| 72 | input_report_key(dev, BTN_BACK, (packet[2] >> 3) & 1); |
| 73 | input_report_key(dev, BTN_FORWARD, (packet[2] >> 4) & 1); |
| 74 | input_report_key(dev, BTN_TASK, (packet[2] >> 2) & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 76 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 78 | case 0x0f: /* TouchPad extra info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 80 | input_report_rel(dev, packet[2] & 0x08 ? REL_HWHEEL : REL_WHEEL, |
| 81 | (int) ((packet[2] >> 4) & 8) - (int) ((packet[2] >> 4) & 7)); |
| 82 | packet[0] = packet[2] | 0x08; |
| 83 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 85 | default: |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 86 | psmouse_dbg(psmouse, |
| 87 | "Received PS2++ packet #%x, but don't know how to handle.\n", |
| 88 | (packet[1] >> 4) | (packet[0] & 0x30)); |
| 89 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | } else { |
| 92 | /* Standard PS/2 motion data */ |
| 93 | input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); |
| 94 | input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); |
| 95 | } |
| 96 | |
| 97 | input_report_key(dev, BTN_LEFT, packet[0] & 1); |
| 98 | input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); |
| 99 | input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); |
| 100 | |
| 101 | input_sync(dev); |
| 102 | |
| 103 | return PSMOUSE_FULL_PACKET; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * ps2pp_cmd() sends a PS2++ command, sliced into two bit |
| 109 | * pieces through the SETRES command. This is needed to send extended |
| 110 | * commands to mice on notebooks that try to understand the PS/2 protocol |
| 111 | * Ugly. |
| 112 | */ |
| 113 | |
| 114 | static int ps2pp_cmd(struct psmouse *psmouse, unsigned char *param, unsigned char command) |
| 115 | { |
| 116 | if (psmouse_sliced_command(psmouse, command)) |
| 117 | return -1; |
| 118 | |
Dmitry Torokhov | f0d5c6f4 | 2006-01-14 00:27:37 -0500 | [diff] [blame] | 119 | if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL | 0x0300)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return -1; |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * SmartScroll / CruiseControl for some newer Logitech mice Defaults to |
| 127 | * enabled if we do nothing to it. Of course I put this in because I want it |
| 128 | * disabled :P |
| 129 | * 1 - enabled (if previously disabled, also default) |
| 130 | * 0 - disabled |
| 131 | */ |
| 132 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 133 | static void ps2pp_set_smartscroll(struct psmouse *psmouse, bool smartscroll) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 136 | unsigned char param[4]; |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | ps2pp_cmd(psmouse, param, 0x32); |
| 139 | |
| 140 | param[0] = 0; |
| 141 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 142 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 143 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 144 | |
| 145 | param[0] = smartscroll; |
| 146 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 147 | } |
| 148 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 149 | static ssize_t ps2pp_attr_show_smartscroll(struct psmouse *psmouse, |
| 150 | void *data, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 152 | return sprintf(buf, "%d\n", psmouse->smartscroll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 155 | static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, |
| 156 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
JJ Ding | 76496e7 | 2011-11-09 10:20:14 -0800 | [diff] [blame^] | 158 | unsigned int value; |
| 159 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
JJ Ding | 76496e7 | 2011-11-09 10:20:14 -0800 | [diff] [blame^] | 161 | err = kstrtouint(buf, 10, &value); |
| 162 | if (err) |
| 163 | return err; |
| 164 | |
| 165 | if (value > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return -EINVAL; |
| 167 | |
| 168 | ps2pp_set_smartscroll(psmouse, value); |
| 169 | psmouse->smartscroll = value; |
| 170 | return count; |
| 171 | } |
| 172 | |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 173 | PSMOUSE_DEFINE_ATTR(smartscroll, S_IWUSR | S_IRUGO, NULL, |
| 174 | ps2pp_attr_show_smartscroll, ps2pp_attr_set_smartscroll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * Support 800 dpi resolution _only_ if the user wants it (there are good |
| 178 | * reasons to not use it even if the mouse supports it, and of course there are |
| 179 | * also good reasons to use it, let the user decide). |
| 180 | */ |
| 181 | |
| 182 | static void ps2pp_set_resolution(struct psmouse *psmouse, unsigned int resolution) |
| 183 | { |
| 184 | if (resolution > 400) { |
| 185 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 186 | unsigned char param = 3; |
| 187 | |
| 188 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 189 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 190 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 191 | ps2_command(ps2dev, ¶m, PSMOUSE_CMD_SETRES); |
| 192 | psmouse->resolution = 800; |
| 193 | } else |
| 194 | psmouse_set_resolution(psmouse, resolution); |
| 195 | } |
| 196 | |
| 197 | static void ps2pp_disconnect(struct psmouse *psmouse) |
| 198 | { |
Dmitry Torokhov | cfe9e88 | 2005-09-04 01:40:20 -0500 | [diff] [blame] | 199 | device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll.dattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 202 | static const struct ps2pp_info *get_model_info(unsigned char model) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 204 | static const struct ps2pp_info ps2pp_list[] = { |
Dmitry Torokhov | 21298f7 | 2007-04-12 01:33:19 -0400 | [diff] [blame] | 205 | { 1, 0, 0 }, /* Simple 2-button mouse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { 12, 0, PS2PP_SIDE_BTN}, |
| 207 | { 13, 0, 0 }, |
| 208 | { 15, PS2PP_KIND_MX, /* MX1000 */ |
| 209 | PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | |
| 210 | PS2PP_EXTRA_BTN | PS2PP_NAV_BTN | PS2PP_HWHEEL }, |
| 211 | { 40, 0, PS2PP_SIDE_BTN }, |
| 212 | { 41, 0, PS2PP_SIDE_BTN }, |
| 213 | { 42, 0, PS2PP_SIDE_BTN }, |
| 214 | { 43, 0, PS2PP_SIDE_BTN }, |
| 215 | { 50, 0, 0 }, |
| 216 | { 51, 0, 0 }, |
| 217 | { 52, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, |
| 218 | { 53, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 219 | { 56, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, /* Cordless MouseMan Wheel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { 61, PS2PP_KIND_MX, /* MX700 */ |
| 221 | PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | |
| 222 | PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, |
Mirco Macrelli | 14a48b4 | 2005-11-02 22:52:45 -0500 | [diff] [blame] | 223 | { 66, PS2PP_KIND_MX, /* MX3100 reciver */ |
| 224 | PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | |
| 225 | PS2PP_EXTRA_BTN | PS2PP_NAV_BTN | PS2PP_HWHEEL }, |
Peter Samuelson | 18cc675 | 2007-05-08 23:34:18 -0400 | [diff] [blame] | 226 | { 72, PS2PP_KIND_TRACKMAN, 0 }, /* T-CH11: TrackMan Marble */ |
Dmitry Torokhov | 4f7802d | 2009-10-15 09:46:48 -0700 | [diff] [blame] | 227 | { 73, PS2PP_KIND_TRACKMAN, PS2PP_SIDE_BTN }, /* TrackMan FX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { 75, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
| 229 | { 76, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Zbigniew Luszpinski | 4f8b05e | 2006-05-29 23:29:19 -0400 | [diff] [blame] | 230 | { 79, PS2PP_KIND_TRACKMAN, PS2PP_WHEEL }, /* TrackMan with wheel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { 80, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, |
| 232 | { 81, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
| 233 | { 83, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Jasper Spaans | 58057b9 | 2005-12-11 12:41:22 -0500 | [diff] [blame] | 234 | { 85, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Vojtech Pavlik | d2b5ffc | 2005-09-04 01:40:55 -0500 | [diff] [blame] | 235 | { 86, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Dmitry Torokhov | 8ea3694 | 2005-12-21 01:02:54 -0500 | [diff] [blame] | 236 | { 87, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { 88, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
| 238 | { 96, 0, 0 }, |
| 239 | { 97, PS2PP_KIND_TP3, PS2PP_WHEEL | PS2PP_HWHEEL }, |
Meelis Roos | 50f6dde | 2006-02-15 00:48:58 -0500 | [diff] [blame] | 240 | { 99, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { 100, PS2PP_KIND_MX, /* MX510 */ |
| 242 | PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | |
| 243 | PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, |
Roberto Castagnola | 0c19fcd8 | 2006-08-04 22:52:13 -0400 | [diff] [blame] | 244 | { 111, PS2PP_KIND_MX, PS2PP_WHEEL | PS2PP_SIDE_BTN }, /* MX300 reports task button as side */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { 112, PS2PP_KIND_MX, /* MX500 */ |
| 246 | PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | |
| 247 | PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, |
| 248 | { 114, PS2PP_KIND_MX, /* MX310 */ |
| 249 | PS2PP_WHEEL | PS2PP_SIDE_BTN | |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 250 | PS2PP_TASK_BTN | PS2PP_EXTRA_BTN } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | }; |
| 252 | int i; |
| 253 | |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 254 | for (i = 0; i < ARRAY_SIZE(ps2pp_list); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (model == ps2pp_list[i].model) |
| 256 | return &ps2pp_list[i]; |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | return NULL; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Set up input device's properties based on the detected mouse model. |
| 263 | */ |
| 264 | |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 265 | static void ps2pp_set_model_properties(struct psmouse *psmouse, |
| 266 | const struct ps2pp_info *model_info, |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 267 | bool using_ps2pp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 269 | struct input_dev *input_dev = psmouse->dev; |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | if (model_info->features & PS2PP_SIDE_BTN) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 272 | __set_bit(BTN_SIDE, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | if (model_info->features & PS2PP_EXTRA_BTN) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 275 | __set_bit(BTN_EXTRA, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | if (model_info->features & PS2PP_TASK_BTN) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 278 | __set_bit(BTN_TASK, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | if (model_info->features & PS2PP_NAV_BTN) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 281 | __set_bit(BTN_FORWARD, input_dev->keybit); |
| 282 | __set_bit(BTN_BACK, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | if (model_info->features & PS2PP_WHEEL) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 286 | __set_bit(REL_WHEEL, input_dev->relbit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (model_info->features & PS2PP_HWHEEL) |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 289 | __set_bit(REL_HWHEEL, input_dev->relbit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | switch (model_info->kind) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 293 | case PS2PP_KIND_WHEEL: |
| 294 | psmouse->name = "Wheel Mouse"; |
| 295 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 297 | case PS2PP_KIND_MX: |
| 298 | psmouse->name = "MX Mouse"; |
| 299 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 301 | case PS2PP_KIND_TP3: |
| 302 | psmouse->name = "TouchPad 3"; |
| 303 | break; |
Zbigniew Luszpinski | 4f8b05e | 2006-05-29 23:29:19 -0400 | [diff] [blame] | 304 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 305 | case PS2PP_KIND_TRACKMAN: |
| 306 | psmouse->name = "TrackMan"; |
| 307 | break; |
| 308 | |
| 309 | default: |
| 310 | /* |
| 311 | * Set name to "Mouse" only when using PS2++, |
| 312 | * otherwise let other protocols define suitable |
| 313 | * name |
| 314 | */ |
| 315 | if (using_ps2pp) |
| 316 | psmouse->name = "Mouse"; |
| 317 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | |
| 322 | /* |
| 323 | * Logitech magic init. Detect whether the mouse is a Logitech one |
| 324 | * and its exact model and try turning on extended protocol for ones |
| 325 | * that support it. |
| 326 | */ |
| 327 | |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 328 | int ps2pp_init(struct psmouse *psmouse, bool set_properties) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
| 330 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 331 | unsigned char param[4]; |
| 332 | unsigned char model, buttons; |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 333 | const struct ps2pp_info *model_info; |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 334 | bool use_ps2pp = false; |
Jeff Garzik | 0fea0e9 | 2006-11-02 23:59:40 -0500 | [diff] [blame] | 335 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | param[0] = 0; |
| 338 | ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); |
| 339 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 340 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 341 | ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); |
| 342 | param[1] = 0; |
| 343 | ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); |
| 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78); |
| 346 | buttons = param[1]; |
| 347 | |
Dmitry Torokhov | 688897b | 2007-04-12 01:32:22 -0400 | [diff] [blame] | 348 | if (!model || !buttons) |
| 349 | return -1; |
| 350 | |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 351 | model_info = get_model_info(model); |
| 352 | if (model_info) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * Do Logitech PS2++ / PS2T++ magic init. |
| 356 | */ |
Helge Deller | e3882bb | 2006-08-08 23:37:18 -0400 | [diff] [blame] | 357 | if (model_info->kind == PS2PP_KIND_TP3) { /* Touch Pad 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | /* Unprotect RAM */ |
| 360 | param[0] = 0x11; param[1] = 0x04; param[2] = 0x68; |
| 361 | ps2_command(ps2dev, param, 0x30d1); |
| 362 | /* Enable features */ |
| 363 | param[0] = 0x11; param[1] = 0x05; param[2] = 0x0b; |
| 364 | ps2_command(ps2dev, param, 0x30d1); |
| 365 | /* Enable PS2++ */ |
| 366 | param[0] = 0x11; param[1] = 0x09; param[2] = 0xc3; |
| 367 | ps2_command(ps2dev, param, 0x30d1); |
| 368 | |
| 369 | param[0] = 0; |
| 370 | if (!ps2_command(ps2dev, param, 0x13d1) && |
| 371 | param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 372 | use_ps2pp = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | } else { |
| 376 | |
| 377 | param[0] = param[1] = param[2] = 0; |
| 378 | ps2pp_cmd(psmouse, param, 0x39); /* Magic knock */ |
| 379 | ps2pp_cmd(psmouse, param, 0xDB); |
| 380 | |
| 381 | if ((param[0] & 0x78) == 0x48 && |
| 382 | (param[1] & 0xf3) == 0xc2 && |
| 383 | (param[2] & 0x03) == ((param[1] >> 2) & 3)) { |
Dmitry Torokhov | b7802c5 | 2009-09-09 19:13:20 -0700 | [diff] [blame] | 384 | ps2pp_set_smartscroll(psmouse, false); |
| 385 | use_ps2pp = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
Dmitry Torokhov | a62f0d2 | 2010-05-19 10:39:17 -0700 | [diff] [blame] | 388 | |
| 389 | } else { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 390 | psmouse_warn(psmouse, "Detected unknown Logitech mouse model %d\n", model); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | if (set_properties) { |
| 394 | psmouse->vendor = "Logitech"; |
| 395 | psmouse->model = model; |
| 396 | |
| 397 | if (use_ps2pp) { |
| 398 | psmouse->protocol_handler = ps2pp_process_byte; |
| 399 | psmouse->pktsize = 3; |
| 400 | |
| 401 | if (model_info->kind != PS2PP_KIND_TP3) { |
| 402 | psmouse->set_resolution = ps2pp_set_resolution; |
| 403 | psmouse->disconnect = ps2pp_disconnect; |
| 404 | |
Jeff Garzik | 0fea0e9 | 2006-11-02 23:59:40 -0500 | [diff] [blame] | 405 | error = device_create_file(&psmouse->ps2dev.serio->dev, |
| 406 | &psmouse_attr_smartscroll.dattr); |
| 407 | if (error) { |
Dmitry Torokhov | b5d2170 | 2011-10-10 18:27:03 -0700 | [diff] [blame] | 408 | psmouse_err(psmouse, |
| 409 | "failed to create smartscroll sysfs attribute, error: %d\n", |
| 410 | error); |
Jeff Garzik | 0fea0e9 | 2006-11-02 23:59:40 -0500 | [diff] [blame] | 411 | return -1; |
| 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
Dmitry Torokhov | 315eb99 | 2009-11-16 22:12:21 -0800 | [diff] [blame] | 416 | if (buttons >= 3) |
| 417 | __set_bit(BTN_MIDDLE, psmouse->dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | if (model_info) |
| 420 | ps2pp_set_model_properties(psmouse, model_info, use_ps2pp); |
| 421 | } |
| 422 | |
| 423 | return use_ps2pp ? 0 : -1; |
| 424 | } |
| 425 | |