blob: 4cca77cf0c4875aa166e06fe64cdad15133dd65d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/usb/core/sysfs.c
3 *
4 * (C) Copyright 2002 David Brownell
5 * (C) Copyright 2002,2004 Greg Kroah-Hartman
6 * (C) Copyright 2002,2004 IBM Corp.
7 *
8 * All of the sysfs file attributes for usb devices and interfaces.
9 *
10 */
11
12
13#include <linux/config.h>
14#include <linux/kernel.h>
15
16#ifdef CONFIG_USB_DEBUG
17 #define DEBUG
18#else
19 #undef DEBUG
20#endif
21#include <linux/usb.h>
22
23#include "usb.h"
24
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070025/* endpoint stuff */
Alan Sternbe69e5b2005-10-25 15:56:06 -040026struct ep_object {
27 struct usb_endpoint_descriptor *desc;
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070028 struct usb_device *udev;
Alan Sternbe69e5b2005-10-25 15:56:06 -040029 struct kobject kobj;
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070030};
Alan Sternbe69e5b2005-10-25 15:56:06 -040031#define to_ep_object(_kobj) \
32 container_of(_kobj, struct ep_object, kobj)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070033
Alan Sternbe69e5b2005-10-25 15:56:06 -040034struct ep_attribute {
35 struct attribute attr;
36 ssize_t (*show)(struct usb_device *,
37 struct usb_endpoint_descriptor *, char *);
38};
39#define to_ep_attribute(_attr) \
40 container_of(_attr, struct ep_attribute, attr)
41
42#define EP_ATTR(_name) \
43struct ep_attribute ep_##_name = { \
44 .attr = {.name = #_name, .owner = THIS_MODULE, \
45 .mode = S_IRUGO}, \
46 .show = show_ep_##_name}
47
48#define usb_ep_attr(field, format_string) \
49static ssize_t show_ep_##field(struct usb_device *udev, \
50 struct usb_endpoint_descriptor *desc, \
51 char *buf) \
52{ \
53 return sprintf(buf, format_string, desc->field); \
54} \
55static EP_ATTR(field);
56
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070057usb_ep_attr(bLength, "%02x\n")
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070058usb_ep_attr(bEndpointAddress, "%02x\n")
59usb_ep_attr(bmAttributes, "%02x\n")
60usb_ep_attr(bInterval, "%02x\n")
61
Alan Sternbe69e5b2005-10-25 15:56:06 -040062static ssize_t show_ep_wMaxPacketSize(struct usb_device *udev,
63 struct usb_endpoint_descriptor *desc, char *buf)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070064{
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070065 return sprintf(buf, "%04x\n",
Alan Sternbe69e5b2005-10-25 15:56:06 -040066 le16_to_cpu(desc->wMaxPacketSize) & 0x07ff);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070067}
Alan Sternbe69e5b2005-10-25 15:56:06 -040068static EP_ATTR(wMaxPacketSize);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070069
Alan Sternbe69e5b2005-10-25 15:56:06 -040070static ssize_t show_ep_type(struct usb_device *udev,
71 struct usb_endpoint_descriptor *desc, char *buf)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070072{
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070073 char *type = "unknown";
74
Alan Sternbe69e5b2005-10-25 15:56:06 -040075 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070076 case USB_ENDPOINT_XFER_CONTROL:
77 type = "Control";
78 break;
79 case USB_ENDPOINT_XFER_ISOC:
80 type = "Isoc";
81 break;
82 case USB_ENDPOINT_XFER_BULK:
83 type = "Bulk";
84 break;
85 case USB_ENDPOINT_XFER_INT:
86 type = "Interrupt";
87 break;
88 }
89 return sprintf(buf, "%s\n", type);
90}
Alan Sternbe69e5b2005-10-25 15:56:06 -040091static EP_ATTR(type);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070092
Alan Sternbe69e5b2005-10-25 15:56:06 -040093static ssize_t show_ep_interval(struct usb_device *udev,
94 struct usb_endpoint_descriptor *desc, char *buf)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070095{
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -070096 char unit;
97 unsigned interval = 0;
98 unsigned in;
99
Alan Sternbe69e5b2005-10-25 15:56:06 -0400100 in = (desc->bEndpointAddress & USB_DIR_IN);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700101
Alan Sternbe69e5b2005-10-25 15:56:06 -0400102 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700103 case USB_ENDPOINT_XFER_CONTROL:
104 if (udev->speed == USB_SPEED_HIGH) /* uframes per NAK */
Alan Sternbe69e5b2005-10-25 15:56:06 -0400105 interval = desc->bInterval;
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700106 break;
107 case USB_ENDPOINT_XFER_ISOC:
Alan Sternbe69e5b2005-10-25 15:56:06 -0400108 interval = 1 << (desc->bInterval - 1);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700109 break;
110 case USB_ENDPOINT_XFER_BULK:
Alan Sternbe69e5b2005-10-25 15:56:06 -0400111 if (udev->speed == USB_SPEED_HIGH && !in) /* uframes per NAK */
112 interval = desc->bInterval;
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700113 break;
114 case USB_ENDPOINT_XFER_INT:
Alan Sternbe69e5b2005-10-25 15:56:06 -0400115 if (udev->speed == USB_SPEED_HIGH)
116 interval = 1 << (desc->bInterval - 1);
117 else
118 interval = desc->bInterval;
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700119 break;
120 }
121 interval *= (udev->speed == USB_SPEED_HIGH) ? 125 : 1000;
122 if (interval % 1000)
123 unit = 'u';
124 else {
125 unit = 'm';
126 interval /= 1000;
127 }
128
129 return sprintf(buf, "%d%cs\n", interval, unit);
130}
Alan Sternbe69e5b2005-10-25 15:56:06 -0400131static EP_ATTR(interval);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700132
Alan Sternbe69e5b2005-10-25 15:56:06 -0400133static ssize_t show_ep_direction(struct usb_device *udev,
134 struct usb_endpoint_descriptor *desc, char *buf)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700135{
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700136 char *direction;
137
Alan Sternbe69e5b2005-10-25 15:56:06 -0400138 if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
139 USB_ENDPOINT_XFER_CONTROL)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700140 direction = "both";
Alan Sternbe69e5b2005-10-25 15:56:06 -0400141 else if (desc->bEndpointAddress & USB_DIR_IN)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700142 direction = "in";
143 else
144 direction = "out";
145 return sprintf(buf, "%s\n", direction);
146}
Alan Sternbe69e5b2005-10-25 15:56:06 -0400147static EP_ATTR(direction);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700148
Alan Sternbe69e5b2005-10-25 15:56:06 -0400149static struct attribute *ep_attrs[] = {
150 &ep_bLength.attr,
151 &ep_bEndpointAddress.attr,
152 &ep_bmAttributes.attr,
153 &ep_bInterval.attr,
154 &ep_wMaxPacketSize.attr,
155 &ep_type.attr,
156 &ep_interval.attr,
157 &ep_direction.attr,
158 NULL,
159};
160
161static void ep_object_release(struct kobject *kobj)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700162{
Alan Sternbe69e5b2005-10-25 15:56:06 -0400163 kfree(to_ep_object(kobj));
164}
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700165
Alan Sternbe69e5b2005-10-25 15:56:06 -0400166static ssize_t ep_object_show(struct kobject *kobj, struct attribute *attr,
167 char *buf)
168{
169 struct ep_object *ep_obj = to_ep_object(kobj);
170 struct ep_attribute *ep_attr = to_ep_attribute(attr);
171
172 return (ep_attr->show)(ep_obj->udev, ep_obj->desc, buf);
173}
174
175static struct sysfs_ops ep_object_sysfs_ops = {
176 .show = ep_object_show,
177};
178
179static struct kobj_type ep_object_ktype = {
180 .release = ep_object_release,
181 .sysfs_ops = &ep_object_sysfs_ops,
182 .default_attrs = ep_attrs,
183};
184
185static void usb_create_ep_files(struct kobject *parent,
186 struct usb_host_endpoint *endpoint,
187 struct usb_device *udev)
188{
189 struct ep_object *ep_obj;
190 struct kobject *kobj;
191
192 ep_obj = kzalloc(sizeof(struct ep_object), GFP_KERNEL);
193 if (!ep_obj)
194 return;
195
196 ep_obj->desc = &endpoint->desc;
197 ep_obj->udev = udev;
198
199 kobj = &ep_obj->kobj;
200 kobject_set_name(kobj, "ep_%02x", endpoint->desc.bEndpointAddress);
201 kobj->parent = parent;
202 kobj->ktype = &ep_object_ktype;
203
204 /* Don't use kobject_register, because it generates a hotplug event */
205 kobject_init(kobj);
206 if (kobject_add(kobj) == 0)
207 endpoint->kobj = kobj;
208 else
209 kobject_put(kobj);
210}
211
212static void usb_remove_ep_files(struct usb_host_endpoint *endpoint)
213{
214
215 if (endpoint->kobj) {
216 kobject_del(endpoint->kobj);
217 kobject_put(endpoint->kobj);
218 endpoint->kobj = NULL;
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700219 }
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/* Active configuration fields */
223#define usb_actconfig_show(field, multiplier, format_string) \
Alan Sternb724ae72005-10-24 15:36:00 -0400224static ssize_t show_##field (struct device *dev, \
225 struct device_attribute *attr, char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{ \
227 struct usb_device *udev; \
228 struct usb_host_config *actconfig; \
229 \
230 udev = to_usb_device (dev); \
231 actconfig = udev->actconfig; \
232 if (actconfig) \
233 return sprintf (buf, format_string, \
234 actconfig->desc.field * multiplier); \
235 else \
236 return 0; \
237} \
238
239#define usb_actconfig_attr(field, multiplier, format_string) \
240usb_actconfig_show(field, multiplier, format_string) \
241static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
242
243usb_actconfig_attr (bNumInterfaces, 1, "%2d\n")
244usb_actconfig_attr (bmAttributes, 1, "%2x\n")
245usb_actconfig_attr (bMaxPower, 2, "%3dmA\n")
246
Alan Sternb724ae72005-10-24 15:36:00 -0400247static ssize_t show_configuration_string(struct device *dev,
248 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 struct usb_device *udev;
251 struct usb_host_config *actconfig;
252 int len;
253
254 udev = to_usb_device (dev);
255 actconfig = udev->actconfig;
256 if ((!actconfig) || (!actconfig->string))
257 return 0;
258 len = sprintf(buf, actconfig->string, PAGE_SIZE);
259 if (len < 0)
260 return 0;
261 buf[len] = '\n';
262 buf[len+1] = 0;
263 return len+1;
264}
265static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
266
267/* configuration value is always present, and r/w */
268usb_actconfig_show(bConfigurationValue, 1, "%u\n");
269
270static ssize_t
Alan Sternb724ae72005-10-24 15:36:00 -0400271set_bConfigurationValue (struct device *dev, struct device_attribute *attr,
272 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
274 struct usb_device *udev = udev = to_usb_device (dev);
275 int config, value;
276
277 if (sscanf (buf, "%u", &config) != 1 || config > 255)
278 return -EINVAL;
279 usb_lock_device(udev);
280 value = usb_set_configuration (udev, config);
281 usb_unlock_device(udev);
282 return (value < 0) ? value : count;
283}
284
285static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR,
286 show_bConfigurationValue, set_bConfigurationValue);
287
288/* String fields */
289#define usb_string_attr(name) \
Alan Sternb724ae72005-10-24 15:36:00 -0400290static ssize_t show_##name(struct device *dev, \
291 struct device_attribute *attr, char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{ \
293 struct usb_device *udev; \
294 int len; \
295 \
296 udev = to_usb_device (dev); \
297 len = snprintf(buf, 256, "%s", udev->name); \
298 if (len < 0) \
299 return 0; \
300 buf[len] = '\n'; \
301 buf[len+1] = 0; \
302 return len+1; \
303} \
304static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
305
306usb_string_attr(product);
307usb_string_attr(manufacturer);
308usb_string_attr(serial);
309
310static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400311show_speed (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
313 struct usb_device *udev;
314 char *speed;
315
316 udev = to_usb_device (dev);
317
318 switch (udev->speed) {
319 case USB_SPEED_LOW:
320 speed = "1.5";
321 break;
322 case USB_SPEED_UNKNOWN:
323 case USB_SPEED_FULL:
324 speed = "12";
325 break;
326 case USB_SPEED_HIGH:
327 speed = "480";
328 break;
329 default:
330 speed = "unknown";
331 }
332 return sprintf (buf, "%s\n", speed);
333}
334static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL);
335
336static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400337show_devnum (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 struct usb_device *udev;
340
341 udev = to_usb_device (dev);
342 return sprintf (buf, "%d\n", udev->devnum);
343}
344static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL);
345
346static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400347show_version (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 struct usb_device *udev;
350 u16 bcdUSB;
351
352 udev = to_usb_device(dev);
353 bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB);
354 return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff);
355}
356static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
357
358static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400359show_maxchild (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 struct usb_device *udev;
362
363 udev = to_usb_device (dev);
364 return sprintf (buf, "%d\n", udev->maxchild);
365}
366static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
367
368/* Descriptor fields */
369#define usb_descriptor_attr_le16(field, format_string) \
370static ssize_t \
Alan Sternb724ae72005-10-24 15:36:00 -0400371show_##field (struct device *dev, struct device_attribute *attr, \
372 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{ \
374 struct usb_device *udev; \
375 \
376 udev = to_usb_device (dev); \
377 return sprintf (buf, format_string, \
378 le16_to_cpu(udev->descriptor.field)); \
379} \
380static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
381
382usb_descriptor_attr_le16(idVendor, "%04x\n")
383usb_descriptor_attr_le16(idProduct, "%04x\n")
384usb_descriptor_attr_le16(bcdDevice, "%04x\n")
385
386#define usb_descriptor_attr(field, format_string) \
387static ssize_t \
Alan Sternb724ae72005-10-24 15:36:00 -0400388show_##field (struct device *dev, struct device_attribute *attr, \
389 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{ \
391 struct usb_device *udev; \
392 \
393 udev = to_usb_device (dev); \
394 return sprintf (buf, format_string, udev->descriptor.field); \
395} \
396static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
397
398usb_descriptor_attr (bDeviceClass, "%02x\n")
399usb_descriptor_attr (bDeviceSubClass, "%02x\n")
400usb_descriptor_attr (bDeviceProtocol, "%02x\n")
401usb_descriptor_attr (bNumConfigurations, "%d\n")
Greg Kroah-Hartmancf5910b2005-06-29 16:53:29 -0700402usb_descriptor_attr (bMaxPacketSize0, "%d\n")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404static struct attribute *dev_attrs[] = {
405 /* current configuration's attributes */
406 &dev_attr_bNumInterfaces.attr,
407 &dev_attr_bConfigurationValue.attr,
408 &dev_attr_bmAttributes.attr,
409 &dev_attr_bMaxPower.attr,
410 /* device attributes */
411 &dev_attr_idVendor.attr,
412 &dev_attr_idProduct.attr,
413 &dev_attr_bcdDevice.attr,
414 &dev_attr_bDeviceClass.attr,
415 &dev_attr_bDeviceSubClass.attr,
416 &dev_attr_bDeviceProtocol.attr,
417 &dev_attr_bNumConfigurations.attr,
Greg Kroah-Hartmancf5910b2005-06-29 16:53:29 -0700418 &dev_attr_bMaxPacketSize0.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 &dev_attr_speed.attr,
420 &dev_attr_devnum.attr,
421 &dev_attr_version.attr,
422 &dev_attr_maxchild.attr,
423 NULL,
424};
425static struct attribute_group dev_attr_grp = {
426 .attrs = dev_attrs,
427};
428
429void usb_create_sysfs_dev_files (struct usb_device *udev)
430{
431 struct device *dev = &udev->dev;
432
433 sysfs_create_group(&dev->kobj, &dev_attr_grp);
434
435 if (udev->manufacturer)
436 device_create_file (dev, &dev_attr_manufacturer);
437 if (udev->product)
438 device_create_file (dev, &dev_attr_product);
439 if (udev->serial)
440 device_create_file (dev, &dev_attr_serial);
441 device_create_file (dev, &dev_attr_configuration);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700442 usb_create_ep_files(&dev->kobj, &udev->ep0, udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
445void usb_remove_sysfs_dev_files (struct usb_device *udev)
446{
447 struct device *dev = &udev->dev;
448
Alan Sternbe69e5b2005-10-25 15:56:06 -0400449 usb_remove_ep_files(&udev->ep0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 sysfs_remove_group(&dev->kobj, &dev_attr_grp);
451
452 if (udev->descriptor.iManufacturer)
453 device_remove_file(dev, &dev_attr_manufacturer);
454 if (udev->descriptor.iProduct)
455 device_remove_file(dev, &dev_attr_product);
456 if (udev->descriptor.iSerialNumber)
457 device_remove_file(dev, &dev_attr_serial);
458 device_remove_file (dev, &dev_attr_configuration);
459}
460
461/* Interface fields */
462#define usb_intf_attr(field, format_string) \
463static ssize_t \
Alan Sternb724ae72005-10-24 15:36:00 -0400464show_##field (struct device *dev, struct device_attribute *attr, \
465 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{ \
467 struct usb_interface *intf = to_usb_interface (dev); \
468 \
Alan Sternb724ae72005-10-24 15:36:00 -0400469 return sprintf (buf, format_string, \
470 intf->cur_altsetting->desc.field); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471} \
472static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
473
474usb_intf_attr (bInterfaceNumber, "%02x\n")
475usb_intf_attr (bAlternateSetting, "%2d\n")
476usb_intf_attr (bNumEndpoints, "%02x\n")
477usb_intf_attr (bInterfaceClass, "%02x\n")
478usb_intf_attr (bInterfaceSubClass, "%02x\n")
479usb_intf_attr (bInterfaceProtocol, "%02x\n")
480
Alan Sternb724ae72005-10-24 15:36:00 -0400481static ssize_t show_interface_string(struct device *dev,
482 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 struct usb_interface *intf;
485 struct usb_device *udev;
486 int len;
487
488 intf = to_usb_interface (dev);
489 udev = interface_to_usbdev (intf);
490 len = snprintf(buf, 256, "%s", intf->cur_altsetting->string);
491 if (len < 0)
492 return 0;
493 buf[len] = '\n';
494 buf[len+1] = 0;
495 return len+1;
496}
497static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL);
498
Alan Sternb724ae72005-10-24 15:36:00 -0400499static ssize_t show_modalias(struct device *dev,
500 struct device_attribute *attr, char *buf)
Greg KH360b52b2005-05-10 06:45:10 -0700501{
502 struct usb_interface *intf;
503 struct usb_device *udev;
Greg Kroah-Hartman75218032005-06-20 21:15:16 -0700504 struct usb_host_interface *alt;
Greg KH360b52b2005-05-10 06:45:10 -0700505
506 intf = to_usb_interface(dev);
507 udev = interface_to_usbdev(intf);
Greg Kroah-Hartman75218032005-06-20 21:15:16 -0700508 alt = intf->cur_altsetting;
Greg KH360b52b2005-05-10 06:45:10 -0700509
Greg Kroah-Hartman75218032005-06-20 21:15:16 -0700510 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
511 "ic%02Xisc%02Xip%02X\n",
512 le16_to_cpu(udev->descriptor.idVendor),
513 le16_to_cpu(udev->descriptor.idProduct),
514 le16_to_cpu(udev->descriptor.bcdDevice),
515 udev->descriptor.bDeviceClass,
516 udev->descriptor.bDeviceSubClass,
517 udev->descriptor.bDeviceProtocol,
518 alt->desc.bInterfaceClass,
519 alt->desc.bInterfaceSubClass,
520 alt->desc.bInterfaceProtocol);
Greg KH360b52b2005-05-10 06:45:10 -0700521}
522static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524static struct attribute *intf_attrs[] = {
525 &dev_attr_bInterfaceNumber.attr,
526 &dev_attr_bAlternateSetting.attr,
527 &dev_attr_bNumEndpoints.attr,
528 &dev_attr_bInterfaceClass.attr,
529 &dev_attr_bInterfaceSubClass.attr,
530 &dev_attr_bInterfaceProtocol.attr,
Greg KH360b52b2005-05-10 06:45:10 -0700531 &dev_attr_modalias.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 NULL,
533};
534static struct attribute_group intf_attr_grp = {
535 .attrs = intf_attrs,
536};
537
Alan Sternbe69e5b2005-10-25 15:56:06 -0400538static inline void usb_create_intf_ep_files(struct usb_interface *intf)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700539{
540 struct usb_host_interface *iface_desc;
541 int i;
542
543 iface_desc = intf->cur_altsetting;
544 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
545 usb_create_ep_files(&intf->dev.kobj, &iface_desc->endpoint[i],
Alan Sternbe69e5b2005-10-25 15:56:06 -0400546 interface_to_usbdev(intf));
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700547}
548
Alan Sternbe69e5b2005-10-25 15:56:06 -0400549static inline void usb_remove_intf_ep_files(struct usb_interface *intf)
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700550{
551 struct usb_host_interface *iface_desc;
552 int i;
553
554 iface_desc = intf->cur_altsetting;
555 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
Alan Sternbe69e5b2005-10-25 15:56:06 -0400556 usb_remove_ep_files(&iface_desc->endpoint[i]);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700557}
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559void usb_create_sysfs_intf_files (struct usb_interface *intf)
560{
561 sysfs_create_group(&intf->dev.kobj, &intf_attr_grp);
562
563 if (intf->cur_altsetting->string)
564 device_create_file(&intf->dev, &dev_attr_interface);
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700565 usb_create_intf_ep_files(intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568void usb_remove_sysfs_intf_files (struct usb_interface *intf)
569{
Greg Kroah-Hartman094f16492005-06-20 21:15:16 -0700570 usb_remove_intf_ep_files(intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp);
572
573 if (intf->cur_altsetting->string)
574 device_remove_file(&intf->dev, &dev_attr_interface);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}