Skip to contentSkip to conversation

Set of input (psmouse) patches

PATCH In review Dmitry Torokhov 3 participants 18 messages Sep 29, 2004 – Sep 30, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover 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!

Signature · 1 line
Dmitry
#1 lore raw

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

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

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

drivers/input/mouse/alps.c +1 -0
diff -Nru a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
@@ -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 },
 };
 
 /*
#5 lore raw

PATCH 5/8 Export psmouse parameters via sysfs

In reply to Dmitry Torokhov

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

[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(-)

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

drivers/input/mouse/logips2pp.c +39 -9
diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
@@ -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);
drivers/input/mouse/psmouse-base.c +125 -2

169 lines not on this page · raw message

drivers/input/mouse/psmouse.h +21 -1
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
@@ -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 */
#2 lore raw

PATCH 2/8 Psmouse rate and resolution handlers

In reply to Dmitry Torokhov

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

[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

 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(-)

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

drivers/input/mouse/logips2pp.c +14 -8
diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
@@ -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);
drivers/input/mouse/logips2pp.h +0 -1
diff -Nru a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
@@ -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
drivers/input/mouse/psmouse-base.c +20 -23

89 lines not on this page · raw message

drivers/input/mouse/psmouse.h +7 -1
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
@@ -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 */
drivers/input/mouse/synaptics.c +27 -10
diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
@@ -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;
 
drivers/input/mouse/synaptics.h +1 -0
diff -Nru a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
@@ -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 */
#3 lore raw

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.

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

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

drivers/input/mouse/synaptics.c +7 -3
diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
@@ -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");
 	}
 }
 
#4 lore raw

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.

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

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

drivers/input/mouse/psmouse-base.c +11 -7
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
@@ -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);
 }
 
 /*
#8 lore raw

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

In reply to Dmitry Torokhov

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

[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.

 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(-)

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

drivers/input/mouse/alps.c +10 -2
diff -Nru a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
@@ -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;
 }
 
drivers/input/mouse/alps.h +1 -1
diff -Nru a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
@@ -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
drivers/input/mouse/logips2pp.c +1 -0
diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
@@ -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;
drivers/input/mouse/psmouse-base.c +76 -73

251 lines not on this page · raw message

drivers/input/mouse/psmouse.h +1 -0
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
@@ -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;
drivers/input/mouse/synaptics.c +11 -3
diff -Nru a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
@@ -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;
 
drivers/input/mouse/synaptics.h +1 -1
diff -Nru a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
@@ -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);
 
#7 lore raw

PATCH 7/8 Separate PS2PP protocol handling

In reply to Dmitry Torokhov

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

[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.

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

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

drivers/input/mouse/logips2pp.c +33 -10
diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
@@ -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)
drivers/input/mouse/logips2pp.h +0 -1
diff -Nru a/drivers/input/mouse/logips2pp.h b/drivers/input/mouse/logips2pp.h
@@ -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
drivers/input/mouse/psmouse-base.c +0 -7
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
@@ -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
  */
 
#6 lore raw

PATCH 6/8 Drop PS2TPP protocol identifier

In reply to Dmitry Torokhov

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

[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.

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

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

drivers/input/mouse/logips2pp.c +28 -24
diff -Nru a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
@@ -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;
 }
 
drivers/input/mouse/psmouse-base.c +4 -7
diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
@@ -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
drivers/input/mouse/psmouse.h +0 -1
diff -Nru a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
@@ -70,7 +70,6 @@
 	PSMOUSE_NONE,
 	PSMOUSE_PS2,
 	PSMOUSE_PS2PP,
-	PSMOUSE_PS2TPP,
 	PSMOUSE_THINKPS,
 	PSMOUSE_GENPS,
 	PSMOUSE_IMPS,
#17 lore raw
In reply to Dmitry Torokhov
Quoted 38 lines · Dmitry Torokhov

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.

Quoted 6 lines

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.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#9 lore raw

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

In reply to Dmitry Torokhov

drivers/input/mouse/alps.c line 423

Quoted 13 lines · Dmitry Torokhov
drivers/input/mouse/alps.c +9 -2
-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.

drivers/input/mouse/psmouse-base.c line 330

Quoted 13 lines
drivers/input/mouse/psmouse-base.c +11 -1
-	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.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#10 lore raw

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

Quoted 19 lines · Vojtech Pavlik

drivers/input/mouse/alps.c line 423

Quoted 13 lines · Dmitry Torokhov
drivers/input/mouse/alps.c +9 -2
-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.

Quoted 13 lines

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;
Quoted 3 lines

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

Ok, will change.

Signature · 1 line
Dmitry
#11 lore raw

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

Quoted 21 lines · Dmitry Torokhov
Quoted 19 lines · Vojtech Pavlik

drivers/input/mouse/alps.c line 423

Quoted 13 lines · Dmitry Torokhov
drivers/input/mouse/alps.c +9 -2
-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.

Quoted 4 lines

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.

Quoted 21 lines
Quoted 12 lines

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;
Quoted 3 lines

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

Ok, will change.

Signature · 1 line
Dmitry
Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#12 lore raw

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

Quoted 31 lines · Vojtech Pavlik
Quoted 21 lines · Dmitry Torokhov
Quoted 19 lines · Vojtech Pavlik

drivers/input/mouse/alps.c line 423

Quoted 13 lines · Dmitry Torokhov
drivers/input/mouse/alps.c +9 -2
-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.

Quoted 4 lines

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.

Quoted 6 lines

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 ;).

Signature · 1 line
Dmitry
#13 lore raw

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

Quoted 10 lines · Dmitry Torokhov

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

Quoted 7 lines
        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.

Quoted 2 lines

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.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#14 lore raw

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

Quoted 6 lines · Vojtech Pavlik

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!

Signature · 1 line
Dmitry
#15 lore raw

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

Quoted 8 lines · Dmitry Torokhov
Quoted 6 lines · Vojtech Pavlik

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.

Quoted 6 lines

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!

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#16 lore raw

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

In reply to Dmitry Torokhov

On Thu, 2004-09-30 01:43:23 -0500, Dmitry Torokhov <[email protected]> wrote in message <[email protected]>:

Quoted 5 lines · Vojtech Pavlik

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

Signature · 4 lines
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));