Greg:

Pavel Machek has stated that the current /sys/devices/.../power/state
interface is broken and likely to be replaced.  It seems like a good idea
to add a separate private interface for use with USB devices, where
we know that the only possible power states are suspended and fully-on.  
This patch (as737) adds a "suspended" attribute for each usb_device.  
Writing 1 to the attribute will suspend the device and its interfaces, and
writing 0 will resume them.  The attribute is present only when 
CONFIG_USB_SUSPEND has been set, for obvious reasons.

The patch also makes a small cleanup to the sysfs.c file, by moving the 
dev_attr_configuration entry into the large attribute group instead of 
handling it separately.

Alan Stern



Signed-off-by: Alan Stern <[EMAIL PROTECTED]>

---

Index: usb-2.6/drivers/usb/core/sysfs.c
===================================================================
--- usb-2.6.orig/drivers/usb/core/sysfs.c
+++ usb-2.6/drivers/usb/core/sysfs.c
@@ -61,7 +61,7 @@ static ssize_t
 set_bConfigurationValue (struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
 {
-       struct usb_device       *udev = udev = to_usb_device (dev);
+       struct usb_device       *udev = to_usb_device (dev);
        int                     config, value;
 
        if (sscanf (buf, "%u", &config) != 1 || config > 255)
@@ -149,6 +149,37 @@ show_maxchild (struct device *dev, struc
 }
 static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
 
+/* suspended attribute is present only if CONFIG_USB_SUSPEND is set */
+#ifdef CONFIG_USB_SUSPEND
+
+static ssize_t
+show_suspended (struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct usb_device *udev = to_usb_device (dev);
+
+       return sprintf(buf, "%d\n", (udev->state == USB_STATE_SUSPENDED));
+}
+
+static ssize_t
+set_suspended (struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       unsigned                value;
+
+       if (sscanf (buf, "%u", &value) != 1 || value > 1)
+               return -EINVAL;
+       if (value)
+               value = dpm_runtime_suspend(dev, PMSG_SUSPEND);
+       else
+               dpm_runtime_resume(dev);        /* No return code?? */
+       return (value < 0) ? value : count;
+}
+
+static DEVICE_ATTR(suspended, S_IRUGO | S_IWUSR,
+               show_suspended, set_suspended);
+
+#endif /* CONFIG_USB_SUSPEND */
+
 /* Descriptor fields */
 #define usb_descriptor_attr_le16(field, format_string)                 \
 static ssize_t                                                         \
@@ -187,6 +218,7 @@ usb_descriptor_attr (bMaxPacketSize0, "%
 
 static struct attribute *dev_attrs[] = {
        /* current configuration's attributes */
+       &dev_attr_configuration.attr,
        &dev_attr_bNumInterfaces.attr,
        &dev_attr_bConfigurationValue.attr,
        &dev_attr_bmAttributes.attr,
@@ -204,6 +236,9 @@ static struct attribute *dev_attrs[] = {
        &dev_attr_devnum.attr,
        &dev_attr_version.attr,
        &dev_attr_maxchild.attr,
+#ifdef CONFIG_USB_SUSPEND
+       &dev_attr_suspended.attr,
+#endif
        NULL,
 };
 static struct attribute_group dev_attr_grp = {
@@ -222,7 +257,6 @@ void usb_create_sysfs_dev_files (struct 
                device_create_file (dev, &dev_attr_product);
        if (udev->serial)
                device_create_file (dev, &dev_attr_serial);
-       device_create_file (dev, &dev_attr_configuration);
        usb_create_ep_files(dev, &udev->ep0, udev);
 }
 
@@ -239,7 +273,6 @@ void usb_remove_sysfs_dev_files (struct 
                device_remove_file(dev, &dev_attr_product);
        if (udev->serial)
                device_remove_file(dev, &dev_attr_serial);
-       device_remove_file (dev, &dev_attr_configuration);
 }
 
 /* Interface fields */


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
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