diff options
| author | Andres Salomon <dilinger@queued.net> | 2008-09-16 12:30:34 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2008-09-21 18:28:58 -0400 |
| commit | df08ef27a7f91961c91a2a718f5d1e616f1c8e57 (patch) | |
| tree | 99d85254467e408cef43014d054f0ed97b476c67 | |
| parent | 68d482214bb0eaac138ace329e72390d6c8d44ff (diff) | |
Input: psmouse - add OLPC touchpad driver
This adds support for OLPC's touchpad. It has lots of neat features,
none of which are enabled because the hardware is too buggy. Instead,
we use it like a normal touchpad, but with a number of workarounds in
place to deal with the frequent hardware spasms. Humidity changes,
sweat, tinfoil underwear, plugging in AC, drinks, evil felines.. All
tend to cause the touchpad to freak out.
Signed-off-by: Andres Salomon <dilinger@debian.org>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
| -rw-r--r-- | drivers/input/mouse/Kconfig | 10 | ||||
| -rw-r--r-- | drivers/input/mouse/Makefile | 1 | ||||
| -rw-r--r-- | drivers/input/mouse/hgpk.c | 477 | ||||
| -rw-r--r-- | drivers/input/mouse/hgpk.h | 49 | ||||
| -rw-r--r-- | drivers/input/mouse/psmouse-base.c | 23 | ||||
| -rw-r--r-- | drivers/input/mouse/psmouse.h | 2 |
6 files changed, 560 insertions, 2 deletions
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig index 7bbea097cda2..fff025359e7f 100644 --- a/drivers/input/mouse/Kconfig +++ b/drivers/input/mouse/Kconfig | |||
| @@ -96,6 +96,16 @@ config MOUSE_PS2_TOUCHKIT | |||
| 96 | 96 | ||
| 97 | If unsure, say N. | 97 | If unsure, say N. |
| 98 | 98 | ||
| 99 | config MOUSE_PS2_OLPC | ||
| 100 | bool "OLPC PS/2 mouse protocol extension" | ||
| 101 | depends on MOUSE_PS2 && OLPC | ||
| 102 | help | ||
| 103 | Say Y here if you have an OLPC XO-1 laptop (with built-in | ||
| 104 | PS/2 touchpad/tablet device). The manufacturer calls the | ||
| 105 | touchpad an HGPK. | ||
| 106 | |||
| 107 | If unsure, say N. | ||
| 108 | |||
| 99 | config MOUSE_SERIAL | 109 | config MOUSE_SERIAL |
| 100 | tristate "Serial mouse" | 110 | tristate "Serial mouse" |
| 101 | select SERIO | 111 | select SERIO |
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile index 9e6e36330820..5e4fb38f59cb 100644 --- a/drivers/input/mouse/Makefile +++ b/drivers/input/mouse/Makefile | |||
| @@ -20,6 +20,7 @@ obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o | |||
| 20 | psmouse-objs := psmouse-base.o synaptics.o | 20 | psmouse-objs := psmouse-base.o synaptics.o |
| 21 | 21 | ||
| 22 | psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o | 22 | psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o |
| 23 | psmouse-$(CONFIG_MOUSE_PS2_OLPC) += hgpk.o | ||
| 23 | psmouse-$(CONFIG_MOUSE_PS2_LOGIPS2PP) += logips2pp.o | 24 | psmouse-$(CONFIG_MOUSE_PS2_LOGIPS2PP) += logips2pp.o |
| 24 | psmouse-$(CONFIG_MOUSE_PS2_LIFEBOOK) += lifebook.o | 25 | psmouse-$(CONFIG_MOUSE_PS2_LIFEBOOK) += lifebook.o |
| 25 | psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o | 26 | psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o |
diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c new file mode 100644 index 000000000000..e82d34201e97 --- /dev/null +++ b/drivers/input/mouse/hgpk.c | |||
| @@ -0,0 +1,477 @@ | |||
| 1 | /* | ||
| 2 | * OLPC HGPK (XO-1) touchpad PS/2 mouse driver | ||
| 3 | * | ||
| 4 | * Copyright (c) 2006-2008 One Laptop Per Child | ||
| 5 | * Authors: | ||
| 6 | * Zephaniah E. Hull | ||
| 7 | * Andres Salomon <dilinger@debian.org> | ||
| 8 | * | ||
| 9 | * This driver is partly based on the ALPS driver, which is: | ||
| 10 | * | ||
| 11 | * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au> | ||
| 12 | * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com> | ||
| 13 | * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru> | ||
| 14 | * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> | ||
| 15 | * | ||
| 16 | * This program is free software; you can redistribute it and/or modify | ||
| 17 | * it under the terms of the GNU General Public License version 2 as | ||
| 18 | * published by the Free Software Foundation. | ||
| 19 | */ | ||
| 20 | |||
| 21 | /* | ||
| 22 | * The spec from ALPS is available from | ||
| 23 | * <http://wiki.laptop.org/go/Touch_Pad/Tablet>. It refers to this | ||
| 24 | * device as HGPK (Hybrid GS, PT, and Keymatrix). | ||
| 25 | * | ||
| 26 | * The earliest versions of the device had simultaneous reporting; that | ||
| 27 | * was removed. After that, the device used the Advanced Mode GS/PT streaming | ||
| 28 | * stuff. That turned out to be too buggy to support, so we've finally | ||
| 29 | * switched to Mouse Mode (which utilizes only the center 1/3 of the touchpad). | ||
| 30 | */ | ||
| 31 | |||
| 32 | #define DEBUG | ||
| 33 | #include <linux/input.h> | ||
| 34 | #include <linux/serio.h> | ||
| 35 | #include <linux/libps2.h> | ||
| 36 | #include <linux/delay.h> | ||
| 37 | #include <asm/olpc.h> | ||
| 38 | |||
| 39 | #include "psmouse.h" | ||
| 40 | #include "hgpk.h" | ||
| 41 | |||
| 42 | static int tpdebug; | ||
| 43 | module_param(tpdebug, int, 0644); | ||
| 44 | MODULE_PARM_DESC(tpdebug, "enable debugging, dumping packets to KERN_DEBUG."); | ||
| 45 | |||
| 46 | static int recalib_delta = 100; | ||
| 47 | module_param(recalib_delta, int, 0644); | ||
| 48 | MODULE_PARM_DESC(recalib_delta, | ||
| 49 | "packets containing a delta this large will cause a recalibration."); | ||
| 50 | |||
| 51 | /* | ||
| 52 | * When the touchpad gets ultra-sensitive, one can keep their finger 1/2" | ||
| 53 | * above the pad and still have it send packets. This causes a jump cursor | ||
| 54 | * when one places their finger on the pad. We can probably detect the | ||
| 55 | * jump as we see a large deltas (>= 100px). In mouse mode, I've been | ||
| 56 | * unable to even come close to 100px deltas during normal usage, so I think | ||
| 57 | * this threshold is safe. If a large delta occurs, trigger a recalibration. | ||
| 58 | */ | ||
| 59 | static void hgpk_jumpy_hack(struct psmouse *psmouse, int x, int y) | ||
| 60 | { | ||
| 61 | struct hgpk_data *priv = psmouse->private; | ||
| 62 | |||
| 63 | if (abs(x) > recalib_delta || abs(y) > recalib_delta) { | ||
| 64 | hgpk_err(psmouse, ">%dpx jump detected (%d,%d)\n", | ||
| 65 | recalib_delta, x, y); | ||
| 66 | /* My car gets forty rods to the hogshead and that's the | ||
| 67 | * way I likes it! */ | ||
| 68 | psmouse_queue_work(psmouse, &priv->recalib_wq, | ||
| 69 | msecs_to_jiffies(1000)); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | /* | ||
| 74 | * We have no idea why this particular hardware bug occurs. The touchpad | ||
| 75 | * will randomly start spewing packets without anything touching the | ||
| 76 | * pad. This wouldn't necessarily be bad, but it's indicative of a | ||
| 77 | * severely miscalibrated pad; attempting to use the touchpad while it's | ||
| 78 | * spewing means the cursor will jump all over the place, and act "drunk". | ||
| 79 | * | ||
| 80 | * The packets that are spewed tend to all have deltas between -2 and 2, and | ||
| 81 | * the cursor will move around without really going very far. It will | ||
| 82 | * tend to end up in the same location; if we tally up the changes over | ||
| 83 | * 100 packets, we end up w/ a final delta of close to 0. This happens | ||
| 84 | * pretty regularly when the touchpad is spewing, and is pretty hard to | ||
| 85 | * manually trigger (at least for *my* fingers). So, it makes a perfect | ||
| 86 | * scheme for detecting spews. | ||
| 87 | */ | ||
| 88 | static void hgpk_spewing_hack(struct psmouse *psmouse, | ||
| 89 | int l, int r, int x, int y) | ||
| 90 | { | ||
| 91 | struct hgpk_data *priv = psmouse->private; | ||
| 92 | |||
| 93 | /* ignore button press packets; many in a row could trigger | ||
| 94 | * a false-positive! */ | ||
| 95 | if (l || r) | ||
| 96 | return; | ||
| 97 | |||
| 98 | priv->x_tally += x; | ||
| 99 | priv->y_tally += y; | ||
| 100 | |||
| 101 | if (++priv->count > 100) { | ||
| 102 | if (abs(priv->x_tally) < 3 && abs(priv->y_tally) < 3) { | ||
| 103 | hgpk_dbg(psmouse, "packet spew detected (%d,%d)\n", | ||
| 104 | priv->x_tally, priv->y_tally); | ||
| 105 | psmouse_queue_work(psmouse, &priv->recalib_wq, | ||
| 106 | msecs_to_jiffies(1000)); | ||
| 107 | } | ||
| 108 | /* reset every 100 packets */ | ||
| 109 | priv->count = 0; | ||
| 110 | priv->x_tally = 0; | ||
| 111 | priv->y_tally = 0; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | /* | ||
| 116 | * HGPK Mouse Mode format (standard mouse format, sans middle button) | ||
| 117 | * | ||
| 118 | * byte 0: y-over x-over y-neg x-neg 1 0 swr swl | ||
| 119 | * byte 1: x7 x6 x5 x4 x3 x2 x1 x0 | ||
| 120 | * byte 2: y7 y6 y5 y4 y3 y2 y1 y0 | ||
| 121 | * | ||
| 122 | * swr/swl are the left/right buttons. | ||
| 123 | * x-neg/y-neg are the x and y delta negative bits | ||
| 124 | * x-over/y-over are the x and y overflow bits | ||
| 125 | */ | ||
| 126 | static int hgpk_validate_byte(unsigned char *packet) | ||
| 127 | { | ||
| 128 | return (packet[0] & 0x0C) == 0x08; | ||
| 129 | } | ||
| 130 | |||
| 131 | static void hgpk_process_packet(struct psmouse *psmouse) | ||
| 132 | { | ||
| 133 | struct input_dev *dev = psmouse->dev; | ||
| 134 | unsigned char *packet = psmouse->packet; | ||
| 135 | int x, y, left, right; | ||
| 136 | |||
| 137 | left = packet[0] & 1; | ||
| 138 | right = (packet[0] >> 1) & 1; | ||
| 139 | |||
| 140 | x = packet[1] - ((packet[0] << 4) & 0x100); | ||
| 141 | y = ((packet[0] << 3) & 0x100) - packet[2]; | ||
| 142 | |||
| 143 | hgpk_jumpy_hack(psmouse, x, y); | ||
| 144 | hgpk_spewing_hack(psmouse, left, right, x, y); | ||
| 145 | |||
| 146 | if (tpdebug) | ||
| 147 | hgpk_dbg(psmouse, "l=%d r=%d x=%d y=%d\n", left, right, x, y); | ||
| 148 | |||
| 149 | input_report_key(dev, BTN_LEFT, left); | ||
| 150 | input_report_key(dev, BTN_RIGHT, right); | ||
| 151 | |||
| 152 | input_report_rel(dev, REL_X, x); | ||
