Hi,
this patch set introduces usb_anchor and uses it to implement all modern
APIs in the skeleton driver.
- support for suspend/resume
Regards
Oliver
Signed-off-by: Oliver Neukum <[EMAIL PROTECTED]>
-----
--- linux-2.6.22-rc2/drivers/usb/usb-skeleton.c.1 2007-05-25
12:52:17.000000000 +0200
+++ linux-2.6.22-rc2-autosuspend/drivers/usb/usb-skeleton.c 2007-05-25
13:05:01.000000000 +0200
@@ -60,6 +60,7 @@ struct usb_skel {
__u8 bulk_in_endpointAddr; /* the address of the
bulk in endpoint */
__u8 bulk_out_endpointAddr; /* the address of the
bulk out endpoint */
int errors; /* the last request
tanked */
+ int open_count; /* count the number of
openers */
spinlock_t err_lock; /* lock for errors */
struct kref kref;
struct mutex io_mutex; /* synchronize I/O with
disconnect */
@@ -106,18 +107,29 @@ static int skel_open(struct inode *inode
/* increment our usage count for the device */
kref_get(&dev->kref);
- /* now we can drop the lock */
+
+ /* now we can drop the common lock */
+ mutex_lock(&dev->io_mutex);
mutex_unlock(&skel_open_lock);
- /* prevent the device from being autosuspended */
- retval = usb_autopm_get_interface(interface);
- if (retval) {
+ if (!dev->open_count++) {
+ retval = usb_autopm_get_interface(interface);
+ if (retval) {
+ mutex_unlock(&dev->io_mutex);
+ kref_put(&dev->kref, skel_delete);
+ goto exit;
+ }
+ } /* else { //uncomment this block if you want exclusive open
+ retval = -EBUSY;
+ dev->open_count--;
+ mutex_unlock(&dev->io_mutex);
kref_put(&dev->kref, skel_delete);
goto exit;
- }
+ } */
/* save our object in the file's private structure */
file->private_data = dev;
+ mutex_unlock(&dev->io_mutex);
exit:
return retval;
@@ -133,7 +145,7 @@ static int skel_release(struct inode *in
/* allow the device to be autosuspended */
mutex_lock(&dev->io_mutex);
- if (dev->interface)
+ if (!--dev->open_count && dev->interface)
usb_autopm_put_interface(dev->interface);
mutex_unlock(&dev->io_mutex);
@@ -449,10 +461,27 @@ static void skel_draw_down(struct usb_sk
usb_kill_anchored_urbs(&dev->submitted);
}
+static int skel_suspend(struct usb_interface *intf, pm_message_t message)
+{
+ struct usb_skel *dev = usb_get_intfdata(intf);
+
+ if (!dev)
+ return 0;
+ skel_draw_down(dev);
+ return 0;
+}
+
+static int skel_resume (struct usb_interface *intf)
+{
+ return 0;
+}
+
static struct usb_driver skel_driver = {
.name = "skeleton",
.probe = skel_probe,
.disconnect = skel_disconnect,
+ .suspend = skel_suspend,
+ .resume = skel_resume,
.id_table = skel_table,
.supports_autosuspend = 1,
};
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel