diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-05-02 14:03:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-05-02 14:03:08 -0400 |
commit | 1be1d6b7f3f6e3a87f872dd5e7a867d03d8a6851 (patch) | |
tree | 102ef63f93d7d6d8400fc88158cc859a92a2b44f /drivers/usb/gadget/zero.c | |
parent | 37b6a04fd9fc887bbcc1a27d9354a5e7a5a4cdd8 (diff) | |
parent | 62fd2cac5bf5cf9e6fcb2fc40b32e7271e605c53 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (32 commits)
USB GADGET/PERIPHERAL: g_file_storage Bulk-Only Transport compliance, clear-feature ignore
USB GADGET/PERIPHERAL: g_file_storage Bulk-Only Transport compliance
usb_serial: some coding style fixes
USB: Remove redundant dependencies on USB_ATM.
USB: UHCI: disable remote wakeup when it's not needed
USB: OHCI: work around bogus compiler warning
USB: add Cypress c67x00 OTG controller HCD driver
USB: add Cypress c67x00 OTG controller core driver
USB: add Cypress c67x00 low level interface code
USB: airprime: unlock mutex instead of trying to lock it again
USB: storage: Update mailling list address
USB: storage: UNUSUAL_DEVS() for PanDigital Picture frame.
USB: Add the USB 2.0 extension descriptor.
USB: add more FTDI device ids
USB: fix cannot work usb storage when using ohci-sm501
usb: gadget zero timer init fix
usb: gadget zero style fixups (mostly whitespace)
usb serial gadget: CDC ACM fixes
usb: pxa27x_udc driver
USB: INTOVA Pixtreme camera mass storage device
...
Diffstat (limited to 'drivers/usb/gadget/zero.c')
-rw-r--r-- | drivers/usb/gadget/zero.c | 370 |
1 files changed, 175 insertions, 195 deletions
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index d3d4f4048e6c..fce4924dbbe8 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -23,9 +23,7 @@ | |||
23 | /* | 23 | /* |
24 | * Gadget Zero only needs two bulk endpoints, and is an example of how you | 24 | * Gadget Zero only needs two bulk endpoints, and is an example of how you |
25 | * can write a hardware-agnostic gadget driver running inside a USB device. | 25 | * can write a hardware-agnostic gadget driver running inside a USB device. |
26 | * | 26 | * Some hardware details are visible, but don't affect most of the driver. |
27 | * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't | ||
28 | * affect most of the driver. | ||
29 | * | 27 | * |
30 | * Use it with the Linux host/master side "usbtest" driver to get a basic | 28 | * Use it with the Linux host/master side "usbtest" driver to get a basic |
31 | * functional test of your device-side usb stack, or with "usb-skeleton". | 29 | * functional test of your device-side usb stack, or with "usb-skeleton". |
@@ -37,6 +35,7 @@ | |||
37 | * buflen=N default N=4096, buffer size used | 35 | * buflen=N default N=4096, buffer size used |
38 | * qlen=N default N=32, how many buffers in the loopback queue | 36 | * qlen=N default N=32, how many buffers in the loopback queue |
39 | * loopdefault default false, list loopback config first | 37 | * loopdefault default false, list loopback config first |
38 | * autoresume=N default N=0, seconds before triggering remote wakeup | ||
40 | * | 39 | * |
41 | * Many drivers will only have one configuration, letting them be much | 40 | * Many drivers will only have one configuration, letting them be much |
42 | * simpler if they also don't support high speed operation (like this | 41 | * simpler if they also don't support high speed operation (like this |
@@ -62,13 +61,13 @@ | |||
62 | 61 | ||
63 | /*-------------------------------------------------------------------------*/ | 62 | /*-------------------------------------------------------------------------*/ |
64 | 63 | ||
65 | #define DRIVER_VERSION "Lughnasadh, 2007" | 64 | #define DRIVER_VERSION "Earth Day 2008" |
66 | 65 | ||
67 | static const char shortname [] = "zero"; | 66 | static const char shortname[] = "zero"; |
68 | static const char longname [] = "Gadget Zero"; | 67 | static const char longname[] = "Gadget Zero"; |
69 | 68 | ||
70 | static const char source_sink [] = "source and sink data"; | 69 | static const char source_sink[] = "source and sink data"; |
71 | static const char loopback [] = "loop input to output"; | 70 | static const char loopback[] = "loop input to output"; |
72 | 71 | ||
73 | /*-------------------------------------------------------------------------*/ | 72 | /*-------------------------------------------------------------------------*/ |
74 | 73 | ||
@@ -120,16 +119,16 @@ static unsigned buflen = 4096; | |||
120 | static unsigned qlen = 32; | 119 | static unsigned qlen = 32; |
121 | static unsigned pattern = 0; | 120 | static unsigned pattern = 0; |
122 | 121 | ||
123 | module_param (buflen, uint, S_IRUGO); | 122 | module_param(buflen, uint, S_IRUGO); |
124 | module_param (qlen, uint, S_IRUGO); | 123 | module_param(qlen, uint, S_IRUGO); |
125 | module_param (pattern, uint, S_IRUGO|S_IWUSR); | 124 | module_param(pattern, uint, S_IRUGO|S_IWUSR); |
126 | 125 | ||
127 | /* | 126 | /* |
128 | * if it's nonzero, autoresume says how many seconds to wait | 127 | * if it's nonzero, autoresume says how many seconds to wait |
129 | * before trying to wake up the host after suspend. | 128 | * before trying to wake up the host after suspend. |
130 | */ | 129 | */ |
131 | static unsigned autoresume = 0; | 130 | static unsigned autoresume = 0; |
132 | module_param (autoresume, uint, 0); | 131 | module_param(autoresume, uint, 0); |
133 | 132 | ||
134 | /* | 133 | /* |
135 | * Normally the "loopback" configuration is second (index 1) so | 134 | * Normally the "loopback" configuration is second (index 1) so |
@@ -138,8 +137,7 @@ module_param (autoresume, uint, 0); | |||
138 | * Or controllers (like superh) that only support one config. | 137 | * Or controllers (like superh) that only support one config. |
139 | */ | 138 | */ |
140 | static int loopdefault = 0; | 139 | static int loopdefault = 0; |
141 | 140 | module_param(loopdefault, bool, S_IRUGO|S_IWUSR); | |
142 | module_param (loopdefault, bool, S_IRUGO|S_IWUSR); | ||
143 | 141 | ||
144 | /*-------------------------------------------------------------------------*/ | 142 | /*-------------------------------------------------------------------------*/ |
145 | 143 | ||
@@ -176,24 +174,22 @@ module_param (loopdefault, bool, S_IRUGO|S_IWUSR); | |||
176 | #define CONFIG_SOURCE_SINK 3 | 174 | #define CONFIG_SOURCE_SINK 3 |
177 | #define CONFIG_LOOPBACK 2 | 175 | #define CONFIG_LOOPBACK 2 |
178 | 176 | ||
179 | static struct usb_device_descriptor | 177 | static struct usb_device_descriptor device_desc = { |
180 | device_desc = { | ||
181 | .bLength = sizeof device_desc, | 178 | .bLength = sizeof device_desc, |
182 | .bDescriptorType = USB_DT_DEVICE, | 179 | .bDescriptorType = USB_DT_DEVICE, |
183 | 180 | ||
184 | .bcdUSB = __constant_cpu_to_le16 (0x0200), | 181 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
185 | .bDeviceClass = USB_CLASS_VENDOR_SPEC, | 182 | .bDeviceClass = USB_CLASS_VENDOR_SPEC, |
186 | 183 | ||
187 | .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM), | 184 | .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), |
188 | .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM), | 185 | .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), |
189 | .iManufacturer = STRING_MANUFACTURER, | 186 | .iManufacturer = STRING_MANUFACTURER, |
190 | .iProduct = STRING_PRODUCT, | 187 | .iProduct = STRING_PRODUCT, |
191 | .iSerialNumber = STRING_SERIAL, | 188 | .iSerialNumber = STRING_SERIAL, |
192 | .bNumConfigurations = 2, | 189 | .bNumConfigurations = 2, |
193 | }; | 190 | }; |
194 | 191 | ||
195 | static struct usb_config_descriptor | 192 | static struct usb_config_descriptor source_sink_config = { |
196 | source_sink_config = { | ||
197 | .bLength = sizeof source_sink_config, | 193 | .bLength = sizeof source_sink_config, |
198 | .bDescriptorType = USB_DT_CONFIG, | 194 | .bDescriptorType = USB_DT_CONFIG, |
199 | 195 | ||
@@ -205,8 +201,7 @@ source_sink_config = { | |||
205 | .bMaxPower = 1, /* self-powered */ | 201 | .bMaxPower = 1, /* self-powered */ |
206 | }; | 202 | }; |
207 | 203 | ||
208 | static struct usb_config_descriptor | 204 | static struct usb_config_descriptor loopback_config = { |
209 | loopback_config = { | ||
210 | .bLength = sizeof loopback_config, | 205 | .bLength = sizeof loopback_config, |
211 | .bDescriptorType = USB_DT_CONFIG, | 206 | .bDescriptorType = USB_DT_CONFIG, |
212 | 207 | ||
@@ -218,8 +213,7 @@ loopback_config = { | |||
218 | .bMaxPower = 1, /* self-powered */ | 213 | .bMaxPower = 1, /* self-powered */ |
219 | }; | 214 | }; |
220 | 215 | ||
221 | static struct usb_otg_descriptor | 216 | static struct usb_otg_descriptor otg_descriptor = { |
222 | otg_descriptor = { | ||
223 | .bLength = sizeof otg_descriptor, | 217 | .bLength = sizeof otg_descriptor, |
224 | .bDescriptorType = USB_DT_OTG, | 218 | .bDescriptorType = USB_DT_OTG, |
225 | 219 | ||
@@ -228,8 +222,7 @@ otg_descriptor = { | |||
228 | 222 | ||
229 | /* one interface in each configuration */ | 223 | /* one interface in each configuration */ |
230 | 224 | ||
231 | static const struct usb_interface_descriptor | 225 | static const struct usb_interface_descriptor source_sink_intf = { |
232 | source_sink_intf = { | ||
233 | .bLength = sizeof source_sink_intf, | 226 | .bLength = sizeof source_sink_intf, |
234 | .bDescriptorType = USB_DT_INTERFACE, | 227 | .bDescriptorType = USB_DT_INTERFACE, |
235 | 228 | ||
@@ -238,8 +231,7 @@ source_sink_intf = { | |||
238 | .iInterface = STRING_SOURCE_SINK, | 231 | .iInterface = STRING_SOURCE_SINK, |
239 | }; | 232 | }; |
240 | 233 | ||
241 | static const struct usb_interface_descriptor | 234 | static const struct usb_interface_descriptor loopback_intf = { |
242 | loopback_intf = { | ||
243 | .bLength = sizeof loopback_intf, | 235 | .bLength = sizeof loopback_intf, |
244 | .bDescriptorType = USB_DT_INTERFACE, | 236 | .bDescriptorType = USB_DT_INTERFACE, |
245 | 237 | ||
@@ -250,8 +242,7 @@ loopback_intf = { | |||
250 | 242 | ||
251 | /* two full speed bulk endpoints; their use is config-dependent */ | 243 | /* two full speed bulk endpoints; their use is config-dependent */ |
252 | 244 | ||
253 | static struct usb_endpoint_descriptor | 245 | static struct usb_endpoint_descriptor fs_source_desc = { |
254 | fs_source_desc = { | ||
255 | .bLength = USB_DT_ENDPOINT_SIZE, | 246 | .bLength = USB_DT_ENDPOINT_SIZE, |
256 | .bDescriptorType = USB_DT_ENDPOINT, | 247 | .bDescriptorType = USB_DT_ENDPOINT, |
257 | 248 | ||
@@ -259,8 +250,7 @@ fs_source_desc = { | |||
259 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 250 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
260 | }; | 251 | }; |
261 | 252 | ||
262 | static struct usb_endpoint_descriptor | 253 | static struct usb_endpoint_descriptor fs_sink_desc = { |
263 | fs_sink_desc = { | ||
264 | .bLength = USB_DT_ENDPOINT_SIZE, | 254 | .bLength = USB_DT_ENDPOINT_SIZE, |
265 | .bDescriptorType = USB_DT_ENDPOINT, | 255 | .bDescriptorType = USB_DT_ENDPOINT, |
266 | 256 | ||
@@ -268,7 +258,7 @@ fs_sink_desc = { | |||
268 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 258 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
269 | }; | 259 | }; |
270 | 260 | ||
271 | static const struct usb_descriptor_header *fs_source_sink_function [] = { | 261 | static const struct usb_descriptor_header *fs_source_sink_function[] = { |
272 | (struct usb_descriptor_header *) &otg_descriptor, | 262 | (struct usb_descriptor_header *) &otg_descriptor, |
273 | (struct usb_descriptor_header *) &source_sink_intf, | 263 | (struct usb_descriptor_header *) &source_sink_intf, |
274 | (struct usb_descriptor_header *) &fs_sink_desc, | 264 | (struct usb_descriptor_header *) &fs_sink_desc, |
@@ -276,7 +266,7 @@ static const struct usb_descriptor_header *fs_source_sink_function [] = { | |||
276 | NULL, | 266 | NULL, |
277 | }; | 267 | }; |
278 | 268 | ||
279 | static const struct usb_descriptor_header *fs_loopback_function [] = { | 269 | static const struct usb_descriptor_header *fs_loopback_function[] = { |
280 | (struct usb_descriptor_header *) &otg_descriptor, | 270 | (struct usb_descriptor_header *) &otg_descriptor, |
281 | (struct usb_descriptor_header *) &loopback_intf, | 271 | (struct usb_descriptor_header *) &loopback_intf, |
282 | (struct usb_descriptor_header *) &fs_sink_desc, | 272 | (struct usb_descriptor_header *) &fs_sink_desc, |
@@ -293,36 +283,33 @@ static const struct usb_descriptor_header *fs_loopback_function [] = { | |||
293 | * for the config descriptor. | 283 | * for the config descriptor. |
294 | */ | 284 | */ |
295 | 285 | ||
296 | static struct usb_endpoint_descriptor | 286 | static struct usb_endpoint_descriptor hs_source_desc = { |
297 | hs_source_desc = { | ||
298 | .bLength = USB_DT_ENDPOINT_SIZE, | 287 | .bLength = USB_DT_ENDPOINT_SIZE, |
299 | .bDescriptorType = USB_DT_ENDPOINT, | 288 | .bDescriptorType = USB_DT_ENDPOINT, |
300 | 289 | ||
301 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 290 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
302 | .wMaxPacketSize = __constant_cpu_to_le16 (512), | 291 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
303 | }; | 292 | }; |
304 | 293 | ||
305 | static struct usb_endpoint_descriptor | 294 | static struct usb_endpoint_descriptor hs_sink_desc = { |
306 | hs_sink_desc = { | ||
307 | .bLength = USB_DT_ENDPOINT_SIZE, | 295 | .bLength = USB_DT_ENDPOINT_SIZE, |
308 | .bDescriptorType = USB_DT_ENDPOINT, | 296 | .bDescriptorType = USB_DT_ENDPOINT, |
309 | 297 | ||
310 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 298 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
311 | .wMaxPacketSize = __constant_cpu_to_le16 (512), | 299 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
312 | }; | 300 | }; |
313 | 301 | ||
314 | static struct usb_qualifier_descriptor | 302 | static struct usb_qualifier_descriptor dev_qualifier = { |
315 | dev_qualifier = { | ||
316 | .bLength = sizeof dev_qualifier, | 303 | .bLength = sizeof dev_qualifier, |
317 | .bDescriptorType = USB_DT_DEVICE_QUALIFIER, | 304 | .bDescriptorType = USB_DT_DEVICE_QUALIFIER, |
318 | 305 | ||
319 | .bcdUSB = __constant_cpu_to_le16 (0x0200), | 306 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
320 | .bDeviceClass = USB_CLASS_VENDOR_SPEC, | 307 | .bDeviceClass = USB_CLASS_VENDOR_SPEC, |
321 | 308 | ||
322 | .bNumConfigurations = 2, | 309 | .bNumConfigurations = 2, |
323 | }; | 310 | }; |
324 | 311 | ||
325 | static const struct usb_descriptor_header *hs_source_sink_function [] = { | 312 | static const struct usb_descriptor_header *hs_source_sink_function[] = { |
326 | (struct usb_descriptor_header *) &otg_descriptor, | 313 | (struct usb_descriptor_header *) &otg_descriptor, |
327 | (struct usb_descriptor_header *) &source_sink_intf, | 314 | (struct usb_descriptor_header *) &source_sink_intf, |
328 | (struct usb_descriptor_header *) &hs_source_desc, | 315 | (struct usb_descriptor_header *) &hs_source_desc, |
@@ -330,7 +317,7 @@ static const struct usb_descriptor_header *hs_source_sink_function [] = { | |||
330 | NULL, | 317 | NULL, |
331 | }; | 318 | }; |
332 | 319 | ||
333 | static const struct usb_descriptor_header *hs_loopback_function [] = { | 320 | static const struct usb_descriptor_header *hs_loopback_function[] = { |
334 | (struct usb_descriptor_header *) &otg_descriptor, | 321 | (struct usb_descriptor_header *) &otg_descriptor, |
335 | (struct usb_descriptor_header *) &loopback_intf, | 322 | (struct usb_descriptor_header *) &loopback_intf, |
336 | (struct usb_descriptor_header *) &hs_source_desc, | 323 | (struct usb_descriptor_header *) &hs_source_desc, |
@@ -355,7 +342,7 @@ static char serial[] = "0123456789.0123456789.0123456789"; | |||
355 | 342 | ||
356 | 343 | ||
357 | /* static strings, in UTF-8 */ | 344 | /* static strings, in UTF-8 */ |
358 | static struct usb_string strings [] = { | 345 | static struct usb_string strings[] = { |
359 | { STRING_MANUFACTURER, manufacturer, }, | 346 | { STRING_MANUFACTURER, manufacturer, }, |
360 | { STRING_PRODUCT, longname, }, | 347 | { STRING_PRODUCT, longname, }, |
361 | { STRING_SERIAL, serial, }, | 348 | { STRING_SERIAL, serial, }, |
@@ -364,7 +351,7 @@ static struct usb_string strings [] = { | |||
364 | { } /* end of list */ | 351 | { } /* end of list */ |
365 | }; | 352 | }; |
366 | 353 | ||
367 | static struct usb_gadget_strings stringtab = { | 354 | static struct usb_gadget_strings stringtab = { |
368 | .language = 0x0409, /* en-us */ | 355 | .language = 0x0409, /* en-us */ |
369 | .strings = strings, | 356 | .strings = strings, |
370 | }; | 357 | }; |
@@ -387,8 +374,7 @@ static struct usb_gadget_strings stringtab = { | |||
387 | * high bandwidth modes at high speed. (Maybe work like Intel's test | 374 | * high bandwidth modes at high speed. (Maybe work like Intel's test |
388 | * device?) | 375 | * device?) |
389 | */ | 376 | */ |
390 | static int | 377 | static int config_buf(struct usb_gadget *gadget, |
391 | config_buf (struct usb_gadget *gadget, | ||
392 | u8 *buf, u8 type, unsigned index) | 378 | u8 *buf, u8 type, unsigned index) |
393 | { | 379 | { |
394 | int is_source_sink; | 380 | int is_source_sink; |
@@ -419,7 +405,7 @@ config_buf (struct usb_gadget *gadget, | |||
419 | if (!gadget_is_otg(gadget)) | 405 | if (!gadget_is_otg(gadget)) |
420 | function++; | 406 | function++; |
421 | 407 | ||
422 | len = usb_gadget_config_buf (is_source_sink | 408 | len = usb_gadget_config_buf(is_source_sink |
423 | ? &source_sink_config | 409 | ? &source_sink_config |
424 | : &loopback_config, | 410 | : &loopback_config, |
425 | buf, USB_BUFSIZ, function); | 411 | buf, USB_BUFSIZ, function); |
@@ -431,27 +417,26 @@ config_buf (struct usb_gadget *gadget, | |||
431 | 417 | ||
432 | /*-------------------------------------------------------------------------*/ | 418 | /*-------------------------------------------------------------------------*/ |
433 | 419 | ||
434 | static struct usb_request * | 420 | static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) |
435 | alloc_ep_req (struct usb_ep *ep, unsigned length) | ||
436 | { | 421 | { |
437 | struct usb_request *req; | 422 | struct usb_request *req; |
438 | 423 | ||
439 | req = usb_ep_alloc_request (ep, GFP_ATOMIC); | 424 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); |
440 | if (req) { | 425 | if (req) { |
441 | req->length = length; | 426 | req->length = length; |
442 | req->buf = kmalloc(length, GFP_ATOMIC); | 427 | req->buf = kmalloc(length, GFP_ATOMIC); |
443 | if (!req->buf) { | 428 | if (!req->buf) { |
444 | usb_ep_free_request (ep, req); | 429 | usb_ep_free_request(ep, req); |
445 | req = NULL; | 430 | req = NULL; |
446 | } | 431 | } |
447 | } | 432 | } |
448 | return req; | 433 | return req; |
449 | } | 434 | } |
450 | 435 | ||
451 | static void free_ep_req (struct usb_ep *ep, struct usb_request *req) | 436 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) |
452 | { | 437 | { |
453 | kfree(req->buf); | 438 | kfree(req->buf); |
454 | usb_ep_free_request (ep, req); | 439 | usb_ep_free_request(ep, req); |
455 | } | 440 | } |
456 | 441 | ||
457 | /*-------------------------------------------------------------------------*/ | 442 | /*-------------------------------------------------------------------------*/ |
@@ -472,7 +457,7 @@ static void free_ep_req (struct usb_ep *ep, struct usb_request *req) | |||
472 | /* optionally require specific source/sink data patterns */ | 457 | /* optionally require specific source/sink data patterns */ |
473 | 458 | ||
474 | static int | 459 | static int |
475 | check_read_data ( | 460 | check_read_data( |
476 | struct zero_dev *dev, | 461 | struct zero_dev *dev, |
477 | struct usb_ep *ep, | 462 | struct usb_ep *ep, |
478 | struct usb_request *req | 463 | struct usb_request *req |
@@ -498,8 +483,8 @@ check_read_data ( | |||
498 | continue; | 483 | continue; |
499 | break; | 484 | break; |
500 | } | 485 | } |
501 | ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf); | 486 | ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf); |
502 | usb_ep_set_halt (ep); | 487 | usb_ep_set_halt(ep); |
503 | return -EINVAL; | 488 | return -EINVAL; |
504 | } | 489 | } |
505 | return 0; | 490 | return 0; |
@@ -512,7 +497,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) | |||
512 | 497 | ||
513 | switch (pattern) { | 498 | switch (pattern) { |
514 | case 0: | 499 | case 0: |
515 | memset (req->buf, 0, req->length); | 500 | memset(req->buf, 0, req->length); |
516 | break; | 501 | break; |
517 | case 1: | 502 | case 1: |
518 | for (i = 0; i < req->length; i++) | 503 | for (i = 0; i < req->length; i++) |
@@ -525,7 +510,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) | |||
525 | * irq delay between end of one request and start of the next. | 510 | * irq delay between end of one request and start of the next. |
526 | * that prevents using hardware dma queues. | 511 | * that prevents using hardware dma queues. |
527 | */ | 512 | */ |
528 | static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) | 513 | static void source_sink_complete(struct usb_ep *ep, struct usb_request *req) |
529 | { | 514 | { |
530 | struct zero_dev *dev = ep->driver_data; | 515 | struct zero_dev *dev = ep->driver_data; |
531 | int status = req->status; | 516 | int status = req->status; |
@@ -534,8 +519,8 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) | |||
534 | 519 | ||
535 | case 0: /* normal completion? */ | 520 | case 0: /* normal completion? */ |
536 | if (ep == dev->out_ep) { | 521 | if (ep == dev->out_ep) { |
537 | check_read_data (dev, ep, req); | 522 | check_read_data(dev, ep, req); |
538 | memset (req->buf, 0x55, req->length); | 523 | memset(req->buf, 0x55, req->length); |
539 | } else | 524 | } else |
540 | reinit_write_data(ep, req); | 525 | reinit_write_data(ep, req); |
541 | break; | 526 | break; |
@@ -544,11 +529,11 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) | |||
544 | case -ECONNABORTED: /* hardware forced ep reset */ | 529 | case -ECONNABORTED: /* hardware forced ep reset */ |
545 | case -ECONNRESET: /* request dequeued */ | 530 | case -ECONNRESET: /* request dequeued */ |
546 | case -ESHUTDOWN: /* disconnect from host */ | 531 | case -ESHUTDOWN: /* disconnect from host */ |
547 | VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status, | 532 | VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status, |
548 | req->actual, req->length); | 533 | req->actual, req->length); |
549 | if (ep == dev->out_ep) | 534 | if (ep == dev->out_ep) |
550 | check_read_data (dev, ep, req); | 535 | check_read_data(dev, ep, req); |
551 | free_ep_req (ep, req); | 536 | free_ep_req(ep, req); |
552 | return; | 537 | return; |
553 | 538 | ||
554 | case -EOVERFLOW: /* buffer overrun on read means that | 539 | case -EOVERFLOW: /* buffer overrun on read means that |
@@ -557,18 +542,18 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) | |||
557 | */ | 542 | */ |
558 | default: | 543 | default: |
559 | #if 1 | 544 | #if 1 |
560 | DBG (dev, "%s complete --> %d, %d/%d\n", ep->name, | 545 | DBG(dev, "%s complete --> %d, %d/%d\n", ep->name, |
561 | status, req->actual, req->length); | 546 | status, req->actual, req->length); |
562 | #endif | 547 | #endif |
563 | case -EREMOTEIO: /* short read */ | 548 | case -EREMOTEIO: /* short read */ |
564 | break; | 549 | break; |
565 | } | 550 | } |
566 | 551 | ||
567 | status = usb_ep_queue (ep, req, GFP_ATOMIC); | 552 | status = usb_ep_queue(ep, req, GFP_ATOMIC); |
568 | if (status) { | 553 | if (status) { |
569 | ERROR (dev, "kill %s: resubmit %d bytes --> %d\n", | 554 | ERROR(dev, "kill %s: resubmit %d bytes --> %d\n", |
570 | ep->name, req->length, status); | 555 | ep->name, req->length, status); |
571 | usb_ep_set_halt (ep); | 556 | usb_ep_set_halt(ep); |
572 | /* FIXME recover later ... somehow */ | 557 | /* FIXME recover later ... somehow */ |
573 | } | 558 | } |
574 | } | 559 | } |
@@ -578,24 +563,24 @@ static struct usb_request *source_sink_start_ep(struct usb_ep *ep) | |||
578 | struct usb_request *req; | 563 | struct usb_request *req; |
579 | int status; | 564 | int status; |
580 | 565 | ||
581 | req = alloc_ep_req (ep, buflen); | 566 | req = alloc_ep_req(ep, buflen); |
582 | if (!req) | 567 | if (!req) |
583 | return NULL; | 568 | return NULL; |
584 | 569 | ||
585 | memset (req->buf, 0, req->length); | 570 | memset(req->buf, 0, req->length); |
586 | req->complete = source_sink_complete; | 571 | req->complete = source_sink_complete; |
587 | 572 | ||
588 | if (strcmp (ep->name, EP_IN_NAME) == 0) | 573 | if (strcmp(ep->name, EP_IN_NAME) == 0) |
589 | reinit_write_data(ep, req); | 574 | reinit_write_data(ep, req); |
590 | else | 575 | else |
591 | memset (req->buf, 0x55, req->length); | 576 | memset(req->buf, 0x55, req->length); |
592 | 577 | ||
593 | status = usb_ep_queue(ep, req, GFP_ATOMIC); | 578 | status = usb_ep_queue(ep, req, GFP_ATOMIC); |
594 | if (status) { | 579 | if (status) { |
595 | struct zero_dev *dev = ep->driver_data; | 580 | struct zero_dev *dev = ep->driver_data; |
596 | 581 | ||
597 | ERROR (dev, "start %s --> %d\n", ep->name, status); | 582 | ERROR(dev, "start %s --> %d\n", ep->name, status); |
598 | free_ep_req (ep, req); | 583 | free_ep_req(ep, req); |
599 | req = NULL; | 584 | req = NULL; |
600 | } | 585 | } |
601 | 586 | ||
@@ -608,34 +593,34 @@ static int set_source_sink_config(struct zero_dev *dev) | |||
608 | struct usb_ep *ep; | 593 | struct usb_ep *ep; |
609 | struct usb_gadget *gadget = dev->gadget; | 594 | struct usb_gadget *gadget = dev->gadget; |
610 | 595 | ||
611 | gadget_for_each_ep (ep, gadget) { | 596 | gadget_for_each_ep(ep, gadget) { |
612 | const struct usb_endpoint_descriptor *d; | 597 | const struct usb_endpoint_descriptor *d; |
613 | 598 | ||
614 | /* one endpoint writes (sources) zeroes in (to the host) */ | 599 | /* one endpoint writes (sources) zeroes in (to the host) */ |
615 | if (strcmp (ep->name, EP_IN_NAME) == 0) { | 600 | if (strcmp(ep->name, EP_IN_NAME) == 0) { |
616 | d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); | 601 | d = ep_desc(gadget, &hs_source_desc, &fs_source_desc); |
617 | result = usb_ep_enable (ep, d); | 602 | result = usb_ep_enable(ep, d); |
618 | if (result == 0) { | 603 | if (result == 0) { |
619 | ep->driver_data = dev; | 604 | ep->driver_data = dev; |
620 | if (source_sink_start_ep(ep) != NULL) { | 605 | if (source_sink_start_ep(ep) != NULL) { |
621 | dev->in_ep = ep; | 606 | dev->in_ep = ep; |
622 | continue; | 607 | continue; |
623 | } | 608 | } |
624 | usb_ep_disable (ep); | 609 | usb_ep_disable(ep); |
625 | result = -EIO; | 610 | result = -EIO; |
626 | } | 611 | } |
627 | 612 | ||
628 | /* one endpoint reads (sinks) anything out (from the host) */ | 613 | /* one endpoint reads (sinks) anything out (from the host) */ |
629 | } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { | 614 | } else if (strcmp(ep->name, EP_OUT_NAME) == 0) { |
630 | d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); | 615 | d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc); |
631 | result = usb_ep_enable (ep, d); | 616 | result = usb_ep_enable(ep, d); |
632 | if (result == 0) { | 617 | if (result == 0) { |
633 | ep->driver_data = dev; | 618 | ep->driver_data = dev; |
634 | if (source_sink_start_ep(ep) != NULL) { | 619 | if (source_sink_start_ep(ep) != NULL) { |
635 | dev->out_ep = ep; | 620 | dev->out_ep = ep; |
636 | continue; | 621 | continue; |
637 | } | 622 | } |
638 | usb_ep_disable (ep); | 623 | usb_ep_disable(ep); |
639 | result = -EIO; | 624 | result = -EIO; |
640 | } | 625 | } |
641 | 626 | ||
@@ -644,11 +629,11 @@ static int set_source_sink_config(struct zero_dev *dev) | |||
644 | continue; | 629 | continue; |
645 | 630 | ||
646 | /* stop on error */ | 631 | /* stop on error */ |
647 | ERROR (dev, "can't start %s, result %d\n", ep->name, result); | 632 | ERROR(dev, "can't start %s, result %d\n", ep->name, result); |
648 | break; | 633 | break; |
649 | } | 634 | } |
650 | if (result == 0) | 635 | if (result == 0) |
651 | DBG (dev, "buflen %d\n", buflen); | 636 | DBG(dev, "buflen %d\n", buflen); |
652 | 637 | ||
653 | /* caller is responsible for cleanup on error */ | 638 | /* caller is responsible for cleanup on error */ |
654 | return result; | 639 | return result; |
@@ -656,7 +641,7 @@ static int set_source_sink_config(struct zero_dev *dev) | |||
656 | 641 | ||
657 | /*-------------------------------------------------------------------------*/ | 642 | /*-------------------------------------------------------------------------*/ |
658 | 643 | ||
659 | static void loopback_complete (struct usb_ep *ep, struct usb_request *req) | 644 | static void loopback_complete(struct usb_ep *ep, struct usb_request *req) |
660 | { | 645 | { |
661 | struct zero_dev *dev = ep->driver_data; | 646 | struct zero_dev *dev = ep->driver_data; |
662 | int status = req->status; | 647 | int status = req->status; |
@@ -668,19 +653,19 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req) | |||
668 | /* loop this OUT packet back IN to the host */ | 653 | /* loop this OUT packet back IN to the host */ |
669 | req->zero = (req->actual < req->length); | 654 | req->zero = (req->actual < req->length); |
670 | req->length = req->actual; | 655 | req->length = req->actual; |
671 | status = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC); | 656 | status = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); |
672 | if (status == 0) | 657 | if (status == 0) |
673 | return; | 658 | return; |
674 | 659 | ||
675 | /* "should never get here" */ | 660 | /* "should never get here" */ |
676 | ERROR (dev, "can't loop %s to %s: %d\n", | 661 | ERROR(dev, "can't loop %s to %s: %d\n", |
677 | ep->name, dev->in_ep->name, | 662 | ep->name, dev->in_ep->name, |
678 | status); | 663 | status); |
679 | } | 664 | } |
680 | 665 | ||
681 | /* queue the buffer for some later OUT packet */ | 666 | /* queue the buffer for some later OUT packet */ |
682 | req->length = buflen; | 667 | req->length = buflen; |
683 | status = usb_ep_queue (dev->out_ep, req, GFP_ATOMIC); | 668 | status = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC); |
684 | if (status == 0) | 669 | if (status == 0) |
685 | return; | 670 | return; |
686 | 671 | ||
@@ -688,7 +673,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req) | |||
688 | /* FALLTHROUGH */ | 673 | /* FALLTHROUGH */ |
689 | 674 | ||
690 | default: | 675 | default: |
691 | ERROR (dev, "%s loop complete --> %d, %d/%d\n", ep->name, | 676 | ERROR(dev, "%s loop complete --> %d, %d/%d\n", ep->name, |
692 | status, req->actual, req->length); | 677 | status, req->actual, req->length); |
693 | /* FALLTHROUGH */ | 678 | /* FALLTHROUGH */ |
694 | 679 | ||
@@ -700,7 +685,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req) | |||
700 | case -ECONNABORTED: /* hardware forced ep reset */ | 685 | case -ECONNABORTED: /* hardware forced ep reset */ |
701 | case -ECONNRESET: /* request dequeued */ | 686 | case -ECONNRESET: /* request dequeued */ |
702 | case -ESHUTDOWN: /* disconnect from host */ | 687 | case -ESHUTDOWN: /* disconnect from host */ |
703 | free_ep_req (ep, req); | 688 | free_ep_req(ep, req); |
704 | return; | 689 | return; |
705 | } | 690 | } |
706 | } | 691 | } |
@@ -711,13 +696,13 @@ static int set_loopback_config(struct zero_dev *dev) | |||
711 | struct usb_ep *ep; | 696 | struct usb_ep *ep; |
712 | struct usb_gadget *gadget = dev->gadget; | 697 | struct usb_gadget *gadget = dev->gadget; |
713 | 698 | ||
714 | gadget_for_each_ep (ep, gadget) { | 699 | gadget_for_each_ep(ep, gadget) { |
715 | const struct usb_endpoint_descriptor *d; | 700 | const struct usb_endpoint_descriptor *d; |
716 | 701 | ||
717 | /* one endpoint writes data back IN to the host */ | 702 | /* one endpoint writes data back IN to the host */ |
718 | if (strcmp (ep->name, EP_IN_NAME) == 0) { | 703 | if (strcmp(ep->name, EP_IN_NAME) == 0) { |
719 | d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); | 704 | d = ep_desc(gadget, &hs_source_desc, &fs_source_desc); |
720 | result = usb_ep_enable (ep, d); | 705 | result = usb_ep_enable(ep, d); |
721 | if (result == 0) { | 706 | if (result == 0) { |
722 | ep->driver_data = dev; | 707 | ep->driver_data = dev; |
723 | dev->in_ep = ep; | 708 | dev->in_ep = ep; |
@@ -725,9 +710,9 @@ static int set_loopback_config(struct zero_dev *dev) | |||
725 | } | 710 | } |
726 | 711 | ||
727 | /* one endpoint just reads OUT packets */ | 712 | /* one endpoint just reads OUT packets */ |
728 | } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { | 713 | } else if (strcmp(ep->name, EP_OUT_NAME) == 0) { |
729 | d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); | 714 | d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc); |
730 | result = usb_ep_enable (ep, d); | 715 | result = usb_ep_enable(ep, d); |
731 | if (result == 0) { | 716 | if (result == 0) { |
732 | ep->driver_data = dev; | 717 | ep->driver_data = dev; |
733 | dev->out_ep = ep; | 718 | dev->out_ep = ep; |
@@ -739,7 +724,7 @@ static int set_loopback_config(struct zero_dev *dev) | |||
739 | continue; | 724 | continue; |
740 | 725 | ||
741 | /* stop on error */ | 726 | /* stop on error */ |
742 | ERROR (dev, "can't enable %s, result %d\n", ep->name, result); | 727 | ERROR(dev, "can't enable %s, result %d\n", ep->name, result); |
743 | break; | 728 | break; |
744 | } | 729 | } |
745 | 730 | ||
@@ -753,19 +738,19 @@ static int set_loopback_config(struct zero_dev *dev) | |||
753 | 738 | ||
754 | ep = dev->out_ep; | 739 | ep = dev->out_ep; |
755 | for (i = 0; i < qlen && result == 0; i++) { | 740 | for (i = 0; i < qlen && result == 0; i++) { |
756 | req = alloc_ep_req (ep, buflen); | 741 | req = alloc_ep_req(ep, buflen); |
757 | if (req) { | 742 | if (req) { |
758 | req->complete = loopback_complete; | 743 | req->complete = loopback_complete; |
759 | result = usb_ep_queue (ep, req, GFP_ATOMIC); | 744 | result = usb_ep_queue(ep, req, GFP_ATOMIC); |
760 | if (result) | 745 | if (result) |
761 | DBG (dev, "%s queue req --> %d\n", | 746 | DBG(dev, "%s queue req --> %d\n", |
762 | ep->name, result); | 747 | ep->name, result); |
763 | } else | 748 | } else |
764 | result = -ENOMEM; | 749 | result = -ENOMEM; |
765 | } | 750 | } |
766 | } | 751 | } |
767 | if (result == 0) | 752 | if (result == 0) |
768 | DBG (dev, "qlen %d, buflen %d\n", qlen, buflen); | 753 | DBG(dev, "qlen %d, buflen %d\n", qlen, buflen); |
769 | 754 | ||
770 | /* caller is responsible for cleanup on error */ | 755 | /* caller is responsible for cleanup on error */ |
771 | return result; | 756 | return result; |
@@ -773,26 +758,26 @@ static int set_loopback_config(struct zero_dev *dev) | |||
773 | 758 | ||
774 | /*-------------------------------------------------------------------------*/ | 759 | /*-------------------------------------------------------------------------*/ |
775 | 760 | ||
776 | static void zero_reset_config (struct zero_dev *dev) | 761 | static void zero_reset_config(struct zero_dev *dev) |
777 | { | 762 | { |
778 | if (dev->config == 0) | 763 | if (dev->config == 0) |
779 | return; | 764 | return; |
780 | 765 | ||
781 | DBG (dev, "reset config\n"); | 766 | DBG(dev, "reset config\n"); |
782 | 767 | ||
783 | /* just disable endpoints, forcing completion of pending i/o. | 768 | /* just disable endpoints, forcing completion of pending i/o. |
784 | * all our completion handlers free their requests in this case. | 769 | * all our completion handlers free their requests in this case. |
785 | */ | 770 | */ |
786 | if (dev->in_ep) { | 771 | if (dev->in_ep) { |
787 | usb_ep_disable (dev->in_ep); | 772 | usb_ep_disable(dev->in_ep); |
788 | dev->in_ep = NULL; | 773 | dev->in_ep = NULL; |
789 | } | 774 | } |
790 | if (dev->out_ep) { | 775 | if (dev->out_ep) { |
791 | usb_ep_disable (dev->out_ep); | 776 | usb_ep_disable(dev->out_ep); |
792 | dev->out_ep = NULL; | 777 | dev->out_ep = NULL; |
793 | } | 778 | } |
794 | dev->config = 0; | 779 | dev->config = 0; |
795 | del_timer (&dev->resume); | 780 | del_timer(&dev->resume); |
796 | } | 781 | } |
797 | 782 | ||
798 | /* change our operational config. this code must agree with the code | 783 | /* change our operational config. this code must agree with the code |
@@ -813,12 +798,12 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) | |||
813 | if (number == dev->config) | 798 | if (number == dev->config) |
814 | return 0; | 799 | return 0; |
815 | 800 | ||
816 | if (gadget_is_sa1100 (gadget) && dev->config) { | 801 | if (gadget_is_sa1100(gadget) && dev->config) { |
817 | /* tx fifo is full, but we can't clear it...*/ | 802 | /* tx fifo is full, but we can't clear it...*/ |
818 | ERROR(dev, "can't change configurations\n"); | 803 | ERROR(dev, "can't change configurations\n"); |
819 | return -ESPIPE; | 804 | return -ESPIPE; |
820 | } | 805 | } |
821 | zero_reset_config (dev); | 806 | zero_reset_config(dev); |
822 | 807 | ||
823 | switch (number) { | 808 | switch (number) { |
824 | case CONFIG_SOURCE_SINK: | 809 | case CONFIG_SOURCE_SINK: |
@@ -837,7 +822,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) | |||
837 | if (!result && (!dev->in_ep || !dev->out_ep)) | 822 | if (!result && (!dev->in_ep || !dev->out_ep)) |
838 | result = -ENODEV; | 823 | result = -ENODEV; |
839 | if (result) | 824 | if (result) |
840 | zero_reset_config (dev); | 825 | zero_reset_config(dev); |
841 | else { | 826 | else { |
842 | char *speed; | 827 | char *speed; |
843 | 828 | ||
@@ -849,7 +834,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) | |||
849 | } | 834 | } |
850 | 835 | ||
851 | dev->config = number; | 836 | dev->config = number; |
852 | INFO (dev, "%s speed config #%d: %s\n", speed, number, | 837 | INFO(dev, "%s speed config #%d: %s\n", speed, number, |
853 | (number == CONFIG_SOURCE_SINK) | 838 | (number == CONFIG_SOURCE_SINK) |
854 | ? source_sink : loopback); | 839 | ? source_sink : loopback); |
855 | } | 840 | } |
@@ -858,10 +843,10 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) | |||
858 | 843 | ||
859 | /*-------------------------------------------------------------------------*/ | 844 | /*-------------------------------------------------------------------------*/ |
860 | 845 | ||
861 | static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) | 846 | static void zero_setup_complete(struct usb_ep *ep, struct usb_request *req) |
862 | { | 847 | { |
863 | if (req->status || req->actual != req->length) | 848 | if (req->status || req->actual != req->length) |
864 | DBG ((struct zero_dev *) ep->driver_data, | 849 | DBG((struct zero_dev *) ep->driver_data, |
865 | "setup complete --> %d, %d/%d\n", | 850 | "setup complete --> %d, %d/%d\n", |
866 | req->status, req->actual, req->length); | 851 | req->status, req->actual, req->length); |
867 | } | 852 | } |
@@ -874,9 +859,9 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) | |||
874 | * the work is in config-specific setup. | 859 | * the work is in config-specific setup. |
875 | */ | 860 | */ |
876 | static int | 861 | static int |
877 | zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | 862 | zero_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) |
878 | { | 863 | { |
879 | struct zero_dev *dev = get_gadget_data (gadget); | 864 | struct zero_dev *dev = get_gadget_data(gadget); |
880 | struct usb_request *req = dev->req; | 865 | struct usb_request *req = dev->req; |
881 | int value = -EOPNOTSUPP; | 866 | int value = -EOPNOTSUPP; |
882 | u16 w_index = le16_to_cpu(ctrl->wIndex); | 867 | u16 w_index = le16_to_cpu(ctrl->wIndex); |
@@ -895,14 +880,14 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
895 | switch (w_value >> 8) { | 880 | switch (w_value >> 8) { |
896 | 881 | ||
897 | case USB_DT_DEVICE: | 882 | case USB_DT_DEVICE: |
898 | value = min (w_length, (u16) sizeof device_desc); | 883 | value = min(w_length, (u16) sizeof device_desc); |
899 | memcpy (req->buf, &device_desc, value); | 884 | memcpy(req->buf, &device_desc, value); |
900 | break; | 885 | break; |
901 | case USB_DT_DEVICE_QUALIFIER: | 886 | case USB_DT_DEVICE_QUALIFIER: |
902 | if (!gadget_is_dualspeed(gadget)) | 887 | if (!gadget_is_dualspeed(gadget)) |
903 | break; | 888 | break; |
904 | value = min (w_length, (u16) sizeof dev_qualifier); | 889 | value = min(w_length, (u16) sizeof dev_qualifier); |
905 | memcpy (req->buf, &dev_qualifier, value); | 890 | memcpy(req->buf, &dev_qualifier, value); |
906 | break; | 891 | break; |
907 | 892 | ||
908 | case USB_DT_OTHER_SPEED_CONFIG: | 893 | case USB_DT_OTHER_SPEED_CONFIG: |
@@ -910,11 +895,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
910 | break; | 895 | break; |
911 | // FALLTHROUGH | 896 | // FALLTHROUGH |
912 | case USB_DT_CONFIG: | 897 | case USB_DT_CONFIG: |
913 | value = config_buf (gadget, req->buf, | 898 | value = config_buf(gadget, req->buf, |
914 | w_value >> 8, | 899 | w_value >> 8, |
915 | w_value & 0xff); | 900 | w_value & 0xff); |
916 | if (value >= 0) | 901 | if (value >= 0) |
917 | value = min (w_length, (u16) value); | 902 | value = min(w_length, (u16) value); |
918 | break; | 903 | break; |
919 | 904 | ||
920 | case USB_DT_STRING: | 905 | case USB_DT_STRING: |
@@ -923,10 +908,10 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
923 | * add string tables for other languages, using | 908 | * add string tables for other languages, using |
924 | * any UTF-8 characters | 909 | * any UTF-8 characters |
925 | */ | 910 | */ |
926 | value = usb_gadget_get_string (&stringtab, | 911 | value = usb_gadget_get_string(&stringtab, |
927 | w_value & 0xff, req->buf); | 912 | w_value & 0xff, req->buf); |
928 | if (value >= 0) | 913 | if (value >= 0) |
929 | value = min (w_length, (u16) value); | 914 | value = min(w_length, (u16) value); |
930 | break; | 915 | break; |
931 | } | 916 | } |
932 | break; | 917 | break; |
@@ -936,20 +921,20 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
936 | if (ctrl->bRequestType != 0) | 921 | if (ctrl->bRequestType != 0) |
937 | goto unknown; | 922 | goto unknown; |
938 | if (gadget->a_hnp_support) | 923 | if (gadget->a_hnp_support) |
939 | DBG (dev, "HNP available\n"); | 924 | DBG(dev, "HNP available\n"); |
940 | else if (gadget->a_alt_hnp_support) | 925 | else if (gadget->a_alt_hnp_support) |
941 | DBG (dev, "HNP needs a different root port\n"); | 926 | DBG(dev, "HNP needs a different root port\n"); |
942 | else | 927 | else |
943 | VDBG (dev, "HNP inactive\n"); | 928 | VDBG(dev, "HNP inactive\n"); |
944 | spin_lock (&dev->lock); | 929 | spin_lock(&dev->lock); |
945 | value = zero_set_config(dev, w_value); | 930 | value = zero_set_config(dev, w_value); |
946 | spin_unlock (&dev->lock); | 931 | spin_unlock(&dev->lock); |
947 | break; | 932 | break; |
948 | case USB_REQ_GET_CONFIGURATION: | 933 | case USB_REQ_GET_CONFIGURATION: |
949 | if (ctrl->bRequestType != USB_DIR_IN) | 934 | if (ctrl->bRequestType != USB_DIR_IN) |
950 | goto unknown; | 935 | goto unknown; |
951 | *(u8 *)req->buf = dev->config; | 936 | *(u8 *)req->buf = dev->config; |
952 | value = min (w_length, (u16) 1); | 937 | value = min(w_length, (u16) 1); |
953 | break; | 938 | break; |
954 | 939 | ||
955 | /* until we add altsetting support, or other interfaces, | 940 | /* until we add altsetting support, or other interfaces, |
@@ -959,7 +944,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
959 | case USB_REQ_SET_INTERFACE: | 944 | case USB_REQ_SET_INTERFACE: |
960 | if (ctrl->bRequestType != USB_RECIP_INTERFACE) | 945 | if (ctrl->bRequestType != USB_RECIP_INTERFACE) |
961 | goto unknown; | 946 | goto unknown; |
962 | spin_lock (&dev->lock); | 947 | spin_lock(&dev->lock); |
963 | if (dev->config && w_index == 0 && w_value == 0) { | 948 | if (dev->config && w_index == 0 && w_value == 0) { |
964 | u8 config = dev->config; | 949 | u8 config = dev->config; |
965 | 950 | ||
@@ -970,11 +955,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
970 | * if we had more than one interface we couldn't | 955 | * if we had more than one interface we couldn't |
971 | * use this "reset the config" shortcut. | 956 | * use this "reset the config" shortcut. |
972 | */ | 957 | */ |
973 | zero_reset_config (dev); | 958 | zero_reset_config(dev); |
974 | zero_set_config(dev, config); | 959 | zero_set_config(dev, config); |
975 | value = 0; | 960 | value = 0; |
976 | } | 961 | } |
977 | spin_unlock (&dev->lock); | 962 | spin_unlock(&dev->lock); |
978 | break; | 963 | break; |
979 | case USB_REQ_GET_INTERFACE: | 964 | case USB_REQ_GET_INTERFACE: |
980 | if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) | 965 | if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) |
@@ -986,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
986 | break; | 971 | break; |
987 | } | 972 | } |
988 | *(u8 *)req->buf = 0; | 973 | *(u8 *)req->buf = 0; |
989 | value = min (w_length, (u16) 1); | 974 | value = min(w_length, (u16) 1); |
990 | break; | 975 | break; |
991 | 976 | ||
992 | /* | 977 | /* |
@@ -1018,7 +1003,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1018 | 1003 | ||
1019 | default: | 1004 | default: |
1020 | unknown: | 1005 | unknown: |
1021 | VDBG (dev, | 1006 | VDBG(dev, |
1022 | "unknown control req%02x.%02x v%04x i%04x l%d\n", | 1007 | "unknown control req%02x.%02x v%04x i%04x l%d\n", |
1023 | ctrl->bRequestType, ctrl->bRequest, | 1008 | ctrl->bRequestType, ctrl->bRequest, |
1024 | w_value, w_index, w_length); | 1009 | w_value, w_index, w_length); |
@@ -1028,11 +1013,11 @@ unknown: | |||
1028 | if (value >= 0) { | 1013 | if (value >= 0) { |
1029 | req->length = value; | 1014 | req->length = value; |
1030 | req->zero = value < w_length; | 1015 | req->zero = value < w_length; |
1031 | value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); | 1016 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); |
1032 | if (value < 0) { | 1017 | if (value < 0) { |
1033 | DBG (dev, "ep_queue --> %d\n", value); | 1018 | DBG(dev, "ep_queue --> %d\n", value); |
1034 | req->status = 0; | 1019 | req->status = 0; |
1035 | zero_setup_complete (gadget->ep0, req); | 1020 | zero_setup_complete(gadget->ep0, req); |
1036 | } | 1021 | } |
1037 | } | 1022 | } |
1038 | 1023 | ||
@@ -1040,28 +1025,26 @@ unknown: | |||
1040 | return value; | 1025 | return value; |
1041 | } | 1026 | } |
1042 | 1027 | ||
1043 | static void | 1028 | static void zero_disconnect(struct usb_gadget *gadget) |
1044 | zero_disconnect (struct usb_gadget *gadget) | ||
1045 | { | 1029 | { |
1046 | struct zero_dev *dev = get_gadget_data (gadget); | 1030 | struct zero_dev *dev = get_gadget_data(gadget); |
1047 | unsigned long flags; | 1031 | unsigned long flags; |
1048 | 1032 | ||
1049 | spin_lock_irqsave (&dev->lock, flags); | 1033 | spin_lock_irqsave(&dev->lock, flags); |
1050 | zero_reset_config (dev); | 1034 | zero_reset_config(dev); |
1051 | 1035 | ||
1052 | /* a more significant application might have some non-usb | 1036 | /* a more significant application might have some non-usb |
1053 | * activities to quiesce here, saving resources like power | 1037 | * activities to quiesce here, saving resources like power |
1054 | * or pushing the notification up a network stack. | 1038 | * or pushing the notification up a network stack. |
1055 | */ | 1039 | */ |
1056 | spin_unlock_irqrestore (&dev->lock, flags); | 1040 | spin_unlock_irqrestore(&dev->lock, flags); |
1057 | 1041 | ||
1058 | /* next we may get setup() calls to enumerate new connections; | 1042 | /* next we may get setup() calls to enumerate new connections; |
1059 | * or an unbind() during shutdown (including removing module). | 1043 | * or an unbind() during shutdown (including removing module). |
1060 | */ | 1044 | */ |
1061 | } | 1045 | } |
1062 | 1046 | ||
1063 | static void | 1047 | static void zero_autoresume(unsigned long _dev) |
1064 | zero_autoresume (unsigned long _dev) | ||
1065 | { | 1048 | { |
1066 | struct zero_dev *dev = (struct zero_dev *) _dev; | 1049 | struct zero_dev *dev = (struct zero_dev *) _dev; |
1067 | int status; | 1050 | int status; |
@@ -1070,32 +1053,30 @@ zero_autoresume (unsigned long _dev) | |||
1070 | * more significant than just a timer firing... | 1053 | * more significant than just a timer firing... |
1071 | */ | 1054 | */ |
1072 | if (dev->gadget->speed != USB_SPEED_UNKNOWN) { | 1055 | if (dev->gadget->speed != USB_SPEED_UNKNOWN) { |
1073 | status = usb_gadget_wakeup (dev->gadget); | 1056 | status = usb_gadget_wakeup(dev->gadget); |
1074 | DBG (dev, "wakeup --> %d\n", status); | 1057 | DBG(dev, "wakeup --> %d\n", status); |
1075 | } | 1058 | } |
1076 | } | 1059 | } |
1077 | 1060 | ||
1078 | /*-------------------------------------------------------------------------*/ | 1061 | /*-------------------------------------------------------------------------*/ |
1079 | 1062 | ||
1080 | static void /* __init_or_exit */ | 1063 | static void zero_unbind(struct usb_gadget *gadget) |
1081 | zero_unbind (struct usb_gadget *gadget) | ||
1082 | { | 1064 | { |
1083 | struct zero_dev *dev = get_gadget_data (gadget); | 1065 | struct zero_dev *dev = get_gadget_data(gadget); |
1084 | 1066 | ||
1085 | DBG (dev, "unbind\n"); | 1067 | DBG(dev, "unbind\n"); |
1086 | 1068 | ||
1087 | /* we've already been disconnected ... no i/o is active */ | 1069 | /* we've already been disconnected ... no i/o is active */ |
1088 | if (dev->req) { | 1070 | if (dev->req) { |
1089 | dev->req->length = USB_BUFSIZ; | 1071 | dev->req->length = USB_BUFSIZ; |
1090 | free_ep_req (gadget->ep0, dev->req); | 1072 | free_ep_req(gadget->ep0, dev->req); |
1091 | } | 1073 | } |
1092 | del_timer_sync (&dev->resume); | 1074 | del_timer_sync(&dev->resume); |
1093 | kfree (dev); | 1075 | kfree(dev); |
1094 | set_gadget_data (gadget, NULL); | 1076 | set_gadget_data(gadget, NULL); |
1095 | } | 1077 | } |
1096 | 1078 | ||
1097 | static int __init | 1079 | static int __init zero_bind(struct usb_gadget *gadget) |
1098 | zero_bind (struct usb_gadget *gadget) | ||
1099 | { | 1080 | { |
1100 | struct zero_dev *dev; | 1081 | struct zero_dev *dev; |
1101 | struct usb_ep *ep; | 1082 | struct usb_ep *ep; |
@@ -1111,8 +1092,8 @@ zero_bind (struct usb_gadget *gadget) | |||
1111 | * autoconfigure on any sane usb controller driver, | 1092 | * autoconfigure on any sane usb controller driver, |
1112 | * but there may also be important quirks to address. | 1093 | * but there may also be important quirks to address. |
1113 | */ | 1094 | */ |
1114 | usb_ep_autoconfig_reset (gadget); | 1095 | usb_ep_autoconfig_reset(gadget); |
1115 | ep = usb_ep_autoconfig (gadget, &fs_source_desc); | 1096 | ep = usb_ep_autoconfig(gadget, &fs_source_desc); |
1116 | if (!ep) { | 1097 | if (!ep) { |
1117 | autoconf_fail: | 1098 | autoconf_fail: |
1118 | pr_err("%s: can't autoconfigure on %s\n", | 1099 | pr_err("%s: can't autoconfigure on %s\n", |
@@ -1122,15 +1103,15 @@ autoconf_fail: | |||
1122 | EP_IN_NAME = ep->name; | 1103 | EP_IN_NAME = ep->name; |
1123 | ep->driver_data = ep; /* claim */ | 1104 | ep->driver_data = ep; /* claim */ |
1124 | 1105 | ||
1125 | ep = usb_ep_autoconfig (gadget, &fs_sink_desc); | 1106 | ep = usb_ep_autoconfig(gadget, &fs_sink_desc); |
1126 | if (!ep) | 1107 | if (!ep) |
1127 | goto autoconf_fail; | 1108 | goto autoconf_fail; |
1128 | EP_OUT_NAME = ep->name; | 1109 | EP_OUT_NAME = ep->name; |
1129 | ep->driver_data = ep; /* claim */ | 1110 | ep->driver_data = ep; /* claim */ |
1130 | 1111 | ||
1131 | gcnum = usb_gadget_controller_number (gadget); | 1112 | gcnum = usb_gadget_controller_number(gadget); |
1132 | if (gcnum >= 0) | 1113 | if (gcnum >= 0) |
1133 | device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum); | 1114 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); |
1134 | else { | 1115 | else { |
1135 | /* gadget zero is so simple (for now, no altsettings) that | 1116 | /* gadget zero is so simple (for now, no altsettings) that |
1136 | * it SHOULD NOT have problems with bulk-capable hardware. | 1117 | * it SHOULD NOT have problems with bulk-capable hardware. |
@@ -1141,7 +1122,7 @@ autoconf_fail: | |||
1141 | */ | 1122 | */ |
1142 | pr_warning("%s: controller '%s' not recognized\n", | 1123 | pr_warning("%s: controller '%s' not recognized\n", |
1143 | shortname, gadget->name); | 1124 | shortname, gadget->name); |
1144 | device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999); | 1125 | device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); |
1145 | } | 1126 | } |
1146 | 1127 | ||
1147 | 1128 | ||
@@ -1149,12 +1130,16 @@ autoconf_fail: | |||
1149 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 1130 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
1150 | if (!dev) | 1131 | if (!dev) |
1151 | return -ENOMEM; | 1132 | return -ENOMEM; |
1152 | spin_lock_init (&dev->lock); | 1133 | spin_lock_init(&dev->lock); |
1153 | dev->gadget = gadget; | 1134 | dev->gadget = gadget; |
1154 | set_gadget_data (gadget, dev); | 1135 | set_gadget_data(gadget, dev); |
1136 | |||
1137 | init_timer(&dev->resume); | ||
1138 | dev->resume.function = zero_autoresume; | ||
1139 | dev->resume.data = (unsigned long) dev; | ||
1155 | 1140 | ||
1156 | /* preallocate control response and buffer */ | 1141 | /* preallocate control response and buffer */ |
1157 | dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); | 1142 | dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); |
1158 | if (!dev->req) | 1143 | if (!dev->req) |
1159 | goto enomem; | 1144 | goto enomem; |
1160 | dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL); | 1145 | dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL); |
@@ -1182,11 +1167,8 @@ autoconf_fail: | |||
1182 | loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 1167 | loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
1183 | } | 1168 | } |
1184 | 1169 | ||
1185 | usb_gadget_set_selfpowered (gadget); | 1170 | usb_gadget_set_selfpowered(gadget); |
1186 | 1171 | ||
1187 | init_timer (&dev->resume); | ||
1188 | dev->resume.function = zero_autoresume; | ||
1189 | dev->resume.data = (unsigned long) dev; | ||
1190 | if (autoresume) { | 1172 | if (autoresume) { |
1191 | source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 1173 | source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
1192 | loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 1174 | loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
@@ -1194,45 +1176,43 @@ autoconf_fail: | |||
1194 | 1176 | ||
1195 | gadget->ep0->driver_data = dev; | 1177 | gadget->ep0->driver_data = dev; |
1196 | 1178 | ||
1197 | INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname); | 1179 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname); |
1198 | INFO (dev, "using %s, OUT %s IN %s\n", gadget->name, | 1180 | INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, |
1199 | EP_OUT_NAME, EP_IN_NAME); | 1181 | EP_OUT_NAME, EP_IN_NAME); |
1200 | 1182 | ||
1201 | snprintf (manufacturer, sizeof manufacturer, "%s %s with %s", | 1183 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", |
1202 | init_utsname()->sysname, init_utsname()->release, | 1184 | init_utsname()->sysname, init_utsname()->release, |
1203 | gadget->name); | 1185 | gadget->name); |
1204 | 1186 | ||
1205 | return 0; | 1187 | return 0; |
1206 | 1188 | ||
1207 | enomem: | 1189 | enomem: |
1208 | zero_unbind (gadget); | 1190 | zero_unbind(gadget); |
1209 | return -ENOMEM; | 1191 | return -ENOMEM; |
1210 | } | 1192 | } |
1211 | 1193 | ||
1212 | /*-------------------------------------------------------------------------*/ | 1194 | /*-------------------------------------------------------------------------*/ |
1213 | 1195 | ||
1214 | static void | 1196 | static void zero_suspend(struct usb_gadget *gadget) |
1215 | zero_suspend (struct usb_gadget *gadget) | ||
1216 | { | 1197 | { |
1217 | struct zero_dev *dev = get_gadget_data (gadget); | 1198 | struct zero_dev *dev = get_gadget_data(gadget); |
1218 | 1199 | ||
1219 | if (gadget->speed == USB_SPEED_UNKNOWN) | 1200 | if (gadget->speed == USB_SPEED_UNKNOWN) |
1220 | return; | 1201 | return; |
1221 | 1202 | ||
1222 | if (autoresume) { | 1203 | if (autoresume) { |
1223 | mod_timer (&dev->resume, jiffies + (HZ * autoresume)); | 1204 | mod_timer(&dev->resume, jiffies + (HZ * autoresume)); |
1224 | DBG (dev, "suspend, wakeup in %d seconds\n", autoresume); | 1205 | DBG(dev, "suspend, wakeup in %d seconds\n", autoresume); |
1225 | } else | 1206 | } else |
1226 | DBG (dev, "suspend\n"); | 1207 | DBG(dev, "suspend\n"); |
1227 | } | 1208 | } |
1228 | 1209 | ||
1229 | static void | 1210 | static void zero_resume(struct usb_gadget *gadget) |
1230 | zero_resume (struct usb_gadget *gadget) | ||
1231 | { | 1211 | { |
1232 | struct zero_dev *dev = get_gadget_data (gadget); | 1212 | struct zero_dev *dev = get_gadget_data(gadget); |
1233 | 1213 | ||
1234 | DBG (dev, "resume\n"); | 1214 | DBG(dev, "resume\n"); |
1235 | del_timer (&dev->resume); | 1215 | del_timer(&dev->resume); |
1236 | } | 1216 | } |
1237 | 1217 | ||
1238 | 1218 | ||
@@ -1264,15 +1244,15 @@ MODULE_AUTHOR("David Brownell"); | |||
1264 | MODULE_LICENSE("GPL"); | 1244 | MODULE_LICENSE("GPL"); |
1265 | 1245 | ||
1266 | 1246 | ||
1267 | static int __init init (void) | 1247 | static int __init init(void) |
1268 | { | 1248 | { |
1269 | return usb_gadget_register_driver (&zero_driver); | 1249 | return usb_gadget_register_driver(&zero_driver); |
1270 | } | 1250 | } |
1271 | module_init (init); | 1251 | module_init(init); |
1272 | 1252 | ||
1273 | static void __exit cleanup (void) | 1253 | static void __exit cleanup(void) |
1274 | { | 1254 | { |
1275 | usb_gadget_unregister_driver (&zero_driver); | 1255 | usb_gadget_unregister_driver(&zero_driver); |
1276 | } | 1256 | } |
1277 | module_exit (cleanup); | 1257 | module_exit(cleanup); |
1278 | 1258 | ||