2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-10-10 19:27:03 -06:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#define psmouse_fmt(fmt) fmt
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/module.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>
|
2006-02-18 22:22:11 -07:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "psmouse.h"
|
|
|
|
#include "synaptics.h"
|
|
|
|
#include "logips2pp.h"
|
|
|
|
#include "alps.h"
|
2008-09-16 10:30:34 -06:00
|
|
|
#include "hgpk.h"
|
2005-05-29 01:30:22 -06:00
|
|
|
#include "lifebook.h"
|
2005-08-08 00:26:18 -06:00
|
|
|
#include "trackpoint.h"
|
2007-02-17 23:49:10 -07:00
|
|
|
#include "touchkit_ps2.h"
|
2008-10-16 20:10:19 -06:00
|
|
|
#include "elantech.h"
|
2009-05-10 19:15:39 -06:00
|
|
|
#include "sentelic.h"
|
2013-01-05 01:14:22 -07:00
|
|
|
#include "cypress_ps2.h"
|
2014-09-12 18:24:47 -06:00
|
|
|
#include "focaltech.h"
|
2015-04-14 11:06:38 -06:00
|
|
|
#include "vmmouse.h"
|
2016-01-27 18:04:35 -07:00
|
|
|
#include "byd.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define DRIVER_DESC "PS/2 mouse driver"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
|
2010-08-11 23:04:12 -06:00
|
|
|
static int psmouse_set_maxproto(const char *val, const struct kernel_param *);
|
|
|
|
static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp);
|
2015-05-26 19:39:38 -06:00
|
|
|
static const struct kernel_param_ops param_ops_proto_abbrev = {
|
2010-08-11 23:04:12 -06:00
|
|
|
.set = psmouse_set_maxproto,
|
|
|
|
.get = psmouse_get_maxproto,
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
|
|
|
|
module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
|
2005-06-01 01:40:01 -06:00
|
|
|
MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
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.");
|
|
|
|
|
2015-05-26 15:07:12 -06:00
|
|
|
static bool psmouse_smartscroll = true;
|
2005-04-16 16:20:36 -06:00
|
|
|
module_param_named(smartscroll, psmouse_smartscroll, bool, 0644);
|
|
|
|
MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
|
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
static unsigned int psmouse_resetafter = 5;
|
2005-04-16 16:20:36 -06:00
|
|
|
module_param_named(resetafter, psmouse_resetafter, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
|
|
|
|
|
2006-03-10 22:23:38 -07:00
|
|
|
static unsigned int psmouse_resync_time;
|
2006-01-13 22:27:37 -07:00
|
|
|
module_param_named(resync_time, psmouse_resync_time, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never).");
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
|
|
|
|
NULL,
|
|
|
|
psmouse_attr_show_protocol, psmouse_attr_set_protocol);
|
|
|
|
PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO,
|
|
|
|
(void *) offsetof(struct psmouse, rate),
|
|
|
|
psmouse_show_int_attr, psmouse_attr_set_rate);
|
|
|
|
PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
|
|
|
|
(void *) offsetof(struct psmouse, resolution),
|
|
|
|
psmouse_show_int_attr, psmouse_attr_set_resolution);
|
|
|
|
PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
|
|
|
|
(void *) offsetof(struct psmouse, resetafter),
|
|
|
|
psmouse_show_int_attr, psmouse_set_int_attr);
|
2006-01-13 22:27:37 -07:00
|
|
|
PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO,
|
|
|
|
(void *) offsetof(struct psmouse, resync_time),
|
|
|
|
psmouse_show_int_attr, psmouse_set_int_attr);
|
2005-09-04 00:40:20 -06:00
|
|
|
|
|
|
|
static struct attribute *psmouse_attributes[] = {
|
|
|
|
&psmouse_attr_protocol.dattr.attr,
|
|
|
|
&psmouse_attr_rate.dattr.attr,
|
|
|
|
&psmouse_attr_resolution.dattr.attr,
|
|
|
|
&psmouse_attr_resetafter.dattr.attr,
|
2006-01-13 22:27:37 -07:00
|
|
|
&psmouse_attr_resync_time.dattr.attr,
|
2005-09-04 00:40:20 -06:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group psmouse_attribute_group = {
|
|
|
|
.attrs = psmouse_attributes,
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-01 01:39:44 -06:00
|
|
|
/*
|
2006-02-18 22:22:11 -07:00
|
|
|
* psmouse_mutex protects all operations changing state of mouse
|
2005-06-01 01:39:44 -06:00
|
|
|
* (connecting, disconnecting, changing rate or resolution via
|
|
|
|
* sysfs). We could use a per-device semaphore but since there
|
|
|
|
* rarely more than one PS/2 mouse connected and since semaphore
|
|
|
|
* is taken in "slow" paths it is not worth it.
|
|
|
|
*/
|
2006-02-18 22:22:11 -07:00
|
|
|
static DEFINE_MUTEX(psmouse_mutex);
|
2005-06-01 01:39:44 -06:00
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
static struct workqueue_struct *kpsmoused_wq;
|
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
struct psmouse_protocol {
|
|
|
|
enum psmouse_type type;
|
2009-09-09 20:13:20 -06:00
|
|
|
bool maxproto;
|
2010-04-19 01:42:16 -06:00
|
|
|
bool ignore_parity; /* Protocol should ignore parity errors from KBC */
|
Input: psmouse - limit protocols that we try on passthrough ports
PS/2 protocol is slow, and using it with pass-through port (where we
encapsulate PS/2 into PS/2) is slower yet so it takes quite a bit of time
to do full protocol discovery for device attached to a pass-through port.
However, so far we have not see anything but trackpoints or basic PS/2
mice on pass-through ports, so let's limit protocols that we probe there
to Trackpoint, IntelliMouse Explorer, IntelliMouse, and bare PS/2 protocol,
and avoid other extended protocols, such as Synaptics, ALPS, etc.
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-11-24 13:58:46 -07:00
|
|
|
bool try_passthru; /* Try protocol also on passthrough ports */
|
2006-09-10 19:54:39 -06:00
|
|
|
const char *name;
|
|
|
|
const char *alias;
|
2009-09-09 20:13:20 -06:00
|
|
|
int (*detect)(struct psmouse *, bool);
|
2005-06-01 01:40:01 -06:00
|
|
|
int (*init)(struct psmouse *);
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_process_byte() analyzes the PS/2 data stream and reports
|
|
|
|
* relevant events to the input module once full packet has arrived.
|
|
|
|
*/
|
Input: synaptics - add support for Relative mode
Currently, the synaptics driver puts the device into Absolute mode.
As explained in the synaptics documentation section 3.2, in this mode,
the device sends a continuous stream of packets at the maximum rate
to the host when the user's fingers are near or on the pad or
pressing buttons, and continues streaming for 1 second afterwards.
These packets are even sent when there is no new information to report,
even when they are duplicates of the previous packet.
For embedded systems this is a bit much - it results in a huge
and uninterrupted stream of interrupts at high rate.
This patch adds support for Relative mode, which can be selected as
a new psmouse protocol. In this mode, the device does not send duplicate
packets and acts like a standard PS/2 mouse. However, synaptics-specific
functionality is still available, such as the ability to set the packet
rate, and rather than disabling gestures and taps at the hardware level
unconditionally, a 'synaptics_disable_gesture' sysfs attribute has
been added to allow control of this functionality.
This solves a long standing OLPC issue: synaptics hardware enables
tap to click by default (even in the default relative mode), but we
have found this to be inappropriate for young children and first
time computer users. Enabling the synaptics driver disables tap-to-click,
but we have previously been unable to use this because it also enables
Absolute mode, which is too "spammy" for our desires and actually
overloads our EC with its continuous stream of packets. Now we can enable
the synaptics driver, disabling tap to click while retaining the less
noisy Relative mode.
Signed-off-by: Daniel Drake <dsd@laptop.org>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2011-11-08 01:00:35 -07:00
|
|
|
psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-09-15 01:01:44 -06:00
|
|
|
struct input_dev *dev = psmouse->dev;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned char *packet = psmouse->packet;
|
|
|
|
|
|
|
|
if (psmouse->pktcnt < psmouse->pktsize)
|
|
|
|
return PSMOUSE_GOOD_DATA;
|
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
/* Full packet accumulated, process it */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
switch (psmouse->type) {
|
|
|
|
case PSMOUSE_IMPS:
|
|
|
|
/* IntelliMouse has scroll wheel */
|
2005-04-16 16:20:36 -06:00
|
|
|
input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
|
2015-11-27 21:29:22 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
case PSMOUSE_IMEX:
|
|
|
|
/* Scroll wheel and buttons on IntelliMouse Explorer */
|
2006-06-25 23:56:08 -06:00
|
|
|
switch (packet[3] & 0xC0) {
|
2010-05-19 11:39:17 -06:00
|
|
|
case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
|
|
|
|
input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
|
|
|
|
break;
|
|
|
|
case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */
|
|
|
|
input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31));
|
|
|
|
break;
|
|
|
|
case 0x00:
|
|
|
|
case 0xC0:
|
|
|
|
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);
|
|
|
|
break;
|
2006-06-25 23:56:08 -06:00
|
|
|
}
|
2015-11-27 21:29:22 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
case PSMOUSE_GENPS:
|
|
|
|
/* Report scroll buttons on NetMice */
|
|
|
|
input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
/* Extra buttons on Genius NewNet 3D */
|
2005-04-16 16:20:36 -06:00
|
|
|
input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1);
|
|
|
|
input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1);
|
2015-11-27 21:29:22 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
case PSMOUSE_THINKPS:
|
|
|
|
/* Extra button on ThinkingMouse */
|
2005-04-16 16:20:36 -06:00
|
|
|
input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1);
|
2015-11-27 21:29:22 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Without this bit of weirdness moving up gives wildly
|
|
|
|
* high Y changes.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
packet[1] |= (packet[0] & 0x40) << 1;
|
2015-11-27 21:29:22 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
case PSMOUSE_CORTRON:
|
|
|
|
/*
|
|
|
|
* Cortron PS2 Trackball reports SIDE button in the
|
|
|
|
* 4th bit of the first byte.
|
|
|
|
*/
|
2007-05-09 23:47:18 -06:00
|
|
|
input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1);
|
|
|
|
packet[0] |= 0x08;
|
2015-11-27 21:29:22 -07:00
|
|
|
break;
|
2007-05-09 23:47:18 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:29:22 -07:00
|
|
|
/* Generic PS/2 Mouse */
|
2005-04-16 16:20:36 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-16 10:30:33 -06:00
|
|
|
void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
|
|
|
|
unsigned long delay)
|
|
|
|
{
|
|
|
|
queue_delayed_work(kpsmoused_wq, work, delay);
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2006-01-13 22:27:37 -07:00
|
|
|
* __psmouse_set_state() sets new psmouse state and resets all flags.
|
|
|
|
*/
|
|
|
|
static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
|
|
|
|
{
|
|
|
|
psmouse->state = new_state;
|
2009-09-09 20:13:20 -06:00
|
|
|
psmouse->pktcnt = psmouse->out_of_sync_cnt = 0;
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->ps2dev.flags = 0;
|
|
|
|
psmouse->last = jiffies;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-09-16 10:30:33 -06:00
|
|
|
void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
|
2006-01-13 22:27:37 -07:00
|
|
|
{
|
|
|
|
serio_pause_rx(psmouse->ps2dev.serio);
|
|
|
|
__psmouse_set_state(psmouse, new_state);
|
|
|
|
serio_continue_rx(psmouse->ps2dev.serio);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_handle_byte() processes one byte of the input data stream
|
|
|
|
* by calling corresponding protocol handler.
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
static int psmouse_handle_byte(struct psmouse *psmouse)
|
2006-01-13 22:27:37 -07:00
|
|
|
{
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
psmouse_ret_t rc = psmouse->protocol_handler(psmouse);
|
2006-01-13 22:27:37 -07:00
|
|
|
|
|
|
|
switch (rc) {
|
2010-05-19 11:39:17 -06:00
|
|
|
case PSMOUSE_BAD_DATA:
|
|
|
|
if (psmouse->state == PSMOUSE_ACTIVATED) {
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse,
|
|
|
|
"%s at %s lost sync at byte %d\n",
|
|
|
|
psmouse->name, psmouse->phys,
|
|
|
|
psmouse->pktcnt);
|
2010-05-19 11:39:17 -06:00
|
|
|
if (++psmouse->out_of_sync_cnt == psmouse->resetafter) {
|
|
|
|
__psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_notice(psmouse,
|
|
|
|
"issuing reconnect request\n");
|
2010-05-19 11:39:17 -06:00
|
|
|
serio_reconnect(psmouse->ps2dev.serio);
|
|
|
|
return -1;
|
2006-01-13 22:27:37 -07:00
|
|
|
}
|
2010-05-19 11:39:17 -06:00
|
|
|
}
|
|
|
|
psmouse->pktcnt = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSMOUSE_FULL_PACKET:
|
|
|
|
psmouse->pktcnt = 0;
|
|
|
|
if (psmouse->out_of_sync_cnt) {
|
|
|
|
psmouse->out_of_sync_cnt = 0;
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_notice(psmouse,
|
|
|
|
"%s at %s - driver resynced.\n",
|
|
|
|
psmouse->name, psmouse->phys);
|
2010-05-19 11:39:17 -06:00
|
|
|
}
|
|
|
|
break;
|
2006-01-13 22:27:37 -07:00
|
|
|
|
2010-05-19 11:39:17 -06:00
|
|
|
case PSMOUSE_GOOD_DATA:
|
|
|
|
break;
|
2006-01-13 22:27:37 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_interrupt() handles incoming characters, either passing them
|
|
|
|
* for normal processing or gathering them as command response.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
static irqreturn_t psmouse_interrupt(struct serio *serio,
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
unsigned char data, unsigned int flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct psmouse *psmouse = serio_get_drvdata(serio);
|
|
|
|
|
|
|
|
if (psmouse->state == PSMOUSE_IGNORE)
|
|
|
|
goto out;
|
|
|
|
|
2010-04-19 01:42:16 -06:00
|
|
|
if (unlikely((flags & SERIO_TIMEOUT) ||
|
|
|
|
((flags & SERIO_PARITY) && !psmouse->ignore_parity))) {
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (psmouse->state == PSMOUSE_ACTIVATED)
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse,
|
|
|
|
"bad data from KBC -%s%s\n",
|
|
|
|
flags & SERIO_TIMEOUT ? " timeout" : "",
|
|
|
|
flags & SERIO_PARITY ? " bad parity" : "");
|
2005-04-16 16:20:36 -06:00
|
|
|
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;
|
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
if (psmouse->state <= PSMOUSE_RESYNCING)
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (psmouse->state == PSMOUSE_ACTIVATED &&
|
|
|
|
psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_info(psmouse, "%s at %s lost synchronization, throwing %d bytes away.\n",
|
|
|
|
psmouse->name, psmouse->phys, psmouse->pktcnt);
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->badbyte = psmouse->packet[0];
|
|
|
|
__psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
|
2008-09-16 10:30:33 -06:00
|
|
|
psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
|
2006-01-13 22:27:37 -07:00
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
psmouse->packet[psmouse->pktcnt++] = data;
|
2015-11-27 21:47:08 -07:00
|
|
|
|
|
|
|
/* Check if this is a new device announcement (0xAA 0x00) */
|
2006-01-13 22:27:37 -07:00
|
|
|
if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) {
|
2006-04-28 23:12:44 -06:00
|
|
|
if (psmouse->pktcnt == 1) {
|
|
|
|
psmouse->last = jiffies;
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
2006-04-28 23:12:44 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-05-14 23:02:33 -06:00
|
|
|
if (psmouse->packet[1] == PSMOUSE_RET_ID ||
|
|
|
|
(psmouse->type == PSMOUSE_HGPK &&
|
|
|
|
psmouse->packet[1] == PSMOUSE_RET_BAT)) {
|
2006-01-13 22:27:37 -07:00
|
|
|
__psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
|
|
|
serio_reconnect(serio);
|
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2015-11-27 21:47:08 -07:00
|
|
|
|
|
|
|
/* Not a new device, try processing first byte normally */
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->pktcnt = 1;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
if (psmouse_handle_byte(psmouse))
|
2006-01-13 22:27:37 -07:00
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->packet[psmouse->pktcnt++] = data;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* See if we need to force resync because mouse was idle for
|
|
|
|
* too long.
|
|
|
|
*/
|
2006-01-13 22:27:37 -07:00
|
|
|
if (psmouse->state == PSMOUSE_ACTIVATED &&
|
|
|
|
psmouse->pktcnt == 1 && psmouse->resync_time &&
|
|
|
|
time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
|
|
|
|
psmouse->badbyte = psmouse->packet[0];
|
|
|
|
__psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
|
2008-09-16 10:30:33 -06:00
|
|
|
psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
|
2006-01-13 22:27:37 -07:00
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->last = jiffies;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
psmouse_handle_byte(psmouse);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
out:
|
2005-04-16 16:20:36 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
/*
|
|
|
|
* Here we set the mouse resolution.
|
|
|
|
*/
|
|
|
|
void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
|
|
|
|
{
|
|
|
|
static const unsigned char params[] = { 0, 1, 2, 2, 3 };
|
|
|
|
unsigned char p;
|
|
|
|
|
|
|
|
if (resolution == 0 || resolution > 200)
|
|
|
|
resolution = 200;
|
|
|
|
|
|
|
|
p = params[resolution / 50];
|
|
|
|
ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
|
|
|
|
psmouse->resolution = 25 << p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we set the mouse report rate.
|
|
|
|
*/
|
|
|
|
static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
|
|
|
|
{
|
|
|
|
static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
|
|
|
|
unsigned char r;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (rates[i] > rate) i++;
|
|
|
|
r = rates[i];
|
|
|
|
ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
|
|
|
|
psmouse->rate = r;
|
|
|
|
}
|
|
|
|
|
2015-03-07 14:32:10 -07:00
|
|
|
/*
|
|
|
|
* Here we set the mouse scaling.
|
|
|
|
*/
|
|
|
|
static void psmouse_set_scale(struct psmouse *psmouse, enum psmouse_scale scale)
|
|
|
|
{
|
|
|
|
ps2_command(&psmouse->ps2dev, NULL,
|
|
|
|
scale == PSMOUSE_SCALE21 ? PSMOUSE_CMD_SETSCALE21 :
|
|
|
|
PSMOUSE_CMD_SETSCALE11);
|
|
|
|
}
|
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
/*
|
|
|
|
* psmouse_poll() - default poll handler. Everyone except for ALPS uses it.
|
|
|
|
*/
|
|
|
|
static int psmouse_poll(struct psmouse *psmouse)
|
|
|
|
{
|
|
|
|
return ps2_command(&psmouse->ps2dev, psmouse->packet,
|
|
|
|
PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
|
|
|
|
}
|
|
|
|
|
2015-02-27 17:17:59 -07:00
|
|
|
static bool psmouse_check_pnp_id(const char *id, const char * const ids[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; ids[i]; i++)
|
|
|
|
if (!strcasecmp(id, ids[i]))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-11 11:14:09 -06:00
|
|
|
/*
|
|
|
|
* psmouse_matches_pnp_id - check if psmouse matches one of the passed in ids.
|
|
|
|
*/
|
|
|
|
bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[])
|
|
|
|
{
|
2015-02-27 17:17:59 -07:00
|
|
|
struct serio *serio = psmouse->ps2dev.serio;
|
|
|
|
char *p, *fw_id_copy, *save_ptr;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if (strncmp(serio->firmware_id, "PNP: ", 5))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fw_id_copy = kstrndup(&serio->firmware_id[5],
|
|
|
|
sizeof(serio->firmware_id) - 5,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!fw_id_copy)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
save_ptr = fw_id_copy;
|
|
|
|
while ((p = strsep(&fw_id_copy, " ")) != NULL) {
|
|
|
|
if (psmouse_check_pnp_id(p, ids)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-11 11:14:09 -06:00
|
|
|
|
2015-02-27 17:17:59 -07:00
|
|
|
kfree(save_ptr);
|
|
|
|
return found;
|
2014-09-11 11:14:09 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Genius NetMouse magic init.
|
|
|
|
*/
|
2009-09-09 20:13:20 -06:00
|
|
|
static int genius_detect(struct psmouse *psmouse, bool set_properties)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
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) {
|
2009-11-16 23:12:21 -07:00
|
|
|
__set_bit(BTN_MIDDLE, psmouse->dev->keybit);
|
2009-09-09 20:13:20 -06:00
|
|
|
__set_bit(BTN_EXTRA, psmouse->dev->keybit);
|
|
|
|
__set_bit(BTN_SIDE, psmouse->dev->keybit);
|
|
|
|
__set_bit(REL_WHEEL, psmouse->dev->relbit);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse->vendor = "Genius";
|
2006-01-29 19:50:46 -07:00
|
|
|
psmouse->name = "Mouse";
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse->pktsize = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IntelliMouse magic init.
|
|
|
|
*/
|
2009-09-09 20:13:20 -06:00
|
|
|
static int intellimouse_detect(struct psmouse *psmouse, bool set_properties)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
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) {
|
2009-09-09 20:13:20 -06:00
|
|
|
__set_bit(BTN_MIDDLE, psmouse->dev->keybit);
|
|
|
|
__set_bit(REL_WHEEL, psmouse->dev->relbit);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-16 23:12:21 -07:00
|
|
|
if (!psmouse->vendor)
|
|
|
|
psmouse->vendor = "Generic";
|
|
|
|
if (!psmouse->name)
|
|
|
|
psmouse->name = "Wheel Mouse";
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse->pktsize = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try IntelliMouse/Explorer magic init.
|
|
|
|
*/
|
2009-09-09 20:13:20 -06:00
|
|
|
static int im_explorer_detect(struct psmouse *psmouse, bool set_properties)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
|
2006-06-25 23:56:08 -06:00
|
|
|
param[0] = 200;
|
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
|
|
|
|
param[0] = 80;
|
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
|
|
|
|
param[0] = 40;
|
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (set_properties) {
|
2009-09-09 20:13:20 -06:00
|
|
|
__set_bit(BTN_MIDDLE, psmouse->dev->keybit);
|
|
|
|
__set_bit(REL_WHEEL, psmouse->dev->relbit);
|
|
|
|
__set_bit(REL_HWHEEL, psmouse->dev->relbit);
|
|
|
|
__set_bit(BTN_SIDE, psmouse->dev->keybit);
|
|
|
|
__set_bit(BTN_EXTRA, psmouse->dev->keybit);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-16 23:12:21 -07:00
|
|
|
if (!psmouse->vendor)
|
|
|
|
psmouse->vendor = "Generic";
|
|
|
|
if (!psmouse->name)
|
|
|
|
psmouse->name = "Explorer Mouse";
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse->pktsize = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kensington ThinkingMouse / ExpertMouse magic init.
|
|
|
|
*/
|
2009-09-09 20:13:20 -06:00
|
|
|
static int thinking_detect(struct psmouse *psmouse, bool set_properties)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ps2dev *ps2dev = &psmouse->ps2dev;
|
|
|
|
unsigned char param[2];
|
2006-09-10 19:54:39 -06:00
|
|
|
static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
|
2005-04-16 16:20:36 -06:00
|
|
|
int i;
|
|
|
|
|
|
|
|
param[0] = 10;
|
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
|
|
|
|
param[0] = 0;
|
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
|
2006-09-10 19:54:39 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(seq); i++) {
|
|
|
|
param[0] = seq[i];
|
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
|
|
|
|
|
|
|
|
if (param[0] != 2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (set_properties) {
|
2009-11-16 23:12:21 -07:00
|
|
|
__set_bit(BTN_MIDDLE, psmouse->dev->keybit);
|
2009-09-09 20:13:20 -06:00
|
|
|
__set_bit(BTN_EXTRA, psmouse->dev->keybit);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse->vendor = "Kensington";
|
|
|
|
psmouse->name = "ThinkingMouse";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bare PS/2 protocol "detection". Always succeeds.
|
|
|
|
*/
|
2009-09-09 20:13:20 -06:00
|
|
|
static int ps2bare_detect(struct psmouse *psmouse, bool set_properties)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-06-01 01:40:01 -06:00
|
|
|
if (set_properties) {
|
2009-11-16 23:12:21 -07:00
|
|
|
if (!psmouse->vendor)
|
|
|
|
psmouse->vendor = "Generic";
|
|
|
|
if (!psmouse->name)
|
|
|
|
psmouse->name = "Mouse";
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* We have no way of figuring true number of buttons so let's
|
|
|
|
* assume that the device has 3.
|
|
|
|
*/
|
2009-11-16 23:12:21 -07:00
|
|
|
__set_bit(BTN_MIDDLE, psmouse->dev->keybit);
|
2005-06-01 01:40:01 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-09 23:47:18 -06:00
|
|
|
/*
|
|
|
|
* Cortron PS/2 protocol detection. There's no special way to detect it, so it
|
|
|
|
* must be forced by sysfs protocol writing.
|
|
|
|
*/
|
2009-09-09 20:13:20 -06:00
|
|
|
static int cortron_detect(struct psmouse *psmouse, bool set_properties)
|
2007-05-09 23:47:18 -06:00
|
|
|
{
|
|
|
|
if (set_properties) {
|
|
|
|
psmouse->vendor = "Cortron";
|
|
|
|
psmouse->name = "PS/2 Trackball";
|
2009-11-16 23:12:21 -07:00
|
|
|
|
|
|
|
__set_bit(BTN_MIDDLE, psmouse->dev->keybit);
|
2009-09-09 20:13:20 -06:00
|
|
|
__set_bit(BTN_SIDE, psmouse->dev->keybit);
|
2007-05-09 23:47:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2015-11-27 22:08:28 -07:00
|
|
|
static const struct psmouse_protocol psmouse_protocols[] = {
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_PS2,
|
|
|
|
.name = "PS/2",
|
|
|
|
.alias = "bare",
|
|
|
|
.maxproto = true,
|
|
|
|
.ignore_parity = true,
|
|
|
|
.detect = ps2bare_detect,
|
Input: psmouse - limit protocols that we try on passthrough ports
PS/2 protocol is slow, and using it with pass-through port (where we
encapsulate PS/2 into PS/2) is slower yet so it takes quite a bit of time
to do full protocol discovery for device attached to a pass-through port.
However, so far we have not see anything but trackpoints or basic PS/2
mice on pass-through ports, so let's limit protocols that we probe there
to Trackpoint, IntelliMouse Explorer, IntelliMouse, and bare PS/2 protocol,
and avoid other extended protocols, such as Synaptics, ALPS, etc.
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-11-24 13:58:46 -07:00
|
|
|
.try_passthru = true,
|
2015-11-27 22:08:28 -07:00
|
|
|
},
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_LOGIPS2PP
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_PS2PP,
|
|
|
|
.name = "PS2++",
|
|
|
|
.alias = "logitech",
|
2015-12-02 12:02:39 -07:00
|
|
|
.detect = ps2pp_detect,
|
2015-11-27 22:08:28 -07:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_THINKPS,
|
|
|
|
.name = "ThinkPS/2",
|
|
|
|
.alias = "thinkps",
|
|
|
|
.detect = thinking_detect,
|
|
|
|
},
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_CYPRESS
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_CYPRESS,
|
|
|
|
.name = "CyPS/2",
|
|
|
|
.alias = "cypress",
|
|
|
|
.detect = cypress_detect,
|
|
|
|
.init = cypress_init,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_GENPS,
|
|
|
|
.name = "GenPS/2",
|
|
|
|
.alias = "genius",
|
|
|
|
.detect = genius_detect,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_IMPS,
|
|
|
|
.name = "ImPS/2",
|
|
|
|
.alias = "imps",
|
|
|
|
.maxproto = true,
|
|
|
|
.ignore_parity = true,
|
|
|
|
.detect = intellimouse_detect,
|
Input: psmouse - limit protocols that we try on passthrough ports
PS/2 protocol is slow, and using it with pass-through port (where we
encapsulate PS/2 into PS/2) is slower yet so it takes quite a bit of time
to do full protocol discovery for device attached to a pass-through port.
However, so far we have not see anything but trackpoints or basic PS/2
mice on pass-through ports, so let's limit protocols that we probe there
to Trackpoint, IntelliMouse Explorer, IntelliMouse, and bare PS/2 protocol,
and avoid other extended protocols, such as Synaptics, ALPS, etc.
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-11-24 13:58:46 -07:00
|
|
|
.try_passthru = true,
|
2015-11-27 22:08:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_IMEX,
|
|
|
|
.name = "ImExPS/2",
|
|
|
|
.alias = "exps",
|
|
|
|
.maxproto = true,
|
|
|
|
.ignore_parity = true,
|
|
|
|
.detect = im_explorer_detect,
|
Input: psmouse - limit protocols that we try on passthrough ports
PS/2 protocol is slow, and using it with pass-through port (where we
encapsulate PS/2 into PS/2) is slower yet so it takes quite a bit of time
to do full protocol discovery for device attached to a pass-through port.
However, so far we have not see anything but trackpoints or basic PS/2
mice on pass-through ports, so let's limit protocols that we probe there
to Trackpoint, IntelliMouse Explorer, IntelliMouse, and bare PS/2 protocol,
and avoid other extended protocols, such as Synaptics, ALPS, etc.
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-11-24 13:58:46 -07:00
|
|
|
.try_passthru = true,
|
2015-11-27 22:08:28 -07:00
|
|
|
},
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_SYNAPTICS
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_SYNAPTICS,
|
|
|
|
.name = "SynPS/2",
|
|
|
|
.alias = "synaptics",
|
|
|
|
.detect = synaptics_detect,
|
|
|
|
.init = synaptics_init,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_SYNAPTICS_RELATIVE,
|
|
|
|
.name = "SynRelPS/2",
|
|
|
|
.alias = "synaptics-relative",
|
|
|
|
.detect = synaptics_detect,
|
|
|
|
.init = synaptics_init_relative,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_ALPS
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_ALPS,
|
|
|
|
.name = "AlpsPS/2",
|
|
|
|
.alias = "alps",
|
|
|
|
.detect = alps_detect,
|
|
|
|
.init = alps_init,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_LIFEBOOK
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_LIFEBOOK,
|
|
|
|
.name = "LBPS/2",
|
|
|
|
.alias = "lifebook",
|
2015-11-27 22:17:40 -07:00
|
|
|
.detect = lifebook_detect,
|
2015-11-27 22:08:28 -07:00
|
|
|
.init = lifebook_init,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_TRACKPOINT
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_TRACKPOINT,
|
|
|
|
.name = "TPPS/2",
|
|
|
|
.alias = "trackpoint",
|
|
|
|
.detect = trackpoint_detect,
|
Input: psmouse - limit protocols that we try on passthrough ports
PS/2 protocol is slow, and using it with pass-through port (where we
encapsulate PS/2 into PS/2) is slower yet so it takes quite a bit of time
to do full protocol discovery for device attached to a pass-through port.
However, so far we have not see anything but trackpoints or basic PS/2
mice on pass-through ports, so let's limit protocols that we probe there
to Trackpoint, IntelliMouse Explorer, IntelliMouse, and bare PS/2 protocol,
and avoid other extended protocols, such as Synaptics, ALPS, etc.
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-11-24 13:58:46 -07:00
|
|
|
.try_passthru = true,
|
2015-11-27 22:08:28 -07:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_TOUCHKIT
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_TOUCHKIT_PS2,
|
|
|
|
.name = "touchkitPS/2",
|
|
|
|
.alias = "touchkit",
|
|
|
|
.detect = touchkit_ps2_detect,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_OLPC
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_HGPK,
|
|
|
|
.name = "OLPC HGPK",
|
|
|
|
.alias = "hgpk",
|
|
|
|
.detect = hgpk_detect,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_ELANTECH
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_ELANTECH,
|
|
|
|
.name = "ETPS/2",
|
|
|
|
.alias = "elantech",
|
|
|
|
.detect = elantech_detect,
|
|
|
|
.init = elantech_init,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_SENTELIC
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_FSP,
|
|
|
|
.name = "FSPPS/2",
|
|
|
|
.alias = "fsp",
|
|
|
|
.detect = fsp_detect,
|
|
|
|
.init = fsp_init,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_CORTRON,
|
|
|
|
.name = "CortronPS/2",
|
|
|
|
.alias = "cortps",
|
|
|
|
.detect = cortron_detect,
|
|
|
|
},
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_FOCALTECH
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_FOCALTECH,
|
|
|
|
.name = "FocalTechPS/2",
|
|
|
|
.alias = "focaltech",
|
|
|
|
.detect = focaltech_detect,
|
|
|
|
.init = focaltech_init,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_VMMOUSE
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_VMMOUSE,
|
|
|
|
.name = VMMOUSE_PSNAME,
|
|
|
|
.alias = "vmmouse",
|
|
|
|
.detect = vmmouse_detect,
|
|
|
|
.init = vmmouse_init,
|
|
|
|
},
|
2016-01-27 18:04:35 -07:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MOUSE_PS2_BYD
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_BYD,
|
2016-03-14 10:41:16 -06:00
|
|
|
.name = "BYDPS/2",
|
2016-01-27 18:04:35 -07:00
|
|
|
.alias = "byd",
|
|
|
|
.detect = byd_detect,
|
|
|
|
.init = byd_init,
|
|
|
|
},
|
2015-11-27 22:08:28 -07:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.type = PSMOUSE_AUTO,
|
|
|
|
.name = "auto",
|
|
|
|
.alias = "any",
|
|
|
|
.maxproto = true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
static const struct psmouse_protocol *__psmouse_protocol_by_type(enum psmouse_type type)
|
2015-11-27 22:08:28 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
|
|
|
|
if (psmouse_protocols[i].type == type)
|
|
|
|
return &psmouse_protocols[i];
|
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
|
|
|
|
{
|
|
|
|
const struct psmouse_protocol *proto;
|
|
|
|
|
|
|
|
proto = __psmouse_protocol_by_type(type);
|
|
|
|
if (proto)
|
|
|
|
return proto;
|
|
|
|
|
2015-11-27 22:08:28 -07:00
|
|
|
WARN_ON(1);
|
|
|
|
return &psmouse_protocols[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
|
|
|
|
{
|
|
|
|
const struct psmouse_protocol *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
|
|
|
|
p = &psmouse_protocols[i];
|
|
|
|
|
|
|
|
if ((strlen(p->name) == len && !strncmp(p->name, name, len)) ||
|
|
|
|
(strlen(p->alias) == len && !strncmp(p->alias, name, len)))
|
|
|
|
return &psmouse_protocols[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
/*
|
|
|
|
* Apply default settings to the psmouse structure. Most of them will
|
|
|
|
* be overridden by individual protocol initialization routines.
|
|
|
|
*/
|
|
|
|
static void psmouse_apply_defaults(struct psmouse *psmouse)
|
|
|
|
{
|
|
|
|
struct input_dev *input_dev = psmouse->dev;
|
|
|
|
|
|
|
|
memset(input_dev->evbit, 0, sizeof(input_dev->evbit));
|
|
|
|
memset(input_dev->keybit, 0, sizeof(input_dev->keybit));
|
|
|
|
memset(input_dev->relbit, 0, sizeof(input_dev->relbit));
|
|
|
|
memset(input_dev->absbit, 0, sizeof(input_dev->absbit));
|
|
|
|
memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit));
|
|
|
|
|
|
|
|
__set_bit(EV_KEY, input_dev->evbit);
|
|
|
|
__set_bit(EV_REL, input_dev->evbit);
|
|
|
|
|
|
|
|
__set_bit(BTN_LEFT, input_dev->keybit);
|
|
|
|
__set_bit(BTN_RIGHT, input_dev->keybit);
|
|
|
|
|
|
|
|
__set_bit(REL_X, input_dev->relbit);
|
|
|
|
__set_bit(REL_Y, input_dev->relbit);
|
|
|
|
|
2014-09-08 15:44:05 -06:00
|
|
|
__set_bit(INPUT_PROP_POINTER, input_dev->propbit);
|
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
psmouse->set_rate = psmouse_set_rate;
|
|
|
|
psmouse->set_resolution = psmouse_set_resolution;
|
2015-03-07 14:32:10 -07:00
|
|
|
psmouse->set_scale = psmouse_set_scale;
|
2011-12-30 16:16:45 -07:00
|
|
|
psmouse->poll = psmouse_poll;
|
|
|
|
psmouse->protocol_handler = psmouse_process_byte;
|
|
|
|
psmouse->pktsize = 3;
|
|
|
|
psmouse->reconnect = NULL;
|
|
|
|
psmouse->disconnect = NULL;
|
|
|
|
psmouse->cleanup = NULL;
|
|
|
|
psmouse->pt_activate = NULL;
|
|
|
|
psmouse->pt_deactivate = NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
static bool psmouse_try_protocol(struct psmouse *psmouse,
|
|
|
|
enum psmouse_type type,
|
|
|
|
unsigned int *max_proto,
|
|
|
|
bool set_properties, bool init_allowed)
|
2011-12-30 16:16:45 -07:00
|
|
|
{
|
2015-11-27 22:17:40 -07:00
|
|
|
const struct psmouse_protocol *proto;
|
|
|
|
|
|
|
|
proto = __psmouse_protocol_by_type(type);
|
|
|
|
if (!proto)
|
|
|
|
return false;
|
|
|
|
|
Input: psmouse - limit protocols that we try on passthrough ports
PS/2 protocol is slow, and using it with pass-through port (where we
encapsulate PS/2 into PS/2) is slower yet so it takes quite a bit of time
to do full protocol discovery for device attached to a pass-through port.
However, so far we have not see anything but trackpoints or basic PS/2
mice on pass-through ports, so let's limit protocols that we probe there
to Trackpoint, IntelliMouse Explorer, IntelliMouse, and bare PS/2 protocol,
and avoid other extended protocols, such as Synaptics, ALPS, etc.
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-11-24 13:58:46 -07:00
|
|
|
if (psmouse->ps2dev.serio->id.type == SERIO_PS_PSTHRU &&
|
|
|
|
!proto->try_passthru) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
if (set_properties)
|
|
|
|
psmouse_apply_defaults(psmouse);
|
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
if (proto->detect(psmouse, set_properties) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (set_properties && proto->init && init_allowed) {
|
|
|
|
if (proto->init(psmouse) != 0) {
|
|
|
|
/*
|
|
|
|
* We detected device, but init failed. Adjust
|
|
|
|
* max_proto so we only try standard protocols.
|
|
|
|
*/
|
|
|
|
if (*max_proto > PSMOUSE_IMEX)
|
|
|
|
*max_proto = PSMOUSE_IMEX;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-12-30 16:16:45 -07:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* psmouse_extensions() probes for any extensions to the basic PS/2 protocol
|
|
|
|
* the mouse may have.
|
|
|
|
*/
|
|
|
|
static int psmouse_extensions(struct psmouse *psmouse,
|
2009-09-09 20:13:20 -06:00
|
|
|
unsigned int max_proto, bool set_properties)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-11-16 23:12:13 -07:00
|
|
|
bool synaptics_hardware = false;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Always check for focaltech, this is safe as it uses pnp-id
|
|
|
|
* matching.
|
|
|
|
*/
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_FOCALTECH,
|
|
|
|
&max_proto, set_properties, false)) {
|
|
|
|
if (max_proto > PSMOUSE_IMEX &&
|
|
|
|
IS_ENABLED(CONFIG_MOUSE_PS2_FOCALTECH) &&
|
|
|
|
(!set_properties || focaltech_init(psmouse) == 0)) {
|
|
|
|
return PSMOUSE_FOCALTECH;
|
2014-09-12 18:24:47 -06:00
|
|
|
}
|
2015-11-27 21:52:36 -07:00
|
|
|
/*
|
|
|
|
* Restrict psmouse_max_proto so that psmouse_initialize()
|
|
|
|
* does not try to reset rate and resolution, because even
|
|
|
|
* that upsets the device.
|
|
|
|
* This also causes us to basically fall through to basic
|
|
|
|
* protocol detection, where we fully reset the mouse,
|
|
|
|
* and set it up as bare PS/2 protocol device.
|
|
|
|
*/
|
|
|
|
psmouse_max_proto = max_proto = PSMOUSE_PS2;
|
2014-09-12 18:24:47 -06:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* We always check for LifeBook because it does not disturb mouse
|
|
|
|
* (it only checks DMI information).
|
|
|
|
*/
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_LIFEBOOK, &max_proto,
|
|
|
|
set_properties, max_proto > PSMOUSE_IMEX))
|
|
|
|
return PSMOUSE_LIFEBOOK;
|
2005-05-29 01:30:22 -06:00
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_VMMOUSE, &max_proto,
|
|
|
|
set_properties, max_proto > PSMOUSE_IMEX))
|
|
|
|
return PSMOUSE_VMMOUSE;
|
2015-04-14 11:06:38 -06:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Try Kensington ThinkingMouse (we try first, because Synaptics
|
|
|
|
* probe upsets the ThinkingMouse).
|
|
|
|
*/
|
2011-12-30 16:16:45 -07:00
|
|
|
if (max_proto > PSMOUSE_IMEX &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_THINKPS, &max_proto,
|
|
|
|
set_properties, true)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
return PSMOUSE_THINKPS;
|
2011-12-30 16:16:45 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Try Synaptics TouchPad. Note that probing is done even if
|
|
|
|
* Synaptics protocol support is disabled in config - we need to
|
|
|
|
* know if it is Synaptics so we can reset it properly after
|
|
|
|
* probing for IntelliMouse.
|
|
|
|
*/
|
2011-12-30 16:16:45 -07:00
|
|
|
if (max_proto > PSMOUSE_PS2 &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_SYNAPTICS, &max_proto,
|
|
|
|
set_properties, false)) {
|
2009-09-09 20:13:20 -06:00
|
|
|
synaptics_hardware = true;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (max_proto > PSMOUSE_IMEX) {
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Try activating protocol, but check if support is
|
|
|
|
* enabled first, since we try detecting Synaptics
|
|
|
|
* even when protocol is disabled.
|
|
|
|
*/
|
2014-12-29 13:06:38 -07:00
|
|
|
if (IS_ENABLED(CONFIG_MOUSE_PS2_SYNAPTICS) &&
|
2010-01-07 02:52:39 -07:00
|
|
|
(!set_properties || synaptics_init(psmouse) == 0)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
return PSMOUSE_SYNAPTICS;
|
2010-01-07 02:52:39 -07:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
max_proto = PSMOUSE_IMEX;
|
|
|
|
}
|
2015-11-27 21:47:08 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that touchpad is in relative mode, gestures
|
|
|
|
* (taps) are enabled.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
synaptics_reset(psmouse);
|
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Try Cypress Trackpad. We must try it before Finger Sensing Pad
|
|
|
|
* because Finger Sensing Pad probe upsets some modules of Cypress
|
|
|
|
* Trackpads.
|
|
|
|
*/
|
2013-01-05 01:14:22 -07:00
|
|
|
if (max_proto > PSMOUSE_IMEX &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_CYPRESS, &max_proto,
|
|
|
|
set_properties, true)) {
|
|
|
|
return PSMOUSE_CYPRESS;
|
2013-01-05 01:14:22 -07:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/* Try ALPS TouchPad */
|
2005-04-16 16:20:36 -06:00
|
|
|
if (max_proto > PSMOUSE_IMEX) {
|
|
|
|
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_ALPS,
|
|
|
|
&max_proto, set_properties, true))
|
|
|
|
return PSMOUSE_ALPS;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/* Try OLPC HGPK touchpad */
|
2008-09-16 10:30:34 -06:00
|
|
|
if (max_proto > PSMOUSE_IMEX &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_HGPK, &max_proto,
|
|
|
|
set_properties, true)) {
|
|
|
|
return PSMOUSE_HGPK;
|
2008-09-16 10:30:34 -06:00
|
|
|
}
|
2007-02-17 23:49:10 -07:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/* Try Elantech touchpad */
|
2008-10-16 20:10:19 -06:00
|
|
|
if (max_proto > PSMOUSE_IMEX &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_ELANTECH,
|
|
|
|
&max_proto, set_properties, true)) {
|
|
|
|
return PSMOUSE_ELANTECH;
|
2008-10-16 20:10:19 -06:00
|
|
|
}
|
|
|
|
|
2008-09-16 10:30:34 -06:00
|
|
|
if (max_proto > PSMOUSE_IMEX) {
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_GENPS,
|
|
|
|
&max_proto, set_properties, true))
|
2007-02-17 23:49:10 -07:00
|
|
|
return PSMOUSE_GENPS;
|
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_PS2PP,
|
|
|
|
&max_proto, set_properties, true))
|
2007-02-17 23:49:10 -07:00
|
|
|
return PSMOUSE_PS2PP;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_TRACKPOINT,
|
|
|
|
&max_proto, set_properties, true))
|
2007-02-17 23:49:10 -07:00
|
|
|
return PSMOUSE_TRACKPOINT;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 22:17:40 -07:00
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_TOUCHKIT_PS2,
|
|
|
|
&max_proto, set_properties, true))
|
2007-02-17 23:49:10 -07:00
|
|
|
return PSMOUSE_TOUCHKIT_PS2;
|
2016-01-27 18:04:35 -07:00
|
|
|
|
|
|
|
if (psmouse_try_protocol(psmouse, PSMOUSE_BYD,
|
|
|
|
&max_proto, set_properties, true))
|
|
|
|
return PSMOUSE_BYD;
|
2007-02-17 23:49:10 -07:00
|
|
|
}
|
2005-12-20 22:51:31 -07:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Try Finger Sensing Pad. We do it here because its probe upsets
|
|
|
|
* Trackpoint devices (causing TP_READ_ID command to time out).
|
|
|
|
*/
|
2015-11-27 22:17:40 -07:00
|
|
|
if (max_proto > PSMOUSE_IMEX &&
|
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_FSP,
|
|
|
|
&max_proto, set_properties, true)) {
|
|
|
|
return PSMOUSE_FSP;
|
2010-01-13 01:16:27 -07:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Reset to defaults in case the device got confused by extended
|
|
|
|
* protocol probes. Note that we follow up with full reset because
|
|
|
|
* some mice put themselves to sleep when they see PSMOUSE_RESET_DIS.
|
|
|
|
*/
|
2007-08-29 22:22:48 -06:00
|
|
|
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
|
2005-12-20 22:51:31 -07:00
|
|
|
psmouse_reset(psmouse);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
if (max_proto >= PSMOUSE_IMEX &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_IMEX,
|
|
|
|
&max_proto, set_properties, true)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
return PSMOUSE_IMEX;
|
2011-12-30 16:16:45 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-12-30 16:16:45 -07:00
|
|
|
if (max_proto >= PSMOUSE_IMPS &&
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_IMPS,
|
|
|
|
&max_proto, set_properties, true)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
return PSMOUSE_IMPS;
|
2011-12-30 16:16:45 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Okay, all failed, we have a standard mouse here. The number of
|
|
|
|
* the buttons is still a question, though. We assume 3.
|
|
|
|
*/
|
2015-11-27 22:17:40 -07:00
|
|
|
psmouse_try_protocol(psmouse, PSMOUSE_PS2,
|
|
|
|
&max_proto, set_properties, true);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (synaptics_hardware) {
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse_reset(psmouse);
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
* Sunrex K8561 IR Keyboard/Mouse reports 0xff on second and
|
|
|
|
* subsequent ID queries, probably due to a firmware bug.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
param[0] = 0xa5;
|
|
|
|
if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID))
|
|
|
|
return -1;
|
|
|
|
|
2005-05-28 01:11:42 -06:00
|
|
|
if (param[0] != 0x00 && param[0] != 0x03 &&
|
|
|
|
param[0] != 0x04 && param[0] != 0xff)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -1;
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Then we reset and disable the mouse so that it doesn't generate
|
|
|
|
* events.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS))
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse, "Failed to reset mouse on %s\n",
|
|
|
|
ps2dev->serio->phys);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_initialize() initializes the mouse to a sane state.
|
|
|
|
*/
|
|
|
|
static void psmouse_initialize(struct psmouse *psmouse)
|
|
|
|
{
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* We set the mouse report rate, resolution and scaling.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
if (psmouse_max_proto != PSMOUSE_PS2) {
|
|
|
|
psmouse->set_rate(psmouse, psmouse->rate);
|
|
|
|
psmouse->set_resolution(psmouse, psmouse->resolution);
|
2015-03-07 14:32:10 -07:00
|
|
|
psmouse->set_scale(psmouse, PSMOUSE_SCALE11);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_activate() enables the mouse so that we get motion reports from it.
|
|
|
|
*/
|
2012-02-24 01:51:37 -07:00
|
|
|
int psmouse_activate(struct psmouse *psmouse)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-02-24 01:51:37 -07:00
|
|
|
if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse, "Failed to enable mouse on %s\n",
|
|
|
|
psmouse->ps2dev.serio->phys);
|
2012-02-24 01:51:37 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
|
2012-02-24 01:51:37 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-11-27 21:47:08 -07:00
|
|
|
* psmouse_deactivate() puts the mouse into poll mode so that we don't get
|
|
|
|
* motion reports from it unless we explicitly request it.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2012-02-24 01:51:37 -07:00
|
|
|
int psmouse_deactivate(struct psmouse *psmouse)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-02-24 01:51:37 -07:00
|
|
|
if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) {
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse, "Failed to deactivate mouse on %s\n",
|
|
|
|
psmouse->ps2dev.serio->phys);
|
2012-02-24 01:51:37 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
|
2012-02-24 01:51:37 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
/*
|
|
|
|
* psmouse_resync() attempts to re-validate current protocol.
|
|
|
|
*/
|
2006-11-22 07:57:56 -07:00
|
|
|
static void psmouse_resync(struct work_struct *work)
|
2006-01-13 22:27:37 -07:00
|
|
|
{
|
2006-11-22 07:57:56 -07:00
|
|
|
struct psmouse *parent = NULL, *psmouse =
|
2008-09-16 10:30:33 -06:00
|
|
|
container_of(work, struct psmouse, resync_work.work);
|
2006-01-13 22:27:37 -07:00
|
|
|
struct serio *serio = psmouse->ps2dev.serio;
|
|
|
|
psmouse_ret_t rc = PSMOUSE_GOOD_DATA;
|
2009-09-09 20:13:20 -06:00
|
|
|
bool failed = false, enabled = false;
|
2006-01-13 22:27:37 -07:00
|
|
|
int i;
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_lock(&psmouse_mutex);
|
2006-01-13 22:27:37 -07:00
|
|
|
|
|
|
|
if (psmouse->state != PSMOUSE_RESYNCING)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
|
|
|
|
parent = serio_get_drvdata(serio->parent);
|
|
|
|
psmouse_deactivate(parent);
|
|
|
|
}
|
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Some mice don't ACK commands sent while they are in the middle of
|
|
|
|
* transmitting motion packet. To avoid delay we use ps2_sendbyte()
|
|
|
|
* instead of ps2_command() which would wait for 200ms for an ACK
|
|
|
|
* that may never come.
|
|
|
|
* As an additional quirk ALPS touchpads may not only forget to ACK
|
|
|
|
* disable command but will stop reporting taps, so if we see that
|
|
|
|
* mouse at least once ACKs disable we will do full reconnect if ACK
|
|
|
|
* is missing.
|
|
|
|
*/
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->num_resyncs++;
|
|
|
|
|
|
|
|
if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) {
|
|
|
|
if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command)
|
2009-09-09 20:13:20 -06:00
|
|
|
failed = true;
|
2006-01-13 22:27:37 -07:00
|
|
|
} else
|
2009-09-09 20:13:20 -06:00
|
|
|
psmouse->acks_disable_command = true;
|
2006-01-13 22:27:37 -07:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Poll the mouse. If it was reset the packet will be shorter than
|
|
|
|
* psmouse->pktsize and ps2_command will fail. We do not expect and
|
|
|
|
* do not handle scenario when mouse "upgrades" its protocol while
|
|
|
|
* disconnected since it would require additional delay. If we ever
|
|
|
|
* see a mouse that does it we'll adjust the code.
|
|
|
|
*/
|
2006-01-13 22:27:37 -07:00
|
|
|
if (!failed) {
|
|
|
|
if (psmouse->poll(psmouse))
|
2009-09-09 20:13:20 -06:00
|
|
|
failed = true;
|
2006-01-13 22:27:37 -07:00
|
|
|
else {
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
|
|
|
|
for (i = 0; i < psmouse->pktsize; i++) {
|
|
|
|
psmouse->pktcnt++;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
rc = psmouse->protocol_handler(psmouse);
|
2006-01-13 22:27:37 -07:00
|
|
|
if (rc != PSMOUSE_GOOD_DATA)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rc != PSMOUSE_FULL_PACKET)
|
2009-09-09 20:13:20 -06:00
|
|
|
failed = true;
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
|
|
|
|
}
|
|
|
|
}
|
2015-11-27 21:47:08 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now try to enable mouse. We try to do that even if poll failed
|
|
|
|
* and also repeat our attempts 5 times, otherwise we may be left
|
|
|
|
* out with disabled mouse.
|
|
|
|
*/
|
2006-01-13 22:27:37 -07:00
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
|
2009-09-09 20:13:20 -06:00
|
|
|
enabled = true;
|
2006-01-13 22:27:37 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
msleep(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enabled) {
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse, "failed to re-enable mouse on %s\n",
|
|
|
|
psmouse->ps2dev.serio->phys);
|
2009-09-09 20:13:20 -06:00
|
|
|
failed = true;
|
2006-01-13 22:27:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_info(psmouse,
|
|
|
|
"resync failed, issuing reconnect request\n");
|
2006-01-13 22:27:37 -07:00
|
|
|
serio_reconnect(serio);
|
|
|
|
} else
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
psmouse_activate(parent);
|
|
|
|
out:
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_unlock(&psmouse_mutex);
|
2006-01-13 22:27:37 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_cleanup() resets the mouse into power-on state.
|
|
|
|
*/
|
|
|
|
static void psmouse_cleanup(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct psmouse *psmouse = serio_get_drvdata(serio);
|
2007-02-17 23:40:24 -07:00
|
|
|
struct psmouse *parent = NULL;
|
|
|
|
|
|
|
|
mutex_lock(&psmouse_mutex);
|
|
|
|
|
|
|
|
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
|
|
|
|
parent = serio_get_drvdata(serio->parent);
|
|
|
|
psmouse_deactivate(parent);
|
|
|
|
}
|
|
|
|
|
2010-02-08 00:10:04 -07:00
|
|
|
psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable stream mode so cleanup routine can proceed undisturbed.
|
|
|
|
*/
|
|
|
|
if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE))
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse, "Failed to disable mouse on %s\n",
|
|
|
|
psmouse->ps2dev.serio->phys);
|
2007-02-17 23:40:24 -07:00
|
|
|
|
|
|
|
if (psmouse->cleanup)
|
|
|
|
psmouse->cleanup(psmouse);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Reset the mouse to defaults (bare PS/2 protocol).
|
|
|
|
*/
|
2009-12-24 22:40:24 -07:00
|
|
|
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
|
2007-02-17 23:40:24 -07:00
|
|
|
|
2015-11-27 21:47:08 -07:00
|
|
|
/*
|
|
|
|
* Some boxes, such as HP nx7400, get terribly confused if mouse
|
|
|
|
* is not fully enabled before suspending/shutting down.
|
|
|
|
*/
|
2007-02-17 23:40:24 -07:00
|
|
|
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
if (parent->pt_deactivate)
|
|
|
|
parent->pt_deactivate(parent);
|
|
|
|
|
|
|
|
psmouse_activate(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&psmouse_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* psmouse_disconnect() closes and frees.
|
|
|
|
*/
|
|
|
|
static void psmouse_disconnect(struct serio *serio)
|
|
|
|
{
|
2005-06-01 01:39:44 -06:00
|
|
|
struct psmouse *psmouse, *parent = NULL;
|
|
|
|
|
|
|
|
psmouse = serio_get_drvdata(serio);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_lock(&psmouse_mutex);
|
2005-06-01 01:39:44 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
|
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
/* make sure we don't have a resync in progress */
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_unlock(&psmouse_mutex);
|
2006-01-13 22:27:37 -07:00
|
|
|
flush_workqueue(kpsmoused_wq);
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_lock(&psmouse_mutex);
|
2006-01-13 22:27:37 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
|
|
|
|
parent = serio_get_drvdata(serio->parent);
|
2005-06-01 01:39:44 -06:00
|
|
|
psmouse_deactivate(parent);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (psmouse->disconnect)
|
|
|
|
psmouse->disconnect(psmouse);
|
|
|
|
|
2005-06-01 01:39:44 -06:00
|
|
|
if (parent && parent->pt_deactivate)
|
|
|
|
parent->pt_deactivate(parent);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
|
|
|
|
|
|
|
serio_close(serio);
|
|
|
|
serio_set_drvdata(serio, NULL);
|
2005-09-15 01:01:44 -06:00
|
|
|
input_unregister_device(psmouse->dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree(psmouse);
|
2005-06-01 01:39:44 -06:00
|
|
|
|
|
|
|
if (parent)
|
|
|
|
psmouse_activate(parent);
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_unlock(&psmouse_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-11-16 23:12:21 -07:00
|
|
|
static int psmouse_switch_protocol(struct psmouse *psmouse,
|
|
|
|
const struct psmouse_protocol *proto)
|
2005-06-01 01:40:01 -06:00
|
|
|
{
|
2010-04-19 01:42:16 -06:00
|
|
|
const struct psmouse_protocol *selected_proto;
|
2005-09-15 01:01:44 -06:00
|
|
|
struct input_dev *input_dev = psmouse->dev;
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2007-04-11 23:35:09 -06:00
|
|
|
input_dev->dev.parent = &psmouse->ps2dev.serio->dev;
|
2005-06-01 01:40:01 -06:00
|
|
|
|
|
|
|
if (proto && (proto->detect || proto->init)) {
|
2011-12-30 16:16:45 -07:00
|
|
|
psmouse_apply_defaults(psmouse);
|
|
|
|
|
2010-05-19 11:39:17 -06:00
|
|
|
if (proto->detect && proto->detect(psmouse, true) < 0)
|
2005-06-01 01:40:01 -06:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (proto->init && proto->init(psmouse) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
psmouse->type = proto->type;
|
2010-04-19 01:42:16 -06:00
|
|
|
selected_proto = proto;
|
|
|
|
} else {
|
2009-09-09 20:13:20 -06:00
|
|
|
psmouse->type = psmouse_extensions(psmouse,
|
|
|
|
psmouse_max_proto, true);
|
2010-04-19 01:42:16 -06:00
|
|
|
selected_proto = psmouse_protocol_by_type(psmouse->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
psmouse->ignore_parity = selected_proto->ignore_parity;
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
/*
|
|
|
|
* If mouse's packet size is 3 there is no point in polling the
|
|
|
|
* device in hopes to detect protocol reset - we won't get less
|
|
|
|
* than 3 bytes response anyhow.
|
|
|
|
*/
|
|
|
|
if (psmouse->pktsize == 3)
|
|
|
|
psmouse->resync_time = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some smart KVMs fake response to POLL command returning just
|
|
|
|
* 3 bytes and messing up our resync logic, so if initial poll
|
|
|
|
* fails we won't try polling the device anymore. Hopefully
|
|
|
|
* such KVM will maintain initially selected protocol.
|
|
|
|
*/
|
|
|
|
if (psmouse->resync_time && psmouse->poll(psmouse))
|
|
|
|
psmouse->resync_time = 0;
|
|
|
|
|
2006-06-25 23:45:10 -06:00
|
|
|
snprintf(psmouse->devname, sizeof(psmouse->devname), "%s %s %s",
|
2010-04-19 01:42:16 -06:00
|
|
|
selected_proto->name, psmouse->vendor, psmouse->name);
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2005-09-15 01:01:44 -06:00
|
|
|
input_dev->name = psmouse->devname;
|
|
|
|
input_dev->phys = psmouse->phys;
|
|
|
|
input_dev->id.bustype = BUS_I8042;
|
|
|
|
input_dev->id.vendor = 0x0002;
|
|
|
|
input_dev->id.product = psmouse->type;
|
|
|
|
input_dev->id.version = psmouse->model;
|
2005-06-01 01:40:01 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* 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;
|
2005-09-15 01:01:44 -06:00
|
|
|
struct input_dev *input_dev;
|
2006-11-05 20:40:19 -07:00
|
|
|
int retval = 0, error = -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_lock(&psmouse_mutex);
|
2005-06-01 01:39:44 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2005-09-15 01:01:44 -06:00
|
|
|
psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!psmouse || !input_dev)
|
2006-11-05 20:40:19 -07:00
|
|
|
goto err_free;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
ps2_init(&psmouse->ps2dev, serio);
|
2008-09-16 10:30:33 -06:00
|
|
|
INIT_DELAYED_WORK(&psmouse->resync_work, psmouse_resync);
|
2005-09-15 01:01:44 -06:00
|
|
|
psmouse->dev = input_dev;
|
2006-06-25 23:45:10 -06:00
|
|
|
snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys);
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
|
|
|
|
|
|
|
|
serio_set_drvdata(serio, psmouse);
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
error = serio_open(serio, drv);
|
|
|
|
if (error)
|
|
|
|
goto err_clear_drvdata;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-08-26 14:11:49 -06:00
|
|
|
/* give PT device some time to settle down before probing */
|
|
|
|
if (serio->id.type == SERIO_PS_PSTHRU)
|
|
|
|
usleep_range(10000, 15000);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (psmouse_probe(psmouse) < 0) {
|
2006-11-05 20:40:19 -07:00
|
|
|
error = -ENODEV;
|
|
|
|
goto err_close_serio;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
psmouse->rate = psmouse_rate;
|
|
|
|
psmouse->resolution = psmouse_resolution;
|
|
|
|
psmouse->resetafter = psmouse_resetafter;
|
2006-01-13 22:27:37 -07:00
|
|
|
psmouse->resync_time = parent ? 0 : psmouse_resync_time;
|
2005-04-16 16:20:36 -06:00
|
|
|
psmouse->smartscroll = psmouse_smartscroll;
|
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
psmouse_switch_protocol(psmouse, NULL);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
|
|
|
|
psmouse_initialize(psmouse);
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
error = input_register_device(psmouse->dev);
|
|
|
|
if (error)
|
|
|
|
goto err_protocol_disconnect;
|
2005-09-15 01:01:44 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (parent && parent->pt_activate)
|
|
|
|
parent->pt_activate(parent);
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
error = sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
|
|
|
|
if (error)
|
|
|
|
goto err_pt_deactivate;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse_activate(psmouse);
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
out:
|
2005-06-01 01:39:44 -06:00
|
|
|
/* If this is a pass-through port the parent needs to be re-activated */
|
2005-04-16 16:20:36 -06:00
|
|
|
if (parent)
|
|
|
|
psmouse_activate(parent);
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_unlock(&psmouse_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
return retval;
|
2006-11-05 20:40:19 -07:00
|
|
|
|
|
|
|
err_pt_deactivate:
|
|
|
|
if (parent && parent->pt_deactivate)
|
|
|
|
parent->pt_deactivate(parent);
|
2008-01-17 10:01:30 -07:00
|
|
|
input_unregister_device(psmouse->dev);
|
|
|
|
input_dev = NULL; /* so we don't try to free it below */
|
2006-11-05 20:40:19 -07:00
|
|
|
err_protocol_disconnect:
|
|
|
|
if (psmouse->disconnect)
|
|
|
|
psmouse->disconnect(psmouse);
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
|
|
|
err_close_serio:
|
|
|
|
serio_close(serio);
|
|
|
|
err_clear_drvdata:
|
|
|
|
serio_set_drvdata(serio, NULL);
|
|
|
|
err_free:
|
|
|
|
input_free_device(input_dev);
|
|
|
|
kfree(psmouse);
|
|
|
|
|
|
|
|
retval = error;
|
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int psmouse_reconnect(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct psmouse *psmouse = serio_get_drvdata(serio);
|
|
|
|
struct psmouse *parent = NULL;
|
2010-05-13 01:42:23 -06:00
|
|
|
unsigned char type;
|
2005-04-16 16:20:36 -06:00
|
|
|
int rc = -1;
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_lock(&psmouse_mutex);
|
2005-06-01 01:39:44 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
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;
|
2010-05-13 01:42:23 -06:00
|
|
|
} else {
|
|
|
|
psmouse_reset(psmouse);
|
|
|
|
|
|
|
|
if (psmouse_probe(psmouse) < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
type = psmouse_extensions(psmouse, psmouse_max_proto, false);
|
|
|
|
if (psmouse->type != type)
|
|
|
|
goto out;
|
2009-09-09 20:13:20 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-10-10 19:27:03 -06:00
|
|
|
/*
|
|
|
|
* OK, the device type (and capabilities) match the old one,
|
|
|
|
* we can continue using it, complete initialization
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_unlock(&psmouse_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr,
|
|
|
|
char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
2005-09-04 00:40:20 -06:00
|
|
|
struct psmouse_attribute *attr = to_psmouse_attr(devattr);
|
|
|
|
struct psmouse *psmouse;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
psmouse = serio_get_drvdata(serio);
|
|
|
|
|
2010-01-05 18:56:02 -07:00
|
|
|
return attr->show(psmouse, attr->data, buf);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
2005-09-04 00:40:20 -06:00
|
|
|
struct psmouse_attribute *attr = to_psmouse_attr(devattr);
|
|
|
|
struct psmouse *psmouse, *parent = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
int retval;
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
retval = mutex_lock_interruptible(&psmouse_mutex);
|
2005-06-01 01:39:44 -06:00
|
|
|
if (retval)
|
2010-01-05 18:56:02 -07:00
|
|
|
goto out;
|
2005-06-01 01:39:44 -06:00
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
psmouse = serio_get_drvdata(serio);
|
|
|
|
|
2008-09-16 10:30:34 -06:00
|
|
|
if (attr->protect) {
|
|
|
|
if (psmouse->state == PSMOUSE_IGNORE) {
|
|
|
|
retval = -ENODEV;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-09-16 10:30:34 -06:00
|
|
|
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
|
|
|
|
parent = serio_get_drvdata(serio->parent);
|
|
|
|
psmouse_deactivate(parent);
|
|
|
|
}
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2008-09-16 10:30:34 -06:00
|
|
|
psmouse_deactivate(psmouse);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
retval = attr->set(psmouse, attr->data, buf, count);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-09-16 10:30:34 -06:00
|
|
|
if (attr->protect) {
|
|
|
|
if (retval != -ENODEV)
|
|
|
|
psmouse_activate(psmouse);
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2008-09-16 10:30:34 -06:00
|
|
|
if (parent)
|
|
|
|
psmouse_activate(parent);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&psmouse_mutex);
|
2010-01-05 18:56:02 -07:00
|
|
|
out:
|
2005-04-16 16:20:36 -06:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
|
|
|
|
{
|
2006-11-08 22:34:27 -07:00
|
|
|
unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
|
2005-09-04 00:40:20 -06:00
|
|
|
|
2006-11-08 22:34:27 -07:00
|
|
|
return sprintf(buf, "%u\n", *field);
|
2005-09-04 00:40:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
|
|
|
|
{
|
2006-11-08 22:34:27 -07:00
|
|
|
unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
|
2011-11-09 11:20:14 -07:00
|
|
|
unsigned int value;
|
|
|
|
int err;
|
2005-09-04 00:40:20 -06:00
|
|
|
|
2011-11-09 11:20:14 -07:00
|
|
|
err = kstrtouint(buf, 10, &value);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2006-11-08 22:34:27 -07:00
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
*field = value;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf)
|
2005-06-01 01:40:01 -06:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
|
|
|
|
}
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
2005-06-01 01:40:01 -06:00
|
|
|
{
|
|
|
|
struct serio *serio = psmouse->ps2dev.serio;
|
|
|
|
struct psmouse *parent = NULL;
|
2006-11-05 20:40:19 -07:00
|
|
|
struct input_dev *old_dev, *new_dev;
|
|
|
|
const struct psmouse_protocol *proto, *old_proto;
|
|
|
|
int error;
|
2005-06-01 01:40:01 -06:00
|
|
|
int retry = 0;
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
proto = psmouse_protocol_by_name(buf, count);
|
|
|
|
if (!proto)
|
2005-06-01 01:40:01 -06:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (psmouse->type == proto->type)
|
|
|
|
return count;
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
new_dev = input_allocate_device();
|
|
|
|
if (!new_dev)
|
2005-09-15 01:01:44 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-10-04 22:46:10 -06:00
|
|
|
while (!list_empty(&serio->children)) {
|
2005-06-01 01:40:01 -06:00
|
|
|
if (++retry > 3) {
|
2011-10-10 19:27:03 -06:00
|
|
|
psmouse_warn(psmouse,
|
|
|
|
"failed to destroy children ports, protocol change aborted.\n");
|
2005-09-15 01:01:44 -06:00
|
|
|
input_free_device(new_dev);
|
2005-06-01 01:40:01 -06:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_unlock(&psmouse_mutex);
|
2005-06-01 01:40:01 -06:00
|
|
|
serio_unregister_child_port(serio);
|
2006-02-18 22:22:11 -07:00
|
|
|
mutex_lock(&psmouse_mutex);
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2005-09-15 01:01:44 -06:00
|
|
|
if (serio->drv != &psmouse_drv) {
|
|
|
|
input_free_device(new_dev);
|
2005-06-01 01:40:01 -06:00
|
|
|
return -ENODEV;
|
2005-09-15 01:01:44 -06:00
|
|
|
}
|
2005-06-01 01:40:01 -06:00
|
|
|
|
2005-09-15 01:01:44 -06:00
|
|
|
if (psmouse->type == proto->type) {
|
|
|
|
input_free_device(new_dev);
|
2005-06-01 01:40:01 -06:00
|
|
|
return count; /* switched by other thread */
|
2005-09-15 01:01:44 -06:00
|
|
|
}
|
2005-06-01 01:40:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
|
|
|
|
parent = serio_get_drvdata(serio->parent);
|
|
|
|
if (parent->pt_deactivate)
|
|
|
|
parent->pt_deactivate(parent);
|
|
|
|
}
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
old_dev = psmouse->dev;
|
|
|
|
old_proto = psmouse_protocol_by_type(psmouse->type);
|
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
if (psmouse->disconnect)
|
|
|
|
psmouse->disconnect(psmouse);
|
|
|
|
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
|
|
|
|
2005-09-15 01:01:44 -06:00
|
|
|
psmouse->dev = new_dev;
|
2005-06-01 01:40:01 -06:00
|
|
|
psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
|
|
|
|
|
|
|
|
if (psmouse_switch_protocol(psmouse, proto) < 0) {
|
|
|
|
psmouse_reset(psmouse);
|
|
|
|
/* default to PSMOUSE_PS2 */
|
|
|
|
psmouse_switch_protocol(psmouse, &psmouse_protocols[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
psmouse_initialize(psmouse);
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
|
|
|
|
|
2006-11-05 20:40:19 -07:00
|
|
|
error = input_register_device(psmouse->dev);
|
|
|
|
if (error) {
|
|
|
|
if (psmouse->disconnect)
|
|
|
|
psmouse->disconnect(psmouse);
|
|
|
|
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_IGNORE);
|
|
|
|
input_free_device(new_dev);
|
|
|
|
psmouse->dev = old_dev;
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
|
|
|
|
psmouse_switch_protocol(psmouse, old_proto);
|
|
|
|
psmouse_initialize(psmouse);
|
|
|
|
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_unregister_device(old_dev);
|
2005-06-01 01:40:01 -06:00
|
|
|
|
|
|
|
if (parent && parent->pt_activate)
|
|
|
|
parent->pt_activate(parent);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-11-09 11:20:14 -07:00
|
|
|
unsigned int value;
|
|
|
|
int err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-11-09 11:20:14 -07:00
|
|
|
err = kstrtouint(buf, 10, &value);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse->set_rate(psmouse, value);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2005-09-04 00:40:20 -06:00
|
|
|
static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-11-09 11:20:14 -07:00
|
|
|
unsigned int value;
|
|
|
|
int err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-11-09 11:20:14 -07:00
|
|
|
err = kstrtouint(buf, 10, &value);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
psmouse->set_resolution(psmouse, value);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-11 23:04:12 -06:00
|
|
|
static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-10 19:54:39 -06:00
|
|
|
const struct psmouse_protocol *proto;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (!val)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
proto = psmouse_protocol_by_name(val, strlen(val));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
if (!proto || !proto->maxproto)
|
|
|
|
return -EINVAL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-01 01:40:01 -06:00
|
|
|
*((unsigned int *)kp->arg) = proto->type;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-08-08 00:26:18 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-08-11 23:04:12 -06:00
|
|
|
static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-06-01 01:40:01 -06:00
|
|
|
int type = *((unsigned int *)kp->arg);
|
|
|
|
|
2009-11-13 00:30:52 -07:00
|
|
|
return sprintf(buffer, "%s", psmouse_protocol_by_type(type)->name);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init psmouse_init(void)
|
|
|
|
{
|
2006-11-23 21:35:10 -07:00
|
|
|
int err;
|
|
|
|
|
2009-12-04 00:21:14 -07:00
|
|
|
lifebook_module_init();
|
|
|
|
synaptics_module_init();
|
2010-11-11 23:19:57 -07:00
|
|
|
hgpk_module_init();
|
2009-12-04 00:21:14 -07:00
|
|
|
|
2006-01-13 22:27:37 -07:00
|
|
|
kpsmoused_wq = create_singlethread_workqueue("kpsmoused");
|
|
|
|
if (!kpsmoused_wq) {
|
2011-10-10 19:27:03 -06:00
|
|
|
pr_err("failed to create kpsmoused workqueue\n");
|
2006-01-13 22:27:37 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-11-23 21:35:10 -07:00
|
|
|
err = serio_register_driver(&psmouse_drv);
|
|
|
|
if (err)
|
|
|
|
destroy_workqueue(kpsmoused_wq);
|
2006-01-13 22:27:37 -07:00
|
|
|
|
2006-11-23 21:35:10 -07:00
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit psmouse_exit(void)
|
|
|
|
{
|
|
|
|
serio_unregister_driver(&psmouse_drv);
|
2006-01-13 22:27:37 -07:00
|
|
|
destroy_workqueue(kpsmoused_wq);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(psmouse_init);
|
|
|
|
module_exit(psmouse_exit);
|