12 #include <linux/kernel.h>
14 #include <linux/slab.h>
24 #define to_ep_device(_dev) \
25 container_of(_dev, struct ep_device, dev)
32 #define to_ep_attribute(_attr) \
33 container_of(_attr, struct ep_attribute, attr)
35 #define usb_ep_attr(field, format_string) \
36 static ssize_t show_ep_##field(struct device *dev, \
37 struct device_attribute *attr, \
40 struct ep_device *ep = to_ep_device(dev); \
41 return sprintf(buf, format_string, ep->desc->field); \
43 static DEVICE_ATTR(field, S_IRUGO, show_ep_##field, NULL);
55 usb_endpoint_maxp(ep->
desc) & 0x07ff);
63 char *
type =
"unknown";
65 switch (usb_endpoint_type(ep->
desc)) {
79 return sprintf(buf,
"%s\n", type);
93 switch (usb_endpoint_type(ep->
desc)) {
97 interval = ep->
desc->bInterval;
101 interval = 1 << (ep->
desc->bInterval - 1);
107 interval = ep->
desc->bInterval;
112 interval = 1 << (ep->
desc->bInterval - 1);
114 interval = ep->
desc->bInterval;
125 return sprintf(buf,
"%d%cs\n", interval, unit);
135 if (usb_endpoint_xfer_control(ep->
desc))
137 else if (usb_endpoint_dir_in(ep->
desc))
141 return sprintf(buf,
"%s\n", direction);
145 static struct attribute *ep_dev_attrs[] = {
146 &dev_attr_bLength.attr,
147 &dev_attr_bEndpointAddress.attr,
148 &dev_attr_bmAttributes.attr,
149 &dev_attr_bInterval.attr,
150 &dev_attr_wMaxPacketSize.attr,
151 &dev_attr_interval.attr,
153 &dev_attr_direction.attr,
157 .attrs = ep_dev_attrs,
164 static void ep_device_release(
struct device *dev)
172 .name =
"usb_endpoint",
173 .release = ep_device_release,
178 struct usb_device *
udev)
183 ep_dev = kzalloc(
sizeof(*ep_dev),
GFP_KERNEL);
189 ep_dev->
desc = &endpoint->desc;
191 ep_dev->
dev.groups = ep_dev_groups;
193 ep_dev->
dev.parent = parent;
194 dev_set_name(&ep_dev->
dev,
"ep_%02x", endpoint->desc.bEndpointAddress);
200 device_enable_async_suspend(&ep_dev->
dev);
201 endpoint->ep_dev = ep_dev;
212 struct ep_device *ep_dev = endpoint->ep_dev;
216 endpoint->ep_dev =
NULL;