59 #include <linux/module.h>
61 #include <linux/sched.h>
62 #include <linux/device.h>
64 #include <linux/parport.h>
65 #include <linux/ctype.h>
66 #include <linux/poll.h>
67 #include <linux/slab.h>
73 #define PP_VERSION "ppdev: user-space parallel port driver"
74 #define CHRDEV "ppdev"
89 #define PP_CLAIMED (1<<0)
90 #define PP_EXCL (1<<1)
93 #define PP_INTERRUPT_TIMEOUT (10 * HZ)
94 #define PP_BUFFER_SIZE 1024
95 #define PARDEVICE_MAX 8
98 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
101 static inline void pp_enable_irq (
struct pp_struct *
pp)
104 port->
ops->enable_irq (port);
110 unsigned int minor = iminor(file->
f_path.dentry->d_inode);
131 pport = pp->
pdev->port;
139 while (bytes_read == 0) {
154 fn = pport->
ops->epp_read_addr;
156 fn = pport->
ops->epp_read_data;
158 bytes_read = (*fn)(
pport, kbuffer, need,
flags);
171 if (signal_pending (
current)) {
181 if (bytes_read > 0 &&
copy_to_user (buf, kbuffer, bytes_read))
189 static ssize_t pp_write (
struct file * file,
const char __user * buf,
190 size_t count, loff_t * ppos)
192 unsigned int minor = iminor(file->
f_path.dentry->d_inode);
210 pport = pp->
pdev->port;
218 while (bytes_written < count) {
229 wrote = pport->
ops->epp_write_addr (pport,
232 wrote = pport->
ops->epp_write_data (pport,
240 if (!bytes_written) {
241 bytes_written = wrote;
246 bytes_written += wrote;
254 if (signal_pending (
current)) {
255 if (!bytes_written) {
256 bytes_written = -
EINTR;
268 return bytes_written;
271 static void pp_irq (
void *
private)
284 static int register_device (
int minor,
struct pp_struct *pp)
304 NULL, pp_irq, fl, pp);
314 pr_debug(
"%s: registered pardevice\n", name);
329 static int pp_do_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
331 unsigned int minor = iminor(file->
f_path.dentry->d_inode);
350 int err = register_device (minor, pp);
367 info = &pp->
pdev->port->ieee1284;
380 "already registered\n", minor);
399 pp->
state.phase = init_phase (mode);
402 pp->
pdev->port->ieee1284.mode =
mode;
403 pp->
pdev->port->ieee1284.phase = pp->
state.phase;
413 mode = pp->
pdev->port->ieee1284.mode;
415 mode = pp->
state.mode;
442 phase = pp->
pdev->port->ieee1284.phase;
444 phase = pp->
state.phase;
496 port = pp->
pdev->port;
522 parport_yield_blocking (pp->
pdev);
527 info = &pp->
pdev->port->ieee1284;
562 port->
ops->data_reverse (port);
564 port->
ops->data_forward (port);
604 if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) {
607 to_jiffies =
ROUND_UP(par_timeout.tv_usec, 1000000/
HZ);
608 to_jiffies += par_timeout.tv_sec * (
long)
HZ;
609 if (to_jiffies <= 0) {
612 pp->
pdev->timeout = to_jiffies;
616 to_jiffies = pp->
pdev->timeout;
617 memset(&par_timeout, 0,
sizeof(par_timeout));
618 par_timeout.tv_sec = to_jiffies /
HZ;
619 par_timeout.tv_usec = (to_jiffies % (
long)
HZ) * (1000000/
HZ);
633 static long pp_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
637 ret = pp_do_ioctl(file, cmd, arg);
642 static int pp_open (
struct inode *
inode,
struct file * file)
644 unsigned int minor = iminor(inode);
655 pp->
state.phase = init_phase (pp->
state.mode);
671 static int pp_release (
struct inode * inode,
struct file * file)
673 unsigned int minor = iminor(inode);
685 info = &pp->
pdev->port->ieee1284;
698 "mode because user-space forgot\n", minor);
704 info = &pp->
pdev->port->ieee1284;
710 if (compat_negot != 1) {
712 "because user-space forgot\n", minor);
717 const char *name = pp->
pdev->name;
730 static unsigned int pp_poll (
struct file * file,
poll_table *
wait)
733 unsigned int mask = 0;
735 poll_wait (file, &pp->
irq_wait, wait);
742 static struct class *ppdev_class;
750 .unlocked_ioctl = pp_ioctl,
752 .release = pp_release,
755 static void pp_attach(
struct parport *port)
761 static void pp_detach(
struct parport *port)
772 static int __init ppdev_init (
void)
782 if (IS_ERR(ppdev_class)) {
783 err = PTR_ERR(ppdev_class);
803 static void __exit ppdev_cleanup (
void)