2004-09-29 06:48:06

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 0/8] Set of input (psmouse) patches

Hi Vojtech,

Here is new bunch of small psmouse patches. Nothing particularly interesting
except probably exporting rate, resolution, resetafter and smartscroll
parameters as sysfs attributes. Protocol exporting and switching is still
in progress though...

01-alps-signature.patch
- add a new signature to ALPS response table (Inspiron 8500)

02-rate-resolution-handlers.patch
- add set_rate and set_resolution handlers to psmouse structure
to reduce dependencies between protocols, helps wihen exporting
resolutin and rate via sysfs

03-synaptics-guest-protocol-switch.patch
- not only set 4 byte guest protocol but also reset it back to 3
if for some odd reason user reconnects guest requesting lower
protocol.

04-psmouse-probe-fix.patch
- patch from Marko Macek dealing with probing and his KVM (the thing
doctors stream and gets confused by the extended probes)

05-psmouse-sysfs-attr.patch
- export rate, resolution, resetafter and smartscroll as sysfs
attributes.

06-psmouse-drop-ps2tpp.patch
- get rid of PS2T++ protocol symbol as it it handled exactly the same
as PS2++. This leaves space for THINKPS protocol and allows keeping
old Synaptics and Alps protocol numbers that Synaptics X driver
relied on.

07-separate-ps2pp-handling.patch
- complete separation of PS2++ protocol deconding by moving everything
into logips2pp.c - cleanup.

08-psmouse-packet-size.patch
- add pktsize to psmouse structure and check it instead on relying on
protcol numbering. Also rearrange detect routines in preparation to
dynamic protocol switching via sysfs.

Please let me know what you think and I will push it on bkbits.

Thanks!

--
Dmitry


2004-09-29 06:48:11

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 1/8] New ALPS signature


===================================================================


[email protected], 2004-09-25 22:36:41-05:00, [email protected]
Input: add a new signature for ALPS DualPoint found in
Dell Inspiron 8500

Signed-off-by: Dmitry Torokhov <[email protected]>


alps.c | 1 +
1 files changed, 1 insertion(+)


===================================================================



diff -Nru a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
--- a/drivers/input/mouse/alps.c 2004-09-29 01:14:35 -05:00
+++ b/drivers/input/mouse/alps.c 2004-09-29 01:14:35 -05:00
@@ -48,6 +48,7 @@
{ { 0x20, 0x02, 0x0e }, ALPS_MODEL_DUALPOINT },
{ { 0x22, 0x02, 0x0a }, ALPS_MODEL_DUALPOINT },
{ { 0x22, 0x02, 0x14 }, ALPS_MODEL_DUALPOINT },
+ { { 0x63, 0x03, 0xc8 }, ALPS_MODEL_DUALPOINT },
};

/*

2004-09-29 06:51:04

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 2/8] Psmouse rate and resolution handlers


===================================================================


[email protected], 2004-09-28 00:07:10-05:00, [email protected]
Input: psmouse - add set_rate and set_resolution handlers to make
adding new protocols easier and remove special knowledge
from psmouse-base.c

Signed-off-by: Dmitry Torokhov <[email protected]>


logips2pp.c | 22 ++++++++++++++--------
logips2pp.h | 1 -
psmouse-base.c | 43 ++++++++++++++++++++-----------------------
psmouse.h | 8 +++++++-
synaptics.c | 37 +++++++++++++++++++++++++++----------
synaptics.h | 1 +
6 files changed, 69 insertions(+), 43 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
--- a/drivers/input/mouse/logips2pp.c 2004-09-29 01:15:50 -05:00
+++ b/drivers/input/mouse/logips2pp.c 2004-09-29 01:15:50 -05:00
@@ -137,15 +137,19 @@
* also good reasons to use it, let the user decide).
*/

-void ps2pp_set_800dpi(struct psmouse *psmouse)
+static void ps2pp_set_resolution(struct psmouse *psmouse, unsigned int resolution)
{
- struct ps2dev *ps2dev = &psmouse->ps2dev;
- unsigned char param = 3;
-
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
- ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
+ if (resolution > 400) {
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+ unsigned char param = 3;
+
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
+ ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
+ psmouse->resolution = 800;
+ } else
+ psmouse_set_resolution(psmouse, resolution);
}

static struct ps2pp_info *get_model_info(unsigned char model)
@@ -299,6 +303,8 @@
if (set_properties) {
psmouse->vendor = "Logitech";
psmouse->model = model;
+ if (protocol == PSMOUSE_PS2PP)
+ psmouse->set_resolution = ps2pp_set_resolution;

if (buttons < 3)
clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
diff -Nru a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
--- a/drivers/input/mouse/logips2pp.h 2004-09-29 01:15:50 -05:00
+++ b/drivers/input/mouse/logips2pp.h 2004-09-29 01:15:50 -05:00
@@ -12,7 +12,6 @@
#define _LOGIPS2PP_H

void ps2pp_process_packet(struct psmouse *psmouse);
-void ps2pp_set_800dpi(struct psmouse *psmouse);
int ps2pp_init(struct psmouse *psmouse, int set_properties);

#endif
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c 2004-09-29 01:15:50 -05:00
+++ b/drivers/input/mouse/psmouse-base.c 2004-09-29 01:15:50 -05:00
@@ -36,11 +36,11 @@
module_param_named(proto, psmouse_proto, charp, 0);
MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps). Useful for KVM switches.");

-int psmouse_resolution = 200;
+static unsigned int psmouse_resolution = 200;
module_param_named(resolution, psmouse_resolution, uint, 0);
MODULE_PARM_DESC(resolution, "Resolution, in dpi.");

-unsigned int psmouse_rate = 100;
+static unsigned int psmouse_rate = 100;
module_param_named(rate, psmouse_rate, uint, 0);
MODULE_PARM_DESC(rate, "Report rate, in reports per second.");

@@ -521,38 +521,29 @@
* Here we set the mouse resolution.
*/

-static void psmouse_set_resolution(struct psmouse *psmouse)
+void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
{
- unsigned char param[1];
+ unsigned char params[] = { 0, 1, 2, 2, 3 };

- if (psmouse->type == PSMOUSE_PS2PP && psmouse_resolution > 400) {
- ps2pp_set_800dpi(psmouse);
- return;
- }
-
- if (!psmouse_resolution || psmouse_resolution >= 200)
- param[0] = 3;
- else if (psmouse_resolution >= 100)
- param[0] = 2;
- else if (psmouse_resolution >= 50)
- param[0] = 1;
- else if (psmouse_resolution)
- param[0] = 0;
+ if (resolution == 0 || resolution > 200)
+ resolution = 200;

- ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRES);
+ ps2_command(&psmouse->ps2dev, &params[resolution / 50], PSMOUSE_CMD_SETRES);
+ psmouse->resolution = 25 << params[resolution / 50];
}

/*
* Here we set the mouse report rate.
*/

-static void psmouse_set_rate(struct psmouse *psmouse)
+static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
{
unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
int i = 0;

- while (rates[i] > psmouse_rate) i++;
- ps2_command(&psmouse->ps2dev, rates + i, PSMOUSE_CMD_SETRATE);
+ while (rates[i] > rate) i++;
+ ps2_command(&psmouse->ps2dev, &rates[i], PSMOUSE_CMD_SETRATE);
+ psmouse->rate = rates[i];
}

/*
@@ -568,8 +559,8 @@
*/

if (psmouse_max_proto != PSMOUSE_PS2) {
- psmouse_set_rate(psmouse);
- psmouse_set_resolution(psmouse);
+ psmouse->set_rate(psmouse, psmouse->rate);
+ psmouse->set_resolution(psmouse, psmouse->resolution);
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
}

@@ -709,6 +700,8 @@
goto out;
}

+ psmouse->rate = psmouse_rate;
+ psmouse->resolution = psmouse_resolution;
psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
if (!psmouse->vendor)
psmouse->vendor = "Generic";
@@ -716,6 +709,10 @@
psmouse->name = "Mouse";
if (!psmouse->protocol_handler)
psmouse->protocol_handler = psmouse_process_byte;
+ if (!psmouse->set_rate)
+ psmouse->set_rate = psmouse_set_rate;
+ if (!psmouse->set_resolution)
+ psmouse->set_resolution = psmouse_set_resolution;

sprintf(psmouse->devname, "%s %s %s",
psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
--- a/drivers/input/mouse/psmouse.h 2004-09-29 01:15:50 -05:00
+++ b/drivers/input/mouse/psmouse.h 2004-09-29 01:15:50 -05:00
@@ -50,7 +50,13 @@
char devname[64];
char phys[32];

+ unsigned int rate;
+ unsigned int resolution;
+
psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse, struct pt_regs *regs);
+ void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
+ void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
+
int (*reconnect)(struct psmouse *psmouse);
void (*disconnect)(struct psmouse *psmouse);

@@ -73,8 +79,8 @@

int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
int psmouse_reset(struct psmouse *psmouse);
+void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);

extern int psmouse_smartscroll;
-extern unsigned int psmouse_rate;

#endif /* _PSMOUSE_H */
diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
--- a/drivers/input/mouse/synaptics.c 2004-09-29 01:15:50 -05:00
+++ b/drivers/input/mouse/synaptics.c 2004-09-29 01:15:50 -05:00
@@ -193,23 +193,37 @@
return 0;
}

-static int synaptics_set_mode(struct psmouse *psmouse, int mode)
+static int synaptics_set_absolute_mode(struct psmouse *psmouse)
{
struct synaptics_data *priv = psmouse->private;

- mode |= SYN_BIT_ABSOLUTE_MODE;
- if (psmouse_rate >= 80)
- mode |= SYN_BIT_HIGH_RATE;
+ priv->mode = SYN_BIT_ABSOLUTE_MODE;
if (SYN_ID_MAJOR(priv->identity) >= 4)
- mode |= SYN_BIT_DISABLE_GESTURE;
+ priv->mode |= SYN_BIT_DISABLE_GESTURE;
if (SYN_CAP_EXTENDED(priv->capabilities))
- mode |= SYN_BIT_W_MODE;
- if (synaptics_mode_cmd(psmouse, mode))
+ priv->mode |= SYN_BIT_W_MODE;
+
+ if (synaptics_mode_cmd(psmouse, priv->mode))
return -1;

return 0;
}

+static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate)
+{
+ struct synaptics_data *priv = psmouse->private;
+
+ if (rate >= 80) {
+ priv->mode |= SYN_BIT_HIGH_RATE;
+ psmouse->rate = 80;
+ } else {
+ priv->mode &= ~SYN_BIT_HIGH_RATE;
+ psmouse->rate = 40;
+ }
+
+ synaptics_mode_cmd(psmouse, priv->mode);
+}
+
/*****************************************************************************
* Synaptics pass-through PS/2 port support
****************************************************************************/
@@ -247,10 +261,12 @@
static void synaptics_pt_activate(struct psmouse *psmouse)
{
struct psmouse *child = psmouse->ps2dev.serio->child->private;
+ struct synaptics_data *priv = psmouse->private;

/* adjust the touchpad to child's choice of protocol */
if (child && child->type >= PSMOUSE_GENPS) {
- if (synaptics_set_mode(psmouse, SYN_BIT_FOUR_BYTE_CLIENT))
+ priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
+ if (synaptics_mode_cmd(psmouse, priv->mode))
printk(KERN_INFO "synaptics: failed to enable 4-byte guest protocol\n");
}
}
@@ -552,7 +568,7 @@
old_priv.ext_cap != priv->ext_cap)
return -1;

- if (synaptics_set_mode(psmouse, 0)) {
+ if (synaptics_set_absolute_mode(psmouse)) {
printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
return -1;
}
@@ -590,7 +606,7 @@
goto init_fail;
}

- if (synaptics_set_mode(psmouse, 0)) {
+ if (synaptics_set_absolute_mode(psmouse)) {
printk(KERN_ERR "Unable to initialize Synaptics hardware.\n");
goto init_fail;
}
@@ -604,6 +620,7 @@
set_input_params(&psmouse->dev, priv);

psmouse->protocol_handler = synaptics_process_byte;
+ psmouse->set_rate = synaptics_set_rate;
psmouse->disconnect = synaptics_disconnect;
psmouse->reconnect = synaptics_reconnect;

diff -Nru a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
--- a/drivers/input/mouse/synaptics.h 2004-09-29 01:15:50 -05:00
+++ b/drivers/input/mouse/synaptics.h 2004-09-29 01:15:50 -05:00
@@ -104,6 +104,7 @@
/* Data for normal processing */
int old_w; /* Previous w value */
unsigned char pkt_type; /* packet type - old, new, etc */
+ unsigned char mode; /* current mode byte */
};

#endif /* _SYNAPTICS_H */

2004-09-29 06:51:00

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 5/8] Export psmouse parameters via sysfs


===================================================================


[email protected], 2004-09-28 00:51:49-05:00, [email protected]
Input: psmouse - export rate, resolution, resetafter and smartscroll
(Logitech only) as individual mouse attributes (sysfs) and allow
them to be set/changed independently for each mouse:

echo -n "100" > /sys/bus/serio/devices/serio0/rate
echo -n "200" > /sys/bus/serio/devices/serio0/resolution


logips2pp.c | 48 +++++++++++++++++----
psmouse-base.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
psmouse.h | 22 +++++++++
3 files changed, 185 insertions(+), 12 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
--- a/drivers/input/mouse/logips2pp.c 2004-09-29 01:21:02 -05:00
+++ b/drivers/input/mouse/logips2pp.c 2004-09-29 01:21:02 -05:00
@@ -109,14 +109,17 @@
* enabled if we do nothing to it. Of course I put this in because I want it
* disabled :P
* 1 - enabled (if previously disabled, also default)
- * 0/2 - disabled
+ * 0 - disabled
*/

-static void ps2pp_set_smartscroll(struct psmouse *psmouse)
+static void ps2pp_set_smartscroll(struct psmouse *psmouse, unsigned int smartscroll)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[4];

+ if (smartscroll > 1)
+ smartscroll = 1;
+
ps2pp_cmd(psmouse, param, 0x32);

param[0] = 0;
@@ -124,13 +127,31 @@
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);

- if (psmouse_smartscroll < 2) {
- /* 0 - disabled, 1 - enabled */
- param[0] = psmouse_smartscroll;
- ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
- }
+ param[0] = smartscroll;
+ ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
+}
+
+static ssize_t psmouse_attr_show_smartscroll(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->smartscroll ? 1 : 0);
+}
+
+static ssize_t psmouse_attr_set_smartscroll(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest || value > 1)
+ return -EINVAL;
+
+ ps2pp_set_smartscroll(psmouse, value);
+ psmouse->smartscroll = value;
+ return count;
}

+PSMOUSE_DEFINE_ATTR(smartscroll);
+
/*
* Support 800 dpi resolution _only_ if the user wants it (there are good
* reasons to not use it even if the mouse supports it, and of course there are
@@ -152,6 +173,11 @@
psmouse_set_resolution(psmouse, resolution);
}

+static void ps2pp_disconnect(struct psmouse *psmouse)
+{
+ device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+}
+
static struct ps2pp_info *get_model_info(unsigned char model)
{
static struct ps2pp_info ps2pp_list[] = {
@@ -295,7 +321,7 @@
if ((param[0] & 0x78) == 0x48 &&
(param[1] & 0xf3) == 0xc2 &&
(param[2] & 0x03) == ((param[1] >> 2) & 3)) {
- ps2pp_set_smartscroll(psmouse);
+ ps2pp_set_smartscroll(psmouse, psmouse->smartscroll);
protocol = PSMOUSE_PS2PP;
}
}
@@ -303,8 +329,12 @@
if (set_properties) {
psmouse->vendor = "Logitech";
psmouse->model = model;
- if (protocol == PSMOUSE_PS2PP)
+ if (protocol == PSMOUSE_PS2PP) {
psmouse->set_resolution = ps2pp_set_resolution;
+ psmouse->disconnect = ps2pp_disconnect;
+
+ device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+ }

if (buttons < 3)
clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c 2004-09-29 01:21:02 -05:00
+++ b/drivers/input/mouse/psmouse-base.c 2004-09-29 01:21:02 -05:00
@@ -44,7 +44,7 @@
module_param_named(rate, psmouse_rate, uint, 0);
MODULE_PARM_DESC(rate, "Report rate, in reports per second.");

-int psmouse_smartscroll = 1;
+static unsigned int psmouse_smartscroll = 1;
module_param_named(smartscroll, psmouse_smartscroll, bool, 0);
MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");

@@ -52,6 +52,10 @@
module_param_named(resetafter, psmouse_resetafter, uint, 0);
MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");

+PSMOUSE_DEFINE_ATTR(rate);
+PSMOUSE_DEFINE_ATTR(resolution);
+PSMOUSE_DEFINE_ATTR(resetafter);
+
__obsolete_setup("psmouse_noext");
__obsolete_setup("psmouse_resolution=");
__obsolete_setup("psmouse_smartscroll=");
@@ -209,7 +213,7 @@
psmouse->name, psmouse->phys, psmouse->pktcnt);
psmouse->pktcnt = 0;

- if (++psmouse->out_of_sync == psmouse_resetafter) {
+ if (++psmouse->out_of_sync == psmouse->resetafter) {
psmouse->state = PSMOUSE_IGNORE;
printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n");
serio_reconnect(psmouse->ps2dev.serio);
@@ -638,6 +642,10 @@
{
struct psmouse *psmouse, *parent;

+ device_remove_file(&serio->dev, &psmouse_attr_rate);
+ device_remove_file(&serio->dev, &psmouse_attr_resolution);
+ device_remove_file(&serio->dev, &psmouse_attr_resetafter);
+
psmouse = serio->private;
psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);

@@ -706,6 +714,8 @@

psmouse->rate = psmouse_rate;
psmouse->resolution = psmouse_resolution;
+ psmouse->resetafter = psmouse_resetafter;
+ psmouse->smartscroll = psmouse_smartscroll;
psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
if (!psmouse->vendor)
psmouse->vendor = "Generic";
@@ -741,6 +751,10 @@
if (parent && parent->pt_activate)
parent->pt_activate(parent);

+ device_create_file(&serio->dev, &psmouse_attr_rate);
+ device_create_file(&serio->dev, &psmouse_attr_resolution);
+ device_create_file(&serio->dev, &psmouse_attr_resetafter);
+
if (serio->child) {
/*
* Nothing to be done here, serio core will detect that
@@ -817,6 +831,115 @@
.disconnect = psmouse_disconnect,
.cleanup = psmouse_cleanup,
};
+
+ssize_t psmouse_attr_show_helper(struct device *dev, char *buf,
+ ssize_t (*handler)(struct psmouse *, char *))
+{
+ struct serio *serio = to_serio_port(dev);
+ int retval;
+
+ retval = serio_pin_driver(serio);
+ if (retval)
+ return retval;
+
+ if (serio->drv != &psmouse_drv) {
+ retval = -ENODEV;
+ goto out;
+ }
+
+ retval = handler(serio->private, buf);
+
+out:
+ serio_unpin_driver(serio);
+ return retval;
+}
+
+ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count,
+ ssize_t (*handler)(struct psmouse *, const char *, size_t))
+{
+ struct serio *serio = to_serio_port(dev);
+ struct psmouse *psmouse = serio->private, *parent = NULL;
+ int retval;
+
+ retval = serio_pin_driver(serio);
+ if (retval)
+ return retval;
+
+ if (serio->drv != &psmouse_drv) {
+ retval = -ENODEV;
+ goto out;
+ }
+
+ if (serio->parent && (serio->type & SERIO_TYPE) == SERIO_PS_PSTHRU) {
+ parent = serio->parent->private;
+ psmouse_deactivate(parent);
+ }
+ psmouse_deactivate(psmouse);
+
+ retval = handler(psmouse, buf, count);
+
+ psmouse_activate(psmouse);
+ if (parent)
+ psmouse_activate(parent);
+
+out:
+ serio_unpin_driver(serio);
+ return retval;
+}
+
+static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->rate);
+}
+
+static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest)
+ return -EINVAL;
+
+ psmouse->set_rate(psmouse, value);
+ return count;
+}
+
+static ssize_t psmouse_attr_show_resolution(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->resolution);
+}
+
+static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest)
+ return -EINVAL;
+
+ psmouse->set_resolution(psmouse, value);
+ return count;
+}
+
+static ssize_t psmouse_attr_show_resetafter(struct psmouse *psmouse, char *buf)
+{
+ return sprintf(buf, "%d\n", psmouse->resetafter);
+}
+
+static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *buf, size_t count)
+{
+ unsigned long value;
+ char *rest;
+
+ value = simple_strtoul(buf, &rest, 10);
+ if (*rest)
+ return -EINVAL;
+
+ psmouse->resetafter = value;
+ return count;
+}

static inline void psmouse_parse_proto(void)
{
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
--- a/drivers/input/mouse/psmouse.h 2004-09-29 01:21:02 -05:00
+++ b/drivers/input/mouse/psmouse.h 2004-09-29 01:21:02 -05:00
@@ -52,6 +52,8 @@

unsigned int rate;
unsigned int resolution;
+ unsigned int resetafter;
+ unsigned int smartscroll; /* Logitech only */

psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse, struct pt_regs *regs);
void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
@@ -81,6 +83,24 @@
int psmouse_reset(struct psmouse *psmouse);
void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);

-extern int psmouse_smartscroll;
+ssize_t psmouse_attr_show_helper(struct device *dev, char *buf,
+ ssize_t (*handler)(struct psmouse *, char *));
+ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count,
+ int (*handler)(struct psmouse *, const char *, size_t));
+
+#define PSMOUSE_DEFINE_ATTR(_name) \
+static ssize_t psmouse_attr_show_##_name(struct psmouse *, char *); \
+static ssize_t psmouse_attr_set_##_name(struct psmouse *, const char *, size_t);\
+static ssize_t psmouse_do_show_##_name(struct device *d, char *b) \
+{ \
+ return psmouse_attr_show_helper(d, b, psmouse_attr_show_##_name); \
+} \
+static ssize_t psmouse_do_set_##_name(struct device *d, const char *b, size_t s)\
+{ \
+ return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \
+} \
+static struct device_attribute psmouse_attr_##_name = \
+ __ATTR(_name, S_IWUSR | S_IRUGO, \
+ psmouse_do_show_##_name, psmouse_do_set_##_name);

#endif /* _PSMOUSE_H */

2004-09-29 06:55:16

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 7/8] Separate PS2PP protocol handling


===================================================================


[email protected], 2004-09-29 01:06:41-05:00, [email protected]
Input: psmouse - make logips2pp fully decode its protocol packets
and not rely on generic handler to finish job.

Signed-off-by: Dmitry Torokhov <[email protected]>


logips2pp.c | 43 +++++++++++++++++++++++++++++++++----------
logips2pp.h | 1 -
psmouse-base.c | 7 -------
3 files changed, 33 insertions(+), 18 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
--- a/drivers/input/mouse/logips2pp.c 2004-09-29 01:23:24 -05:00
+++ b/drivers/input/mouse/logips2pp.c 2004-09-29 01:23:24 -05:00
@@ -38,13 +38,23 @@
* Process a PS2++ or PS2T++ packet.
*/

-void ps2pp_process_packet(struct psmouse *psmouse)
+static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
{
struct input_dev *dev = &psmouse->dev;
- unsigned char *packet = psmouse->packet;
+ unsigned char *packet = psmouse->packet;
+
+ if (psmouse->pktcnt < 3)
+ return PSMOUSE_GOOD_DATA;
+
+/*
+ * Full packet accumulated, process it
+ */
+
+ input_regs(dev, regs);

if ((packet[0] & 0x48) == 0x48 && (packet[1] & 0x02) == 0x02) {

+ /* Logitech extended packet */
switch ((packet[1] >> 4) | (packet[0] & 0x30)) {

case 0x0d: /* Mouse extra info */
@@ -79,11 +89,20 @@
(packet[1] >> 4) | (packet[0] & 0x30));
#endif
}
-
- packet[0] &= 0x0f;
- packet[1] = 0;
- packet[2] = 0;
+ } else {
+ /* Standard PS/2 motion data */
+ input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0);
+ input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0);
}
+
+ input_report_key(dev, BTN_LEFT, packet[0] & 1);
+ input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1);
+ input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);
+
+ input_sync(dev);
+
+ return PSMOUSE_FULL_PACKET;
+
}

/*
@@ -334,11 +353,15 @@
psmouse->vendor = "Logitech";
psmouse->model = model;

- if (use_ps2pp && model_info->kind != PS2PP_KIND_TP3) {
- psmouse->set_resolution = ps2pp_set_resolution;
- psmouse->disconnect = ps2pp_disconnect;
+ if (use_ps2pp) {
+ psmouse->protocol_handler = ps2pp_process_byte;
+
+ if (model_info->kind != PS2PP_KIND_TP3) {
+ psmouse->set_resolution = ps2pp_set_resolution;
+ psmouse->disconnect = ps2pp_disconnect;

- device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+ device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+ }
}

if (buttons < 3)
diff -Nru a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
--- a/drivers/input/mouse/logips2pp.h 2004-09-29 01:23:24 -05:00
+++ b/drivers/input/mouse/logips2pp.h 2004-09-29 01:23:24 -05:00
@@ -11,7 +11,6 @@
#ifndef _LOGIPS2PP_H
#define _LOGIPS2PP_H

-void ps2pp_process_packet(struct psmouse *psmouse);
int ps2pp_init(struct psmouse *psmouse, int set_properties);

#endif
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c 2004-09-29 01:23:24 -05:00
+++ b/drivers/input/mouse/psmouse-base.c 2004-09-29 01:23:24 -05:00
@@ -84,13 +84,6 @@
input_regs(dev, regs);

/*
- * The PS2++ protocol is a little bit complex
- */
-
- if (psmouse->type == PSMOUSE_PS2PP)
- ps2pp_process_packet(psmouse);
-
-/*
* Scroll wheel on IntelliMice, scroll buttons on NetMice
*/

2004-09-29 06:51:05

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 4/8] Psmouse probe fixes


===================================================================


[email protected], 2004-09-28 00:09:06-05:00, [email protected]
Input: psmouse - reset mouse before doing intellimouse/explorer
probes in case it got confused by earlier probes; switch
to streaming mode before setting scale and resolution,
otherwise some KVMs get confused.

Patch-by: Marko Macek <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>


psmouse-base.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c 2004-09-29 01:18:55 -05:00
+++ b/drivers/input/mouse/psmouse-base.c 2004-09-29 01:18:55 -05:00
@@ -444,6 +444,12 @@
return type;
}

+/*
+ * Reset to defaults in case the device got confused by extended
+ * protocol probes.
+ */
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
+
if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse)) {

if (set_properties) {
@@ -552,7 +558,11 @@

static void psmouse_initialize(struct psmouse *psmouse)
{
- unsigned char param[2];
+/*
+ * We set the mouse into streaming mode.
+ */
+
+ ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSTREAM);

/*
* We set the mouse report rate, resolution and scaling.
@@ -563,12 +573,6 @@
psmouse->set_resolution(psmouse, psmouse->resolution);
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
}
-
-/*
- * We set the mouse into streaming mode.
- */
-
- ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETSTREAM);
}

/*

2004-09-29 06:55:15

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size


===================================================================


[email protected], 2004-09-29 01:07:29-05:00, [email protected]
Input: psmouse - explicitely specify packet size instead of relying
on protocol numbering scheme. Make protocol detection routines
set mouse parameters by themselves instead of doing it in
psmouse_extensions.

Signed-off-by: Dmitry Torokhov <[email protected]>


alps.c | 12 +++-
alps.h | 2
logips2pp.c | 1
psmouse-base.c | 149 +++++++++++++++++++++++++++++----------------------------
psmouse.h | 1
synaptics.c | 14 ++++-
synaptics.h | 2
7 files changed, 101 insertions(+), 80 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
--- a/drivers/input/mouse/alps.c 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/alps.c 2004-09-29 01:25:12 -05:00
@@ -405,12 +405,20 @@
psmouse->protocol_handler = alps_process_byte;
psmouse->disconnect = alps_disconnect;
psmouse->reconnect = alps_reconnect;
+ psmouse->pktsize = 6;

return 0;
}

-int alps_detect(struct psmouse *psmouse)
+int alps_detect(struct psmouse *psmouse, int set_properties)
{
- return alps_get_model(psmouse) < 0 ? 0 : 1;
+ if (alps_get_model(psmouse) < 0)
+ return 0;
+
+ if (set_properties) {
+ psmouse->vendor = "ALPS";
+ psmouse->name = "TouchPad";
+ }
+ return 1;
}

diff -Nru a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
--- a/drivers/input/mouse/alps.h 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/alps.h 2004-09-29 01:25:12 -05:00
@@ -11,7 +11,7 @@
#ifndef _ALPS_H
#define _ALPS_H

-int alps_detect(struct psmouse *psmouse);
+int alps_detect(struct psmouse *psmouse, int set_properties);
int alps_init(struct psmouse *psmouse);

#endif
diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
--- a/drivers/input/mouse/logips2pp.c 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/logips2pp.c 2004-09-29 01:25:12 -05:00
@@ -355,6 +355,7 @@

if (use_ps2pp) {
psmouse->protocol_handler = ps2pp_process_byte;
+ psmouse->pktsize = 3;

if (model_info->kind != PS2PP_KIND_TP3) {
psmouse->set_resolution = ps2pp_set_resolution;
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/psmouse-base.c 2004-09-29 01:25:12 -05:00
@@ -74,7 +74,7 @@
struct input_dev *dev = &psmouse->dev;
unsigned char *packet = psmouse->packet;

- if (psmouse->pktcnt < 3 + (psmouse->type >= PSMOUSE_GENPS))
+ if (psmouse->pktcnt < psmouse->pktsize)
return PSMOUSE_GOOD_DATA;

/*
@@ -274,7 +274,7 @@
/*
* Genius NetMouse magic init.
*/
-static int genius_detect(struct psmouse *psmouse)
+static int genius_detect(struct psmouse *psmouse, int set_properties)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[4];
@@ -286,13 +286,24 @@
ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);

- return param[0] == 0x00 && param[1] == 0x33 && param[2] == 0x55;
+ if (param[0] == 0x00 && param[1] == 0x33 && param[2] == 0x55) {
+ if (set_properties) {
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+ set_bit(BTN_SIDE, psmouse->dev.keybit);
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+
+ psmouse->vendor = "Genius";
+ psmouse->name = "Wheel Mouse";
+ psmouse->pktsize = 4;
+ }
+ }
+ return 0;
}

/*
* IntelliMouse magic init.
*/
-static int intellimouse_detect(struct psmouse *psmouse)
+static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[2];
@@ -305,18 +316,28 @@
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);

- return param[0] == 3;
+ if (param[0] == 3) {
+ if (set_properties) {
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+
+ if (!psmouse->vendor) psmouse->vendor = "Generic";
+ if (!psmouse->name) psmouse->name = "Wheel Mouse";
+ psmouse->pktsize = 4;
+ }
+ return 1;
+ }
+ return 0;
}

/*
* Try IntelliMouse/Explorer magic init.
*/
-static int im_explorer_detect(struct psmouse *psmouse)
+static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[2];

- intellimouse_detect(psmouse);
+ intellimouse_detect(psmouse, 0);

param[0] = 200;
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
@@ -326,13 +347,25 @@
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);

- return param[0] == 4;
+ if (param[0] == 4) {
+ if (set_properties) {
+ set_bit(REL_WHEEL, psmouse->dev.relbit);
+ set_bit(BTN_SIDE, psmouse->dev.keybit);
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+
+ if (!psmouse->vendor) psmouse->vendor = "Generic";
+ if (!psmouse->name) psmouse->name = "Explorer Mouse";
+ psmouse->pktsize = 4;
+ }
+ return 1;
+ }
+ return 0;
}

/*
* Kensington ThinkingMouse / ExpertMouse magic init.
*/
-static int thinking_detect(struct psmouse *psmouse)
+static int thinking_detect(struct psmouse *psmouse, int set_properties)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[2];
@@ -347,7 +380,27 @@
ps2_command(ps2dev, seq + i, PSMOUSE_CMD_SETRATE);
ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);

- return param[0] == 2;
+ if (param[0] == 2) {
+ if (set_properties) {
+ set_bit(BTN_EXTRA, psmouse->dev.keybit);
+
+ psmouse->vendor = "Kensington";
+ psmouse->name = "ThinkingMouse";
+ }
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Bare PS/2 protocol "detection". Always succeeds.
+ */
+static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
+{
+ if (!psmouse->vendor) psmouse->vendor = "Generic";
+ if (!psmouse->name) psmouse->name = "Mouse";
+
+ return 1;
}

/*
@@ -365,28 +418,15 @@
* upsets the thinkingmouse).
*/

- if (max_proto > PSMOUSE_PS2 && thinking_detect(psmouse)) {
-
- if (set_properties) {
- set_bit(BTN_EXTRA, psmouse->dev.keybit);
- psmouse->vendor = "Kensington";
- psmouse->name = "ThinkingMouse";
- }
-
+ if (max_proto > PSMOUSE_PS2 && thinking_detect(psmouse, set_properties))
return PSMOUSE_THINKPS;
- }

/*
* Try Synaptics TouchPad
*/
- if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse)) {
+ if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties)) {
synaptics_hardware = 1;

- if (set_properties) {
- psmouse->vendor = "Synaptics";
- psmouse->name = "TouchPad";
- }
-
if (max_proto > PSMOUSE_IMEX) {
if (!set_properties || synaptics_init(psmouse) == 0)
return PSMOUSE_SYNAPTICS;
@@ -406,13 +446,7 @@
/*
* Try ALPS TouchPad
*/
- if (max_proto > PSMOUSE_IMEX && alps_detect(psmouse)) {
-
- if (set_properties) {
- psmouse->vendor = "ALPS";
- psmouse->name = "TouchPad";
- }
-
+ if (max_proto > PSMOUSE_IMEX && alps_detect(psmouse, set_properties)) {
if (!set_properties || alps_init(psmouse) == 0)
return PSMOUSE_ALPS;

@@ -422,18 +456,8 @@
max_proto = PSMOUSE_IMEX;
}

- if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse)) {
-
- if (set_properties) {
- set_bit(BTN_EXTRA, psmouse->dev.keybit);
- set_bit(BTN_SIDE, psmouse->dev.keybit);
- set_bit(REL_WHEEL, psmouse->dev.relbit);
- psmouse->vendor = "Genius";
- psmouse->name = "Wheel Mouse";
- }
-
+ if (max_proto > PSMOUSE_IMEX && genius_detect(psmouse, set_properties))
return PSMOUSE_GENPS;
- }

if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties))
return PSMOUSE_PS2PP;
@@ -444,34 +468,18 @@
*/
ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);

- if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse)) {
-
- if (set_properties) {
- set_bit(REL_WHEEL, psmouse->dev.relbit);
- set_bit(BTN_SIDE, psmouse->dev.keybit);
- set_bit(BTN_EXTRA, psmouse->dev.keybit);
- if (!psmouse->name)
- psmouse->name = "Explorer Mouse";
- }
-
+ if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties))
return PSMOUSE_IMEX;
- }
-
- if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse)) {
-
- if (set_properties) {
- set_bit(REL_WHEEL, psmouse->dev.relbit);
- if (!psmouse->name)
- psmouse->name = "Wheel Mouse";
- }

+ if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties))
return PSMOUSE_IMPS;
- }

/*
* Okay, all failed, we have a standard mouse here. The number of the buttons
* is still a question, though. We assume 3.
*/
+ ps2bare_detect(psmouse, set_properties);
+
if (synaptics_hardware) {
/*
* We detected Synaptics hardware but it did not respond to IMPS/2 probes.
@@ -706,17 +714,12 @@
psmouse->resolution = psmouse_resolution;
psmouse->resetafter = psmouse_resetafter;
psmouse->smartscroll = psmouse_smartscroll;
+ psmouse->set_rate = psmouse_set_rate;
+ psmouse->set_resolution = psmouse_set_resolution;
+ psmouse->protocol_handler = psmouse_process_byte;
+ psmouse->pktsize = 3;
+
psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
- if (!psmouse->vendor)
- psmouse->vendor = "Generic";
- if (!psmouse->name)
- psmouse->name = "Mouse";
- if (!psmouse->protocol_handler)
- psmouse->protocol_handler = psmouse_process_byte;
- if (!psmouse->set_rate)
- psmouse->set_rate = psmouse_set_rate;
- if (!psmouse->set_resolution)
- psmouse->set_resolution = psmouse_set_resolution;

sprintf(psmouse->devname, "%s %s %s",
psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
--- a/drivers/input/mouse/psmouse.h 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/psmouse.h 2004-09-29 01:25:12 -05:00
@@ -42,6 +42,7 @@
char *name;
unsigned char packet[8];
unsigned char pktcnt;
+ unsigned char pktsize;
unsigned char type;
unsigned char model;
unsigned long last;
diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
--- a/drivers/input/mouse/synaptics.c 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/synaptics.c 2004-09-29 01:25:12 -05:00
@@ -558,7 +558,7 @@
struct synaptics_data *priv = psmouse->private;
struct synaptics_data old_priv = *priv;

- if (!synaptics_detect(psmouse))
+ if (!synaptics_detect(psmouse, 0))
return -1;

if (synaptics_query_hardware(psmouse)) {
@@ -580,7 +580,7 @@
return 0;
}

-int synaptics_detect(struct psmouse *psmouse)
+int synaptics_detect(struct psmouse *psmouse, int set_properties)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[4];
@@ -593,7 +593,14 @@
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);

- return param[1] == 0x47;
+ if (param[1] == 0x47) {
+ if (set_properties) {
+ psmouse->vendor = "Synaptics";
+ psmouse->name = "TouchPad";
+ }
+ return 1;
+ }
+ return 0;
}

int synaptics_init(struct psmouse *psmouse)
@@ -627,6 +634,7 @@
psmouse->set_rate = synaptics_set_rate;
psmouse->disconnect = synaptics_disconnect;
psmouse->reconnect = synaptics_reconnect;
+ psmouse->pktsize = 6;

return 0;

diff -Nru a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
--- a/drivers/input/mouse/synaptics.h 2004-09-29 01:25:12 -05:00
+++ b/drivers/input/mouse/synaptics.h 2004-09-29 01:25:12 -05:00
@@ -9,7 +9,7 @@
#ifndef _SYNAPTICS_H
#define _SYNAPTICS_H

-extern int synaptics_detect(struct psmouse *psmouse);
+extern int synaptics_detect(struct psmouse *psmouse, int set_properties);
extern int synaptics_init(struct psmouse *psmouse);
extern void synaptics_reset(struct psmouse *psmouse);

2004-09-29 06:59:57

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 6/8] Drop PS2TPP protocol identifier


===================================================================


[email protected], 2004-09-29 01:05:22-05:00, [email protected]
Input: psmouse - drop PS2TPP protocol (it is handled exactly like
PS2PP) to free spot for THINKPS protocol and keep old protocol
numbers for binary compatibility with Synaptics/ALPS touchpad
driver for X.

Signed-off-by: Dmitry Torokhov <[email protected]>


logips2pp.c | 52 ++++++++++++++++++++++++++++------------------------
psmouse-base.c | 11 ++++-------
psmouse.h | 1 -
3 files changed, 32 insertions(+), 32 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
--- a/drivers/input/mouse/logips2pp.c 2004-09-29 01:22:10 -05:00
+++ b/drivers/input/mouse/logips2pp.c 2004-09-29 01:22:10 -05:00
@@ -274,9 +274,9 @@
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[4];
- unsigned char protocol = PSMOUSE_PS2;
unsigned char model, buttons;
struct ps2pp_info *model_info;
+ int use_ps2pp = 0;

param[0] = 0;
ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
@@ -286,10 +286,13 @@
param[1] = 0;
ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);

- if (param[1] != 0) {
- model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78);
- buttons = param[1];
- model_info = get_model_info(model);
+ if (!param[1])
+ return 0;
+
+ model = ((param[0] >> 4) & 0x07) | ((param[0] << 3) & 0x78);
+ buttons = param[1];
+
+ if ((model_info = get_model_info(model)) != NULL) {

/*
* Do Logitech PS2++ / PS2T++ magic init.
@@ -309,10 +312,10 @@
param[0] = 0;
if (!ps2_command(ps2dev, param, 0x13d1) &&
param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) {
- protocol = PSMOUSE_PS2TPP;
+ use_ps2pp = 1;
}

- } else if (model_info != NULL) {
+ } else {

param[0] = param[1] = param[2] = 0;
ps2pp_cmd(psmouse, param, 0x39); /* Magic knock */
@@ -322,30 +325,31 @@
(param[1] & 0xf3) == 0xc2 &&
(param[2] & 0x03) == ((param[1] >> 2) & 3)) {
ps2pp_set_smartscroll(psmouse, psmouse->smartscroll);
- protocol = PSMOUSE_PS2PP;
+ use_ps2pp = 1;
}
}
+ }

- if (set_properties) {
- psmouse->vendor = "Logitech";
- psmouse->model = model;
- if (protocol == PSMOUSE_PS2PP) {
- psmouse->set_resolution = ps2pp_set_resolution;
- psmouse->disconnect = ps2pp_disconnect;
+ if (set_properties) {
+ psmouse->vendor = "Logitech";
+ psmouse->model = model;
+
+ if (use_ps2pp && model_info->kind != PS2PP_KIND_TP3) {
+ psmouse->set_resolution = ps2pp_set_resolution;
+ psmouse->disconnect = ps2pp_disconnect;

- device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
- }
+ device_create_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll);
+ }

- if (buttons < 3)
- clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
- if (buttons < 2)
- clear_bit(BTN_RIGHT, psmouse->dev.keybit);
+ if (buttons < 3)
+ clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
+ if (buttons < 2)
+ clear_bit(BTN_RIGHT, psmouse->dev.keybit);

- if (model_info)
- ps2pp_set_model_properties(psmouse, model_info);
- }
+ if (model_info)
+ ps2pp_set_model_properties(psmouse, model_info);
}

- return protocol;
+ return use_ps2pp;
}

diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c 2004-09-29 01:22:10 -05:00
+++ b/drivers/input/mouse/psmouse-base.c 2004-09-29 01:22:10 -05:00
@@ -62,7 +62,7 @@
__obsolete_setup("psmouse_resetafter=");
__obsolete_setup("psmouse_rate=");

-static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "PS2T++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2" };
+static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2" };

/*
* psmouse_process_byte() analyzes the PS/2 data stream and reports
@@ -87,7 +87,7 @@
* The PS2++ protocol is a little bit complex
*/

- if (psmouse->type == PSMOUSE_PS2PP || psmouse->type == PSMOUSE_PS2TPP)
+ if (psmouse->type == PSMOUSE_PS2PP)
ps2pp_process_packet(psmouse);

/*
@@ -442,11 +442,8 @@
return PSMOUSE_GENPS;
}

- if (max_proto > PSMOUSE_IMEX) {
- int type = ps2pp_init(psmouse, set_properties);
- if (type > PSMOUSE_PS2)
- return type;
- }
+ if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties))
+ return PSMOUSE_PS2PP;

/*
* Reset to defaults in case the device got confused by extended
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
--- a/drivers/input/mouse/psmouse.h 2004-09-29 01:22:10 -05:00
+++ b/drivers/input/mouse/psmouse.h 2004-09-29 01:22:10 -05:00
@@ -70,7 +70,6 @@
PSMOUSE_NONE,
PSMOUSE_PS2,
PSMOUSE_PS2PP,
- PSMOUSE_PS2TPP,
PSMOUSE_THINKPS,
PSMOUSE_GENPS,
PSMOUSE_IMPS,

2004-09-29 06:51:04

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH 3/8] Guest protocol switch in synaptics


===================================================================


[email protected], 2004-09-28 00:07:41-05:00, [email protected]
Input: synaptics - not only switch to 4-byte client protocol
but also revert to 3-byte mode if client selected lower
protocol.

Signed-off-by: Dmitry Torokhov <[email protected]>


synaptics.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
--- a/drivers/input/mouse/synaptics.c 2004-09-29 01:16:30 -05:00
+++ b/drivers/input/mouse/synaptics.c 2004-09-29 01:16:30 -05:00
@@ -264,10 +264,14 @@
struct synaptics_data *priv = psmouse->private;

/* adjust the touchpad to child's choice of protocol */
- if (child && child->type >= PSMOUSE_GENPS) {
- priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
+ if (child) {
+ if (child->type >= PSMOUSE_GENPS)
+ priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
+ else
+ priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
+
if (synaptics_mode_cmd(psmouse, priv->mode))
- printk(KERN_INFO "synaptics: failed to enable 4-byte guest protocol\n");
+ printk(KERN_INFO "synaptics: failed to switch guest protocol\n");
}
}

2004-09-29 07:10:57

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH 0/8] Set of input (psmouse) patches

On Wed, Sep 29, 2004 at 01:40:53AM -0500, Dmitry Torokhov wrote:
> Hi Vojtech,
>
> Here is new bunch of small psmouse patches. Nothing particularly interesting
> except probably exporting rate, resolution, resetafter and smartscroll
> parameters as sysfs attributes. Protocol exporting and switching is still
> in progress though...
>
> 01-alps-signature.patch
> - add a new signature to ALPS response table (Inspiron 8500)
>
> 02-rate-resolution-handlers.patch
> - add set_rate and set_resolution handlers to psmouse structure
> to reduce dependencies between protocols, helps wihen exporting
> resolutin and rate via sysfs
>
> 03-synaptics-guest-protocol-switch.patch
> - not only set 4 byte guest protocol but also reset it back to 3
> if for some odd reason user reconnects guest requesting lower
> protocol.
>
> 04-psmouse-probe-fix.patch
> - patch from Marko Macek dealing with probing and his KVM (the thing
> doctors stream and gets confused by the extended probes)
>
> 05-psmouse-sysfs-attr.patch
> - export rate, resolution, resetafter and smartscroll as sysfs
> attributes.
>
> 06-psmouse-drop-ps2tpp.patch
> - get rid of PS2T++ protocol symbol as it it handled exactly the same
> as PS2++. This leaves space for THINKPS protocol and allows keeping
> old Synaptics and Alps protocol numbers that Synaptics X driver
> relied on.
>
> 07-separate-ps2pp-handling.patch
> - complete separation of PS2++ protocol deconding by moving everything
> into logips2pp.c - cleanup.
>
> 08-psmouse-packet-size.patch
> - add pktsize to psmouse structure and check it instead on relying on
> protcol numbering. Also rearrange detect routines in preparation to
> dynamic protocol switching via sysfs.
>
> Please let me know what you think and I will push it on bkbits.

All look OK, except for the last one. I'll comment in the patch itself.

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2004-09-29 07:14:37

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Wed, Sep 29, 2004 at 01:47:34AM -0500, Dmitry Torokhov wrote:

> -int alps_detect(struct psmouse *psmouse)
> +int alps_detect(struct psmouse *psmouse, int set_properties)
> {
> - return alps_get_model(psmouse) < 0 ? 0 : 1;
> + if (alps_get_model(psmouse) < 0)
> + return 0;
> +
> + if (set_properties) {
> + psmouse->vendor = "ALPS";
> + psmouse->name = "TouchPad";
> + }
> + return 1;
> }

I think we should return -1 (or -errno) on failure and 0 on success,
like everybody else does.

> - return param[0] == 3;
> + if (param[0] == 3) {
> + if (set_properties) {
> + set_bit(REL_WHEEL, psmouse->dev.relbit);
> +
> + if (!psmouse->vendor) psmouse->vendor = "Generic";
> + if (!psmouse->name) psmouse->name = "Wheel Mouse";
> + psmouse->pktsize = 4;
> + }
> + return 1;
> + }
> + return 0;
> }

This should be:

if (param[0] != 3)
return -1;
if (set_properties) {
set_bit(REL_WHEEL, psmouse->dev.relbit);
if (!psmouse->vendor) psmouse->vendor = "Generic";
if (!psmouse->name) psmouse->name = "Wheel Mouse";
psmouse->pktsize = 4;
}
return 0;

... and similarly elsewhere. You save one level of nesting and it makes
more sense.

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2004-09-29 07:29:37

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Wednesday 29 September 2004 02:15 am, Vojtech Pavlik wrote:
> On Wed, Sep 29, 2004 at 01:47:34AM -0500, Dmitry Torokhov wrote:
>
> > -int alps_detect(struct psmouse *psmouse)
> > +int alps_detect(struct psmouse *psmouse, int set_properties)
> > {
> > - return alps_get_model(psmouse) < 0 ? 0 : 1;
> > + if (alps_get_model(psmouse) < 0)
> > + return 0;
> > +
> > + if (set_properties) {
> > + psmouse->vendor = "ALPS";
> > + psmouse->name = "TouchPad";
> > + }
> > + return 1;
> > }
>
> I think we should return -1 (or -errno) on failure and 0 on success,
> like everybody else does.
>

All *detect functions return boolean value - either the device was detected or
not. I think it makes most sense. Negative error is convenient when function
normally returns some other meaningful value, like length. *detect is a simple
yes/no question, it is not really an error at all.

>
> This should be:
>
> if (param[0] != 3)
> return -1;
> if (set_properties) {
> set_bit(REL_WHEEL, psmouse->dev.relbit);
> if (!psmouse->vendor) psmouse->vendor = "Generic";
> if (!psmouse->name) psmouse->name = "Wheel Mouse";
> psmouse->pktsize = 4;
> }
> return 0;
>
> ... and similarly elsewhere. You save one level of nesting and it makes
> more sense.
>

Ok, will change.

--
Dmitry

2004-09-29 09:30:49

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Wed, Sep 29, 2004 at 02:29:28AM -0500, Dmitry Torokhov wrote:
> On Wednesday 29 September 2004 02:15 am, Vojtech Pavlik wrote:
> > On Wed, Sep 29, 2004 at 01:47:34AM -0500, Dmitry Torokhov wrote:
> >
> > > -int alps_detect(struct psmouse *psmouse)
> > > +int alps_detect(struct psmouse *psmouse, int set_properties)
> > > {
> > > - return alps_get_model(psmouse) < 0 ? 0 : 1;
> > > + if (alps_get_model(psmouse) < 0)
> > > + return 0;
> > > +
> > > + if (set_properties) {
> > > + psmouse->vendor = "ALPS";
> > > + psmouse->name = "TouchPad";
> > > + }
> > > + return 1;
> > > }
> >
> > I think we should return -1 (or -errno) on failure and 0 on success,
> > like everybody else does.
> >
>
> All *detect functions return boolean value - either the device was detected or
> not. I think it makes most sense. Negative error is convenient when function
> normally returns some other meaningful value, like length. *detect is a simple
> yes/no question, it is not really an error at all.

psmouse_probe() is very similar in its use, as are a lot of other
functions in the serio framework - and they return 0 on success, and -1
on failure.

I see it as "detected/initialized" = success (0) and "not detected / failed
to initialize" = fail (-1).

I agree that your view also makes sense, however I'd like to keep the
driver return values consistent to make it easier to read.

Maybe renaming the *_detect functions to *_probe would make it more
obvious.

> > This should be:
> >
> > if (param[0] != 3)
> > return -1;
> > if (set_properties) {
> > set_bit(REL_WHEEL, psmouse->dev.relbit);
> > if (!psmouse->vendor) psmouse->vendor = "Generic";
> > if (!psmouse->name) psmouse->name = "Wheel Mouse";
> > psmouse->pktsize = 4;
> > }
> > return 0;
> >
> > ... and similarly elsewhere. You save one level of nesting and it makes
> > more sense.
> >
>
> Ok, will change.
>
> --
> Dmitry
>

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2004-09-29 13:26:40

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Wednesday 29 September 2004 04:31 am, Vojtech Pavlik wrote:
> On Wed, Sep 29, 2004 at 02:29:28AM -0500, Dmitry Torokhov wrote:
> > On Wednesday 29 September 2004 02:15 am, Vojtech Pavlik wrote:
> > > On Wed, Sep 29, 2004 at 01:47:34AM -0500, Dmitry Torokhov wrote:
> > >
> > > > -int alps_detect(struct psmouse *psmouse)
> > > > +int alps_detect(struct psmouse *psmouse, int set_properties)
> > > > {
> > > > - return alps_get_model(psmouse) < 0 ? 0 : 1;
> > > > + if (alps_get_model(psmouse) < 0)
> > > > + return 0;
> > > > +
> > > > + if (set_properties) {
> > > > + psmouse->vendor = "ALPS";
> > > > + psmouse->name = "TouchPad";
> > > > + }
> > > > + return 1;
> > > > }
> > >
> > > I think we should return -1 (or -errno) on failure and 0 on success,
> > > like everybody else does.
> > >
> >
> > All *detect functions return boolean value - either the device was detected or
> > not. I think it makes most sense. Negative error is convenient when function
> > normally returns some other meaningful value, like length. *detect is a simple
> > yes/no question, it is not really an error at all.
>
> psmouse_probe() is very similar in its use, as are a lot of other
> functions in the serio framework - and they return 0 on success, and -1
> on failure.
>
> I see it as "detected/initialized" = success (0) and "not detected / failed
> to initialize" = fail (-1).
>
> I agree that your view also makes sense, however I'd like to keep the
> driver return values consistent to make it easier to read.
>

I have been battling with myself about whether to keep them consistent
with probe/init or make them as they are today... My issue with
*detect returning -1 on failure is that the caller's code will look
like:

if (max_proto >= PSMOUSE_IMPS && !intellimouse_detect(psmouse, set_properties))
return PSMOUSE_IMPS;

or

if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0)
return PSMOUSE_IMPS;

which does not flow for me when I read the code. With pretty much every
other function caller checks for negative and exits in case of error, it
reads naturally as well. Here with multiple btanches I go "... and
intellimouse is NOT detected... oh, wait, it IS detected..."

Oh, well. I guess I will convert them... unless I managed to presuade you
to keep them as is ;).

--
Dmitry

2004-09-29 13:39:28

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Wed, Sep 29, 2004 at 08:24:58AM -0500, Dmitry Torokhov wrote:

> I have been battling with myself about whether to keep them consistent
> with probe/init or make them as they are today... My issue with
> *detect returning -1 on failure is that the caller's code will look
> like:
>
> if (max_proto >= PSMOUSE_IMPS && !intellimouse_detect(psmouse, set_properties))
> return PSMOUSE_IMPS;
>
> or
>
> if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0)
> return PSMOUSE_IMPS;
>
> which does not flow for me when I read the code. With pretty much every
> other function caller checks for negative and exits in case of error, it
> reads naturally as well. Here with multiple btanches I go "... and
> intellimouse is NOT detected... oh, wait, it IS detected..."

Well, yeah. I kinda got used to that reversed logic after a while.

> Oh, well. I guess I will convert them... unless I managed to presuade you
> to keep them as is ;).

Well, I understand your point, but I still think it's worth keeping the
return values consistent with the rest of the probe routines, because if
not, THEN you (or some other reader) would get used to the
positive-style returns with the protocol detection routines and
definitely understand it wrong elsewhere.

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2004-09-30 06:43:28

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Wednesday 29 September 2004 08:38 am, Vojtech Pavlik wrote:
> Well, I understand your point, but I still think it's worth keeping the
> return values consistent with the rest of the probe routines, because if
> not, THEN you (or some other reader) would get used to the
> positive-style returns with the protocol detection routines and
> definitely understand it wrong elsewhere.
>

Vojtech,

I converted the -detect routines to return -1 on failure and implemented the
other change you have requested. Please do:

bk pull bk://dtor.bkbits.net/input

Thanks!

--
Dmitry

2004-09-30 07:55:12

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Thu, Sep 30, 2004 at 01:43:23AM -0500, Dmitry Torokhov wrote:

> On Wednesday 29 September 2004 08:38 am, Vojtech Pavlik wrote:
> > Well, I understand your point, but I still think it's worth keeping the
> > return values consistent with the rest of the probe routines, because if
> > not, THEN you (or some other reader) would get used to the
> > positive-style returns with the protocol detection routines and
> > definitely understand it wrong elsewhere.
> >
>
> Vojtech,
>
> I converted the -detect routines to return -1 on failure and implemented the
> other change you have requested. Please do:
>
> bk pull bk://dtor.bkbits.net/input

Done, thanks!

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2004-09-30 10:34:45

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: [PATCH 7/8] Psmouse - add packet size

On Thu, 2004-09-30 01:43:23 -0500, Dmitry Torokhov <[email protected]>
wrote in message <[email protected]>:
> On Wednesday 29 September 2004 08:38 am, Vojtech Pavlik wrote:
> I converted the -detect routines to return -1 on failure and implemented the
> other change you have requested. Please do:
>
> bk pull bk://dtor.bkbits.net/input

Inline patches?

MfG, JBG

--
Jan-Benedict Glaw [email protected] . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier B?rger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));


Attachments:
(No filename) (722.00 B)
signature.asc (189.00 B)
Digital signature
Download all attachments