diff options
author | Dmitry Torokhov <dtor_core@ameritech.net> | 2006-06-26 01:31:38 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor_core@ameritech.net> | 2006-06-26 01:31:38 -0400 |
commit | 4854c7b27f0975a2b629f35ea3996d2968eb7c4f (patch) | |
tree | 4102bdb70289764a2058aff0f907b13d7cf0e0d1 /drivers/usb/core/sysfs.c | |
parent | 3cbd5b32cb625f5c0f1b1476d154fac873dd49ce (diff) | |
parent | fcc18e83e1f6fd9fa6b333735bf0fcd530655511 (diff) |
Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers/usb/core/sysfs.c')
-rw-r--r-- | drivers/usb/core/sysfs.c | 201 |
1 files changed, 2 insertions, 199 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 71d881327e88..3f49bf51cff7 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -15,203 +15,6 @@ | |||
15 | #include <linux/usb.h> | 15 | #include <linux/usb.h> |
16 | #include "usb.h" | 16 | #include "usb.h" |
17 | 17 | ||
18 | /* endpoint stuff */ | ||
19 | struct ep_object { | ||
20 | struct usb_endpoint_descriptor *desc; | ||
21 | struct usb_device *udev; | ||
22 | struct kobject kobj; | ||
23 | }; | ||
24 | #define to_ep_object(_kobj) \ | ||
25 | container_of(_kobj, struct ep_object, kobj) | ||
26 | |||
27 | struct ep_attribute { | ||
28 | struct attribute attr; | ||
29 | ssize_t (*show)(struct usb_device *, | ||
30 | struct usb_endpoint_descriptor *, char *); | ||
31 | }; | ||
32 | #define to_ep_attribute(_attr) \ | ||
33 | container_of(_attr, struct ep_attribute, attr) | ||
34 | |||
35 | #define EP_ATTR(_name) \ | ||
36 | struct ep_attribute ep_##_name = { \ | ||
37 | .attr = {.name = #_name, .owner = THIS_MODULE, \ | ||
38 | .mode = S_IRUGO}, \ | ||
39 | .show = show_ep_##_name} | ||
40 | |||
41 | #define usb_ep_attr(field, format_string) \ | ||
42 | static ssize_t show_ep_##field(struct usb_device *udev, \ | ||
43 | struct usb_endpoint_descriptor *desc, \ | ||
44 | char *buf) \ | ||
45 | { \ | ||
46 | return sprintf(buf, format_string, desc->field); \ | ||
47 | } \ | ||
48 | static EP_ATTR(field); | ||
49 | |||
50 | usb_ep_attr(bLength, "%02x\n") | ||
51 | usb_ep_attr(bEndpointAddress, "%02x\n") | ||
52 | usb_ep_attr(bmAttributes, "%02x\n") | ||
53 | usb_ep_attr(bInterval, "%02x\n") | ||
54 | |||
55 | static ssize_t show_ep_wMaxPacketSize(struct usb_device *udev, | ||
56 | struct usb_endpoint_descriptor *desc, char *buf) | ||
57 | { | ||
58 | return sprintf(buf, "%04x\n", | ||
59 | le16_to_cpu(desc->wMaxPacketSize) & 0x07ff); | ||
60 | } | ||
61 | static EP_ATTR(wMaxPacketSize); | ||
62 | |||
63 | static ssize_t show_ep_type(struct usb_device *udev, | ||
64 | struct usb_endpoint_descriptor *desc, char *buf) | ||
65 | { | ||
66 | char *type = "unknown"; | ||
67 | |||
68 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | ||
69 | case USB_ENDPOINT_XFER_CONTROL: | ||
70 | type = "Control"; | ||
71 | break; | ||
72 | case USB_ENDPOINT_XFER_ISOC: | ||
73 | type = "Isoc"; | ||
74 | break; | ||
75 | case USB_ENDPOINT_XFER_BULK: | ||
76 | type = "Bulk"; | ||
77 | break; | ||
78 | case USB_ENDPOINT_XFER_INT: | ||
79 | type = "Interrupt"; | ||
80 | break; | ||
81 | } | ||
82 | return sprintf(buf, "%s\n", type); | ||
83 | } | ||
84 | static EP_ATTR(type); | ||
85 | |||
86 | static ssize_t show_ep_interval(struct usb_device *udev, | ||
87 | struct usb_endpoint_descriptor *desc, char *buf) | ||
88 | { | ||
89 | char unit; | ||
90 | unsigned interval = 0; | ||
91 | unsigned in; | ||
92 | |||
93 | in = (desc->bEndpointAddress & USB_DIR_IN); | ||
94 | |||
95 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | ||
96 | case USB_ENDPOINT_XFER_CONTROL: | ||
97 | if (udev->speed == USB_SPEED_HIGH) /* uframes per NAK */ | ||
98 | interval = desc->bInterval; | ||
99 | break; | ||
100 | case USB_ENDPOINT_XFER_ISOC: | ||
101 | interval = 1 << (desc->bInterval - 1); | ||
102 | break; | ||
103 | case USB_ENDPOINT_XFER_BULK: | ||
104 | if (udev->speed == USB_SPEED_HIGH && !in) /* uframes per NAK */ | ||
105 | interval = desc->bInterval; | ||
106 | break; | ||
107 | case USB_ENDPOINT_XFER_INT: | ||
108 | if (udev->speed == USB_SPEED_HIGH) | ||
109 | interval = 1 << (desc->bInterval - 1); | ||
110 | else | ||
111 | interval = desc->bInterval; | ||
112 | break; | ||
113 | } | ||
114 | interval *= (udev->speed == USB_SPEED_HIGH) ? 125 : 1000; | ||
115 | if (interval % 1000) | ||
116 | unit = 'u'; | ||
117 | else { | ||
118 | unit = 'm'; | ||
119 | interval /= 1000; | ||
120 | } | ||
121 | |||
122 | return sprintf(buf, "%d%cs\n", interval, unit); | ||
123 | } | ||
124 | static EP_ATTR(interval); | ||
125 | |||
126 | static ssize_t show_ep_direction(struct usb_device *udev, | ||
127 | struct usb_endpoint_descriptor *desc, char *buf) | ||
128 | { | ||
129 | char *direction; | ||
130 | |||
131 | if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == | ||
132 | USB_ENDPOINT_XFER_CONTROL) | ||
133 | direction = "both"; | ||
134 | else if (desc->bEndpointAddress & USB_DIR_IN) | ||
135 | direction = "in"; | ||
136 | else | ||
137 | direction = "out"; | ||
138 | return sprintf(buf, "%s\n", direction); | ||
139 | } | ||
140 | static EP_ATTR(direction); | ||
141 | |||
142 | static struct attribute *ep_attrs[] = { | ||
143 | &ep_bLength.attr, | ||
144 | &ep_bEndpointAddress.attr, | ||
145 | &ep_bmAttributes.attr, | ||
146 | &ep_bInterval.attr, | ||
147 | &ep_wMaxPacketSize.attr, | ||
148 | &ep_type.attr, | ||
149 | &ep_interval.attr, | ||
150 | &ep_direction.attr, | ||
151 | NULL, | ||
152 | }; | ||
153 | |||
154 | static void ep_object_release(struct kobject *kobj) | ||
155 | { | ||
156 | kfree(to_ep_object(kobj)); | ||
157 | } | ||
158 | |||
159 | static ssize_t ep_object_show(struct kobject *kobj, struct attribute *attr, | ||
160 | char *buf) | ||
161 | { | ||
162 | struct ep_object *ep_obj = to_ep_object(kobj); | ||
163 | struct ep_attribute *ep_attr = to_ep_attribute(attr); | ||
164 | |||
165 | return (ep_attr->show)(ep_obj->udev, ep_obj->desc, buf); | ||
166 | } | ||
167 | |||
168 | static struct sysfs_ops ep_object_sysfs_ops = { | ||
169 | .show = ep_object_show, | ||
170 | }; | ||
171 | |||
172 | static struct kobj_type ep_object_ktype = { | ||
173 | .release = ep_object_release, | ||
174 | .sysfs_ops = &ep_object_sysfs_ops, | ||
175 | .default_attrs = ep_attrs, | ||
176 | }; | ||
177 | |||
178 | static void usb_create_ep_files(struct kobject *parent, | ||
179 | struct usb_host_endpoint *endpoint, | ||
180 | struct usb_device *udev) | ||
181 | { | ||
182 | struct ep_object *ep_obj; | ||
183 | struct kobject *kobj; | ||
184 | |||
185 | ep_obj = kzalloc(sizeof(struct ep_object), GFP_KERNEL); | ||
186 | if (!ep_obj) | ||
187 | return; | ||
188 | |||
189 | ep_obj->desc = &endpoint->desc; | ||
190 | ep_obj->udev = udev; | ||
191 | |||
192 | kobj = &ep_obj->kobj; | ||
193 | kobject_set_name(kobj, "ep_%02x", endpoint->desc.bEndpointAddress); | ||
194 | kobj->parent = parent; | ||
195 | kobj->ktype = &ep_object_ktype; | ||
196 | |||
197 | /* Don't use kobject_register, because it generates a hotplug event */ | ||
198 | kobject_init(kobj); | ||
199 | if (kobject_add(kobj) == 0) | ||
200 | endpoint->kobj = kobj; | ||
201 | else | ||
202 | kobject_put(kobj); | ||
203 | } | ||
204 | |||
205 | static void usb_remove_ep_files(struct usb_host_endpoint *endpoint) | ||
206 | { | ||
207 | |||
208 | if (endpoint->kobj) { | ||
209 | kobject_del(endpoint->kobj); | ||
210 | kobject_put(endpoint->kobj); | ||
211 | endpoint->kobj = NULL; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | /* Active configuration fields */ | 18 | /* Active configuration fields */ |
216 | #define usb_actconfig_show(field, multiplier, format_string) \ | 19 | #define usb_actconfig_show(field, multiplier, format_string) \ |
217 | static ssize_t show_##field (struct device *dev, \ | 20 | static ssize_t show_##field (struct device *dev, \ |
@@ -420,7 +223,7 @@ void usb_create_sysfs_dev_files (struct usb_device *udev) | |||
420 | if (udev->serial) | 223 | if (udev->serial) |
421 | device_create_file (dev, &dev_attr_serial); | 224 | device_create_file (dev, &dev_attr_serial); |
422 | device_create_file (dev, &dev_attr_configuration); | 225 | device_create_file (dev, &dev_attr_configuration); |
423 | usb_create_ep_files(&dev->kobj, &udev->ep0, udev); | 226 | usb_create_ep_files(dev, &udev->ep0, udev); |
424 | } | 227 | } |
425 | 228 | ||
426 | void usb_remove_sysfs_dev_files (struct usb_device *udev) | 229 | void usb_remove_sysfs_dev_files (struct usb_device *udev) |
@@ -524,7 +327,7 @@ static inline void usb_create_intf_ep_files(struct usb_interface *intf, | |||
524 | 327 | ||
525 | iface_desc = intf->cur_altsetting; | 328 | iface_desc = intf->cur_altsetting; |
526 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) | 329 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) |
527 | usb_create_ep_files(&intf->dev.kobj, &iface_desc->endpoint[i], | 330 | usb_create_ep_files(&intf->dev, &iface_desc->endpoint[i], |
528 | udev); | 331 | udev); |
529 | } | 332 | } |
530 | 333 | ||