aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-06-19 21:18:27 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-07-21 18:16:04 -0400
commit097db1d034b0927056f3d9e844dc80b3ba881765 (patch)
tree674bab7cb6e94bd90f01e187661a3838ae4b2104 /drivers/usb/gadget
parente5760fdac8c8aeca060d1afc8a233ea3d7a46720 (diff)
usb gadget zero: use composite gadget framework
Update Gadget Zero to use the more modular versions of the loopback and source/sink configuration drivers which build on the new gadget framework code. The core code is a LOT simpler, and it should be much easier now to understand how the parts fit together. The conversion is an overall source shrink in terms of this gadget, since it uses more midlayer support. However, it's an overall increase in object size because there's less sharing between the two configurations (improves code clarity) and because the midlayer is a bit more functional than this driver actually needs. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Makefile4
-rw-r--r--drivers/usb/gadget/zero.c1162
2 files changed, 97 insertions, 1069 deletions
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 16211435761f..fe60cca704d9 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -22,7 +22,9 @@ obj-$(CONFIG_USB_M66592) += m66592-udc.o
22# 22#
23# USB gadget drivers 23# USB gadget drivers
24# 24#
25g_zero-objs := zero.o usbstring.o config.o epautoconf.o 25C_UTILS = composite.o usbstring.o config.o epautoconf.o
26
27g_zero-objs := zero.o f_sourcesink.o f_loopback.o $(C_UTILS)
26g_ether-objs := ether.o usbstring.o config.o epautoconf.o 28g_ether-objs := ether.o usbstring.o config.o epautoconf.o
27g_serial-objs := serial.o u_serial.o usbstring.o config.o epautoconf.o 29g_serial-objs := serial.o u_serial.o usbstring.o config.o epautoconf.o
28g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o 30g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index fce4924dbbe8..aa0bd4f126a1 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * zero.c -- Gadget Zero, for USB development 2 * zero.c -- Gadget Zero, for USB development
3 * 3 *
4 * Copyright (C) 2003-2007 David Brownell 4 * Copyright (C) 2003-2008 David Brownell
5 * All rights reserved. 5 * Copyright (C) 2008 by Nokia Corporation
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -30,12 +30,7 @@
30 * 30 *
31 * It supports two similar configurations. One sinks whatever the usb host 31 * It supports two similar configurations. One sinks whatever the usb host
32 * writes, and in return sources zeroes. The other loops whatever the host 32 * writes, and in return sources zeroes. The other loops whatever the host
33 * writes back, so the host can read it. Module options include: 33 * writes back, so the host can read it.
34 *
35 * buflen=N default N=4096, buffer size used
36 * qlen=N default N=32, how many buffers in the loopback queue
37 * loopdefault default false, list loopback config first
38 * autoresume=N default N=0, seconds before triggering remote wakeup
39 * 34 *
40 * Many drivers will only have one configuration, letting them be much 35 * Many drivers will only have one configuration, letting them be much
41 * simpler if they also don't support high speed operation (like this 36 * simpler if they also don't support high speed operation (like this
@@ -47,94 +42,35 @@
47 * work with low capability USB controllers without four bulk endpoints. 42 * work with low capability USB controllers without four bulk endpoints.
48 */ 43 */
49 44
45/*
46 * driver assumes self-powered hardware, and
47 * has no way for users to trigger remote wakeup.
48 */
49
50/* #define VERBOSE_DEBUG */ 50/* #define VERBOSE_DEBUG */
51 51
52#include <linux/kernel.h> 52#include <linux/kernel.h>
53#include <linux/utsname.h> 53#include <linux/utsname.h>
54#include <linux/device.h> 54#include <linux/device.h>
55 55
56#include <linux/usb/ch9.h> 56#include "g_zero.h"
57#include <linux/usb/gadget.h>
58
59#include "gadget_chips.h" 57#include "gadget_chips.h"
60 58
61 59
62/*-------------------------------------------------------------------------*/ 60/*-------------------------------------------------------------------------*/
63 61
64#define DRIVER_VERSION "Earth Day 2008" 62#define DRIVER_VERSION "Cinco de Mayo 2008"
65 63
66static const char shortname[] = "zero";
67static const char longname[] = "Gadget Zero"; 64static const char longname[] = "Gadget Zero";
68 65
69static const char source_sink[] = "source and sink data"; 66unsigned buflen = 4096;
70static const char loopback[] = "loop input to output"; 67module_param(buflen, uint, 0);
71
72/*-------------------------------------------------------------------------*/
73
74/*
75 * driver assumes self-powered hardware, and
76 * has no way for users to trigger remote wakeup.
77 *
78 * this version autoconfigures as much as possible,
79 * which is reasonable for most "bulk-only" drivers.
80 */
81static const char *EP_IN_NAME; /* source */
82static const char *EP_OUT_NAME; /* sink */
83
84/*-------------------------------------------------------------------------*/
85
86/* big enough to hold our biggest descriptor */
87#define USB_BUFSIZ 256
88
89struct zero_dev {
90 spinlock_t lock;
91 struct usb_gadget *gadget;
92 struct usb_request *req; /* for control responses */
93
94 /* when configured, we have one of two configs:
95 * - source data (in to host) and sink it (out from host)
96 * - or loop it back (out from host back in to host)
97 */
98 u8 config;
99 struct usb_ep *in_ep, *out_ep;
100
101 /* autoresume timer */
102 struct timer_list resume;
103};
104
105#define DBG(d, fmt, args...) \
106 dev_dbg(&(d)->gadget->dev , fmt , ## args)
107#define VDBG(d, fmt, args...) \
108 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
109#define ERROR(d, fmt, args...) \
110 dev_err(&(d)->gadget->dev , fmt , ## args)
111#define WARN(d, fmt, args...) \
112 dev_warn(&(d)->gadget->dev , fmt , ## args)
113#define INFO(d, fmt, args...) \
114 dev_info(&(d)->gadget->dev , fmt , ## args)
115
116/*-------------------------------------------------------------------------*/
117
118static unsigned buflen = 4096;
119static unsigned qlen = 32;
120static unsigned pattern = 0;
121
122module_param(buflen, uint, S_IRUGO);
123module_param(qlen, uint, S_IRUGO);
124module_param(pattern, uint, S_IRUGO|S_IWUSR);
125
126/*
127 * if it's nonzero, autoresume says how many seconds to wait
128 * before trying to wake up the host after suspend.
129 */
130static unsigned autoresume = 0;
131module_param(autoresume, uint, 0);
132 68
133/* 69/*
134 * Normally the "loopback" configuration is second (index 1) so 70 * Normally the "loopback" configuration is second (index 1) so
135 * it's not the default. Here's where to change that order, to 71 * it's not the default. Here's where to change that order, to
136 * work better with hosts where config changes are problematic. 72 * work better with hosts where config changes are problematic or
137 * Or controllers (like superh) that only support one config. 73 * controllers (like original superh) that only support one config.
138 */ 74 */
139static int loopdefault = 0; 75static int loopdefault = 0;
140module_param(loopdefault, bool, S_IRUGO|S_IWUSR); 76module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
@@ -156,24 +92,6 @@ module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
156 92
157/*-------------------------------------------------------------------------*/ 93/*-------------------------------------------------------------------------*/
158 94
159/*
160 * DESCRIPTORS ... most are static, but strings and (full)
161 * configuration descriptors are built on demand.
162 */
163
164#define STRING_MANUFACTURER 25
165#define STRING_PRODUCT 42
166#define STRING_SERIAL 101
167#define STRING_SOURCE_SINK 250
168#define STRING_LOOPBACK 251
169
170/*
171 * This device advertises two configurations; these numbers work
172 * on a pxa250 as well as more flexible hardware.
173 */
174#define CONFIG_SOURCE_SINK 3
175#define CONFIG_LOOPBACK 2
176
177static struct usb_device_descriptor device_desc = { 95static struct usb_device_descriptor device_desc = {
178 .bLength = sizeof device_desc, 96 .bLength = sizeof device_desc,
179 .bDescriptorType = USB_DT_DEVICE, 97 .bDescriptorType = USB_DT_DEVICE,
@@ -183,248 +101,64 @@ static struct usb_device_descriptor device_desc = {
183 101
184 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), 102 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
185 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), 103 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
186 .iManufacturer = STRING_MANUFACTURER,
187 .iProduct = STRING_PRODUCT,
188 .iSerialNumber = STRING_SERIAL,
189 .bNumConfigurations = 2, 104 .bNumConfigurations = 2,
190}; 105};
191 106
192static struct usb_config_descriptor source_sink_config = { 107#ifdef CONFIG_USB_OTG
193 .bLength = sizeof source_sink_config,
194 .bDescriptorType = USB_DT_CONFIG,
195
196 /* compute wTotalLength on the fly */
197 .bNumInterfaces = 1,
198 .bConfigurationValue = CONFIG_SOURCE_SINK,
199 .iConfiguration = STRING_SOURCE_SINK,
200 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
201 .bMaxPower = 1, /* self-powered */
202};
203
204static struct usb_config_descriptor loopback_config = {
205 .bLength = sizeof loopback_config,
206 .bDescriptorType = USB_DT_CONFIG,
207
208 /* compute wTotalLength on the fly */
209 .bNumInterfaces = 1,
210 .bConfigurationValue = CONFIG_LOOPBACK,
211 .iConfiguration = STRING_LOOPBACK,
212 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
213 .bMaxPower = 1, /* self-powered */
214};
215
216static struct usb_otg_descriptor otg_descriptor = { 108static struct usb_otg_descriptor otg_descriptor = {
217 .bLength = sizeof otg_descriptor, 109 .bLength = sizeof otg_descriptor,
218 .bDescriptorType = USB_DT_OTG, 110 .bDescriptorType = USB_DT_OTG,
219 111
220 .bmAttributes = USB_OTG_SRP, 112 /* REVISIT SRP-only hardware is possible, although
221}; 113 * it would not be called "OTG" ...
222 114 */
223/* one interface in each configuration */ 115 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
224
225static const struct usb_interface_descriptor source_sink_intf = {
226 .bLength = sizeof source_sink_intf,
227 .bDescriptorType = USB_DT_INTERFACE,
228
229 .bNumEndpoints = 2,
230 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
231 .iInterface = STRING_SOURCE_SINK,
232};
233
234static const struct usb_interface_descriptor loopback_intf = {
235 .bLength = sizeof loopback_intf,
236 .bDescriptorType = USB_DT_INTERFACE,
237
238 .bNumEndpoints = 2,
239 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
240 .iInterface = STRING_LOOPBACK,
241};
242
243/* two full speed bulk endpoints; their use is config-dependent */
244
245static struct usb_endpoint_descriptor fs_source_desc = {
246 .bLength = USB_DT_ENDPOINT_SIZE,
247 .bDescriptorType = USB_DT_ENDPOINT,
248
249 .bEndpointAddress = USB_DIR_IN,
250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
251};
252
253static struct usb_endpoint_descriptor fs_sink_desc = {
254 .bLength = USB_DT_ENDPOINT_SIZE,
255 .bDescriptorType = USB_DT_ENDPOINT,
256
257 .bEndpointAddress = USB_DIR_OUT,
258 .bmAttributes = USB_ENDPOINT_XFER_BULK,
259};
260
261static const struct usb_descriptor_header *fs_source_sink_function[] = {
262 (struct usb_descriptor_header *) &otg_descriptor,
263 (struct usb_descriptor_header *) &source_sink_intf,
264 (struct usb_descriptor_header *) &fs_sink_desc,
265 (struct usb_descriptor_header *) &fs_source_desc,
266 NULL,
267};
268
269static const struct usb_descriptor_header *fs_loopback_function[] = {
270 (struct usb_descriptor_header *) &otg_descriptor,
271 (struct usb_descriptor_header *) &loopback_intf,
272 (struct usb_descriptor_header *) &fs_sink_desc,
273 (struct usb_descriptor_header *) &fs_source_desc,
274 NULL,
275};
276
277/*
278 * usb 2.0 devices need to expose both high speed and full speed
279 * descriptors, unless they only run at full speed.
280 *
281 * that means alternate endpoint descriptors (bigger packets)
282 * and a "device qualifier" ... plus more construction options
283 * for the config descriptor.
284 */
285
286static struct usb_endpoint_descriptor hs_source_desc = {
287 .bLength = USB_DT_ENDPOINT_SIZE,
288 .bDescriptorType = USB_DT_ENDPOINT,
289
290 .bmAttributes = USB_ENDPOINT_XFER_BULK,
291 .wMaxPacketSize = __constant_cpu_to_le16(512),
292};
293
294static struct usb_endpoint_descriptor hs_sink_desc = {
295 .bLength = USB_DT_ENDPOINT_SIZE,
296 .bDescriptorType = USB_DT_ENDPOINT,
297
298 .bmAttributes = USB_ENDPOINT_XFER_BULK,
299 .wMaxPacketSize = __constant_cpu_to_le16(512),
300};
301
302static struct usb_qualifier_descriptor dev_qualifier = {
303 .bLength = sizeof dev_qualifier,
304 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
305
306 .bcdUSB = __constant_cpu_to_le16(0x0200),
307 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
308
309 .bNumConfigurations = 2,
310}; 116};
311 117
312static const struct usb_descriptor_header *hs_source_sink_function[] = { 118const struct usb_descriptor_header *otg_desc[] = {
313 (struct usb_descriptor_header *) &otg_descriptor, 119 (struct usb_descriptor_header *) &otg_descriptor,
314 (struct usb_descriptor_header *) &source_sink_intf,
315 (struct usb_descriptor_header *) &hs_source_desc,
316 (struct usb_descriptor_header *) &hs_sink_desc,
317 NULL, 120 NULL,
318}; 121};
122#endif
319 123
320static const struct usb_descriptor_header *hs_loopback_function[] = { 124/* string IDs are assigned dynamically */
321 (struct usb_descriptor_header *) &otg_descriptor,
322 (struct usb_descriptor_header *) &loopback_intf,
323 (struct usb_descriptor_header *) &hs_source_desc,
324 (struct usb_descriptor_header *) &hs_sink_desc,
325 NULL,
326};
327 125
328/* maxpacket and other transfer characteristics vary by speed. */ 126#define STRING_MANUFACTURER_IDX 0
329static inline struct usb_endpoint_descriptor * 127#define STRING_PRODUCT_IDX 1
330ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs, 128#define STRING_SERIAL_IDX 2
331 struct usb_endpoint_descriptor *fs)
332{
333 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
334 return hs;
335 return fs;
336}
337 129
338static char manufacturer[50]; 130static char manufacturer[50];
339 131
340/* default serial number takes at least two packets */ 132/* default serial number takes at least two packets */
341static char serial[] = "0123456789.0123456789.0123456789"; 133static char serial[] = "0123456789.0123456789.0123456789";
342 134
343 135static struct usb_string strings_dev[] = {
344/* static strings, in UTF-8 */ 136 [STRING_MANUFACTURER_IDX].s = manufacturer,
345static struct usb_string strings[] = { 137 [STRING_PRODUCT_IDX].s = longname,
346 { STRING_MANUFACTURER, manufacturer, }, 138 [STRING_SERIAL_IDX].s = serial,
347 { STRING_PRODUCT, longname, },
348 { STRING_SERIAL, serial, },
349 { STRING_LOOPBACK, loopback, },
350 { STRING_SOURCE_SINK, source_sink, },
351 { } /* end of list */ 139 { } /* end of list */
352}; 140};
353 141
354static struct usb_gadget_strings stringtab = { 142static struct usb_gadget_strings stringtab_dev = {
355 .language = 0x0409, /* en-us */ 143 .language = 0x0409, /* en-us */
356 .strings = strings, 144 .strings = strings_dev,
357}; 145};
358 146
359/* 147static struct usb_gadget_strings *dev_strings[] = {
360 * config descriptors are also handcrafted. these must agree with code 148 &stringtab_dev,
361 * that sets configurations, and with code managing interfaces and their 149 NULL,
362 * altsettings. other complexity may come from: 150};
363 *
364 * - high speed support, including "other speed config" rules
365 * - multiple configurations
366 * - interfaces with alternate settings
367 * - embedded class or vendor-specific descriptors
368 *
369 * this handles high speed, and has a second config that could as easily
370 * have been an alternate interface setting (on most hardware).
371 *
372 * NOTE: to demonstrate (and test) more USB capabilities, this driver
373 * should include an altsetting to test interrupt transfers, including
374 * high bandwidth modes at high speed. (Maybe work like Intel's test
375 * device?)
376 */
377static int config_buf(struct usb_gadget *gadget,
378 u8 *buf, u8 type, unsigned index)
379{
380 int is_source_sink;
381 int len;
382 const struct usb_descriptor_header **function;
383 int hs = 0;
384
385 /* two configurations will always be index 0 and index 1 */
386 if (index > 1)
387 return -EINVAL;
388 is_source_sink = loopdefault ? (index == 1) : (index == 0);
389
390 if (gadget_is_dualspeed(gadget)) {
391 hs = (gadget->speed == USB_SPEED_HIGH);
392 if (type == USB_DT_OTHER_SPEED_CONFIG)
393 hs = !hs;
394 }
395 if (hs)
396 function = is_source_sink
397 ? hs_source_sink_function
398 : hs_loopback_function;
399 else
400 function = is_source_sink
401 ? fs_source_sink_function
402 : fs_loopback_function;
403
404 /* for now, don't advertise srp-only devices */
405 if (!gadget_is_otg(gadget))
406 function++;
407
408 len = usb_gadget_config_buf(is_source_sink
409 ? &source_sink_config
410 : &loopback_config,
411 buf, USB_BUFSIZ, function);
412 if (len < 0)
413 return len;
414 ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
415 return len;
416}
417 151
418/*-------------------------------------------------------------------------*/ 152/*-------------------------------------------------------------------------*/
419 153
420static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) 154struct usb_request *alloc_ep_req(struct usb_ep *ep)
421{ 155{
422 struct usb_request *req; 156 struct usb_request *req;
423 157
424 req = usb_ep_alloc_request(ep, GFP_ATOMIC); 158 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
425 if (req) { 159 if (req) {
426 req->length = length; 160 req->length = buflen;
427 req->buf = kmalloc(length, GFP_ATOMIC); 161 req->buf = kmalloc(buflen, GFP_ATOMIC);
428 if (!req->buf) { 162 if (!req->buf) {
429 usb_ep_free_request(ep, req); 163 usb_ep_free_request(ep, req);
430 req = NULL; 164 req = NULL;
@@ -433,681 +167,73 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
433 return req; 167 return req;
434} 168}
435 169
436static void free_ep_req(struct usb_ep *ep, struct usb_request *req) 170void free_ep_req(struct usb_ep *ep, struct usb_request *req)
437{ 171{
438 kfree(req->buf); 172 kfree(req->buf);
439 usb_ep_free_request(ep, req); 173 usb_ep_free_request(ep, req);
440} 174}
441 175
442/*-------------------------------------------------------------------------*/ 176static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
443
444/*
445 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripherals,
446 * this just sinks bulk packets OUT to the peripheral and sources them IN
447 * to the host, optionally with specific data patterns.
448 *
449 * In terms of control messaging, this supports all the standard requests
450 * plus two that support control-OUT tests.
451 *
452 * Note that because this doesn't queue more than one request at a time,
453 * some other function must be used to test queueing logic. The network
454 * link (g_ether) is probably the best option for that.
455 */
456
457/* optionally require specific source/sink data patterns */
458
459static int
460check_read_data(
461 struct zero_dev *dev,
462 struct usb_ep *ep,
463 struct usb_request *req
464)
465{ 177{
466 unsigned i; 178 int value;
467 u8 *buf = req->buf; 179
468 180 if (ep->driver_data) {
469 for (i = 0; i < req->actual; i++, buf++) { 181 value = usb_ep_disable(ep);
470 switch (pattern) { 182 if (value < 0)
471 /* all-zeroes has no synchronization issues */ 183 DBG(cdev, "disable %s --> %d\n",
472 case 0: 184 ep->name, value);
473 if (*buf == 0) 185 ep->driver_data = NULL;
474 continue;
475 break;
476 /* mod63 stays in sync with short-terminated transfers,
477 * or otherwise when host and gadget agree on how large
478 * each usb transfer request should be. resync is done
479 * with set_interface or set_config.
480 */
481 case 1:
482 if (*buf == (u8)(i % 63))
483 continue;
484 break;
485 }
486 ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
487 usb_ep_set_halt(ep);
488 return -EINVAL;
489 } 186 }
490 return 0;
491} 187}
492 188
493static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) 189void disable_endpoints(struct usb_composite_dev *cdev,
190 struct usb_ep *in, struct usb_ep *out)
494{ 191{
495 unsigned i; 192 disable_ep(cdev, in);
496 u8 *buf = req->buf; 193 disable_ep(cdev, out);
497
498 switch (pattern) {
499 case 0:
500 memset(req->buf, 0, req->length);
501 break;
502 case 1:
503 for (i = 0; i < req->length; i++)
504 *buf++ = (u8) (i % 63);
505 break;
506 }
507}
508
509/* if there is only one request in the queue, there'll always be an
510 * irq delay between end of one request and start of the next.
511 * that prevents using hardware dma queues.
512 */
513static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
514{
515 struct zero_dev *dev = ep->driver_data;
516 int status = req->status;
517
518 switch (status) {
519
520 case 0: /* normal completion? */
521 if (ep == dev->out_ep) {
522 check_read_data(dev, ep, req);
523 memset(req->buf, 0x55, req->length);
524 } else
525 reinit_write_data(ep, req);
526 break;
527
528 /* this endpoint is normally active while we're configured */
529 case -ECONNABORTED: /* hardware forced ep reset */
530 case -ECONNRESET: /* request dequeued */
531 case -ESHUTDOWN: /* disconnect from host */
532 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
533 req->actual, req->length);
534 if (ep == dev->out_ep)
535 check_read_data(dev, ep, req);
536 free_ep_req(ep, req);
537 return;
538
539 case -EOVERFLOW: /* buffer overrun on read means that
540 * we didn't provide a big enough
541 * buffer.
542 */
543 default:
544#if 1
545 DBG(dev, "%s complete --> %d, %d/%d\n", ep->name,
546 status, req->actual, req->length);
547#endif
548 case -EREMOTEIO: /* short read */
549 break;
550 }
551
552 status = usb_ep_queue(ep, req, GFP_ATOMIC);
553 if (status) {
554 ERROR(dev, "kill %s: resubmit %d bytes --> %d\n",
555 ep->name, req->length, status);
556 usb_ep_set_halt(ep);
557 /* FIXME recover later ... somehow */
558 }
559}
560
561static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
562{
563 struct usb_request *req;
564 int status;
565
566 req = alloc_ep_req(ep, buflen);
567 if (!req)
568 return NULL;
569
570 memset(req->buf, 0, req->length);
571 req->complete = source_sink_complete;
572
573 if (strcmp(ep->name, EP_IN_NAME) == 0)
574 reinit_write_data(ep, req);
575 else
576 memset(req->buf, 0x55, req->length);
577
578 status = usb_ep_queue(ep, req, GFP_ATOMIC);
579 if (status) {
580 struct zero_dev *dev = ep->driver_data;
581
582 ERROR(dev, "start %s --> %d\n", ep->name, status);
583 free_ep_req(ep, req);
584 req = NULL;
585 }
586
587 return req;
588}
589
590static int set_source_sink_config(struct zero_dev *dev)
591{
592 int result = 0;
593 struct usb_ep *ep;
594 struct usb_gadget *gadget = dev->gadget;
595
596 gadget_for_each_ep(ep, gadget) {
597 const struct usb_endpoint_descriptor *d;
598
599 /* one endpoint writes (sources) zeroes in (to the host) */
600 if (strcmp(ep->name, EP_IN_NAME) == 0) {
601 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
602 result = usb_ep_enable(ep, d);
603 if (result == 0) {
604 ep->driver_data = dev;
605 if (source_sink_start_ep(ep) != NULL) {
606 dev->in_ep = ep;
607 continue;
608 }
609 usb_ep_disable(ep);
610 result = -EIO;
611 }
612
613 /* one endpoint reads (sinks) anything out (from the host) */
614 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
615 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
616 result = usb_ep_enable(ep, d);
617 if (result == 0) {
618 ep->driver_data = dev;
619 if (source_sink_start_ep(ep) != NULL) {
620 dev->out_ep = ep;
621 continue;
622 }
623 usb_ep_disable(ep);
624 result = -EIO;
625 }
626
627 /* ignore any other endpoints */
628 } else
629 continue;
630
631 /* stop on error */
632 ERROR(dev, "can't start %s, result %d\n", ep->name, result);
633 break;
634 }
635 if (result == 0)
636 DBG(dev, "buflen %d\n", buflen);
637
638 /* caller is responsible for cleanup on error */
639 return result;
640}
641
642/*-------------------------------------------------------------------------*/
643
644static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
645{
646 struct zero_dev *dev = ep->driver_data;
647 int status = req->status;
648
649 switch (status) {
650
651 case 0: /* normal completion? */
652 if (ep == dev->out_ep) {
653 /* loop this OUT packet back IN to the host */
654 req->zero = (req->actual < req->length);
655 req->length = req->actual;
656 status = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
657 if (status == 0)
658 return;
659
660 /* "should never get here" */
661 ERROR(dev, "can't loop %s to %s: %d\n",
662 ep->name, dev->in_ep->name,
663 status);
664 }
665
666 /* queue the buffer for some later OUT packet */
667 req->length = buflen;
668 status = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
669 if (status == 0)
670 return;
671
672 /* "should never get here" */
673 /* FALLTHROUGH */
674
675 default:
676 ERROR(dev, "%s loop complete --> %d, %d/%d\n", ep->name,
677 status, req->actual, req->length);
678 /* FALLTHROUGH */
679
680 /* NOTE: since this driver doesn't maintain an explicit record
681 * of requests it submitted (just maintains qlen count), we
682 * rely on the hardware driver to clean up on disconnect or
683 * endpoint disable.
684 */
685 case -ECONNABORTED: /* hardware forced ep reset */
686 case -ECONNRESET: /* request dequeued */
687 case -ESHUTDOWN: /* disconnect from host */
688 free_ep_req(ep, req);
689 return;
690 }
691}
692
693static int set_loopback_config(struct zero_dev *dev)
694{
695 int result = 0;
696 struct usb_ep *ep;
697 struct usb_gadget *gadget = dev->gadget;
698
699 gadget_for_each_ep(ep, gadget) {
700 const struct usb_endpoint_descriptor *d;
701
702 /* one endpoint writes data back IN to the host */
703 if (strcmp(ep->name, EP_IN_NAME) == 0) {
704 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
705 result = usb_ep_enable(ep, d);
706 if (result == 0) {
707 ep->driver_data = dev;
708 dev->in_ep = ep;
709 continue;
710 }
711
712 /* one endpoint just reads OUT packets */
713 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
714 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
715 result = usb_ep_enable(ep, d);
716 if (result == 0) {
717 ep->driver_data = dev;
718 dev->out_ep = ep;
719 continue;
720 }
721
722 /* ignore any other endpoints */
723 } else
724 continue;
725
726 /* stop on error */
727 ERROR(dev, "can't enable %s, result %d\n", ep->name, result);
728 break;
729 }
730
731 /* allocate a bunch of read buffers and queue them all at once.
732 * we buffer at most 'qlen' transfers; fewer if any need more
733 * than 'buflen' bytes each.
734 */
735 if (result == 0) {
736 struct usb_request *req;
737 unsigned i;
738
739 ep = dev->out_ep;
740 for (i = 0; i < qlen && result == 0; i++) {
741 req = alloc_ep_req(ep, buflen);
742 if (req) {
743 req->complete = loopback_complete;
744 result = usb_ep_queue(ep, req, GFP_ATOMIC);
745 if (result)
746 DBG(dev, "%s queue req --> %d\n",
747 ep->name, result);
748 } else
749 result = -ENOMEM;
750 }
751 }
752 if (result == 0)
753 DBG(dev, "qlen %d, buflen %d\n", qlen, buflen);
754
755 /* caller is responsible for cleanup on error */
756 return result;
757}
758
759/*-------------------------------------------------------------------------*/
760
761static void zero_reset_config(struct zero_dev *dev)
762{
763 if (dev->config == 0)
764 return;
765
766 DBG(dev, "reset config\n");
767
768 /* just disable endpoints, forcing completion of pending i/o.
769 * all our completion handlers free their requests in this case.
770 */
771 if (dev->in_ep) {
772 usb_ep_disable(dev->in_ep);
773 dev->in_ep = NULL;
774 }
775 if (dev->out_ep) {
776 usb_ep_disable(dev->out_ep);
777 dev->out_ep = NULL;
778 }
779 dev->config = 0;
780 del_timer(&dev->resume);
781}
782
783/* change our operational config. this code must agree with the code
784 * that returns config descriptors, and altsetting code.
785 *
786 * it's also responsible for power management interactions. some
787 * configurations might not work with our current power sources.
788 *
789 * note that some device controller hardware will constrain what this
790 * code can do, perhaps by disallowing more than one configuration or
791 * by limiting configuration choices (like the pxa2xx).
792 */
793static int zero_set_config(struct zero_dev *dev, unsigned number)
794{
795 int result = 0;
796 struct usb_gadget *gadget = dev->gadget;
797
798 if (number == dev->config)
799 return 0;
800
801 if (gadget_is_sa1100(gadget) && dev->config) {
802 /* tx fifo is full, but we can't clear it...*/
803 ERROR(dev, "can't change configurations\n");
804 return -ESPIPE;
805 }
806 zero_reset_config(dev);
807
808 switch (number) {
809 case CONFIG_SOURCE_SINK:
810 result = set_source_sink_config(dev);
811 break;
812 case CONFIG_LOOPBACK:
813 result = set_loopback_config(dev);
814 break;
815 default:
816 result = -EINVAL;
817 /* FALL THROUGH */
818 case 0:
819 return result;
820 }
821
822 if (!result && (!dev->in_ep || !dev->out_ep))
823 result = -ENODEV;
824 if (result)
825 zero_reset_config(dev);
826 else {
827 char *speed;
828
829 switch (gadget->speed) {
830 case USB_SPEED_LOW: speed = "low"; break;
831 case USB_SPEED_FULL: speed = "full"; break;
832 case USB_SPEED_HIGH: speed = "high"; break;
833 default: speed = "?"; break;
834 }
835
836 dev->config = number;
837 INFO(dev, "%s speed config #%d: %s\n", speed, number,
838 (number == CONFIG_SOURCE_SINK)
839 ? source_sink : loopback);
840 }
841 return result;
842}
843
844/*-------------------------------------------------------------------------*/
845
846static void zero_setup_complete(struct usb_ep *ep, struct usb_request *req)
847{
848 if (req->status || req->actual != req->length)
849 DBG((struct zero_dev *) ep->driver_data,
850 "setup complete --> %d, %d/%d\n",
851 req->status, req->actual, req->length);
852}
853
854/*
855 * The setup() callback implements all the ep0 functionality that's
856 * not handled lower down, in hardware or the hardware driver (like
857 * device and endpoint feature flags, and their status). It's all
858 * housekeeping for the gadget function we're implementing. Most of
859 * the work is in config-specific setup.
860 */
861static int
862zero_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
863{
864 struct zero_dev *dev = get_gadget_data(gadget);
865 struct usb_request *req = dev->req;
866 int value = -EOPNOTSUPP;
867 u16 w_index = le16_to_cpu(ctrl->wIndex);
868 u16 w_value = le16_to_cpu(ctrl->wValue);
869 u16 w_length = le16_to_cpu(ctrl->wLength);
870
871 /* usually this stores reply data in the pre-allocated ep0 buffer,
872 * but config change events will reconfigure hardware.
873 */
874 req->zero = 0;
875 switch (ctrl->bRequest) {
876
877 case USB_REQ_GET_DESCRIPTOR:
878 if (ctrl->bRequestType != USB_DIR_IN)
879 goto unknown;
880 switch (w_value >> 8) {
881
882 case USB_DT_DEVICE:
883 value = min(w_length, (u16) sizeof device_desc);
884 memcpy(req->buf, &device_desc, value);
885 break;
886 case USB_DT_DEVICE_QUALIFIER:
887 if (!gadget_is_dualspeed(gadget))
888 break;
889 value = min(w_length, (u16) sizeof dev_qualifier);
890 memcpy(req->buf, &dev_qualifier, value);
891 break;
892
893 case USB_DT_OTHER_SPEED_CONFIG:
894 if (!gadget_is_dualspeed(gadget))
895 break;
896 // FALLTHROUGH
897 case USB_DT_CONFIG:
898 value = config_buf(gadget, req->buf,
899 w_value >> 8,
900 w_value & 0xff);
901 if (value >= 0)
902 value = min(w_length, (u16) value);
903 break;
904
905 case USB_DT_STRING:
906 /* wIndex == language code.
907 * this driver only handles one language, you can
908 * add string tables for other languages, using
909 * any UTF-8 characters
910 */
911 value = usb_gadget_get_string(&stringtab,
912 w_value & 0xff, req->buf);
913 if (value >= 0)
914 value = min(w_length, (u16) value);
915 break;
916 }
917 break;
918
919 /* currently two configs, two speeds */
920 case USB_REQ_SET_CONFIGURATION:
921 if (ctrl->bRequestType != 0)
922 goto unknown;
923 if (gadget->a_hnp_support)
924 DBG(dev, "HNP available\n");
925 else if (gadget->a_alt_hnp_support)
926 DBG(dev, "HNP needs a different root port\n");
927 else
928 VDBG(dev, "HNP inactive\n");
929 spin_lock(&dev->lock);
930 value = zero_set_config(dev, w_value);
931 spin_unlock(&dev->lock);
932 break;
933 case USB_REQ_GET_CONFIGURATION:
934 if (ctrl->bRequestType != USB_DIR_IN)
935 goto unknown;
936 *(u8 *)req->buf = dev->config;
937 value = min(w_length, (u16) 1);
938 break;
939
940 /* until we add altsetting support, or other interfaces,
941 * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
942 * and already killed pending endpoint I/O.
943 */
944 case USB_REQ_SET_INTERFACE:
945 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
946 goto unknown;
947 spin_lock(&dev->lock);
948 if (dev->config && w_index == 0 && w_value == 0) {
949 u8 config = dev->config;
950
951 /* resets interface configuration, forgets about
952 * previous transaction state (queued bufs, etc)
953 * and re-inits endpoint state (toggle etc)
954 * no response queued, just zero status == success.
955 * if we had more than one interface we couldn't
956 * use this "reset the config" shortcut.
957 */
958 zero_reset_config(dev);
959 zero_set_config(dev, config);
960 value = 0;
961 }
962 spin_unlock(&dev->lock);
963 break;
964 case USB_REQ_GET_INTERFACE:
965 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
966 goto unknown;
967 if (!dev->config)
968 break;
969 if (w_index != 0) {
970 value = -EDOM;
971 break;
972 }
973 *(u8 *)req->buf = 0;
974 value = min(w_length, (u16) 1);
975 break;
976
977 /*
978 * These are the same vendor-specific requests supported by
979 * Intel's USB 2.0 compliance test devices. We exceed that
980 * device spec by allowing multiple-packet requests.
981 */
982 case 0x5b: /* control WRITE test -- fill the buffer */
983 if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
984 goto unknown;
985 if (w_value || w_index)
986 break;
987 /* just read that many bytes into the buffer */
988 if (w_length > USB_BUFSIZ)
989 break;
990 value = w_length;
991 break;
992 case 0x5c: /* control READ test -- return the buffer */
993 if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
994 goto unknown;
995 if (w_value || w_index)
996 break;
997 /* expect those bytes are still in the buffer; send back */
998 if (w_length > USB_BUFSIZ
999 || w_length != req->length)
1000 break;
1001 value = w_length;
1002 break;
1003
1004 default:
1005unknown:
1006 VDBG(dev,
1007 "unknown control req%02x.%02x v%04x i%04x l%d\n",
1008 ctrl->bRequestType, ctrl->bRequest,
1009 w_value, w_index, w_length);
1010 }
1011
1012 /* respond with data transfer before status phase? */
1013 if (value >= 0) {
1014 req->length = value;
1015 req->zero = value < w_length;
1016 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1017 if (value < 0) {
1018 DBG(dev, "ep_queue --> %d\n", value);
1019 req->status = 0;
1020 zero_setup_complete(gadget->ep0, req);
1021 }
1022 }
1023
1024 /* device either stalls (value < 0) or reports success */
1025 return value;
1026}
1027
1028static void zero_disconnect(struct usb_gadget *gadget)
1029{
1030 struct zero_dev *dev = get_gadget_data(gadget);
1031 unsigned long flags;
1032
1033 spin_lock_irqsave(&dev->lock, flags);
1034 zero_reset_config(dev);
1035
1036 /* a more significant application might have some non-usb
1037 * activities to quiesce here, saving resources like power
1038 * or pushing the notification up a network stack.
1039 */
1040 spin_unlock_irqrestore(&dev->lock, flags);
1041
1042 /* next we may get setup() calls to enumerate new connections;
1043 * or an unbind() during shutdown (including removing module).
1044 */
1045}
1046
1047static void zero_autoresume(unsigned long _dev)
1048{
1049 struct zero_dev *dev = (struct zero_dev *) _dev;
1050 int status;
1051
1052 /* normally the host would be woken up for something
1053 * more significant than just a timer firing...
1054 */
1055 if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
1056 status = usb_gadget_wakeup(dev->gadget);
1057 DBG(dev, "wakeup --> %d\n", status);
1058 }
1059} 194}
1060 195
1061/*-------------------------------------------------------------------------*/ 196/*-------------------------------------------------------------------------*/
1062 197
1063static void zero_unbind(struct usb_gadget *gadget) 198static int __init zero_bind(struct usb_composite_dev *cdev)
1064{ 199{
1065 struct zero_dev *dev = get_gadget_data(gadget);
1066
1067 DBG(dev, "unbind\n");
1068
1069 /* we've already been disconnected ... no i/o is active */
1070 if (dev->req) {
1071 dev->req->length = USB_BUFSIZ;
1072 free_ep_req(gadget->ep0, dev->req);
1073 }
1074 del_timer_sync(&dev->resume);
1075 kfree(dev);
1076 set_gadget_data(gadget, NULL);
1077}
1078
1079static int __init zero_bind(struct usb_gadget *gadget)
1080{
1081 struct zero_dev *dev;
1082 struct usb_ep *ep;
1083 int gcnum; 200 int gcnum;
201 struct usb_gadget *gadget = cdev->gadget;
202 int id;
1084 203
1085 /* FIXME this can't yet work right with SH ... it has only 204 /* Allocate string descriptor numbers ... note that string
1086 * one configuration, numbered one. 205 * contents can be overridden by the composite_dev glue.
1087 */ 206 */
1088 if (gadget_is_sh(gadget)) 207 id = usb_string_id(cdev);
1089 return -ENODEV; 208 if (id < 0)
1090 209 return id;
1091 /* Bulk-only drivers like this one SHOULD be able to 210 strings_dev[STRING_MANUFACTURER_IDX].id = id;
1092 * autoconfigure on any sane usb controller driver, 211 device_desc.iManufacturer = id;
1093 * but there may also be important quirks to address. 212
213 id = usb_string_id(cdev);
214 if (id < 0)
215 return id;
216 strings_dev[STRING_PRODUCT_IDX].id = id;
217 device_desc.iProduct = id;
218
219 id = usb_string_id(cdev);
220 if (id < 0)
221 return id;
222 strings_dev[STRING_SERIAL_IDX].id = id;
223 device_desc.iSerialNumber = id;
224
225 /* Register primary, then secondary configuration. Note that
226 * SH3 only allows one config...
1094 */ 227 */
1095 usb_ep_autoconfig_reset(gadget); 228 if (loopdefault) {
1096 ep = usb_ep_autoconfig(gadget, &fs_source_desc); 229 loopback_add(cdev);
1097 if (!ep) { 230 if (!gadget_is_sh(gadget))
1098autoconf_fail: 231 sourcesink_add(cdev);
1099 pr_err("%s: can't autoconfigure on %s\n", 232 } else {
1100 shortname, gadget->name); 233 sourcesink_add(cdev);
1101 return -ENODEV; 234 if (!gadget_is_sh(gadget))
235 loopback_add(cdev);
1102 } 236 }
1103 EP_IN_NAME = ep->name;
1104 ep->driver_data = ep; /* claim */
1105
1106 ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
1107 if (!ep)
1108 goto autoconf_fail;
1109 EP_OUT_NAME = ep->name;
1110 ep->driver_data = ep; /* claim */
1111 237
1112 gcnum = usb_gadget_controller_number(gadget); 238 gcnum = usb_gadget_controller_number(gadget);
1113 if (gcnum >= 0) 239 if (gcnum >= 0)
@@ -1115,144 +241,44 @@ autoconf_fail:
1115 else { 241 else {
1116 /* gadget zero is so simple (for now, no altsettings) that 242 /* gadget zero is so simple (for now, no altsettings) that
1117 * it SHOULD NOT have problems with bulk-capable hardware. 243 * it SHOULD NOT have problems with bulk-capable hardware.
1118 * so warn about unrcognized controllers, don't panic. 244 * so just warn about unrcognized controllers -- don't panic.
1119 * 245 *
1120 * things like configuration and altsetting numbering 246 * things like configuration and altsetting numbering
1121 * can need hardware-specific attention though. 247 * can need hardware-specific attention though.
1122 */ 248 */
1123 pr_warning("%s: controller '%s' not recognized\n", 249 pr_warning("%s: controller '%s' not recognized\n",
1124 shortname, gadget->name); 250 longname, gadget->name);
1125 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 251 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1126 } 252 }
1127 253
1128 254
1129 /* ok, we made sense of the hardware ... */ 255 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
1130 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1131 if (!dev)
1132 return -ENOMEM;
1133 spin_lock_init(&dev->lock);
1134 dev->gadget = gadget;
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;
1140
1141 /* preallocate control response and buffer */
1142 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1143 if (!dev->req)
1144 goto enomem;
1145 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
1146 if (!dev->req->buf)
1147 goto enomem;
1148
1149 dev->req->complete = zero_setup_complete;
1150
1151 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1152
1153 if (gadget_is_dualspeed(gadget)) {
1154 /* assume ep0 uses the same value for both speeds ... */
1155 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1156
1157 /* and that all endpoints are dual-speed */
1158 hs_source_desc.bEndpointAddress =
1159 fs_source_desc.bEndpointAddress;
1160 hs_sink_desc.bEndpointAddress =
1161 fs_sink_desc.bEndpointAddress;
1162 }
1163
1164 if (gadget_is_otg(gadget)) {
1165 otg_descriptor.bmAttributes |= USB_OTG_HNP,
1166 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1167 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1168 }
1169
1170 usb_gadget_set_selfpowered(gadget);
1171
1172 if (autoresume) {
1173 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1174 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1175 }
1176
1177 gadget->ep0->driver_data = dev;
1178
1179 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
1180 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name,
1181 EP_OUT_NAME, EP_IN_NAME);
1182 256
1183 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 257 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
1184 init_utsname()->sysname, init_utsname()->release, 258 init_utsname()->sysname, init_utsname()->release,
1185 gadget->name); 259 gadget->name);
1186 260
1187 return 0; 261 return 0;
1188
1189enomem:
1190 zero_unbind(gadget);
1191 return -ENOMEM;
1192} 262}
1193 263
1194/*-------------------------------------------------------------------------*/ 264static struct usb_composite_driver zero_driver = {
1195 265 .name = "zero",
1196static void zero_suspend(struct usb_gadget *gadget) 266 .dev = &device_desc,
1197{ 267 .strings = dev_strings,
1198 struct zero_dev *dev = get_gadget_data(gadget);
1199
1200 if (gadget->speed == USB_SPEED_UNKNOWN)
1201 return;
1202
1203 if (autoresume) {
1204 mod_timer(&dev->resume, jiffies + (HZ * autoresume));
1205 DBG(dev, "suspend, wakeup in %d seconds\n", autoresume);
1206 } else
1207 DBG(dev, "suspend\n");
1208}
1209
1210static void zero_resume(struct usb_gadget *gadget)
1211{
1212 struct zero_dev *dev = get_gadget_data(gadget);
1213
1214 DBG(dev, "resume\n");
1215 del_timer(&dev->resume);
1216}
1217
1218
1219/*-------------------------------------------------------------------------*/
1220
1221static struct usb_gadget_driver zero_driver = {
1222#ifdef CONFIG_USB_GADGET_DUALSPEED
1223 .speed = USB_SPEED_HIGH,
1224#else
1225 .speed = USB_SPEED_FULL,
1226#endif
1227 .function = (char *) longname,
1228 .bind = zero_bind, 268 .bind = zero_bind,
1229 .unbind = __exit_p(zero_unbind),
1230
1231 .setup = zero_setup,
1232 .disconnect = zero_disconnect,
1233
1234 .suspend = zero_suspend,
1235 .resume = zero_resume,
1236
1237 .driver = {
1238 .name = (char *) shortname,
1239 .owner = THIS_MODULE,
1240 },
1241}; 269};
1242 270
1243MODULE_AUTHOR("David Brownell"); 271MODULE_AUTHOR("David Brownell");
1244MODULE_LICENSE("GPL"); 272MODULE_LICENSE("GPL");
1245 273
1246
1247static int __init init(void) 274static int __init init(void)
1248{ 275{
1249 return usb_gadget_register_driver(&zero_driver); 276 return usb_composite_register(&zero_driver);
1250} 277}
1251module_init(init); 278module_init(init);
1252 279
1253static void __exit cleanup(void) 280static void __exit cleanup(void)
1254{ 281{
1255 usb_gadget_unregister_driver(&zero_driver); 282 usb_composite_unregister(&zero_driver);
1256} 283}
1257module_exit(cleanup); 284module_exit(cleanup);
1258