2 * drivers/usb/core/sysfs.c
4 * (C) Copyright 2002 David Brownell
5 * (C) Copyright 2002,2004 Greg Kroah-Hartman
6 * (C) Copyright 2002,2004 IBM Corp.
8 * All of the sysfs file attributes for usb devices and interfaces.
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/usb.h>
16 #include <linux/usb/quirks.h>
19 /* Active configuration fields */
20 #define usb_actconfig_show(field, format_string) \
21 static ssize_t show_##field(struct device *dev, \
22 struct device_attribute *attr, char *buf) \
24 struct usb_device *udev; \
25 struct usb_host_config *actconfig; \
27 udev = to_usb_device(dev); \
28 actconfig = udev->actconfig; \
30 return sprintf(buf, format_string, \
31 actconfig->desc.field); \
36 #define usb_actconfig_attr(field, format_string) \
37 usb_actconfig_show(field, format_string) \
38 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
40 usb_actconfig_attr(bNumInterfaces, "%2d\n")
41 usb_actconfig_attr(bmAttributes, "%2x\n")
43 static ssize_t show_bMaxPower(struct device *dev,
44 struct device_attribute *attr, char *buf)
46 struct usb_device *udev;
47 struct usb_host_config *actconfig;
49 udev = to_usb_device(dev);
50 actconfig = udev->actconfig;
53 return sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig));
55 static DEVICE_ATTR(bMaxPower, S_IRUGO, show_bMaxPower, NULL);
57 static ssize_t show_configuration_string(struct device *dev,
58 struct device_attribute *attr, char *buf)
60 struct usb_device *udev;
61 struct usb_host_config *actconfig;
63 udev = to_usb_device(dev);
64 actconfig = udev->actconfig;
65 if ((!actconfig) || (!actconfig->string))
67 return sprintf(buf, "%s\n", actconfig->string);
69 static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
71 /* configuration value is always present, and r/w */
72 usb_actconfig_show(bConfigurationValue, "%u\n");
75 set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
76 const char *buf, size_t count)
78 struct usb_device *udev = to_usb_device(dev);
81 if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
83 usb_lock_device(udev);
84 value = usb_set_configuration(udev, config);
85 usb_unlock_device(udev);
86 return (value < 0) ? value : count;
89 static DEVICE_ATTR_IGNORE_LOCKDEP(bConfigurationValue, S_IRUGO | S_IWUSR,
90 show_bConfigurationValue, set_bConfigurationValue);
93 #define usb_string_attr(name) \
94 static ssize_t show_##name(struct device *dev, \
95 struct device_attribute *attr, char *buf) \
97 struct usb_device *udev; \
100 udev = to_usb_device(dev); \
101 usb_lock_device(udev); \
102 retval = sprintf(buf, "%s\n", udev->name); \
103 usb_unlock_device(udev); \
106 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
108 usb_string_attr(product);
109 usb_string_attr(manufacturer);
110 usb_string_attr(serial);
113 show_speed(struct device *dev, struct device_attribute *attr, char *buf)
115 struct usb_device *udev;
118 udev = to_usb_device(dev);
120 switch (udev->speed) {
124 case USB_SPEED_UNKNOWN:
131 case USB_SPEED_WIRELESS:
134 case USB_SPEED_SUPER:
140 return sprintf(buf, "%s\n", speed);
142 static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL);
145 show_busnum(struct device *dev, struct device_attribute *attr, char *buf)
147 struct usb_device *udev;
149 udev = to_usb_device(dev);
150 return sprintf(buf, "%d\n", udev->bus->busnum);
152 static DEVICE_ATTR(busnum, S_IRUGO, show_busnum, NULL);
155 show_devnum(struct device *dev, struct device_attribute *attr, char *buf)
157 struct usb_device *udev;
159 udev = to_usb_device(dev);
160 return sprintf(buf, "%d\n", udev->devnum);
162 static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL);
165 show_devpath(struct device *dev, struct device_attribute *attr, char *buf)
167 struct usb_device *udev;
169 udev = to_usb_device(dev);
170 return sprintf(buf, "%s\n", udev->devpath);
172 static DEVICE_ATTR(devpath, S_IRUGO, show_devpath, NULL);
175 show_version(struct device *dev, struct device_attribute *attr, char *buf)
177 struct usb_device *udev;
180 udev = to_usb_device(dev);
181 bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB);
182 return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff);
184 static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
187 show_maxchild(struct device *dev, struct device_attribute *attr, char *buf)
189 struct usb_device *udev;
191 udev = to_usb_device(dev);
192 return sprintf(buf, "%d\n", udev->maxchild);
194 static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
197 show_quirks(struct device *dev, struct device_attribute *attr, char *buf)
199 struct usb_device *udev;
201 udev = to_usb_device(dev);
202 return sprintf(buf, "0x%x\n", udev->quirks);
204 static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL);
207 show_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, char *buf)
209 struct usb_device *udev;
211 udev = to_usb_device(dev);
212 return sprintf(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET));
216 set_avoid_reset_quirk(struct device *dev, struct device_attribute *attr,
217 const char *buf, size_t count)
219 struct usb_device *udev = to_usb_device(dev);
222 if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1)
224 usb_lock_device(udev);
226 udev->quirks |= USB_QUIRK_RESET;
228 udev->quirks &= ~USB_QUIRK_RESET;
229 usb_unlock_device(udev);
233 static DEVICE_ATTR(avoid_reset_quirk, S_IRUGO | S_IWUSR,
234 show_avoid_reset_quirk, set_avoid_reset_quirk);
237 show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
239 struct usb_device *udev;
241 udev = to_usb_device(dev);
242 return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
244 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
247 show_removable(struct device *dev, struct device_attribute *attr, char *buf)
249 struct usb_device *udev;
252 udev = to_usb_device(dev);
254 switch (udev->removable) {
255 case USB_DEVICE_REMOVABLE:
258 case USB_DEVICE_FIXED:
265 return sprintf(buf, "%s\n", state);
267 static DEVICE_ATTR(removable, S_IRUGO, show_removable, NULL);
270 show_ltm_capable(struct device *dev, struct device_attribute *attr, char *buf)
272 if (usb_device_supports_ltm(to_usb_device(dev)))
273 return sprintf(buf, "%s\n", "yes");
274 return sprintf(buf, "%s\n", "no");
276 static DEVICE_ATTR(ltm_capable, S_IRUGO, show_ltm_capable, NULL);
281 show_persist(struct device *dev, struct device_attribute *attr, char *buf)
283 struct usb_device *udev = to_usb_device(dev);
285 return sprintf(buf, "%d\n", udev->persist_enabled);
289 set_persist(struct device *dev, struct device_attribute *attr,
290 const char *buf, size_t count)
292 struct usb_device *udev = to_usb_device(dev);
295 /* Hubs are always enabled for USB_PERSIST */
296 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
299 if (sscanf(buf, "%d", &value) != 1)
302 usb_lock_device(udev);
303 udev->persist_enabled = !!value;
304 usb_unlock_device(udev);
308 static DEVICE_ATTR(persist, S_IRUGO | S_IWUSR, show_persist, set_persist);
310 static int add_persist_attributes(struct device *dev)
314 if (is_usb_device(dev)) {
315 struct usb_device *udev = to_usb_device(dev);
317 /* Hubs are automatically enabled for USB_PERSIST,
318 * no point in creating the attribute file.
320 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
321 rc = sysfs_add_file_to_group(&dev->kobj,
322 &dev_attr_persist.attr,
328 static void remove_persist_attributes(struct device *dev)
330 sysfs_remove_file_from_group(&dev->kobj,
331 &dev_attr_persist.attr,
336 #define add_persist_attributes(dev) 0
337 #define remove_persist_attributes(dev) do {} while (0)
339 #endif /* CONFIG_PM */
341 #ifdef CONFIG_PM_RUNTIME
344 show_connected_duration(struct device *dev, struct device_attribute *attr,
347 struct usb_device *udev = to_usb_device(dev);
349 return sprintf(buf, "%u\n",
350 jiffies_to_msecs(jiffies - udev->connect_time));
353 static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL);
356 * If the device is resumed, the last time the device was suspended has
357 * been pre-subtracted from active_duration. We add the current time to
358 * get the duration that the device was actually active.
360 * If the device is suspended, the active_duration is up-to-date.
363 show_active_duration(struct device *dev, struct device_attribute *attr,
366 struct usb_device *udev = to_usb_device(dev);
369 if (udev->state != USB_STATE_SUSPENDED)
370 duration = jiffies_to_msecs(jiffies + udev->active_duration);
372 duration = jiffies_to_msecs(udev->active_duration);
373 return sprintf(buf, "%u\n", duration);
376 static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
379 show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
381 return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000);
385 set_autosuspend(struct device *dev, struct device_attribute *attr,
386 const char *buf, size_t count)
390 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/1000 ||
391 value <= -INT_MAX/1000)
394 pm_runtime_set_autosuspend_delay(dev, value * 1000);
398 static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
399 show_autosuspend, set_autosuspend);
401 static const char on_string[] = "on";
402 static const char auto_string[] = "auto";
404 static void warn_level(void) {
405 static int level_warned;
409 printk(KERN_WARNING "WARNING! power/level is deprecated; "
410 "use power/control instead\n");
415 show_level(struct device *dev, struct device_attribute *attr, char *buf)
417 struct usb_device *udev = to_usb_device(dev);
418 const char *p = auto_string;
421 if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto)
423 return sprintf(buf, "%s\n", p);
427 set_level(struct device *dev, struct device_attribute *attr,
428 const char *buf, size_t count)
430 struct usb_device *udev = to_usb_device(dev);
436 cp = memchr(buf, '\n', count);
440 usb_lock_device(udev);
442 if (len == sizeof on_string - 1 &&
443 strncmp(buf, on_string, len) == 0)
444 usb_disable_autosuspend(udev);
446 else if (len == sizeof auto_string - 1 &&
447 strncmp(buf, auto_string, len) == 0)
448 usb_enable_autosuspend(udev);
453 usb_unlock_device(udev);
457 static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level);
460 show_usb2_hardware_lpm(struct device *dev, struct device_attribute *attr,
463 struct usb_device *udev = to_usb_device(dev);
466 if (udev->usb2_hw_lpm_enabled == 1)
471 return sprintf(buf, "%s\n", p);
475 set_usb2_hardware_lpm(struct device *dev, struct device_attribute *attr,
476 const char *buf, size_t count)
478 struct usb_device *udev = to_usb_device(dev);
482 usb_lock_device(udev);
484 ret = strtobool(buf, &value);
487 ret = usb_set_usb2_hardware_lpm(udev, value);
489 usb_unlock_device(udev);
497 static DEVICE_ATTR(usb2_hardware_lpm, S_IRUGO | S_IWUSR, show_usb2_hardware_lpm,
498 set_usb2_hardware_lpm);
500 static struct attribute *usb2_hardware_lpm_attr[] = {
501 &dev_attr_usb2_hardware_lpm.attr,
504 static struct attribute_group usb2_hardware_lpm_attr_group = {
505 .name = power_group_name,
506 .attrs = usb2_hardware_lpm_attr,
509 static struct attribute *power_attrs[] = {
510 &dev_attr_autosuspend.attr,
511 &dev_attr_level.attr,
512 &dev_attr_connected_duration.attr,
513 &dev_attr_active_duration.attr,
516 static struct attribute_group power_attr_group = {
517 .name = power_group_name,
518 .attrs = power_attrs,
521 static int add_power_attributes(struct device *dev)
525 if (is_usb_device(dev)) {
526 struct usb_device *udev = to_usb_device(dev);
527 rc = sysfs_merge_group(&dev->kobj, &power_attr_group);
528 if (udev->usb2_hw_lpm_capable == 1)
529 rc = sysfs_merge_group(&dev->kobj,
530 &usb2_hardware_lpm_attr_group);
536 static void remove_power_attributes(struct device *dev)
538 sysfs_unmerge_group(&dev->kobj, &usb2_hardware_lpm_attr_group);
539 sysfs_unmerge_group(&dev->kobj, &power_attr_group);
544 #define add_power_attributes(dev) 0
545 #define remove_power_attributes(dev) do {} while (0)
547 #endif /* CONFIG_PM_RUNTIME */
550 /* Descriptor fields */
551 #define usb_descriptor_attr_le16(field, format_string) \
553 show_##field(struct device *dev, struct device_attribute *attr, \
556 struct usb_device *udev; \
558 udev = to_usb_device(dev); \
559 return sprintf(buf, format_string, \
560 le16_to_cpu(udev->descriptor.field)); \
562 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
564 usb_descriptor_attr_le16(idVendor, "%04x\n")
565 usb_descriptor_attr_le16(idProduct, "%04x\n")
566 usb_descriptor_attr_le16(bcdDevice, "%04x\n")
568 #define usb_descriptor_attr(field, format_string) \
570 show_##field(struct device *dev, struct device_attribute *attr, \
573 struct usb_device *udev; \
575 udev = to_usb_device(dev); \
576 return sprintf(buf, format_string, udev->descriptor.field); \
578 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
580 usb_descriptor_attr(bDeviceClass, "%02x\n")
581 usb_descriptor_attr(bDeviceSubClass, "%02x\n")
582 usb_descriptor_attr(bDeviceProtocol, "%02x\n")
583 usb_descriptor_attr(bNumConfigurations, "%d\n")
584 usb_descriptor_attr(bMaxPacketSize0, "%d\n")
588 /* show if the device is authorized (1) or not (0) */
589 static ssize_t usb_dev_authorized_show(struct device *dev,
590 struct device_attribute *attr,
593 struct usb_device *usb_dev = to_usb_device(dev);
594 return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
599 * Authorize a device to be used in the system
601 * Writing a 0 deauthorizes the device, writing a 1 authorizes it.
603 static ssize_t usb_dev_authorized_store(struct device *dev,
604 struct device_attribute *attr,
605 const char *buf, size_t size)
608 struct usb_device *usb_dev = to_usb_device(dev);
610 result = sscanf(buf, "%u\n", &val);
614 result = usb_deauthorize_device(usb_dev);
616 result = usb_authorize_device(usb_dev);
617 return result < 0? result : size;
620 static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, 0644,
621 usb_dev_authorized_show, usb_dev_authorized_store);
623 /* "Safely remove a device" */
624 static ssize_t usb_remove_store(struct device *dev,
625 struct device_attribute *attr,
626 const char *buf, size_t count)
628 struct usb_device *udev = to_usb_device(dev);
631 usb_lock_device(udev);
632 if (udev->state != USB_STATE_NOTATTACHED) {
634 /* To avoid races, first unconfigure and then remove */
635 usb_set_configuration(udev, -1);
636 rc = usb_remove_device(udev);
640 usb_unlock_device(udev);
643 static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, usb_remove_store);
646 static struct attribute *dev_attrs[] = {
647 /* current configuration's attributes */
648 &dev_attr_configuration.attr,
649 &dev_attr_bNumInterfaces.attr,
650 &dev_attr_bConfigurationValue.attr,
651 &dev_attr_bmAttributes.attr,
652 &dev_attr_bMaxPower.attr,
653 /* device attributes */
654 &dev_attr_urbnum.attr,
655 &dev_attr_idVendor.attr,
656 &dev_attr_idProduct.attr,
657 &dev_attr_bcdDevice.attr,
658 &dev_attr_bDeviceClass.attr,
659 &dev_attr_bDeviceSubClass.attr,
660 &dev_attr_bDeviceProtocol.attr,
661 &dev_attr_bNumConfigurations.attr,
662 &dev_attr_bMaxPacketSize0.attr,
663 &dev_attr_speed.attr,
664 &dev_attr_busnum.attr,
665 &dev_attr_devnum.attr,
666 &dev_attr_devpath.attr,
667 &dev_attr_version.attr,
668 &dev_attr_maxchild.attr,
669 &dev_attr_quirks.attr,
670 &dev_attr_avoid_reset_quirk.attr,
671 &dev_attr_authorized.attr,
672 &dev_attr_remove.attr,
673 &dev_attr_removable.attr,
674 &dev_attr_ltm_capable.attr,
677 static struct attribute_group dev_attr_grp = {
681 /* When modifying this list, be sure to modify dev_string_attrs_are_visible()
684 static struct attribute *dev_string_attrs[] = {
685 &dev_attr_manufacturer.attr,
686 &dev_attr_product.attr,
687 &dev_attr_serial.attr,
691 static umode_t dev_string_attrs_are_visible(struct kobject *kobj,
692 struct attribute *a, int n)
694 struct device *dev = container_of(kobj, struct device, kobj);
695 struct usb_device *udev = to_usb_device(dev);
697 if (a == &dev_attr_manufacturer.attr) {
698 if (udev->manufacturer == NULL)
700 } else if (a == &dev_attr_product.attr) {
701 if (udev->product == NULL)
703 } else if (a == &dev_attr_serial.attr) {
704 if (udev->serial == NULL)
710 static struct attribute_group dev_string_attr_grp = {
711 .attrs = dev_string_attrs,
712 .is_visible = dev_string_attrs_are_visible,
715 const struct attribute_group *usb_device_groups[] = {
717 &dev_string_attr_grp,
721 /* Binary descriptors */
724 read_descriptors(struct file *filp, struct kobject *kobj,
725 struct bin_attribute *attr,
726 char *buf, loff_t off, size_t count)
728 struct device *dev = container_of(kobj, struct device, kobj);
729 struct usb_device *udev = to_usb_device(dev);
730 size_t nleft = count;
735 /* The binary attribute begins with the device descriptor.
736 * Following that are the raw descriptor entries for all the
737 * configurations (config plus subsidiary descriptors).
739 for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
740 nleft > 0; ++cfgno) {
742 src = &udev->descriptor;
743 srclen = sizeof(struct usb_device_descriptor);
745 src = udev->rawdescriptors[cfgno];
746 srclen = __le16_to_cpu(udev->config[cfgno].desc.
750 n = min(nleft, srclen - (size_t) off);
751 memcpy(buf, src + off, n);
759 return count - nleft;
762 static struct bin_attribute dev_bin_attr_descriptors = {
763 .attr = {.name = "descriptors", .mode = 0444},
764 .read = read_descriptors,
765 .size = 18 + 65535, /* dev descr + max-size raw descriptor */
768 int usb_create_sysfs_dev_files(struct usb_device *udev)
770 struct device *dev = &udev->dev;
773 retval = device_create_bin_file(dev, &dev_bin_attr_descriptors);
777 retval = add_persist_attributes(dev);
781 retval = add_power_attributes(dev);
786 usb_remove_sysfs_dev_files(udev);
790 void usb_remove_sysfs_dev_files(struct usb_device *udev)
792 struct device *dev = &udev->dev;
794 remove_power_attributes(dev);
795 remove_persist_attributes(dev);
796 device_remove_bin_file(dev, &dev_bin_attr_descriptors);
799 /* Interface Accociation Descriptor fields */
800 #define usb_intf_assoc_attr(field, format_string) \
802 show_iad_##field(struct device *dev, struct device_attribute *attr, \
805 struct usb_interface *intf = to_usb_interface(dev); \
807 return sprintf(buf, format_string, \
808 intf->intf_assoc->field); \
810 static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL);
812 usb_intf_assoc_attr(bFirstInterface, "%02x\n")
813 usb_intf_assoc_attr(bInterfaceCount, "%02d\n")
814 usb_intf_assoc_attr(bFunctionClass, "%02x\n")
815 usb_intf_assoc_attr(bFunctionSubClass, "%02x\n")
816 usb_intf_assoc_attr(bFunctionProtocol, "%02x\n")
818 /* Interface fields */
819 #define usb_intf_attr(field, format_string) \
821 show_##field(struct device *dev, struct device_attribute *attr, \
824 struct usb_interface *intf = to_usb_interface(dev); \
826 return sprintf(buf, format_string, \
827 intf->cur_altsetting->desc.field); \
829 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
831 usb_intf_attr(bInterfaceNumber, "%02x\n")
832 usb_intf_attr(bAlternateSetting, "%2d\n")
833 usb_intf_attr(bNumEndpoints, "%02x\n")
834 usb_intf_attr(bInterfaceClass, "%02x\n")
835 usb_intf_attr(bInterfaceSubClass, "%02x\n")
836 usb_intf_attr(bInterfaceProtocol, "%02x\n")
838 static ssize_t show_interface_string(struct device *dev,
839 struct device_attribute *attr, char *buf)
841 struct usb_interface *intf;
844 intf = to_usb_interface(dev);
845 string = intf->cur_altsetting->string;
846 barrier(); /* The altsetting might change! */
850 return sprintf(buf, "%s\n", string);
852 static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL);
854 static ssize_t show_modalias(struct device *dev,
855 struct device_attribute *attr, char *buf)
857 struct usb_interface *intf;
858 struct usb_device *udev;
859 struct usb_host_interface *alt;
861 intf = to_usb_interface(dev);
862 udev = interface_to_usbdev(intf);
863 alt = intf->cur_altsetting;
865 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
866 "ic%02Xisc%02Xip%02Xin%02X\n",
867 le16_to_cpu(udev->descriptor.idVendor),
868 le16_to_cpu(udev->descriptor.idProduct),
869 le16_to_cpu(udev->descriptor.bcdDevice),
870 udev->descriptor.bDeviceClass,
871 udev->descriptor.bDeviceSubClass,
872 udev->descriptor.bDeviceProtocol,
873 alt->desc.bInterfaceClass,
874 alt->desc.bInterfaceSubClass,
875 alt->desc.bInterfaceProtocol,
876 alt->desc.bInterfaceNumber);
878 static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
880 static ssize_t show_supports_autosuspend(struct device *dev,
881 struct device_attribute *attr, char *buf)
883 struct usb_interface *intf;
884 struct usb_device *udev;
887 intf = to_usb_interface(dev);
888 udev = interface_to_usbdev(intf);
890 usb_lock_device(udev);
891 /* Devices will be autosuspended even when an interface isn't claimed */
892 if (!intf->dev.driver ||
893 to_usb_driver(intf->dev.driver)->supports_autosuspend)
894 ret = sprintf(buf, "%u\n", 1);
896 ret = sprintf(buf, "%u\n", 0);
897 usb_unlock_device(udev);
901 static DEVICE_ATTR(supports_autosuspend, S_IRUGO, show_supports_autosuspend, NULL);
903 static struct attribute *intf_attrs[] = {
904 &dev_attr_bInterfaceNumber.attr,
905 &dev_attr_bAlternateSetting.attr,
906 &dev_attr_bNumEndpoints.attr,
907 &dev_attr_bInterfaceClass.attr,
908 &dev_attr_bInterfaceSubClass.attr,
909 &dev_attr_bInterfaceProtocol.attr,
910 &dev_attr_modalias.attr,
911 &dev_attr_supports_autosuspend.attr,
914 static struct attribute_group intf_attr_grp = {
918 static struct attribute *intf_assoc_attrs[] = {
919 &dev_attr_iad_bFirstInterface.attr,
920 &dev_attr_iad_bInterfaceCount.attr,
921 &dev_attr_iad_bFunctionClass.attr,
922 &dev_attr_iad_bFunctionSubClass.attr,
923 &dev_attr_iad_bFunctionProtocol.attr,
927 static umode_t intf_assoc_attrs_are_visible(struct kobject *kobj,
928 struct attribute *a, int n)
930 struct device *dev = container_of(kobj, struct device, kobj);
931 struct usb_interface *intf = to_usb_interface(dev);
933 if (intf->intf_assoc == NULL)
938 static struct attribute_group intf_assoc_attr_grp = {
939 .attrs = intf_assoc_attrs,
940 .is_visible = intf_assoc_attrs_are_visible,
943 const struct attribute_group *usb_interface_groups[] = {
945 &intf_assoc_attr_grp,
949 void usb_create_sysfs_intf_files(struct usb_interface *intf)
951 struct usb_device *udev = interface_to_usbdev(intf);
952 struct usb_host_interface *alt = intf->cur_altsetting;
954 if (intf->sysfs_files_created || intf->unregistering)
957 if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
958 alt->string = usb_cache_string(udev, alt->desc.iInterface);
959 if (alt->string && device_create_file(&intf->dev, &dev_attr_interface))
960 ; /* We don't actually care if the function fails. */
961 intf->sysfs_files_created = 1;
964 void usb_remove_sysfs_intf_files(struct usb_interface *intf)
966 if (!intf->sysfs_files_created)
969 device_remove_file(&intf->dev, &dev_attr_interface);
970 intf->sysfs_files_created = 0;