diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2007-08-28 20:29:28 +0000 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2007-08-28 20:29:28 +0000 |
commit | 195ef597f5347d29a75eacad3f674bf635e791e5 (patch) | |
tree | 5e227df9a5a6c9671c2c7d21d83d12c51374e569 /firmware/usbstack/drivers/device/usb_storage.c | |
parent | 53b183f600a37000b0a2b33141800f9cbf052dcc (diff) | |
download | rockbox-195ef597f5347d29a75eacad3f674bf635e791e5.tar.gz rockbox-195ef597f5347d29a75eacad3f674bf635e791e5.zip |
Add support for full and highspeed in stack and drivers.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14492 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usbstack/drivers/device/usb_storage.c')
-rw-r--r-- | firmware/usbstack/drivers/device/usb_storage.c | 85 |
1 files changed, 59 insertions, 26 deletions
diff --git a/firmware/usbstack/drivers/device/usb_storage.c b/firmware/usbstack/drivers/device/usb_storage.c index 38c2b97eb0..3db379c1df 100644 --- a/firmware/usbstack/drivers/device/usb_storage.c +++ b/firmware/usbstack/drivers/device/usb_storage.c | |||
@@ -31,17 +31,9 @@ struct usb_device_driver usb_storage_driver = { | |||
31 | .request = usb_storage_driver_request, | 31 | .request = usb_storage_driver_request, |
32 | .suspend = NULL, | 32 | .suspend = NULL, |
33 | .resume = NULL, | 33 | .resume = NULL, |
34 | .speed = NULL, | 34 | .speed = usb_storage_driver_speed, |
35 | }; | 35 | }; |
36 | 36 | ||
37 | struct device { | ||
38 | struct usb_ep* in; | ||
39 | struct usb_ep* out; | ||
40 | struct usb_ep* intr; | ||
41 | }; | ||
42 | |||
43 | static struct device dev; | ||
44 | |||
45 | /*-------------------------------------------------------------------------*/ | 37 | /*-------------------------------------------------------------------------*/ |
46 | 38 | ||
47 | #define PROTO_BULK 0x50 // Bulk only | 39 | #define PROTO_BULK 0x50 // Bulk only |
@@ -92,8 +84,31 @@ static struct usb_interface_descriptor storage_interface_desc = { | |||
92 | .iInterface = 0, | 84 | .iInterface = 0, |
93 | }; | 85 | }; |
94 | 86 | ||
95 | /* endpoint I -> bulk in */ | 87 | static struct usb_endpoint_descriptor storage_fs_bulk_in_desc = { |
96 | static struct usb_endpoint_descriptor storage_bulk_in_desc = { | 88 | .bLength = USB_DT_ENDPOINT_SIZE, |
89 | .bDescriptorType = USB_DT_ENDPOINT, | ||
90 | .bEndpointAddress = USB_DIR_IN, | ||
91 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
92 | .wMaxPacketSize = 64, | ||
93 | }; | ||
94 | |||
95 | static struct usb_endpoint_descriptor storage_fs_bulk_out_desc = { | ||
96 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
97 | .bDescriptorType = USB_DT_ENDPOINT, | ||
98 | .bEndpointAddress = USB_DIR_OUT, | ||
99 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
100 | .wMaxPacketSize = 64, | ||
101 | }; | ||
102 | |||
103 | struct usb_descriptor_header *storage_fs_function[] = { | ||
104 | (struct usb_descriptor_header *) &storage_interface_desc, | ||
105 | (struct usb_descriptor_header *) &storage_fs_bulk_in_desc, | ||
106 | (struct usb_descriptor_header *) &storage_fs_bulk_out_desc, | ||
107 | NULL, | ||
108 | }; | ||
109 | |||
110 | /* USB 2.0 */ | ||
111 | static struct usb_endpoint_descriptor storage_hs_bulk_in_desc = { | ||
97 | .bLength = USB_DT_ENDPOINT_SIZE, | 112 | .bLength = USB_DT_ENDPOINT_SIZE, |
98 | .bDescriptorType = USB_DT_ENDPOINT, | 113 | .bDescriptorType = USB_DT_ENDPOINT, |
99 | .bEndpointAddress = USB_DIR_IN, | 114 | .bEndpointAddress = USB_DIR_IN, |
@@ -101,8 +116,7 @@ static struct usb_endpoint_descriptor storage_bulk_in_desc = { | |||
101 | .wMaxPacketSize = 512, | 116 | .wMaxPacketSize = 512, |
102 | }; | 117 | }; |
103 | 118 | ||
104 | /* endpoint II -> bulk out */ | 119 | static struct usb_endpoint_descriptor storage_hs_bulk_out_desc = { |
105 | static struct usb_endpoint_descriptor storage_bulk_out_desc = { | ||
106 | .bLength = USB_DT_ENDPOINT_SIZE, | 120 | .bLength = USB_DT_ENDPOINT_SIZE, |
107 | .bDescriptorType = USB_DT_ENDPOINT, | 121 | .bDescriptorType = USB_DT_ENDPOINT, |
108 | .bEndpointAddress = USB_DIR_OUT, | 122 | .bEndpointAddress = USB_DIR_OUT, |
@@ -110,10 +124,10 @@ static struct usb_endpoint_descriptor storage_bulk_out_desc = { | |||
110 | .wMaxPacketSize = 512, | 124 | .wMaxPacketSize = 512, |
111 | }; | 125 | }; |
112 | 126 | ||
113 | struct usb_descriptor_header *storage_fullspeed_function[] = { | 127 | struct usb_descriptor_header *storage_hs_function[] = { |
114 | (struct usb_descriptor_header *) &storage_interface_desc, | 128 | (struct usb_descriptor_header *) &storage_interface_desc, |
115 | (struct usb_descriptor_header *) &storage_bulk_in_desc, | 129 | (struct usb_descriptor_header *) &storage_hs_bulk_in_desc, |
116 | (struct usb_descriptor_header *) &storage_bulk_out_desc, | 130 | (struct usb_descriptor_header *) &storage_hs_bulk_out_desc, |
117 | NULL, | 131 | NULL, |
118 | }; | 132 | }; |
119 | 133 | ||
@@ -126,6 +140,15 @@ struct usb_response res; | |||
126 | static int config_buf(uint8_t *buf, uint8_t type, unsigned index); | 140 | static int config_buf(uint8_t *buf, uint8_t type, unsigned index); |
127 | static int set_config(int config); | 141 | static int set_config(int config); |
128 | 142 | ||
143 | struct device { | ||
144 | struct usb_ep* in; | ||
145 | struct usb_ep* out; | ||
146 | struct usb_ep* intr; | ||
147 | struct usb_descriptor_header** descriptors; | ||
148 | }; | ||
149 | |||
150 | static struct device dev; | ||
151 | |||
129 | /*-------------------------------------------------------------------------*/ | 152 | /*-------------------------------------------------------------------------*/ |
130 | 153 | ||
131 | void usb_storage_driver_init(void) | 154 | void usb_storage_driver_init(void) |
@@ -144,14 +167,14 @@ void usb_storage_driver_bind(void* controler_ops) | |||
144 | /* serach and asign endpoints */ | 167 | /* serach and asign endpoints */ |
145 | usb_ep_autoconfig_reset(); | 168 | usb_ep_autoconfig_reset(); |
146 | 169 | ||
147 | dev.in = usb_ep_autoconfig(&storage_bulk_in_desc); | 170 | dev.in = usb_ep_autoconfig(&storage_fs_bulk_in_desc); |
148 | if (!dev.in) { | 171 | if (!dev.in) { |
149 | goto autoconf_fail; | 172 | goto autoconf_fail; |
150 | } | 173 | } |
151 | dev.in->claimed = true; | 174 | dev.in->claimed = true; |
152 | logf("usb storage: in: %s", dev.in->name); | 175 | logf("usb storage: in: %s", dev.in->name); |
153 | 176 | ||
154 | dev.out = usb_ep_autoconfig(&storage_bulk_out_desc); | 177 | dev.out = usb_ep_autoconfig(&storage_fs_bulk_out_desc); |
155 | if (!dev.out) { | 178 | if (!dev.out) { |
156 | goto autoconf_fail; | 179 | goto autoconf_fail; |
157 | } | 180 | } |
@@ -234,6 +257,20 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request) | |||
234 | return ret; | 257 | return ret; |
235 | } | 258 | } |
236 | 259 | ||
260 | void usb_storage_driver_speed(enum usb_device_speed speed) | ||
261 | { | ||
262 | switch (speed) { | ||
263 | case USB_SPEED_HIGH: | ||
264 | logf("usb storage: using highspeed"); | ||
265 | dev.descriptors = storage_hs_function; | ||
266 | break; | ||
267 | default: | ||
268 | logf("usb storage: using fullspeed"); | ||
269 | dev.descriptors = storage_fs_function; | ||
270 | break; | ||
271 | } | ||
272 | } | ||
273 | |||
237 | /*-------------------------------------------------------------------------*/ | 274 | /*-------------------------------------------------------------------------*/ |
238 | /* S/GET CONFIGURATION helpers */ | 275 | /* S/GET CONFIGURATION helpers */ |
239 | 276 | ||
@@ -241,12 +278,8 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index) | |||
241 | { | 278 | { |
242 | int len; | 279 | int len; |
243 | 280 | ||
244 | /* only one configuration */ | 281 | len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, dev.descriptors); |
245 | if (index != 0) { | 282 | logf("result %d", len); |
246 | return -EINVAL; | ||
247 | } | ||
248 | |||
249 | len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, storage_fullspeed_function); | ||
250 | if (len < 0) { | 283 | if (len < 0) { |
251 | return len; | 284 | return len; |
252 | } | 285 | } |
@@ -258,9 +291,9 @@ static int set_config(int config) | |||
258 | { | 291 | { |
259 | /* enable endpoints */ | 292 | /* enable endpoints */ |
260 | logf("setup %s", dev.in->name); | 293 | logf("setup %s", dev.in->name); |
261 | ops->enable(dev.in); | 294 | ops->enable(dev.in, (struct usb_endpoint_descriptor*)dev.descriptors[1]); |
262 | logf("setup %s", dev.out->name); | 295 | logf("setup %s", dev.out->name); |
263 | ops->enable(dev.out); | 296 | ops->enable(dev.out, (struct usb_endpoint_descriptor*)dev.descriptors[2]); |
264 | 297 | ||
265 | /* setup buffers */ | 298 | /* setup buffers */ |
266 | 299 | ||