diff options
Diffstat (limited to 'drivers/usb/misc/idmouse.c')
| -rw-r--r-- | drivers/usb/misc/idmouse.c | 106 |
1 files changed, 59 insertions, 47 deletions
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index e6fd024024f..4e38683c653 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c @@ -19,7 +19,6 @@ #include <linux/kernel.h> #include <linux/errno.h> #include <linux/delay.h> -#include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/completion.h> @@ -48,7 +47,7 @@ #define ID_CHERRY 0x0010 /* device ID table */ -static struct usb_device_id idmouse_table[] = { +static const struct usb_device_id idmouse_table[] = { {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */ {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */ {} /* terminating null entry */ @@ -66,6 +65,7 @@ static struct usb_device_id idmouse_table[] = { USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000) MODULE_DEVICE_TABLE(usb, idmouse_table); +static DEFINE_MUTEX(open_disc_mutex); /* structure to hold all of our device specific stuff */ struct usb_idmouse { @@ -80,7 +80,7 @@ struct usb_idmouse { int open; /* if the port is open or not */ int present; /* if the device is not disconnected */ - struct semaphore sem; /* locks this structure */ + struct mutex lock; /* locks this structure */ }; @@ -95,6 +95,8 @@ static int idmouse_probe(struct usb_interface *interface, const struct usb_device_id *id); static void idmouse_disconnect(struct usb_interface *interface); +static int idmouse_suspend(struct usb_interface *intf, pm_message_t message); +static int idmouse_resume(struct usb_interface *intf); /* file operation pointers */ static const struct file_operations idmouse_fops = { @@ -102,6 +104,7 @@ static const struct file_operations idmouse_fops = { .read = idmouse_read, .open = idmouse_open, .release = idmouse_release, + .llseek = default_llseek, }; /* class driver information */ @@ -116,7 +119,11 @@ static struct usb_driver idmouse_driver = { .name = DRIVER_SHORT, .probe = idmouse_probe, .disconnect = idmouse_disconnect, + .suspend = idmouse_suspend, + .resume = idmouse_resume, + .reset_resume = idmouse_resume, .id_table = idmouse_table, + .supports_autosuspend = 1, }; static int idmouse_create_image(struct usb_idmouse *dev) @@ -192,10 +199,22 @@ reset: return -EAGAIN; /* should be IMGSIZE == 65040 */ - dbg("read %d bytes fingerprint data", bytes_read); + dev_dbg(&dev->interface->dev, "read %d bytes fingerprint data\n", + bytes_read); return result; } +/* PM operations are nops as this driver does IO only during open() */ +static int idmouse_suspend(struct usb_interface *intf, pm_message_t message) +{ + return 0; +} + +static int idmouse_resume(struct usb_interface *intf) +{ + return 0; +} + static inline void idmouse_delete(struct usb_idmouse *dev) { kfree(dev->bulk_in_buffer); @@ -213,13 +232,17 @@ static int idmouse_open(struct inode *inode, struct file *file) if (!interface) return -ENODEV; + mutex_lock(&open_disc_mutex); /* get the device information block from the interface */ dev = usb_get_intfdata(interface); - if (!dev) + if (!dev) { + mutex_unlock(&open_disc_mutex); return -ENODEV; + } /* lock this device */ - down(&dev->sem); + mutex_lock(&dev->lock); + mutex_unlock(&open_disc_mutex); /* check if already open */ if (dev->open) { @@ -230,9 +253,13 @@ static int idmouse_open(struct inode *inode, struct file *file) } else { /* create a new image and check for success */ + result = usb_autopm_get_interface(interface); + if (result) + goto error; result = idmouse_create_image (dev); if (result) goto error; + usb_autopm_put_interface(interface); /* increment our usage count for the driver */ ++dev->open; @@ -245,7 +272,7 @@ static int idmouse_open(struct inode *inode, struct file *file) error: /* unlock this device */ - up(&dev->sem); + mutex_unlock(&dev->lock); return result; } @@ -258,12 +285,14 @@ static int idmouse_release(struct inode *inode, struct file *file) if (dev == NULL) return -ENODEV; + mutex_lock(&open_disc_mutex); /* lock our device */ - down(&dev->sem); + mutex_lock(&dev->lock); /* are we really open? */ if (dev->open <= 0) { - up(&dev->sem); + mutex_unlock(&dev->lock); + mutex_unlock(&open_disc_mutex); return -ENODEV; } @@ -271,10 +300,12 @@ static int idmouse_release(struct inode *inode, struct file *file) if (!dev->present) { /* the device was unplugged before the file was released */ - up(&dev->sem); + mutex_unlock(&dev->lock); + mutex_unlock(&open_disc_mutex); idmouse_delete(dev); } else { - up(&dev->sem); + mutex_unlock(&dev->lock); + mutex_unlock(&open_disc_mutex); } return 0; } @@ -286,18 +317,18 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count int result; /* lock this object */ - down(&dev->sem); + mutex_lock(&dev->lock); /* verify that the device wasn't unplugged */ if (!dev->present) { - up(&dev->sem); + mutex_unlock(&dev->lock); return -ENODEV; } result = simple_read_from_buffer(buffer, count, ppos, dev->bulk_in_buffer, IMGSIZE); /* unlock the device */ - up(&dev->sem); + mutex_unlock(&dev->lock); return result; } @@ -320,7 +351,7 @@ static int idmouse_probe(struct usb_interface *interface, if (dev == NULL) return -ENOMEM; - init_MUTEX(&dev->sem); + mutex_init(&dev->lock); dev->udev = udev; dev->interface = interface; @@ -328,21 +359,21 @@ static int idmouse_probe(struct usb_interface *interface, endpoint = &iface_desc->endpoint[0].desc; if (!dev->bulk_in_endpointAddr && usb_endpoint_is_bulk_in(endpoint)) { /* we found a bulk in endpoint */ - dev->orig_bi_size = le16_to_cpu(endpoint->wMaxPacketSize); + dev->orig_bi_size = usb_endpoint_maxp(endpoint); dev->bulk_in_size = 0x200; /* works _much_ faster */ dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; dev->bulk_in_buffer = kmalloc(IMGSIZE + dev->bulk_in_size, GFP_KERNEL); if (!dev->bulk_in_buffer) { - err("Unable to allocate input buffer."); + dev_err(&interface->dev, "Unable to allocate input buffer.\n"); idmouse_delete(dev); return -ENOMEM; } } if (!(dev->bulk_in_endpointAddr)) { - err("Unable to find bulk-in endpoint."); + dev_err(&interface->dev, "Unable to find bulk-in endpoint.\n"); idmouse_delete(dev); return -ENODEV; } @@ -354,7 +385,7 @@ static int idmouse_probe(struct usb_interface *interface, result = usb_register_dev(interface, &idmouse_class); if (result) { /* something prevented us from registering this device */ - err("Unble to allocate minor number."); + dev_err(&interface->dev, "Unable to allocate minor number.\n"); usb_set_intfdata(interface, NULL); idmouse_delete(dev); return result; @@ -372,51 +403,32 @@ static void idmouse_disconnect(struct usb_interface *interface) /* get device structure */ dev = usb_get_intfdata(interface); - usb_set_intfdata(interface, NULL); /* give back our minor */ usb_deregister_dev(interface, &idmouse_class); - /* lock it */ - down(&dev->sem); + mutex_lock(&open_disc_mutex); + usb_set_intfdata(interface, NULL); + /* lock the device */ + mutex_lock(&dev->lock); + mutex_unlock(&open_disc_mutex); /* prevent device read, write and ioctl */ dev->present = 0; /* if the device is opened, idmouse_release will clean this up */ if (!dev->open) { - up(&dev->sem); + mutex_unlock(&dev->lock); idmouse_delete(dev); } else { /* unlock */ - up(&dev->sem); + mutex_unlock(&dev->lock); } - info("%s disconnected", DRIVER_DESC); -} - -static int __init usb_idmouse_init(void) -{ - int result; - - info(DRIVER_DESC " " DRIVER_VERSION); - - /* register this driver with the USB subsystem */ - result = usb_register(&idmouse_driver); - if (result) - err("Unable to register device (error %d).", result); - - return result; -} - -static void __exit usb_idmouse_exit(void) -{ - /* deregister this driver with the USB subsystem */ - usb_deregister(&idmouse_driver); + dev_info(&interface->dev, "disconnected\n"); } -module_init(usb_idmouse_init); -module_exit(usb_idmouse_exit); +module_usb_driver(idmouse_driver); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); |
