Change in PSM sync behavior

From: Justin T. Gibbs <gibbs_at_scsiguy.com>
Date: Fri, 13 Aug 2004 16:59:55 -0600
I've had this change locally for some time and think it may be
a worth while change to commit to the tree.  My patch defers the
setup of the sync bits until the first "normal" data packet is
received from the mouse.  In the case of Avocent Outlook KVM's,
this avoids a bug in their intellimouse emulator that sends back
incorrect sync when you explicitly request a data packet from the
mouse.  Without this change, you must force the driver into stock
PS/2 mode or be flooded with a never ending stream of "out of sync"
messages.

--
Justin

Index: psm.c
===================================================================
RCS file: /usr/cvs/src/sys/isa/psm.c,v
retrieving revision 1.76
diff -d -u -r1.76 psm.c
--- psm.c	8 Aug 2004 01:26:00 -0000	1.76
+++ psm.c	13 Aug 2004 16:54:27 -0000
_at__at_ -200,6 +200,7 _at__at_
 #define PSM_OPEN		1	/* Device is open */
 #define PSM_ASLP		2	/* Waiting for mouse data */
 #define PSM_SOFTARMED		4	/* Software interrupt armed */
+#define PSM_NEED_SYNCBITS	8	/* Set syncbits using next data pkt */
 
 /* driver configuration flags (config) */
 #define PSM_CONFIG_RESOLUTION	0x000f	/* resolution */
_at__at_ -739,16 +740,8 _at__at_
         set_mouse_mode(kbdc);	
     }
 
-    /* request a data packet and extract sync. bits */
-    if (get_mouse_status(kbdc, stat, 1, 3) < 3) {
-        log(LOG_DEBUG, "psm%d: failed to get data (doinitialize).\n",
-	    sc->unit);
-        sc->mode.syncmask[0] = 0;
-    } else {
-        sc->mode.syncmask[1] = stat[0] & sc->mode.syncmask[0];	/* syncbits */
-	/* the NetScroll Mouse will send three more bytes... Ignore them */
-	empty_aux_buffer(kbdc, 5);
-    }
+    /* Record sync on the next data packet we see. */
+    sc->flags |= PSM_NEED_SYNCBITS;
 
     /* just check the status of the mouse */
     if (get_mouse_status(kbdc, stat, 0, 3) < 3)
_at__at_ -890,7 +883,8 _at__at_
                 (c & KBD_KBD_CONTROL_BITS)
                     | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
             /* CONTROLLER ERROR */
-            log(LOG_ERR, "psm%d: failed to disable the aux port (reinitialize).\n",
+            log(LOG_ERR,
+                "psm%d: failed to disable the aux port (reinitialize).\n",
                 sc->unit);
             err = EIO;
 	}
_at__at_ -1209,15 +1203,8 _at__at_
     }
     set_mouse_scaling(sc->kbdc, 1);
 
-    /* request a data packet and extract sync. bits */
-    if (get_mouse_status(sc->kbdc, stat, 1, 3) < 3) {
-        printf("psm%d: failed to get data.\n", unit);
-        sc->mode.syncmask[0] = 0;
-    } else {
-        sc->mode.syncmask[1] = stat[0] & sc->mode.syncmask[0];	/* syncbits */
-	/* the NetScroll Mouse will send three more bytes... Ignore them */
-	empty_aux_buffer(sc->kbdc, 5);
-    }
+    /* Record sync on the next data packet we see. */
+    sc->flags |= PSM_NEED_SYNCBITS;
 
     /* just check the status of the mouse */
     /* 
_at__at_ -2081,6 +2068,11 _at__at_
 	c = pb->ipacket[0];
 
 	if ((c & sc->mode.syncmask[0]) != sc->mode.syncmask[1]) {
+	    if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
+		sc->mode.syncmask[1] = (c & sc->mode.syncmask[0]);
+		sc->flags &= ~PSM_NEED_SYNCBITS;
+		goto valid_sync;
+	    }
 #if DEBUG
             log(LOG_DEBUG, "psmintr: out of sync (%04x != %04x) %d"
 		" cmds since last error.\n", 
_at__at_ -2119,6 +2111,7 _at__at_
 	    }
 	    continue;
 	}
+valid_sync:
 	/* if this packet is at all bogus then drop the packet. */
 	if (haderror ||
 	    !timeelapsed(&sc->lastinputerr, psmerrsecs, psmerrusecs, &now)) {
Received on Fri Aug 13 2004 - 21:00:00 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:06 UTC