patch-2.3.27 linux/drivers/parport/ieee1284.c

Next file: linux/drivers/parport/ieee1284_ops.c
Previous file: linux/drivers/net/yellowfin.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.26/linux/drivers/parport/ieee1284.c linux/drivers/parport/ieee1284.c
@@ -80,19 +80,42 @@
  * are able to eat the time up to 40ms.
  */ 
 
+int parport_poll_peripheral(struct parport *port,
+			    unsigned char mask,
+			    unsigned char result,
+			    int usec)
+{
+	/* Zero return code is success, >0 is timeout. */
+	int counter = usec / 5;
+	unsigned char status;
+	for (; counter > 0; counter--) {
+		status = parport_read_status (port);
+		if ((status & mask) == result)
+			return 0;
+		if (signal_pending (current))
+			return -EINTR;
+		if (current->need_resched)
+			break;
+		udelay (5);
+	}
+
+	return 1;
+}
+
 int parport_wait_peripheral(struct parport *port,
 			    unsigned char mask, 
 			    unsigned char result)
 {
-	int counter;
+	int ret;
+	int usec;
 	long deadline;
 	unsigned char status;
 
-	counter = port->physport->spintime; /* usecs of fast polling */
+	usec = port->physport->spintime; /* usecs of fast polling */
 	if (!port->physport->cad->timeout)
 		/* A zero timeout is "special": busy wait for the
 		   entire 35ms. */
-		counter = 35000;
+		usec = 35000;
 
 	/* Fast polling.
 	 *
@@ -100,16 +123,9 @@
 	 * How about making a note (in the device structure) of how long
 	 * it takes, so we know for next time?
 	 */
-	for (counter /= 5; counter > 0; counter--) {
-		status = parport_read_status (port);
-		if ((status & mask) == result)
-			return 0;
-		if (signal_pending (current))
-			return -EINTR;
-		if (current->need_resched)
-			break;
-		udelay(5);
-	}
+	ret = parport_poll_peripheral (port, mask, result, usec);
+	if (ret != 1)
+		return ret;
 
 	if (!port->physport->cad->timeout)
 		/* We may be in an interrupt handler, so we can't poll
@@ -137,7 +153,7 @@
 			/* parport_wait_event didn't time out, but the
 			 * peripheral wasn't actually ready either.
 			 * Wait for another 10ms. */
-			current->state = TASK_INTERRUPTIBLE;
+			__set_current_state (TASK_INTERRUPTIBLE);
 			schedule_timeout ((HZ+ 99) / 100);
 		}
 	}
@@ -369,8 +385,17 @@
 				      PARPORT_CONTROL_STROBE,
 				      PARPORT_CONTROL_STROBE);
 
+		/* Event 52: nAck goes low */
+		if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
+			/* This peripheral is _very_ slow. */
+			DPRINTK (KERN_DEBUG
+				 "%s: Event 52 didn't happen\n",
+				 port->name);
+			parport_ieee1284_terminate (port);
+			return 1;
+		}
+
 		/* Event 53: Set nStrobe high */
-		udelay (5);
 		parport_frob_control (port,
 				      PARPORT_CONTROL_STROBE,
 				      0);

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