ChangeSet 1.1071, 2003/05/07 00:21:53-07:00, greg@kroah.com [PATCH] USB: converted auerswald over to new usb_register_dev() changes. drivers/usb/misc/auerswald.c | 71 ++++++++++++------------------------------- 1 files changed, 20 insertions(+), 51 deletions(-) diff -Nru a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c --- a/drivers/usb/misc/auerswald.c Wed May 7 11:12:16 2003 +++ b/drivers/usb/misc/auerswald.c Wed May 7 11:12:16 2003 @@ -29,7 +29,6 @@ #include #include #include -#include #undef DEBUG /* include debug macros until it's done */ #include @@ -60,16 +59,10 @@ /* Auerswald Vendor ID */ #define ID_AUERSWALD 0x09BF -#ifdef CONFIG_USB_DYNAMIC_MINORS -/* we can have up to 256 devices at once */ -#define AUER_MINOR_BASE 0 -#define AUER_MAX_DEVICES 256 -#else #define AUER_MINOR_BASE 112 /* auerswald driver minor number */ /* we can have up to this number of device plugged in at once */ #define AUER_MAX_DEVICES 16 -#endif /* Number of read buffers for each device */ @@ -256,12 +249,6 @@ wait_queue_head_t bufferwait; /* wait for a control buffer */ } auerswald_t,*pauerswald_t; -/* array of pointers to our devices that are currently connected */ -static pauerswald_t dev_table[AUER_MAX_DEVICES]; - -/* lock to protect the dev_table structure */ -static struct semaphore dev_table_mutex; - /* ................................................................... */ /* character device context */ typedef struct @@ -1384,29 +1371,29 @@ /* Open a new character device */ static int auerchar_open (struct inode *inode, struct file *file) { - int dtindex = minor(inode->i_rdev) - AUER_MINOR_BASE; + int dtindex = minor(inode->i_rdev); pauerswald_t cp = NULL; pauerchar_t ccp = NULL; + struct usb_interface *intf; int ret; /* minor number in range? */ - if ((dtindex < 0) || (dtindex >= AUER_MAX_DEVICES)) { + if (dtindex < 0) { return -ENODEV; } - /* usb device available? */ - if (down_interruptible (&dev_table_mutex)) { - return -ERESTARTSYS; + intf = usb_find_interface(&auerswald_driver, dtindex); + if (!intf) { + return -ENODEV; } - cp = dev_table[dtindex]; + + /* usb device available? */ + cp = usb_get_intfdata (intf); if (cp == NULL) { - up (&dev_table_mutex); return -ENODEV; } if (down_interruptible (&cp->mutex)) { - up (&dev_table_mutex); return -ERESTARTSYS; } - up (&dev_table_mutex); /* we have access to the device. Now lets allocate memory */ ccp = (pauerchar_t) kmalloc(sizeof(auerchar_t), GFP_KERNEL); @@ -1895,6 +1882,13 @@ .release = auerchar_release, }; +static struct usb_class_driver auerswald_class = { + .name = "usb/auer%d", + .fops = &auerswald_fops, + .mode = S_IFCHR | S_IRUGO | S_IWUGO, + .minor_base = AUER_MINOR_BASE, +}; + /* --------------------------------------------------------------------- */ /* Special USB driver functions */ @@ -1923,7 +1917,6 @@ struct usb_device *usbdev = interface_to_usbdev(intf); pauerswald_t cp = NULL; DECLARE_WAIT_QUEUE_HEAD (wqh); - unsigned int dtindex; unsigned int u = 0; char *pbuf; int ret; @@ -1954,27 +1947,17 @@ auerbuf_init (&cp->bufctl); init_waitqueue_head (&cp->bufferwait); - down (&dev_table_mutex); - ret = usb_register_dev (&auerswald_fops, AUER_MINOR_BASE, 1, &dtindex); + ret = usb_register_dev(intf, &auerswald_class); if (ret) { err ("Not able to get a minor for this device."); - up (&dev_table_mutex); goto pfail; } /* Give the device a name */ - sprintf (cp->name, "usb/auer%d", dtindex); + sprintf (cp->name, "usb/auer%d", intf->minor); /* Store the index */ - cp->dtindex = dtindex; - dev_table[dtindex] = cp; - up (&dev_table_mutex); - - /* initialize the devfs node for this device and register it */ - devfs_register(NULL, cp->name, 0, USB_MAJOR, - AUER_MINOR_BASE + dtindex, - S_IFCHR | S_IRUGO | S_IWUGO, - &auerswald_fops, NULL); + cp->dtindex = intf->minor; /* Get the usb version of the device */ cp->version = cp->usbdev->descriptor.bcdDevice; @@ -2083,18 +2066,8 @@ down (&cp->mutex); info ("device /dev/%s now disconnecting", cp->name); - /* remove from device table */ - /* Nobody can open() this device any more */ - down (&dev_table_mutex); - dev_table[cp->dtindex] = NULL; - up (&dev_table_mutex); - - /* remove our devfs node */ - /* Nobody can see this device any more */ - devfs_remove(cp->name); - /* give back our USB minor number */ - usb_deregister_dev (1, cp->dtindex); + usb_deregister_dev(intf, &auerswald_class); /* Stop the interrupt endpoint */ auerswald_int_release (cp); @@ -2162,10 +2135,6 @@ { int result; dbg ("init"); - - /* initialize the device table */ - memset (&dev_table, 0, sizeof(dev_table)); - init_MUTEX (&dev_table_mutex); /* register driver at the USB subsystem */ result = usb_register (&auerswald_driver);