linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* i8042 access timings
@ 2005-01-25  7:41 Dmitry Torokhov
  2005-01-25 10:51 ` Andries Brouwer
                   ` (3 more replies)
  0 siblings, 4 replies; 47+ messages in thread
From: Dmitry Torokhov @ 2005-01-25  7:41 UTC (permalink / raw)
  To: linux-input; +Cc: Alan Cox, linux-kernel, Vojtech Pavlik

Hi,

Recently there was a patch from Alan regarding access timing violations
in i8042. It made me curious as we only wait between accesses to status
register but not data register. I peeked into FreeBSD code and they use
delays to access both registers and I wonder if that's the piece that
makes i8042 mysteriously fail on some boards.

Anyway, regardless of whether access to data register should be done with
delay as well there seem to be another timing access violation - in
i8042_command we do i8042_wait_read which reads STR and then immediately
do i8042_read_status to check AUXDATA bit.

Does the patch below makes any sense?

-- 
Dmitry

===== drivers/input/serio/i8042.c 1.79 vs edited =====
--- 1.79/drivers/input/serio/i8042.c	2005-01-25 00:54:50 -05:00
+++ edited/drivers/input/serio/i8042.c	2005-01-25 02:04:56 -05:00
@@ -137,8 +137,8 @@
 static int i8042_wait_read(void)
 {
 	int i = 0;
-	while ((~i8042_read_status() & I8042_STR_OBF) && (i < I8042_CTL_TIMEOUT)) {
-		udelay(50);
+	while ((~i8042_read_status() & I8042_STR_OBF) && i < I8042_CTL_TIMEOUT) {
+		udelay(I8042_STR_DELAY);
 		i++;
 	}
 	return -(i == I8042_CTL_TIMEOUT);
@@ -147,8 +147,8 @@
 static int i8042_wait_write(void)
 {
 	int i = 0;
-	while ((i8042_read_status() & I8042_STR_IBF) && (i < I8042_CTL_TIMEOUT)) {
-		udelay(50);
+	while ((i8042_read_status() & I8042_STR_IBF) && i < I8042_CTL_TIMEOUT) {
+		udelay(I8042_STR_DELAY);
 		i++;
 	}
 	return -(i == I8042_CTL_TIMEOUT);
@@ -162,17 +162,20 @@
 static int i8042_flush(void)
 {
 	unsigned long flags;
-	unsigned char data;
+	unsigned char str, data;
 	int i = 0;
 
 	spin_lock_irqsave(&i8042_lock, flags);
 
-	while ((i8042_read_status() & I8042_STR_OBF) && (i++ < I8042_BUFFER_SIZE)) {
-		udelay(50);
+	do {
+		str = i8042_read_status();
+		if (~str & I8042_STR_OBF)
+			break;
+		udelay(I8042_DATA_DELAY);
 		data = i8042_read_data();
-		dbg("%02x <- i8042 (flush, %s)", data,
-			i8042_read_status() & I8042_STR_AUXDATA ? "aux" : "kbd");
-	}
+		dbg("%02x <- i8042 (flush, %s)", data, str & I8042_STR_AUXDATA ? "aux" : "kbd");
+		udelay(I8042_STR_DELAY);
+	} while (i++ < I8042_BUFFER_SIZE);
 
 	spin_unlock_irqrestore(&i8042_lock, flags);
 
@@ -190,6 +193,7 @@
 static int i8042_command(unsigned char *param, int command)
 {
 	unsigned long flags;
+	unsigned char str;
 	int retval = 0, i = 0;
 
 	if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
@@ -213,7 +217,10 @@
 	if (!retval)
 		for (i = 0; i < ((command >> 8) & 0xf); i++) {
 			if ((retval = i8042_wait_read())) break;
-			if (i8042_read_status() & I8042_STR_AUXDATA)
+			udelay(I8042_STR_DELAY);
+			str = i8042_read_status();
+			udelay(I8042_DATA_DELAY);
+			if (str & I8042_STR_AUXDATA)
 				param[i] = ~i8042_read_data();
 			else
 				param[i] = i8042_read_data();
@@ -424,6 +431,7 @@
 		ret = 0;
 		goto out;
 	}
+	udelay(I8042_DATA_DELAY);
 	data = i8042_read_data();
 	spin_unlock_irqrestore(&i8042_lock, flags);
 
===== drivers/input/serio/i8042.h 1.12 vs edited =====
--- 1.12/drivers/input/serio/i8042.h	2005-01-22 02:22:51 -05:00
+++ edited/drivers/input/serio/i8042.h	2005-01-25 01:44:36 -05:00
@@ -30,12 +30,19 @@
 #endif
 
 /*
- * This is in 50us units, the time we wait for the i8042 to react. This
+ * i8042 I/O recovery times
+ */
+#define I8042_STR_DELAY		20
+#define I8042_DATA_DELAY	7
+
+
+/*
+ * This is in 20us units, the time we wait for the i8042 to react. This
  * has to be long enough for the i8042 itself to timeout on sending a byte
  * to a non-existent mouse.
  */
 
-#define I8042_CTL_TIMEOUT	10000
+#define I8042_CTL_TIMEOUT	25000
 
 /*
  * When the device isn't opened and it's interrupts aren't used, we poll it at

^ permalink raw reply	[flat|nested] 47+ messages in thread
[parent not found: <200501260040.46288.sebekpi@poczta.onet.pl>]

end of thread, other threads:[~2005-02-13 16:17 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-25  7:41 i8042 access timings Dmitry Torokhov
2005-01-25 10:51 ` Andries Brouwer
2005-01-25 19:17   ` Dmitry Torokhov
2005-01-25 19:25     ` Vojtech Pavlik
2005-01-25 19:41       ` Dmitry Torokhov
2005-01-25 19:46     ` Andries Brouwer
2005-01-25 20:37       ` Lee Revell
2005-01-27 15:14         ` Alan Cox
2005-01-27 16:24           ` Vojtech Pavlik
2005-01-27 16:34           ` Bill Rugolsky Jr.
2005-01-27 16:37             ` Vojtech Pavlik
2005-02-13  0:16               ` Bill Rugolsky Jr.
2005-02-13  8:22                 ` Vojtech Pavlik
2005-02-13 16:17                   ` Bill Rugolsky Jr.
2005-01-27 17:45           ` Andries Brouwer
2005-01-28 14:55             ` Vojtech Pavlik
2005-01-25 12:44 ` Alan Cox
2005-01-25 12:44 ` Alan Cox
2005-01-26 15:43 ` Vojtech Pavlik
2005-01-26 16:36   ` Dmitry Torokhov
2005-01-26 17:05     ` linux-os
2005-01-26 18:30       ` Dmitry Torokhov
2005-01-27 10:19     ` Vojtech Pavlik
     [not found] <200501260040.46288.sebekpi@poczta.onet.pl>
2005-01-27  6:23 ` Jaco Kroon
2005-01-27 10:25   ` Vojtech Pavlik
2005-01-27 11:12     ` Sebastian Piechocki
2005-01-27 11:31       ` Vojtech Pavlik
2005-01-27 17:33         ` Jaco Kroon
2005-01-27 18:09   ` Linus Torvalds
2005-01-27 20:29     ` Andries Brouwer
2005-01-27 20:41       ` Dmitry Torokhov
2005-01-27 23:11         ` Andries Brouwer
2005-01-28 13:17       ` Vojtech Pavlik
2005-01-28 14:20         ` Jaco Kroon
2005-01-28 18:39           ` Vojtech Pavlik
2005-01-29 19:59             ` Jaco Kroon
2005-01-29 23:21               ` Dmitry Torokhov
2005-01-29 20:02             ` Randy.Dunlap
2005-01-27 20:51     ` Jaco Kroon
2005-01-27 21:17       ` Linus Torvalds
2005-01-27 22:12         ` Jaco Kroon
2005-01-27 22:36           ` Linus Torvalds
2005-01-27 23:40             ` Dmitry Torokhov
2005-01-28  5:52             ` Jaco Kroon
2005-02-04 19:54             ` Bukie Mabayoje
2005-01-28 11:04           ` Vojtech Pavlik
2005-01-27 20:23   ` Andries Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).