2 * composite.c - infrastructure for Composite USB Gadgets
4 * Copyright (C) 2006-2008 David Brownell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* #define VERBOSE_DEBUG */
23 #include <linux/kallsyms.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include <linux/device.h>
28 #include <linux/usb/composite.h>
32 * The code in this file is utility code, used to build a gadget driver
33 * from one or more "function" drivers, one or more "configuration"
34 * objects, and a "usb_composite_driver" by gluing them together along
35 * with the relevant device-wide data.
38 /* big enough to hold our biggest descriptor */
39 #define USB_BUFSIZ 512
41 static struct usb_composite_driver *composite;
43 /* Some systems will need runtime overrides for the product identifers
44 * published in the device descriptor, either numbers or strings or both.
45 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
48 static ushort idVendor;
49 module_param(idVendor, ushort, 0);
50 MODULE_PARM_DESC(idVendor, "USB Vendor ID");
52 static ushort idProduct;
53 module_param(idProduct, ushort, 0);
54 MODULE_PARM_DESC(idProduct, "USB Product ID");
56 static ushort bcdDevice;
57 module_param(bcdDevice, ushort, 0);
58 MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
60 static char *iManufacturer;
61 module_param(iManufacturer, charp, 0);
62 MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
64 static char *iProduct;
65 module_param(iProduct, charp, 0);
66 MODULE_PARM_DESC(iProduct, "USB Product string");
68 static char *iSerialNumber;
69 module_param(iSerialNumber, charp, 0);
70 MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
72 /*-------------------------------------------------------------------------*/
75 * usb_add_function() - add a function to a configuration
76 * @config: the configuration
77 * @function: the function being added
78 * Context: single threaded during gadget setup
80 * After initialization, each configuration must have one or more
81 * functions added to it. Adding a function involves calling its @bind()
82 * method to allocate resources such as interface and string identifiers
85 * This function returns the value of the function's bind(), which is
86 * zero for success else a negative errno value.
88 int __init usb_add_function(struct usb_configuration *config,
89 struct usb_function *function)
93 DBG(config->cdev, "adding '%s'/%p to config '%s'/%p\n",
94 function->name, function,
95 config->label, config);
97 if (!function->set_alt || !function->disable)
100 function->config = config;
101 list_add_tail(&function->list, &config->functions);
103 /* REVISIT *require* function->bind? */
104 if (function->bind) {
105 value = function->bind(config, function);
107 list_del(&function->list);
108 function->config = NULL;
113 /* We allow configurations that don't work at both speeds.
114 * If we run into a lowspeed Linux system, treat it the same
115 * as full speed ... it's the function drivers that will need
116 * to avoid bulk and ISO transfers.
118 if (!config->fullspeed && function->descriptors)
119 config->fullspeed = true;
120 if (!config->highspeed && function->hs_descriptors)
121 config->highspeed = true;
125 DBG(config->cdev, "adding '%s'/%p --> %d\n",
126 function->name, function, value);
131 * usb_interface_id() - allocate an unused interface ID
132 * @config: configuration associated with the interface
133 * @function: function handling the interface
134 * Context: single threaded during gadget setup
136 * usb_interface_id() is called from usb_function.bind() callbacks to
137 * allocate new interface IDs. The function driver will then store that
138 * ID in interface, association, CDC union, and other descriptors. It
139 * will also handle any control requests targetted at that interface,
140 * particularly changing its altsetting via set_alt(). There may
141 * also be class-specific or vendor-specific requests to handle.
143 * All interface identifier should be allocated using this routine, to
144 * ensure that for example different functions don't wrongly assign
145 * different meanings to the same identifier. Note that since interface
146 * identifers are configuration-specific, functions used in more than
147 * one configuration (or more than once in a given configuration) need
148 * multiple versions of the relevant descriptors.
150 * Returns the interface ID which was allocated; or -ENODEV if no
151 * more interface IDs can be allocated.
153 int __init usb_interface_id(struct usb_configuration *config,
154 struct usb_function *function)
156 unsigned id = config->next_interface_id;
158 if (id < MAX_CONFIG_INTERFACES) {
159 config->interface[id] = function;
160 config->next_interface_id = id + 1;
166 static int config_buf(struct usb_configuration *config,
167 enum usb_device_speed speed, void *buf, u8 type)
169 struct usb_config_descriptor *c = buf;
170 void *next = buf + USB_DT_CONFIG_SIZE;
171 int len = USB_BUFSIZ - USB_DT_CONFIG_SIZE;
172 struct usb_function *f;
175 /* write the config descriptor */
177 c->bLength = USB_DT_CONFIG_SIZE;
178 c->bDescriptorType = type;
179 /* wTotalLength is written later */
180 c->bNumInterfaces = config->next_interface_id;
181 c->bConfigurationValue = config->bConfigurationValue;
182 c->iConfiguration = config->iConfiguration;
183 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
184 c->bMaxPower = config->bMaxPower;
186 /* There may be e.g. OTG descriptors */
187 if (config->descriptors) {
188 status = usb_descriptor_fillbuf(next, len,
189 config->descriptors);
196 /* add each function's descriptors */
197 list_for_each_entry(f, &config->functions, list) {
198 struct usb_descriptor_header **descriptors;
200 if (speed == USB_SPEED_HIGH)
201 descriptors = f->hs_descriptors;
203 descriptors = f->descriptors;
206 status = usb_descriptor_fillbuf(next, len,
207 (const struct usb_descriptor_header **) descriptors);
215 c->wTotalLength = cpu_to_le16(len);
219 static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
221 struct usb_gadget *gadget = cdev->gadget;
222 struct usb_configuration *c;
223 u8 type = w_value >> 8;
224 enum usb_device_speed speed = USB_SPEED_UNKNOWN;
226 if (gadget_is_dualspeed(gadget)) {
229 if (gadget->speed == USB_SPEED_HIGH)
231 if (type == USB_DT_OTHER_SPEED_CONFIG)
234 speed = USB_SPEED_HIGH;
238 /* This is a lookup by config *INDEX* */
240 list_for_each_entry(c, &cdev->configs, list) {
241 /* ignore configs that won't work at this speed */
242 if (speed == USB_SPEED_HIGH) {
250 return config_buf(c, speed, cdev->req->buf, type);
256 static int count_configs(struct usb_composite_dev *cdev, unsigned type)
258 struct usb_gadget *gadget = cdev->gadget;
259 struct usb_configuration *c;
263 if (gadget_is_dualspeed(gadget)) {
264 if (gadget->speed == USB_SPEED_HIGH)
266 if (type == USB_DT_DEVICE_QUALIFIER)
269 list_for_each_entry(c, &cdev->configs, list) {
270 /* ignore configs that won't work at this speed */
283 static void device_qual(struct usb_composite_dev *cdev)
285 struct usb_qualifier_descriptor *qual = cdev->req->buf;
287 qual->bLength = sizeof(*qual);
288 qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
289 /* POLICY: same bcdUSB and device type info at both speeds */
290 qual->bcdUSB = cdev->desc.bcdUSB;
291 qual->bDeviceClass = cdev->desc.bDeviceClass;
292 qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
293 qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
294 /* ASSUME same EP0 fifo size at both speeds */
295 qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0;
296 qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
300 /*-------------------------------------------------------------------------*/
302 static void reset_config(struct usb_composite_dev *cdev)
304 struct usb_function *f;
306 DBG(cdev, "reset config\n");
308 list_for_each_entry(f, &cdev->config->functions, list) {
315 static int set_config(struct usb_composite_dev *cdev,
316 const struct usb_ctrlrequest *ctrl, unsigned number)
318 struct usb_gadget *gadget = cdev->gadget;
319 struct usb_configuration *c = NULL;
320 int result = -EINVAL;
321 unsigned power = gadget_is_otg(gadget) ? 8 : 100;
328 list_for_each_entry(c, &cdev->configs, list) {
329 if (c->bConfigurationValue == number) {
339 INFO(cdev, "%s speed config #%d: %s\n",
341 switch (gadget->speed) {
342 case USB_SPEED_LOW: speed = "low"; break;
343 case USB_SPEED_FULL: speed = "full"; break;
344 case USB_SPEED_HIGH: speed = "high"; break;
345 default: speed = "?"; break;
346 } ; speed; }), number, c ? c->label : "unconfigured");
353 /* Initialize all interfaces by setting them to altsetting zero. */
354 for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
355 struct usb_function *f = c->interface[tmp];
360 result = f->set_alt(f, tmp, 0);
362 DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n",
363 tmp, f->name, f, result);
370 /* when we return, be sure our power usage is valid */
371 power = 2 * c->bMaxPower;
373 usb_gadget_vbus_draw(gadget, power);
378 * usb_add_config() - add a configuration to a device.
379 * @cdev: wraps the USB gadget
380 * @config: the configuration, with bConfigurationValue assigned
381 * Context: single threaded during gadget setup
383 * One of the main tasks of a composite driver's bind() routine is to
384 * add each of the configurations it supports, using this routine.
386 * This function returns the value of the configuration's bind(), which
387 * is zero for success else a negative errno value. Binding configurations
388 * assigns global resources including string IDs, and per-configuration
389 * resources such as interface IDs and endpoints.
391 int __init usb_add_config(struct usb_composite_dev *cdev,
392 struct usb_configuration *config)
394 int status = -EINVAL;
395 struct usb_configuration *c;
397 DBG(cdev, "adding config #%u '%s'/%p\n",
398 config->bConfigurationValue,
399 config->label, config);
401 if (!config->bConfigurationValue || !config->bind)
404 /* Prevent duplicate configuration identifiers */
405 list_for_each_entry(c, &cdev->configs, list) {
406 if (c->bConfigurationValue == config->bConfigurationValue) {
413 list_add_tail(&config->list, &cdev->configs);
415 INIT_LIST_HEAD(&config->functions);
416 config->next_interface_id = 0;
418 status = config->bind(config);
420 list_del(&config->list);
425 DBG(cdev, "cfg %d/%p speeds:%s%s\n",
426 config->bConfigurationValue, config,
427 config->highspeed ? " high" : "",
429 ? (gadget_is_dualspeed(cdev->gadget)
434 for (i = 0; i < MAX_CONFIG_INTERFACES; i++) {
435 struct usb_function *f = config->interface[i];
439 DBG(cdev, " interface %d = %s/%p\n",
444 /* set_alt(), or next config->bind(), sets up
445 * ep->driver_data as needed.
447 usb_ep_autoconfig_reset(cdev->gadget);
451 DBG(cdev, "added config '%s'/%u --> %d\n", config->label,
452 config->bConfigurationValue, status);
456 /*-------------------------------------------------------------------------*/
458 /* We support strings in multiple languages ... string descriptor zero
459 * says which languages are supported. The typical case will be that
460 * only one language (probably English) is used, with I18N handled on
464 static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
466 const struct usb_gadget_strings *s;
472 language = cpu_to_le16(s->language);
473 for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) {
474 if (*tmp == language)
483 static int lookup_string(
484 struct usb_gadget_strings **sp,
490 struct usb_gadget_strings *s;
495 if (s->language != language)
497 value = usb_gadget_get_string(s, id, buf);
504 static int get_string(struct usb_composite_dev *cdev,
505 void *buf, u16 language, int id)
507 struct usb_configuration *c;
508 struct usb_function *f;
511 /* Yes, not only is USB's I18N support probably more than most
512 * folk will ever care about ... also, it's all supported here.
513 * (Except for UTF8 support for Unicode's "Astral Planes".)
516 /* 0 == report all available language codes */
518 struct usb_string_descriptor *s = buf;
519 struct usb_gadget_strings **sp;
522 s->bDescriptorType = USB_DT_STRING;
524 sp = composite->strings;
526 collect_langs(sp, s->wData);
528 list_for_each_entry(c, &cdev->configs, list) {
531 collect_langs(sp, s->wData);
533 list_for_each_entry(f, &c->functions, list) {
536 collect_langs(sp, s->wData);
540 for (len = 0; s->wData[len] && len <= 126; len++)
545 s->bLength = 2 * (len + 1);
549 /* Otherwise, look up and return a specified string. String IDs
550 * are device-scoped, so we look up each string table we're told
551 * about. These lookups are infrequent; simpler-is-better here.
553 if (composite->strings) {
554 len = lookup_string(composite->strings, buf, language, id);
558 list_for_each_entry(c, &cdev->configs, list) {
560 len = lookup_string(c->strings, buf, language, id);
564 list_for_each_entry(f, &c->functions, list) {
567 len = lookup_string(f->strings, buf, language, id);
576 * usb_string_id() - allocate an unused string ID
577 * @cdev: the device whose string descriptor IDs are being allocated
578 * Context: single threaded during gadget setup
580 * @usb_string_id() is called from bind() callbacks to allocate
581 * string IDs. Drivers for functions, configurations, or gadgets will
582 * then store that ID in the appropriate descriptors and string table.
584 * All string identifier should be allocated using this routine, to
585 * ensure that for example different functions don't wrongly assign
586 * different meanings to the same identifier.
588 int __init usb_string_id(struct usb_composite_dev *cdev)
590 if (cdev->next_string_id < 254) {
591 /* string id 0 is reserved */
592 cdev->next_string_id++;
593 return cdev->next_string_id;
598 /*-------------------------------------------------------------------------*/
600 static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
602 if (req->status || req->actual != req->length)
603 DBG((struct usb_composite_dev *) ep->driver_data,
604 "setup complete --> %d, %d/%d\n",
605 req->status, req->actual, req->length);
609 * The setup() callback implements all the ep0 functionality that's
610 * not handled lower down, in hardware or the hardware driver(like
611 * device and endpoint feature flags, and their status). It's all
612 * housekeeping for the gadget function we're implementing. Most of
613 * the work is in config and function specific setup.
616 composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
618 struct usb_composite_dev *cdev = get_gadget_data(gadget);
619 struct usb_request *req = cdev->req;
620 int value = -EOPNOTSUPP;
621 u16 w_index = le16_to_cpu(ctrl->wIndex);
622 u16 w_value = le16_to_cpu(ctrl->wValue);
623 u16 w_length = le16_to_cpu(ctrl->wLength);
624 struct usb_function *f = NULL;
626 /* partial re-init of the response message; the function or the
627 * gadget might need to intercept e.g. a control-OUT completion
628 * when we delegate to it.
631 req->complete = composite_setup_complete;
632 req->length = USB_BUFSIZ;
633 gadget->ep0->driver_data = cdev;
635 switch (ctrl->bRequest) {
637 /* we handle all standard USB descriptors */
638 case USB_REQ_GET_DESCRIPTOR:
639 if (ctrl->bRequestType != USB_DIR_IN)
641 switch (w_value >> 8) {
644 cdev->desc.bNumConfigurations =
645 count_configs(cdev, USB_DT_DEVICE);
646 value = min(w_length, (u16) sizeof cdev->desc);
647 memcpy(req->buf, &cdev->desc, value);
649 case USB_DT_DEVICE_QUALIFIER:
650 if (!gadget_is_dualspeed(gadget))
653 value = min_t(int, w_length,
654 sizeof(struct usb_qualifier_descriptor));
656 case USB_DT_OTHER_SPEED_CONFIG:
657 if (!gadget_is_dualspeed(gadget))
661 value = config_desc(cdev, w_value);
663 value = min(w_length, (u16) value);
666 value = get_string(cdev, req->buf,
667 w_index, w_value & 0xff);
669 value = min(w_length, (u16) value);
674 /* any number of configs can work */
675 case USB_REQ_SET_CONFIGURATION:
676 if (ctrl->bRequestType != 0)
678 if (gadget_is_otg(gadget)) {
679 if (gadget->a_hnp_support)
680 DBG(cdev, "HNP available\n");
681 else if (gadget->a_alt_hnp_support)
682 DBG(cdev, "HNP on another port\n");
684 VDBG(cdev, "HNP inactive\n");
686 spin_lock(&cdev->lock);
687 value = set_config(cdev, ctrl, w_value);
688 spin_unlock(&cdev->lock);
690 case USB_REQ_GET_CONFIGURATION:
691 if (ctrl->bRequestType != USB_DIR_IN)
694 *(u8 *)req->buf = cdev->config->bConfigurationValue;
697 value = min(w_length, (u16) 1);
700 /* function drivers must handle get/set altsetting; if there's
701 * no get() method, we know only altsetting zero works.
703 case USB_REQ_SET_INTERFACE:
704 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
706 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
708 f = cdev->config->interface[w_index];
711 if (w_value && !f->get_alt)
713 value = f->set_alt(f, w_index, w_value);
715 case USB_REQ_GET_INTERFACE:
716 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
718 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
720 f = cdev->config->interface[w_index];
723 /* lots of interfaces only need altsetting zero... */
724 value = f->get_alt ? f->get_alt(f, w_index) : 0;
727 *((u8 *)req->buf) = value;
728 value = min(w_length, (u16) 1);
733 "non-core control req%02x.%02x v%04x i%04x l%d\n",
734 ctrl->bRequestType, ctrl->bRequest,
735 w_value, w_index, w_length);
737 /* functions always handle their interfaces ... punt other
738 * recipients (endpoint, other, WUSB, ...) to the current
739 * configuration code.
741 * REVISIT it could make sense to let the composite device
742 * take such requests too, if that's ever needed: to work
745 if ((ctrl->bRequestType & USB_RECIP_MASK)
746 == USB_RECIP_INTERFACE) {
747 f = cdev->config->interface[w_index];
749 value = f->setup(f, ctrl);
753 if (value < 0 && !f) {
754 struct usb_configuration *c;
758 value = c->setup(c, ctrl);
764 /* respond with data transfer before status phase? */
767 req->zero = value < w_length;
768 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
770 DBG(cdev, "ep_queue --> %d\n", value);
772 composite_setup_complete(gadget->ep0, req);
777 /* device either stalls (value < 0) or reports success */
781 static void composite_disconnect(struct usb_gadget *gadget)
783 struct usb_composite_dev *cdev = get_gadget_data(gadget);
786 /* REVISIT: should we have config and device level
787 * disconnect callbacks?
789 spin_lock_irqsave(&cdev->lock, flags);
792 spin_unlock_irqrestore(&cdev->lock, flags);
795 /*-------------------------------------------------------------------------*/
797 static void /* __init_or_exit */
798 composite_unbind(struct usb_gadget *gadget)
800 struct usb_composite_dev *cdev = get_gadget_data(gadget);
802 /* composite_disconnect() must already have been called
803 * by the underlying peripheral controller driver!
804 * so there's no i/o concurrency that could affect the
805 * state protected by cdev->lock.
807 WARN_ON(cdev->config);
809 while (!list_empty(&cdev->configs)) {
810 struct usb_configuration *c;
812 c = list_first_entry(&cdev->configs,
813 struct usb_configuration, list);
814 while (!list_empty(&c->functions)) {
815 struct usb_function *f;
817 f = list_first_entry(&c->functions,
818 struct usb_function, list);
821 DBG(cdev, "unbind function '%s'/%p\n",
824 /* may free memory for "f" */
829 DBG(cdev, "unbind config '%s'/%p\n", c->label, c);
831 /* may free memory for "c" */
834 if (composite->unbind)
835 composite->unbind(cdev);
838 kfree(cdev->req->buf);
839 usb_ep_free_request(gadget->ep0, cdev->req);
842 set_gadget_data(gadget, NULL);
847 string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
849 struct usb_string *str = tab->strings;
851 for (str = tab->strings; str->s; str++) {
860 string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
863 string_override_one(*tab, id, s);
868 static int __init composite_bind(struct usb_gadget *gadget)
870 struct usb_composite_dev *cdev;
871 int status = -ENOMEM;
873 cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
877 spin_lock_init(&cdev->lock);
878 cdev->gadget = gadget;
879 set_gadget_data(gadget, cdev);
880 INIT_LIST_HEAD(&cdev->configs);
882 /* preallocate control response and buffer */
883 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
886 cdev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
889 cdev->req->complete = composite_setup_complete;
890 gadget->ep0->driver_data = cdev;
892 cdev->bufsiz = USB_BUFSIZ;
893 cdev->driver = composite;
895 usb_gadget_set_selfpowered(gadget);
897 /* interface and string IDs start at zero via kzalloc.
898 * we force endpoints to start unassigned; few controller
899 * drivers will zero ep->driver_data.
901 usb_ep_autoconfig_reset(cdev->gadget);
903 /* composite gadget needs to assign strings for whole device (like
904 * serial number), register function drivers, potentially update
905 * power state and consumption, etc
907 status = composite->bind(cdev);
911 cdev->desc = *composite->dev;
912 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
914 /* standardized runtime overrides for device ID data */
916 cdev->desc.idVendor = cpu_to_le16(idVendor);
918 cdev->desc.idProduct = cpu_to_le16(idProduct);
920 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
922 /* strings can't be assigned before bind() allocates the
923 * releavnt identifiers
925 if (cdev->desc.iManufacturer && iManufacturer)
926 string_override(composite->strings,
927 cdev->desc.iManufacturer, iManufacturer);
928 if (cdev->desc.iProduct && iProduct)
929 string_override(composite->strings,
930 cdev->desc.iProduct, iProduct);
931 if (cdev->desc.iSerialNumber && iSerialNumber)
932 string_override(composite->strings,
933 cdev->desc.iSerialNumber, iSerialNumber);
935 INFO(cdev, "%s ready\n", composite->name);
939 composite_unbind(gadget);
943 /*-------------------------------------------------------------------------*/
946 composite_suspend(struct usb_gadget *gadget)
948 struct usb_composite_dev *cdev = get_gadget_data(gadget);
949 struct usb_function *f;
951 /* REVISIT: should we have config and device level
952 * suspend/resume callbacks?
954 DBG(cdev, "suspend\n");
956 list_for_each_entry(f, &cdev->config->functions, list) {
964 composite_resume(struct usb_gadget *gadget)
966 struct usb_composite_dev *cdev = get_gadget_data(gadget);
967 struct usb_function *f;
969 /* REVISIT: should we have config and device level
970 * suspend/resume callbacks?
972 DBG(cdev, "resume\n");
974 list_for_each_entry(f, &cdev->config->functions, list) {
981 /*-------------------------------------------------------------------------*/
983 static struct usb_gadget_driver composite_driver = {
984 .speed = USB_SPEED_HIGH,
986 .bind = composite_bind,
987 .unbind = __exit_p(composite_unbind),
989 .setup = composite_setup,
990 .disconnect = composite_disconnect,
992 .suspend = composite_suspend,
993 .resume = composite_resume,
996 .owner = THIS_MODULE,
1001 * usb_composite_register() - register a composite driver
1002 * @driver: the driver to register
1003 * Context: single threaded during gadget setup
1005 * This function is used to register drivers using the composite driver
1006 * framework. The return value is zero, or a negative errno value.
1007 * Those values normally come from the driver's @bind method, which does
1008 * all the work of setting up the driver to match the hardware.
1010 * On successful return, the gadget is ready to respond to requests from
1011 * the host, unless one of its components invokes usb_gadget_disconnect()
1012 * while it was binding. That would usually be done in order to wait for
1013 * some userspace participation.
1015 int __init usb_composite_register(struct usb_composite_driver *driver)
1017 if (!driver || !driver->dev || !driver->bind || composite)
1021 driver->name = "composite";
1022 composite_driver.function = (char *) driver->name;
1023 composite_driver.driver.name = driver->name;
1026 return usb_gadget_register_driver(&composite_driver);
1030 * usb_composite_unregister() - unregister a composite driver
1031 * @driver: the driver to unregister
1033 * This function is used to unregister drivers using the composite
1036 void __exit usb_composite_unregister(struct usb_composite_driver *driver)
1038 if (composite != driver)
1040 usb_gadget_unregister_driver(&composite_driver);