aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2006-06-14 15:14:34 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-21 18:04:18 -0400
commit84412f6291b50690febd81899e46f0f0ef7a13e0 (patch)
treed13850f546c4d3a7a8ff561982145325336e4167 /drivers/usb/core
parentae0dadcf0f912cbab2ac84caa437454620bf71b2 (diff)
[PATCH] USB: move the endpoint specific sysfs code to it's own file
This makes it easier to modify in the future without touching anything else. Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/Makefile3
-rw-r--r--drivers/usb/core/endpoint.c213
-rw-r--r--drivers/usb/core/sysfs.c197
-rw-r--r--drivers/usb/core/usb.h3
4 files changed, 218 insertions, 198 deletions
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index 28329ddf187c..ec510922af63 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -3,7 +3,8 @@
3# 3#
4 4
5usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ 5usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \
6 config.o file.o buffer.o sysfs.o devio.o notify.o 6 config.o file.o buffer.o sysfs.o endpoint.o \
7 devio.o notify.o
7 8
8ifeq ($(CONFIG_PCI),y) 9ifeq ($(CONFIG_PCI),y)
9 usbcore-objs += hcd-pci.o 10 usbcore-objs += hcd-pci.o
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
new file mode 100644
index 000000000000..2b1697715e88
--- /dev/null
+++ b/drivers/usb/core/endpoint.c
@@ -0,0 +1,213 @@
1/*
2 * drivers/usb/core/endpoint.c
3 *
4 * (C) Copyright 2002,2004,2006 Greg Kroah-Hartman
5 * (C) Copyright 2002,2004 IBM Corp.
6 * (C) Copyright 2006 Novell Inc.
7 *
8 * Endpoint sysfs stuff
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/usb.h>
14#include "usb.h"
15
16/* endpoint stuff */
17struct ep_object {
18 struct usb_endpoint_descriptor *desc;
19 struct usb_device *udev;
20 struct kobject kobj;
21};
22#define to_ep_object(_kobj) \
23 container_of(_kobj, struct ep_object, kobj)
24
25struct ep_attribute {
26 struct attribute attr;
27 ssize_t (*show)(struct usb_device *,
28 struct usb_endpoint_descriptor *, char *);
29};
30#define to_ep_attribute(_attr) \
31 container_of(_attr, struct ep_attribute, attr)
32
33#define EP_ATTR(_name) \
34struct ep_attribute ep_##_name = { \
35 .attr = {.name = #_name, .owner = THIS_MODULE, \
36 .mode = S_IRUGO}, \
37 .show = show_ep_##_name}
38
39#define usb_ep_attr(field, format_string) \
40static ssize_t show_ep_##field(struct usb_device *udev, \
41 struct usb_endpoint_descriptor *desc, \
42 char *buf) \
43{ \
44 return sprintf(buf, format_string, desc->field); \
45} \
46static EP_ATTR(field);
47
48usb_ep_attr(bLength, "%02x\n")
49usb_ep_attr(bEndpointAddress, "%02x\n")
50usb_ep_attr(bmAttributes, "%02x\n")
51usb_ep_attr(bInterval, "%02x\n")
52
53static ssize_t show_ep_wMaxPacketSize(struct usb_device *udev,
54 struct usb_endpoint_descriptor *desc, char *buf)
55{
56 return sprintf(buf, "%04x\n",
57 le16_to_cpu(desc->wMaxPacketSize) & 0x07ff);
58}
59static EP_ATTR(wMaxPacketSize);
60
61static ssize_t show_ep_type(struct usb_device *udev,
62 struct usb_endpoint_descriptor *desc, char *buf)
63{
64 char *type = "unknown";
65
66 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
67 case USB_ENDPOINT_XFER_CONTROL:
68 type = "Control";
69 break;
70 case USB_ENDPOINT_XFER_ISOC:
71 type = "Isoc";
72 break;
73 case USB_ENDPOINT_XFER_BULK:
74 type = "Bulk";
75 break;
76 case USB_ENDPOINT_XFER_INT:
77 type = "Interrupt";
78 break;
79 }
80 return sprintf(buf, "%s\n", type);
81}
82static EP_ATTR(type);
83
84static ssize_t show_ep_interval(struct usb_device *udev,
85 struct usb_endpoint_descriptor *desc, char *buf)
86{
87 char unit;
88 unsigned interval = 0;
89 unsigned in;
90
91 in = (desc->bEndpointAddress & USB_DIR_IN);
92
93 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
94 case USB_ENDPOINT_XFER_CONTROL:
95 if (udev->speed == USB_SPEED_HIGH) /* uframes per NAK */
96 interval = desc->bInterval;
97 break;
98 case USB_ENDPOINT_XFER_ISOC:
99 interval = 1 << (desc->bInterval - 1);
100 break;
101 case USB_ENDPOINT_XFER_BULK:
102 if (udev->speed == USB_SPEED_HIGH && !in) /* uframes per NAK */
103 interval = desc->bInterval;
104 break;
105 case USB_ENDPOINT_XFER_INT:
106 if (udev->speed == USB_SPEED_HIGH)
107 interval = 1 << (desc->bInterval - 1);
108 else
109 interval = desc->bInterval;
110 break;
111 }
112 interval *= (udev->speed == USB_SPEED_HIGH) ? 125 : 1000;
113 if (interval % 1000)
114 unit = 'u';
115 else {
116 unit = 'm';
117 interval /= 1000;
118 }
119
120 return sprintf(buf, "%d%cs\n", interval, unit);
121}
122static EP_ATTR(interval);
123
124static ssize_t show_ep_direction(struct usb_device *udev,
125 struct usb_endpoint_descriptor *desc, char *buf)
126{
127 char *direction;
128
129 if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
130 USB_ENDPOINT_XFER_CONTROL)
131 direction = "both";
132 else if (desc->bEndpointAddress & USB_DIR_IN)
133 direction = "in";
134 else
135 direction = "out";
136 return sprintf(buf, "%s\n", direction);
137}
138static EP_ATTR(direction);
139
140static struct attribute *ep_attrs[] = {
141 &ep_bLength.attr,
142 &ep_bEndpointAddress.attr,
143 &ep_bmAttributes.attr,
144 &ep_bInterval.attr,
145 &ep_wMaxPacketSize.attr,
146 &ep_type.attr,
147 &ep_interval.attr,
148 &ep_direction.attr,
149 NULL,
150};
151
152static void ep_object_release(struct kobject *kobj)
153{
154 kfree(to_ep_object(kobj));
155}
156
157static ssize_t ep_object_show(struct kobject *kobj, struct attribute *attr,
158 char *buf)
159{
160 struct ep_object *ep_obj = to_ep_object(kobj);
161 struct ep_attribute *ep_attr = to_ep_attribute(attr);
162
163 return (ep_attr->show)(ep_obj->udev, ep_obj->desc, buf);
164}
165
166static struct sysfs_ops ep_object_sysfs_ops = {
167 .show = ep_object_show,
168};
169
170static struct kobj_type ep_object_ktype = {
171 .release = ep_object_release,
172 .sysfs_ops = &ep_object_sysfs_ops,
173 .default_attrs = ep_attrs,
174};
175
176void usb_create_ep_files(struct kobject *parent,
177 struct usb_host_endpoint *endpoint,
178 struct usb_device *udev)
179{
180 struct ep_object *ep_obj;
181 struct kobject *kobj;
182
183 ep_obj = kzalloc(sizeof(struct ep_object), GFP_KERNEL);
184 if (!ep_obj)
185 return;
186
187 ep_obj->desc = &endpoint->desc;
188 ep_obj->udev = udev;
189
190 kobj = &ep_obj->kobj;
191 kobject_set_name(kobj, "ep_%02x", endpoint->desc.bEndpointAddress);
192 kobj->parent = parent;
193 kobj->ktype = &ep_object_ktype;
194
195 /* Don't use kobject_register, because it generates a hotplug event */
196 kobject_init(kobj);
197 if (kobject_add(kobj) == 0)
198 endpoint->kobj = kobj;
199 else
200 kobject_put(kobj);
201}
202
203void usb_remove_ep_files(struct usb_host_endpoint *endpoint)
204{
205
206 if (endpoint->kobj) {
207 kobject_del(endpoint->kobj);
208 kobject_put(endpoint->kobj);
209 endpoint->kobj = NULL;
210 }
211}
212
213
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 71d881327e88..cc18a05e5777 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 */
19struct 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
27struct 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) \
36struct 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) \
42static 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} \
48static EP_ATTR(field);
49
50usb_ep_attr(bLength, "%02x\n")
51usb_ep_attr(bEndpointAddress, "%02x\n")
52usb_ep_attr(bmAttributes, "%02x\n")
53usb_ep_attr(bInterval, "%02x\n")
54
55static 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}
61static EP_ATTR(wMaxPacketSize);
62
63static 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}
84static EP_ATTR(type);
85
86static 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}
124static EP_ATTR(interval);
125
126static 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}
140static EP_ATTR(direction);
141
142static 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
154static void ep_object_release(struct kobject *kobj)
155{
156 kfree(to_ep_object(kobj));
157}
158
159static 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
168static struct sysfs_ops ep_object_sysfs_ops = {
169 .show = ep_object_show,
170};
171
172static 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
178static 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
205static 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) \
217static ssize_t show_##field (struct device *dev, \ 20static ssize_t show_##field (struct device *dev, \
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 4647e1ebc68d..941cb397ba04 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -4,6 +4,9 @@ extern void usb_create_sysfs_dev_files (struct usb_device *dev);
4extern void usb_remove_sysfs_dev_files (struct usb_device *dev); 4extern void usb_remove_sysfs_dev_files (struct usb_device *dev);
5extern void usb_create_sysfs_intf_files (struct usb_interface *intf); 5extern void usb_create_sysfs_intf_files (struct usb_interface *intf);
6extern void usb_remove_sysfs_intf_files (struct usb_interface *intf); 6extern void usb_remove_sysfs_intf_files (struct usb_interface *intf);
7extern void usb_create_ep_files(struct kobject *parent, struct usb_host_endpoint *endpoint,
8 struct usb_device *udev);
9extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
7 10
8extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr); 11extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr);
9extern void usb_disable_interface (struct usb_device *dev, 12extern void usb_disable_interface (struct usb_device *dev,