2 * Logitech PS/2++ mouse driver
4 * Copyright (c) 1999-2003 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2003 Eric Wong <eric@yhbt.net>
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.
12 #include <linux/input.h>
13 #include <linux/serio.h>
15 #include "logips2pp.h"
18 * Process a PS2++ or PS2T++ packet.
21 void ps2pp_process_packet(struct psmouse *psmouse)
23 struct input_dev *dev = &psmouse->dev;
24 unsigned char *packet = psmouse->packet;
26 if ((packet[0] & 0x48) == 0x48 && (packet[1] & 0x02) == 0x02) {
28 switch ((packet[1] >> 4) | (packet[0] & 0x30)) {
30 case 0x0d: /* Mouse extra info */
32 input_report_rel(dev, packet[2] & 0x80 ? REL_HWHEEL : REL_WHEEL,
33 (int) (packet[2] & 8) - (int) (packet[2] & 7));
34 input_report_key(dev, BTN_SIDE, (packet[2] >> 4) & 1);
35 input_report_key(dev, BTN_EXTRA, (packet[2] >> 5) & 1);
39 case 0x0e: /* buttons 4, 5, 6, 7, 8, 9, 10 info */
41 input_report_key(dev, BTN_SIDE, (packet[2]) & 1);
42 input_report_key(dev, BTN_EXTRA, (packet[2] >> 1) & 1);
43 input_report_key(dev, BTN_BACK, (packet[2] >> 3) & 1);
44 input_report_key(dev, BTN_FORWARD, (packet[2] >> 4) & 1);
45 input_report_key(dev, BTN_TASK, (packet[2] >> 2) & 1);
49 case 0x0f: /* TouchPad extra info */
51 input_report_rel(dev, packet[2] & 0x08 ? REL_HWHEEL : REL_WHEEL,
52 (int) ((packet[2] >> 4) & 8) - (int) ((packet[2] >> 4) & 7));
53 packet[0] = packet[2] | 0x08;
58 printk(KERN_WARNING "psmouse.c: Received PS2++ packet #%x, but don't know how to handle.\n",
59 (packet[1] >> 4) | (packet[0] & 0x30));
71 * ps2pp_cmd() sends a PS2++ command, sliced into two bit
72 * pieces through the SETRES command. This is needed to send extended
73 * commands to mice on notebooks that try to understand the PS/2 protocol
77 static int ps2pp_cmd(struct psmouse *psmouse, unsigned char *param, unsigned char command)
82 if (psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11))
85 for (i = 6; i >= 0; i -= 2) {
86 d = (command >> i) & 3;
87 if(psmouse_command(psmouse, &d, PSMOUSE_CMD_SETRES))
91 if (psmouse_command(psmouse, param, PSMOUSE_CMD_POLL))
98 * SmartScroll / CruiseControl for some newer Logitech mice Defaults to
99 * enabled if we do nothing to it. Of course I put this in because I want it
101 * 1 - enabled (if previously disabled, also default)
105 static void ps2pp_set_smartscroll(struct psmouse *psmouse)
107 unsigned char param[4];
109 ps2pp_cmd(psmouse, param, 0x32);
112 psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
113 psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
114 psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
116 if (psmouse_smartscroll == 1)
119 if (psmouse_smartscroll > 2)
122 /* else leave param[0] == 0 to disable */
123 psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
127 * Support 800 dpi resolution _only_ if the user wants it (there are good
128 * reasons to not use it even if the mouse supports it, and of course there are
129 * also good reasons to use it, let the user decide).
132 void ps2pp_set_800dpi(struct psmouse *psmouse)
134 unsigned char param = 3;
135 psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11);
136 psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11);
137 psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11);
138 psmouse_command(psmouse, ¶m, PSMOUSE_CMD_SETRES);
142 * Detect the exact model and features of a PS2++ or PS2T++ Logitech mouse or
146 static int ps2pp_detect_model(struct psmouse *psmouse, unsigned char *param)
149 static struct _logips2_list {
151 unsigned const int features;
152 } logips2pp_list [] = {
161 { 52, PS2PP_4BTN | PS2PP_WHEEL },
163 { 61, PS2PP_WHEEL | PS2PP_MX }, /* MX700 */
167 { 80, PS2PP_4BTN | PS2PP_WHEEL },
173 { 100 , PS2PP_WHEEL | PS2PP_MX }, /* MX510 */
174 { 112 , PS2PP_WHEEL | PS2PP_MX }, /* MX500 */
175 { 114 , PS2PP_WHEEL | PS2PP_MX | PS2PP_MX310 }, /* MX310 */
179 psmouse->vendor = "Logitech";
180 psmouse->model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78);
183 clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
185 clear_bit(BTN_RIGHT, psmouse->dev.keybit);
187 psmouse->type = PSMOUSE_PS2;
189 for (i = 0; logips2pp_list[i].model; i++){
190 if (logips2pp_list[i].model == psmouse->model){
191 psmouse->type = PSMOUSE_PS2PP;
192 if (logips2pp_list[i].features & PS2PP_4BTN)
193 set_bit(BTN_SIDE, psmouse->dev.keybit);
195 if (logips2pp_list[i].features & PS2PP_WHEEL){
196 set_bit(REL_WHEEL, psmouse->dev.relbit);
197 psmouse->name = "Wheel Mouse";
199 if (logips2pp_list[i].features & PS2PP_MX) {
200 set_bit(BTN_SIDE, psmouse->dev.keybit);
201 set_bit(BTN_EXTRA, psmouse->dev.keybit);
202 set_bit(BTN_TASK, psmouse->dev.keybit);
203 if (!(logips2pp_list[i].features & PS2PP_MX310)){
204 set_bit(BTN_BACK, psmouse->dev.keybit);
205 set_bit(BTN_FORWARD, psmouse->dev.keybit);
207 psmouse->name = "MX Mouse";
213 * Do Logitech PS2++ / PS2T++ magic init.
215 if (psmouse->type == PSMOUSE_PS2PP) {
217 if (psmouse->model == 97) { /* TouchPad 3 */
219 set_bit(REL_WHEEL, psmouse->dev.relbit);
220 set_bit(REL_HWHEEL, psmouse->dev.relbit);
222 param[0] = 0x11; param[1] = 0x04; param[2] = 0x68; /* Unprotect RAM */
223 psmouse_command(psmouse, param, 0x30d1);
224 param[0] = 0x11; param[1] = 0x05; param[2] = 0x0b; /* Enable features */
225 psmouse_command(psmouse, param, 0x30d1);
226 param[0] = 0x11; param[1] = 0x09; param[2] = 0xc3; /* Enable PS2++ */
227 psmouse_command(psmouse, param, 0x30d1);
230 if (!psmouse_command(psmouse, param, 0x13d1) &&
231 param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) {
232 psmouse->name = "TouchPad 3";
233 return PSMOUSE_PS2TPP;
238 param[0] = param[1] = param[2] = 0;
239 ps2pp_cmd(psmouse, param, 0x39); /* Magic knock */
240 ps2pp_cmd(psmouse, param, 0xDB);
242 if ((param[0] & 0x78) == 0x48 && (param[1] & 0xf3) == 0xc2 &&
243 (param[2] & 3) == ((param[1] >> 2) & 3)) {
244 ps2pp_set_smartscroll(psmouse);
245 return PSMOUSE_PS2PP;
254 * Logitech magic init.
256 int ps2pp_detect(struct psmouse *psmouse)
258 unsigned char param[4];
261 psmouse_command(psmouse, param, PSMOUSE_CMD_SETRES);
262 psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11);
263 psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11);
264 psmouse_command(psmouse, NULL, PSMOUSE_CMD_SETSCALE11);
266 psmouse_command(psmouse, param, PSMOUSE_CMD_GETINFO);
268 return param[1] != 0 ? ps2pp_detect_model(psmouse, param) : 0;