2 * composite.c - infrastructure for Composite USB Gadgets
4 * Copyright (C) 2006-2008 David Brownell
5 * U-boot porting: Lukasz Majewski <l.majewski@samsung.com>
7 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/bitops.h>
12 #include <linux/usb/composite.h>
14 #define USB_BUFSIZ 4096
16 static struct usb_composite_driver *composite;
19 * usb_add_function() - add a function to a configuration
20 * @config: the configuration
21 * @function: the function being added
22 * Context: single threaded during gadget setup
24 * After initialization, each configuration must have one or more
25 * functions added to it. Adding a function involves calling its @bind()
26 * method to allocate resources such as interface and string identifiers
29 * This function returns the value of the function's bind(), which is
30 * zero for success else a negative errno value.
32 int usb_add_function(struct usb_configuration *config,
33 struct usb_function *function)
37 debug("adding '%s'/%p to config '%s'/%p\n",
38 function->name, function,
39 config->label, config);
41 if (!function->set_alt || !function->disable)
44 function->config = config;
45 list_add_tail(&function->list, &config->functions);
48 value = function->bind(config, function);
50 list_del(&function->list);
51 function->config = NULL;
56 if (!config->fullspeed && function->descriptors)
57 config->fullspeed = 1;
58 if (!config->highspeed && function->hs_descriptors)
59 config->highspeed = 1;
63 debug("adding '%s'/%p --> %d\n",
64 function->name, function, value);
69 * usb_function_deactivate - prevent function and gadget enumeration
70 * @function: the function that isn't yet ready to respond
72 * Blocks response of the gadget driver to host enumeration by
73 * preventing the data line pullup from being activated. This is
74 * normally called during @bind() processing to change from the
75 * initial "ready to respond" state, or when a required resource
78 * For example, drivers that serve as a passthrough to a userspace
79 * daemon can block enumeration unless that daemon (such as an OBEX,
80 * MTP, or print server) is ready to handle host requests.
82 * Not all systems support software control of their USB peripheral
85 * Returns zero on success, else negative errno.
87 int usb_function_deactivate(struct usb_function *function)
89 struct usb_composite_dev *cdev = function->config->cdev;
92 if (cdev->deactivations == 0)
93 status = usb_gadget_disconnect(cdev->gadget);
95 cdev->deactivations++;
101 * usb_function_activate - allow function and gadget enumeration
102 * @function: function on which usb_function_activate() was called
104 * Reverses effect of usb_function_deactivate(). If no more functions
105 * are delaying their activation, the gadget driver will respond to
106 * host enumeration procedures.
108 * Returns zero on success, else negative errno.
110 int usb_function_activate(struct usb_function *function)
112 struct usb_composite_dev *cdev = function->config->cdev;
115 if (cdev->deactivations == 0)
118 cdev->deactivations--;
119 if (cdev->deactivations == 0)
120 status = usb_gadget_connect(cdev->gadget);
127 * usb_interface_id() - allocate an unused interface ID
128 * @config: configuration associated with the interface
129 * @function: function handling the interface
130 * Context: single threaded during gadget setup
132 * usb_interface_id() is called from usb_function.bind() callbacks to
133 * allocate new interface IDs. The function driver will then store that
134 * ID in interface, association, CDC union, and other descriptors. It
135 * will also handle any control requests targetted at that interface,
136 * particularly changing its altsetting via set_alt(). There may
137 * also be class-specific or vendor-specific requests to handle.
139 * All interface identifier should be allocated using this routine, to
140 * ensure that for example different functions don't wrongly assign
141 * different meanings to the same identifier. Note that since interface
142 * identifers are configuration-specific, functions used in more than
143 * one configuration (or more than once in a given configuration) need
144 * multiple versions of the relevant descriptors.
146 * Returns the interface ID which was allocated; or -ENODEV if no
147 * more interface IDs can be allocated.
149 int usb_interface_id(struct usb_configuration *config,
150 struct usb_function *function)
152 unsigned char id = config->next_interface_id;
154 if (id < MAX_CONFIG_INTERFACES) {
155 config->interface[id] = function;
156 config->next_interface_id = id + 1;
162 static int config_buf(struct usb_configuration *config,
163 enum usb_device_speed speed, void *buf, u8 type)
165 int len = USB_BUFSIZ - USB_DT_CONFIG_SIZE;
166 void *next = buf + USB_DT_CONFIG_SIZE;
167 struct usb_descriptor_header **descriptors;
168 struct usb_config_descriptor *c = buf;
170 struct usb_function *f;
172 /* write the config descriptor */
174 c->bLength = USB_DT_CONFIG_SIZE;
175 c->bDescriptorType = type;
177 c->bNumInterfaces = config->next_interface_id;
178 c->bConfigurationValue = config->bConfigurationValue;
179 c->iConfiguration = config->iConfiguration;
180 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
181 c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2);
183 /* There may be e.g. OTG descriptors */
184 if (config->descriptors) {
185 status = usb_descriptor_fillbuf(next, len,
186 config->descriptors);
193 /* add each function's descriptors */
194 list_for_each_entry(f, &config->functions, list) {
195 if (speed == USB_SPEED_HIGH)
196 descriptors = f->hs_descriptors;
198 descriptors = f->descriptors;
201 status = usb_descriptor_fillbuf(next, len,
202 (const struct usb_descriptor_header **) descriptors);
210 c->wTotalLength = cpu_to_le16(len);
214 static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
216 enum usb_device_speed speed = USB_SPEED_UNKNOWN;
217 struct usb_gadget *gadget = cdev->gadget;
218 u8 type = w_value >> 8;
220 struct usb_configuration *c;
222 if (gadget_is_dualspeed(gadget)) {
223 if (gadget->speed == USB_SPEED_HIGH)
225 if (type == USB_DT_OTHER_SPEED_CONFIG)
228 speed = USB_SPEED_HIGH;
232 list_for_each_entry(c, &cdev->configs, list) {
233 if (speed == USB_SPEED_HIGH) {
241 return config_buf(c, speed, cdev->req->buf, type);
247 static int count_configs(struct usb_composite_dev *cdev, unsigned type)
249 struct usb_gadget *gadget = cdev->gadget;
252 struct usb_configuration *c;
254 if (gadget_is_dualspeed(gadget)) {
255 if (gadget->speed == USB_SPEED_HIGH)
257 if (type == USB_DT_DEVICE_QUALIFIER)
260 list_for_each_entry(c, &cdev->configs, list) {
261 /* ignore configs that won't work at this speed */
274 static void device_qual(struct usb_composite_dev *cdev)
276 struct usb_qualifier_descriptor *qual = cdev->req->buf;
278 qual->bLength = sizeof(*qual);
279 qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
280 /* POLICY: same bcdUSB and device type info at both speeds */
281 qual->bcdUSB = cdev->desc.bcdUSB;
282 qual->bDeviceClass = cdev->desc.bDeviceClass;
283 qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
284 qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
285 /* ASSUME same EP0 fifo size at both speeds */
286 qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0;
287 qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
291 static void reset_config(struct usb_composite_dev *cdev)
293 struct usb_function *f;
295 debug("%s:\n", __func__);
297 list_for_each_entry(f, &cdev->config->functions, list) {
301 bitmap_zero(f->endpoints, 32);
306 static int set_config(struct usb_composite_dev *cdev,
307 const struct usb_ctrlrequest *ctrl, unsigned number)
309 struct usb_gadget *gadget = cdev->gadget;
310 unsigned power = gadget_is_otg(gadget) ? 8 : 100;
311 struct usb_descriptor_header **descriptors;
312 int result = -EINVAL;
313 struct usb_endpoint_descriptor *ep;
314 struct usb_configuration *c = NULL;
317 struct usb_function *f;
323 list_for_each_entry(c, &cdev->configs, list) {
324 if (c->bConfigurationValue == number) {
334 debug("%s: %s speed config #%d: %s\n", __func__,
336 switch (gadget->speed) {
351 }), number, c ? c->label : "unconfigured");
358 /* Initialize all interfaces by setting them to altsetting zero. */
359 for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
360 f = c->interface[tmp];
365 * Record which endpoints are used by the function. This is used
366 * to dispatch control requests targeted at that endpoint to the
367 * function's setup callback instead of the current
368 * configuration's setup callback.
370 if (gadget->speed == USB_SPEED_HIGH)
371 descriptors = f->hs_descriptors;
373 descriptors = f->descriptors;
375 for (; *descriptors; ++descriptors) {
376 if ((*descriptors)->bDescriptorType != USB_DT_ENDPOINT)
379 ep = (struct usb_endpoint_descriptor *)*descriptors;
380 addr = ((ep->bEndpointAddress & 0x80) >> 3)
381 | (ep->bEndpointAddress & 0x0f);
382 __set_bit(addr, f->endpoints);
385 result = f->set_alt(f, tmp, 0);
387 debug("interface %d (%s/%p) alt 0 --> %d\n",
388 tmp, f->name, f, result);
395 /* when we return, be sure our power usage is valid */
396 power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
398 usb_gadget_vbus_draw(gadget, power);
403 * usb_add_config() - add a configuration to a device.
404 * @cdev: wraps the USB gadget
405 * @config: the configuration, with bConfigurationValue assigned
406 * Context: single threaded during gadget setup
408 * One of the main tasks of a composite driver's bind() routine is to
409 * add each of the configurations it supports, using this routine.
411 * This function returns the value of the configuration's bind(), which
412 * is zero for success else a negative errno value. Binding configurations
413 * assigns global resources including string IDs, and per-configuration
414 * resources such as interface IDs and endpoints.
416 int usb_add_config(struct usb_composite_dev *cdev,
417 struct usb_configuration *config)
419 int status = -EINVAL;
420 struct usb_configuration *c;
421 struct usb_function *f;
424 debug("%s: adding config #%u '%s'/%p\n", __func__,
425 config->bConfigurationValue,
426 config->label, config);
428 if (!config->bConfigurationValue || !config->bind)
431 /* Prevent duplicate configuration identifiers */
432 list_for_each_entry(c, &cdev->configs, list) {
433 if (c->bConfigurationValue == config->bConfigurationValue) {
440 list_add_tail(&config->list, &cdev->configs);
442 INIT_LIST_HEAD(&config->functions);
443 config->next_interface_id = 0;
445 status = config->bind(config);
447 list_del(&config->list);
450 debug("cfg %d/%p speeds:%s%s\n",
451 config->bConfigurationValue, config,
452 config->highspeed ? " high" : "",
454 ? (gadget_is_dualspeed(cdev->gadget)
459 for (i = 0; i < MAX_CONFIG_INTERFACES; i++) {
460 f = config->interface[i];
463 debug("%s: interface %d = %s/%p\n",
464 __func__, i, f->name, f);
468 usb_ep_autoconfig_reset(cdev->gadget);
472 debug("added config '%s'/%u --> %d\n", config->label,
473 config->bConfigurationValue, status);
478 * We support strings in multiple languages ... string descriptor zero
479 * says which languages are supported. The typical case will be that
480 * only one language (probably English) is used, with I18N handled on
484 static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
486 const struct usb_gadget_strings *s;
492 language = cpu_to_le16(s->language);
493 for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) {
494 if (*tmp == language)
503 static int lookup_string(
504 struct usb_gadget_strings **sp,
511 struct usb_gadget_strings *s;
515 if (s->language != language)
517 value = usb_gadget_get_string(s, id, buf);
524 static int get_string(struct usb_composite_dev *cdev,
525 void *buf, u16 language, int id)
527 struct usb_string_descriptor *s = buf;
528 struct usb_gadget_strings **sp;
530 struct usb_configuration *c;
531 struct usb_function *f;
534 * Yes, not only is USB's I18N support probably more than most
535 * folk will ever care about ... also, it's all supported here.
536 * (Except for UTF8 support for Unicode's "Astral Planes".)
539 /* 0 == report all available language codes */
542 s->bDescriptorType = USB_DT_STRING;
544 sp = composite->strings;
546 collect_langs(sp, s->wData);
548 list_for_each_entry(c, &cdev->configs, list) {
551 collect_langs(sp, s->wData);
553 list_for_each_entry(f, &c->functions, list) {
556 collect_langs(sp, s->wData);
560 for (len = 0; len <= 126 && s->wData[len]; len++)
565 s->bLength = 2 * (len + 1);
570 * Otherwise, look up and return a specified string. String IDs
571 * are device-scoped, so we look up each string table we're told
572 * about. These lookups are infrequent; simpler-is-better here.
574 if (composite->strings) {
575 len = lookup_string(composite->strings, buf, language, id);
579 list_for_each_entry(c, &cdev->configs, list) {
581 len = lookup_string(c->strings, buf, language, id);
585 list_for_each_entry(f, &c->functions, list) {
588 len = lookup_string(f->strings, buf, language, id);
597 * usb_string_id() - allocate an unused string ID
598 * @cdev: the device whose string descriptor IDs are being allocated
599 * Context: single threaded during gadget setup
601 * @usb_string_id() is called from bind() callbacks to allocate
602 * string IDs. Drivers for functions, configurations, or gadgets will
603 * then store that ID in the appropriate descriptors and string table.
605 * All string identifier should be allocated using this,
606 * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure
607 * that for example different functions don't wrongly assign different
608 * meanings to the same identifier.
610 int usb_string_id(struct usb_composite_dev *cdev)
612 if (cdev->next_string_id < 254) {
614 * string id 0 is reserved by USB spec for list of
615 * supported languages
616 * 255 reserved as well? -- mina86
618 cdev->next_string_id++;
619 return cdev->next_string_id;
625 * usb_string_ids() - allocate unused string IDs in batch
626 * @cdev: the device whose string descriptor IDs are being allocated
627 * @str: an array of usb_string objects to assign numbers to
628 * Context: single threaded during gadget setup
630 * @usb_string_ids() is called from bind() callbacks to allocate
631 * string IDs. Drivers for functions, configurations, or gadgets will
632 * then copy IDs from the string table to the appropriate descriptors
633 * and string table for other languages.
635 * All string identifier should be allocated using this,
636 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
637 * example different functions don't wrongly assign different meanings
638 * to the same identifier.
640 int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
642 u8 next = cdev->next_string_id;
644 for (; str->s; ++str) {
650 cdev->next_string_id = next;
656 * usb_string_ids_n() - allocate unused string IDs in batch
657 * @c: the device whose string descriptor IDs are being allocated
658 * @n: number of string IDs to allocate
659 * Context: single threaded during gadget setup
661 * Returns the first requested ID. This ID and next @n-1 IDs are now
662 * valid IDs. At least provided that @n is non-zero because if it
663 * is, returns last requested ID which is now very useful information.
665 * @usb_string_ids_n() is called from bind() callbacks to allocate
666 * string IDs. Drivers for functions, configurations, or gadgets will
667 * then store that ID in the appropriate descriptors and string table.
669 * All string identifier should be allocated using this,
670 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
671 * example different functions don't wrongly assign different meanings
672 * to the same identifier.
674 int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
676 u8 next = c->next_string_id;
678 if (n > 254 || next + n > 254)
681 c->next_string_id += n;
685 static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
687 if (req->status || req->actual != req->length)
688 debug("%s: setup complete --> %d, %d/%d\n", __func__,
689 req->status, req->actual, req->length);
693 * The setup() callback implements all the ep0 functionality that's
694 * not handled lower down, in hardware or the hardware driver(like
695 * device and endpoint feature flags, and their status). It's all
696 * housekeeping for the gadget function we're implementing. Most of
697 * the work is in config and function specific setup.
700 composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
702 u16 w_length = le16_to_cpu(ctrl->wLength);
703 u16 w_index = le16_to_cpu(ctrl->wIndex);
704 u16 w_value = le16_to_cpu(ctrl->wValue);
705 struct usb_composite_dev *cdev = get_gadget_data(gadget);
706 u8 intf = w_index & 0xFF;
707 int value = -EOPNOTSUPP;
708 struct usb_request *req = cdev->req;
709 struct usb_function *f = NULL;
712 struct usb_configuration *c;
715 * partial re-init of the response message; the function or the
716 * gadget might need to intercept e.g. a control-OUT completion
717 * when we delegate to it.
720 req->complete = composite_setup_complete;
721 req->length = USB_BUFSIZ;
722 gadget->ep0->driver_data = cdev;
723 standard = (ctrl->bRequestType & USB_TYPE_MASK)
724 == USB_TYPE_STANDARD;
728 switch (ctrl->bRequest) {
730 /* we handle all standard USB descriptors */
731 case USB_REQ_GET_DESCRIPTOR:
732 if (ctrl->bRequestType != USB_DIR_IN)
734 switch (w_value >> 8) {
737 cdev->desc.bNumConfigurations =
738 count_configs(cdev, USB_DT_DEVICE);
739 value = min(w_length, (u16) sizeof cdev->desc);
740 memcpy(req->buf, &cdev->desc, value);
742 case USB_DT_DEVICE_QUALIFIER:
743 if (!gadget_is_dualspeed(gadget))
746 value = min_t(int, w_length,
747 sizeof(struct usb_qualifier_descriptor));
749 case USB_DT_OTHER_SPEED_CONFIG:
750 if (!gadget_is_dualspeed(gadget))
754 value = config_desc(cdev, w_value);
756 value = min(w_length, (u16) value);
759 value = get_string(cdev, req->buf,
760 w_index, w_value & 0xff);
762 value = min(w_length, (u16) value);
769 /* any number of configs can work */
770 case USB_REQ_SET_CONFIGURATION:
771 if (ctrl->bRequestType != 0)
773 if (gadget_is_otg(gadget)) {
774 if (gadget->a_hnp_support)
775 debug("HNP available\n");
776 else if (gadget->a_alt_hnp_support)
777 debug("HNP on another port\n");
779 debug("HNP inactive\n");
782 value = set_config(cdev, ctrl, w_value);
784 case USB_REQ_GET_CONFIGURATION:
785 if (ctrl->bRequestType != USB_DIR_IN)
788 *(u8 *)req->buf = cdev->config->bConfigurationValue;
791 value = min(w_length, (u16) 1);
795 * function drivers must handle get/set altsetting; if there's
796 * no get() method, we know only altsetting zero works.
798 case USB_REQ_SET_INTERFACE:
799 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
801 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
803 f = cdev->config->interface[intf];
806 if (w_value && !f->set_alt)
808 value = f->set_alt(f, w_index, w_value);
810 case USB_REQ_GET_INTERFACE:
811 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
813 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
815 f = cdev->config->interface[intf];
818 /* lots of interfaces only need altsetting zero... */
819 value = f->get_alt ? f->get_alt(f, w_index) : 0;
822 *((u8 *)req->buf) = value;
823 value = min(w_length, (u16) 1);
827 debug("non-core control req%02x.%02x v%04x i%04x l%d\n",
828 ctrl->bRequestType, ctrl->bRequest,
829 w_value, w_index, w_length);
832 * functions always handle their interfaces and endpoints...
833 * punt other recipients (other, WUSB, ...) to the current
834 * configuration code.
836 switch (ctrl->bRequestType & USB_RECIP_MASK) {
837 case USB_RECIP_INTERFACE:
838 f = cdev->config->interface[intf];
841 case USB_RECIP_ENDPOINT:
842 endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f);
843 list_for_each_entry(f, &cdev->config->functions, list) {
844 if (test_bit(endp, f->endpoints))
847 if (&f->list == &cdev->config->functions)
851 * dfu-util (version 0.5) sets bmRequestType.Receipent = Device
852 * for non-standard request (w_value = 0x21,
853 * bRequest = GET_DESCRIPTOR in this case).
854 * When only one interface is registered (as it is done now),
855 * then this request shall be handled as it was requested for
858 * In the below code it is checked if only one interface is
859 * present and proper function for it is extracted. Due to that
860 * function's setup (f->setup) is called to handle this
861 * special non-standard request.
863 case USB_RECIP_DEVICE:
864 debug("cdev->config->next_interface_id: %d intf: %d\n",
865 cdev->config->next_interface_id, intf);
866 if (cdev->config->next_interface_id == 1)
867 f = cdev->config->interface[intf];
872 value = f->setup(f, ctrl);
876 value = c->setup(c, ctrl);
882 /* respond with data transfer before status phase? */
885 req->zero = value < w_length;
886 value = usb_ep_queue(gadget->ep0, req, GFP_KERNEL);
888 debug("ep_queue --> %d\n", value);
890 composite_setup_complete(gadget->ep0, req);
895 /* device either stalls (value < 0) or reports success */
899 static void composite_disconnect(struct usb_gadget *gadget)
901 struct usb_composite_dev *cdev = get_gadget_data(gadget);
905 if (composite->disconnect)
906 composite->disconnect(cdev);
909 static void composite_unbind(struct usb_gadget *gadget)
911 struct usb_composite_dev *cdev = get_gadget_data(gadget);
912 struct usb_configuration *c;
913 struct usb_function *f;
916 * composite_disconnect() must already have been called
917 * by the underlying peripheral controller driver!
918 * so there's no i/o concurrency that could affect the
919 * state protected by cdev->lock.
921 BUG_ON(cdev->config);
923 while (!list_empty(&cdev->configs)) {
924 c = list_first_entry(&cdev->configs,
925 struct usb_configuration, list);
926 while (!list_empty(&c->functions)) {
927 f = list_first_entry(&c->functions,
928 struct usb_function, list);
931 debug("unbind function '%s'/%p\n",
938 debug("unbind config '%s'/%p\n", c->label, c);
942 if (composite->unbind)
943 composite->unbind(cdev);
946 kfree(cdev->req->buf);
947 usb_ep_free_request(gadget->ep0, cdev->req);
950 set_gadget_data(gadget, NULL);
955 static int composite_bind(struct usb_gadget *gadget)
957 int status = -ENOMEM;
958 struct usb_composite_dev *cdev;
960 cdev = calloc(sizeof *cdev, 1);
964 cdev->gadget = gadget;
965 set_gadget_data(gadget, cdev);
966 INIT_LIST_HEAD(&cdev->configs);
968 /* preallocate control response and buffer */
969 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
972 cdev->req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, USB_BUFSIZ);
975 cdev->req->complete = composite_setup_complete;
976 gadget->ep0->driver_data = cdev;
978 cdev->bufsiz = USB_BUFSIZ;
979 cdev->driver = composite;
981 usb_gadget_set_selfpowered(gadget);
982 usb_ep_autoconfig_reset(cdev->gadget);
984 status = composite->bind(cdev);
988 memcpy(&cdev->desc, composite->dev,
989 sizeof(struct usb_device_descriptor));
990 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
992 debug("%s: ready\n", composite->name);
996 composite_unbind(gadget);
1001 composite_suspend(struct usb_gadget *gadget)
1003 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1004 struct usb_function *f;
1006 debug("%s: suspend\n", __func__);
1008 list_for_each_entry(f, &cdev->config->functions, list) {
1013 if (composite->suspend)
1014 composite->suspend(cdev);
1016 cdev->suspended = 1;
1020 composite_resume(struct usb_gadget *gadget)
1022 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1023 struct usb_function *f;
1025 debug("%s: resume\n", __func__);
1026 if (composite->resume)
1027 composite->resume(cdev);
1029 list_for_each_entry(f, &cdev->config->functions, list) {
1035 cdev->suspended = 0;
1038 static struct usb_gadget_driver composite_driver = {
1039 .speed = USB_SPEED_HIGH,
1041 .bind = composite_bind,
1042 .unbind = composite_unbind,
1044 .setup = composite_setup,
1045 .disconnect = composite_disconnect,
1047 .suspend = composite_suspend,
1048 .resume = composite_resume,
1052 * usb_composite_register() - register a composite driver
1053 * @driver: the driver to register
1054 * Context: single threaded during gadget setup
1056 * This function is used to register drivers using the composite driver
1057 * framework. The return value is zero, or a negative errno value.
1058 * Those values normally come from the driver's @bind method, which does
1059 * all the work of setting up the driver to match the hardware.
1061 * On successful return, the gadget is ready to respond to requests from
1062 * the host, unless one of its components invokes usb_gadget_disconnect()
1063 * while it was binding. That would usually be done in order to wait for
1064 * some userspace participation.
1066 int usb_composite_register(struct usb_composite_driver *driver)
1068 if (!driver || !driver->dev || !driver->bind || composite)
1072 driver->name = "composite";
1075 return usb_gadget_register_driver(&composite_driver);
1079 * usb_composite_unregister() - unregister a composite driver
1080 * @driver: the driver to unregister
1082 * This function is used to unregister drivers using the composite
1085 void usb_composite_unregister(struct usb_composite_driver *driver)
1087 if (composite != driver)
1089 usb_gadget_unregister_driver(&composite_driver);