lkml.org 
[lkml]   [2001]   [Aug]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] usbscanner and devfs
From
Date

This patch adds devfs support for the usbscanner module.

--- linux-2.4.8/drivers/usb/scanner.c.y Thu Aug 16 13:27:11 2001
+++ linux-2.4.8/drivers/usb/scanner.c Thu Aug 16 16:37:38 2001
@@ -228,6 +228,9 @@
* - Added Epson Perfection 1640SU and 1640SU Photo. Thanks to
* Jean-Luc <f5ibh@db0bm.ampr.org>.
*
+ * 0.4.6 08/16/2001 Yves Duret <yduret@mandrakesoft.com>
+ * - added devfs support (from printer.c)
+ *
* TODO
*
* - Performance
@@ -579,6 +582,100 @@
return ret ? ret : bytes_read;
}

+#ifdef SCN_IOCTL
+static int
+ioctl_scanner(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct usb_device *dev;
+
+ int result;
+
+ kdev_t scn_minor;
+
+ scn_minor = USB_SCN_MINOR(inode);
+
+ if (!p_scn_table[scn_minor]) {
+ err("ioctl_scanner(%d): invalid scn_minor", scn_minor);
+ return -ENODEV;
+ }
+
+ dev = p_scn_table[scn_minor]->scn_dev;
+
+ switch (cmd)
+ {
+ case IOCTL_SCANNER_VENDOR :
+ return (put_user(dev->descriptor.idVendor, (unsigned int *) arg));
+ case IOCTL_SCANNER_PRODUCT :
+ return (put_user(dev->descriptor.idProduct, (unsigned int *) arg));
+ case PV8630_IOCTL_INREQUEST :
+ {
+ struct {
+ __u8 data;
+ __u8 request;
+ __u16 value;
+ __u16 index;
+ } args;
+
+ if (copy_from_user(&args, (void *)arg, sizeof(args)))
+ return -EFAULT;
+
+ result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+ args.request, USB_TYPE_VENDOR|
+ USB_RECIP_DEVICE|USB_DIR_IN,
+ args.value, args.index, &args.data,
+ 1, HZ*5);
+
+ dbg("ioctl_scanner(%d): inreq: args.data:%x args.value:%x args.index:%x args.request:%x\n", scn_minor, args.data, args.value, args.index, args.request);
+
+ if (copy_to_user((void *)arg, &args, sizeof(args)))
+ return -EFAULT;
+
+ dbg("ioctl_scanner(%d): inreq: result:%d\n", scn_minor, result);
+
+ return result;
+ }
+ case PV8630_IOCTL_OUTREQUEST :
+ {
+ struct {
+ __u8 request;
+ __u16 value;
+ __u16 index;
+ } args;
+
+ if (copy_from_user(&args, (void *)arg, sizeof(args)))
+ return -EFAULT;
+
+ dbg("ioctl_scanner(%d): outreq: args.value:%x args.index:%x args.request:%x\n", scn_minor, args.value, args.index, args.request);
+
+ result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+ args.request, USB_TYPE_VENDOR|
+ USB_RECIP_DEVICE|USB_DIR_OUT,
+ args.value, args.index, NULL,
+ 0, HZ*5);
+
+ dbg("ioctl_scanner(%d): outreq: result:%d\n", scn_minor, result);
+
+ return result;
+ }
+ default:
+ return -ENOTTY;
+ }
+ return 0;
+}
+#endif /* SCN_IOCTL */
+
+static struct
+file_operations usb_scanner_fops = {
+ read: read_scanner,
+ write: write_scanner,
+#ifdef SCN_IOCTL
+ ioctl: ioctl_scanner,
+#endif /* SCN_IOCTL */
+ open: open_scanner,
+ release: close_scanner,
+};
+
static void *
probe_scanner(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id)
@@ -813,6 +910,14 @@

init_MUTEX(&(scn->gen_lock));

+ /* if we have devfs, create with perms=660 */
+ scn->devfs = devfs_register(usb_devfs_handle, "scanner",
+ DEVFS_FL_DEFAULT, USB_MAJOR,
+ SCN_BASE_MNR + scn_minor,
+ S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP |
+ S_IWGRP, &usb_scanner_fops, NULL);
+
+
return p_scn_table[scn_minor] = scn;
}

@@ -828,6 +933,8 @@
usb_driver_release_interface(&scanner_driver,
&scn->scn_dev->actconfig->interface[scn->ifnum]);

+ devfs_unregister (scn->devfs);
+
kfree(scn->ibuf);
kfree(scn->obuf);

@@ -836,99 +943,6 @@
kfree (scn);
}

-#ifdef SCN_IOCTL
-static int
-ioctl_scanner(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
-{
- struct usb_device *dev;
-
- int result;
-
- kdev_t scn_minor;
-
- scn_minor = USB_SCN_MINOR(inode);
-
- if (!p_scn_table[scn_minor]) {
- err("ioctl_scanner(%d): invalid scn_minor", scn_minor);
- return -ENODEV;
- }
-
- dev = p_scn_table[scn_minor]->scn_dev;
-
- switch (cmd)
- {
- case IOCTL_SCANNER_VENDOR :
- return (put_user(dev->descriptor.idVendor, (unsigned int *) arg));
- case IOCTL_SCANNER_PRODUCT :
- return (put_user(dev->descriptor.idProduct, (unsigned int *) arg));
- case PV8630_IOCTL_INREQUEST :
- {
- struct {
- __u8 data;
- __u8 request;
- __u16 value;
- __u16 index;
- } args;
-
- if (copy_from_user(&args, (void *)arg, sizeof(args)))
- return -EFAULT;
-
- result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
- args.request, USB_TYPE_VENDOR|
- USB_RECIP_DEVICE|USB_DIR_IN,
- args.value, args.index, &args.data,
- 1, HZ*5);
-
- dbg("ioctl_scanner(%d): inreq: args.data:%x args.value:%x args.index:%x args.request:%x\n", scn_minor, args.data, args.value, args.index, args.request);
-
- if (copy_to_user((void *)arg, &args, sizeof(args)))
- return -EFAULT;
-
- dbg("ioctl_scanner(%d): inreq: result:%d\n", scn_minor, result);
-
- return result;
- }
- case PV8630_IOCTL_OUTREQUEST :
- {
- struct {
- __u8 request;
- __u16 value;
- __u16 index;
- } args;
-
- if (copy_from_user(&args, (void *)arg, sizeof(args)))
- return -EFAULT;
-
- dbg("ioctl_scanner(%d): outreq: args.value:%x args.index:%x args.request:%x\n", scn_minor, args.value, args.index, args.request);
-
- result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
- args.request, USB_TYPE_VENDOR|
- USB_RECIP_DEVICE|USB_DIR_OUT,
- args.value, args.index, NULL,
- 0, HZ*5);
-
- dbg("ioctl_scanner(%d): outreq: result:%d\n", scn_minor, result);
-
- return result;
- }
- default:
- return -ENOTTY;
- }
- return 0;
-}
-#endif /* SCN_IOCTL */
-
-static struct
-file_operations usb_scanner_fops = {
- read: read_scanner,
- write: write_scanner,
-#ifdef SCN_IOCTL
- ioctl: ioctl_scanner,
-#endif /* SCN_IOCTL */
- open: open_scanner,
- release: close_scanner,
-};

static struct
usb_driver scanner_driver = {
--- linux-2.4.8/drivers/usb/scanner.h.y Thu Aug 16 13:27:18 2001
+++ linux-2.4.8/drivers/usb/scanner.h Thu Aug 16 16:37:39 2001
@@ -5,6 +5,8 @@
*
* David E. Nelson (dnelson@jump.net)
*
+ * 08/16/2001 added devfs support Yves Duret <yduret@mandrakesoft.com>
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
@@ -31,6 +33,7 @@
#include <linux/ioctl.h>
#include <linux/sched.h>
#include <linux/smp_lock.h>
+#include <linux/devfs_fs_kernel.h>

// #define DEBUG

@@ -174,6 +177,7 @@

struct scn_usb_data {
struct usb_device *scn_dev;
+ devfs_handle_t devfs; /* devfs device */
struct urb scn_irq;
unsigned int ifnum; /* Interface number of the USB device */
kdev_t scn_minor; /* Scanner minor - used in disconnect() */
@@ -190,3 +194,5 @@
static struct scn_usb_data *p_scn_table[SCN_MAX_MNR] = { NULL, /* ... */};

static struct usb_driver scanner_driver;
+
+extern devfs_handle_t usb_devfs_handle; /* /dev/usb dir. */
--
Yves Duret
yduret@mandrakesoft.com
P|-|34R |)4 R4|<317
\
 
 \ /
  Last update: 2005-03-22 12:57    [W:0.032 / U:0.412 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site