All of lore.kernel.org
 help / color / mirror / Atom feed
* Sun mouse using 5-byte MSC protocol
@ 2005-09-03 21:10 Christopher Zimmermann
  0 siblings, 0 replies; 3+ messages in thread
From: Christopher Zimmermann @ 2005-09-03 21:10 UTC (permalink / raw)
  To: sparclinux

Hi, 

I use a Sun mouse which sends 5-byte MSC packets instead of the normal
3-byte ones. The current sermouse driver just drops the last two bytes
making the cursor move slow. I changed the driver to switch to the
5-byte protocol after dropping too many bytes.
Maybe someone knows a better method of probing for such mice. Please let
me know.
Unfortunately I don't have any "real" sun mouse sending 3-byte packets;
therefore I could not test if my modifications breaks support for those
sun mice.

Christopher

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Sun mouse using 5-byte MSC protocol
@ 2005-11-13 19:31 Christopher Zimmermann
  0 siblings, 0 replies; 3+ messages in thread
From: Christopher Zimmermann @ 2005-11-13 19:31 UTC (permalink / raw)
  To: sparclinux

Hi,

I asked this question already two months ago.
Maybe now someone has an idea.

I use a Sun mouse which sends 5-byte MSC packets instead of the normal
3-byte ones. The current sermouse driver just drops the last two bytes
making the cursor move slow. I changed the driver to switch to the
5-byte protocol after dropping too many bytes.
Maybe someone knows a better method of probing for such mice. Please let
me know.
Unfortunately I don't have any "real" sun mouse sending 3-byte packets;
therefore I could not test if my modifications breaks support for those
sun mice.

Christopher

--- linux-2.6.15-rc1.orig/drivers/input/mouse/sermouse.c	2005-11-13 19:51:38.000000000 +0100
+++ linux-2.6.15-rc1/drivers/input/mouse/sermouse.c	2005-11-13 20:07:37.000000000 +0100
@@ -60,6 +60,16 @@
  * sermouse_process_msc() analyzes the incoming MSC/Sun bytestream and
  * applies some prediction to the data, resulting in 96 updates per
  * second, which is as good as a PS/2 or USB mouse.
+ * The first byte of the MSC protocol contains the button state of the
+ * mouse and has a certain format. If we expect the mouse button state
+ * byte, but receive one which doesn't look like one, we drop it.
+ * There are two variations of the MSC protocol for Sun mice. Some use
+ * a 3-byte protocol (SERIO_SUN), others use a 5-byte protocol (SERIO_MSC).
+ * First we try the 3-byte protocol. If the mouse uses a 5-byte one,
+ * the last two bytes will be dropped as bad bytes resulting in a slower
+ * mouse motion.
+ * If we receive more bad button state bytes than good ones, we will
+ * switch to the 5-byte protocol.
  */
 
 static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
@@ -67,12 +77,32 @@
 	struct input_dev *dev = sermouse->dev;
 	signed char *buf = sermouse->buf;
 
+	static unsigned char bad_byte;
+
 	input_regs(dev, regs);
 
 	switch (sermouse->count) {
 
 		case 0:
-			if ((data & 0xf8) != 0x80) return;
+			/* Check if the data looks like button state data */
+			if ((data & 0xf8) != 0x80) {
+				/* If we are currently using the 3-byte protocol
+				 * increment the bad_byte counter. If we received
+				 * more bad bytes than good ones, switch to the
+				 * 5-byte prococol. The user will notice this as
+				 * speedup of the mouse cursor :-) */
+				if(sermouse->type = SERIO_SUN && ++bad_byte > 20) {
+					sermouse->type = SERIO_MSC;
+					bad_byte = 0; /* I don't know, why I do this. */
+					printk(KERN_INFO
+						"sermouse.c: Switched to the 5-byte MSC mouse protocol.\n");
+				}
+				return;
+			}
+			/* Decrement the bad_byte counter so that a 3-byte Sun mouse
+			 * can make up for a bad button state byte it sent. */
+			if(sermouse->type = SERIO_SUN && bad_byte > 0) bad_byte--;
+			
 			input_report_key(dev, BTN_LEFT,   !(data & 4));
 			input_report_key(dev, BTN_RIGHT,  !(data & 1));
 			input_report_key(dev, BTN_MIDDLE, !(data & 2));

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Sun mouse using 5-byte MSC protocol
@ 2005-12-28 20:43 David S. Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David S. Miller @ 2005-12-28 20:43 UTC (permalink / raw)
  To: sparclinux

From: Christopher Zimmermann <madroach@zakweb.de>
Date: Sun, 13 Nov 2005 20:31:44 +0100

> Unfortunately I don't have any "real" sun mouse sending 3-byte packets;
> therefore I could not test if my modifications breaks support for those
> sun mice.

I've made a slight modification to your patch, using a per-mouse
bad_bytes count.  If I have 2 mice, I don't one MSC one causing
the other to switch to MSC too :-)

I'll try to see if this breaks normal 3-byte protocol speaking
mice.

diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index 4bf5843..7bfc2f3 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -52,6 +52,7 @@ struct sermouse {
 	signed char buf[8];
 	unsigned char count;
 	unsigned char type;
+	unsigned char bad_bytes;
 	unsigned long last;
 	char phys[32];
 };
@@ -72,7 +73,21 @@ static void sermouse_process_msc(struct 
 	switch (sermouse->count) {
 
 		case 0:
-			if ((data & 0xf8) != 0x80) return;
+			if ((data & 0xf8) != 0x80) {
+				if (sermouse->type = SERIO_SUN &&
+				    ++sermouse->bad_bytes > 20) {
+					sermouse->type = SERIO_MSC;
+					sermouse->bad_bytes = 0;
+					printk(KERN_INFO "sermouse.c: "
+					       "Switched to the 5-byte "
+					       "MSC mouse protocol.\n");
+				}
+				return;
+			}
+			if (sermouse->type = SERIO_SUN &&
+			    sermouse->bad_bytes > 0)
+				sermouse->bad_bytes--;
+
 			input_report_key(dev, BTN_LEFT,   !(data & 4));
 			input_report_key(dev, BTN_RIGHT,  !(data & 1));
 			input_report_key(dev, BTN_MIDDLE, !(data & 2));

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-28 20:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-13 19:31 Sun mouse using 5-byte MSC protocol Christopher Zimmermann
  -- strict thread matches above, loose matches on Subject: below --
2005-12-28 20:43 David S. Miller
2005-09-03 21:10 Christopher Zimmermann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.