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