[PARPORT] ppdev device timeout IOCTLs


Frederick Barnes (frmb@mail.cern.ch)
Sun, 26 Sep 1999 11:21:03 +0200 (CEST)


Hi,

I've added two IOCTLs to ppdev to get and set the device timeout (as set
by drivers/parport/share.c). The default 5 seconds is probably a little
too long for most uses, especially as in ECP mode, there is no definite
way to signal the end of a reverse transfer and go back to forward-idle.

It's entirely possible that this comes under the definition of
'new-features', which is against the feature-freeze ethos, but it's a
useful addition.

Ta,
  Fred.

-- 
+--------------------------------------------------------------------------+
| Fred Barnes                                                              |
| Frederick.Barnes@cern.ch                        http://teddy.xylene.com/ |
+--------------------------------------------------------------------------+

diff -u linux-pcetb/drivers/char/ppdev.c.orig linux-pcetb/drivers/char/ppdev.c --- linux-pcetb/drivers/char/ppdev.c.orig Sun Sep 26 11:29:10 1999 +++ linux-pcetb/drivers/char/ppdev.c Sun Sep 26 12:27:11 1999 @@ -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,31 @@ 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 -EINVAL; + } return 0; default: diff -u linux-pcetb/drivers/char/ppdev.h.orig linux-pcetb/drivers/char/ppdev.h --- linux-pcetb/drivers/char/ppdev.h.orig Sun Sep 26 11:50:35 1999 +++ linux-pcetb/drivers/char/ppdev.h Sun Sep 26 11:55:12 1999 @@ -10,6 +10,7 @@ * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * + * Added PPGETTIME/PPSETTIME, Fred Barnes, 1999 */ #define PP_MAJOR 99 @@ -72,3 +73,9 @@ /* Set the IEEE 1284 phase that we're in (e.g. IEEE1284_PH_FWD_IDLE) */ #define PPSETPHASE _IOW(PP_IOCTL, 0x94, int) + +/* Set and get port timeout (struct timeval's) */ +#define PPGETTIME _IOW(PP_IOCTL, 0x95, struct timeval) +#define PPSETTIME _IOR(PP_IOCTL, 0x96, struct timeval) + +

-- To unsubscribe, send mail to: linux-parport-request@torque.net -- -- with the single word "unsubscribe" in the body of the message. --



This archive was generated by hypermail 2.0b3 on Sun 26 Sep 1999 - 05:24:07 EDT