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, multiplier, 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 * multiplier); \
36 #define usb_actconfig_attr(field, multiplier, format_string) \
37 usb_actconfig_show(field, multiplier, format_string) \
38 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
40 usb_actconfig_attr(bNumInterfaces, 1, "%2d\n")
41 usb_actconfig_attr(bmAttributes, 1, "%2x\n")
42 usb_actconfig_attr(bMaxPower, 2, "%3dmA\n")
44 static ssize_t show_configuration_string(struct device *dev,
45 struct device_attribute *attr, char *buf)
47 struct usb_device *udev;
48 struct usb_host_config *actconfig;
50 udev = to_usb_device(dev);
51 actconfig = udev->actconfig;
52 if ((!actconfig) || (!actconfig->string))
54 return sprintf(buf, "%s\n", actconfig->string);
56 static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
58 /* configuration value is always present, and r/w */
59 usb_actconfig_show(bConfigurationValue, 1, "%u\n");
62 set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
63 const char *buf, size_t count)
65 struct usb_device *udev = to_usb_device(dev);
68 if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
70 usb_lock_device(udev);
71 value = usb_set_configuration(udev, config);
72 usb_unlock_device(udev);
73 return (value < 0) ? value : count;
76 static DEVICE_ATTR_IGNORE_LOCKDEP(bConfigurationValue, S_IRUGO | S_IWUSR,
77 show_bConfigurationValue, set_bConfigurationValue);
80 #define usb_string_attr(name) \
81 static ssize_t show_##name(struct device *dev, \
82 struct device_attribute *attr, char *buf) \
84 struct usb_device *udev; \
87 udev = to_usb_device(dev); \
88 usb_lock_device(udev); \
89 retval = sprintf(buf, "%s\n", udev->name); \
90 usb_unlock_device(udev); \
93 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
95 usb_string_attr(product);
96 usb_string_attr(manufacturer);
97 usb_string_attr(serial);
100 show_speed(struct device *dev, struct device_attribute *attr, char *buf)
102 struct usb_device *udev;
105 udev = to_usb_device(dev);
107 switch (udev->speed) {
111 case USB_SPEED_UNKNOWN:
118 case USB_SPEED_WIRELESS:
121 case USB_SPEED_SUPER:
127 return sprintf(buf, "%s\n", speed);
129 static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL);
132 show_busnum(struct device *dev, struct device_attribute *attr, char *buf)
134 struct usb_device *udev;
136 udev = to_usb_device(dev);
137 return sprintf(buf, "%d\n", udev->bus->busnum);
139 static DEVICE_ATTR(busnum, S_IRUGO, show_busnum, NULL);
142 show_devnum(struct device *dev, struct device_attribute *attr, char *buf)
144 struct usb_device *udev;
146 udev = to_usb_device(dev);
147 return sprintf(buf, "%d\n", udev->devnum);
149 static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL);
152 show_devpath(struct device *dev, struct device_attribute *attr, char *buf)
154 struct usb_device *udev;
156 udev = to_usb_device(dev);
157 return sprintf(buf, "%s\n", udev->devpath);
159 static DEVICE_ATTR(devpath, S_IRUGO, show_devpath, NULL);
162 show_version(struct device *dev, struct device_attribute *attr, char *buf)
164 struct usb_device *udev;
167 udev = to_usb_device(dev);
168 bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB);
169 return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff);
171 static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
174 show_maxchild(struct device *dev, struct device_attribute *attr, char *buf)
176 struct usb_device *udev;
178 udev = to_usb_device(dev);
179 return sprintf(buf, "%d\n", udev->maxchild);
181 static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
184 show_quirks(struct device *dev, struct device_attribute *attr, char *buf)
186 struct usb_device *udev;
188 udev = to_usb_device(dev);
189 return sprintf(buf, "0x%x\n", udev->quirks);
191 static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL);
194 show_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, char *buf)
196 struct usb_device *udev;
198 udev = to_usb_device(dev);
199 return sprintf(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET_MORPHS));
203 set_avoid_reset_quirk(struct device *dev, struct device_attribute *attr,
204 const char *buf, size_t count)
206 struct usb_device *udev = to_usb_device(dev);
209 if (sscanf(buf, "%d", &config) != 1 || config < 0 || config > 1)
211 usb_lock_device(udev);
213 udev->quirks |= USB_QUIRK_RESET_MORPHS;
215 udev->quirks &= ~USB_QUIRK_RESET_MORPHS;
216 usb_unlock_device(udev);
220 static DEVICE_ATTR(avoid_reset_quirk, S_IRUGO | S_IWUSR,
221 show_avoid_reset_quirk, set_avoid_reset_quirk);
224 show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
226 struct usb_device *udev;
228 udev = to_usb_device(dev);
229 return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
231 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
234 show_removable(struct device *dev, struct device_attribute *attr, char *buf)
236 struct usb_device *udev;
239 udev = to_usb_device(dev);
241 switch (udev->removable) {
242 case USB_DEVICE_REMOVABLE:
245 case USB_DEVICE_FIXED:
252 return sprintf(buf, "%s\n", state);
254 static DEVICE_ATTR(removable, S_IRUGO, show_removable, NULL);
257 show_ltm_capable(struct device *dev, struct device_attribute *attr, char *buf)
259 if (usb_device_supports_ltm(to_usb_device(dev)))
260 return sprintf(buf, "%s\n", "yes");
261 return sprintf(buf, "%s\n", "no");
263 static DEVICE_ATTR(ltm_capable, S_IRUGO, show_ltm_capable, NULL);
268 show_persist(struct device *dev, struct device_attribute *attr, char *buf)
270 struct usb_device *udev = to_usb_device(dev);
272 return sprintf(buf, "%d\n", udev->persist_enabled);
276 set_persist(struct device *dev, struct device_attribute *attr,
277 const char *buf, size_t count)
279 struct usb_device *udev = to_usb_device(dev);
282 /* Hubs are always enabled for USB_PERSIST */
283 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
286 if (sscanf(buf, "%d", &value) != 1)
289 usb_lock_device(udev);
290 udev->persist_enabled = !!value;
291 usb_unlock_device(udev);
295 static DEVICE_ATTR(persist, S_IRUGO | S_IWUSR, show_persist, set_persist);
297 static int add_persist_attributes(struct device *dev)
301 if (is_usb_device(dev)) {
302 struct usb_device *udev = to_usb_device(dev);
304 /* Hubs are automatically enabled for USB_PERSIST,
305 * no point in creating the attribute file.
307 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
308 rc = sysfs_add_file_to_group(&dev->kobj,
309 &dev_attr_persist.attr,
315 static void remove_persist_attributes(struct device *dev)
317 sysfs_remove_file_from_group(&dev->kobj,
318 &dev_attr_persist.attr,
323 #define add_persist_attributes(dev) 0
324 #define remove_persist_attributes(dev) do {} while (0)
326 #endif /* CONFIG_PM */
328 #ifdef CONFIG_USB_SUSPEND
331 show_connected_duration(struct device *dev, struct device_attribute *attr,
334 struct usb_device *udev = to_usb_device(dev);
336 return sprintf(buf, "%u\n",
337 jiffies_to_msecs(jiffies - udev->connect_time));
340 static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL);
343 * If the device is resumed, the last time the device was suspended has
344 * been pre-subtracted from active_duration. We add the current time to
345 * get the duration that the device was actually active.
347 * If the device is suspended, the active_duration is up-to-date.
350 show_active_duration(struct device *dev, struct device_attribute *attr,
353 struct usb_device *udev = to_usb_device(dev);
356 if (udev->state != USB_STATE_SUSPENDED)
357 duration = jiffies_to_msecs(jiffies + udev->active_duration);
359 duration = jiffies_to_msecs(udev->active_duration);
360 return sprintf(buf, "%u\n", duration);
363 static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
366 show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
368 return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000);
372 set_autosuspend(struct device *dev, struct device_attribute *attr,
373 const char *buf, size_t count)
377 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/1000 ||
378 value <= -INT_MAX/1000)
381 pm_runtime_set_autosuspend_delay(dev, value * 1000);
385 static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
386 show_autosuspend, set_autosuspend);
388 static const char on_string[] = "on";
389 static const char auto_string[] = "auto";
391 static void warn_level(void) {
392 static int level_warned;
396 printk(KERN_WARNING "WARNING! power/level is deprecated; "
397 "use power/control instead\n");
402 show_level(struct device *dev, struct device_attribute *attr, char *buf)
404 struct usb_device *udev = to_usb_device(dev);
405 const char *p = auto_string;
408 if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto)
410 return sprintf(buf, "%s\n", p);
414 set_level(struct device *dev, struct device_attribute *attr,
415 const char *buf, size_t count)
417 struct usb_device *udev = to_usb_device(dev);
423 cp = memchr(buf, '\n', count);
427 usb_lock_device(udev);
429 if (len == sizeof on_string - 1 &&
430 strncmp(buf, on_string, len) == 0)
431 usb_disable_autosuspend(udev);
433 else if (len == sizeof auto_string - 1 &&
434 strncmp(buf, auto_string, len) == 0)
435 usb_enable_autosuspend(udev);
440 usb_unlock_device(udev);
444 static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level);
447 show_usb2_hardware_lpm(struct device *dev, struct device_attribute *attr,
450 struct usb_device *udev = to_usb_device(dev);
453 if (udev->usb2_hw_lpm_enabled == 1)
458 return sprintf(buf, "%s\n", p);
462 set_usb2_hardware_lpm(struct device *dev, struct device_attribute *attr,
463 const char *buf, size_t count)
465 struct usb_device *udev = to_usb_device(dev);
469 usb_lock_device(udev);
471 ret = strtobool(buf, &value);
474 ret = usb_set_usb2_hardware_lpm(udev, value);
476 usb_unlock_device(udev);
484 static DEVICE_ATTR(usb2_hardware_lpm, S_IRUGO | S_IWUSR, show_usb2_hardware_lpm,
485 set_usb2_hardware_lpm);
487 static struct attribute *usb2_hardware_lpm_attr[] = {
488 &dev_attr_usb2_hardware_lpm.attr,
491 static struct attribute_group usb2_hardware_lpm_attr_group = {
492 .name = power_group_name,
493 .attrs = usb2_hardware_lpm_attr,
496 static struct attribute *power_attrs[] = {
497 &dev_attr_autosuspend.attr,
498 &dev_attr_level.attr,
499 &dev_attr_connected_duration.attr,
500 &dev_attr_active_duration.attr,
503 static struct attribute_group power_attr_group = {
504 .name = power_group_name,
505 .attrs = power_attrs,
508 static int add_power_attributes(struct device *dev)
512 if (is_usb_device(dev)) {
513 struct usb_device *udev = to_usb_device(dev);
514 rc = sysfs_merge_group(&dev->kobj, &power_attr_group);
515 if (udev->usb2_hw_lpm_capable == 1)
516 rc = sysfs_merge_group(&dev->kobj,
517 &usb2_hardware_lpm_attr_group);
523 static void remove_power_attributes(struct device *dev)
525 sysfs_unmerge_group(&dev->kobj, &usb2_hardware_lpm_attr_group);
526 sysfs_unmerge_group(&dev->kobj, &power_attr_group);
531 #define add_power_attributes(dev) 0
532 #define remove_power_attributes(dev) do {} while (0)
534 #endif /* CONFIG_USB_SUSPEND */
537 /* Descriptor fields */
538 #define usb_descriptor_attr_le16(field, format_string) \
540 show_##field(struct device *dev, struct device_attribute *attr, \
543 struct usb_device *udev; \
545 udev = to_usb_device(dev); \
546 return sprintf(buf, format_string, \
547 le16_to_cpu(udev->descriptor.field)); \
549 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
551 usb_descriptor_attr_le16(idVendor, "%04x\n")
552 usb_descriptor_attr_le16(idProduct, "%04x\n")
553 usb_descriptor_attr_le16(bcdDevice, "%04x\n")
555 #define usb_descriptor_attr(field, format_string) \
557 show_##field(struct device *dev, struct device_attribute *attr, \
560 struct usb_device *udev; \
562 udev = to_usb_device(dev); \
563 return sprintf(buf, format_string, udev->descriptor.field); \
565 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
567 usb_descriptor_attr(bDeviceClass, "%02x\n")
568 usb_descriptor_attr(bDeviceSubClass, "%02x\n")
569 usb_descriptor_attr(bDeviceProtocol, "%02x\n")
570 usb_descriptor_attr(bNumConfigurations, "%d\n")
571 usb_descriptor_attr(bMaxPacketSize0, "%d\n")
575 /* show if the device is authorized (1) or not (0) */
576 static ssize_t usb_dev_authorized_show(struct device *dev,
577 struct device_attribute *attr,
580 struct usb_device *usb_dev = to_usb_device(dev);
581 return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
586 * Authorize a device to be used in the system
588 * Writing a 0 deauthorizes the device, writing a 1 authorizes it.
590 static ssize_t usb_dev_authorized_store(struct device *dev,
591 struct device_attribute *attr,
592 const char *buf, size_t size)
595 struct usb_device *usb_dev = to_usb_device(dev);
597 result = sscanf(buf, "%u\n", &val);
601 result = usb_deauthorize_device(usb_dev);
603 result = usb_authorize_device(usb_dev);
604 return result < 0? result : size;
607 static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, 0644,
608 usb_dev_authorized_show, usb_dev_authorized_store);
610 /* "Safely remove a device" */
611 static ssize_t usb_remove_store(struct device *dev,
612 struct device_attribute *attr,
613 const char *buf, size_t count)
615 struct usb_device *udev = to_usb_device(dev);
618 usb_lock_device(udev);
619 if (udev->state != USB_STATE_NOTATTACHED) {
621 /* To avoid races, first unconfigure and then remove */
622 usb_set_configuration(udev, -1);
623 rc = usb_remove_device(udev);
627 usb_unlock_device(udev);
630 static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, usb_remove_store);
633 static struct attribute *dev_attrs[] = {
634 /* current configuration's attributes */
635 &dev_attr_configuration.attr,
636 &dev_attr_bNumInterfaces.attr,
637 &dev_attr_bConfigurationValue.attr,
638 &dev_attr_bmAttributes.attr,
639 &dev_attr_bMaxPower.attr,
640 /* device attributes */
641 &dev_attr_urbnum.attr,
642 &dev_attr_idVendor.attr,
643 &dev_attr_idProduct.attr,
644 &dev_attr_bcdDevice.attr,
645 &dev_attr_bDeviceClass.attr,
646 &dev_attr_bDeviceSubClass.attr,
647 &dev_attr_bDeviceProtocol.attr,
648 &dev_attr_bNumConfigurations.attr,
649 &dev_attr_bMaxPacketSize0.attr,
650 &dev_attr_speed.attr,
651 &dev_attr_busnum.attr,
652 &dev_attr_devnum.attr,
653 &dev_attr_devpath.attr,
654 &dev_attr_version.attr,
655 &dev_attr_maxchild.attr,
656 &dev_attr_quirks.attr,
657 &dev_attr_avoid_reset_quirk.attr,
658 &dev_attr_authorized.attr,
659 &dev_attr_remove.attr,
660 &dev_attr_removable.attr,
661 &dev_attr_ltm_capable.attr,
664 static struct attribute_group dev_attr_grp = {
668 /* When modifying this list, be sure to modify dev_string_attrs_are_visible()
671 static struct attribute *dev_string_attrs[] = {
672 &dev_attr_manufacturer.attr,
673 &dev_attr_product.attr,
674 &dev_attr_serial.attr,
678 static umode_t dev_string_attrs_are_visible(struct kobject *kobj,
679 struct attribute *a, int n)
681 struct device *dev = container_of(kobj, struct device, kobj);
682 struct usb_device *udev = to_usb_device(dev);
684 if (a == &dev_attr_manufacturer.attr) {
685 if (udev->manufacturer == NULL)
687 } else if (a == &dev_attr_product.attr) {
688 if (udev->product == NULL)
690 } else if (a == &dev_attr_serial.attr) {
691 if (udev->serial == NULL)
697 static struct attribute_group dev_string_attr_grp = {
698 .attrs = dev_string_attrs,
699 .is_visible = dev_string_attrs_are_visible,
702 const struct attribute_group *usb_device_groups[] = {
704 &dev_string_attr_grp,
708 /* Binary descriptors */
711 read_descriptors(struct file *filp, struct kobject *kobj,
712 struct bin_attribute *attr,
713 char *buf, loff_t off, size_t count)
715 struct device *dev = container_of(kobj, struct device, kobj);
716 struct usb_device *udev = to_usb_device(dev);
717 size_t nleft = count;
722 /* The binary attribute begins with the device descriptor.
723 * Following that are the raw descriptor entries for all the
724 * configurations (config plus subsidiary descriptors).
726 for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
727 nleft > 0; ++cfgno) {
729 src = &udev->descriptor;
730 srclen = sizeof(struct usb_device_descriptor);
732 src = udev->rawdescriptors[cfgno];
733 srclen = __le16_to_cpu(udev->config[cfgno].desc.
737 n = min(nleft, srclen - (size_t) off);
738 memcpy(buf, src + off, n);
746 return count - nleft;
749 static struct bin_attribute dev_bin_attr_descriptors = {
750 .attr = {.name = "descriptors", .mode = 0444},
751 .read = read_descriptors,
752 .size = 18 + 65535, /* dev descr + max-size raw descriptor */
755 int usb_create_sysfs_dev_files(struct usb_device *udev)
757 struct device *dev = &udev->dev;
760 retval = device_create_bin_file(dev, &dev_bin_attr_descriptors);
764 retval = add_persist_attributes(dev);
768 retval = add_power_attributes(dev);
773 usb_remove_sysfs_dev_files(udev);
777 void usb_remove_sysfs_dev_files(struct usb_device *udev)
779 struct device *dev = &udev->dev;
781 remove_power_attributes(dev);
782 remove_persist_attributes(dev);
783 device_remove_bin_file(dev, &dev_bin_attr_descriptors);
786 /* Interface Accociation Descriptor fields */
787 #define usb_intf_assoc_attr(field, format_string) \
789 show_iad_##field(struct device *dev, struct device_attribute *attr, \
792 struct usb_interface *intf = to_usb_interface(dev); \
794 return sprintf(buf, format_string, \
795 intf->intf_assoc->field); \
797 static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL);
799 usb_intf_assoc_attr(bFirstInterface, "%02x\n")
800 usb_intf_assoc_attr(bInterfaceCount, "%02d\n")
801 usb_intf_assoc_attr(bFunctionClass, "%02x\n")
802 usb_intf_assoc_attr(bFunctionSubClass, "%02x\n")
803 usb_intf_assoc_attr(bFunctionProtocol, "%02x\n")
805 /* Interface fields */
806 #define usb_intf_attr(field, format_string) \
808 show_##field(struct device *dev, struct device_attribute *attr, \
811 struct usb_interface *intf = to_usb_interface(dev); \
813 return sprintf(buf, format_string, \
814 intf->cur_altsetting->desc.field); \
816 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
818 usb_intf_attr(bInterfaceNumber, "%02x\n")
819 usb_intf_attr(bAlternateSetting, "%2d\n")
820 usb_intf_attr(bNumEndpoints, "%02x\n")
821 usb_intf_attr(bInterfaceClass, "%02x\n")
822 usb_intf_attr(bInterfaceSubClass, "%02x\n")
823 usb_intf_attr(bInterfaceProtocol, "%02x\n")
825 static ssize_t show_interface_string(struct device *dev,
826 struct device_attribute *attr, char *buf)
828 struct usb_interface *intf;
831 intf = to_usb_interface(dev);
832 string = intf->cur_altsetting->string;
833 barrier(); /* The altsetting might change! */
837 return sprintf(buf, "%s\n", string);
839 static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL);
841 static ssize_t show_modalias(struct device *dev,
842 struct device_attribute *attr, char *buf)
844 struct usb_interface *intf;
845 struct usb_device *udev;
846 struct usb_host_interface *alt;
848 intf = to_usb_interface(dev);
849 udev = interface_to_usbdev(intf);
850 alt = intf->cur_altsetting;
852 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
853 "ic%02Xisc%02Xip%02Xin%02X\n",
854 le16_to_cpu(udev->descriptor.idVendor),
855 le16_to_cpu(udev->descriptor.idProduct),
856 le16_to_cpu(udev->descriptor.bcdDevice),
857 udev->descriptor.bDeviceClass,
858 udev->descriptor.bDeviceSubClass,
859 udev->descriptor.bDeviceProtocol,
860 alt->desc.bInterfaceClass,
861 alt->desc.bInterfaceSubClass,
862 alt->desc.bInterfaceProtocol,
863 alt->desc.bInterfaceNumber);
865 static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
867 static ssize_t show_supports_autosuspend(struct device *dev,
868 struct device_attribute *attr, char *buf)
870 struct usb_interface *intf;
871 struct usb_device *udev;
874 intf = to_usb_interface(dev);
875 udev = interface_to_usbdev(intf);
877 usb_lock_device(udev);
878 /* Devices will be autosuspended even when an interface isn't claimed */
879 if (!intf->dev.driver ||
880 to_usb_driver(intf->dev.driver)->supports_autosuspend)
881 ret = sprintf(buf, "%u\n", 1);
883 ret = sprintf(buf, "%u\n", 0);
884 usb_unlock_device(udev);
888 static DEVICE_ATTR(supports_autosuspend, S_IRUGO, show_supports_autosuspend, NULL);
890 static struct attribute *intf_attrs[] = {
891 &dev_attr_bInterfaceNumber.attr,
892 &dev_attr_bAlternateSetting.attr,
893 &dev_attr_bNumEndpoints.attr,
894 &dev_attr_bInterfaceClass.attr,
895 &dev_attr_bInterfaceSubClass.attr,
896 &dev_attr_bInterfaceProtocol.attr,
897 &dev_attr_modalias.attr,
898 &dev_attr_supports_autosuspend.attr,
901 static struct attribute_group intf_attr_grp = {
905 static struct attribute *intf_assoc_attrs[] = {
906 &dev_attr_iad_bFirstInterface.attr,
907 &dev_attr_iad_bInterfaceCount.attr,
908 &dev_attr_iad_bFunctionClass.attr,
909 &dev_attr_iad_bFunctionSubClass.attr,
910 &dev_attr_iad_bFunctionProtocol.attr,
914 static umode_t intf_assoc_attrs_are_visible(struct kobject *kobj,
915 struct attribute *a, int n)
917 struct device *dev = container_of(kobj, struct device, kobj);
918 struct usb_interface *intf = to_usb_interface(dev);
920 if (intf->intf_assoc == NULL)
925 static struct attribute_group intf_assoc_attr_grp = {
926 .attrs = intf_assoc_attrs,
927 .is_visible = intf_assoc_attrs_are_visible,
930 const struct attribute_group *usb_interface_groups[] = {
932 &intf_assoc_attr_grp,
936 void usb_create_sysfs_intf_files(struct usb_interface *intf)
938 struct usb_device *udev = interface_to_usbdev(intf);
939 struct usb_host_interface *alt = intf->cur_altsetting;
941 if (intf->sysfs_files_created || intf->unregistering)
944 if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
945 alt->string = usb_cache_string(udev, alt->desc.iInterface);
946 if (alt->string && device_create_file(&intf->dev, &dev_attr_interface))
947 ; /* We don't actually care if the function fails. */
948 intf->sysfs_files_created = 1;
951 void usb_remove_sysfs_intf_files(struct usb_interface *intf)
953 if (!intf->sysfs_files_created)
956 device_remove_file(&intf->dev, &dev_attr_interface);
957 intf->sysfs_files_created = 0;