Lines Matching +full:ctrl +full:- +full:ids
1 // SPDX-License-Identifier: GPL-2.0+
3 * composite.c - infrastructure for Composite USB Gadgets
5 * Copyright (C) 2006-2008 David Brownell
27 * struct usb_os_string - represents OS String to be reported by a gadget
46 * with the relevant device-wide data.
52 return (struct usb_gadget_strings **)uc->stash; in get_containers_gs()
56 * function_descriptors() - get function descriptors for speed
75 descriptors = f->ssp_descriptors; in function_descriptors()
80 descriptors = f->ss_descriptors; in function_descriptors()
85 descriptors = f->hs_descriptors; in function_descriptors()
90 descriptors = f->fs_descriptors; in function_descriptors()
102 * next_desc() - advance to the next desc_type descriptor
115 if ((*t)->bDescriptorType == desc_type) in next_desc()
122 * for_each_desc() - iterate over desc_type descriptors in the
133 * config_ep_by_speed_and_alt() - configures the given endpoint
145 * assigned to it - overwrites it with currently corresponding
168 return -EIO; in config_ep_by_speed_and_alt()
171 switch (g->speed) { in config_ep_by_speed_and_alt()
173 if (f->ssp_descriptors) { in config_ep_by_speed_and_alt()
174 speed_desc = f->ssp_descriptors; in config_ep_by_speed_and_alt()
181 if (f->ss_descriptors) { in config_ep_by_speed_and_alt()
182 speed_desc = f->ss_descriptors; in config_ep_by_speed_and_alt()
189 if (f->hs_descriptors) { in config_ep_by_speed_and_alt()
190 speed_desc = f->hs_descriptors; in config_ep_by_speed_and_alt()
196 speed_desc = f->fs_descriptors; in config_ep_by_speed_and_alt()
203 f->name); in config_ep_by_speed_and_alt()
209 if (int_desc->bAlternateSetting == alt) { in config_ep_by_speed_and_alt()
214 return -EIO; in config_ep_by_speed_and_alt()
220 if (chosen_desc->bEndpointAddress == _ep->address) in config_ep_by_speed_and_alt()
223 return -EIO; in config_ep_by_speed_and_alt()
227 _ep->maxpacket = usb_endpoint_maxp(chosen_desc); in config_ep_by_speed_and_alt()
228 _ep->desc = chosen_desc; in config_ep_by_speed_and_alt()
229 _ep->comp_desc = NULL; in config_ep_by_speed_and_alt()
230 _ep->maxburst = 0; in config_ep_by_speed_and_alt()
231 _ep->mult = 1; in config_ep_by_speed_and_alt()
233 if (g->speed == USB_SPEED_HIGH && (usb_endpoint_xfer_isoc(_ep->desc) || in config_ep_by_speed_and_alt()
234 usb_endpoint_xfer_int(_ep->desc))) in config_ep_by_speed_and_alt()
235 _ep->mult = usb_endpoint_maxp_mult(_ep->desc); in config_ep_by_speed_and_alt()
246 (comp_desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP)) in config_ep_by_speed_and_alt()
247 return -EIO; in config_ep_by_speed_and_alt()
248 _ep->comp_desc = comp_desc; in config_ep_by_speed_and_alt()
249 if (g->speed >= USB_SPEED_SUPER) { in config_ep_by_speed_and_alt()
250 switch (usb_endpoint_type(_ep->desc)) { in config_ep_by_speed_and_alt()
253 _ep->mult = (comp_desc->bmAttributes & 0x3) + 1; in config_ep_by_speed_and_alt()
257 _ep->maxburst = comp_desc->bMaxBurst + 1; in config_ep_by_speed_and_alt()
260 if (comp_desc->bMaxBurst != 0) in config_ep_by_speed_and_alt()
262 _ep->maxburst = 1; in config_ep_by_speed_and_alt()
271 * config_ep_by_speed() - configures the given endpoint
282 * assigned to it - overwrites it with currently corresponding
297 * usb_add_function() - add a function to a configuration
313 int value = -EINVAL; in usb_add_function()
315 DBG(config->cdev, "adding '%s'/%p to config '%s'/%p\n", in usb_add_function()
316 function->name, function, in usb_add_function()
317 config->label, config); in usb_add_function()
319 if (!function->set_alt || !function->disable) in usb_add_function()
322 function->config = config; in usb_add_function()
323 list_add_tail(&function->list, &config->functions); in usb_add_function()
325 if (function->bind_deactivated) { in usb_add_function()
331 /* REVISIT *require* function->bind? */ in usb_add_function()
332 if (function->bind) { in usb_add_function()
333 value = function->bind(config, function); in usb_add_function()
335 list_del(&function->list); in usb_add_function()
336 function->config = NULL; in usb_add_function()
346 if (!config->fullspeed && function->fs_descriptors) in usb_add_function()
347 config->fullspeed = true; in usb_add_function()
348 if (!config->highspeed && function->hs_descriptors) in usb_add_function()
349 config->highspeed = true; in usb_add_function()
350 if (!config->superspeed && function->ss_descriptors) in usb_add_function()
351 config->superspeed = true; in usb_add_function()
352 if (!config->superspeed_plus && function->ssp_descriptors) in usb_add_function()
353 config->superspeed_plus = true; in usb_add_function()
357 DBG(config->cdev, "adding '%s'/%p --> %d\n", in usb_add_function()
358 function->name, function, value); in usb_add_function()
365 if (f->disable) in usb_remove_function()
366 f->disable(f); in usb_remove_function()
368 bitmap_zero(f->endpoints, 32); in usb_remove_function()
369 list_del(&f->list); in usb_remove_function()
370 if (f->unbind) in usb_remove_function()
371 f->unbind(c, f); in usb_remove_function()
373 if (f->bind_deactivated) in usb_remove_function()
379 * usb_function_deactivate - prevent function and gadget enumeration
399 struct usb_composite_dev *cdev = function->config->cdev; in usb_function_deactivate()
403 spin_lock_irqsave(&cdev->lock, flags); in usb_function_deactivate()
405 if (cdev->deactivations == 0) { in usb_function_deactivate()
406 spin_unlock_irqrestore(&cdev->lock, flags); in usb_function_deactivate()
407 status = usb_gadget_deactivate(cdev->gadget); in usb_function_deactivate()
408 spin_lock_irqsave(&cdev->lock, flags); in usb_function_deactivate()
411 cdev->deactivations++; in usb_function_deactivate()
413 spin_unlock_irqrestore(&cdev->lock, flags); in usb_function_deactivate()
419 * usb_function_activate - allow function and gadget enumeration
430 struct usb_composite_dev *cdev = function->config->cdev; in usb_function_activate()
434 spin_lock_irqsave(&cdev->lock, flags); in usb_function_activate()
436 if (WARN_ON(cdev->deactivations == 0)) in usb_function_activate()
437 status = -EINVAL; in usb_function_activate()
439 cdev->deactivations--; in usb_function_activate()
440 if (cdev->deactivations == 0) { in usb_function_activate()
441 spin_unlock_irqrestore(&cdev->lock, flags); in usb_function_activate()
442 status = usb_gadget_activate(cdev->gadget); in usb_function_activate()
443 spin_lock_irqsave(&cdev->lock, flags); in usb_function_activate()
447 spin_unlock_irqrestore(&cdev->lock, flags); in usb_function_activate()
453 * usb_interface_id() - allocate an unused interface ID
459 * allocate new interface IDs. The function driver will then store that
463 * also be class-specific or vendor-specific requests to handle.
468 * identifiers are configuration-specific, functions used in more than
472 * Returns the interface ID which was allocated; or -ENODEV if no
473 * more interface IDs can be allocated.
478 unsigned id = config->next_interface_id; in usb_interface_id()
481 config->interface[id] = function; in usb_interface_id()
482 config->next_interface_id = id + 1; in usb_interface_id()
485 return -ENODEV; in usb_interface_id()
490 * usb_func_wakeup - sends function wake notification to the host.
505 struct usb_gadget *gadget = func->config->cdev->gadget; in usb_func_wakeup()
508 if (!gadget->ops->func_wakeup) in usb_func_wakeup()
509 return -EOPNOTSUPP; in usb_func_wakeup()
511 if (!func->func_wakeup_armed) { in usb_func_wakeup()
512 ERROR(func->config->cdev, "not armed for func remote wakeup\n"); in usb_func_wakeup()
513 return -EINVAL; in usb_func_wakeup()
517 if (func->config->interface[id] == func) in usb_func_wakeup()
521 ERROR(func->config->cdev, "Invalid function\n"); in usb_func_wakeup()
522 return -EINVAL; in usb_func_wakeup()
525 return gadget->ops->func_wakeup(gadget, id); in usb_func_wakeup()
534 if (c->MaxPower || (c->bmAttributes & USB_CONFIG_ATT_SELFPOWER)) in encode_bMaxPower()
535 val = c->MaxPower; in encode_bMaxPower()
553 if (USB_CONFIG_ATT_WAKEUP & c->bmAttributes) { in check_remote_wakeup_config()
555 if (!g->wakeup_capable && g->ops->set_remote_wakeup) { in check_remote_wakeup_config()
556 WARN(c->cdev, "Clearing wakeup bit for config c.%d\n", in check_remote_wakeup_config()
557 c->bConfigurationValue); in check_remote_wakeup_config()
558 c->bmAttributes &= ~USB_CONFIG_ATT_WAKEUP; in check_remote_wakeup_config()
572 len = USB_COMP_EP0_BUFSIZ - USB_DT_CONFIG_SIZE; in config_buf()
575 c->bLength = USB_DT_CONFIG_SIZE; in config_buf()
576 c->bDescriptorType = type; in config_buf()
578 c->bNumInterfaces = config->next_interface_id; in config_buf()
579 c->bConfigurationValue = config->bConfigurationValue; in config_buf()
580 c->iConfiguration = config->iConfiguration; in config_buf()
581 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; in config_buf()
582 c->bMaxPower = encode_bMaxPower(speed, config); in config_buf()
585 if (config->descriptors) { in config_buf()
587 config->descriptors); in config_buf()
590 len -= status; in config_buf()
595 list_for_each_entry(f, &config->functions, list) { in config_buf()
605 len -= status; in config_buf()
609 len = next - buf; in config_buf()
610 c->wTotalLength = cpu_to_le16(len); in config_buf()
616 struct usb_gadget *gadget = cdev->gadget; in config_desc()
622 if (gadget->speed >= USB_SPEED_SUPER) in config_desc()
623 speed = gadget->speed; in config_desc()
626 if (gadget->speed == USB_SPEED_HIGH) in config_desc()
638 pos = &cdev->configs; in config_desc()
639 c = cdev->os_desc_config; in config_desc()
643 while ((pos = pos->next) != &cdev->configs) { in config_desc()
647 if (c == cdev->os_desc_config) in config_desc()
654 if (!c->superspeed_plus) in config_desc()
658 if (!c->superspeed) in config_desc()
662 if (!c->highspeed) in config_desc()
666 if (!c->fullspeed) in config_desc()
671 return config_buf(c, speed, cdev->req->buf, type); in config_desc()
672 w_value--; in config_desc()
674 return -EINVAL; in config_desc()
679 struct usb_gadget *gadget = cdev->gadget; in count_configs()
687 if (gadget->speed == USB_SPEED_HIGH) in count_configs()
689 if (gadget->speed == USB_SPEED_SUPER) in count_configs()
691 if (gadget->speed == USB_SPEED_SUPER_PLUS) in count_configs()
696 list_for_each_entry(c, &cdev->configs, list) { in count_configs()
699 if (!c->superspeed_plus) in count_configs()
702 if (!c->superspeed) in count_configs()
705 if (!c->highspeed) in count_configs()
708 if (!c->fullspeed) in count_configs()
717 * bos_desc() - prepares the BOS descriptor.
729 struct usb_bos_descriptor *bos = cdev->req->buf; in bos_desc()
732 bos->bLength = USB_DT_BOS_SIZE; in bos_desc()
733 bos->bDescriptorType = USB_DT_BOS; in bos_desc()
735 bos->wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE); in bos_desc()
736 bos->bNumDeviceCaps = 0; in bos_desc()
739 if (cdev->gadget->ops->get_config_params) { in bos_desc()
740 cdev->gadget->ops->get_config_params(cdev->gadget, in bos_desc()
765 if (cdev->gadget->lpm_capable) { in bos_desc()
766 usb_ext = cdev->req->buf + le16_to_cpu(bos->wTotalLength); in bos_desc()
767 bos->bNumDeviceCaps++; in bos_desc()
768 le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE); in bos_desc()
769 usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE; in bos_desc()
770 usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY; in bos_desc()
771 usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT; in bos_desc()
772 usb_ext->bmAttributes = cpu_to_le32(USB_LPM_SUPPORT | in bos_desc()
780 if (gadget_is_superspeed(cdev->gadget)) { in bos_desc()
783 ss_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); in bos_desc()
784 bos->bNumDeviceCaps++; in bos_desc()
785 le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE); in bos_desc()
786 ss_cap->bLength = USB_DT_USB_SS_CAP_SIZE; in bos_desc()
787 ss_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY; in bos_desc()
788 ss_cap->bDevCapabilityType = USB_SS_CAP_TYPE; in bos_desc()
789 ss_cap->bmAttributes = 0; /* LTM is not supported yet */ in bos_desc()
790 ss_cap->wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION | in bos_desc()
794 ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION; in bos_desc()
795 ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat; in bos_desc()
796 ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat; in bos_desc()
800 if (gadget_is_superspeed_plus(cdev->gadget)) { in bos_desc()
806 if (cdev->gadget->max_ssp_rate == USB_SSP_GEN_2x2) in bos_desc()
813 ssic = (ssac + 1) / 2 - 1; in bos_desc()
815 ssp_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); in bos_desc()
816 bos->bNumDeviceCaps++; in bos_desc()
818 le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SSP_CAP_SIZE(ssac)); in bos_desc()
819 ssp_cap->bLength = USB_DT_USB_SSP_CAP_SIZE(ssac); in bos_desc()
820 ssp_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY; in bos_desc()
821 ssp_cap->bDevCapabilityType = USB_SSP_CAP_TYPE; in bos_desc()
822 ssp_cap->bReserved = 0; in bos_desc()
823 ssp_cap->wReserved = 0; in bos_desc()
825 ssp_cap->bmAttributes = in bos_desc()
829 ssp_cap->wFunctionalitySupport = in bos_desc()
837 * - SSID 0 for symmetric RX/TX sublink speed of 10 Gbps. in bos_desc()
840 * - SSID 0 for symmetric RX/TX sublink speed of 5 Gbps. in bos_desc()
843 * - SSID 0 for symmetric RX/TX sublink speed of 5 Gbps. in bos_desc()
844 * - SSID 1 for symmetric RX/TX sublink speed of 10 Gbps. in bos_desc()
853 if (cdev->gadget->max_ssp_rate == USB_SSP_GEN_2x1 || in bos_desc()
854 cdev->gadget->max_ssp_rate == USB_SSP_GEN_UNKNOWN) in bos_desc()
864 ssp_cap->bmSublinkSpeedAttr[i] = in bos_desc()
876 if (cdev->use_webusb) { in bos_desc()
881 webusb_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); in bos_desc()
882 webusb_cap_data = (struct usb_webusb_cap_data *) webusb_cap->CapabilityData; in bos_desc()
883 bos->bNumDeviceCaps++; in bos_desc()
884 le16_add_cpu(&bos->wTotalLength, in bos_desc()
887 webusb_cap->bLength = USB_DT_USB_PLAT_DEV_CAP_SIZE(USB_WEBUSB_CAP_DATA_SIZE); in bos_desc()
888 webusb_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY; in bos_desc()
889 webusb_cap->bDevCapabilityType = USB_PLAT_DEV_CAP_TYPE; in bos_desc()
890 webusb_cap->bReserved = 0; in bos_desc()
891 export_guid(webusb_cap->UUID, &webusb_uuid); in bos_desc()
893 if (cdev->bcd_webusb_version != 0) in bos_desc()
894 webusb_cap_data->bcdVersion = cpu_to_le16(cdev->bcd_webusb_version); in bos_desc()
896 webusb_cap_data->bcdVersion = WEBUSB_VERSION_1_00; in bos_desc()
898 webusb_cap_data->bVendorCode = cdev->b_webusb_vendor_code; in bos_desc()
900 if (strnlen(cdev->landing_page, sizeof(cdev->landing_page)) > 0) in bos_desc()
901 webusb_cap_data->iLandingPage = WEBUSB_LANDING_PAGE_PRESENT; in bos_desc()
903 webusb_cap_data->iLandingPage = WEBUSB_LANDING_PAGE_NOT_PRESENT; in bos_desc()
906 return le16_to_cpu(bos->wTotalLength); in bos_desc()
911 struct usb_qualifier_descriptor *qual = cdev->req->buf; in device_qual()
913 qual->bLength = sizeof(*qual); in device_qual()
914 qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER; in device_qual()
916 qual->bcdUSB = cdev->desc.bcdUSB; in device_qual()
917 qual->bDeviceClass = cdev->desc.bDeviceClass; in device_qual()
918 qual->bDeviceSubClass = cdev->desc.bDeviceSubClass; in device_qual()
919 qual->bDeviceProtocol = cdev->desc.bDeviceProtocol; in device_qual()
921 qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket; in device_qual()
922 qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER); in device_qual()
923 qual->bRESERVED = 0; in device_qual()
926 /*-------------------------------------------------------------------------*/
934 list_for_each_entry(f, &cdev->config->functions, list) { in reset_config()
935 if (f->disable) in reset_config()
936 f->disable(f); in reset_config()
939 f->func_wakeup_armed = false; in reset_config()
941 bitmap_zero(f->endpoints, 32); in reset_config()
943 cdev->config = NULL; in reset_config()
944 cdev->delayed_status = 0; in reset_config()
948 const struct usb_ctrlrequest *ctrl, unsigned number) in set_config() argument
950 struct usb_gadget *gadget = cdev->gadget; in set_config()
952 int result = -EINVAL; in set_config()
957 list_for_each_entry(iter, &cdev->configs, list) { in set_config()
958 if (iter->bConfigurationValue != number) in set_config()
965 if (cdev->config) in set_config()
973 } else { /* Zero configuration value - need to reset the config */ in set_config()
974 if (cdev->config) in set_config()
980 usb_speed_string(gadget->speed), in set_config()
981 number, c ? c->label : "unconfigured"); in set_config()
987 cdev->config = c; in set_config()
991 struct usb_function *f = c->interface[tmp]; in set_config()
1003 descriptors = function_descriptors(f, gadget->speed); in set_config()
1009 if ((*descriptors)->bDescriptorType != USB_DT_ENDPOINT) in set_config()
1013 addr = ((ep->bEndpointAddress & 0x80) >> 3) in set_config()
1014 | (ep->bEndpointAddress & 0x0f); in set_config()
1015 set_bit(addr, f->endpoints); in set_config()
1018 result = f->set_alt(f, tmp, 0); in set_config()
1020 DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n", in set_config()
1021 tmp, f->name, f, result); in set_config()
1030 __func__, tmp, f->name); in set_config()
1031 cdev->delayed_status++; in set_config()
1033 cdev->delayed_status); in set_config()
1038 if (c->MaxPower || (c->bmAttributes & USB_CONFIG_ATT_SELFPOWER)) in set_config()
1039 power = c->MaxPower; in set_config()
1043 if (gadget->speed < USB_SPEED_SUPER) in set_config()
1048 if (USB_CONFIG_ATT_WAKEUP & c->bmAttributes) in set_config()
1059 if (result >= 0 && cdev->delayed_status) in set_config()
1069 if (!config->bConfigurationValue) in usb_add_config_only()
1070 return -EINVAL; in usb_add_config_only()
1073 list_for_each_entry(c, &cdev->configs, list) { in usb_add_config_only()
1074 if (c->bConfigurationValue == config->bConfigurationValue) in usb_add_config_only()
1075 return -EBUSY; in usb_add_config_only()
1078 config->cdev = cdev; in usb_add_config_only()
1079 list_add_tail(&config->list, &cdev->configs); in usb_add_config_only()
1081 INIT_LIST_HEAD(&config->functions); in usb_add_config_only()
1082 config->next_interface_id = 0; in usb_add_config_only()
1083 memset(config->interface, 0, sizeof(config->interface)); in usb_add_config_only()
1090 * usb_add_config() - add a configuration to a device.
1101 * assigns global resources including string IDs, and per-configuration
1102 * resources such as interface IDs and endpoints.
1108 int status = -EINVAL; in usb_add_config()
1114 config->bConfigurationValue, in usb_add_config()
1115 config->label, config); in usb_add_config()
1124 status = usb_gadget_check_config(cdev->gadget); in usb_add_config()
1127 while (!list_empty(&config->functions)) { in usb_add_config()
1130 f = list_first_entry(&config->functions, in usb_add_config()
1132 list_del(&f->list); in usb_add_config()
1133 if (f->unbind) { in usb_add_config()
1135 f->name, f); in usb_add_config()
1136 f->unbind(config, f); in usb_add_config()
1140 list_del(&config->list); in usb_add_config()
1141 config->cdev = NULL; in usb_add_config()
1146 config->bConfigurationValue, config, in usb_add_config()
1147 config->superspeed_plus ? " superplus" : "", in usb_add_config()
1148 config->superspeed ? " super" : "", in usb_add_config()
1149 config->highspeed ? " high" : "", in usb_add_config()
1150 config->fullspeed in usb_add_config()
1151 ? (gadget_is_dualspeed(cdev->gadget) in usb_add_config()
1157 struct usb_function *f = config->interface[i]; in usb_add_config()
1162 i, f->name, f); in usb_add_config()
1166 /* set_alt(), or next bind(), sets up ep->claimed as needed */ in usb_add_config()
1167 usb_ep_autoconfig_reset(cdev->gadget); in usb_add_config()
1171 DBG(cdev, "added config '%s'/%u --> %d\n", config->label, in usb_add_config()
1172 config->bConfigurationValue, status); in usb_add_config()
1180 while (!list_empty(&config->functions)) { in remove_config()
1183 f = list_first_entry(&config->functions, in remove_config()
1188 list_del(&config->list); in remove_config()
1189 if (config->unbind) { in remove_config()
1190 DBG(cdev, "unbind config '%s'/%p\n", config->label, config); in remove_config()
1191 config->unbind(config); in remove_config()
1197 * usb_remove_config() - remove a configuration from a device.
1210 spin_lock_irqsave(&cdev->lock, flags); in usb_remove_config()
1212 if (cdev->config == config) in usb_remove_config()
1215 spin_unlock_irqrestore(&cdev->lock, flags); in usb_remove_config()
1220 /*-------------------------------------------------------------------------*/
1236 language = cpu_to_le16(s->language); in collect_langs()
1259 if (s->language != language) in lookup_string()
1265 return -EINVAL; in lookup_string()
1271 struct usb_composite_driver *composite = cdev->driver; in get_string()
1288 s->bDescriptorType = USB_DT_STRING; in get_string()
1290 sp = composite->strings; in get_string()
1292 collect_langs(sp, s->wData); in get_string()
1294 list_for_each_entry(c, &cdev->configs, list) { in get_string()
1295 sp = c->strings; in get_string()
1297 collect_langs(sp, s->wData); in get_string()
1299 list_for_each_entry(f, &c->functions, list) { in get_string()
1300 sp = f->strings; in get_string()
1302 collect_langs(sp, s->wData); in get_string()
1305 list_for_each_entry(uc, &cdev->gstrings, list) { in get_string()
1309 collect_langs(sp, s->wData); in get_string()
1312 for (len = 0; len <= USB_MAX_STRING_LEN && s->wData[len]; len++) in get_string()
1315 return -EINVAL; in get_string()
1317 s->bLength = 2 * (len + 1); in get_string()
1318 return s->bLength; in get_string()
1321 if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) { in get_string()
1323 b->bLength = sizeof(*b); in get_string()
1324 b->bDescriptorType = USB_DT_STRING; in get_string()
1326 sizeof(b->qwSignature) == sizeof(cdev->qw_sign), in get_string()
1328 memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature)); in get_string()
1329 b->bMS_VendorCode = cdev->b_vendor_code; in get_string()
1330 b->bPad = 0; in get_string()
1334 list_for_each_entry(uc, &cdev->gstrings, list) { in get_string()
1343 /* String IDs are device-scoped, so we look up each string in get_string()
1345 * simpler-is-better here. in get_string()
1347 if (composite->strings) { in get_string()
1348 len = lookup_string(composite->strings, buf, language, id); in get_string()
1352 list_for_each_entry(c, &cdev->configs, list) { in get_string()
1353 if (c->strings) { in get_string()
1354 len = lookup_string(c->strings, buf, language, id); in get_string()
1358 list_for_each_entry(f, &c->functions, list) { in get_string()
1359 if (!f->strings) in get_string()
1361 len = lookup_string(f->strings, buf, language, id); in get_string()
1366 return -EINVAL; in get_string()
1370 * usb_string_id() - allocate an unused string ID
1371 * @cdev: the device whose string descriptor IDs are being allocated
1375 * string IDs. Drivers for functions, configurations, or gadgets will
1385 if (cdev->next_string_id < 254) { in usb_string_id()
1388 /* 255 reserved as well? -- mina86 */ in usb_string_id()
1389 cdev->next_string_id++; in usb_string_id()
1390 return cdev->next_string_id; in usb_string_id()
1392 return -ENODEV; in usb_string_id()
1397 * usb_string_ids_tab() - allocate unused string IDs in batch
1398 * @cdev: the device whose string descriptor IDs are being allocated
1403 * string IDs. Drivers for functions, configurations, or gadgets will
1404 * then copy IDs from the string table to the appropriate descriptors
1414 int next = cdev->next_string_id; in usb_string_ids_tab()
1416 for (; str->s; ++str) { in usb_string_ids_tab()
1418 return -ENODEV; in usb_string_ids_tab()
1419 str->id = ++next; in usb_string_ids_tab()
1422 cdev->next_string_id = next; in usb_string_ids_tab()
1447 return ERR_PTR(-ENOMEM); in copy_gadget_strings()
1449 stash = uc->stash; in copy_gadget_strings()
1457 gs->language = sp[n_gs]->language; in copy_gadget_strings()
1458 gs->strings = stash; in copy_gadget_strings()
1459 org_s = sp[n_gs]->strings; in copy_gadget_strings()
1464 if (org_s->s) in copy_gadget_strings()
1465 s->s = org_s->s; in copy_gadget_strings()
1467 s->s = ""; in copy_gadget_strings()
1471 s->s = NULL; in copy_gadget_strings()
1480 * usb_gstrings_attach() - attach gadget strings to a cdev and assign ids
1481 * @cdev: the device whose string descriptor IDs are being allocated
1484 * @n_strings: number of entries in each usb_strings array (sp[]->strings)
1490 * The ->language pointer of each struct usb_gadget_strings has to contain the
1492 * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first
1493 * usb_string entry of es-ES contains the translation of the first usb_string
1494 * entry of en-US. Therefore both entries become the same id assign.
1509 return ERR_PTR(-EINVAL); in usb_gstrings_attach()
1516 ret = usb_string_ids_tab(cdev, n_gs[0]->strings); in usb_gstrings_attach()
1525 m_s = n_gs[0]->strings; in usb_gstrings_attach()
1526 s = n_gs[i]->strings; in usb_gstrings_attach()
1528 s->id = m_s->id; in usb_gstrings_attach()
1533 list_add_tail(&uc->list, &cdev->gstrings); in usb_gstrings_attach()
1534 return n_gs[0]->strings; in usb_gstrings_attach()
1542 * usb_string_ids_n() - allocate unused string IDs in batch
1543 * @c: the device whose string descriptor IDs are being allocated
1544 * @n: number of string IDs to allocate
1547 * Returns the first requested ID. This ID and next @n-1 IDs are now
1548 * valid IDs. At least provided that @n is non-zero because if it
1552 * string IDs. Drivers for functions, configurations, or gadgets will
1562 unsigned next = c->next_string_id; in usb_string_ids_n()
1564 return -ENODEV; in usb_string_ids_n()
1565 c->next_string_id += n; in usb_string_ids_n()
1570 /*-------------------------------------------------------------------------*/
1576 if (req->status || req->actual != req->length) in composite_setup_complete()
1577 DBG((struct usb_composite_dev *) ep->driver_data, in composite_setup_complete()
1578 "setup complete --> %d, %d/%d\n", in composite_setup_complete()
1579 req->status, req->actual, req->length); in composite_setup_complete()
1583 * so they don't have to maintain the same ->complete() stubs. in composite_setup_complete()
1585 * Because of that, we need to check for the validity of ->context in composite_setup_complete()
1588 if (!req->context) in composite_setup_complete()
1591 cdev = req->context; in composite_setup_complete()
1593 if (cdev->req == req) in composite_setup_complete()
1594 cdev->setup_pending = false; in composite_setup_complete()
1595 else if (cdev->os_desc_req == req) in composite_setup_complete()
1596 cdev->os_desc_pending = false; in composite_setup_complete()
1606 ret = usb_ep_queue(cdev->gadget->ep0, req, gfp_flags); in composite_ep0_queue()
1608 if (cdev->req == req) in composite_ep0_queue()
1609 cdev->setup_pending = true; in composite_ep0_queue()
1610 else if (cdev->os_desc_req == req) in composite_ep0_queue()
1611 cdev->os_desc_pending = true; in composite_ep0_queue()
1624 for (i = 0; i < c->next_interface_id; ++i) { in count_ext_compat()
1628 f = c->interface[i]; in count_ext_compat()
1629 for (j = 0; j < f->os_desc_n; ++j) { in count_ext_compat()
1632 if (i != f->os_desc_table[j].if_id) in count_ext_compat()
1634 d = f->os_desc_table[j].os_desc; in count_ext_compat()
1635 if (d && d->ext_compat_id) in count_ext_compat()
1649 for (i = 0; i < c->next_interface_id; ++i) { in fill_ext_compat()
1653 f = c->interface[i]; in fill_ext_compat()
1654 for (j = 0; j < f->os_desc_n; ++j) { in fill_ext_compat()
1657 if (i != f->os_desc_table[j].if_id) in fill_ext_compat()
1659 d = f->os_desc_table[j].os_desc; in fill_ext_compat()
1660 if (d && d->ext_compat_id) { in fill_ext_compat()
1663 memcpy(buf, d->ext_compat_id, 16); in fill_ext_compat()
1684 f = c->interface[interface]; in count_ext_prop()
1685 for (j = 0; j < f->os_desc_n; ++j) { in count_ext_prop()
1688 if (interface != f->os_desc_table[j].if_id) in count_ext_prop()
1690 d = f->os_desc_table[j].os_desc; in count_ext_prop()
1691 if (d && d->ext_compat_id) in count_ext_prop()
1692 return d->ext_prop_count; in count_ext_prop()
1704 f = c->interface[interface]; in len_ext_prop()
1705 for (j = 0; j < f->os_desc_n; ++j) { in len_ext_prop()
1706 if (interface != f->os_desc_table[j].if_id) in len_ext_prop()
1708 d = f->os_desc_table[j].os_desc; in len_ext_prop()
1710 return min(res + d->ext_prop_len, 4096); in len_ext_prop()
1722 f = c->interface[interface]; in fill_ext_prop()
1725 for (j = 0; j < f->os_desc_n; ++j) { in fill_ext_prop()
1726 if (interface != f->os_desc_table[j].if_id) in fill_ext_prop()
1728 d = f->os_desc_table[j].os_desc; in fill_ext_prop()
1730 list_for_each_entry(ext_prop, &d->ext_prop, entry) { in fill_ext_prop()
1731 n = ext_prop->data_len + in fill_ext_prop()
1732 ext_prop->name_len + 14; in fill_ext_prop()
1736 usb_ext_prop_put_type(buf, ext_prop->type); in fill_ext_prop()
1737 ret = usb_ext_prop_put_name(buf, ext_prop->name, in fill_ext_prop()
1738 ext_prop->name_len); in fill_ext_prop()
1741 switch (ext_prop->type) { in fill_ext_prop()
1746 ext_prop->data, in fill_ext_prop()
1747 ext_prop->data_len); in fill_ext_prop()
1751 ext_prop->data, in fill_ext_prop()
1752 ext_prop->data_len); in fill_ext_prop()
1759 return -EINVAL; in fill_ext_prop()
1777 composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) in composite_setup() argument
1780 struct usb_request *req = cdev->req; in composite_setup()
1781 int value = -EOPNOTSUPP; in composite_setup()
1783 u16 w_index = le16_to_cpu(ctrl->wIndex); in composite_setup()
1785 u16 w_value = le16_to_cpu(ctrl->wValue); in composite_setup()
1786 u16 w_length = le16_to_cpu(ctrl->wLength); in composite_setup()
1792 if (ctrl->bRequestType & USB_DIR_IN) { in composite_setup()
1794 __le16 *temp = (__le16 *)&ctrl->wLength; in composite_setup()
1803 /* partial re-init of the response message; the function or the in composite_setup()
1804 * gadget might need to intercept e.g. a control-OUT completion in composite_setup()
1807 req->zero = 0; in composite_setup()
1808 req->context = cdev; in composite_setup()
1809 req->complete = composite_setup_complete; in composite_setup()
1810 req->length = 0; in composite_setup()
1811 gadget->ep0->driver_data = cdev; in composite_setup()
1814 * Don't let non-standard requests match any of the cases below in composite_setup()
1817 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) in composite_setup()
1820 switch (ctrl->bRequest) { in composite_setup()
1824 if (ctrl->bRequestType != USB_DIR_IN) in composite_setup()
1829 cdev->desc.bNumConfigurations = in composite_setup()
1831 cdev->desc.bMaxPacketSize0 = in composite_setup()
1832 cdev->gadget->ep0->maxpacket; in composite_setup()
1834 if (gadget->speed >= USB_SPEED_SUPER) { in composite_setup()
1835 cdev->desc.bcdUSB = cpu_to_le16(0x0320); in composite_setup()
1836 cdev->desc.bMaxPacketSize0 = 9; in composite_setup()
1838 cdev->desc.bcdUSB = cpu_to_le16(0x0210); in composite_setup()
1841 if (gadget->lpm_capable || cdev->use_webusb) in composite_setup()
1842 cdev->desc.bcdUSB = cpu_to_le16(0x0201); in composite_setup()
1844 cdev->desc.bcdUSB = cpu_to_le16(0x0200); in composite_setup()
1847 value = min(w_length, (u16) sizeof cdev->desc); in composite_setup()
1848 memcpy(req->buf, &cdev->desc, value); in composite_setup()
1852 gadget->speed >= USB_SPEED_SUPER) in composite_setup()
1860 gadget->speed >= USB_SPEED_SUPER) in composite_setup()
1869 value = get_string(cdev, req->buf, in composite_setup()
1876 gadget->lpm_capable || cdev->use_webusb) { in composite_setup()
1886 if (cdev->config) in composite_setup()
1887 config = cdev->config; in composite_setup()
1890 &cdev->configs, in composite_setup()
1895 if (gadget->otg_caps && in composite_setup()
1896 (gadget->otg_caps->otg_rev >= 0x0200)) in composite_setup()
1904 memcpy(req->buf, config->descriptors[0], value); in composite_setup()
1912 if (ctrl->bRequestType != 0) in composite_setup()
1915 if (gadget->a_hnp_support) in composite_setup()
1917 else if (gadget->a_alt_hnp_support) in composite_setup()
1922 spin_lock(&cdev->lock); in composite_setup()
1923 value = set_config(cdev, ctrl, w_value); in composite_setup()
1924 spin_unlock(&cdev->lock); in composite_setup()
1927 if (ctrl->bRequestType != USB_DIR_IN) in composite_setup()
1929 if (cdev->config) in composite_setup()
1930 *(u8 *)req->buf = cdev->config->bConfigurationValue; in composite_setup()
1932 *(u8 *)req->buf = 0; in composite_setup()
1938 if (ctrl->bRequestType != USB_RECIP_INTERFACE) in composite_setup()
1940 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
1942 f = cdev->config->interface[intf]; in composite_setup()
1951 if (w_value && !f->get_alt) in composite_setup()
1954 spin_lock(&cdev->lock); in composite_setup()
1955 value = f->set_alt(f, w_index, w_value); in composite_setup()
1959 __func__, intf, f->name); in composite_setup()
1960 cdev->delayed_status++; in composite_setup()
1962 cdev->delayed_status); in composite_setup()
1964 spin_unlock(&cdev->lock); in composite_setup()
1967 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) in composite_setup()
1969 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
1971 f = cdev->config->interface[intf]; in composite_setup()
1975 value = f->get_alt ? f->get_alt(f, w_index) : 0; in composite_setup()
1978 *((u8 *)req->buf) = value; in composite_setup()
1982 if (gadget_is_otg(gadget) && gadget->hnp_polling_support && in composite_setup()
1984 if (ctrl->bRequestType != (USB_DIR_IN | in composite_setup()
1987 *((u8 *)req->buf) = gadget->host_request_flag; in composite_setup()
2001 if (ctrl->bRequestType != (USB_DIR_IN | USB_RECIP_INTERFACE)) in composite_setup()
2004 put_unaligned_le16(0, req->buf); in composite_setup()
2005 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
2007 f = cdev->config->interface[intf]; in composite_setup()
2011 if (f->get_status) { in composite_setup()
2012 status = f->get_status(f); in composite_setup()
2017 if (f->config->bmAttributes & USB_CONFIG_ATT_WAKEUP) { in composite_setup()
2019 if (f->func_wakeup_armed) in composite_setup()
2024 put_unaligned_le16(status & 0x0000ffff, req->buf); in composite_setup()
2035 if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_INTERFACE)) in composite_setup()
2039 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
2041 f = cdev->config->interface[intf]; in composite_setup()
2045 if (f->func_suspend) { in composite_setup()
2046 value = f->func_suspend(f, w_index >> 8); in composite_setup()
2048 } else if (ctrl->bRequest == USB_REQ_SET_FEATURE) { in composite_setup()
2049 if (!(f->config->bmAttributes & in composite_setup()
2054 f->func_wakeup_armed = !!(w_index & in composite_setup()
2058 if (f->suspend && !f->func_suspended) { in composite_setup()
2059 f->suspend(f); in composite_setup()
2060 f->func_suspended = true; in composite_setup()
2068 if (f->resume && f->func_suspended) { in composite_setup()
2069 f->resume(f); in composite_setup()
2070 f->func_suspended = false; in composite_setup()
2074 } else if (ctrl->bRequest == USB_REQ_CLEAR_FEATURE) { in composite_setup()
2075 f->func_wakeup_armed = false; in composite_setup()
2077 if (f->resume && f->func_suspended) { in composite_setup()
2078 f->resume(f); in composite_setup()
2079 f->func_suspended = false; in composite_setup()
2097 if (cdev->use_os_string && cdev->os_desc_config && in composite_setup()
2098 (ctrl->bRequestType & USB_TYPE_VENDOR) && in composite_setup()
2099 ctrl->bRequest == cdev->b_vendor_code) { in composite_setup()
2105 req = cdev->os_desc_req; in composite_setup()
2106 req->context = cdev; in composite_setup()
2107 req->complete = composite_setup_complete; in composite_setup()
2108 buf = req->buf; in composite_setup()
2109 os_desc_cfg = cdev->os_desc_config; in composite_setup()
2113 switch (ctrl->bRequestType & USB_RECIP_MASK) { in composite_setup()
2135 !os_desc_cfg->interface[interface]) in composite_setup()
2159 * https://wicg.github.io/webusb/#device-requests in composite_setup()
2161 if (cdev->use_webusb && in composite_setup()
2162 ctrl->bRequestType == (USB_DIR_IN | USB_TYPE_VENDOR) && in composite_setup()
2165 ctrl->bRequest == cdev->b_webusb_vendor_code) { in composite_setup()
2169 (struct webusb_url_descriptor *)cdev->req->buf; in composite_setup()
2171 url_descriptor->bDescriptorType = WEBUSB_URL_DESCRIPTOR_TYPE; in composite_setup()
2173 if (strncasecmp(cdev->landing_page, "https://", 8) == 0) { in composite_setup()
2175 url_descriptor->bScheme = WEBUSB_URL_SCHEME_HTTPS; in composite_setup()
2176 } else if (strncasecmp(cdev->landing_page, "http://", 7) == 0) { in composite_setup()
2178 url_descriptor->bScheme = WEBUSB_URL_SCHEME_HTTP; in composite_setup()
2181 url_descriptor->bScheme = WEBUSB_URL_SCHEME_NONE; in composite_setup()
2184 landing_page_length = strnlen(cdev->landing_page, in composite_setup()
2185 sizeof(url_descriptor->URL) in composite_setup()
2186 - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset); in composite_setup()
2190 - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset; in composite_setup()
2192 memcpy(url_descriptor->URL, in composite_setup()
2193 cdev->landing_page + landing_page_offset, in composite_setup()
2194 landing_page_length - landing_page_offset); in composite_setup()
2195 url_descriptor->bLength = landing_page_length in composite_setup()
2196 - landing_page_offset + WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH; in composite_setup()
2198 value = url_descriptor->bLength; in composite_setup()
2204 "non-core control req%02x.%02x v%04x i%04x l%d\n", in composite_setup()
2205 ctrl->bRequestType, ctrl->bRequest, in composite_setup()
2212 if (cdev->config) { in composite_setup()
2213 list_for_each_entry(f, &cdev->config->functions, list) in composite_setup()
2214 if (f->req_match && in composite_setup()
2215 f->req_match(f, ctrl, false)) in composite_setup()
2219 list_for_each_entry(c, &cdev->configs, list) in composite_setup()
2220 list_for_each_entry(f, &c->functions, list) in composite_setup()
2221 if (f->req_match && in composite_setup()
2222 f->req_match(f, ctrl, true)) in composite_setup()
2227 switch (ctrl->bRequestType & USB_RECIP_MASK) { in composite_setup()
2229 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
2231 f = cdev->config->interface[intf]; in composite_setup()
2235 if (!cdev->config) in composite_setup()
2238 list_for_each_entry(iter, &cdev->config->functions, list) { in composite_setup()
2239 if (test_bit(endp, iter->endpoints)) { in composite_setup()
2247 if (f && f->setup) in composite_setup()
2248 value = f->setup(f, ctrl); in composite_setup()
2252 c = cdev->config; in composite_setup()
2257 if (c->setup) { in composite_setup()
2258 value = c->setup(c, ctrl); in composite_setup()
2263 if (!list_is_singular(&c->functions)) in composite_setup()
2265 f = list_first_entry(&c->functions, struct usb_function, in composite_setup()
2267 if (f->setup) in composite_setup()
2268 value = f->setup(f, ctrl); in composite_setup()
2277 req->length = value; in composite_setup()
2278 req->context = cdev; in composite_setup()
2279 req->zero = value < w_length; in composite_setup()
2282 DBG(cdev, "ep_queue --> %d\n", value); in composite_setup()
2283 req->status = 0; in composite_setup()
2284 composite_setup_complete(gadget->ep0, req); in composite_setup()
2305 spin_lock_irqsave(&cdev->lock, flags); in __composite_disconnect()
2306 cdev->suspended = 0; in __composite_disconnect()
2307 if (cdev->config) in __composite_disconnect()
2309 if (cdev->driver->disconnect) in __composite_disconnect()
2310 cdev->driver->disconnect(cdev); in __composite_disconnect()
2311 spin_unlock_irqrestore(&cdev->lock, flags); in __composite_disconnect()
2331 /*-------------------------------------------------------------------------*/
2339 return sprintf(buf, "%d\n", cdev->suspended); in suspended_show()
2346 struct usb_gadget_strings *gstr = cdev->driver->strings[0]; in __composite_unbind()
2347 struct usb_string *dev_str = gstr->strings; in __composite_unbind()
2352 * state protected by cdev->lock. in __composite_unbind()
2354 WARN_ON(cdev->config); in __composite_unbind()
2356 while (!list_empty(&cdev->configs)) { in __composite_unbind()
2358 c = list_first_entry(&cdev->configs, in __composite_unbind()
2362 if (cdev->driver->unbind && unbind_driver) in __composite_unbind()
2363 cdev->driver->unbind(cdev); in __composite_unbind()
2367 if (dev_str[USB_GADGET_MANUFACTURER_IDX].s == cdev->def_manufacturer) in __composite_unbind()
2370 kfree(cdev->def_manufacturer); in __composite_unbind()
2394 idVendor = new->idVendor; in update_unchanged_dev_desc()
2395 idProduct = new->idProduct; in update_unchanged_dev_desc()
2396 bcdDevice = new->bcdDevice; in update_unchanged_dev_desc()
2397 iSerialNumber = new->iSerialNumber; in update_unchanged_dev_desc()
2398 iManufacturer = new->iManufacturer; in update_unchanged_dev_desc()
2399 iProduct = new->iProduct; in update_unchanged_dev_desc()
2403 new->idVendor = idVendor; in update_unchanged_dev_desc()
2405 new->idProduct = idProduct; in update_unchanged_dev_desc()
2407 new->bcdDevice = bcdDevice; in update_unchanged_dev_desc()
2409 new->bcdDevice = cpu_to_le16(get_default_bcdDevice()); in update_unchanged_dev_desc()
2411 new->iSerialNumber = iSerialNumber; in update_unchanged_dev_desc()
2413 new->iManufacturer = iManufacturer; in update_unchanged_dev_desc()
2415 new->iProduct = iProduct; in update_unchanged_dev_desc()
2421 struct usb_gadget *gadget = cdev->gadget; in composite_dev_prepare()
2422 int ret = -ENOMEM; in composite_dev_prepare()
2425 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); in composite_dev_prepare()
2426 if (!cdev->req) in composite_dev_prepare()
2427 return -ENOMEM; in composite_dev_prepare()
2429 cdev->req->buf = kzalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL); in composite_dev_prepare()
2430 if (!cdev->req->buf) in composite_dev_prepare()
2433 ret = device_create_file(&gadget->dev, &dev_attr_suspended); in composite_dev_prepare()
2437 cdev->req->complete = composite_setup_complete; in composite_dev_prepare()
2438 cdev->req->context = cdev; in composite_dev_prepare()
2439 gadget->ep0->driver_data = cdev; in composite_dev_prepare()
2441 cdev->driver = composite; in composite_dev_prepare()
2445 * more than 100mA from USB must report itself as bus-powered in in composite_dev_prepare()
2451 /* interface and string IDs start at zero via kzalloc. in composite_dev_prepare()
2453 * drivers will zero ep->driver_data. in composite_dev_prepare()
2458 kfree(cdev->req->buf); in composite_dev_prepare()
2460 usb_ep_free_request(gadget->ep0, cdev->req); in composite_dev_prepare()
2461 cdev->req = NULL; in composite_dev_prepare()
2470 cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL); in composite_os_desc_req_prepare()
2471 if (!cdev->os_desc_req) { in composite_os_desc_req_prepare()
2472 ret = -ENOMEM; in composite_os_desc_req_prepare()
2476 cdev->os_desc_req->buf = kmalloc(USB_COMP_EP0_OS_DESC_BUFSIZ, in composite_os_desc_req_prepare()
2478 if (!cdev->os_desc_req->buf) { in composite_os_desc_req_prepare()
2479 ret = -ENOMEM; in composite_os_desc_req_prepare()
2480 usb_ep_free_request(ep0, cdev->os_desc_req); in composite_os_desc_req_prepare()
2483 cdev->os_desc_req->context = cdev; in composite_os_desc_req_prepare()
2484 cdev->os_desc_req->complete = composite_setup_complete; in composite_os_desc_req_prepare()
2494 list_for_each_entry_safe(uc, tmp, &cdev->gstrings, list) { in composite_dev_cleanup()
2495 list_del(&uc->list); in composite_dev_cleanup()
2498 if (cdev->os_desc_req) { in composite_dev_cleanup()
2499 if (cdev->os_desc_pending) in composite_dev_cleanup()
2500 usb_ep_dequeue(cdev->gadget->ep0, cdev->os_desc_req); in composite_dev_cleanup()
2502 kfree(cdev->os_desc_req->buf); in composite_dev_cleanup()
2503 cdev->os_desc_req->buf = NULL; in composite_dev_cleanup()
2504 usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req); in composite_dev_cleanup()
2505 cdev->os_desc_req = NULL; in composite_dev_cleanup()
2507 if (cdev->req) { in composite_dev_cleanup()
2508 if (cdev->setup_pending) in composite_dev_cleanup()
2509 usb_ep_dequeue(cdev->gadget->ep0, cdev->req); in composite_dev_cleanup()
2511 kfree(cdev->req->buf); in composite_dev_cleanup()
2512 cdev->req->buf = NULL; in composite_dev_cleanup()
2513 usb_ep_free_request(cdev->gadget->ep0, cdev->req); in composite_dev_cleanup()
2514 cdev->req = NULL; in composite_dev_cleanup()
2516 cdev->next_string_id = 0; in composite_dev_cleanup()
2517 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); in composite_dev_cleanup()
2529 &cdev->gadget->ep_list, ep_list) { in composite_dev_cleanup()
2530 if (ep->ops->dispose) in composite_dev_cleanup()
2531 ep->ops->dispose(ep); in composite_dev_cleanup()
2540 int status = -ENOMEM; in composite_bind()
2546 spin_lock_init(&cdev->lock); in composite_bind()
2547 cdev->gadget = gadget; in composite_bind()
2549 INIT_LIST_HEAD(&cdev->configs); in composite_bind()
2550 INIT_LIST_HEAD(&cdev->gstrings); in composite_bind()
2560 status = composite->bind(cdev); in composite_bind()
2564 if (cdev->use_os_string) { in composite_bind()
2565 status = composite_os_desc_req_prepare(cdev, gadget->ep0); in composite_bind()
2570 update_unchanged_dev_desc(&cdev->desc, composite->dev); in composite_bind()
2573 if (composite->needs_serial && !cdev->desc.iSerialNumber) in composite_bind()
2576 INFO(cdev, "%s ready\n", composite->name); in composite_bind()
2584 /*-------------------------------------------------------------------------*/
2595 if (cdev->config) { in composite_suspend()
2596 list_for_each_entry(f, &cdev->config->functions, list) { in composite_suspend()
2597 if (f->suspend) in composite_suspend()
2598 f->suspend(f); in composite_suspend()
2601 if (cdev->driver->suspend) in composite_suspend()
2602 cdev->driver->suspend(cdev); in composite_suspend()
2604 cdev->suspended = 1; in composite_suspend()
2620 if (cdev->driver->resume) in composite_resume()
2621 cdev->driver->resume(cdev); in composite_resume()
2622 if (cdev->config) { in composite_resume()
2623 list_for_each_entry(f, &cdev->config->functions, list) { in composite_resume()
2629 if (f->resume && !f->func_suspended) in composite_resume()
2630 f->resume(f); in composite_resume()
2633 maxpower = cdev->config->MaxPower ? in composite_resume()
2634 cdev->config->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW; in composite_resume()
2635 if (gadget->speed < USB_SPEED_SUPER) in composite_resume()
2650 cdev->suspended = 0; in composite_resume()
2653 /*-------------------------------------------------------------------------*/
2672 * usb_composite_probe() - register a composite driver
2691 if (!driver || !driver->dev || !driver->bind) in usb_composite_probe()
2692 return -EINVAL; in usb_composite_probe()
2694 if (!driver->name) in usb_composite_probe()
2695 driver->name = "composite"; in usb_composite_probe()
2697 driver->gadget_driver = composite_driver_template; in usb_composite_probe()
2698 gadget_driver = &driver->gadget_driver; in usb_composite_probe()
2700 gadget_driver->function = (char *) driver->name; in usb_composite_probe()
2701 gadget_driver->driver.name = driver->name; in usb_composite_probe()
2702 gadget_driver->max_speed = driver->max_speed; in usb_composite_probe()
2709 * usb_composite_unregister() - unregister a composite driver
2717 usb_gadget_unregister_driver(&driver->gadget_driver); in usb_composite_unregister()
2722 * usb_composite_setup_continue() - Continue with the control transfer
2734 struct usb_request *req = cdev->req; in usb_composite_setup_continue()
2738 spin_lock_irqsave(&cdev->lock, flags); in usb_composite_setup_continue()
2740 if (cdev->delayed_status == 0) { in usb_composite_setup_continue()
2743 } else if (--cdev->delayed_status == 0) { in usb_composite_setup_continue()
2745 req->length = 0; in usb_composite_setup_continue()
2746 req->context = cdev; in usb_composite_setup_continue()
2749 DBG(cdev, "ep_queue --> %d\n", value); in usb_composite_setup_continue()
2750 req->status = 0; in usb_composite_setup_continue()
2751 composite_setup_complete(cdev->gadget->ep0, req); in usb_composite_setup_continue()
2755 spin_unlock_irqrestore(&cdev->lock, flags); in usb_composite_setup_continue()
2761 return kasprintf(GFP_KERNEL, "%s %s with %s", init_utsname()->sysname, in composite_default_mfr()
2762 init_utsname()->release, gadget->name); in composite_default_mfr()
2768 struct usb_device_descriptor *desc = &cdev->desc; in usb_composite_overwrite_options()
2769 struct usb_gadget_strings *gstr = cdev->driver->strings[0]; in usb_composite_overwrite_options()
2770 struct usb_string *dev_str = gstr->strings; in usb_composite_overwrite_options()
2772 if (covr->idVendor) in usb_composite_overwrite_options()
2773 desc->idVendor = cpu_to_le16(covr->idVendor); in usb_composite_overwrite_options()
2775 if (covr->idProduct) in usb_composite_overwrite_options()
2776 desc->idProduct = cpu_to_le16(covr->idProduct); in usb_composite_overwrite_options()
2778 if (covr->bcdDevice) in usb_composite_overwrite_options()
2779 desc->bcdDevice = cpu_to_le16(covr->bcdDevice); in usb_composite_overwrite_options()
2781 if (covr->serial_number) { in usb_composite_overwrite_options()
2782 desc->iSerialNumber = dev_str[USB_GADGET_SERIAL_IDX].id; in usb_composite_overwrite_options()
2783 dev_str[USB_GADGET_SERIAL_IDX].s = covr->serial_number; in usb_composite_overwrite_options()
2785 if (covr->manufacturer) { in usb_composite_overwrite_options()
2786 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id; in usb_composite_overwrite_options()
2787 dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer; in usb_composite_overwrite_options()
2790 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id; in usb_composite_overwrite_options()
2791 cdev->def_manufacturer = composite_default_mfr(cdev->gadget); in usb_composite_overwrite_options()
2792 dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer; in usb_composite_overwrite_options()
2795 if (covr->product) { in usb_composite_overwrite_options()
2796 desc->iProduct = dev_str[USB_GADGET_PRODUCT_IDX].id; in usb_composite_overwrite_options()
2797 dev_str[USB_GADGET_PRODUCT_IDX].s = covr->product; in usb_composite_overwrite_options()