aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/input/mouse
downloadkernel_samsung_tuna-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.zip
kernel_samsung_tuna-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.gz
kernel_samsung_tuna-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.bz2
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/input/mouse')
-rw-r--r--drivers/input/mouse/Kconfig138
-rw-r--r--drivers/input/mouse/Makefile18
-rw-r--r--drivers/input/mouse/alps.c477
-rw-r--r--drivers/input/mouse/alps.h32
-rw-r--r--drivers/input/mouse/amimouse.c137
-rw-r--r--drivers/input/mouse/hil_ptr.c414
-rw-r--r--drivers/input/mouse/inport.c196
-rw-r--r--drivers/input/mouse/logibm.c183
-rw-r--r--drivers/input/mouse/logips2pp.c397
-rw-r--r--drivers/input/mouse/logips2pp.h16
-rw-r--r--drivers/input/mouse/maplemouse.c134
-rw-r--r--drivers/input/mouse/pc110pad.c178
-rw-r--r--drivers/input/mouse/psmouse-base.c1011
-rw-r--r--drivers/input/mouse/psmouse.h106
-rw-r--r--drivers/input/mouse/rpcmouse.c107
-rw-r--r--drivers/input/mouse/sermouse.c370
-rw-r--r--drivers/input/mouse/synaptics.c700
-rw-r--r--drivers/input/mouse/synaptics.h110
-rw-r--r--drivers/input/mouse/vsxxxaa.c591
19 files changed, 5315 insertions, 0 deletions
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
new file mode 100644
index 0000000..537154d
--- /dev/null
+++ b/drivers/input/mouse/Kconfig
@@ -0,0 +1,138 @@
+#
+# Mouse driver configuration
+#
+menuconfig INPUT_MOUSE
+ bool "Mouse"
+ default y
+ help
+ Say Y here, and a list of supported mice will be displayed.
+ This option doesn't affect the kernel.
+
+ If unsure, say Y.
+
+if INPUT_MOUSE
+
+config MOUSE_PS2
+ tristate "PS/2 mouse"
+ default y
+ select SERIO
+ select SERIO_LIBPS2
+ select SERIO_I8042 if PC
+ select SERIO_GSCPS2 if GSC
+ ---help---
+ Say Y here if you have a PS/2 mouse connected to your system. This
+ includes the standard 2 or 3-button PS/2 mouse, as well as PS/2
+ mice with wheels and extra buttons, Microsoft, Logitech or Genius
+ compatible.
+
+ Synaptics TouchPad users might be interested in a specialized
+ XFree86 driver at:
+ <http://w1.894.telia.com/~u89404340/touchpad/index.html>
+ and a new version of GPM at:
+ <http://www.geocities.com/dt_or/gpm/gpm.html>
+ to take advantage of the advanced features of the touchpad.
+
+ If unsure, say Y.
+
+ To compile this driver as a module, choose M here: the
+ module will be called psmouse.
+
+config MOUSE_SERIAL
+ tristate "Serial mouse"
+ select SERIO
+ ---help---
+ Say Y here if you have a serial (RS-232, COM port) mouse connected
+ to your system. This includes Sun, MouseSystems, Microsoft,
+ Logitech and all other compatible serial mice.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called sermouse.
+
+config MOUSE_INPORT
+ tristate "InPort/MS/ATIXL busmouse"
+ depends on ISA
+ help
+ Say Y here if you have an InPort, Microsoft or ATI XL busmouse.
+ They are rather rare these days.
+
+ To compile this driver as a module, choose M here: the
+ module will be called inport.
+
+config MOUSE_ATIXL
+ bool "ATI XL variant"
+ depends on MOUSE_INPORT
+ help
+ Say Y here if your mouse is of the ATI XL variety.
+
+config MOUSE_LOGIBM
+ tristate "Logitech busmouse"
+ depends on ISA
+ help
+ Say Y here if you have a Logitech busmouse.
+ They are rather rare these days.
+
+ To compile this driver as a module, choose M here: the
+ module will be called logibm.
+
+config MOUSE_PC110PAD
+ tristate "IBM PC110 touchpad"
+ depends on ISA
+ help
+ Say Y if you have the IBM PC-110 micro-notebook and want its
+ touchpad supported.
+
+ To compile this driver as a module, choose M here: the
+ module will be called pc110pad.
+
+config MOUSE_MAPLE
+ tristate "Maple bus mouse"
+ depends on SH_DREAMCAST && MAPLE
+ help
+ Say Y if you have a DreamCast console and a mouse attached to
+ its Maple bus.
+
+ To compile this driver as a module, choose M here: the
+ module will be called maplemouse.
+
+config MOUSE_AMIGA
+ tristate "Amiga mouse"
+ depends on AMIGA
+ help
+ Say Y here if you have an Amiga and want its native mouse
+ supported by the kernel.
+
+ To compile this driver as a module, choose M here: the
+ module will be called amimouse.
+
+config MOUSE_RISCPC
+ tristate "Acorn RiscPC mouse"
+ depends on ARCH_ACORN
+ help
+ Say Y here if you have the Acorn RiscPC computer and want its
+ native mouse supported.
+
+ To compile this driver as a module, choose M here: the
+ module will be called rpcmouse.
+
+config MOUSE_VSXXXAA
+ tristate "DEC VSXXX-AA/GA mouse and VSXXX-AB tablet"
+ select SERIO
+ help
+ Say Y (or M) if you want to use a DEC VSXXX-AA (hockey
+ puck) or a VSXXX-GA (rectangular) mouse. Theses mice are
+ typically used on DECstations or VAXstations, but can also
+ be used on any box capable of RS232 (with some adaptor
+ described in the source file). This driver also works with the
+ digitizer (VSXXX-AB) DEC produced.
+
+config MOUSE_HIL
+ tristate "HIL pointers (mice etc)."
+ depends on GSC
+ select HP_SDC
+ select HIL_MLC
+ help
+ Say Y here to support HIL pointers.
+
+endif
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
new file mode 100644
index 0000000..a786419
--- /dev/null
+++ b/drivers/input/mouse/Makefile
@@ -0,0 +1,18 @@
+#
+# Makefile for the mouse drivers.
+#
+
+# Each configuration option enables a list of files.
+
+obj-$(CONFIG_MOUSE_AMIGA) += amimouse.o
+obj-$(CONFIG_MOUSE_RISCPC) += rpcmouse.o
+obj-$(CONFIG_MOUSE_INPORT) += inport.o
+obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
+obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o
+obj-$(CONFIG_MOUSE_PC110PAD) += pc110pad.o
+obj-$(CONFIG_MOUSE_PS2) += psmouse.o
+obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
+obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
+obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
+
+psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
new file mode 100644
index 0000000..1f85a97
--- /dev/null
+++ b/drivers/input/mouse/alps.c
@@ -0,0 +1,477 @@
+/*
+ * ALPS touchpad PS/2 mouse driver
+ *
+ * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
+ * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
+ * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
+ * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
+ *
+ * ALPS detection, tap switching and status querying info is taken from
+ * tpconfig utility (by C. Scott Ananian and Bruce Kall).
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/input.h>
+#include <linux/serio.h>
+#include <linux/libps2.h>
+
+#include "psmouse.h"
+#include "alps.h"
+
+#undef DEBUG
+#ifdef DEBUG
+#define dbg(format, arg...) printk(KERN_INFO "alps.c: " format "\n", ## arg)
+#else
+#define dbg(format, arg...) do {} while (0)
+#endif
+
+#define ALPS_DUALPOINT 0x01
+#define ALPS_WHEEL 0x02
+#define ALPS_FW_BK 0x04
+#define ALPS_4BTN 0x08
+#define ALPS_OLDPROTO 0x10
+#define ALPS_PASS 0x20
+
+static struct alps_model_info alps_model_data[] = {
+ { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
+ { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
+ { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
+ { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
+ { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
+ { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, 0 },
+ { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
+ { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK }, /* NEC Versa L320 */
+ { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
+ { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS }, /* Dell Latitude D800 */
+ { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
+ { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
+ { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
+ { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
+ { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
+};
+
+/*
+ * XXX - this entry is suspicious. First byte has zero lower nibble,
+ * which is what a normal mouse would report. Also, the value 0x0e
+ * isn't valid per PS/2 spec.
+ */
+
+/*
+ * ALPS abolute Mode - new format
+ *
+ * byte 0: 1 ? ? ? 1 ? ? ?
+ * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
+ * byte 2: 0 x10 x9 x8 x7 ? fin ges
+ * byte 3: 0 y9 y8 y7 1 M R L
+ * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
+ * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
+ *
+ * ?'s can have different meanings on different models,
+ * such as wheel rotation, extra buttons, stick buttons
+ * on a dualpoint, etc.
+ */
+
+static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
+{
+ struct alps_data *priv = psmouse->private;
+ unsigned char *packet = psmouse->packet;
+ struct input_dev *dev = &psmouse->dev;
+ struct input_dev *dev2 = &priv->dev2;
+ int x, y, z, ges, fin, left, right, middle;
+
+ input_regs(dev, regs);
+
+ if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */
+ input_report_key(dev2, BTN_LEFT, packet[0] & 1);
+ input_report_key(dev2, BTN_RIGHT, packet[0] & 2);
+ input_report_key(dev2, BTN_MIDDLE, packet[0] & 4);
+ input_report_rel(dev2, REL_X,
+ packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0);
+ input_report_rel(dev2, REL_Y,
+ packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0);
+ input_sync(dev2);
+ return;
+ }
+
+ if (priv->i->flags & ALPS_OLDPROTO) {
+ left = packet[2] & 0x08;
+ right = packet[2] & 0x10;
+ middle = 0;
+ x = packet[1] | ((packet[0] & 0x07) << 7);
+ y = packet[4] | ((packet[3] & 0x07) << 7);
+ z = packet[5];
+ } else {
+ left = packet[3] & 1;
+ right = packet[3] & 2;
+ middle = packet[3] & 4;
+ x = packet[1] | ((packet[2] & 0x78) << (7 - 3));
+ y = packet[4] | ((packet[3] & 0x70) << (7 - 4));
+ z = packet[5];
+ }
+
+ ges = packet[2] & 1;
+ fin = packet[2] & 2;
+
+ input_report_key(dev, BTN_LEFT, left);
+ input_report_key(dev, BTN_RIGHT, right);
+ input_report_key(dev, BTN_MIDDLE, middle);
+
+ if ((priv->i->flags & ALPS_DUALPOINT) && z == 127) {
+ input_report_rel(dev2, REL_X, (x > 383 ? (x - 768) : x));
+ input_report_rel(dev2, REL_Y, -(y > 255 ? (y - 512) : y));
+ input_sync(dev);
+ input_sync(dev2);
+ return;
+ }
+
+ /* Convert hardware tap to a reasonable Z value */
+ if (ges && !fin) z = 40;
+
+ /*
+ * A "tap and drag" operation is reported by the hardware as a transition
+ * from (!fin && ges) to (fin && ges). This should be translated to the
+ * sequence Z>0, Z==0, Z>0, so the Z==0 event has to be generated manually.
+ */
+ if (ges && fin && !priv->prev_fin) {
+ input_report_abs(dev, ABS_X, x);
+ input_report_abs(dev, ABS_Y, y);
+ input_report_abs(dev, ABS_PRESSURE, 0);
+ input_report_key(dev, BTN_TOOL_FINGER, 0);
+ input_sync(dev);
+ }
+ priv->prev_fin = fin;
+
+ if (z > 30) input_report_key(dev, BTN_TOUCH, 1);
+ if (z < 25) input_report_key(dev, BTN_TOUCH, 0);
+
+ if (z > 0) {
+ input_report_abs(dev, ABS_X, x);
+ input_report_abs(dev, ABS_Y, y);
+ }
+
+ input_report_abs(dev, ABS_PRESSURE, z);
+ input_report_key(dev, BTN_TOOL_FINGER, z > 0);
+
+
+ if (priv->i->flags & ALPS_WHEEL)
+ input_report_rel(dev, REL_WHEEL, ((packet[0] >> 4) & 0x07) | ((packet[2] >> 2) & 0x08));
+
+ if (priv->i->flags & ALPS_FW_BK) {
+ input_report_key(dev, BTN_FORWARD, packet[0] & 0x10);
+ input_report_key(dev, BTN_BACK, packet[2] & 0x04);
+ }
+
+ input_sync(dev);
+}
+
+static psmouse_ret_t alps_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
+{
+ struct alps_data *priv = psmouse->private;
+
+ if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
+ if (psmouse->pktcnt == 3) {
+ alps_process_packet(psmouse, regs);
+ return PSMOUSE_FULL_PACKET;
+ }
+ return PSMOUSE_GOOD_DATA;
+ }
+
+ if ((psmouse->packet[0] & priv->i->mask0) != priv->i->byte0)
+ return PSMOUSE_BAD_DATA;
+
+ /* Bytes 2 - 6 should have 0 in the highest bit */
+ if (psmouse->pktcnt >= 2 && psmouse->pktcnt <= 6 &&
+ (psmouse->packet[psmouse->pktcnt - 1] & 0x80))
+ return PSMOUSE_BAD_DATA;
+
+ if (psmouse->pktcnt == 6) {
+ alps_process_packet(psmouse, regs);
+ return PSMOUSE_FULL_PACKET;
+ }
+
+ return PSMOUSE_GOOD_DATA;
+}
+
+static struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
+ unsigned char param[4];
+ int i;
+
+ /*
+ * First try "E6 report".
+ * ALPS should return 0,0,10 or 0,0,100
+ */
+ param[0] = 0;
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
+ return NULL;
+
+ param[0] = param[1] = param[2] = 0xff;
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ return NULL;
+
+ dbg("E6 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
+
+ if (param[0] != 0 || param[1] != 0 || (param[2] != 10 && param[2] != 100))
+ return NULL;
+
+ /*
+ * Now try "E7 report". Allowed responses are in
+ * alps_model_data[].signature
+ */
+ param[0] = 0;
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
+ return NULL;
+
+ param[0] = param[1] = param[2] = 0xff;
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ return NULL;
+
+ dbg("E7 report: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
+
+ for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++);
+ *version = (param[0] << 8) | (param[1] << 4) | i;
+
+ for (i = 0; i < ARRAY_SIZE(alps_model_data); i++)
+ if (!memcmp(param, alps_model_data[i].signature, sizeof(alps_model_data[i].signature)))
+ return alps_model_data + i;
+
+ return NULL;
+}
+
+/*
+ * For DualPoint devices select the device that should respond to
+ * subsequent commands. It looks like glidepad is behind stickpointer,
+ * I'd thought it would be other way around...
+ */
+static int alps_passthrough_mode(struct psmouse *psmouse, int enable)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[3];
+ int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
+
+ if (ps2_command(ps2dev, NULL, cmd) ||
+ ps2_command(ps2dev, NULL, cmd) ||
+ ps2_command(ps2dev, NULL, cmd) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE))
+ return -1;
+
+ /* we may get 3 more bytes, just ignore them */
+ ps2_command(ps2dev, param, 0x0300);
+
+ return 0;
+}
+
+static int alps_absolute_mode(struct psmouse *psmouse)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+
+ /* Try ALPS magic knock - 4 disable before enable */
+ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
+ return -1;
+
+ /*
+ * Switch mouse to poll (remote) mode so motion data will not
+ * get in our way
+ */
+ return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL);
+}
+
+static int alps_get_status(struct psmouse *psmouse, char *param)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+
+ /* Get status: 0xF5 0xF5 0xF5 0xE9 */
+ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ return -1;
+
+ dbg("Status: %2.2x %2.2x %2.2x", param[0], param[1], param[2]);
+
+ return 0;
+}
+
+/*
+ * Turn touchpad tapping on or off. The sequences are:
+ * 0xE9 0xF5 0xF5 0xF3 0x0A to enable,
+ * 0xE9 0xF5 0xF5 0xE8 0x00 to disable.
+ * My guess that 0xE9 (GetInfo) is here as a sync point.
+ * For models that also have stickpointer (DualPoints) its tapping
+ * is controlled separately (0xE6 0xE6 0xE6 0xF3 0x14|0x0A) but
+ * we don't fiddle with it.
+ */
+static int alps_tap_mode(struct psmouse *psmouse, int enable)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ int cmd = enable ? PSMOUSE_CMD_SETRATE : PSMOUSE_CMD_SETRES;
+ unsigned char tap_arg = enable ? 0x0A : 0x00;
+ unsigned char param[4];
+
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
+ ps2_command(ps2dev, &tap_arg, cmd))
+ return -1;
+
+ if (alps_get_status(psmouse, param))
+ return -1;
+
+ return 0;
+}
+
+static int alps_reconnect(struct psmouse *psmouse)
+{
+ struct alps_data *priv = psmouse->private;
+ unsigned char param[4];
+ int version;
+
+ if (!(priv->i = alps_get_model(psmouse, &version)))
+ return -1;
+
+ if (priv->i->flags & ALPS_PASS && alps_passthrough_mode(psmouse, 1))
+ return -1;
+
+ if (alps_get_status(psmouse, param))
+ return -1;
+
+ if (param[0] & 0x04)
+ alps_tap_mode(psmouse, 1);
+
+ if (alps_absolute_mode(psmouse)) {
+ printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
+ return -1;
+ }
+
+ if (priv->i->flags == ALPS_PASS && alps_passthrough_mode(psmouse, 0))
+ return -1;
+
+ return 0;
+}
+
+static void alps_disconnect(struct psmouse *psmouse)
+{
+ struct alps_data *priv = psmouse->private;
+ psmouse_reset(psmouse);
+ input_unregister_device(&priv->dev2);
+ kfree(priv);
+}
+
+int alps_init(struct psmouse *psmouse)
+{
+ struct alps_data *priv;
+ unsigned char param[4];
+ int version;
+
+ psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL);
+ if (!priv)
+ goto init_fail;
+ memset(priv, 0, sizeof(struct alps_data));
+
+ if (!(priv->i = alps_get_model(psmouse, &version)))
+ goto init_fail;
+
+ if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 1))
+ goto init_fail;
+
+ if (alps_get_status(psmouse, param)) {
+ printk(KERN_ERR "alps.c: touchpad status report request failed\n");
+ goto init_fail;
+ }
+
+ if (param[0] & 0x04) {
+ printk(KERN_INFO " Enabling hardware tapping\n");
+ if (alps_tap_mode(psmouse, 1))
+ printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
+ }
+
+ if (alps_absolute_mode(psmouse)) {
+ printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
+ goto init_fail;
+ }
+
+ if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0))
+ goto init_fail;
+
+ psmouse->dev.evbit[LONG(EV_KEY)] |= BIT(EV_KEY);
+ psmouse->dev.keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
+ psmouse->dev.keybit[LONG(BTN_TOOL_FINGER)] |= BIT(BTN_TOOL_FINGER);
+ psmouse->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
+
+ psmouse->dev.evbit[LONG(EV_ABS)] |= BIT(EV_ABS);
+ input_set_abs_params(&psmouse->dev, ABS_X, 0, 1023, 0, 0);
+ input_set_abs_params(&psmouse->dev, ABS_Y, 0, 767, 0, 0);
+ input_set_abs_params(&psmouse->dev, ABS_PRESSURE, 0, 127, 0, 0);
+
+ if (priv->i->flags & ALPS_WHEEL) {
+ psmouse->dev.evbit[LONG(EV_REL)] |= BIT(EV_REL);
+ psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL);
+ }
+
+ if (priv->i->flags & ALPS_FW_BK) {
+ psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD);
+ psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK);
+ }
+
+ sprintf(priv->phys, "%s/input1", psmouse->ps2dev.serio->phys);
+ priv->dev2.phys = priv->phys;
+ priv->dev2.name = (priv->i->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
+ priv->dev2.id.bustype = BUS_I8042;
+ priv->dev2.id.vendor = 0x0002;
+ priv->dev2.id.product = PSMOUSE_ALPS;
+ priv->dev2.id.version = 0x0000;
+
+ priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+ priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
+ priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
+
+ input_register_device(&priv->dev2);
+
+ printk(KERN_INFO "input: %s on %s\n", priv->dev2.name, psmouse->ps2dev.serio->phys);
+
+ psmouse->protocol_handler = alps_process_byte;
+ psmouse->disconnect = alps_disconnect;
+ psmouse->reconnect = alps_reconnect;
+ psmouse->pktsize = 6;
+
+ return 0;
+
+init_fail:
+ kfree(priv);
+ return -1;
+}
+
+int alps_detect(struct psmouse *psmouse, int set_properties)
+{
+ int version;
+ struct alps_model_info *model;
+
+ if (!(model = alps_get_model(psmouse, &version)))
+ return -1;
+
+ if (set_properties) {
+ psmouse->vendor = "ALPS";
+ if (model->flags & ALPS_DUALPOINT)
+ psmouse->name = "DualPoint TouchPad";
+ else
+ psmouse->name = "GlidePoint";
+ psmouse->model = version;
+ }
+ return 0;
+}
+
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
new file mode 100644
index 0000000..aba103d
--- /dev/null
+++ b/drivers/input/mouse/alps.h
@@ -0,0 +1,32 @@
+/*
+ * ALPS touchpad PS/2 mouse driver
+ *
+ * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
+ * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef _ALPS_H
+#define _ALPS_H
+
+int alps_detect(struct psmouse *psmouse, int set_properties);
+int alps_init(struct psmouse *psmouse);
+
+struct alps_model_info {
+ unsigned char signature[3];
+ unsigned char byte0, mask0;
+ unsigned char flags;
+};
+
+struct alps_data {
+ struct input_dev dev2; /* Relative device */
+ char name[32]; /* Name */
+ char phys[32]; /* Phys */
+ struct alps_model_info *i; /* Info */
+ int prev_fin; /* Finger bit from previous packet */
+};
+
+#endif
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
new file mode 100644
index 0000000..7baa09c
--- /dev/null
+++ b/drivers/input/mouse/amimouse.c
@@ -0,0 +1,137 @@
+/*
+ * Amiga mouse driver for Linux/m68k
+ *
+ * Copyright (c) 2000-2002 Vojtech Pavlik
+ *
+ * Based on the work of:
+ * Michael Rausch James Banks
+ * Matther Dillon David Giller
+ * Nathan Laredo Linus Torvalds
+ * Johan Myreen Jes Sorensen
+ * Russell King
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+
+#include <asm/irq.h>
+#include <asm/setup.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/amigahw.h>
+#include <asm/amigaints.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
+MODULE_DESCRIPTION("Amiga mouse driver");
+MODULE_LICENSE("GPL");
+
+static int amimouse_used = 0;
+static int amimouse_lastx, amimouse_lasty;
+static struct input_dev amimouse_dev;
+
+static char *amimouse_name = "Amiga mouse";
+static char *amimouse_phys = "amimouse/input0";
+
+static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
+{
+ unsigned short joy0dat, potgor;
+ int nx, ny, dx, dy;
+
+ joy0dat = custom.joy0dat;
+
+ nx = joy0dat & 0xff;
+ ny = joy0dat >> 8;
+
+ dx = nx - amimouse_lastx;
+ dy = ny - amimouse_lasty;
+
+ if (dx < -127) dx = (256 + nx) - amimouse_lastx;
+ if (dx > 127) dx = (nx - 256) - amimouse_lastx;
+ if (dy < -127) dy = (256 + ny) - amimouse_lasty;
+ if (dy > 127) dy = (ny - 256) - amimouse_lasty;
+
+ amimouse_lastx = nx;
+ amimouse_lasty = ny;
+
+ potgor = custom.potgor;
+
+ input_regs(&amimouse_dev, fp);
+
+ input_report_rel(&amimouse_dev, REL_X, dx);
+ input_report_rel(&amimouse_dev, REL_Y, dy);
+
+ input_report_key(&amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
+ input_report_key(&amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
+ input_report_key(&amimouse_dev, BTN_RIGHT, potgor & 0x0400);
+
+ input_sync(&amimouse_dev);
+
+ return IRQ_HANDLED;
+}
+
+static int amimouse_open(struct input_dev *dev)
+{
+ unsigned short joy0dat;
+
+ if (amimouse_used++)
+ return 0;
+
+ joy0dat = custom.joy0dat;
+
+ amimouse_lastx = joy0dat & 0xff;
+ amimouse_lasty = joy0dat >> 8;
+
+ if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
+ amimouse_used--;
+ printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+static void amimouse_close(struct input_dev *dev)
+{
+ if (!--amimouse_used)
+ free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
+}
+
+static int __init amimouse_init(void)
+{
+ if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
+ return -ENODEV;
+
+ amimouse_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+ amimouse_dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
+ amimouse_dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
+ amimouse_dev.open = amimouse_open;
+ amimouse_dev.close = amimouse_close;
+
+ amimouse_dev.name = amimouse_name;
+ amimouse_dev.phys = amimouse_phys;
+ amimouse_dev.id.bustype = BUS_AMIGA;
+ amimouse_dev.id.vendor = 0x0001;
+ amimouse_dev.id.product = 0x0002;
+ amimouse_dev.id.version = 0x0100;
+
+ input_register_device(&amimouse_dev);
+
+ printk(KERN_INFO "input: %s at joy0dat\n", amimouse_name);
+ return 0;
+}
+
+static void __exit amimouse_exit(void)
+{
+ input_unregister_device(&amimouse_dev);
+}
+
+module_init(amimouse_init);
+module_exit(amimouse_exit);
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
new file mode 100644
index 0000000..bc22849
--- /dev/null
+++ b/drivers/input/mouse/hil_ptr.c
@@ -0,0 +1,414 @@
+/*
+ * Generic linux-input device driver for axis-bearing devices
+ *
+ * Copyright (c) 2001 Brian S. Julin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL").
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ *
+ * References:
+ * HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
+ *
+ */
+
+#include <linux/hil.h>
+#include <linux/input.h>
+#include <linux/serio.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/pci_ids.h>
+
+#define PREFIX "HIL PTR: "
+#define HIL_GENERIC_NAME "HIL pointer device"
+
+MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
+MODULE_DESCRIPTION(HIL_GENERIC_NAME " driver");
+MODULE_LICENSE("Dual BSD/GPL");
+
+
+#define TABLET_SIMULATES_MOUSE /* allow tablet to be used as mouse */
+#undef TABLET_AUTOADJUST /* auto-adjust valid tablet ranges */
+
+
+#define HIL_PTR_MAX_LENGTH 16
+
+struct hil_ptr {
+ struct input_dev dev;
+ struct serio *serio;
+
+ /* Input buffer and index for packets from HIL bus. */
+ hil_packet data[HIL_PTR_MAX_LENGTH];
+ int idx4; /* four counts per packet */
+
+ /* Raw device info records from HIL bus, see hil.h for fields. */
+ char idd[HIL_PTR_MAX_LENGTH]; /* DID byte and IDD record */
+ char rsc[HIL_PTR_MAX_LENGTH]; /* RSC record */
+ char exd[HIL_PTR_MAX_LENGTH]; /* EXD record */
+ char rnm[HIL_PTR_MAX_LENGTH + 1]; /* RNM record + NULL term. */
+
+ /* Extra device details not contained in struct input_dev. */
+ unsigned int nbtn, naxes;
+ unsigned int btnmap[7];
+
+ /* Something to sleep around with. */
+ struct semaphore sem;
+};
+
+/* Process a complete packet after transfer from the HIL */
+static void hil_ptr_process_record(struct hil_ptr *ptr)
+{
+ struct input_dev *dev = &ptr->dev;
+ hil_packet *data = ptr->data;
+ hil_packet p;
+ int idx, i, cnt, laxis;
+ int ax16, absdev;
+
+ idx = ptr->idx4/4;
+ p = data[idx - 1];
+
+ if ((p & ~HIL_CMDCT_POL) ==
+ (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) goto report;
+ if ((p & ~HIL_CMDCT_RPL) ==
+ (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) goto report;
+
+ /* Not a poll response. See if we are loading config records. */
+ switch (p & HIL_PKT_DATA_MASK) {
+ case HIL_CMD_IDD:
+ for (i = 0; i < idx; i++)
+ ptr->idd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
+ for (; i < HIL_PTR_MAX_LENGTH; i++)
+ ptr->idd[i] = 0;
+ break;
+ case HIL_CMD_RSC:
+ for (i = 0; i < idx; i++)
+ ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
+ for (; i < HIL_PTR_MAX_LENGTH; i++)
+ ptr->rsc[i] = 0;
+ break;
+ case HIL_CMD_EXD:
+ for (i = 0; i < idx; i++)
+ ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
+ for (; i < HIL_PTR_MAX_LENGTH; i++)
+ ptr->exd[i] = 0;
+ break;
+ case HIL_CMD_RNM:
+ for (i = 0; i < idx; i++)
+ ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
+ for (; i < HIL_PTR_MAX_LENGTH + 1; i++)
+ ptr->rnm[i] = '\0';
+ break;
+ default:
+ /* These occur when device isn't present */
+ if (p == (HIL_ERR_INT | HIL_PKT_CMD)) break;
+ /* Anything else we'd like to know about. */
+ printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
+ break;
+ }
+ goto out;
+
+ report:
+ if ((p & HIL_CMDCT_POL) != idx - 1) {
+ printk(KERN_WARNING PREFIX "Malformed poll packet %x (idx = %i)\n", p, idx);
+ goto out;
+ }
+
+ i = (ptr->data[0] & HIL_POL_AXIS_ALT) ? 3 : 0;
+ laxis = ptr->data[0] & HIL_POL_NUM_AXES_MASK;
+ laxis += i;
+
+ ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */
+ absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS;
+
+ for (cnt = 1; i < laxis; i++) {
+ unsigned int lo,hi,val;
+ lo = ptr->data[cnt++] & HIL_PKT_DATA_MASK;
+ hi = ax16 ? (ptr->data[cnt++] & HIL_PKT_DATA_MASK) : 0;
+ if (absdev) {
+ val = lo + (hi<<8);
+#ifdef TABLET_AUTOADJUST
+ if (val < ptr->dev.absmin[ABS_X + i])
+ ptr->dev.absmin[ABS_X + i] = val;
+ if (val > ptr->dev.absmax[ABS_X + i])
+ ptr->dev.absmax[ABS_X + i] = val;
+#endif
+ if (i%3) val = ptr->dev.absmax[ABS_X + i] - val;
+ input_report_abs(dev, ABS_X + i, val);
+ } else {
+ val = (int) (((int8_t)lo) | ((int8_t)hi<<8));
+ if (i%3) val *= -1;
+ input_report_rel(dev, REL_X + i, val);
+ }
+ }
+
+ while (cnt < idx - 1) {
+ unsigned int btn;
+ int up;
+ btn = ptr->data[cnt++];
+ up = btn & 1;
+ btn &= 0xfe;
+ if (btn == 0x8e) {
+ continue; /* TODO: proximity == touch? */
+ }
+ else if ((btn > 0x8c) || (btn < 0x80)) continue;
+ btn = (btn - 0x80) >> 1;
+ btn = ptr->btnmap[btn];
+ input_report_key(dev, btn, !up);
+ }
+ input_sync(dev);
+ out:
+ ptr->idx4 = 0;
+ up(&ptr->sem);
+}
+
+static void hil_ptr_process_err(struct hil_ptr *ptr) {
+ printk(KERN_WARNING PREFIX "errored HIL packet\n");
+ ptr->idx4 = 0;
+ up(&ptr->sem);
+ return;
+}
+
+static irqreturn_t hil_ptr_interrupt(struct serio *serio,
+ unsigned char data, unsigned int flags, struct pt_regs *regs)
+{
+ struct hil_ptr *ptr;
+ hil_packet packet;
+ int idx;
+
+ ptr = (struct hil_ptr *)serio->private;
+ if (ptr == NULL) {
+ BUG();
+ return IRQ_HANDLED;
+ }
+
+ if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) {
+ hil_ptr_process_err(ptr);
+ return IRQ_HANDLED;
+ }
+ idx = ptr->idx4/4;
+ if (!(ptr->idx4 % 4)) ptr->data[idx] = 0;
+ packet = ptr->data[idx];
+ packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8);
+ ptr->data[idx] = packet;
+
+ /* Records of N 4-byte hil_packets must terminate with a command. */
+ if ((++(ptr->idx4)) % 4) return IRQ_HANDLED;
+ if ((packet & 0xffff0000) != HIL_ERR_INT) {
+ hil_ptr_process_err(ptr);
+ return IRQ_HANDLED;
+ }
+ if (packet & HIL_PKT_CMD)
+ hil_ptr_process_record(ptr);
+ return IRQ_HANDLED;
+}
+
+static void hil_ptr_disconnect(struct serio *serio)
+{
+ struct hil_ptr *ptr;
+
+ ptr = (struct hil_ptr *)serio->private;
+ if (ptr == NULL) {
+ BUG();
+ return;
+ }
+
+ input_unregister_device(&ptr->dev);
+ serio_close(serio);
+ kfree(ptr);
+}
+
+static void hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
+{
+ struct hil_ptr *ptr;
+ char *txt;
+ unsigned int i, naxsets, btntype;
+ uint8_t did, *idd;
+
+ if (serio->type != (SERIO_HIL_MLC | SERIO_HIL)) return;
+
+ if (!(ptr = kmalloc(sizeof(struct hil_ptr), GFP_KERNEL))) return;
+ memset(ptr, 0, sizeof(struct hil_ptr));
+
+ if (serio_open(serio, driver)) goto bail0;
+
+ serio->private = ptr;
+ ptr->serio = serio;
+ ptr->dev.private = ptr;
+
+ init_MUTEX_LOCKED(&(ptr->sem));
+
+ /* Get device info. MLC driver supplies devid/status/etc. */
+ serio->write(serio, 0);
+ serio->write(serio, 0);
+ serio->write(serio, HIL_PKT_CMD >> 8);
+ serio->write(serio, HIL_CMD_IDD);
+ down(&(ptr->sem));
+
+ serio->write(serio, 0);
+ serio->write(serio, 0);
+ serio->write(serio, HIL_PKT_CMD >> 8);
+ serio->write(serio, HIL_CMD_RSC);
+ down(&(ptr->sem));
+
+ serio->write(serio, 0);
+ serio->write(serio, 0);
+ serio->write(serio, HIL_PKT_CMD >> 8);
+ serio->write(serio, HIL_CMD_RNM);
+ down(&(ptr->sem));
+
+ serio->write(serio, 0);
+ serio->write(serio, 0);
+ serio->write(serio, HIL_PKT_CMD >> 8);
+ serio->write(serio, HIL_CMD_EXD);
+ down(&(ptr->sem));
+
+ up(&(ptr->sem));
+
+ init_input_dev(&ptr->dev);
+ did = ptr->idd[0];
+ idd = ptr->idd + 1;
+ txt = "unknown";
+ if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
+ ptr->dev.evbit[0] = BIT(EV_REL);
+ txt = "relative";
+ }
+
+ if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_ABS) {
+ ptr->dev.evbit[0] = BIT(EV_ABS);
+ txt = "absolute";
+ }
+ if (!ptr->dev.evbit[0]) {
+ goto bail1;
+ }
+
+ ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
+ if (ptr->nbtn) ptr->dev.evbit[0] |= BIT(EV_KEY);
+
+ naxsets = HIL_IDD_NUM_AXSETS(*idd);
+ ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
+
+ printk(KERN_INFO PREFIX "HIL pointer device found (did: 0x%02x, axis: %s)\n",
+ did, txt);
+ printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n",
+ ptr->nbtn, naxsets, ptr->naxes);
+
+ btntype = BTN_MISC;
+ if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET)
+#ifdef TABLET_SIMULATES_MOUSE
+ btntype = BTN_TOUCH;
+#else
+ btntype = BTN_DIGI;
+#endif
+ if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN)
+ btntype = BTN_TOUCH;
+
+ if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE)
+ btntype = BTN_MOUSE;
+
+ for (i = 0; i < ptr->nbtn; i++) {
+ set_bit(btntype | i, ptr->dev.keybit);
+ ptr->btnmap[i] = btntype | i;
+ }
+
+ if (btntype == BTN_MOUSE) {
+ /* Swap buttons 2 and 3 */
+ ptr->btnmap[1] = BTN_MIDDLE;
+ ptr->btnmap[2] = BTN_RIGHT;
+ }
+
+ if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
+ for (i = 0; i < ptr->naxes; i++) {
+ set_bit(REL_X + i, ptr->dev.relbit);
+ }
+ for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
+ set_bit(REL_X + i, ptr->dev.relbit);
+ }
+ } else {
+ for (i = 0; i < ptr->naxes; i++) {
+ set_bit(ABS_X + i, ptr->dev.absbit);
+ ptr->dev.absmin[ABS_X + i] = 0;
+ ptr->dev.absmax[ABS_X + i] =
+ HIL_IDD_AXIS_MAX((ptr->idd + 1), i);
+ }
+ for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
+ set_bit(ABS_X + i, ptr->dev.absbit);
+ ptr->dev.absmin[ABS_X + i] = 0;
+ ptr->dev.absmax[ABS_X + i] =
+ HIL_IDD_AXIS_MAX((ptr->idd + 1), (i - 3));
+ }
+#ifdef TABLET_AUTOADJUST
+ for (i = 0; i < ABS_MAX; i++) {
+ int diff = ptr->dev.absmax[ABS_X + i] / 10;
+ ptr->dev.absmin[ABS_X + i] += diff;
+ ptr->dev.absmax[ABS_X + i] -= diff;
+ }
+#endif
+ }
+
+ ptr->dev.name = strlen(ptr->rnm) ? ptr->rnm : HIL_GENERIC_NAME;
+
+ ptr->dev.id.bustype = BUS_HIL;
+ ptr->dev.id.vendor = PCI_VENDOR_ID_HP;
+ ptr->dev.id.product = 0x0001; /* TODO: get from ptr->rsc */
+ ptr->dev.id.version = 0x0100; /* TODO: get from ptr->rsc */
+ ptr->dev.dev = &serio->dev;
+
+ input_register_device(&ptr->dev);
+ printk(KERN_INFO "input: %s (%s), ID: %d\n",
+ ptr->dev.name,
+ (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
+ did);
+
+ return;
+ bail1:
+ serio_close(serio);
+ bail0:
+ kfree(ptr);
+ return;
+}
+
+
+static struct serio_driver hil_ptr_serio_driver = {
+ .driver = {
+ .name = "hil_ptr",
+ },
+ .description = "HP HIL mouse/tablet driver",
+ .connect = hil_ptr_connect,
+ .disconnect = hil_ptr_disconnect,
+ .interrupt = hil_ptr_interrupt
+};
+
+static int __init hil_ptr_init(void)
+{
+ serio_register_driver(&hil_ptr_serio_driver);
+ return 0;
+}
+
+static void __exit hil_ptr_exit(void)
+{
+ serio_unregister_driver(&hil_ptr_serio_driver);
+}
+
+module_init(hil_ptr_init);
+module_exit(hil_ptr_exit);
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
new file mode 100644
index 0000000..ca4e968
--- /dev/null
+++ b/drivers/input/mouse/inport.c
@@ -0,0 +1,196 @@
+/*
+ * $Id: inport.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
+ *
+ * Copyright (c) 1999-2001 Vojtech Pavlik
+ *
+ * Based on the work of:
+ * Teemu Rantanen Derrick Cole
+ * Peter Cervasio Christoph Niemann
+ * Philip Blundell Russell King
+ * Bob Harris
+ */
+
+/*
+ * Inport (ATI XL and Microsoft) busmouse driver for Linux
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Should you need to contact me, the author, you can do so either by
+ * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
+ * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/config.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
+MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver");
+MODULE_LICENSE("GPL");
+
+#define INPORT_BASE 0x23c
+#define INPORT_EXTENT 4
+
+#define INPORT_CONTROL_PORT INPORT_BASE + 0
+#define INPORT_DATA_PORT INPORT_BASE + 1
+#define INPORT_SIGNATURE_PORT INPORT_BASE + 2
+
+#define INPORT_REG_BTNS 0x00
+#define INPORT_REG_X 0x01
+#define INPORT_REG_Y 0x02
+#define INPORT_REG_MODE 0x07
+#define INPORT_RESET 0x80
+
+#ifdef CONFIG_INPUT_ATIXL
+#define INPORT_NAME "ATI XL Mouse"
+#define INPORT_VENDOR 0x0002
+#define INPORT_SPEED_30HZ 0x01
+#define INPORT_SPEED_50HZ 0x02
+#define INPORT_SPEED_100HZ 0x03
+#define INPORT_SPEED_200HZ 0x04
+#define INPORT_MODE_BASE INPORT_SPEED_100HZ
+#define INPORT_MODE_IRQ 0x08
+#else
+#define INPORT_NAME "Microsoft InPort Mouse"
+#define INPORT_VENDOR 0x0001
+#define INPORT_MODE_BASE 0x10
+#define INPORT_MODE_IRQ 0x01
+#endif
+#define INPORT_MODE_HOLD 0x20
+
+#define INPORT_IRQ 5
+
+static int inport_irq = INPORT_IRQ;
+module_param_named(irq, inport_irq, uint, 0);
+MODULE_PARM_DESC(irq, "IRQ number (5=default)");
+
+__obsolete_setup("inport_irq=");
+
+static int inport_used;
+
+static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+
+static int inport_open(struct input_dev *dev)
+{
+ if (!inport_used++) {
+ if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
+ return -EBUSY;
+ outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
+ outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
+ }
+
+ return 0;
+}
+
+static void inport_close(struct input_dev *dev)
+{
+ if (!--inport_used) {
+ outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
+ outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
+ free_irq(inport_irq, NULL);
+ }
+}
+
+static struct input_dev inport_dev = {
+ .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
+ .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
+ .relbit = { BIT(REL_X) | BIT(REL_Y) },
+ .open = inport_open,
+ .close = inport_close,
+ .name = INPORT_NAME,
+ .phys = "isa023c/input0",
+ .id = {
+ .bustype = BUS_ISA,
+ .vendor = INPORT_VENDOR,
+ .product = 0x0001,
+ .version = 0x0100,
+ },
+};
+
+static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ unsigned char buttons;
+
+ outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
+ outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
+
+ input_regs(&inport_dev, regs);
+
+ outb(INPORT_REG_X, INPORT_CONTROL_PORT);
+ input_report_rel(&inport_dev, REL_X, inb(INPORT_DATA_PORT));
+
+ outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
+ input_report_rel(&inport_dev, REL_Y, inb(INPORT_DATA_PORT));
+
+ outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
+ buttons = inb(INPORT_DATA_PORT);
+
+ input_report_key(&inport_dev, BTN_MIDDLE, buttons & 1);
+ input_report_key(&inport_dev, BTN_LEFT, buttons & 2);
+ input_report_key(&inport_dev, BTN_RIGHT, buttons & 4);
+
+ outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
+ outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
+
+ input_sync(&inport_dev);
+ return IRQ_HANDLED;
+}
+
+static int __init inport_init(void)
+{
+ unsigned char a,b,c;
+
+ if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
+ printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
+ return -EBUSY;
+ }
+
+ a = inb(INPORT_SIGNATURE_PORT);
+ b = inb(INPORT_SIGNATURE_PORT);
+ c = inb(INPORT_SIGNATURE_PORT);
+ if (( a == b ) || ( a != c )) {
+ release_region(INPORT_BASE, INPORT_EXTENT);
+ printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
+ return -ENODEV;
+ }
+
+ outb(INPORT_RESET, INPORT_CONTROL_PORT);
+ outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
+ outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
+
+ input_register_device(&inport_dev);
+
+ printk(KERN_INFO "input: " INPORT_NAME " at %#x irq %d\n", INPORT_BASE, inport_irq);
+
+ return 0;
+}
+
+static void __exit inport_exit(void)
+{
+ input_unregister_device(&inport_dev);
+ release_region(INPORT_BASE, INPORT_EXTENT);
+}
+
+module_init(inport_init);
+module_exit(inport_exit);
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
new file mode 100644
index 0000000..77eb83e
--- /dev/null
+++ b/drivers/input/mouse/logibm.c
@@ -0,0 +1,183 @@
+/*
+ * $Id: logibm.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $
+ *
+ * Copyright (c) 1999-2001 Vojtech Pavlik
+ *
+ * Based on the work of:
+ * James Banks Matthew Dillon
+ * David Giller Nathan Laredo
+ * Linus Torvalds Johan Myreen
+ * Cliff Matthews Philip Blundell
+ * Russell King
+ */
+
+/*
+ * Logitech Bus Mouse Driver for Linux
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Should you need to contact me, the author, you can do so either by
+ * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
+ * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
+MODULE_DESCRIPTION("Logitech busmouse driver");
+MODULE_LICENSE("GPL");
+
+#define LOGIBM_BASE 0x23c
+#define LOGIBM_EXTENT 4
+
+#define LOGIBM_DATA_PORT LOGIBM_BASE + 0
+#define LOGIBM_SIGNATURE_PORT LOGIBM_BASE + 1
+#define LOGIBM_CONTROL_PORT LOGIBM_BASE + 2
+#define LOGIBM_CONFIG_PORT LOGIBM_BASE + 3
+
+#define LOGIBM_ENABLE_IRQ 0x00
+#define LOGIBM_DISABLE_IRQ 0x10
+#define LOGIBM_READ_X_LOW 0x80
+#define LOGIBM_READ_X_HIGH 0xa0
+#define LOGIBM_READ_Y_LOW 0xc0
+#define LOGIBM_READ_Y_HIGH 0xe0
+
+#define LOGIBM_DEFAULT_MODE 0x90
+#define LOGIBM_CONFIG_BYTE 0x91
+#define LOGIBM_SIGNATURE_BYTE 0xa5
+
+#define LOGIBM_IRQ 5
+
+static int logibm_irq = LOGIBM_IRQ;
+module_param_named(irq, logibm_irq, uint, 0);
+MODULE_PARM_DESC(irq, "IRQ number (5=default)");
+
+__obsolete_setup("logibm_irq=");
+
+static int logibm_used = 0;
+
+static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+
+static int logibm_open(struct input_dev *dev)
+{
+ if (logibm_used++)
+ return 0;
+ if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
+ logibm_used--;
+ printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
+ return -EBUSY;
+ }
+ outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
+ return 0;
+}
+
+static void logibm_close(struct input_dev *dev)
+{
+ if (--logibm_used)
+ return;
+ outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
+ free_irq(logibm_irq, NULL);
+}
+
+static struct input_dev logibm_dev = {
+ .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
+ .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
+ .relbit = { BIT(REL_X) | BIT(REL_Y) },
+ .open = logibm_open,
+ .close = logibm_close,
+ .name = "Logitech bus mouse",
+ .phys = "isa023c/input0",
+ .id = {
+ .bustype = BUS_ISA,
+ .vendor = 0x0003,
+ .product = 0x0001,
+ .version = 0x0100,
+ },
+};
+
+static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ char dx, dy;
+ unsigned char buttons;
+
+ outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT);
+ dx = (inb(LOGIBM_DATA_PORT) & 0xf);
+ outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT);
+ dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4;
+ outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT);
+ dy = (inb(LOGIBM_DATA_PORT) & 0xf);
+ outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT);
+ buttons = inb(LOGIBM_DATA_PORT);
+ dy |= (buttons & 0xf) << 4;
+ buttons = ~buttons >> 5;
+
+ input_regs(&logibm_dev, regs);
+ input_report_rel(&logibm_dev, REL_X, dx);
+ input_report_rel(&logibm_dev, REL_Y, dy);
+ input_report_key(&logibm_dev, BTN_RIGHT, buttons & 1);
+ input_report_key(&logibm_dev, BTN_MIDDLE, buttons & 2);
+ input_report_key(&logibm_dev, BTN_LEFT, buttons & 4);
+ input_sync(&logibm_dev);
+
+ outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
+ return IRQ_HANDLED;
+}
+
+static int __init logibm_init(void)
+{
+ if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
+ printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
+ return -EBUSY;
+ }
+
+ outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT);
+ outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT);
+ udelay(100);
+
+ if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
+ release_region(LOGIBM_BASE, LOGIBM_EXTENT);
+ printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
+ return -ENODEV;
+ }
+
+ outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
+ outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
+
+ input_register_device(&logibm_dev);
+
+ printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq);
+
+ return 0;
+}
+
+static void __exit logibm_exit(void)
+{
+ input_unregister_device(&logibm_dev);
+ release_region(LOGIBM_BASE, LOGIBM_EXTENT);
+}
+
+module_init(logibm_init);
+module_exit(logibm_exit);
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
new file mode 100644
index 0000000..5ab1bd7
--- /dev/null
+++ b/drivers/input/mouse/logips2pp.c
@@ -0,0 +1,397 @@
+/*
+ * Logitech PS/2++ mouse driver
+ *
+ * Copyright (c) 1999-2003 Vojtech Pavlik <vojtech@suse.cz>
+ * Copyright (c) 2003 Eric Wong <eric@yhbt.net>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/input.h>
+#include <linux/serio.h>
+#include <linux/libps2.h>
+#include "psmouse.h"
+#include "logips2pp.h"
+
+/* Logitech mouse types */
+#define PS2PP_KIND_WHEEL 1
+#define PS2PP_KIND_MX 2
+#define PS2PP_KIND_TP3 3
+
+/* Logitech mouse features */
+#define PS2PP_WHEEL 0x01
+#define PS2PP_HWHEEL 0x02
+#define PS2PP_SIDE_BTN 0x04
+#define PS2PP_EXTRA_BTN 0x08
+#define PS2PP_TASK_BTN 0x10
+#define PS2PP_NAV_BTN 0x20
+
+struct ps2pp_info {
+ const int model;
+ unsigned const int kind;
+ unsigned const int features;
+};
+
+/*
+ * Process a PS2++ or PS2T++ packet.
+ */
+
+static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
+{
+ struct input_dev *dev = &psmouse->dev;
+ unsigned char *packet = psmouse->packet;
+
+ if (psmouse->pktcnt < 3)
+ return PSMOUSE_GOOD_DATA;
+
+/*
+ * Full packet accumulated, process it
+ */
+
+ input_regs(dev, regs);
+
+ if ((packet[0] & 0x48) == 0x48 && (packet[1] & 0x02) == 0x02) {
+
+ /* Logitech extended packet */
+ switch ((packet[1] >> 4) | (packet[0] & 0x30)) {
+
+ case 0x0d: /* Mouse extra info */
+
+ input_report_rel(dev, packet[2] & 0x80 ? REL_HWHEEL : REL_WHEEL,
+ (int) (packet[2] & 8) - (int) (packet[2] & 7));
+ input_report_key(dev, BTN_SIDE, (packet[2] >> 4) & 1);
+ input_report_key(dev, BTN_EXTRA, (packet[2] >> 5) & 1);
+
+ break;
+
+ case 0x0e: /* buttons 4, 5, 6, 7, 8, 9, 10 info */
+
+ input_report_key(dev, BTN_SIDE, (packet[2]) & 1);
+ input_report_key(dev, BTN_EXTRA, (packet[2] >> 1) & 1);
+ input_report_key(dev, BTN_BACK, (packet[2] >> 3) & 1);
+ input_report_key(dev, BTN_FORWARD, (packet[2] >> 4) & 1);
+ input_report_key(dev, BTN_TASK, (packet[2] >> 2) & 1);
+
+ break;
+
+ case 0x0f: /* TouchPad extra info */
+
+ input_report_rel(dev, packet[2] & 0x08 ? REL_HWHEEL : REL_WHEEL,
+ (int) ((packet[2] >> 4) & 8) - (int) ((packet[2] >> 4) & 7));
+ packet[0] = packet[2] | 0x08;
+ break;
+
+#ifdef DEBUG
+ default:
+ printk(KERN_WARNING "psmouse.c: Received PS2++ packet #%x, but don't know how to handle.\n",
+ (packet[1] >> 4) | (packet[0] & 0x30));
+#endif
+ }
+ } else {
+ /* Standard PS/2 motion data */
+ input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
+ input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
+ }
+
+ input_report_key(dev, BTN_LEFT, packet[0] & 1);
+ input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
+ input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
+
+ input_sync(dev);
+
+ return PSMOUSE_FULL_PACKET;
+
+}
+
+/*
+ * ps2pp_cmd() sends a PS2++ command, sliced into two bit
+ * pieces through the SETRES command. This is needed to send extended
+ * commands to mice on notebooks that try to understand the PS/2 protocol
+ * Ugly.
+ */
+
+static int ps2pp_cmd(struct psmouse *psmouse, unsigned char *param, unsigned char command)
+{
+ if (psmouse_sliced_command(psmouse, command))
+ return -1;
+
+ if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL))
+ return -1;
+
+ return 0;
+}
+
+/*
+ * SmartScroll / CruiseControl for some newer Logitech mice Defaults to
+ * enabled if we do nothing to it. Of course I put this in because I want it
+ * disabled :P
+ * 1 - enabled (if previously disabled, also default)
+ * 0 - disabled
+ */
+
+static void ps2pp_set_smartscroll(struct psmouse *psmouse, unsigned int smartscroll)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[4];
+
+ if (smartscroll > 1)
+ smartscroll = 1;
+
+ ps2pp_cmd(psmouse, param, 0x32);
+
+ param[0] = 0;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+
+ param[0] = smartscroll;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+}
+
+static ssize_t psmouse_attr_show_smartscroll(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->smartscroll ? 1 : 0);
+}
+
+static ssize_t psmouse_attr_set_smartscroll(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest || value > 1)
+ return -EINVAL;
+
+ ps2pp_set_smartscroll(psmouse, value);
+ psmouse->smartscroll = value;
+ return count;
+}
+
+PSMOUSE_DEFINE_ATTR(smartscroll);
+
+/*
+ * Support 800 dpi resolution _only_ if the user wants it (there are good
+ * reasons to not use it even if the mouse supports it, and of course there are
+ * also good reasons to use it, let the user decide).
+ */
+
+static void ps2pp_set_resolution(struct psmouse *psmouse, unsigned int resolution)
+{
+ if (resolution > 400) {
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param = 3;
+
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
+ psmouse->resolution = 800;
+ } else
+ psmouse_set_resolution(psmouse, resolution);
+}
+
+static void ps2pp_disconnect(struct psmouse *psmouse)
+{
+ device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+}
+
+static struct ps2pp_info *get_model_info(unsigned char model)
+{
+ static struct ps2pp_info ps2pp_list[] = {
+ { 12, 0, PS2PP_SIDE_BTN},
+ { 13, 0, 0 },
+ { 15, PS2PP_KIND_MX, /* MX1000 */
+ PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
+ PS2PP_EXTRA_BTN | PS2PP_NAV_BTN | PS2PP_HWHEEL },
+ { 40, 0, PS2PP_SIDE_BTN },
+ { 41, 0, PS2PP_SIDE_BTN },
+ { 42, 0, PS2PP_SIDE_BTN },
+ { 43, 0, PS2PP_SIDE_BTN },
+ { 50, 0, 0 },
+ { 51, 0, 0 },
+ { 52, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL },
+ { 53, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
+ { 61, PS2PP_KIND_MX, /* MX700 */
+ PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
+ PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
+ { 73, 0, PS2PP_SIDE_BTN },
+ { 75, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
+ { 76, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
+ { 80, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL },
+ { 81, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
+ { 83, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
+ { 88, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
+ { 96, 0, 0 },
+ { 97, PS2PP_KIND_TP3, PS2PP_WHEEL | PS2PP_HWHEEL },
+ { 100, PS2PP_KIND_MX, /* MX510 */
+ PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
+ PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
+ { 111, PS2PP_KIND_MX, /* MX300 */
+ PS2PP_WHEEL | PS2PP_EXTRA_BTN | PS2PP_TASK_BTN },
+ { 112, PS2PP_KIND_MX, /* MX500 */
+ PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
+ PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
+ { 114, PS2PP_KIND_MX, /* MX310 */
+ PS2PP_WHEEL | PS2PP_SIDE_BTN |
+ PS2PP_TASK_BTN | PS2PP_EXTRA_BTN },
+ { }
+ };
+ int i;
+
+ for (i = 0; ps2pp_list[i].model; i++)
+ if (model == ps2pp_list[i].model)
+ return &ps2pp_list[i];
+
+ printk(KERN_WARNING "logips2pp: Detected unknown logitech mouse model %d\n", model);
+ return NULL;
+}
+
+/*
+ * Set up input device's properties based on the detected mouse model.
+ */
+
+static void ps2pp_set_model_properties(struct psmouse *psmouse, struct ps2pp_info *model_info,
+ int using_ps2pp)
+{
+ if (model_info->features & PS2PP_SIDE_BTN)
+ set_bit(BTN_SIDE, psmouse->dev.keybit);
+
+ if (model_info->features & PS2PP_EXTRA_BTN)
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+
+ if (model_info->features & PS2PP_TASK_BTN)
+ set_bit(BTN_TASK, psmouse->dev.keybit);
+
+ if (model_info->features & PS2PP_NAV_BTN) {
+ set_bit(BTN_FORWARD, psmouse->dev.keybit);
+ set_bit(BTN_BACK, psmouse->dev.keybit);
+ }
+
+ if (model_info->features & PS2PP_WHEEL)
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+
+ if (model_info->features & PS2PP_HWHEEL)
+ set_bit(REL_HWHEEL, psmouse->dev.relbit);
+
+ switch (model_info->kind) {
+ case PS2PP_KIND_WHEEL:
+ psmouse->name = "Wheel Mouse";
+ break;
+
+ case PS2PP_KIND_MX:
+ psmouse->name = "MX Mouse";
+ break;
+
+ case PS2PP_KIND_TP3:
+ psmouse->name = "TouchPad 3";
+ break;
+
+ default:
+ /*
+ * Set name to "Mouse" only when using PS2++,
+ * otherwise let other protocols define suitable
+ * name
+ */
+ if (using_ps2pp)
+ psmouse->name = "Mouse";
+ break;
+ }
+}
+
+
+/*
+ * Logitech magic init. Detect whether the mouse is a Logitech one
+ * and its exact model and try turning on extended protocol for ones
+ * that support it.
+ */
+
+int ps2pp_init(struct psmouse *psmouse, int set_properties)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[4];
+ unsigned char model, buttons;
+ struct ps2pp_info *model_info;
+ int use_ps2pp = 0;
+
+ param[0] = 0;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ param[1] = 0;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
+
+ if (!param[1])
+ return -1;
+
+ model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78);
+ buttons = param[1];
+
+ if ((model_info = get_model_info(model)) != NULL) {
+
+/*
+ * Do Logitech PS2++ / PS2T++ magic init.
+ */
+ if (model == 97) { /* Touch Pad 3 */
+
+ /* Unprotect RAM */
+ param[0] = 0x11; param[1] = 0x04; param[2] = 0x68;
+ ps2_command(ps2dev, param, 0x30d1);
+ /* Enable features */
+ param[0] = 0x11; param[1] = 0x05; param[2] = 0x0b;
+ ps2_command(ps2dev, param, 0x30d1);
+ /* Enable PS2++ */
+ param[0] = 0x11; param[1] = 0x09; param[2] = 0xc3;
+ ps2_command(ps2dev, param, 0x30d1);
+
+ param[0] = 0;
+ if (!ps2_command(ps2dev, param, 0x13d1) &&
+ param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) {
+ use_ps2pp = 1;
+ }
+
+ } else {
+
+ param[0] = param[1] = param[2] = 0;
+ ps2pp_cmd(psmouse, param, 0x39); /* Magic knock */
+ ps2pp_cmd(psmouse, param, 0xDB);
+
+ if ((param[0] & 0x78) == 0x48 &&
+ (param[1] & 0xf3) == 0xc2 &&
+ (param[2] & 0x03) == ((param[1] >> 2) & 3)) {
+ ps2pp_set_smartscroll(psmouse, psmouse->smartscroll);
+ use_ps2pp = 1;
+ }
+ }
+ }
+
+ if (set_properties) {
+ psmouse->vendor = "Logitech";
+ psmouse->model = model;
+
+ if (use_ps2pp) {
+ psmouse->protocol_handler = ps2pp_process_byte;
+ psmouse->pktsize = 3;
+
+ if (model_info->kind != PS2PP_KIND_TP3) {
+ psmouse->set_resolution = ps2pp_set_resolution;
+ psmouse->disconnect = ps2pp_disconnect;
+
+ device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+ }
+ }
+
+ if (buttons < 3)
+ clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
+ if (buttons < 2)
+ clear_bit(BTN_RIGHT, psmouse->dev.keybit);
+
+ if (model_info)
+ ps2pp_set_model_properties(psmouse, model_info, use_ps2pp);
+ }
+
+ return use_ps2pp ? 0 : -1;
+}
+
diff --git a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
new file mode 100644
index 0000000..64a8ec5
--- /dev/null
+++ b/drivers/input/mouse/logips2pp.h
@@ -0,0 +1,16 @@
+/*
+ * Logitech PS/2++ mouse driver header
+ *
+ * Copyright (c) 2003 Vojtech Pavlik <vojtech@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef _LOGIPS2PP_H
+#define _LOGIPS2PP_H
+
+int ps2pp_init(struct psmouse *psmouse, int set_properties);
+
+#endif
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
new file mode 100644
index 0000000..12dc0ef
--- /dev/null
+++ b/drivers/input/mouse/maplemouse.c
@@ -0,0 +1,134 @@
+/*
+ * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $
+ * SEGA Dreamcast mouse driver
+ * Based on drivers/usb/usbmouse.c
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/maple.h>
+
+MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
+MODULE_DESCRIPTION("SEGA Dreamcast mouse driver");
+
+struct dc_mouse {
+ struct input_dev dev;
+ int open;
+};
+
+
+static void dc_mouse_callback(struct mapleq *mq)
+{
+ int buttons, relx, rely, relz;
+ struct maple_device *mapledev = mq->dev;
+ struct dc_mouse *mouse = mapledev->private_data;
+ struct input_dev *dev = &mouse->dev;
+ unsigned char *res = mq->recvbuf;
+
+ buttons = ~res[8];
+ relx=*(unsigned short *)(res+12)-512;
+ rely=*(unsigned short *)(res+14)-512;
+ relz=*(unsigned short *)(res+16)-512;
+
+ input_report_key(dev, BTN_LEFT, buttons&4);
+ input_report_key(dev, BTN_MIDDLE, buttons&9);
+ input_report_key(dev, BTN_RIGHT, buttons&2);
+ input_report_rel(dev, REL_X, relx);
+ input_report_rel(dev, REL_Y, rely);
+ input_report_rel(dev, REL_WHEEL, relz);
+ input_sync(dev);
+}
+
+
+static int dc_mouse_open(struct input_dev *dev)
+{
+ struct dc_mouse *mouse = dev->private;
+ mouse->open++;
+ return 0;
+}
+
+
+static void dc_mouse_close(struct input_dev *dev)
+{
+ struct dc_mouse *mouse = dev->private;
+ mouse->open--;
+}
+
+
+static int dc_mouse_connect(struct maple_device *dev)
+{
+ unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
+ struct dc_mouse *mouse;
+
+ if (!(mouse = kmalloc(sizeof(struct dc_mouse), GFP_KERNEL)))
+ return -1;
+ memset(mouse, 0, sizeof(struct dc_mouse));
+
+ dev->private_data = mouse;
+
+ mouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+ mouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
+ mouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
+
+ init_input_dev(&mouse->dev);
+
+ mouse->dev.private = mouse;
+ mouse->dev.open = dc_mouse_open;
+ mouse->dev.close = dc_mouse_close;
+ mouse->dev.event = NULL;
+
+ mouse->dev.name = dev->product_name;
+ mouse->dev.id.bustype = BUS_MAPLE;
+
+ input_register_device(&mouse->dev);
+
+ maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
+
+ printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, mouse->dev.name);
+
+ return 0;
+}
+
+
+static void dc_mouse_disconnect(struct maple_device *dev)
+{
+ struct dc_mouse *mouse = dev->private_data;
+
+ input_unregister_device(&mouse->dev);
+ kfree(mouse);
+}
+
+
+static struct maple_driver dc_mouse_driver = {
+ .function = MAPLE_FUNC_MOUSE,
+ .name = "Dreamcast mouse",
+ .connect = dc_mouse_connect,
+ .disconnect = dc_mouse_disconnect,
+};
+
+
+static int __init dc_mouse_init(void)
+{
+ maple_register_driver(&dc_mouse_driver);
+ return 0;
+}
+
+
+static void __exit dc_mouse_exit(void)
+{
+ maple_unregister_driver(&dc_mouse_driver);
+}
+
+
+module_init(dc_mouse_init);
+module_exit(dc_mouse_exit);
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
new file mode 100644
index 0000000..0c74918
--- /dev/null
+++ b/drivers/input/mouse/pc110pad.c
@@ -0,0 +1,178 @@
+/*
+ * $Id: pc110pad.c,v 1.12 2001/09/25 10:12:07 vojtech Exp $
+ *
+ * Copyright (c) 2000-2001 Vojtech Pavlik
+ *
+ * Based on the work of:
+ * Alan Cox Robin O'Leary
+ */
+
+/*
+ * IBM PC110 touchpad driver for Linux
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Should you need to contact me, the author, you can do so either by
+ * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
+ * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/ioport.h>
+#include <linux/input.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
+MODULE_DESCRIPTION("IBM PC110 touchpad driver");
+MODULE_LICENSE("GPL");
+
+#define PC110PAD_OFF 0x30
+#define PC110PAD_ON 0x38
+
+static int pc110pad_irq = 10;
+static int pc110pad_io = 0x15e0;
+
+static struct input_dev pc110pad_dev;
+static int pc110pad_data[3];
+static int pc110pad_count;
+static int pc110pad_used;
+
+static char *pc110pad_name = "IBM PC110 TouchPad";
+static char *pc110pad_phys = "isa15e0/input0";
+
+static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
+{
+ int value = inb_p(pc110pad_io);
+ int handshake = inb_p(pc110pad_io + 2);
+
+ outb_p(handshake | 1, pc110pad_io + 2);
+ outb_p(handshake & ~1, pc110pad_io + 2);
+ inb_p(0x64);
+
+ pc110pad_data[pc110pad_count++] = value;
+
+ if (pc110pad_count < 3)
+ return IRQ_HANDLED;
+
+ input_regs(&pc110pad_dev, regs);
+ input_report_key(&pc110pad_dev, BTN_TOUCH,
+ pc110pad_data[0] & 0x01);
+ input_report_abs(&pc110pad_dev, ABS_X,
+ pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
+ input_report_abs(&pc110pad_dev, ABS_Y,
+ pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
+ input_sync(&pc110pad_dev);
+
+ pc110pad_count = 0;
+ return IRQ_HANDLED;
+}
+
+static void pc110pad_close(struct input_dev *dev)
+{
+ if (!--pc110pad_used)
+ outb(PC110PAD_OFF, pc110pad_io + 2);
+}
+
+static int pc110pad_open(struct input_dev *dev)
+{
+ if (pc110pad_used++)
+ return 0;
+
+ pc110pad_interrupt(0,NULL,NULL);
+ pc110pad_interrupt(0,NULL,NULL);
+ pc110pad_interrupt(0,NULL,NULL);
+ outb(PC110PAD_ON, pc110pad_io + 2);
+ pc110pad_count = 0;
+
+ return 0;
+}
+
+/*
+ * We try to avoid enabling the hardware if it's not
+ * there, but we don't know how to test. But we do know
+ * that the PC110 is not a PCI system. So if we find any
+ * PCI devices in the machine, we don't have a PC110.
+ */
+static int __init pc110pad_init(void)
+{
+ struct pci_dev *dev;
+
+ dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
+ if (dev) {
+ pci_dev_put(dev);
+ return -ENOENT;
+ }
+
+ if (!request_region(pc110pad_io, 4, "pc110pad")) {
+ printk(KERN_ERR "pc110pad: I/O area %#x-%#x in use.\n",
+ pc110pad_io, pc110pad_io + 4);
+ return -EBUSY;
+ }
+
+ outb(PC110PAD_OFF, pc110pad_io + 2);
+
+ if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL))
+ {
+ release_region(pc110pad_io, 4);
+ printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
+ return -EBUSY;
+ }
+
+ pc110pad_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
+ pc110pad_dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
+ pc110pad_dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
+
+ pc110pad_dev.absmax[ABS_X] = 0x1ff;
+ pc110pad_dev.absmax[ABS_Y] = 0x0ff;
+
+ pc110pad_dev.open = pc110pad_open;
+ pc110pad_dev.close = pc110pad_close;
+
+ pc110pad_dev.name = pc110pad_name;
+ pc110pad_dev.phys = pc110pad_phys;
+ pc110pad_dev.id.bustype = BUS_ISA;
+ pc110pad_dev.id.vendor = 0x0003;
+ pc110pad_dev.id.product = 0x0001;
+ pc110pad_dev.id.version = 0x0100;
+
+ input_register_device(&pc110pad_dev);
+
+ printk(KERN_INFO "input: %s at %#x irq %d\n",
+ pc110pad_name, pc110pad_io, pc110pad_irq);
+
+ return 0;
+}
+
+static void __exit pc110pad_exit(void)
+{
+ input_unregister_device(&pc110pad_dev);
+
+ outb(PC110PAD_OFF, pc110pad_io + 2);
+
+ free_irq(pc110pad_irq, NULL);
+ release_region(pc110pad_io, 4);
+}
+
+module_init(pc110pad_init);
+module_exit(pc110pad_exit);
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
new file mode 100644
index 0000000..cd85095
--- /dev/null
+++ b/drivers/input/mouse/psmouse-base.c
@@ -0,0 +1,1011 @@
+/*
+ * PS/2 mouse driver
+ *
+ * Copyright (c) 1999-2002 Vojtech Pavlik
+ * Copyright (c) 2003-2004 Dmitry Torokhov
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/serio.h>
+#include <linux/init.h>
+#include <linux/libps2.h>
+#include "psmouse.h"
+#include "synaptics.h"
+#include "logips2pp.h"
+#include "alps.h"
+
+#define DRIVER_DESC "PS/2 mouse driver"
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+
+static unsigned int psmouse_max_proto = -1U;
+static int psmouse_set_maxproto(const char *val, struct kernel_param *kp);
+static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp);
+static char *psmouse_proto_abbrev[] = { NULL, "bare", NULL, NULL, NULL, "imps", "exps", NULL, NULL, NULL };
+#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
+#define param_set_proto_abbrev psmouse_set_maxproto
+#define param_get_proto_abbrev psmouse_get_maxproto
+module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
+MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
+
+static unsigned int psmouse_resolution = 200;
+module_param_named(resolution, psmouse_resolution, uint, 0644);
+MODULE_PARM_DESC(resolution, "Resolution, in dpi.");
+
+static unsigned int psmouse_rate = 100;
+module_param_named(rate, psmouse_rate, uint, 0644);
+MODULE_PARM_DESC(rate, "Report rate, in reports per second.");
+
+static unsigned int psmouse_smartscroll = 1;
+module_param_named(smartscroll, psmouse_smartscroll, bool, 0644);
+MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
+
+static unsigned int psmouse_resetafter;
+module_param_named(resetafter, psmouse_resetafter, uint, 0644);
+MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
+
+PSMOUSE_DEFINE_ATTR(rate);
+PSMOUSE_DEFINE_ATTR(resolution);
+PSMOUSE_DEFINE_ATTR(resetafter);
+
+__obsolete_setup("psmouse_noext");
+__obsolete_setup("psmouse_resolution=");
+__obsolete_setup("psmouse_smartscroll=");
+__obsolete_setup("psmouse_resetafter=");
+__obsolete_setup("psmouse_rate=");
+
+static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2" };
+
+/*
+ * psmouse_process_byte() analyzes the PS/2 data stream and reports
+ * relevant events to the input module once full packet has arrived.
+ */
+
+static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
+{
+ struct input_dev *dev = &psmouse->dev;
+ unsigned char *packet = psmouse->packet;
+
+ if (psmouse->pktcnt < psmouse->pktsize)
+ return PSMOUSE_GOOD_DATA;
+
+/*
+ * Full packet accumulated, process it
+ */
+
+ input_regs(dev, regs);
+
+/*
+ * Scroll wheel on IntelliMice, scroll buttons on NetMice
+ */
+
+ if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS)
+ input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
+
+/*
+ * Scroll wheel and buttons on IntelliMouse Explorer
+ */
+
+ if (psmouse->type == PSMOUSE_IMEX) {
+ input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7));
+ input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1);
+ input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1);
+ }
+
+/*
+ * Extra buttons on Genius NewNet 3D
+ */
+
+ if (psmouse->type == PSMOUSE_GENPS) {
+ input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
+ input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
+ }
+
+/*
+ * Extra button on ThinkingMouse
+ */
+ if (psmouse->type == PSMOUSE_THINKPS) {
+ input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1);
+ /* Without this bit of weirdness moving up gives wildly high Y changes. */
+ packet[1] |= (packet[0] & 0x40) << 1;
+ }
+
+/*
+ * Generic PS/2 Mouse
+ */
+
+ input_report_key(dev, BTN_LEFT, packet[0] & 1);
+ input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
+ input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
+
+ input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
+ input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
+
+ input_sync(dev);
+
+ return PSMOUSE_FULL_PACKET;
+}
+
+/*
+ * psmouse_interrupt() handles incoming characters, either gathering them into
+ * packets or passing them to the command routine as command output.
+ */
+
+static irqreturn_t psmouse_interrupt(struct serio *serio,
+ unsigned char data, unsigned int flags, struct pt_regs *regs)
+{
+ struct psmouse *psmouse = serio_get_drvdata(serio);
+ psmouse_ret_t rc;
+
+ if (psmouse->state == PSMOUSE_IGNORE)
+ goto out;
+
+ if (flags & (SERIO_PARITY|SERIO_TIMEOUT)) {
+ if (psmouse->state == PSMOUSE_ACTIVATED)
+ printk(KERN_WARNING "psmouse.c: bad data from KBC -%s%s\n",
+ flags & SERIO_TIMEOUT ? " timeout" : "",
+ flags & SERIO_PARITY ? " bad parity" : "");
+ ps2_cmd_aborted(&psmouse->ps2dev);
+ goto out;
+ }
+
+ if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK))
+ if (ps2_handle_ack(&psmouse->ps2dev, data))
+ goto out;
+
+ if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_CMD))
+ if (ps2_handle_response(&psmouse->ps2dev, data))
+ goto out;
+
+ if (psmouse->state == PSMOUSE_INITIALIZING)
+ goto out;
+
+ if (psmouse->state == PSMOUSE_ACTIVATED &&
+ psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
+ printk(KERN_WARNING "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n",
+ psmouse->name, psmouse->phys, psmouse->pktcnt);
+ psmouse->pktcnt = 0;
+ }
+
+ psmouse->last = jiffies;
+ psmouse->packet[psmouse->pktcnt++] = data;
+
+ if (psmouse->packet[0] == PSMOUSE_RET_BAT) {
+ if (psmouse->pktcnt == 1)
+ goto out;
+
+ if (psmouse->pktcnt == 2) {
+ if (psmouse->packet[1] == PSMOUSE_RET_ID) {
+ psmouse->state = PSMOUSE_IGNORE;
+ serio_reconnect(serio);
+ goto out;
+ }
+ if (psmouse->type == PSMOUSE_SYNAPTICS) {
+ /* neither 0xAA nor 0x00 are valid first bytes
+ * for a packet in absolute mode
+ */
+ psmouse->pktcnt = 0;
+ goto out;
+ }
+ }
+ }
+
+ rc = psmouse->protocol_handler(psmouse, regs);
+
+ switch (rc) {
+ case PSMOUSE_BAD_DATA:
+ printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n",
+ psmouse->name, psmouse->phys, psmouse->pktcnt);
+ psmouse->pktcnt = 0;
+
+ if (++psmouse->out_of_sync == psmouse->resetafter) {
+ psmouse->state = PSMOUSE_IGNORE;
+ printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n");
+ serio_reconnect(psmouse->ps2dev.serio);
+ }
+ break;
+
+ case PSMOUSE_FULL_PACKET:
+ psmouse->pktcnt = 0;
+ if (psmouse->out_of_sync) {
+ psmouse->out_of_sync = 0;
+ printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n",
+ psmouse->name, psmouse->phys);
+ }
+ break;
+
+ case PSMOUSE_GOOD_DATA:
+ break;
+ }
+out:
+ return IRQ_HANDLED;
+}
+
+
+/*
+ * psmouse_sliced_command() sends an extended PS/2 command to the mouse
+ * using sliced syntax, understood by advanced devices, such as Logitech
+ * or Synaptics touchpads. The command is encoded as:
+ * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
+ * is the command.
+ */
+int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command)
+{
+ int i;
+
+ if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
+ return -1;
+
+ for (i = 6; i >= 0; i -= 2) {
+ unsigned char d = (command >> i) & 3;
+ if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES))
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/*
+ * psmouse_reset() resets the mouse into power-on state.
+ */
+int psmouse_reset(struct psmouse *psmouse)
+{
+ unsigned char param[2];
+
+ if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT))
+ return -1;
+
+ if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID)
+ return -1;
+
+ return 0;
+}
+
+
+/*
+ * Genius NetMouse magic init.
+ */
+static int genius_detect(struct psmouse *psmouse, int set_properties)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[4];
+
+ param[0] = 3;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
+
+ if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55)
+ return -1;
+
+ if (set_properties) {
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+ set_bit(BTN_SIDE, psmouse->dev.keybit);
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+
+ psmouse->vendor = "Genius";
+ psmouse->name = "Wheel Mouse";
+ psmouse->pktsize = 4;
+ }
+
+ return 0;
+}
+
+/*
+ * IntelliMouse magic init.
+ */
+static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[2];
+
+ param[0] = 200;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ param[0] = 100;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ param[0] = 80;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
+
+ if (param[0] != 3)
+ return -1;
+
+ if (set_properties) {
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+
+ if (!psmouse->vendor) psmouse->vendor = "Generic";
+ if (!psmouse->name) psmouse->name = "Wheel Mouse";
+ psmouse->pktsize = 4;
+ }
+
+ return 0;
+}
+
+/*
+ * Try IntelliMouse/Explorer magic init.
+ */
+static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[2];
+
+ intellimouse_detect(psmouse, 0);
+
+ param[0] = 200;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ param[0] = 200;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ param[0] = 80;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
+
+ if (param[0] != 4)
+ return -1;
+
+ if (set_properties) {
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+ set_bit(BTN_SIDE, psmouse->dev.keybit);
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+
+ if (!psmouse->vendor) psmouse->vendor = "Generic";
+ if (!psmouse->name) psmouse->name = "Explorer Mouse";
+ psmouse->pktsize = 4;
+ }
+
+ return 0;
+}
+
+/*
+ * Kensington ThinkingMouse / ExpertMouse magic init.
+ */
+static int thinking_detect(struct psmouse *psmouse, int set_properties)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[2];
+ unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20, 0 };
+ int i;
+
+ param[0] = 10;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
+ param[0] = 0;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ for (i = 0; seq[i]; i++)
+ ps2_command(ps2dev, seq + i, PSMOUSE_CMD_SETRATE);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
+
+ if (param[0] != 2)
+ return -1;
+
+ if (set_properties) {
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+
+ psmouse->vendor = "Kensington";
+ psmouse->name = "ThinkingMouse";
+ }
+
+ return 0;
+}
+
+/*
+ * Bare PS/2 protocol "detection". Always succeeds.
+ */
+static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
+{
+ if (!psmouse->vendor) psmouse->vendor = "Generic";
+ if (!psmouse->name) psmouse->name = "Mouse";
+
+ return 0;
+}
+
+/*
+ * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
+ * the mouse may have.
+ */
+
+static int psmouse_extensions(struct psmouse *psmouse,
+ unsigned int max_proto, int set_properties)
+{
+ int synaptics_hardware = 0;
+
+/*
+ * Try Kensington ThinkingMouse (we try first, because synaptics probe
+ * upsets the thinkingmouse).
+ */
+
+ if (max_proto > PSMOUSE_IMEX && thinking_detect(psmouse, set_properties) == 0)
+ return PSMOUSE_THINKPS;
+
+/*
+ * Try Synaptics TouchPad
+ */
+ if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) {
+ synaptics_hardware = 1;
+
+ if (max_proto > PSMOUSE_IMEX) {
+ if (!set_properties || synaptics_init(psmouse) == 0)
+ return PSMOUSE_SYNAPTICS;
+/*
+ * Some Synaptics touchpads can emulate extended protocols (like IMPS/2).
+ * Unfortunately Logitech/Genius probes confuse some firmware versions so
+ * we'll have to skip them.
+ */
+ max_proto = PSMOUSE_IMEX;
+ }
+/*
+ * Make sure that touchpad is in relative mode, gestures (taps) are enabled
+ */
+ synaptics_reset(psmouse);
+ }
+
+/*
+ * Try ALPS TouchPad
+ */
+ if (max_proto > PSMOUSE_IMEX) {
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
+ if (alps_detect(psmouse, set_properties) == 0) {
+ if (!set_properties || alps_init(psmouse) == 0)
+ return PSMOUSE_ALPS;
+/*
+ * Init failed, try basic relative protocols
+ */
+ max_proto = PSMOUSE_IMEX;
+ }
+ }
+
+ if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse, set_properties) == 0)
+ return PSMOUSE_GENPS;
+
+ if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties) == 0)
+ return PSMOUSE_PS2PP;
+
+/*
+ * Reset to defaults in case the device got confused by extended
+ * protocol probes.
+ */
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
+
+ if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0)
+ return PSMOUSE_IMEX;
+
+ if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0)
+ return PSMOUSE_IMPS;
+
+/*
+ * Okay, all failed, we have a standard mouse here. The number of the buttons
+ * is still a question, though. We assume 3.
+ */
+ ps2bare_detect(psmouse, set_properties);
+
+ if (synaptics_hardware) {
+/*
+ * We detected Synaptics hardware but it did not respond to IMPS/2 probes.
+ * We need to reset the touchpad because if there is a track point on the
+ * pass through port it could get disabled while probing for protocol
+ * extensions.
+ */
+ psmouse_reset(psmouse);
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
+ }
+
+ return PSMOUSE_PS2;
+}
+
+/*
+ * psmouse_probe() probes for a PS/2 mouse.
+ */
+
+static int psmouse_probe(struct psmouse *psmouse)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[2];
+
+/*
+ * First, we check if it's a mouse. It should send 0x00 or 0x03
+ * in case of an IntelliMouse in 4-byte mode or 0x04 for IM Explorer.
+ */
+
+ param[0] = 0xa5;
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
+ return -1;
+
+ if (param[0] != 0x00 && param[0] != 0x03 && param[0] != 0x04)
+ return -1;
+
+/*
+ * Then we reset and disable the mouse so that it doesn't generate events.
+ */
+
+ if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS))
+ printk(KERN_WARNING "psmouse.c: Failed to reset mouse on %s\n", ps2dev->serio->phys);
+
+ return 0;
+}
+
+/*
+ * Here we set the mouse resolution.
+ */
+
+void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
+{
+ unsigned char params[] = { 0, 1, 2, 2, 3 };
+
+ if (resolution == 0 || resolution > 200)
+ resolution = 200;
+
+ ps2_command(&psmouse->ps2dev, &params[resolution / 50], PSMOUSE_CMD_SETRES);
+ psmouse->resolution = 25 << params[resolution / 50];
+}
+
+/*
+ * Here we set the mouse report rate.
+ */
+
+static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
+{
+ unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
+ int i = 0;
+
+ while (rates[i] > rate) i++;
+ ps2_command(&psmouse->ps2dev, &rates[i], PSMOUSE_CMD_SETRATE);
+ psmouse->rate = rates[i];
+}
+
+/*
+ * psmouse_initialize() initializes the mouse to a sane state.
+ */
+
+static void psmouse_initialize(struct psmouse *psmouse)
+{
+/*
+ * We set the mouse into streaming mode.
+ */
+
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM);
+
+/*
+ * We set the mouse report rate, resolution and scaling.
+ */
+
+ if (psmouse_max_proto != PSMOUSE_PS2) {
+ psmouse->set_rate(psmouse, psmouse->rate);
+ psmouse->set_resolution(psmouse, psmouse->resolution);
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ }
+}
+
+/*
+ * psmouse_set_state() sets new psmouse state and resets all flags and
+ * counters while holding serio lock so fighting with interrupt handler
+ * is not a concern.
+ */
+
+static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
+{
+ serio_pause_rx(psmouse->ps2dev.serio);
+ psmouse->state = new_state;
+ psmouse->pktcnt = psmouse->out_of_sync = 0;
+ psmouse->ps2dev.flags = 0;
+ serio_continue_rx(psmouse->ps2dev.serio);
+}
+
+/*
+ * psmouse_activate() enables the mouse so that we get motion reports from it.
+ */
+
+static void psmouse_activate(struct psmouse *psmouse)
+{
+ if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE))
+ printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n",
+ psmouse->ps2dev.serio->phys);
+
+ psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
+}
+
+
+/*
+ * psmouse_deactivate() puts the mouse into poll mode so that we don't get motion
+ * reports from it unless we explicitely request it.
+ */
+
+static void psmouse_deactivate(struct psmouse *psmouse)
+{
+ if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE))
+ printk(KERN_WARNING "psmouse.c: Failed to deactivate mouse on %s\n",
+ psmouse->ps2dev.serio->phys);
+
+ psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
+}
+
+
+/*
+ * psmouse_cleanup() resets the mouse into power-on state.
+ */
+
+static void psmouse_cleanup(struct serio *serio)
+{
+ struct psmouse *psmouse = serio_get_drvdata(serio);
+
+ psmouse_reset(psmouse);
+}
+
+/*
+ * psmouse_disconnect() closes and frees.
+ */
+
+static void psmouse_disconnect(struct serio *serio)
+{
+ struct psmouse *psmouse, *parent;
+
+ device_remove_file(&serio->dev, &psmouse_attr_rate);
+ device_remove_file(&serio->dev, &psmouse_attr_resolution);
+ device_remove_file(&serio->dev, &psmouse_attr_resetafter);
+
+ psmouse = serio_get_drvdata(serio);
+ psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
+
+ if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
+ parent = serio_get_drvdata(serio->parent);
+ if (parent->pt_deactivate)
+ parent->pt_deactivate(parent);
+ }
+
+ if (psmouse->disconnect)
+ psmouse->disconnect(psmouse);
+
+ psmouse_set_state(psmouse, PSMOUSE_IGNORE);
+
+ input_unregister_device(&psmouse->dev);
+ serio_close(serio);
+ serio_set_drvdata(serio, NULL);
+ kfree(psmouse);
+}
+
+/*
+ * psmouse_connect() is a callback from the serio module when
+ * an unhandled serio port is found.
+ */
+static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
+{
+ struct psmouse *psmouse, *parent = NULL;
+ int retval;
+
+ /*
+ * If this is a pass-through port deactivate parent so the device
+ * connected to this port can be successfully identified
+ */
+ if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
+ parent = serio_get_drvdata(serio->parent);
+ psmouse_deactivate(parent);
+ }
+
+ if (!(psmouse = kmalloc(sizeof(struct psmouse), GFP_KERNEL))) {
+ retval = -ENOMEM;
+ goto out;
+ }
+
+ memset(psmouse, 0, sizeof(struct psmouse));
+
+ ps2_init(&psmouse->ps2dev, serio);
+ sprintf(psmouse->phys, "%s/input0", serio->phys);
+ psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+ psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
+ psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
+ psmouse->dev.private = psmouse;
+ psmouse->dev.dev = &serio->dev;
+ psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
+
+ serio_set_drvdata(serio, psmouse);
+
+ retval = serio_open(serio, drv);
+ if (retval) {
+ serio_set_drvdata(serio, NULL);
+ kfree(psmouse);
+ goto out;
+ }
+
+ if (psmouse_probe(psmouse) < 0) {
+ serio_close(serio);
+ serio_set_drvdata(serio, NULL);
+ kfree(psmouse);
+ retval = -ENODEV;
+ goto out;
+ }
+
+ psmouse->rate = psmouse_rate;
+ psmouse->resolution = psmouse_resolution;
+ psmouse->resetafter = psmouse_resetafter;
+ psmouse->smartscroll = psmouse_smartscroll;
+ psmouse->set_rate = psmouse_set_rate;
+ psmouse->set_resolution = psmouse_set_resolution;
+ psmouse->protocol_handler = psmouse_process_byte;
+ psmouse->pktsize = 3;
+
+ psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
+
+ sprintf(psmouse->devname, "%s %s %s",
+ psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
+
+ psmouse->dev.name = psmouse->devname;
+ psmouse->dev.phys = psmouse->phys;
+ psmouse->dev.id.bustype = BUS_I8042;
+ psmouse->dev.id.vendor = 0x0002;
+ psmouse->dev.id.product = psmouse->type;
+ psmouse->dev.id.version = psmouse->model;
+
+ input_register_device(&psmouse->dev);
+
+ printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
+
+ psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
+
+ psmouse_initialize(psmouse);
+
+ if (parent && parent->pt_activate)
+ parent->pt_activate(parent);
+
+ device_create_file(&serio->dev, &psmouse_attr_rate);
+ device_create_file(&serio->dev, &psmouse_attr_resolution);
+ device_create_file(&serio->dev, &psmouse_attr_resetafter);
+
+ psmouse_activate(psmouse);
+
+ retval = 0;
+
+out:
+ /* If this is a pass-through port the parent awaits to be activated */
+ if (parent)
+ psmouse_activate(parent);
+
+ return retval;
+}
+
+
+static int psmouse_reconnect(struct serio *serio)
+{
+ struct psmouse *psmouse = serio_get_drvdata(serio);
+ struct psmouse *parent = NULL;
+ struct serio_driver *drv = serio->drv;
+ int rc = -1;
+
+ if (!drv || !psmouse) {
+ printk(KERN_DEBUG "psmouse: reconnect request, but serio is disconnected, ignoring...\n");
+ return -1;
+ }
+
+ if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
+ parent = serio_get_drvdata(serio->parent);
+ psmouse_deactivate(parent);
+ }
+
+ psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
+
+ if (psmouse->reconnect) {
+ if (psmouse->reconnect(psmouse))
+ goto out;
+ } else if (psmouse_probe(psmouse) < 0 ||
+ psmouse->type != psmouse_extensions(psmouse, psmouse_max_proto, 0))
+ goto out;
+
+ /* ok, the device type (and capabilities) match the old one,
+ * we can continue using it, complete intialization
+ */
+ psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
+
+ psmouse_initialize(psmouse);
+
+ if (parent && parent->pt_activate)
+ parent->pt_activate(parent);
+
+ psmouse_activate(psmouse);
+ rc = 0;
+
+out:
+ /* If this is a pass-through port the parent waits to be activated */
+ if (parent)
+ psmouse_activate(parent);
+
+ return rc;
+}
+
+static struct serio_device_id psmouse_serio_ids[] = {
+ {
+ .type = SERIO_8042,
+ .proto = SERIO_ANY,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_PS_PSTHRU,
+ .proto = SERIO_ANY,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ { 0 }
+};
+
+MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
+
+static struct serio_driver psmouse_drv = {
+ .driver = {
+ .name = "psmouse",
+ },
+ .description = DRIVER_DESC,
+ .id_table = psmouse_serio_ids,
+ .interrupt = psmouse_interrupt,
+ .connect = psmouse_connect,
+ .reconnect = psmouse_reconnect,
+ .disconnect = psmouse_disconnect,
+ .cleanup = psmouse_cleanup,
+};
+
+ssize_t psmouse_attr_show_helper(struct device *dev, char *buf,
+ ssize_t (*handler)(struct psmouse *, char *))
+{
+ struct serio *serio = to_serio_port(dev);
+ int retval;
+
+ retval = serio_pin_driver(serio);
+ if (retval)
+ return retval;
+
+ if (serio->drv != &psmouse_drv) {
+ retval = -ENODEV;
+ goto out;
+ }
+
+ retval = handler(serio_get_drvdata(serio), buf);
+
+out:
+ serio_unpin_driver(serio);
+ return retval;
+}
+
+ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count,
+ ssize_t (*handler)(struct psmouse *, const char *, size_t))
+{
+ struct serio *serio = to_serio_port(dev);
+ struct psmouse *psmouse = serio_get_drvdata(serio);
+ struct psmouse *parent = NULL;
+ int retval;
+
+ retval = serio_pin_driver(serio);
+ if (retval)
+ return retval;
+
+ if (serio->drv != &psmouse_drv) {
+ retval = -ENODEV;
+ goto out;
+ }
+
+ if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
+ parent = serio_get_drvdata(serio->parent);
+ psmouse_deactivate(parent);
+ }
+ psmouse_deactivate(psmouse);
+
+ retval = handler(psmouse, buf, count);
+
+ psmouse_activate(psmouse);
+ if (parent)
+ psmouse_activate(parent);
+
+out:
+ serio_unpin_driver(serio);
+ return retval;
+}
+
+static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->rate);
+}
+
+static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest)
+ return -EINVAL;
+
+ psmouse->set_rate(psmouse, value);
+ return count;
+}
+
+static ssize_t psmouse_attr_show_resolution(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->resolution);
+}
+
+static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest)
+ return -EINVAL;
+
+ psmouse->set_resolution(psmouse, value);
+ return count;
+}
+
+static ssize_t psmouse_attr_show_resetafter(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->resetafter);
+}
+
+static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest)
+ return -EINVAL;
+
+ psmouse->resetafter = value;
+ return count;
+}
+
+static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
+{
+ int i;
+
+ if (!val)
+ return -EINVAL;
+
+ if (!strncmp(val, "any", 3)) {
+ *((unsigned int *)kp->arg) = -1UL;
+ return 0;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(psmouse_proto_abbrev); i++) {
+ if (!psmouse_proto_abbrev[i])
+ continue;
+
+ if (!strncmp(val, psmouse_proto_abbrev[i], strlen(psmouse_proto_abbrev[i]))) {
+ *((unsigned int *)kp->arg) = i;
+ return 0;
+ }
+ }
+
+ return -EINVAL; \
+}
+
+static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
+{
+ return sprintf(buffer, "%s\n",
+ psmouse_max_proto < ARRAY_SIZE(psmouse_proto_abbrev) ?
+ psmouse_proto_abbrev[psmouse_max_proto] : "any");
+}
+
+static int __init psmouse_init(void)
+{
+ serio_register_driver(&psmouse_drv);
+ return 0;
+}
+
+static void __exit psmouse_exit(void)
+{
+ serio_unregister_driver(&psmouse_drv);
+}
+
+module_init(psmouse_init);
+module_exit(psmouse_exit);
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
new file mode 100644
index 0000000..bda5b06
--- /dev/null
+++ b/drivers/input/mouse/psmouse.h
@@ -0,0 +1,106 @@
+#ifndef _PSMOUSE_H
+#define _PSMOUSE_H
+
+#define PSMOUSE_CMD_SETSCALE11 0x00e6
+#define PSMOUSE_CMD_SETSCALE21 0x00e7
+#define PSMOUSE_CMD_SETRES 0x10e8
+#define PSMOUSE_CMD_GETINFO 0x03e9
+#define PSMOUSE_CMD_SETSTREAM 0x00ea
+#define PSMOUSE_CMD_SETPOLL 0x00f0
+#define PSMOUSE_CMD_POLL 0x03eb
+#define PSMOUSE_CMD_GETID 0x02f2
+#define PSMOUSE_CMD_SETRATE 0x10f3
+#define PSMOUSE_CMD_ENABLE 0x00f4
+#define PSMOUSE_CMD_DISABLE 0x00f5
+#define PSMOUSE_CMD_RESET_DIS 0x00f6
+#define PSMOUSE_CMD_RESET_BAT 0x02ff
+
+#define PSMOUSE_RET_BAT 0xaa
+#define PSMOUSE_RET_ID 0x00
+#define PSMOUSE_RET_ACK 0xfa
+#define PSMOUSE_RET_NAK 0xfe
+
+enum psmouse_state {
+ PSMOUSE_IGNORE,
+ PSMOUSE_INITIALIZING,
+ PSMOUSE_CMD_MODE,
+ PSMOUSE_ACTIVATED,
+};
+
+/* psmouse protocol handler return codes */
+typedef enum {
+ PSMOUSE_BAD_DATA,
+ PSMOUSE_GOOD_DATA,
+ PSMOUSE_FULL_PACKET
+} psmouse_ret_t;
+
+struct psmouse {
+ void *private;
+ struct input_dev dev;
+ struct ps2dev ps2dev;
+ char *vendor;
+ char *name;
+ unsigned char packet[8];
+ unsigned char pktcnt;
+ unsigned char pktsize;
+ unsigned char type;
+ unsigned int model;
+ unsigned long last;
+ unsigned long out_of_sync;
+ enum psmouse_state state;
+ char devname[64];
+ char phys[32];
+
+ unsigned int rate;
+ unsigned int resolution;
+ unsigned int resetafter;
+ unsigned int smartscroll; /* Logitech only */
+
+ psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse, struct pt_regs *regs);
+ void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
+ void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
+
+ int (*reconnect)(struct psmouse *psmouse);
+ void (*disconnect)(struct psmouse *psmouse);
+
+ void (*pt_activate)(struct psmouse *psmouse);
+ void (*pt_deactivate)(struct psmouse *psmouse);
+};
+
+enum psmouse_type {
+ PSMOUSE_NONE,
+ PSMOUSE_PS2,
+ PSMOUSE_PS2PP,
+ PSMOUSE_THINKPS,
+ PSMOUSE_GENPS,
+ PSMOUSE_IMPS,
+ PSMOUSE_IMEX,
+ PSMOUSE_SYNAPTICS,
+ PSMOUSE_ALPS,
+};
+
+int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
+int psmouse_reset(struct psmouse *psmouse);
+void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
+
+ssize_t psmouse_attr_show_helper(struct device *dev, char *buf,
+ ssize_t (*handler)(struct psmouse *, char *));
+ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count,
+ ssize_t (*handler)(struct psmouse *, const char *, size_t));
+
+#define PSMOUSE_DEFINE_ATTR(_name) \
+static ssize_t psmouse_attr_show_##_name(struct psmouse *, char *); \
+static ssize_t psmouse_attr_set_##_name(struct psmouse *, const char *, size_t);\
+static ssize_t psmouse_do_show_##_name(struct device *d, char *b) \
+{ \
+ return psmouse_attr_show_helper(d, b, psmouse_attr_show_##_name); \
+} \
+static ssize_t psmouse_do_set_##_name(struct device *d, const char *b, size_t s)\
+{ \
+ return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \
+} \
+static struct device_attribute psmouse_attr_##_name = \
+ __ATTR(_name, S_IWUSR | S_IRUGO, \
+ psmouse_do_show_##_name, psmouse_do_set_##_name);
+
+#endif /* _PSMOUSE_H */
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
new file mode 100644
index 0000000..7280f68
--- /dev/null
+++ b/drivers/input/mouse/rpcmouse.c
@@ -0,0 +1,107 @@
+/*
+ * Acorn RiscPC mouse driver for Linux/ARM
+ *
+ * Copyright (c) 2000-2002 Vojtech Pavlik
+ * Copyright (C) 1996-2002 Russell King
+ *
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This handles the Acorn RiscPCs mouse. We basically have a couple of
+ * hardware registers that track the sensor count for the X-Y movement and
+ * another register holding the button state. On every VSYNC interrupt we read
+ * the complete state and then work out if something has changed.
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <linux/input.h>
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/hardware/iomd.h>
+
+MODULE_AUTHOR("Vojtech Pavlik, Russell King");
+MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
+MODULE_LICENSE("GPL");
+
+static short rpcmouse_lastx, rpcmouse_lasty;
+
+static struct input_dev rpcmouse_dev = {
+ .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
+ .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
+ .relbit = { BIT(REL_X) | BIT(REL_Y) },
+ .name = "Acorn RiscPC Mouse",
+ .phys = "rpcmouse/input0",
+ .id = {
+ .bustype = BUS_HOST,
+ .vendor = 0x0005,
+ .product = 0x0001,
+ .version = 0x0100,
+ },
+};
+
+static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
+{
+ struct input_dev *dev = dev_id;
+ short x, y, dx, dy, b;
+
+ x = (short) iomd_readl(IOMD_MOUSEX);
+ y = (short) iomd_readl(IOMD_MOUSEY);
+ b = (short) (__raw_readl(0xe0310000) ^ 0x70);
+
+ dx = x - rpcmouse_lastx;
+ dy = y - rpcmouse_lasty;
+
+ rpcmouse_lastx = x;
+ rpcmouse_lasty = y;
+
+ input_regs(dev, regs);
+
+ input_report_rel(dev, REL_X, dx);
+ input_report_rel(dev, REL_Y, -dy);
+
+ input_report_key(dev, BTN_LEFT, b & 0x40);
+ input_report_key(dev, BTN_MIDDLE, b & 0x20);
+ input_report_key(dev, BTN_RIGHT, b & 0x10);
+
+ input_sync(dev);
+
+ return IRQ_HANDLED;
+}
+
+static int __init rpcmouse_init(void)
+{
+ init_input_dev(&rpcmouse_dev);
+
+ rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
+ rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
+
+ if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, SA_SHIRQ, "rpcmouse", &rpcmouse_dev)) {
+ printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
+ return -1;
+ }
+
+ input_register_device(&rpcmouse_dev);
+
+ printk(KERN_INFO "input: Acorn RiscPC mouse\n");
+
+ return 0;
+}
+
+static void __exit rpcmouse_exit(void)
+{
+ input_unregister_device(&rpcmouse_dev);
+ free_irq(IRQ_VSYNCPULSE, &rpcmouse_dev);
+}
+
+module_init(rpcmouse_init);
+module_exit(rpcmouse_exit);
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
new file mode 100644
index 0000000..d12b93a
--- /dev/null
+++ b/drivers/input/mouse/sermouse.c
@@ -0,0 +1,370 @@
+/*
+ * $Id: sermouse.c,v 1.17 2002/03/13 10:03:43 vojtech Exp $
+ *
+ * Copyright (c) 1999-2001 Vojtech Pavlik
+ */
+
+/*
+ * Serial mouse driver for Linux
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Should you need to contact me, the author, you can do so either by
+ * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
+ * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/config.h>
+#include <linux/serio.h>
+#include <linux/init.h>
+
+#define DRIVER_DESC "Serial mouse driver"
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+
+static char *sermouse_protocols[] = { "None", "Mouse Systems Mouse", "Sun Mouse", "Microsoft Mouse",
+ "Logitech M+ Mouse", "Microsoft MZ Mouse", "Logitech MZ+ Mouse",
+ "Logitech MZ++ Mouse"};
+
+struct sermouse {
+ struct input_dev dev;
+ signed char buf[8];
+ unsigned char count;
+ unsigned char type;
+ unsigned long last;
+ char phys[32];
+};
+
+/*
+ * sermouse_process_msc() analyzes the incoming MSC/Sun bytestream and
+ * applies some prediction to the data, resulting in 96 updates per
+ * second, which is as good as a PS/2 or USB mouse.
+ */
+
+static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
+{
+ struct input_dev *dev = &sermouse->dev;
+ signed char *buf = sermouse->buf;
+
+ input_regs(dev, regs);
+
+ switch (sermouse->count) {
+
+ case 0:
+ if ((data & 0xf8) != 0x80) return;
+ input_report_key(dev, BTN_LEFT, !(data & 4));
+ input_report_key(dev, BTN_RIGHT, !(data & 1));
+ input_report_key(dev, BTN_MIDDLE, !(data & 2));
+ break;
+
+ case 1:
+ case 3:
+ input_report_rel(dev, REL_X, data / 2);
+ input_report_rel(dev, REL_Y, -buf[1]);
+ buf[0] = data - data / 2;
+ break;
+
+ case 2:
+ case 4:
+ input_report_rel(dev, REL_X, buf[0]);
+ input_report_rel(dev, REL_Y, buf[1] - data);
+ buf[1] = data / 2;
+ break;
+ }
+
+ input_sync(dev);
+
+ if (++sermouse->count == (5 - ((sermouse->type == SERIO_SUN) << 1)))
+ sermouse->count = 0;
+}
+
+/*
+ * sermouse_process_ms() anlyzes the incoming MS(Z/+/++) bytestream and
+ * generates events. With prediction it gets 80 updates/sec, assuming
+ * standard 3-byte packets and 1200 bps.
+ */
+
+static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
+{
+ struct input_dev *dev = &sermouse->dev;
+ signed char *buf = sermouse->buf;
+
+ if (data & 0x40) sermouse->count = 0;
+
+ input_regs(dev, regs);
+
+ switch (sermouse->count) {
+
+ case 0:
+ buf[1] = data;
+ input_report_key(dev, BTN_LEFT, (data >> 5) & 1);
+ input_report_key(dev, BTN_RIGHT, (data >> 4) & 1);
+ break;
+
+ case 1:
+ buf[2] = data;
+ data = (signed char) (((buf[1] << 6) & 0xc0) | (data & 0x3f));
+ input_report_rel(dev, REL_X, data / 2);
+ input_report_rel(dev, REL_Y, buf[4]);
+ buf[3] = data - data / 2;
+ break;
+
+ case 2:
+ /* Guessing the state of the middle button on 3-button MS-protocol mice - ugly. */
+ if ((sermouse->type == SERIO_MS) && !data && !buf[2] && !((buf[0] & 0xf0) ^ buf[1]))
+ input_report_key(dev, BTN_MIDDLE, !test_bit(BTN_MIDDLE, dev->key));
+ buf[0] = buf[1];
+
+ data = (signed char) (((buf[1] << 4) & 0xc0) | (data & 0x3f));
+ input_report_rel(dev, REL_X, buf[3]);
+ input_report_rel(dev, REL_Y, data - buf[4]);
+ buf[4] = data / 2;
+ break;
+
+ case 3:
+
+ switch (sermouse->type) {
+
+ case SERIO_MS:
+ sermouse->type = SERIO_MP;
+
+ case SERIO_MP:
+ if ((data >> 2) & 3) break; /* M++ Wireless Extension packet. */
+ input_report_key(dev, BTN_MIDDLE, (data >> 5) & 1);
+ input_report_key(dev, BTN_SIDE, (data >> 4) & 1);
+ break;
+
+ case SERIO_MZP:
+ case SERIO_MZPP:
+ input_report_key(dev, BTN_SIDE, (data >> 5) & 1);
+
+ case SERIO_MZ:
+ input_report_key(dev, BTN_MIDDLE, (data >> 4) & 1);
+ input_report_rel(dev, REL_WHEEL, (data & 8) - (data & 7));
+ break;
+ }
+
+ break;
+
+ case 4:
+ case 6: /* MZ++ packet type. We can get these bytes for M++ too but we ignore them later. */
+ buf[1] = (data >> 2) & 0x0f;
+ break;
+
+ case 5:
+ case 7: /* Ignore anything besides MZ++ */
+ if (sermouse->type != SERIO_MZPP) break;
+
+ switch (buf[1]) {
+
+ case 1: /* Extra mouse info */
+
+ input_report_key(dev, BTN_SIDE, (data >> 4) & 1);
+ input_report_key(dev, BTN_EXTRA, (data >> 5) & 1);
+ input_report_rel(dev, data & 0x80 ? REL_HWHEEL : REL_WHEEL, (data & 7) - (data & 8));
+
+ break;
+
+ default: /* We don't decode anything else yet. */
+
+ printk(KERN_WARNING
+ "sermouse.c: Received MZ++ packet %x, don't know how to handle.\n", buf[1]);
+ break;
+ }
+
+ break;
+ }
+
+ input_sync(dev);
+
+ sermouse->count++;
+}
+
+/*
+ * sermouse_interrupt() handles incoming characters, either gathering them into
+ * packets or passing them to the command routine as command output.
+ */
+
+static irqreturn_t sermouse_interrupt(struct serio *serio,
+ unsigned char data, unsigned int flags, struct pt_regs *regs)
+{
+ struct sermouse *sermouse = serio_get_drvdata(serio);
+
+ if (time_after(jiffies, sermouse->last + HZ/10)) sermouse->count = 0;
+ sermouse->last = jiffies;
+
+ if (sermouse->type > SERIO_SUN)
+ sermouse_process_ms(sermouse, data, regs);
+ else
+ sermouse_process_msc(sermouse, data, regs);
+ return IRQ_HANDLED;
+}
+
+/*
+ * sermouse_disconnect() cleans up after we don't want talk
+ * to the mouse anymore.
+ */
+
+static void sermouse_disconnect(struct serio *serio)
+{
+ struct sermouse *sermouse = serio_get_drvdata(serio);
+
+ input_unregister_device(&sermouse->dev);
+ serio_close(serio);
+ serio_set_drvdata(serio, NULL);
+ kfree(sermouse);
+}
+
+/*
+ * sermouse_connect() is a callback form the serio module when
+ * an unhandled serio port is found.
+ */
+
+static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
+{
+ struct sermouse *sermouse;
+ unsigned char c;
+ int err;
+
+ if (!serio->id.proto || serio->id.proto > SERIO_MZPP)
+ return -ENODEV;
+
+ if (!(sermouse = kmalloc(sizeof(struct sermouse), GFP_KERNEL)))
+ return -ENOMEM;
+
+ memset(sermouse, 0, sizeof(struct sermouse));
+
+ init_input_dev(&sermouse->dev);
+ sermouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+ sermouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
+ sermouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
+ sermouse->dev.private = sermouse;
+
+ sermouse->type = serio->id.proto;
+ c = serio->id.extra;
+
+ if (c & 0x01) set_bit(BTN_MIDDLE, sermouse->dev.keybit);
+ if (c & 0x02) set_bit(BTN_SIDE, sermouse->dev.keybit);
+ if (c & 0x04) set_bit(BTN_EXTRA, sermouse->dev.keybit);
+ if (c & 0x10) set_bit(REL_WHEEL, sermouse->dev.relbit);
+ if (c & 0x20) set_bit(REL_HWHEEL, sermouse->dev.relbit);
+
+ sprintf(sermouse->phys, "%s/input0", serio->phys);
+
+ sermouse->dev.name = sermouse_protocols[sermouse->type];
+ sermouse->dev.phys = sermouse->phys;
+ sermouse->dev.id.bustype = BUS_RS232;
+ sermouse->dev.id.vendor = sermouse->type;
+ sermouse->dev.id.product = c;
+ sermouse->dev.id.version = 0x0100;
+ sermouse->dev.dev = &serio->dev;
+
+ serio_set_drvdata(serio, sermouse);
+
+ err = serio_open(serio, drv);
+ if (err) {
+ serio_set_drvdata(serio, NULL);
+ kfree(sermouse);
+ return err;
+ }
+
+ input_register_device(&sermouse->dev);
+
+ printk(KERN_INFO "input: %s on %s\n", sermouse_protocols[sermouse->type], serio->phys);
+
+ return 0;
+}
+
+static struct serio_device_id sermouse_serio_ids[] = {
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_MSC,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_SUN,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_MS,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_MP,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_MZ,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_MZP,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_MZPP,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ { 0 }
+};
+
+MODULE_DEVICE_TABLE(serio, sermouse_serio_ids);
+
+static struct serio_driver sermouse_drv = {
+ .driver = {
+ .name = "sermouse",
+ },
+ .description = DRIVER_DESC,
+ .id_table = sermouse_serio_ids,
+ .interrupt = sermouse_interrupt,
+ .connect = sermouse_connect,
+ .disconnect = sermouse_disconnect,
+};
+
+static int __init sermouse_init(void)
+{
+ serio_register_driver(&sermouse_drv);
+ return 0;
+}
+
+static void __exit sermouse_exit(void)
+{
+ serio_unregister_driver(&sermouse_drv);
+}
+
+module_init(sermouse_init);
+module_exit(sermouse_exit);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
new file mode 100644
index 0000000..69832f8
--- /dev/null
+++ b/drivers/input/mouse/synaptics.c
@@ -0,0 +1,700 @@
+/*
+ * Synaptics TouchPad PS/2 mouse driver
+ *
+ * 2003 Dmitry Torokhov <dtor@mail.ru>
+ * Added support for pass-through port. Special thanks to Peter Berg Larsen
+ * for explaining various Synaptics quirks.
+ *
+ * 2003 Peter Osterlund <petero2@telia.com>
+ * Ported to 2.5 input device infrastructure.
+ *
+ * Copyright (C) 2001 Stefan Gmeiner <riddlebox@freesurf.ch>
+ * start merging tpconfig and gpm code to a xfree-input module
+ * adding some changes and extensions (ex. 3rd and 4th button)
+ *
+ * Copyright (c) 1997 C. Scott Ananian <cananian@alumni.priceton.edu>
+ * Copyright (c) 1998-2000 Bruce Kalk <kall@compass.com>
+ * code for the special synaptics commands (from the tpconfig-source)
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include <linux/module.h>
+#include <linux/input.h>
+#include <linux/serio.h>
+#include <linux/libps2.h>
+#include "psmouse.h"
+#include "synaptics.h"
+
+/*
+ * The x/y limits are taken from the Synaptics TouchPad interfacing Guide,
+ * section 2.3.2, which says that they should be valid regardless of the
+ * actual size of the sensor.
+ */
+#define XMIN_NOMINAL 1472
+#define XMAX_NOMINAL 5472
+#define YMIN_NOMINAL 1408
+#define YMAX_NOMINAL 4448
+
+/*****************************************************************************
+ * Synaptics communications functions
+ ****************************************************************************/
+
+/*
+ * Send a command to the synpatics touchpad by special commands
+ */
+static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, unsigned char *param)
+{
+ if (psmouse_sliced_command(psmouse, c))
+ return -1;
+ if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO))
+ return -1;
+ return 0;
+}
+
+/*
+ * Set the synaptics touchpad mode byte by special commands
+ */
+static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode)
+{
+ unsigned char param[1];
+
+ if (psmouse_sliced_command(psmouse, mode))
+ return -1;
+ param[0] = SYN_PS_SET_MODE2;
+ if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE))
+ return -1;
+ return 0;
+}
+
+/*
+ * Read the model-id bytes from the touchpad
+ * see also SYN_MODEL_* macros
+ */
+static int synaptics_model_id(struct psmouse *psmouse)
+{
+ struct synaptics_data *priv = psmouse->private;
+ unsigned char mi[3];
+
+ if (synaptics_send_cmd(psmouse, SYN_QUE_MODEL, mi))
+ return -1;
+ priv->model_id = (mi[0]<<16) | (mi[1]<<8) | mi[2];
+ return 0;
+}
+
+/*
+ * Read the capability-bits from the touchpad
+ * see also the SYN_CAP_* macros
+ */
+static int synaptics_capability(struct psmouse *psmouse)
+{
+ struct synaptics_data *priv = psmouse->private;
+ unsigned char cap[3];
+
+ if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap))
+ return -1;
+ priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2];
+ priv->ext_cap = 0;
+ if (!SYN_CAP_VALID(priv->capabilities))
+ return -1;
+
+ /*
+ * Unless capExtended is set the rest of the flags should be ignored
+ */
+ if (!SYN_CAP_EXTENDED(priv->capabilities))
+ priv->capabilities = 0;
+
+ if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) {
+ if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) {
+ printk(KERN_ERR "Synaptics claims to have extended capabilities,"
+ " but I'm not able to read them.");
+ } else {
+ priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2];
+
+ /*
+ * if nExtBtn is greater than 8 it should be considered
+ * invalid and treated as 0
+ */
+ if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) > 8)
+ priv->ext_cap &= 0xff0fff;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Identify Touchpad
+ * See also the SYN_ID_* macros
+ */
+static int synaptics_identify(struct psmouse *psmouse)
+{
+ struct synaptics_data *priv = psmouse->private;
+ unsigned char id[3];
+
+ if (synaptics_send_cmd(psmouse, SYN_QUE_IDENTIFY, id))
+ return -1;
+ priv->identity = (id[0]<<16) | (id[1]<<8) | id[2];
+ if (SYN_ID_IS_SYNAPTICS(priv->identity))
+ return 0;
+ return -1;
+}
+
+static void print_ident(struct synaptics_data *priv)
+{
+ printk(KERN_INFO "Synaptics Touchpad, model: %ld\n", SYN_ID_MODEL(priv->identity));
+ printk(KERN_INFO " Firmware: %ld.%ld\n", SYN_ID_MAJOR(priv->identity),
+ SYN_ID_MINOR(priv->identity));
+ if (SYN_MODEL_ROT180(priv->model_id))
+ printk(KERN_INFO " 180 degree mounted touchpad\n");
+ if (SYN_MODEL_PORTRAIT(priv->model_id))
+ printk(KERN_INFO " portrait touchpad\n");
+ printk(KERN_INFO " Sensor: %ld\n", SYN_MODEL_SENSOR(priv->model_id));
+ if (SYN_MODEL_NEWABS(priv->model_id))
+ printk(KERN_INFO " new absolute packet format\n");
+ if (SYN_MODEL_PEN(priv->model_id))
+ printk(KERN_INFO " pen detection\n");
+
+ if (SYN_CAP_EXTENDED(priv->capabilities)) {
+ printk(KERN_INFO " Touchpad has extended capability bits\n");
+ if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap))
+ printk(KERN_INFO " -> %d multi-buttons, i.e. besides standard buttons\n",
+ (int)(SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)));
+ if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
+ printk(KERN_INFO " -> middle button\n");
+ if (SYN_CAP_FOUR_BUTTON(priv->capabilities))
+ printk(KERN_INFO " -> four buttons\n");
+ if (SYN_CAP_MULTIFINGER(priv->capabilities))
+ printk(KERN_INFO " -> multifinger detection\n");
+ if (SYN_CAP_PALMDETECT(priv->capabilities))
+ printk(KERN_INFO " -> palm detection\n");
+ if (SYN_CAP_PASS_THROUGH(priv->capabilities))
+ printk(KERN_INFO " -> pass-through port\n");
+ }
+}
+
+static int synaptics_query_hardware(struct psmouse *psmouse)
+{
+ int retries = 0;
+
+ while ((retries++ < 3) && psmouse_reset(psmouse))
+ printk(KERN_ERR "synaptics reset failed\n");
+
+ if (synaptics_identify(psmouse))
+ return -1;
+ if (synaptics_model_id(psmouse))
+ return -1;
+ if (synaptics_capability(psmouse))
+ return -1;
+
+ return 0;
+}
+
+static int synaptics_set_absolute_mode(struct psmouse *psmouse)
+{
+ struct synaptics_data *priv = psmouse->private;
+
+ priv->mode = SYN_BIT_ABSOLUTE_MODE;
+ if (SYN_ID_MAJOR(priv->identity) >= 4)
+ priv->mode |= SYN_BIT_DISABLE_GESTURE;
+ if (SYN_CAP_EXTENDED(priv->capabilities))
+ priv->mode |= SYN_BIT_W_MODE;
+
+ if (synaptics_mode_cmd(psmouse, priv->mode))
+ return -1;
+
+ return 0;
+}
+
+static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
+{
+ struct synaptics_data *priv = psmouse->private;
+
+ if (rate >= 80) {
+ priv->mode |= SYN_BIT_HIGH_RATE;
+ psmouse->rate = 80;
+ } else {
+ priv->mode &= ~SYN_BIT_HIGH_RATE;
+ psmouse->rate = 40;
+ }
+
+ synaptics_mode_cmd(psmouse, priv->mode);
+}
+
+/*****************************************************************************
+ * Synaptics pass-through PS/2 port support
+ ****************************************************************************/
+static int synaptics_pt_write(struct serio *serio, unsigned char c)
+{
+ struct psmouse *parent = serio_get_drvdata(serio->parent);
+ char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */
+
+ if (psmouse_sliced_command(parent, c))
+ return -1;
+ if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE))
+ return -1;
+ return 0;
+}
+
+static inline int synaptics_is_pt_packet(unsigned char *buf)
+{
+ return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
+}
+
+static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet)
+{
+ struct psmouse *child = serio_get_drvdata(ptport);
+
+ if (child && child->state == PSMOUSE_ACTIVATED) {
+ serio_interrupt(ptport, packet[1], 0, NULL);
+ serio_interrupt(ptport, packet[4], 0, NULL);
+ serio_interrupt(ptport, packet[5], 0, NULL);
+ if (child->type >= PSMOUSE_GENPS)
+ serio_interrupt(ptport, packet[2], 0, NULL);
+ } else
+ serio_interrupt(ptport, packet[1], 0, NULL);
+}
+
+static void synaptics_pt_activate(struct psmouse *psmouse)
+{
+ struct serio *ptport = psmouse->ps2dev.serio->child;
+ struct psmouse *child = serio_get_drvdata(ptport);
+ struct synaptics_data *priv = psmouse->private;
+
+ /* adjust the touchpad to child's choice of protocol */
+ if (child) {
+ if (child->type >= PSMOUSE_GENPS)
+ priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
+ else
+ priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
+
+ if (synaptics_mode_cmd(psmouse, priv->mode))
+ printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
+ }
+}
+
+static void synaptics_pt_create(struct psmouse *psmouse)
+{
+ struct serio *serio;
+
+ serio = kmalloc(sizeof(struct serio), GFP_KERNEL);
+ if (!serio) {
+ printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
+ return;
+ }
+
+ memset(serio, 0, sizeof(struct serio));
+
+ serio->id.type = SERIO_PS_PSTHRU;
+ strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
+ strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
+ serio->write = synaptics_pt_write;
+ serio->parent = psmouse->ps2dev.serio;
+
+ psmouse->pt_activate = synaptics_pt_activate;
+
+ printk(KERN_INFO "serio: %s port at %s\n", serio->name, psmouse->phys);
+ serio_register_port(serio);
+}
+
+/*****************************************************************************
+ * Functions to interpret the absolute mode packets
+ ****************************************************************************/
+
+static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw)
+{
+ memset(hw, 0, sizeof(struct synaptics_hw_state));
+
+ if (SYN_MODEL_NEWABS(priv->model_id)) {
+ hw->x = (((buf[3] & 0x10) << 8) |
+ ((buf[1] & 0x0f) << 8) |
+ buf[4]);
+ hw->y = (((buf[3] & 0x20) << 7) |
+ ((buf[1] & 0xf0) << 4) |
+ buf[5]);
+
+ hw->z = buf[2];
+ hw->w = (((buf[0] & 0x30) >> 2) |
+ ((buf[0] & 0x04) >> 1) |
+ ((buf[3] & 0x04) >> 2));
+
+ hw->left = (buf[0] & 0x01) ? 1 : 0;
+ hw->right = (buf[0] & 0x02) ? 1 : 0;
+
+ if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
+ hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
+ if (hw->w == 2)
+ hw->scroll = (signed char)(buf[1]);
+ }
+
+ if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
+ hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0;
+ hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
+ }
+
+ if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
+ ((buf[0] ^ buf[3]) & 0x02)) {
+ switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
+ default:
+ /*
+ * if nExtBtn is greater than 8 it should be
+ * considered invalid and treated as 0
+ */
+ break;
+ case 8:
+ hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0;
+ hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0;
+ case 6:
+ hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0;
+ hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0;
+ case 4:
+ hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0;
+ hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0;
+ case 2:
+ hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0;
+ hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0;
+ }
+ }
+ } else {
+ hw->x = (((buf[1] & 0x1f) << 8) | buf[2]);
+ hw->y = (((buf[4] & 0x1f) << 8) | buf[5]);
+
+ hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F));
+ hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1));
+
+ hw->left = (buf[0] & 0x01) ? 1 : 0;
+ hw->right = (buf[0] & 0x02) ? 1 : 0;
+ }
+}
+
+/*
+ * called for each full received packet from the touchpad
+ */
+static void synaptics_process_packet(struct psmouse *psmouse)
+{
+ struct input_dev *dev = &psmouse->dev;
+ struct synaptics_data *priv = psmouse->private;
+ struct synaptics_hw_state hw;
+ int num_fingers;
+ int finger_width;
+ int i;
+
+ synaptics_parse_hw_state(psmouse->packet, priv, &hw);
+
+ if (hw.scroll) {
+ priv->scroll += hw.scroll;
+
+ while (priv->scroll >= 4) {
+ input_report_key(dev, BTN_BACK, !hw.down);
+ input_sync(dev);
+ input_report_key(dev, BTN_BACK, hw.down);
+ input_sync(dev);
+ priv->scroll -= 4;
+ }
+ while (priv->scroll <= -4) {
+ input_report_key(dev, BTN_FORWARD, !hw.up);
+ input_sync(dev);
+ input_report_key(dev, BTN_FORWARD, hw.up);
+ input_sync(dev);
+ priv->scroll += 4;
+ }
+ return;
+ }
+
+ if (hw.z > 0) {
+ num_fingers = 1;
+ finger_width = 5;
+ if (SYN_CAP_EXTENDED(priv->capabilities)) {
+ switch (hw.w) {
+ case 0 ... 1:
+ if (SYN_CAP_MULTIFINGER(priv->capabilities))
+ num_fingers = hw.w + 2;
+ break;
+ case 2:
+ if (SYN_MODEL_PEN(priv->model_id))
+ ; /* Nothing, treat a pen as a single finger */
+ break;
+ case 4 ... 15:
+ if (SYN_CAP_PALMDETECT(priv->capabilities))
+ finger_width = hw.w;
+ break;
+ }
+ }
+ } else {
+ num_fingers = 0;
+ finger_width = 0;
+ }
+
+ /* Post events
+ * BTN_TOUCH has to be first as mousedev relies on it when doing
+ * absolute -> relative conversion
+ */
+ if (hw.z > 30) input_report_key(dev, BTN_TOUCH, 1);
+ if (hw.z < 25) input_report_key(dev, BTN_TOUCH, 0);
+
+ if (hw.z > 0) {
+ input_report_abs(dev, ABS_X, hw.x);
+ input_report_abs(dev, ABS_Y, YMAX_NOMINAL + YMIN_NOMINAL - hw.y);
+ }
+ input_report_abs(dev, ABS_PRESSURE, hw.z);
+
+ input_report_abs(dev, ABS_TOOL_WIDTH, finger_width);
+ input_report_key(dev, BTN_TOOL_FINGER, num_fingers == 1);
+ input_report_key(dev, BTN_TOOL_DOUBLETAP, num_fingers == 2);
+ input_report_key(dev, BTN_TOOL_TRIPLETAP, num_fingers == 3);
+
+ input_report_key(dev, BTN_LEFT, hw.left);
+ input_report_key(dev, BTN_RIGHT, hw.right);
+
+ if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
+ input_report_key(dev, BTN_MIDDLE, hw.middle);
+
+ if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) {
+ input_report_key(dev, BTN_FORWARD, hw.up);
+ input_report_key(dev, BTN_BACK, hw.down);
+ }
+
+ for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
+ input_report_key(dev, BTN_0 + i, hw.ext_buttons & (1 << i));
+
+ input_sync(dev);
+}
+
+static int synaptics_validate_byte(unsigned char packet[], int idx, unsigned char pkt_type)
+{
+ static unsigned char newabs_mask[] = { 0xC8, 0x00, 0x00, 0xC8, 0x00 };
+ static unsigned char newabs_rel_mask[] = { 0xC0, 0x00, 0x00, 0xC0, 0x00 };
+ static unsigned char newabs_rslt[] = { 0x80, 0x00, 0x00, 0xC0, 0x00 };
+ static unsigned char oldabs_mask[] = { 0xC0, 0x60, 0x00, 0xC0, 0x60 };
+ static unsigned char oldabs_rslt[] = { 0xC0, 0x00, 0x00, 0x80, 0x00 };
+
+ if (idx < 0 || idx > 4)
+ return 0;
+
+ switch (pkt_type) {
+ case SYN_NEWABS:
+ case SYN_NEWABS_RELAXED:
+ return (packet[idx] & newabs_rel_mask[idx]) == newabs_rslt[idx];
+
+ case SYN_NEWABS_STRICT:
+ return (packet[idx] & newabs_mask[idx]) == newabs_rslt[idx];
+
+ case SYN_OLDABS:
+ return (packet[idx] & oldabs_mask[idx]) == oldabs_rslt[idx];
+
+ default:
+ printk(KERN_ERR "synaptics: unknown packet type %d\n", pkt_type);
+ return 0;
+ }
+}
+
+static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
+{
+ int i;
+
+ for (i = 0; i < 5; i++)
+ if (!synaptics_validate_byte(psmouse->packet, i, SYN_NEWABS_STRICT)) {
+ printk(KERN_INFO "synaptics: using relaxed packet validation\n");
+ return SYN_NEWABS_RELAXED;
+ }
+
+ return SYN_NEWABS_STRICT;
+}
+
+static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
+{
+ struct input_dev *dev = &psmouse->dev;
+ struct synaptics_data *priv = psmouse->private;
+
+ input_regs(dev, regs);
+
+ if (psmouse->pktcnt >= 6) { /* Full packet received */
+ if (unlikely(priv->pkt_type == SYN_NEWABS))
+ priv->pkt_type = synaptics_detect_pkt_type(psmouse);
+
+ if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) {
+ if (psmouse->ps2dev.serio->child)
+ synaptics_pass_pt_packet(psmouse->ps2dev.serio->child, psmouse->packet);
+ } else
+ synaptics_process_packet(psmouse);
+
+ return PSMOUSE_FULL_PACKET;
+ }
+
+ return synaptics_validate_byte(psmouse->packet, psmouse->pktcnt - 1, priv->pkt_type) ?
+ PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
+}
+
+/*****************************************************************************
+ * Driver initialization/cleanup functions
+ ****************************************************************************/
+static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
+{
+ int i;
+
+ set_bit(EV_ABS, dev->evbit);
+ input_set_abs_params(dev, ABS_X, XMIN_NOMINAL, XMAX_NOMINAL, 0, 0);
+ input_set_abs_params(dev, ABS_Y, YMIN_NOMINAL, YMAX_NOMINAL, 0, 0);
+ input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
+ set_bit(ABS_TOOL_WIDTH, dev->absbit);
+
+ set_bit(EV_KEY, dev->evbit);
+ set_bit(BTN_TOUCH, dev->keybit);
+ set_bit(BTN_TOOL_FINGER, dev->keybit);
+ set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
+ set_bit(BTN_TOOL_TRIPLETAP, dev->keybit);
+
+ set_bit(BTN_LEFT, dev->keybit);
+ set_bit(BTN_RIGHT, dev->keybit);
+
+ if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities))
+ set_bit(BTN_MIDDLE, dev->keybit);
+
+ if (SYN_CAP_FOUR_BUTTON(priv->capabilities) ||
+ SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) {
+ set_bit(BTN_FORWARD, dev->keybit);
+ set_bit(BTN_BACK, dev->keybit);
+ }
+
+ for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap); i++)
+ set_bit(BTN_0 + i, dev->keybit);
+
+ clear_bit(EV_REL, dev->evbit);
+ clear_bit(REL_X, dev->relbit);
+ clear_bit(REL_Y, dev->relbit);
+}
+
+void synaptics_reset(struct psmouse *psmouse)
+{
+ /* reset touchpad back to relative mode, gestures enabled */
+ synaptics_mode_cmd(psmouse, 0);
+}
+
+static void synaptics_disconnect(struct psmouse *psmouse)
+{
+ synaptics_reset(psmouse);
+ kfree(psmouse->private);
+ psmouse->private = NULL;
+}
+
+static int synaptics_reconnect(struct psmouse *psmouse)
+{
+ struct synaptics_data *priv = psmouse->private;
+ struct synaptics_data old_priv = *priv;
+
+ if (synaptics_detect(psmouse, 0))
+ return -1;
+
+ if (synaptics_query_hardware(psmouse)) {
+ printk(KERN_ERR "Unable to query Synaptics hardware.\n");
+ return -1;
+ }
+
+ if (old_priv.identity != priv->identity ||
+ old_priv.model_id != priv->model_id ||
+ old_priv.capabilities != priv->capabilities ||
+ old_priv.ext_cap != priv->ext_cap)
+ return -1;
+
+ if (synaptics_set_absolute_mode(psmouse)) {
+ printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int synaptics_detect(struct psmouse *psmouse, int set_properties)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param[4];
+
+ param[0] = 0;
+
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
+
+ if (param[1] != 0x47)
+ return -1;
+
+ if (set_properties) {
+ psmouse->vendor = "Synaptics";
+ psmouse->name = "TouchPad";
+ }
+
+ return 0;
+}
+
+#if defined(__i386__)
+#include <linux/dmi.h>
+static struct dmi_system_id toshiba_dmi_table[] = {
+ {
+ .ident = "Toshiba Satellite",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+ DMI_MATCH(DMI_PRODUCT_NAME , "Satellite"),
+ },
+ },
+ { }
+};
+#endif
+
+int synaptics_init(struct psmouse *psmouse)
+{
+ struct synaptics_data *priv;
+
+ psmouse->private = priv = kmalloc(sizeof(struct synaptics_data), GFP_KERNEL);
+ if (!priv)
+ return -1;
+ memset(priv, 0, sizeof(struct synaptics_data));
+
+ if (synaptics_query_hardware(psmouse)) {
+ printk(KERN_ERR "Unable to query Synaptics hardware.\n");
+ goto init_fail;
+ }
+
+ if (synaptics_set_absolute_mode(psmouse)) {
+ printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
+ goto init_fail;
+ }
+
+ priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
+
+ print_ident(priv);
+ set_input_params(&psmouse->dev, priv);
+
+ psmouse->protocol_handler = synaptics_process_byte;
+ psmouse->set_rate = synaptics_set_rate;
+ psmouse->disconnect = synaptics_disconnect;
+ psmouse->reconnect = synaptics_reconnect;
+ psmouse->pktsize = 6;
+
+ if (SYN_CAP_PASS_THROUGH(priv->capabilities))
+ synaptics_pt_create(psmouse);
+
+#if defined(__i386__)
+ /*
+ * Toshiba's KBC seems to have trouble handling data from
+ * Synaptics as full rate, switch to lower rate which is roughly
+ * thye same as rate of standard PS/2 mouse.
+ */
+ if (psmouse->rate >= 80 && dmi_check_system(toshiba_dmi_table)) {
+ printk(KERN_INFO "synaptics: Toshiba Satellite detected, limiting rate to 40pps.\n");
+ psmouse->rate = 40;
+ }
+#endif
+
+ return 0;
+
+ init_fail:
+ kfree(priv);
+ return -1;
+}
+
+
diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
new file mode 100644
index 0000000..68fff1d
--- /dev/null
+++ b/drivers/input/mouse/synaptics.h
@@ -0,0 +1,110 @@
+/*
+ * Synaptics TouchPad PS/2 mouse driver
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef _SYNAPTICS_H
+#define _SYNAPTICS_H
+
+extern int synaptics_detect(struct psmouse *psmouse, int set_properties);
+extern int synaptics_init(struct psmouse *psmouse);
+extern void synaptics_reset(struct psmouse *psmouse);
+
+/* synaptics queries */
+#define SYN_QUE_IDENTIFY 0x00
+#define SYN_QUE_MODES 0x01
+#define SYN_QUE_CAPABILITIES 0x02
+#define SYN_QUE_MODEL 0x03
+#define SYN_QUE_SERIAL_NUMBER_PREFIX 0x06
+#define SYN_QUE_SERIAL_NUMBER_SUFFIX 0x07
+#define SYN_QUE_RESOLUTION 0x08
+#define SYN_QUE_EXT_CAPAB 0x09
+
+/* synatics modes */
+#define SYN_BIT_ABSOLUTE_MODE (1 << 7)
+#define SYN_BIT_HIGH_RATE (1 << 6)
+#define SYN_BIT_SLEEP_MODE (1 << 3)
+#define SYN_BIT_DISABLE_GESTURE (1 << 2)
+#define SYN_BIT_FOUR_BYTE_CLIENT (1 << 1)
+#define SYN_BIT_W_MODE (1 << 0)
+
+/* synaptics model ID bits */
+#define SYN_MODEL_ROT180(m) ((m) & (1 << 23))
+#define SYN_MODEL_PORTRAIT(m) ((m) & (1 << 22))
+#define SYN_MODEL_SENSOR(m) (((m) >> 16) & 0x3f)
+#define SYN_MODEL_HARDWARE(m) (((m) >> 9) & 0x7f)
+#define SYN_MODEL_NEWABS(m) ((m) & (1 << 7))
+#define SYN_MODEL_PEN(m) ((m) & (1 << 6))
+#define SYN_MODEL_SIMPLIC(m) ((m) & (1 << 5))
+#define SYN_MODEL_GEOMETRY(m) ((m) & 0x0f)
+
+/* synaptics capability bits */
+#define SYN_CAP_EXTENDED(c) ((c) & (1 << 23))
+#define SYN_CAP_MIDDLE_BUTTON(c) ((c) & (1 << 18))
+#define SYN_CAP_PASS_THROUGH(c) ((c) & (1 << 7))
+#define SYN_CAP_SLEEP(c) ((c) & (1 << 4))
+#define SYN_CAP_FOUR_BUTTON(c) ((c) & (1 << 3))
+#define SYN_CAP_MULTIFINGER(c) ((c) & (1 << 1))
+#define SYN_CAP_PALMDETECT(c) ((c) & (1 << 0))
+#define SYN_CAP_VALID(c) ((((c) & 0x00ff00) >> 8) == 0x47)
+#define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20)
+#define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12)
+
+/* synaptics modes query bits */
+#define SYN_MODE_ABSOLUTE(m) ((m) & (1 << 7))
+#define SYN_MODE_RATE(m) ((m) & (1 << 6))
+#define SYN_MODE_BAUD_SLEEP(m) ((m) & (1 << 3))
+#define SYN_MODE_DISABLE_GESTURE(m) ((m) & (1 << 2))
+#define SYN_MODE_PACKSIZE(m) ((m) & (1 << 1))
+#define SYN_MODE_WMODE(m) ((m) & (1 << 0))
+
+/* synaptics identify query bits */
+#define SYN_ID_MODEL(i) (((i) >> 4) & 0x0f)
+#define SYN_ID_MAJOR(i) ((i) & 0x0f)
+#define SYN_ID_MINOR(i) (((i) >> 16) & 0xff)
+#define SYN_ID_IS_SYNAPTICS(i) ((((i) >> 8) & 0xff) == 0x47)
+
+/* synaptics special commands */
+#define SYN_PS_SET_MODE2 0x14
+#define SYN_PS_CLIENT_CMD 0x28
+
+/* synaptics packet types */
+#define SYN_NEWABS 0
+#define SYN_NEWABS_STRICT 1
+#define SYN_NEWABS_RELAXED 2
+#define SYN_OLDABS 3
+
+/*
+ * A structure to describe the state of the touchpad hardware (buttons and pad)
+ */
+
+struct synaptics_hw_state {
+ int x;
+ int y;
+ int z;
+ int w;
+ unsigned int left:1;
+ unsigned int right:1;
+ unsigned int middle:1;
+ unsigned int up:1;
+ unsigned int down:1;
+ unsigned char ext_buttons;
+ signed char scroll;
+};
+
+struct synaptics_data {
+ /* Data read from the touchpad */
+ unsigned long int model_id; /* Model-ID */
+ unsigned long int capabilities; /* Capabilities */
+ unsigned long int ext_cap; /* Extended Capabilities */
+ unsigned long int identity; /* Identification */
+
+ unsigned char pkt_type; /* packet type - old, new, etc */
+ unsigned char mode; /* current mode byte */
+ int scroll;
+};
+
+#endif /* _SYNAPTICS_H */
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
new file mode 100644
index 0000000..b2cb101
--- /dev/null
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -0,0 +1,591 @@
+/*
+ * Driver for DEC VSXXX-AA mouse (hockey-puck mouse, ball or two rollers)
+ * DEC VSXXX-GA mouse (rectangular mouse, with ball)
+ * DEC VSXXX-AB tablet (digitizer with hair cross or stylus)
+ *
+ * Copyright (C) 2003-2004 by Jan-Benedict Glaw <jbglaw@lug-owl.de>
+ *
+ * The packet format was initially taken from a patch to GPM which is (C) 2001
+ * by Karsten Merker <merker@linuxtag.org>
+ * and Maciej W. Rozycki <macro@ds2.pg.gda.pl>
+ * Later on, I had access to the device's documentation (referenced below).
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Building an adaptor to DE9 / DB25 RS232
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * DISCLAIMER: Use this description AT YOUR OWN RISK! I'll not pay for
+ * anything if you break your mouse, your computer or whatever!
+ *
+ * In theory, this mouse is a simple RS232 device. In practice, it has got
+ * a quite uncommon plug and the requirement to additionally get a power
+ * supply at +5V and -12V.
+ *
+ * If you look at the socket/jack (_not_ at the plug), we use this pin
+ * numbering:
+ * _______
+ * / 7 6 5 \
+ * | 4 --- 3 |
+ * \ 2 1 /
+ * -------
+ *
+ * DEC socket DE9 DB25 Note
+ * 1 (GND) 5 7 -
+ * 2 (RxD) 2 3 -
+ * 3 (TxD) 3 2 -
+ * 4 (-12V) - - Somewhere from the PSU. At ATX, it's
+ * the thin blue wire at pin 12 of the
+ * ATX power connector. Only required for
+ * VSXXX-AA/-GA mice.
+ * 5 (+5V) - - PSU (red wires of ATX power connector
+ * on pin 4, 6, 19 or 20) or HDD power
+ * connector (also red wire).
+ * 6 (+12V) - - HDD power connector, yellow wire. Only
+ * required for VSXXX-AB digitizer.
+ * 7 (dev. avail.) - - The mouse shorts this one to pin 1.
+ * This way, the host computer can detect
+ * the mouse. To use it with the adaptor,
+ * simply don't connect this pin.
+ *
+ * So to get a working adaptor, you need to connect the mouse with three
+ * wires to a RS232 port and two or three additional wires for +5V, +12V and
+ * -12V to the PSU.
+ *
+ * Flow specification for the link is 4800, 8o1.
+ *
+ * The mice and tablet are described in "VCB02 Video Subsystem - Technical
+ * Manual", DEC EK-104AA-TM-001. You'll find it at MANX, a search engine
+ * specific for DEC documentation. Try
+ * http://www.vt100.net/manx/details?pn=EK-104AA-TM-001;id=21;cp=1
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/config.h>
+#include <linux/serio.h>
+#include <linux/init.h>
+
+#define DRIVER_DESC "Driver for DEC VSXXX-AA and -GA mice and VSXXX-AB tablet"
+
+MODULE_AUTHOR ("Jan-Benedict Glaw <jbglaw@lug-owl.de>");
+MODULE_DESCRIPTION (DRIVER_DESC);
+MODULE_LICENSE ("GPL");
+
+#undef VSXXXAA_DEBUG
+#ifdef VSXXXAA_DEBUG
+#define DBG(x...) printk (x)
+#else
+#define DBG(x...) do {} while (0)
+#endif
+
+#define VSXXXAA_INTRO_MASK 0x80
+#define VSXXXAA_INTRO_HEAD 0x80
+#define IS_HDR_BYTE(x) (((x) & VSXXXAA_INTRO_MASK) \
+ == VSXXXAA_INTRO_HEAD)
+
+#define VSXXXAA_PACKET_MASK 0xe0
+#define VSXXXAA_PACKET_REL 0x80
+#define VSXXXAA_PACKET_ABS 0xc0
+#define VSXXXAA_PACKET_POR 0xa0
+#define MATCH_PACKET_TYPE(data, type) (((data) & VSXXXAA_PACKET_MASK) == (type))
+
+
+
+struct vsxxxaa {
+ struct input_dev dev;
+ struct serio *serio;
+#define BUFLEN 15 /* At least 5 is needed for a full tablet packet */
+ unsigned char buf[BUFLEN];
+ unsigned char count;
+ unsigned char version;
+ unsigned char country;
+ unsigned char type;
+ char name[64];
+ char phys[32];
+};
+
+static void
+vsxxxaa_drop_bytes (struct vsxxxaa *mouse, int num)
+{
+ if (num >= mouse->count)
+ mouse->count = 0;
+ else {
+ memmove (mouse->buf, mouse->buf + num - 1, BUFLEN - num);
+ mouse->count -= num;
+ }
+}
+
+static void
+vsxxxaa_queue_byte (struct vsxxxaa *mouse, unsigned char byte)
+{
+ if (mouse->count == BUFLEN) {
+ printk (KERN_ERR "%s on %s: Dropping a byte of full buffer.\n",
+ mouse->name, mouse->phys);
+ vsxxxaa_drop_bytes (mouse, 1);
+ }
+ DBG (KERN_INFO "Queueing byte 0x%02x\n", byte);
+
+ mouse->buf[mouse->count++] = byte;
+}
+
+static void
+vsxxxaa_detection_done (struct vsxxxaa *mouse)
+{
+ switch (mouse->type) {
+ case 0x02:
+ sprintf (mouse->name, "DEC VSXXX-AA/-GA mouse");
+ break;
+
+ case 0x04:
+ sprintf (mouse->name, "DEC VSXXX-AB digitizer");
+ break;
+
+ default:
+ sprintf (mouse->name, "unknown DEC pointer device "
+ "(type = 0x%02x)", mouse->type);
+ break;
+ }
+
+ printk (KERN_INFO "Found %s version 0x%02x from country 0x%02x "
+ "on port %s\n", mouse->name, mouse->version,
+ mouse->country, mouse->phys);
+}
+
+/*
+ * Returns number of bytes to be dropped, 0 if packet is okay.
+ */
+static int
+vsxxxaa_check_packet (struct vsxxxaa *mouse, int packet_len)
+{
+ int i;
+
+ /* First byte must be a header byte */
+ if (!IS_HDR_BYTE (mouse->buf[0])) {
+ DBG ("vsck: len=%d, 1st=0x%02x\n", packet_len, mouse->buf[0]);
+ return 1;
+ }
+
+ /* Check all following bytes */
+ if (packet_len > 1) {
+ for (i = 1; i < packet_len; i++) {
+ if (IS_HDR_BYTE (mouse->buf[i])) {
+ printk (KERN_ERR "Need to drop %d bytes "
+ "of a broken packet.\n",
+ i - 1);
+ DBG (KERN_INFO "check: len=%d, b[%d]=0x%02x\n",
+ packet_len, i, mouse->buf[i]);
+ return i - 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static __inline__ int
+vsxxxaa_smells_like_packet (struct vsxxxaa *mouse, unsigned char type, size_t len)
+{
+ return (mouse->count >= len) && MATCH_PACKET_TYPE (mouse->buf[0], type);
+}
+
+static void
+vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
+{
+ struct input_dev *dev = &mouse->dev;
+ unsigned char *buf = mouse->buf;
+ int left, middle, right;
+ int dx, dy;
+
+ /*
+ * Check for normal stream packets. This is three bytes,
+ * with the first byte's 3 MSB set to 100.
+ *
+ * [0]: 1 0 0 SignX SignY Left Middle Right
+ * [1]: 0 dx dx dx dx dx dx dx
+ * [2]: 0 dy dy dy dy dy dy dy
+ */
+
+ /*
+ * Low 7 bit of byte 1 are abs(dx), bit 7 is
+ * 0, bit 4 of byte 0 is direction.
+ */
+ dx = buf[1] & 0x7f;
+ dx *= ((buf[0] >> 4) & 0x01)? 1: -1;
+
+ /*
+ * Low 7 bit of byte 2 are abs(dy), bit 7 is
+ * 0, bit 3 of byte 0 is direction.
+ */
+ dy = buf[2] & 0x7f;
+ dy *= ((buf[0] >> 3) & 0x01)? -1: 1;
+
+ /*
+ * Get button state. It's the low three bits
+ * (for three buttons) of byte 0.
+ */
+ left = (buf[0] & 0x04)? 1: 0;
+ middle = (buf[0] & 0x02)? 1: 0;
+ right = (buf[0] & 0x01)? 1: 0;
+
+ vsxxxaa_drop_bytes (mouse, 3);
+
+ DBG (KERN_INFO "%s on %s: dx=%d, dy=%d, buttons=%s%s%s\n",
+ mouse->name, mouse->phys, dx, dy,
+ left? "L": "l", middle? "M": "m", right? "R": "r");
+
+ /*
+ * Report what we've found so far...
+ */
+ input_regs (dev, regs);
+ input_report_key (dev, BTN_LEFT, left);
+ input_report_key (dev, BTN_MIDDLE, middle);
+ input_report_key (dev, BTN_RIGHT, right);
+ input_report_key (dev, BTN_TOUCH, 0);
+ input_report_rel (dev, REL_X, dx);
+ input_report_rel (dev, REL_Y, dy);
+ input_sync (dev);
+}
+
+static void
+vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
+{
+ struct input_dev *dev = &mouse->dev;
+ unsigned char *buf = mouse->buf;
+ int left, middle, right, touch;
+ int x, y;
+
+ /*
+ * Tablet position / button packet
+ *
+ * [0]: 1 1 0 B4 B3 B2 B1 Pr
+ * [1]: 0 0 X5 X4 X3 X2 X1 X0
+ * [2]: 0 0 X11 X10 X9 X8 X7 X6
+ * [3]: 0 0 Y5 Y4 Y3 Y2 Y1 Y0
+ * [4]: 0 0 Y11 Y10 Y9 Y8 Y7 Y6
+ */
+
+ /*
+ * Get X/Y position. Y axis needs to be inverted since VSXXX-AB
+ * counts down->top while monitor counts top->bottom.
+ */
+ x = ((buf[2] & 0x3f) << 6) | (buf[1] & 0x3f);
+ y = ((buf[4] & 0x3f) << 6) | (buf[3] & 0x3f);
+ y = 1023 - y;
+
+ /*
+ * Get button state. It's bits <4..1> of byte 0.
+ */
+ left = (buf[0] & 0x02)? 1: 0;
+ middle = (buf[0] & 0x04)? 1: 0;
+ right = (buf[0] & 0x08)? 1: 0;
+ touch = (buf[0] & 0x10)? 1: 0;
+
+ vsxxxaa_drop_bytes (mouse, 5);
+
+ DBG (KERN_INFO "%s on %s: x=%d, y=%d, buttons=%s%s%s%s\n",
+ mouse->name, mouse->phys, x, y,
+ left? "L": "l", middle? "M": "m",
+ right? "R": "r", touch? "T": "t");
+
+ /*
+ * Report what we've found so far...
+ */
+ input_regs (dev, regs);
+ input_report_key (dev, BTN_LEFT, left);
+ input_report_key (dev, BTN_MIDDLE, middle);
+ input_report_key (dev, BTN_RIGHT, right);
+ input_report_key (dev, BTN_TOUCH, touch);
+ input_report_abs (dev, ABS_X, x);
+ input_report_abs (dev, ABS_Y, y);
+ input_sync (dev);
+}
+
+static void
+vsxxxaa_handle_POR_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
+{
+ struct input_dev *dev = &mouse->dev;
+ unsigned char *buf = mouse->buf;
+ int left, middle, right;
+ unsigned char error;
+
+ /*
+ * Check for Power-On-Reset packets. These are sent out
+ * after plugging the mouse in, or when explicitely
+ * requested by sending 'T'.
+ *
+ * [0]: 1 0 1 0 R3 R2 R1 R0
+ * [1]: 0 M2 M1 M0 D3 D2 D1 D0
+ * [2]: 0 E6 E5 E4 E3 E2 E1 E0
+ * [3]: 0 0 0 0 0 Left Middle Right
+ *
+ * M: manufacturer location code
+ * R: revision code
+ * E: Error code. If it's in the range of 0x00..0x1f, only some
+ * minor problem occured. Errors >= 0x20 are considered bad
+ * and the device may not work properly...
+ * D: <0010> == mouse, <0100> == tablet
+ */
+
+ mouse->version = buf[0] & 0x0f;
+ mouse->country = (buf[1] >> 4) & 0x07;
+ mouse->type = buf[1] & 0x0f;
+ error = buf[2] & 0x7f;
+
+ /*
+ * Get button state. It's the low three bits
+ * (for three buttons) of byte 0. Maybe even the bit <3>
+ * has some meaning if a tablet is attached.
+ */
+ left = (buf[0] & 0x04)? 1: 0;
+ middle = (buf[0] & 0x02)? 1: 0;
+ right = (buf[0] & 0x01)? 1: 0;
+
+ vsxxxaa_drop_bytes (mouse, 4);
+ vsxxxaa_detection_done (mouse);
+
+ if (error <= 0x1f) {
+ /* No (serious) error. Report buttons */
+ input_regs (dev, regs);
+ input_report_key (dev, BTN_LEFT, left);
+ input_report_key (dev, BTN_MIDDLE, middle);
+ input_report_key (dev, BTN_RIGHT, right);
+ input_report_key (dev, BTN_TOUCH, 0);
+ input_sync (dev);
+
+ if (error != 0)
+ printk (KERN_INFO "Your %s on %s reports error=0x%02x\n",
+ mouse->name, mouse->phys, error);
+
+ }
+
+ /*
+ * If the mouse was hot-plugged, we need to force differential mode
+ * now... However, give it a second to recover from it's reset.
+ */
+ printk (KERN_NOTICE "%s on %s: Forceing standard packet format, "
+ "incremental streaming mode and 72 samples/sec\n",
+ mouse->name, mouse->phys);
+ mouse->serio->write (mouse->serio, 'S'); /* Standard format */
+ mdelay (50);
+ mouse->serio->write (mouse->serio, 'R'); /* Incremental */
+ mdelay (50);
+ mouse->serio->write (mouse->serio, 'L'); /* 72 samples/sec */
+}
+
+static void
+vsxxxaa_parse_buffer (struct vsxxxaa *mouse, struct pt_regs *regs)
+{
+ unsigned char *buf = mouse->buf;
+ int stray_bytes;
+
+ /*
+ * Parse buffer to death...
+ */
+ do {
+ /*
+ * Out of sync? Throw away what we don't understand. Each
+ * packet starts with a byte whose bit 7 is set. Unhandled
+ * packets (ie. which we don't know about or simply b0rk3d
+ * data...) will get shifted out of the buffer after some
+ * activity on the mouse.
+ */
+ while (mouse->count > 0 && !IS_HDR_BYTE(buf[0])) {
+ printk (KERN_ERR "%s on %s: Dropping a byte to regain "
+ "sync with mouse data stream...\n",
+ mouse->name, mouse->phys);
+ vsxxxaa_drop_bytes (mouse, 1);
+ }
+
+ /*
+ * Check for packets we know about.
+ */
+
+ if (vsxxxaa_smells_like_packet (mouse, VSXXXAA_PACKET_REL, 3)) {
+ /* Check for broken packet */
+ stray_bytes = vsxxxaa_check_packet (mouse, 3);
+ if (stray_bytes > 0) {
+ printk (KERN_ERR "Dropping %d bytes now...\n",
+ stray_bytes);
+ vsxxxaa_drop_bytes (mouse, stray_bytes);
+ continue;
+ }
+
+ vsxxxaa_handle_REL_packet (mouse, regs);
+ continue; /* More to parse? */
+ }
+
+ if (vsxxxaa_smells_like_packet (mouse, VSXXXAA_PACKET_ABS, 5)) {
+ /* Check for broken packet */
+ stray_bytes = vsxxxaa_check_packet (mouse, 5);
+ if (stray_bytes > 0) {
+ printk (KERN_ERR "Dropping %d bytes now...\n",
+ stray_bytes);
+ vsxxxaa_drop_bytes (mouse, stray_bytes);
+ continue;
+ }
+
+ vsxxxaa_handle_ABS_packet (mouse, regs);
+ continue; /* More to parse? */
+ }
+
+ if (vsxxxaa_smells_like_packet (mouse, VSXXXAA_PACKET_POR, 4)) {
+ /* Check for broken packet */
+ stray_bytes = vsxxxaa_check_packet (mouse, 4);
+ if (stray_bytes > 0) {
+ printk (KERN_ERR "Dropping %d bytes now...\n",
+ stray_bytes);
+ vsxxxaa_drop_bytes (mouse, stray_bytes);
+ continue;
+ }
+
+ vsxxxaa_handle_POR_packet (mouse, regs);
+ continue; /* More to parse? */
+ }
+
+ break; /* No REL, ABS or POR packet found */
+ } while (1);
+}
+
+static irqreturn_t
+vsxxxaa_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
+ struct pt_regs *regs)
+{
+ struct vsxxxaa *mouse = serio_get_drvdata (serio);
+
+ vsxxxaa_queue_byte (mouse, data);
+ vsxxxaa_parse_buffer (mouse, regs);
+
+ return IRQ_HANDLED;
+}
+
+static void
+vsxxxaa_disconnect (struct serio *serio)
+{
+ struct vsxxxaa *mouse = serio_get_drvdata (serio);
+
+ input_unregister_device (&mouse->dev);
+ serio_close (serio);
+ serio_set_drvdata (serio, NULL);
+ kfree (mouse);
+}
+
+static int
+vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
+{
+ struct vsxxxaa *mouse;
+ int err;
+
+ if (!(mouse = kmalloc (sizeof (struct vsxxxaa), GFP_KERNEL)))
+ return -ENOMEM;
+
+ memset (mouse, 0, sizeof (struct vsxxxaa));
+
+ init_input_dev (&mouse->dev);
+ set_bit (EV_KEY, mouse->dev.evbit); /* We have buttons */
+ set_bit (EV_REL, mouse->dev.evbit);
+ set_bit (EV_ABS, mouse->dev.evbit);
+ set_bit (BTN_LEFT, mouse->dev.keybit); /* We have 3 buttons */
+ set_bit (BTN_MIDDLE, mouse->dev.keybit);
+ set_bit (BTN_RIGHT, mouse->dev.keybit);
+ set_bit (BTN_TOUCH, mouse->dev.keybit); /* ...and Tablet */
+ set_bit (REL_X, mouse->dev.relbit);
+ set_bit (REL_Y, mouse->dev.relbit);
+ set_bit (ABS_X, mouse->dev.absbit);
+ set_bit (ABS_Y, mouse->dev.absbit);
+
+ mouse->dev.absmin[ABS_X] = 0;
+ mouse->dev.absmax[ABS_X] = 1023;
+ mouse->dev.absmin[ABS_Y] = 0;
+ mouse->dev.absmax[ABS_Y] = 1023;
+
+ mouse->dev.private = mouse;
+
+ sprintf (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer");
+ sprintf (mouse->phys, "%s/input0", serio->phys);
+ mouse->dev.name = mouse->name;
+ mouse->dev.phys = mouse->phys;
+ mouse->dev.id.bustype = BUS_RS232;
+ mouse->dev.dev = &serio->dev;
+ mouse->serio = serio;
+
+ serio_set_drvdata (serio, mouse);
+
+ err = serio_open (serio, drv);
+ if (err) {
+ serio_set_drvdata (serio, NULL);
+ kfree (mouse);
+ return err;
+ }
+
+ /*
+ * Request selftest. Standard packet format and differential
+ * mode will be requested after the device ID'ed successfully.
+ */
+ mouse->serio->write (mouse->serio, 'T'); /* Test */
+
+ input_register_device (&mouse->dev);
+
+ printk (KERN_INFO "input: %s on %s\n", mouse->name, mouse->phys);
+
+ return 0;
+}
+
+static struct serio_device_id vsxxaa_serio_ids[] = {
+ {
+ .type = SERIO_RS232,
+ .proto = SERIO_VSXXXAA,
+ .id = SERIO_ANY,
+ .extra = SERIO_ANY,
+ },
+ { 0 }
+};
+
+MODULE_DEVICE_TABLE(serio, vsxxaa_serio_ids);
+
+static struct serio_driver vsxxxaa_drv = {
+ .driver = {
+ .name = "vsxxxaa",
+ },
+ .description = DRIVER_DESC,
+ .id_table = vsxxaa_serio_ids,
+ .connect = vsxxxaa_connect,
+ .interrupt = vsxxxaa_interrupt,
+ .disconnect = vsxxxaa_disconnect,
+};
+
+static int __init
+vsxxxaa_init (void)
+{
+ serio_register_driver(&vsxxxaa_drv);
+ return 0;
+}
+
+static void __exit
+vsxxxaa_exit (void)
+{
+ serio_unregister_driver(&vsxxxaa_drv);
+}
+
+module_init (vsxxxaa_init);
+module_exit (vsxxxaa_exit);
+