patch-2.2.14 linux/drivers/char/joystick/joy-gravis.c

Next file: linux/drivers/char/joystick/joy-lightning.c
Previous file: linux/drivers/char/joystick/joy-db9.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.13/linux/drivers/char/joystick/joy-gravis.c linux/drivers/char/joystick/joy-gravis.c
@@ -1,7 +1,9 @@
 /*
  *  joy-gravis.c  Version 1.2
  *
- *  Copyright (c) 1998 Vojtech Pavlik
+ *  Copyright (c) 1998-1999 Vojtech Pavlik
+ *
+ *  Sponsored by SuSE
  */
 
 /*
@@ -25,7 +27,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  * 
  * Should you need to contact me, the author, you can do so either by
- * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
+ * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
  */
 
@@ -37,15 +39,16 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/string.h>
+#include <linux/init.h>
 
 #define JS_GR_MODE_GPP		1
 #define JS_GR_LENGTH_GPP	24
-#define JS_GR_STROBE_GPP	75
+#define JS_GR_STROBE_GPP	400
 
 #define JS_GR_MODE_XT		2
 #define JS_GR_MODE_BD		3
 #define JS_GR_LENGTH_XT		4
-#define JS_GR_STROBE_XT		30
+#define JS_GR_STROBE_XT		200
 #define JS_GR_MAX_CHUNKS_XT	10	
 #define JS_GR_MAX_BITS_XT	30	
 
@@ -63,37 +66,36 @@
 
 static int js_gr_gpp_read_packet(int io, int shift, unsigned int *data)
 {
-	unsigned int t, t1;
+	unsigned long flags;
 	unsigned char u, v;
+	unsigned int t, p;
 	int i;
-	unsigned long flags;
-
-	int strobe = (js_time_speed * JS_GR_STROBE_GPP) >> 10;
 
 	i = 0;
 	data[0] = 0;
+	p = t = JS_GR_STROBE_GPP;
+	p += JS_GR_STROBE_GPP;
 
 	__save_flags(flags);
 	__cli();
-	u = inb(io) >> shift;
-	t = js_get_time();
+
+	v = inb(io) >> shift;
 
 	do {
-		v = (inb(io) >> shift) & 3;
-		t1 = js_get_time();
-		if ((u ^ v) & u & 1) {
+		t--;
+		u = v; v = (inb(io) >> shift) & 3;
+		if (~v & u & 1) {
 			data[0] |= (v >> 1) << i++;
-			t = t1;
+			p = t = (p - t) << 1;
 		}
-		u = v;
-	} while (i < JS_GR_LENGTH_GPP && js_delta(t1,t) < strobe);
+	} while (i < JS_GR_LENGTH_GPP && t > 0);
 
 	__restore_flags(flags);
 
 	if (i < JS_GR_LENGTH_GPP) return -1;
 
 	for (i = 0; i < JS_GR_LENGTH_GPP && (data[0] & 0xfe4210) ^ 0x7c0000; i++)
-		data[0] = data[0] >> 1 | (data[0] & 1) << 23;
+		data[0] = data[0] >> 1 | (data[0] & 1) << (JS_GR_LENGTH_GPP - 1);
 
 	return -(i == JS_GR_LENGTH_GPP);
 }
@@ -104,35 +106,36 @@
 
 static int js_gr_xt_read_packet(int io, int shift, unsigned int *data)
 {
-	unsigned int t, t1;
-	unsigned char u, v, w;
 	unsigned int i, j, buf, crc;
+	unsigned char u, v, w;
 	unsigned long flags;
+	unsigned int t, p;
 	char status;
 
-	int strobe = (js_time_speed * JS_GR_STROBE_XT) >> 10;
-
 	data[0] = data[1] = data[2] = data[3] = 0;
 	status = buf = i = j = 0;
+	p = t = JS_GR_STROBE_XT;
+	p += JS_GR_STROBE_XT;
 
 	__save_flags(flags);
 	__cli();
 
 	v = w = (inb(io) >> shift) & 3;
-	t = js_get_time();
 
 	do {
+		t--;
 		u = (inb(io) >> shift) & 3;
-		t1 = js_get_time();
 
 		if (u ^ v) {
 
 			if ((u ^ v) & 1) {
+				p = t = (p - t) << 2;
 				buf = (buf << 1) | (u >> 1);
 				i++;
 			} else 
 
 			if ((((u ^ v) & (v ^ w)) >> 1) & ~(u | v | w) & 1) {
+				p = t = (p - t) << 2;
 				if (i == 20) {
 					crc = buf ^ (buf >> 7) ^ (buf >> 14);
 					if (!((crc ^ (0x25cb9e70 >> ((crc >> 2) & 0x1c))) & 0xf)) {
@@ -145,12 +148,11 @@
 				i = 0;
 			}
 
-			t = t1;
 			w = v;
 			v = u;
 		}
 
-	} while (status != 0xf && i < JS_GR_MAX_BITS_XT && j < JS_GR_MAX_CHUNKS_XT && js_delta(t1,t) < strobe);
+	} while (status != 0xf && i < JS_GR_MAX_BITS_XT && j < JS_GR_MAX_CHUNKS_XT && t > 0);
 
 	__restore_flags(flags);
 
@@ -320,7 +322,7 @@
 }
 
 /*
- * js_gr_probe() probes fro GrIP joysticks.
+ * js_gr_probe() probes for GrIP joysticks.
  */
 
 static struct js_port __init *js_gr_probe(int io, struct js_port *port)
@@ -389,9 +391,9 @@
 	int i;
 	struct js_gr_info *info;
 
-	while (js_gr_port != NULL) {
+	while (js_gr_port) {
 		for (i = 0; i < js_gr_port->ndevs; i++)
-			if (js_gr_port->devs[i] != NULL)
+			if (js_gr_port->devs[i])
 				js_unregister_device(js_gr_port->devs[i]);
 		info = js_gr_port->info;
 		release_region(info->io, 1);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)