aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/sysfs.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 22:28:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 22:28:57 -0500
commitb6cf160c4b788a31f6a4017a469b956ca77febf4 (patch)
treed4d525000e283fe08905385d91dd0170454eae9a /drivers/usb/core/sysfs.c
parented50d6cbc394cd0966469d3e249353c9dd1d38b9 (diff)
parent2c044a4803804708984931bcbd03314732e995d5 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (128 commits) USB: fix codingstyle issues in drivers/usb/core/*.c USB: fix codingstyle issues in drivers/usb/core/message.c USB: fix codingstyle issues in drivers/usb/core/hcd-pci.c USB: fix codingstyle issues in drivers/usb/core/devio.c USB: fix codingstyle issues in drivers/usb/core/devices.c USB: fix codingstyle issues in drivers/usb/core/*.h USB: fix codingstyle issues in include/linux/usb/ USB: fix codingstyle issues in include/linux/usb.h USB: mark USB drivers as being GPL only USB: use a real vendor and product id for root hubs USB: mount options: fix usbfs USB: Fix usb_serial_driver structure for Kobil cardreader driver. usb: ehci should use u16 for isochronous intervals usb: ehci, remove false clear-reset path USB: Use menuconfig objects usb: ohci-sm501 driver usb: dma bounce buffer support USB: last abuses of intfdata in close for usb-serial drivers USB: kl5kusb105 don't flush to logically disconnected devices USB: oti6858: cleanup ...
Diffstat (limited to 'drivers/usb/core/sysfs.c')
-rw-r--r--drivers/usb/core/sysfs.c69
1 files changed, 59 insertions, 10 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 32bd130b1eed..a37ccbd1e007 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -72,7 +72,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
72 return (value < 0) ? value : count; 72 return (value < 0) ? value : count;
73} 73}
74 74
75static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, 75static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR,
76 show_bConfigurationValue, set_bConfigurationValue); 76 show_bConfigurationValue, set_bConfigurationValue);
77 77
78/* String fields */ 78/* String fields */
@@ -249,6 +249,41 @@ static void remove_persist_attributes(struct device *dev)
249#ifdef CONFIG_USB_SUSPEND 249#ifdef CONFIG_USB_SUSPEND
250 250
251static ssize_t 251static ssize_t
252show_connected_duration(struct device *dev, struct device_attribute *attr,
253 char *buf)
254{
255 struct usb_device *udev = to_usb_device(dev);
256
257 return sprintf(buf, "%u\n",
258 jiffies_to_msecs(jiffies - udev->connect_time));
259}
260
261static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL);
262
263/*
264 * If the device is resumed, the last time the device was suspended has
265 * been pre-subtracted from active_duration. We add the current time to
266 * get the duration that the device was actually active.
267 *
268 * If the device is suspended, the active_duration is up-to-date.
269 */
270static ssize_t
271show_active_duration(struct device *dev, struct device_attribute *attr,
272 char *buf)
273{
274 struct usb_device *udev = to_usb_device(dev);
275 int duration;
276
277 if (udev->state != USB_STATE_SUSPENDED)
278 duration = jiffies_to_msecs(jiffies + udev->active_duration);
279 else
280 duration = jiffies_to_msecs(udev->active_duration);
281 return sprintf(buf, "%u\n", duration);
282}
283
284static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
285
286static ssize_t
252show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) 287show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
253{ 288{
254 struct usb_device *udev = to_usb_device(dev); 289 struct usb_device *udev = to_usb_device(dev);
@@ -365,6 +400,14 @@ static int add_power_attributes(struct device *dev)
365 rc = sysfs_add_file_to_group(&dev->kobj, 400 rc = sysfs_add_file_to_group(&dev->kobj,
366 &dev_attr_level.attr, 401 &dev_attr_level.attr,
367 power_group); 402 power_group);
403 if (rc == 0)
404 rc = sysfs_add_file_to_group(&dev->kobj,
405 &dev_attr_connected_duration.attr,
406 power_group);
407 if (rc == 0)
408 rc = sysfs_add_file_to_group(&dev->kobj,
409 &dev_attr_active_duration.attr,
410 power_group);
368 } 411 }
369 return rc; 412 return rc;
370} 413}
@@ -372,6 +415,12 @@ static int add_power_attributes(struct device *dev)
372static void remove_power_attributes(struct device *dev) 415static void remove_power_attributes(struct device *dev)
373{ 416{
374 sysfs_remove_file_from_group(&dev->kobj, 417 sysfs_remove_file_from_group(&dev->kobj,
418 &dev_attr_active_duration.attr,
419 power_group);
420 sysfs_remove_file_from_group(&dev->kobj,
421 &dev_attr_connected_duration.attr,
422 power_group);
423 sysfs_remove_file_from_group(&dev->kobj,
375 &dev_attr_level.attr, 424 &dev_attr_level.attr,
376 power_group); 425 power_group);
377 sysfs_remove_file_from_group(&dev->kobj, 426 sysfs_remove_file_from_group(&dev->kobj,
@@ -601,21 +650,21 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
601/* Interface Accociation Descriptor fields */ 650/* Interface Accociation Descriptor fields */
602#define usb_intf_assoc_attr(field, format_string) \ 651#define usb_intf_assoc_attr(field, format_string) \
603static ssize_t \ 652static ssize_t \
604show_iad_##field (struct device *dev, struct device_attribute *attr, \ 653show_iad_##field(struct device *dev, struct device_attribute *attr, \
605 char *buf) \ 654 char *buf) \
606{ \ 655{ \
607 struct usb_interface *intf = to_usb_interface (dev); \ 656 struct usb_interface *intf = to_usb_interface(dev); \
608 \ 657 \
609 return sprintf (buf, format_string, \ 658 return sprintf(buf, format_string, \
610 intf->intf_assoc->field); \ 659 intf->intf_assoc->field); \
611} \ 660} \
612static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL); 661static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL);
613 662
614usb_intf_assoc_attr (bFirstInterface, "%02x\n") 663usb_intf_assoc_attr(bFirstInterface, "%02x\n")
615usb_intf_assoc_attr (bInterfaceCount, "%02d\n") 664usb_intf_assoc_attr(bInterfaceCount, "%02d\n")
616usb_intf_assoc_attr (bFunctionClass, "%02x\n") 665usb_intf_assoc_attr(bFunctionClass, "%02x\n")
617usb_intf_assoc_attr (bFunctionSubClass, "%02x\n") 666usb_intf_assoc_attr(bFunctionSubClass, "%02x\n")
618usb_intf_assoc_attr (bFunctionProtocol, "%02x\n") 667usb_intf_assoc_attr(bFunctionProtocol, "%02x\n")
619 668
620/* Interface fields */ 669/* Interface fields */
621#define usb_intf_attr(field, format_string) \ 670#define usb_intf_attr(field, format_string) \