Am Freitag, 19. Januar 2007 16:01 schrieb Alan Stern:
> On Fri, 19 Jan 2007, Oliver Neukum wrote:
> 
> > Hi,
> > 
> > this is the second take of the patch to switch off autosuspend

Third take.

> > through sysfs to allow battery powered devices to recharge of the
> > bus. It includes the cleanups Alan suggested.

Alan?

        Regards
                Oliver

Signed-off-by: Oliver Neukum <[EMAIL PROTECTED]>
----

--- a/include/linux/usb.h       2007-01-23 12:15:07.000000000 +0100
+++ b/include/linux/usb.h       2007-01-23 11:53:46.000000000 +0100
@@ -364,6 +364,7 @@
 
        unsigned discon_suspended:1;    /* Disconnected while suspended */
        unsigned have_langid:1;         /* whether string_langid is valid */
+       unsigned may_autosuspend:1;     /* whether it should autosuspend */
        int string_langid;              /* language ID for strings */
 
        /* static strings from the device */
--- a/drivers/usb/core/sysfs.c  2007-01-23 12:29:29.000000000 +0100
+++ b/drivers/usb/core/sysfs.c  2007-01-23 12:00:01.000000000 +0100
@@ -148,6 +148,39 @@
 }
 static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
 
+static ssize_t
+show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct usb_device *udev;
+
+       udev = to_usb_device(dev);
+       return sprintf(buf, "%d\n", udev->may_autosuspend);
+}
+
+static ssize_t
+set_autosuspend(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       struct usb_device *udev = to_usb_device(dev);
+       int value, old;
+
+       if (sscanf (buf, "%u", &value) != 1 || value > 1)
+               return -EINVAL;
+
+       /* protected by sysfs's lock */
+       old = udev->may_autosuspend;
+       udev->may_autosuspend = value;
+       if (!value && old)
+               usb_autoresume_device(udev);
+       else if (value && !old)
+               usb_autosuspend_device(udev);
+
+       return count;
+}
+
+static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR, 
+               show_autosuspend, set_autosuspend);
+
 /* Descriptor fields */
 #define usb_descriptor_attr_le16(field, format_string)                 \
 static ssize_t                                                         \
@@ -185,6 +218,8 @@
 usb_descriptor_attr(bMaxPacketSize0, "%d\n")
 
 static struct attribute *dev_attrs[] = {
+       /* power management attributes */
+       &dev_attr_autosuspend.attr,
        /* current configuration's attributes */
        &dev_attr_configuration.attr,
        &dev_attr_bNumInterfaces.attr,
--- a/drivers/usb/core/usb.c    2007-01-23 12:14:58.000000000 +0100
+++ b/drivers/usb/core/usb.c    2007-01-23 11:56:13.000000000 +0100
@@ -301,6 +301,7 @@
        dev->portnum = port1;
        dev->bus = bus;
        dev->parent = parent;
+       dev->may_autosuspend = 1;
        INIT_LIST_HEAD(&dev->filelist);
 
 #ifdef CONFIG_PM
--- a/drivers/usb/core/driver.c 2007-01-23 12:14:58.000000000 +0100
+++ b/drivers/usb/core/driver.c 2007-01-23 11:51:27.000000000 +0100
@@ -948,7 +948,8 @@
        int                     i;
        struct usb_interface    *intf;
 
-       /* For autosuspend, fail fast if anything is in use.
+       /* For autosuspend, fail fast if anything is in use or autosuspend
+        * is disabled through sysfs.
         * Also fail if any interfaces require remote wakeup but it
         * isn't available. */
        udev->do_remote_wakeup = device_may_wakeup(&udev->dev);

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to