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.
12 /* #define VERBOSE_DEBUG */
14 #include <linux/kallsyms.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/module.h>
18 #include <linux/device.h>
19 #include <linux/utsname.h>
21 #include <linux/usb/composite.h>
22 #include <asm/unaligned.h>
25 * The code in this file is utility code, used to build a gadget driver
26 * from one or more "function" drivers, one or more "configuration"
27 * objects, and a "usb_composite_driver" by gluing them together along
28 * with the relevant device-wide data.
31 static char composite_manufacturer
[50];
33 /*-------------------------------------------------------------------------*/
35 * next_ep_desc() - advance to the next EP descriptor
36 * @t: currect pointer within descriptor array
38 * Return: next EP descriptor or NULL
40 * Iterate over @t until either EP descriptor found or
41 * NULL (that indicates end of list) encountered
43 static struct usb_descriptor_header
**
44 next_ep_desc(struct usb_descriptor_header
**t
)
47 if ((*t
)->bDescriptorType
== USB_DT_ENDPOINT
)
54 * for_each_ep_desc()- iterate over endpoint descriptors in the
56 * @start: pointer within descriptor array.
57 * @ep_desc: endpoint descriptor to use as the loop cursor
59 #define for_each_ep_desc(start, ep_desc) \
60 for (ep_desc = next_ep_desc(start); \
61 ep_desc; ep_desc = next_ep_desc(ep_desc+1))
64 * config_ep_by_speed() - configures the given endpoint
65 * according to gadget speed.
66 * @g: pointer to the gadget
68 * @_ep: the endpoint to configure
70 * Return: error code, 0 on success
72 * This function chooses the right descriptors for a given
73 * endpoint according to gadget speed and saves it in the
74 * endpoint desc field. If the endpoint already has a descriptor
75 * assigned to it - overwrites it with currently corresponding
76 * descriptor. The endpoint maxpacket field is updated according
77 * to the chosen descriptor.
78 * Note: the supplied function should hold all the descriptors
79 * for supported speeds
81 int config_ep_by_speed(struct usb_gadget
*g
,
82 struct usb_function
*f
,
85 struct usb_composite_dev
*cdev
= get_gadget_data(g
);
86 struct usb_endpoint_descriptor
*chosen_desc
= NULL
;
87 struct usb_descriptor_header
**speed_desc
= NULL
;
89 struct usb_ss_ep_comp_descriptor
*comp_desc
= NULL
;
90 int want_comp_desc
= 0;
92 struct usb_descriptor_header
**d_spd
; /* cursor for speed desc */
97 /* select desired speed */
100 if (gadget_is_superspeed(g
)) {
101 speed_desc
= f
->ss_descriptors
;
105 /* else: Fall trough */
107 if (gadget_is_dualspeed(g
)) {
108 speed_desc
= f
->hs_descriptors
;
111 /* else: fall through */
113 speed_desc
= f
->descriptors
;
115 /* find descriptors */
116 for_each_ep_desc(speed_desc
, d_spd
) {
117 chosen_desc
= (struct usb_endpoint_descriptor
*)*d_spd
;
118 if (chosen_desc
->bEndpointAddress
== _ep
->address
)
125 _ep
->maxpacket
= usb_endpoint_maxp(chosen_desc
);
126 _ep
->desc
= chosen_desc
;
127 _ep
->comp_desc
= NULL
;
134 * Companion descriptor should follow EP descriptor
135 * USB 3.0 spec, #9.6.7
137 comp_desc
= (struct usb_ss_ep_comp_descriptor
*)*(++d_spd
);
139 (comp_desc
->bDescriptorType
!= USB_DT_SS_ENDPOINT_COMP
))
141 _ep
->comp_desc
= comp_desc
;
142 if (g
->speed
== USB_SPEED_SUPER
) {
143 switch (usb_endpoint_type(_ep
->desc
)) {
144 case USB_ENDPOINT_XFER_ISOC
:
145 /* mult: bits 1:0 of bmAttributes */
146 _ep
->mult
= comp_desc
->bmAttributes
& 0x3;
147 case USB_ENDPOINT_XFER_BULK
:
148 case USB_ENDPOINT_XFER_INT
:
149 _ep
->maxburst
= comp_desc
->bMaxBurst
+ 1;
152 if (comp_desc
->bMaxBurst
!= 0)
153 ERROR(cdev
, "ep0 bMaxBurst must be 0\n");
162 * usb_add_function() - add a function to a configuration
163 * @config: the configuration
164 * @function: the function being added
165 * Context: single threaded during gadget setup
167 * After initialization, each configuration must have one or more
168 * functions added to it. Adding a function involves calling its @bind()
169 * method to allocate resources such as interface and string identifiers
172 * This function returns the value of the function's bind(), which is
173 * zero for success else a negative errno value.
175 int usb_add_function(struct usb_configuration
*config
,
176 struct usb_function
*function
)
180 DBG(config
->cdev
, "adding '%s'/%p to config '%s'/%p\n",
181 function
->name
, function
,
182 config
->label
, config
);
184 if (!function
->set_alt
|| !function
->disable
)
187 function
->config
= config
;
188 list_add_tail(&function
->list
, &config
->functions
);
190 /* REVISIT *require* function->bind? */
191 if (function
->bind
) {
192 value
= function
->bind(config
, function
);
194 list_del(&function
->list
);
195 function
->config
= NULL
;
200 /* We allow configurations that don't work at both speeds.
201 * If we run into a lowspeed Linux system, treat it the same
202 * as full speed ... it's the function drivers that will need
203 * to avoid bulk and ISO transfers.
205 if (!config
->fullspeed
&& function
->descriptors
)
206 config
->fullspeed
= true;
207 if (!config
->highspeed
&& function
->hs_descriptors
)
208 config
->highspeed
= true;
209 if (!config
->superspeed
&& function
->ss_descriptors
)
210 config
->superspeed
= true;
214 DBG(config
->cdev
, "adding '%s'/%p --> %d\n",
215 function
->name
, function
, value
);
220 * usb_function_deactivate - prevent function and gadget enumeration
221 * @function: the function that isn't yet ready to respond
223 * Blocks response of the gadget driver to host enumeration by
224 * preventing the data line pullup from being activated. This is
225 * normally called during @bind() processing to change from the
226 * initial "ready to respond" state, or when a required resource
229 * For example, drivers that serve as a passthrough to a userspace
230 * daemon can block enumeration unless that daemon (such as an OBEX,
231 * MTP, or print server) is ready to handle host requests.
233 * Not all systems support software control of their USB peripheral
236 * Returns zero on success, else negative errno.
238 int usb_function_deactivate(struct usb_function
*function
)
240 struct usb_composite_dev
*cdev
= function
->config
->cdev
;
244 spin_lock_irqsave(&cdev
->lock
, flags
);
246 if (cdev
->deactivations
== 0)
247 status
= usb_gadget_disconnect(cdev
->gadget
);
249 cdev
->deactivations
++;
251 spin_unlock_irqrestore(&cdev
->lock
, flags
);
256 * usb_function_activate - allow function and gadget enumeration
257 * @function: function on which usb_function_activate() was called
259 * Reverses effect of usb_function_deactivate(). If no more functions
260 * are delaying their activation, the gadget driver will respond to
261 * host enumeration procedures.
263 * Returns zero on success, else negative errno.
265 int usb_function_activate(struct usb_function
*function
)
267 struct usb_composite_dev
*cdev
= function
->config
->cdev
;
271 spin_lock_irqsave(&cdev
->lock
, flags
);
273 if (WARN_ON(cdev
->deactivations
== 0))
276 cdev
->deactivations
--;
277 if (cdev
->deactivations
== 0)
278 status
= usb_gadget_connect(cdev
->gadget
);
281 spin_unlock_irqrestore(&cdev
->lock
, flags
);
286 * usb_interface_id() - allocate an unused interface ID
287 * @config: configuration associated with the interface
288 * @function: function handling the interface
289 * Context: single threaded during gadget setup
291 * usb_interface_id() is called from usb_function.bind() callbacks to
292 * allocate new interface IDs. The function driver will then store that
293 * ID in interface, association, CDC union, and other descriptors. It
294 * will also handle any control requests targeted at that interface,
295 * particularly changing its altsetting via set_alt(). There may
296 * also be class-specific or vendor-specific requests to handle.
298 * All interface identifier should be allocated using this routine, to
299 * ensure that for example different functions don't wrongly assign
300 * different meanings to the same identifier. Note that since interface
301 * identifiers are configuration-specific, functions used in more than
302 * one configuration (or more than once in a given configuration) need
303 * multiple versions of the relevant descriptors.
305 * Returns the interface ID which was allocated; or -ENODEV if no
306 * more interface IDs can be allocated.
308 int usb_interface_id(struct usb_configuration
*config
,
309 struct usb_function
*function
)
311 unsigned id
= config
->next_interface_id
;
313 if (id
< MAX_CONFIG_INTERFACES
) {
314 config
->interface
[id
] = function
;
315 config
->next_interface_id
= id
+ 1;
321 static int config_buf(struct usb_configuration
*config
,
322 enum usb_device_speed speed
, void *buf
, u8 type
)
324 struct usb_config_descriptor
*c
= buf
;
325 void *next
= buf
+ USB_DT_CONFIG_SIZE
;
327 struct usb_function
*f
;
330 len
= USB_COMP_EP0_BUFSIZ
- USB_DT_CONFIG_SIZE
;
331 /* write the config descriptor */
333 c
->bLength
= USB_DT_CONFIG_SIZE
;
334 c
->bDescriptorType
= type
;
335 /* wTotalLength is written later */
336 c
->bNumInterfaces
= config
->next_interface_id
;
337 c
->bConfigurationValue
= config
->bConfigurationValue
;
338 c
->iConfiguration
= config
->iConfiguration
;
339 c
->bmAttributes
= USB_CONFIG_ATT_ONE
| config
->bmAttributes
;
340 c
->bMaxPower
= config
->bMaxPower
? : (CONFIG_USB_GADGET_VBUS_DRAW
/ 2);
342 /* There may be e.g. OTG descriptors */
343 if (config
->descriptors
) {
344 status
= usb_descriptor_fillbuf(next
, len
,
345 config
->descriptors
);
352 /* add each function's descriptors */
353 list_for_each_entry(f
, &config
->functions
, list
) {
354 struct usb_descriptor_header
**descriptors
;
357 case USB_SPEED_SUPER
:
358 descriptors
= f
->ss_descriptors
;
361 descriptors
= f
->hs_descriptors
;
364 descriptors
= f
->descriptors
;
369 status
= usb_descriptor_fillbuf(next
, len
,
370 (const struct usb_descriptor_header
**) descriptors
);
378 c
->wTotalLength
= cpu_to_le16(len
);
382 static int config_desc(struct usb_composite_dev
*cdev
, unsigned w_value
)
384 struct usb_gadget
*gadget
= cdev
->gadget
;
385 struct usb_configuration
*c
;
386 u8 type
= w_value
>> 8;
387 enum usb_device_speed speed
= USB_SPEED_UNKNOWN
;
389 if (gadget
->speed
== USB_SPEED_SUPER
)
390 speed
= gadget
->speed
;
391 else if (gadget_is_dualspeed(gadget
)) {
393 if (gadget
->speed
== USB_SPEED_HIGH
)
395 if (type
== USB_DT_OTHER_SPEED_CONFIG
)
398 speed
= USB_SPEED_HIGH
;
402 /* This is a lookup by config *INDEX* */
404 list_for_each_entry(c
, &cdev
->configs
, list
) {
405 /* ignore configs that won't work at this speed */
407 case USB_SPEED_SUPER
:
421 return config_buf(c
, speed
, cdev
->req
->buf
, type
);
427 static int count_configs(struct usb_composite_dev
*cdev
, unsigned type
)
429 struct usb_gadget
*gadget
= cdev
->gadget
;
430 struct usb_configuration
*c
;
435 if (gadget_is_dualspeed(gadget
)) {
436 if (gadget
->speed
== USB_SPEED_HIGH
)
438 if (gadget
->speed
== USB_SPEED_SUPER
)
440 if (type
== USB_DT_DEVICE_QUALIFIER
)
443 list_for_each_entry(c
, &cdev
->configs
, list
) {
444 /* ignore configs that won't work at this speed */
461 * bos_desc() - prepares the BOS descriptor.
462 * @cdev: pointer to usb_composite device to generate the bos
465 * This function generates the BOS (Binary Device Object)
466 * descriptor and its device capabilities descriptors. The BOS
467 * descriptor should be supported by a SuperSpeed device.
469 static int bos_desc(struct usb_composite_dev
*cdev
)
471 struct usb_ext_cap_descriptor
*usb_ext
;
472 struct usb_ss_cap_descriptor
*ss_cap
;
473 struct usb_dcd_config_params dcd_config_params
;
474 struct usb_bos_descriptor
*bos
= cdev
->req
->buf
;
476 bos
->bLength
= USB_DT_BOS_SIZE
;
477 bos
->bDescriptorType
= USB_DT_BOS
;
479 bos
->wTotalLength
= cpu_to_le16(USB_DT_BOS_SIZE
);
480 bos
->bNumDeviceCaps
= 0;
483 * A SuperSpeed device shall include the USB2.0 extension descriptor
484 * and shall support LPM when operating in USB2.0 HS mode.
486 usb_ext
= cdev
->req
->buf
+ le16_to_cpu(bos
->wTotalLength
);
487 bos
->bNumDeviceCaps
++;
488 le16_add_cpu(&bos
->wTotalLength
, USB_DT_USB_EXT_CAP_SIZE
);
489 usb_ext
->bLength
= USB_DT_USB_EXT_CAP_SIZE
;
490 usb_ext
->bDescriptorType
= USB_DT_DEVICE_CAPABILITY
;
491 usb_ext
->bDevCapabilityType
= USB_CAP_TYPE_EXT
;
492 usb_ext
->bmAttributes
= cpu_to_le32(USB_LPM_SUPPORT
);
495 * The Superspeed USB Capability descriptor shall be implemented by all
496 * SuperSpeed devices.
498 ss_cap
= cdev
->req
->buf
+ le16_to_cpu(bos
->wTotalLength
);
499 bos
->bNumDeviceCaps
++;
500 le16_add_cpu(&bos
->wTotalLength
, USB_DT_USB_SS_CAP_SIZE
);
501 ss_cap
->bLength
= USB_DT_USB_SS_CAP_SIZE
;
502 ss_cap
->bDescriptorType
= USB_DT_DEVICE_CAPABILITY
;
503 ss_cap
->bDevCapabilityType
= USB_SS_CAP_TYPE
;
504 ss_cap
->bmAttributes
= 0; /* LTM is not supported yet */
505 ss_cap
->wSpeedSupported
= cpu_to_le16(USB_LOW_SPEED_OPERATION
|
506 USB_FULL_SPEED_OPERATION
|
507 USB_HIGH_SPEED_OPERATION
|
508 USB_5GBPS_OPERATION
);
509 ss_cap
->bFunctionalitySupport
= USB_LOW_SPEED_OPERATION
;
511 /* Get Controller configuration */
512 if (cdev
->gadget
->ops
->get_config_params
)
513 cdev
->gadget
->ops
->get_config_params(&dcd_config_params
);
515 dcd_config_params
.bU1devExitLat
= USB_DEFAULT_U1_DEV_EXIT_LAT
;
516 dcd_config_params
.bU2DevExitLat
=
517 cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT
);
519 ss_cap
->bU1devExitLat
= dcd_config_params
.bU1devExitLat
;
520 ss_cap
->bU2DevExitLat
= dcd_config_params
.bU2DevExitLat
;
522 return le16_to_cpu(bos
->wTotalLength
);
525 static void device_qual(struct usb_composite_dev
*cdev
)
527 struct usb_qualifier_descriptor
*qual
= cdev
->req
->buf
;
529 qual
->bLength
= sizeof(*qual
);
530 qual
->bDescriptorType
= USB_DT_DEVICE_QUALIFIER
;
531 /* POLICY: same bcdUSB and device type info at both speeds */
532 qual
->bcdUSB
= cdev
->desc
.bcdUSB
;
533 qual
->bDeviceClass
= cdev
->desc
.bDeviceClass
;
534 qual
->bDeviceSubClass
= cdev
->desc
.bDeviceSubClass
;
535 qual
->bDeviceProtocol
= cdev
->desc
.bDeviceProtocol
;
536 /* ASSUME same EP0 fifo size at both speeds */
537 qual
->bMaxPacketSize0
= cdev
->gadget
->ep0
->maxpacket
;
538 qual
->bNumConfigurations
= count_configs(cdev
, USB_DT_DEVICE_QUALIFIER
);
542 /*-------------------------------------------------------------------------*/
544 static void reset_config(struct usb_composite_dev
*cdev
)
546 struct usb_function
*f
;
548 DBG(cdev
, "reset config\n");
550 list_for_each_entry(f
, &cdev
->config
->functions
, list
) {
554 bitmap_zero(f
->endpoints
, 32);
559 static int set_config(struct usb_composite_dev
*cdev
,
560 const struct usb_ctrlrequest
*ctrl
, unsigned number
)
562 struct usb_gadget
*gadget
= cdev
->gadget
;
563 struct usb_configuration
*c
= NULL
;
564 int result
= -EINVAL
;
565 unsigned power
= gadget_is_otg(gadget
) ? 8 : 100;
569 list_for_each_entry(c
, &cdev
->configs
, list
) {
570 if (c
->bConfigurationValue
== number
) {
572 * We disable the FDs of the previous
573 * configuration only if the new configuration
584 } else { /* Zero configuration value - need to reset the config */
590 INFO(cdev
, "%s config #%d: %s\n",
591 usb_speed_string(gadget
->speed
),
592 number
, c
? c
->label
: "unconfigured");
599 /* Initialize all interfaces by setting them to altsetting zero. */
600 for (tmp
= 0; tmp
< MAX_CONFIG_INTERFACES
; tmp
++) {
601 struct usb_function
*f
= c
->interface
[tmp
];
602 struct usb_descriptor_header
**descriptors
;
608 * Record which endpoints are used by the function. This is used
609 * to dispatch control requests targeted at that endpoint to the
610 * function's setup callback instead of the current
611 * configuration's setup callback.
613 switch (gadget
->speed
) {
614 case USB_SPEED_SUPER
:
615 descriptors
= f
->ss_descriptors
;
618 descriptors
= f
->hs_descriptors
;
621 descriptors
= f
->descriptors
;
624 for (; *descriptors
; ++descriptors
) {
625 struct usb_endpoint_descriptor
*ep
;
628 if ((*descriptors
)->bDescriptorType
!= USB_DT_ENDPOINT
)
631 ep
= (struct usb_endpoint_descriptor
*)*descriptors
;
632 addr
= ((ep
->bEndpointAddress
& 0x80) >> 3)
633 | (ep
->bEndpointAddress
& 0x0f);
634 set_bit(addr
, f
->endpoints
);
637 result
= f
->set_alt(f
, tmp
, 0);
639 DBG(cdev
, "interface %d (%s/%p) alt 0 --> %d\n",
640 tmp
, f
->name
, f
, result
);
646 if (result
== USB_GADGET_DELAYED_STATUS
) {
648 "%s: interface %d (%s) requested delayed status\n",
649 __func__
, tmp
, f
->name
);
650 cdev
->delayed_status
++;
651 DBG(cdev
, "delayed_status count %d\n",
652 cdev
->delayed_status
);
656 /* when we return, be sure our power usage is valid */
657 power
= c
->bMaxPower
? (2 * c
->bMaxPower
) : CONFIG_USB_GADGET_VBUS_DRAW
;
659 usb_gadget_vbus_draw(gadget
, power
);
660 if (result
>= 0 && cdev
->delayed_status
)
661 result
= USB_GADGET_DELAYED_STATUS
;
666 * usb_add_config() - add a configuration to a device.
667 * @cdev: wraps the USB gadget
668 * @config: the configuration, with bConfigurationValue assigned
669 * @bind: the configuration's bind function
670 * Context: single threaded during gadget setup
672 * One of the main tasks of a composite @bind() routine is to
673 * add each of the configurations it supports, using this routine.
675 * This function returns the value of the configuration's @bind(), which
676 * is zero for success else a negative errno value. Binding configurations
677 * assigns global resources including string IDs, and per-configuration
678 * resources such as interface IDs and endpoints.
680 int usb_add_config(struct usb_composite_dev
*cdev
,
681 struct usb_configuration
*config
,
682 int (*bind
)(struct usb_configuration
*))
684 int status
= -EINVAL
;
685 struct usb_configuration
*c
;
687 DBG(cdev
, "adding config #%u '%s'/%p\n",
688 config
->bConfigurationValue
,
689 config
->label
, config
);
691 if (!config
->bConfigurationValue
|| !bind
)
694 /* Prevent duplicate configuration identifiers */
695 list_for_each_entry(c
, &cdev
->configs
, list
) {
696 if (c
->bConfigurationValue
== config
->bConfigurationValue
) {
703 list_add_tail(&config
->list
, &cdev
->configs
);
705 INIT_LIST_HEAD(&config
->functions
);
706 config
->next_interface_id
= 0;
707 memset(config
->interface
, 0, sizeof(config
->interface
));
709 status
= bind(config
);
711 while (!list_empty(&config
->functions
)) {
712 struct usb_function
*f
;
714 f
= list_first_entry(&config
->functions
,
715 struct usb_function
, list
);
718 DBG(cdev
, "unbind function '%s'/%p\n",
720 f
->unbind(config
, f
);
721 /* may free memory for "f" */
724 list_del(&config
->list
);
729 DBG(cdev
, "cfg %d/%p speeds:%s%s%s\n",
730 config
->bConfigurationValue
, config
,
731 config
->superspeed
? " super" : "",
732 config
->highspeed
? " high" : "",
734 ? (gadget_is_dualspeed(cdev
->gadget
)
739 for (i
= 0; i
< MAX_CONFIG_INTERFACES
; i
++) {
740 struct usb_function
*f
= config
->interface
[i
];
744 DBG(cdev
, " interface %d = %s/%p\n",
749 /* set_alt(), or next bind(), sets up
750 * ep->driver_data as needed.
752 usb_ep_autoconfig_reset(cdev
->gadget
);
756 DBG(cdev
, "added config '%s'/%u --> %d\n", config
->label
,
757 config
->bConfigurationValue
, status
);
761 static void remove_config(struct usb_composite_dev
*cdev
,
762 struct usb_configuration
*config
)
764 while (!list_empty(&config
->functions
)) {
765 struct usb_function
*f
;
767 f
= list_first_entry(&config
->functions
,
768 struct usb_function
, list
);
771 DBG(cdev
, "unbind function '%s'/%p\n", f
->name
, f
);
772 f
->unbind(config
, f
);
773 /* may free memory for "f" */
776 list_del(&config
->list
);
777 if (config
->unbind
) {
778 DBG(cdev
, "unbind config '%s'/%p\n", config
->label
, config
);
779 config
->unbind(config
);
780 /* may free memory for "c" */
785 * usb_remove_config() - remove a configuration from a device.
786 * @cdev: wraps the USB gadget
787 * @config: the configuration
789 * Drivers must call usb_gadget_disconnect before calling this function
790 * to disconnect the device from the host and make sure the host will not
791 * try to enumerate the device while we are changing the config list.
793 void usb_remove_config(struct usb_composite_dev
*cdev
,
794 struct usb_configuration
*config
)
798 spin_lock_irqsave(&cdev
->lock
, flags
);
800 if (cdev
->config
== config
)
803 spin_unlock_irqrestore(&cdev
->lock
, flags
);
805 remove_config(cdev
, config
);
808 /*-------------------------------------------------------------------------*/
810 /* We support strings in multiple languages ... string descriptor zero
811 * says which languages are supported. The typical case will be that
812 * only one language (probably English) is used, with I18N handled on
816 static void collect_langs(struct usb_gadget_strings
**sp
, __le16
*buf
)
818 const struct usb_gadget_strings
*s
;
824 language
= cpu_to_le16(s
->language
);
825 for (tmp
= buf
; *tmp
&& tmp
< &buf
[126]; tmp
++) {
826 if (*tmp
== language
)
835 static int lookup_string(
836 struct usb_gadget_strings
**sp
,
842 struct usb_gadget_strings
*s
;
847 if (s
->language
!= language
)
849 value
= usb_gadget_get_string(s
, id
, buf
);
856 static int get_string(struct usb_composite_dev
*cdev
,
857 void *buf
, u16 language
, int id
)
859 struct usb_composite_driver
*composite
= cdev
->driver
;
860 struct usb_configuration
*c
;
861 struct usb_function
*f
;
865 /* Yes, not only is USB's I18N support probably more than most
866 * folk will ever care about ... also, it's all supported here.
867 * (Except for UTF8 support for Unicode's "Astral Planes".)
870 /* 0 == report all available language codes */
872 struct usb_string_descriptor
*s
= buf
;
873 struct usb_gadget_strings
**sp
;
876 s
->bDescriptorType
= USB_DT_STRING
;
878 sp
= composite
->strings
;
880 collect_langs(sp
, s
->wData
);
882 list_for_each_entry(c
, &cdev
->configs
, list
) {
885 collect_langs(sp
, s
->wData
);
887 list_for_each_entry(f
, &c
->functions
, list
) {
890 collect_langs(sp
, s
->wData
);
894 for (len
= 0; len
<= 126 && s
->wData
[len
]; len
++)
899 s
->bLength
= 2 * (len
+ 1);
903 /* Otherwise, look up and return a specified string. First
904 * check if the string has not been overridden.
906 if (cdev
->manufacturer_override
== id
)
907 str
= composite_manufacturer
;
911 struct usb_gadget_strings strings
= {
912 .language
= language
,
913 .strings
= &(struct usb_string
) { 0xff, str
}
915 return usb_gadget_get_string(&strings
, 0xff, buf
);
918 /* String IDs are device-scoped, so we look up each string
919 * table we're told about. These lookups are infrequent;
920 * simpler-is-better here.
922 if (composite
->strings
) {
923 len
= lookup_string(composite
->strings
, buf
, language
, id
);
927 list_for_each_entry(c
, &cdev
->configs
, list
) {
929 len
= lookup_string(c
->strings
, buf
, language
, id
);
933 list_for_each_entry(f
, &c
->functions
, list
) {
936 len
= lookup_string(f
->strings
, buf
, language
, id
);
945 * usb_string_id() - allocate an unused string ID
946 * @cdev: the device whose string descriptor IDs are being allocated
947 * Context: single threaded during gadget setup
949 * @usb_string_id() is called from bind() callbacks to allocate
950 * string IDs. Drivers for functions, configurations, or gadgets will
951 * then store that ID in the appropriate descriptors and string table.
953 * All string identifier should be allocated using this,
954 * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure
955 * that for example different functions don't wrongly assign different
956 * meanings to the same identifier.
958 int usb_string_id(struct usb_composite_dev
*cdev
)
960 if (cdev
->next_string_id
< 254) {
961 /* string id 0 is reserved by USB spec for list of
962 * supported languages */
963 /* 255 reserved as well? -- mina86 */
964 cdev
->next_string_id
++;
965 return cdev
->next_string_id
;
971 * usb_string_ids() - allocate unused string IDs in batch
972 * @cdev: the device whose string descriptor IDs are being allocated
973 * @str: an array of usb_string objects to assign numbers to
974 * Context: single threaded during gadget setup
976 * @usb_string_ids() is called from bind() callbacks to allocate
977 * string IDs. Drivers for functions, configurations, or gadgets will
978 * then copy IDs from the string table to the appropriate descriptors
979 * and string table for other languages.
981 * All string identifier should be allocated using this,
982 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
983 * example different functions don't wrongly assign different meanings
984 * to the same identifier.
986 int usb_string_ids_tab(struct usb_composite_dev
*cdev
, struct usb_string
*str
)
988 int next
= cdev
->next_string_id
;
990 for (; str
->s
; ++str
) {
991 if (unlikely(next
>= 254))
996 cdev
->next_string_id
= next
;
1002 * usb_string_ids_n() - allocate unused string IDs in batch
1003 * @c: the device whose string descriptor IDs are being allocated
1004 * @n: number of string IDs to allocate
1005 * Context: single threaded during gadget setup
1007 * Returns the first requested ID. This ID and next @n-1 IDs are now
1008 * valid IDs. At least provided that @n is non-zero because if it
1009 * is, returns last requested ID which is now very useful information.
1011 * @usb_string_ids_n() is called from bind() callbacks to allocate
1012 * string IDs. Drivers for functions, configurations, or gadgets will
1013 * then store that ID in the appropriate descriptors and string table.
1015 * All string identifier should be allocated using this,
1016 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
1017 * example different functions don't wrongly assign different meanings
1018 * to the same identifier.
1020 int usb_string_ids_n(struct usb_composite_dev
*c
, unsigned n
)
1022 unsigned next
= c
->next_string_id
;
1023 if (unlikely(n
> 254 || (unsigned)next
+ n
> 254))
1025 c
->next_string_id
+= n
;
1030 /*-------------------------------------------------------------------------*/
1032 static void composite_setup_complete(struct usb_ep
*ep
, struct usb_request
*req
)
1034 if (req
->status
|| req
->actual
!= req
->length
)
1035 DBG((struct usb_composite_dev
*) ep
->driver_data
,
1036 "setup complete --> %d, %d/%d\n",
1037 req
->status
, req
->actual
, req
->length
);
1041 * The setup() callback implements all the ep0 functionality that's
1042 * not handled lower down, in hardware or the hardware driver(like
1043 * device and endpoint feature flags, and their status). It's all
1044 * housekeeping for the gadget function we're implementing. Most of
1045 * the work is in config and function specific setup.
1048 composite_setup(struct usb_gadget
*gadget
, const struct usb_ctrlrequest
*ctrl
)
1050 struct usb_composite_dev
*cdev
= get_gadget_data(gadget
);
1051 struct usb_request
*req
= cdev
->req
;
1052 int value
= -EOPNOTSUPP
;
1054 u16 w_index
= le16_to_cpu(ctrl
->wIndex
);
1055 u8 intf
= w_index
& 0xFF;
1056 u16 w_value
= le16_to_cpu(ctrl
->wValue
);
1057 u16 w_length
= le16_to_cpu(ctrl
->wLength
);
1058 struct usb_function
*f
= NULL
;
1061 /* partial re-init of the response message; the function or the
1062 * gadget might need to intercept e.g. a control-OUT completion
1063 * when we delegate to it.
1066 req
->complete
= composite_setup_complete
;
1068 gadget
->ep0
->driver_data
= cdev
;
1070 switch (ctrl
->bRequest
) {
1072 /* we handle all standard USB descriptors */
1073 case USB_REQ_GET_DESCRIPTOR
:
1074 if (ctrl
->bRequestType
!= USB_DIR_IN
)
1076 switch (w_value
>> 8) {
1079 cdev
->desc
.bNumConfigurations
=
1080 count_configs(cdev
, USB_DT_DEVICE
);
1081 cdev
->desc
.bMaxPacketSize0
=
1082 cdev
->gadget
->ep0
->maxpacket
;
1083 if (gadget_is_superspeed(gadget
)) {
1084 if (gadget
->speed
>= USB_SPEED_SUPER
) {
1085 cdev
->desc
.bcdUSB
= cpu_to_le16(0x0300);
1086 cdev
->desc
.bMaxPacketSize0
= 9;
1088 cdev
->desc
.bcdUSB
= cpu_to_le16(0x0210);
1092 value
= min(w_length
, (u16
) sizeof cdev
->desc
);
1093 memcpy(req
->buf
, &cdev
->desc
, value
);
1095 case USB_DT_DEVICE_QUALIFIER
:
1096 if (!gadget_is_dualspeed(gadget
) ||
1097 gadget
->speed
>= USB_SPEED_SUPER
)
1100 value
= min_t(int, w_length
,
1101 sizeof(struct usb_qualifier_descriptor
));
1103 case USB_DT_OTHER_SPEED_CONFIG
:
1104 if (!gadget_is_dualspeed(gadget
) ||
1105 gadget
->speed
>= USB_SPEED_SUPER
)
1109 value
= config_desc(cdev
, w_value
);
1111 value
= min(w_length
, (u16
) value
);
1114 value
= get_string(cdev
, req
->buf
,
1115 w_index
, w_value
& 0xff);
1117 value
= min(w_length
, (u16
) value
);
1120 if (gadget_is_superspeed(gadget
)) {
1121 value
= bos_desc(cdev
);
1122 value
= min(w_length
, (u16
) value
);
1128 /* any number of configs can work */
1129 case USB_REQ_SET_CONFIGURATION
:
1130 if (ctrl
->bRequestType
!= 0)
1132 if (gadget_is_otg(gadget
)) {
1133 if (gadget
->a_hnp_support
)
1134 DBG(cdev
, "HNP available\n");
1135 else if (gadget
->a_alt_hnp_support
)
1136 DBG(cdev
, "HNP on another port\n");
1138 VDBG(cdev
, "HNP inactive\n");
1140 spin_lock(&cdev
->lock
);
1141 value
= set_config(cdev
, ctrl
, w_value
);
1142 spin_unlock(&cdev
->lock
);
1144 case USB_REQ_GET_CONFIGURATION
:
1145 if (ctrl
->bRequestType
!= USB_DIR_IN
)
1148 *(u8
*)req
->buf
= cdev
->config
->bConfigurationValue
;
1150 *(u8
*)req
->buf
= 0;
1151 value
= min(w_length
, (u16
) 1);
1154 /* function drivers must handle get/set altsetting; if there's
1155 * no get() method, we know only altsetting zero works.
1157 case USB_REQ_SET_INTERFACE
:
1158 if (ctrl
->bRequestType
!= USB_RECIP_INTERFACE
)
1160 if (!cdev
->config
|| intf
>= MAX_CONFIG_INTERFACES
)
1162 f
= cdev
->config
->interface
[intf
];
1165 if (w_value
&& !f
->set_alt
)
1167 value
= f
->set_alt(f
, w_index
, w_value
);
1168 if (value
== USB_GADGET_DELAYED_STATUS
) {
1170 "%s: interface %d (%s) requested delayed status\n",
1171 __func__
, intf
, f
->name
);
1172 cdev
->delayed_status
++;
1173 DBG(cdev
, "delayed_status count %d\n",
1174 cdev
->delayed_status
);
1177 case USB_REQ_GET_INTERFACE
:
1178 if (ctrl
->bRequestType
!= (USB_DIR_IN
|USB_RECIP_INTERFACE
))
1180 if (!cdev
->config
|| intf
>= MAX_CONFIG_INTERFACES
)
1182 f
= cdev
->config
->interface
[intf
];
1185 /* lots of interfaces only need altsetting zero... */
1186 value
= f
->get_alt
? f
->get_alt(f
, w_index
) : 0;
1189 *((u8
*)req
->buf
) = value
;
1190 value
= min(w_length
, (u16
) 1);
1194 * USB 3.0 additions:
1195 * Function driver should handle get_status request. If such cb
1196 * wasn't supplied we respond with default value = 0
1197 * Note: function driver should supply such cb only for the first
1198 * interface of the function
1200 case USB_REQ_GET_STATUS
:
1201 if (!gadget_is_superspeed(gadget
))
1203 if (ctrl
->bRequestType
!= (USB_DIR_IN
| USB_RECIP_INTERFACE
))
1205 value
= 2; /* This is the length of the get_status reply */
1206 put_unaligned_le16(0, req
->buf
);
1207 if (!cdev
->config
|| intf
>= MAX_CONFIG_INTERFACES
)
1209 f
= cdev
->config
->interface
[intf
];
1212 status
= f
->get_status
? f
->get_status(f
) : 0;
1215 put_unaligned_le16(status
& 0x0000ffff, req
->buf
);
1218 * Function drivers should handle SetFeature/ClearFeature
1219 * (FUNCTION_SUSPEND) request. function_suspend cb should be supplied
1220 * only for the first interface of the function
1222 case USB_REQ_CLEAR_FEATURE
:
1223 case USB_REQ_SET_FEATURE
:
1224 if (!gadget_is_superspeed(gadget
))
1226 if (ctrl
->bRequestType
!= (USB_DIR_OUT
| USB_RECIP_INTERFACE
))
1229 case USB_INTRF_FUNC_SUSPEND
:
1230 if (!cdev
->config
|| intf
>= MAX_CONFIG_INTERFACES
)
1232 f
= cdev
->config
->interface
[intf
];
1236 if (f
->func_suspend
)
1237 value
= f
->func_suspend(f
, w_index
>> 8);
1240 "func_suspend() returned error %d\n",
1250 "non-core control req%02x.%02x v%04x i%04x l%d\n",
1251 ctrl
->bRequestType
, ctrl
->bRequest
,
1252 w_value
, w_index
, w_length
);
1254 /* functions always handle their interfaces and endpoints...
1255 * punt other recipients (other, WUSB, ...) to the current
1256 * configuration code.
1258 * REVISIT it could make sense to let the composite device
1259 * take such requests too, if that's ever needed: to work
1262 switch (ctrl
->bRequestType
& USB_RECIP_MASK
) {
1263 case USB_RECIP_INTERFACE
:
1264 if (!cdev
->config
|| intf
>= MAX_CONFIG_INTERFACES
)
1266 f
= cdev
->config
->interface
[intf
];
1269 case USB_RECIP_ENDPOINT
:
1270 endp
= ((w_index
& 0x80) >> 3) | (w_index
& 0x0f);
1271 list_for_each_entry(f
, &cdev
->config
->functions
, list
) {
1272 if (test_bit(endp
, f
->endpoints
))
1275 if (&f
->list
== &cdev
->config
->functions
)
1281 value
= f
->setup(f
, ctrl
);
1283 struct usb_configuration
*c
;
1287 value
= c
->setup(c
, ctrl
);
1293 /* respond with data transfer before status phase? */
1294 if (value
>= 0 && value
!= USB_GADGET_DELAYED_STATUS
) {
1295 req
->length
= value
;
1296 req
->zero
= value
< w_length
;
1297 value
= usb_ep_queue(gadget
->ep0
, req
, GFP_ATOMIC
);
1299 DBG(cdev
, "ep_queue --> %d\n", value
);
1301 composite_setup_complete(gadget
->ep0
, req
);
1303 } else if (value
== USB_GADGET_DELAYED_STATUS
&& w_length
!= 0) {
1305 "%s: Delayed status not supported for w_length != 0",
1310 /* device either stalls (value < 0) or reports success */
1314 static void composite_disconnect(struct usb_gadget
*gadget
)
1316 struct usb_composite_dev
*cdev
= get_gadget_data(gadget
);
1317 unsigned long flags
;
1319 /* REVISIT: should we have config and device level
1320 * disconnect callbacks?
1322 spin_lock_irqsave(&cdev
->lock
, flags
);
1325 if (cdev
->driver
->disconnect
)
1326 cdev
->driver
->disconnect(cdev
);
1327 spin_unlock_irqrestore(&cdev
->lock
, flags
);
1330 /*-------------------------------------------------------------------------*/
1332 static ssize_t
composite_show_suspended(struct device
*dev
,
1333 struct device_attribute
*attr
,
1336 struct usb_gadget
*gadget
= dev_to_usb_gadget(dev
);
1337 struct usb_composite_dev
*cdev
= get_gadget_data(gadget
);
1339 return sprintf(buf
, "%d\n", cdev
->suspended
);
1342 static DEVICE_ATTR(suspended
, 0444, composite_show_suspended
, NULL
);
1345 composite_unbind(struct usb_gadget
*gadget
)
1347 struct usb_composite_dev
*cdev
= get_gadget_data(gadget
);
1349 /* composite_disconnect() must already have been called
1350 * by the underlying peripheral controller driver!
1351 * so there's no i/o concurrency that could affect the
1352 * state protected by cdev->lock.
1354 WARN_ON(cdev
->config
);
1356 while (!list_empty(&cdev
->configs
)) {
1357 struct usb_configuration
*c
;
1358 c
= list_first_entry(&cdev
->configs
,
1359 struct usb_configuration
, list
);
1360 remove_config(cdev
, c
);
1362 if (cdev
->driver
->unbind
)
1363 cdev
->driver
->unbind(cdev
);
1366 kfree(cdev
->req
->buf
);
1367 usb_ep_free_request(gadget
->ep0
, cdev
->req
);
1369 device_remove_file(&gadget
->dev
, &dev_attr_suspended
);
1371 set_gadget_data(gadget
, NULL
);
1374 static u8
override_id(struct usb_composite_dev
*cdev
, u8
*desc
)
1377 int ret
= usb_string_id(cdev
);
1378 if (unlikely(ret
< 0))
1379 WARNING(cdev
, "failed to override string ID\n");
1387 static void update_unchanged_dev_desc(struct usb_device_descriptor
*new,
1388 const struct usb_device_descriptor
*old
)
1398 * these variables may have been set in
1399 * usb_composite_overwrite_options()
1401 idVendor
= new->idVendor
;
1402 idProduct
= new->idProduct
;
1403 bcdDevice
= new->bcdDevice
;
1404 iSerialNumber
= new->iSerialNumber
;
1405 iManufacturer
= new->iManufacturer
;
1406 iProduct
= new->iProduct
;
1410 new->idVendor
= idVendor
;
1412 new->idProduct
= idProduct
;
1414 new->bcdDevice
= bcdDevice
;
1416 new->iSerialNumber
= iSerialNumber
;
1418 new->iManufacturer
= iManufacturer
;
1420 new->iProduct
= iProduct
;
1423 static struct usb_composite_driver
*to_cdriver(struct usb_gadget_driver
*gdrv
)
1425 return container_of(gdrv
, struct usb_composite_driver
, gadget_driver
);
1428 static int composite_bind(struct usb_gadget
*gadget
,
1429 struct usb_gadget_driver
*gdriver
)
1431 struct usb_composite_dev
*cdev
;
1432 struct usb_composite_driver
*composite
= to_cdriver(gdriver
);
1433 int status
= -ENOMEM
;
1435 cdev
= kzalloc(sizeof *cdev
, GFP_KERNEL
);
1439 spin_lock_init(&cdev
->lock
);
1440 cdev
->gadget
= gadget
;
1441 set_gadget_data(gadget
, cdev
);
1442 INIT_LIST_HEAD(&cdev
->configs
);
1444 /* preallocate control response and buffer */
1445 cdev
->req
= usb_ep_alloc_request(gadget
->ep0
, GFP_KERNEL
);
1448 cdev
->req
->buf
= kmalloc(USB_COMP_EP0_BUFSIZ
, GFP_KERNEL
);
1449 if (!cdev
->req
->buf
)
1451 cdev
->req
->complete
= composite_setup_complete
;
1452 gadget
->ep0
->driver_data
= cdev
;
1454 cdev
->driver
= composite
;
1457 * As per USB compliance update, a device that is actively drawing
1458 * more than 100mA from USB must report itself as bus-powered in
1459 * the GetStatus(DEVICE) call.
1461 if (CONFIG_USB_GADGET_VBUS_DRAW
<= USB_SELF_POWER_VBUS_MAX_DRAW
)
1462 usb_gadget_set_selfpowered(gadget
);
1464 /* interface and string IDs start at zero via kzalloc.
1465 * we force endpoints to start unassigned; few controller
1466 * drivers will zero ep->driver_data.
1468 usb_ep_autoconfig_reset(cdev
->gadget
);
1470 /* composite gadget needs to assign strings for whole device (like
1471 * serial number), register function drivers, potentially update
1472 * power state and consumption, etc
1474 status
= composite
->bind(cdev
);
1478 update_unchanged_dev_desc(&cdev
->desc
, composite
->dev
);
1480 /* string overrides */
1481 if (!cdev
->desc
.iManufacturer
) {
1482 snprintf(composite_manufacturer
,
1483 sizeof composite_manufacturer
,
1485 init_utsname()->sysname
,
1486 init_utsname()->release
,
1489 cdev
->manufacturer_override
=
1490 override_id(cdev
, &cdev
->desc
.iManufacturer
);
1493 /* has userspace failed to provide a serial number? */
1494 if (composite
->needs_serial
&& !cdev
->desc
.iSerialNumber
)
1495 WARNING(cdev
, "userspace failed to provide iSerialNumber\n");
1498 status
= device_create_file(&gadget
->dev
, &dev_attr_suspended
);
1502 INFO(cdev
, "%s ready\n", composite
->name
);
1506 composite_unbind(gadget
);
1510 /*-------------------------------------------------------------------------*/
1513 composite_suspend(struct usb_gadget
*gadget
)
1515 struct usb_composite_dev
*cdev
= get_gadget_data(gadget
);
1516 struct usb_function
*f
;
1518 /* REVISIT: should we have config level
1519 * suspend/resume callbacks?
1521 DBG(cdev
, "suspend\n");
1523 list_for_each_entry(f
, &cdev
->config
->functions
, list
) {
1528 if (cdev
->driver
->suspend
)
1529 cdev
->driver
->suspend(cdev
);
1531 cdev
->suspended
= 1;
1533 usb_gadget_vbus_draw(gadget
, 2);
1537 composite_resume(struct usb_gadget
*gadget
)
1539 struct usb_composite_dev
*cdev
= get_gadget_data(gadget
);
1540 struct usb_function
*f
;
1543 /* REVISIT: should we have config level
1544 * suspend/resume callbacks?
1546 DBG(cdev
, "resume\n");
1547 if (cdev
->driver
->resume
)
1548 cdev
->driver
->resume(cdev
);
1550 list_for_each_entry(f
, &cdev
->config
->functions
, list
) {
1555 maxpower
= cdev
->config
->bMaxPower
;
1557 usb_gadget_vbus_draw(gadget
, maxpower
?
1558 (2 * maxpower
) : CONFIG_USB_GADGET_VBUS_DRAW
);
1561 cdev
->suspended
= 0;
1564 /*-------------------------------------------------------------------------*/
1566 static const struct usb_gadget_driver composite_driver_template
= {
1567 .bind
= composite_bind
,
1568 .unbind
= composite_unbind
,
1570 .setup
= composite_setup
,
1571 .disconnect
= composite_disconnect
,
1573 .suspend
= composite_suspend
,
1574 .resume
= composite_resume
,
1577 .owner
= THIS_MODULE
,
1582 * usb_composite_probe() - register a composite driver
1583 * @driver: the driver to register
1584 * @bind: the callback used to allocate resources that are shared across the
1585 * whole device, such as string IDs, and add its configurations using
1586 * @usb_add_config(). This may fail by returning a negative errno
1587 * value; it should return zero on successful initialization.
1588 * Context: single threaded during gadget setup
1590 * This function is used to register drivers using the composite driver
1591 * framework. The return value is zero, or a negative errno value.
1592 * Those values normally come from the driver's @bind method, which does
1593 * all the work of setting up the driver to match the hardware.
1595 * On successful return, the gadget is ready to respond to requests from
1596 * the host, unless one of its components invokes usb_gadget_disconnect()
1597 * while it was binding. That would usually be done in order to wait for
1598 * some userspace participation.
1600 int usb_composite_probe(struct usb_composite_driver
*driver
)
1602 struct usb_gadget_driver
*gadget_driver
;
1604 if (!driver
|| !driver
->dev
|| !driver
->bind
)
1608 driver
->name
= "composite";
1610 driver
->gadget_driver
= composite_driver_template
;
1611 gadget_driver
= &driver
->gadget_driver
;
1613 gadget_driver
->function
= (char *) driver
->name
;
1614 gadget_driver
->driver
.name
= driver
->name
;
1615 gadget_driver
->max_speed
= driver
->max_speed
;
1617 return usb_gadget_probe_driver(gadget_driver
);
1621 * usb_composite_unregister() - unregister a composite driver
1622 * @driver: the driver to unregister
1624 * This function is used to unregister drivers using the composite
1627 void usb_composite_unregister(struct usb_composite_driver
*driver
)
1629 usb_gadget_unregister_driver(&driver
->gadget_driver
);
1633 * usb_composite_setup_continue() - Continue with the control transfer
1634 * @cdev: the composite device who's control transfer was kept waiting
1636 * This function must be called by the USB function driver to continue
1637 * with the control transfer's data/status stage in case it had requested to
1638 * delay the data/status stages. A USB function's setup handler (e.g. set_alt())
1639 * can request the composite framework to delay the setup request's data/status
1640 * stages by returning USB_GADGET_DELAYED_STATUS.
1642 void usb_composite_setup_continue(struct usb_composite_dev
*cdev
)
1645 struct usb_request
*req
= cdev
->req
;
1646 unsigned long flags
;
1648 DBG(cdev
, "%s\n", __func__
);
1649 spin_lock_irqsave(&cdev
->lock
, flags
);
1651 if (cdev
->delayed_status
== 0) {
1652 WARN(cdev
, "%s: Unexpected call\n", __func__
);
1654 } else if (--cdev
->delayed_status
== 0) {
1655 DBG(cdev
, "%s: Completing delayed status\n", __func__
);
1657 value
= usb_ep_queue(cdev
->gadget
->ep0
, req
, GFP_ATOMIC
);
1659 DBG(cdev
, "ep_queue --> %d\n", value
);
1661 composite_setup_complete(cdev
->gadget
->ep0
, req
);
1665 spin_unlock_irqrestore(&cdev
->lock
, flags
);
1668 void usb_composite_overwrite_options(struct usb_composite_dev
*cdev
,
1669 struct usb_composite_overwrite
*covr
)
1671 struct usb_device_descriptor
*desc
= &cdev
->desc
;
1672 struct usb_gadget_strings
*gstr
= cdev
->driver
->strings
[0];
1673 struct usb_string
*dev_str
= gstr
->strings
;
1676 desc
->idVendor
= cpu_to_le16(covr
->idVendor
);
1678 if (covr
->idProduct
)
1679 desc
->idProduct
= cpu_to_le16(covr
->idProduct
);
1681 if (covr
->bcdDevice
)
1682 desc
->bcdDevice
= cpu_to_le16(covr
->bcdDevice
);
1684 if (covr
->serial_number
) {
1685 desc
->iSerialNumber
= dev_str
[USB_GADGET_SERIAL_IDX
].id
;
1686 dev_str
[USB_GADGET_SERIAL_IDX
].s
= covr
->serial_number
;
1688 if (covr
->manufacturer
) {
1689 desc
->iManufacturer
= dev_str
[USB_GADGET_MANUFACTURER_IDX
].id
;
1690 dev_str
[USB_GADGET_MANUFACTURER_IDX
].s
= covr
->manufacturer
;
1693 if (covr
->product
) {
1694 desc
->iProduct
= dev_str
[USB_GADGET_PRODUCT_IDX
].id
;
1695 dev_str
[USB_GADGET_PRODUCT_IDX
].s
= covr
->product
;