patch-2.3.20 linux/drivers/char/ppdev.c

Next file: linux/drivers/char/ppdev.h
Previous file: linux/drivers/char/pms.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.19/linux/drivers/char/ppdev.c linux/drivers/char/ppdev.c
@@ -34,8 +34,12 @@
  *   YIELD	parport_yield_blocking
  *   WCTLONIRQ	on interrupt, set control lines
  *   CLRIRQ	clear (and return) interrupt count
+ *   SETTIME	sets device timeout (struct timeval)
+ *   GETTIME    gets device timeout (struct timeval)
  * read/write	read or write in current IEEE 1284 protocol
  * select	wait for interrupt (in readfds)
+ *
+ * Added SETTIME/GETTIME ioctl, Fred Barnes 1999.
  */
 
 #include <linux/module.h>
@@ -74,6 +78,9 @@
 #define PP_BUFFER_SIZE 256
 #define PARDEVICE_MAX 8
 
+/* ROUND_UP macro from fs/select.c */
+#define ROUND_UP(x,y) (((x)+(y)-1)/(y))
+
 static inline void enable_irq (struct pp_struct *pp)
 {
 	struct parport *port = pp->pdev->port;
@@ -356,6 +363,8 @@
 		unsigned char mask;
 		int mode;
 		int ret;
+		struct timeval par_timeout;
+		long to_jiffies;
 
 	case PPRSTATUS:
 		reg = parport_read_status (port);
@@ -449,6 +458,33 @@
 		if (copy_to_user ((int *) arg, &ret, sizeof (ret)))
 			return -EFAULT;
 		atomic_sub (ret, &pp->irqc);
+		return 0;
+
+	case PPSETTIME:
+		if (copy_from_user (&par_timeout, (struct timeval *)arg,
+				    sizeof(struct timeval))) {
+			return -EFAULT;
+		}
+		/* Convert to jiffies, place in pp->pdev->timeout */
+		if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) {
+			return -EINVAL;
+		}
+		to_jiffies = ROUND_UP(par_timeout.tv_usec, 1000000/HZ);
+		to_jiffies += par_timeout.tv_sec * (long)HZ;
+		if (to_jiffies <= 0) {
+			return -EINVAL;
+		}
+		pp->pdev->timeout = to_jiffies;
+		return 0;
+
+	case PPGETTIME:
+		to_jiffies = pp->pdev->timeout;
+		par_timeout.tv_sec = to_jiffies / HZ;
+		par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ);
+		if (copy_to_user ((struct timeval *)arg, &par_timeout,
+				  sizeof(struct timeval))) {
+			return -EFAULT;
+		}
 		return 0;
 
 	default:

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