Lines Matching +full:language +full:- +full:id
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
460 * ID in interface, association, CDC union, and other descriptors. It
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
478 unsigned id = config->next_interface_id; in usb_interface_id() local
480 if (id < MAX_CONFIG_INTERFACES) { in usb_interface_id()
481 config->interface[id] = function; in usb_interface_id()
482 config->next_interface_id = id + 1; in usb_interface_id()
483 return id; 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()
506 int id; in usb_func_wakeup() local
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()
516 for (id = 0; id < MAX_CONFIG_INTERFACES; id++) in usb_func_wakeup()
517 if (func->config->interface[id] == func) in usb_func_wakeup()
520 if (id == MAX_CONFIG_INTERFACES) { 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()
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()
1054 (c && !(c->bmAttributes & USB_CONFIG_ATT_SELFPOWER))) in set_config()
1060 if (result >= 0 && cdev->delayed_status) in set_config()
1070 if (!config->bConfigurationValue) in usb_add_config_only()
1071 return -EINVAL; in usb_add_config_only()
1074 list_for_each_entry(c, &cdev->configs, list) { in usb_add_config_only()
1075 if (c->bConfigurationValue == config->bConfigurationValue) in usb_add_config_only()
1076 return -EBUSY; in usb_add_config_only()
1079 config->cdev = cdev; in usb_add_config_only()
1080 list_add_tail(&config->list, &cdev->configs); in usb_add_config_only()
1082 INIT_LIST_HEAD(&config->functions); in usb_add_config_only()
1083 config->next_interface_id = 0; in usb_add_config_only()
1084 memset(config->interface, 0, sizeof(config->interface)); in usb_add_config_only()
1091 * usb_add_config() - add a configuration to a device.
1102 * assigns global resources including string IDs, and per-configuration
1109 int status = -EINVAL; in usb_add_config()
1115 config->bConfigurationValue, in usb_add_config()
1116 config->label, config); in usb_add_config()
1125 status = usb_gadget_check_config(cdev->gadget); in usb_add_config()
1128 while (!list_empty(&config->functions)) { in usb_add_config()
1131 f = list_first_entry(&config->functions, in usb_add_config()
1133 list_del(&f->list); in usb_add_config()
1134 if (f->unbind) { in usb_add_config()
1136 f->name, f); in usb_add_config()
1137 f->unbind(config, f); in usb_add_config()
1141 list_del(&config->list); in usb_add_config()
1142 config->cdev = NULL; in usb_add_config()
1147 config->bConfigurationValue, config, in usb_add_config()
1148 config->superspeed_plus ? " superplus" : "", in usb_add_config()
1149 config->superspeed ? " super" : "", in usb_add_config()
1150 config->highspeed ? " high" : "", in usb_add_config()
1151 config->fullspeed in usb_add_config()
1152 ? (gadget_is_dualspeed(cdev->gadget) in usb_add_config()
1158 struct usb_function *f = config->interface[i]; in usb_add_config()
1163 i, f->name, f); in usb_add_config()
1167 /* set_alt(), or next bind(), sets up ep->claimed as needed */ in usb_add_config()
1168 usb_ep_autoconfig_reset(cdev->gadget); in usb_add_config()
1172 DBG(cdev, "added config '%s'/%u --> %d\n", config->label, in usb_add_config()
1173 config->bConfigurationValue, status); in usb_add_config()
1181 while (!list_empty(&config->functions)) { in remove_config()
1184 f = list_first_entry(&config->functions, in remove_config()
1189 list_del(&config->list); in remove_config()
1190 if (config->unbind) { in remove_config()
1191 DBG(cdev, "unbind config '%s'/%p\n", config->label, config); in remove_config()
1192 config->unbind(config); in remove_config()
1198 * usb_remove_config() - remove a configuration from a device.
1211 spin_lock_irqsave(&cdev->lock, flags); in usb_remove_config()
1213 if (cdev->config == config) in usb_remove_config()
1216 spin_unlock_irqrestore(&cdev->lock, flags); in usb_remove_config()
1221 /*-------------------------------------------------------------------------*/
1225 * only one language (probably English) is used, with i18n handled on
1232 __le16 language; in collect_langs() local
1237 language = cpu_to_le16(s->language); in collect_langs()
1239 if (*tmp == language) in collect_langs()
1242 *tmp++ = language; in collect_langs()
1251 u16 language, in lookup_string() argument
1252 int id in lookup_string() argument
1260 if (s->language != language) in lookup_string()
1262 value = usb_gadget_get_string(s, id, buf); in lookup_string()
1266 return -EINVAL; in lookup_string()
1270 void *buf, u16 language, int id) in get_string() argument
1272 struct usb_composite_driver *composite = cdev->driver; in get_string()
1283 /* 0 == report all available language codes */ in get_string()
1284 if (id == 0) { in get_string()
1289 s->bDescriptorType = USB_DT_STRING; in get_string()
1291 sp = composite->strings; in get_string()
1293 collect_langs(sp, s->wData); in get_string()
1295 list_for_each_entry(c, &cdev->configs, list) { in get_string()
1296 sp = c->strings; in get_string()
1298 collect_langs(sp, s->wData); in get_string()
1300 list_for_each_entry(f, &c->functions, list) { in get_string()
1301 sp = f->strings; in get_string()
1303 collect_langs(sp, s->wData); in get_string()
1306 list_for_each_entry(uc, &cdev->gstrings, list) { in get_string()
1310 collect_langs(sp, s->wData); in get_string()
1313 for (len = 0; len <= USB_MAX_STRING_LEN && s->wData[len]; len++) in get_string()
1316 return -EINVAL; in get_string()
1318 s->bLength = 2 * (len + 1); in get_string()
1319 return s->bLength; in get_string()
1322 if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) { in get_string()
1324 b->bLength = sizeof(*b); in get_string()
1325 b->bDescriptorType = USB_DT_STRING; in get_string()
1327 sizeof(b->qwSignature) == sizeof(cdev->qw_sign), in get_string()
1329 memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature)); in get_string()
1330 b->bMS_VendorCode = cdev->b_vendor_code; in get_string()
1331 b->bPad = 0; in get_string()
1335 list_for_each_entry(uc, &cdev->gstrings, list) { in get_string()
1339 len = lookup_string(sp, buf, language, id); in get_string()
1344 /* String IDs are device-scoped, so we look up each string in get_string()
1346 * simpler-is-better here. in get_string()
1348 if (composite->strings) { in get_string()
1349 len = lookup_string(composite->strings, buf, language, id); in get_string()
1353 list_for_each_entry(c, &cdev->configs, list) { in get_string()
1354 if (c->strings) { in get_string()
1355 len = lookup_string(c->strings, buf, language, id); in get_string()
1359 list_for_each_entry(f, &c->functions, list) { in get_string()
1360 if (!f->strings) in get_string()
1362 len = lookup_string(f->strings, buf, language, id); in get_string()
1367 return -EINVAL; in get_string()
1371 * usb_string_id() - allocate an unused string ID
1377 * then store that ID in the appropriate descriptors and string table.
1386 if (cdev->next_string_id < 254) { in usb_string_id()
1387 /* string id 0 is reserved by USB spec for list of in usb_string_id()
1389 /* 255 reserved as well? -- mina86 */ in usb_string_id()
1390 cdev->next_string_id++; in usb_string_id()
1391 return cdev->next_string_id; in usb_string_id()
1393 return -ENODEV; in usb_string_id()
1398 * usb_string_ids_tab() - allocate unused string IDs in batch
1415 int next = cdev->next_string_id; in usb_string_ids_tab()
1417 for (; str->s; ++str) { in usb_string_ids_tab()
1419 return -ENODEV; in usb_string_ids_tab()
1420 str->id = ++next; in usb_string_ids_tab()
1423 cdev->next_string_id = next; in usb_string_ids_tab()
1448 return ERR_PTR(-ENOMEM); in copy_gadget_strings()
1450 stash = uc->stash; in copy_gadget_strings()
1458 gs->language = sp[n_gs]->language; in copy_gadget_strings()
1459 gs->strings = stash; in copy_gadget_strings()
1460 org_s = sp[n_gs]->strings; in copy_gadget_strings()
1465 if (org_s->s) in copy_gadget_strings()
1466 s->s = org_s->s; in copy_gadget_strings()
1468 s->s = ""; in copy_gadget_strings()
1472 s->s = NULL; in copy_gadget_strings()
1481 * usb_gstrings_attach() - attach gadget strings to a cdev and assign ids
1485 * @n_strings: number of entries in each usb_strings array (sp[]->strings)
1491 * The ->language pointer of each struct usb_gadget_strings has to contain the
1493 * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first
1494 * usb_string entry of es-ES contains the translation of the first usb_string
1495 * entry of en-US. Therefore both entries become the same id assign.
1510 return ERR_PTR(-EINVAL); in usb_gstrings_attach()
1517 ret = usb_string_ids_tab(cdev, n_gs[0]->strings); in usb_gstrings_attach()
1526 m_s = n_gs[0]->strings; in usb_gstrings_attach()
1527 s = n_gs[i]->strings; in usb_gstrings_attach()
1529 s->id = m_s->id; in usb_gstrings_attach()
1534 list_add_tail(&uc->list, &cdev->gstrings); in usb_gstrings_attach()
1535 return n_gs[0]->strings; in usb_gstrings_attach()
1543 * usb_string_ids_n() - allocate unused string IDs in batch
1548 * Returns the first requested ID. This ID and next @n-1 IDs are now
1549 * valid IDs. At least provided that @n is non-zero because if it
1550 * is, returns last requested ID which is now very useful information.
1554 * then store that ID in the appropriate descriptors and string table.
1563 unsigned next = c->next_string_id; in usb_string_ids_n()
1565 return -ENODEV; in usb_string_ids_n()
1566 c->next_string_id += n; in usb_string_ids_n()
1571 /*-------------------------------------------------------------------------*/
1577 if (req->status || req->actual != req->length) in composite_setup_complete()
1578 DBG((struct usb_composite_dev *) ep->driver_data, in composite_setup_complete()
1579 "setup complete --> %d, %d/%d\n", in composite_setup_complete()
1580 req->status, req->actual, req->length); in composite_setup_complete()
1584 * so they don't have to maintain the same ->complete() stubs. in composite_setup_complete()
1586 * Because of that, we need to check for the validity of ->context in composite_setup_complete()
1589 if (!req->context) in composite_setup_complete()
1592 cdev = req->context; in composite_setup_complete()
1594 if (cdev->req == req) in composite_setup_complete()
1595 cdev->setup_pending = false; in composite_setup_complete()
1596 else if (cdev->os_desc_req == req) in composite_setup_complete()
1597 cdev->os_desc_pending = false; in composite_setup_complete()
1607 ret = usb_ep_queue(cdev->gadget->ep0, req, gfp_flags); in composite_ep0_queue()
1609 if (cdev->req == req) in composite_ep0_queue()
1610 cdev->setup_pending = true; in composite_ep0_queue()
1611 else if (cdev->os_desc_req == req) in composite_ep0_queue()
1612 cdev->os_desc_pending = true; in composite_ep0_queue()
1625 for (i = 0; i < c->next_interface_id; ++i) { in count_ext_compat()
1629 f = c->interface[i]; in count_ext_compat()
1630 for (j = 0; j < f->os_desc_n; ++j) { in count_ext_compat()
1633 if (i != f->os_desc_table[j].if_id) in count_ext_compat()
1635 d = f->os_desc_table[j].os_desc; in count_ext_compat()
1636 if (d && d->ext_compat_id) in count_ext_compat()
1650 for (i = 0; i < c->next_interface_id; ++i) { in fill_ext_compat()
1654 f = c->interface[i]; in fill_ext_compat()
1655 for (j = 0; j < f->os_desc_n; ++j) { in fill_ext_compat()
1658 if (i != f->os_desc_table[j].if_id) in fill_ext_compat()
1660 d = f->os_desc_table[j].os_desc; in fill_ext_compat()
1661 if (d && d->ext_compat_id) { in fill_ext_compat()
1664 memcpy(buf, d->ext_compat_id, 16); in fill_ext_compat()
1685 f = c->interface[interface]; in count_ext_prop()
1686 for (j = 0; j < f->os_desc_n; ++j) { in count_ext_prop()
1689 if (interface != f->os_desc_table[j].if_id) in count_ext_prop()
1691 d = f->os_desc_table[j].os_desc; in count_ext_prop()
1692 if (d && d->ext_compat_id) in count_ext_prop()
1693 return d->ext_prop_count; in count_ext_prop()
1705 f = c->interface[interface]; in len_ext_prop()
1706 for (j = 0; j < f->os_desc_n; ++j) { in len_ext_prop()
1707 if (interface != f->os_desc_table[j].if_id) in len_ext_prop()
1709 d = f->os_desc_table[j].os_desc; in len_ext_prop()
1711 return min(res + d->ext_prop_len, 4096); in len_ext_prop()
1723 f = c->interface[interface]; in fill_ext_prop()
1726 for (j = 0; j < f->os_desc_n; ++j) { in fill_ext_prop()
1727 if (interface != f->os_desc_table[j].if_id) in fill_ext_prop()
1729 d = f->os_desc_table[j].os_desc; in fill_ext_prop()
1731 list_for_each_entry(ext_prop, &d->ext_prop, entry) { in fill_ext_prop()
1732 n = ext_prop->data_len + in fill_ext_prop()
1733 ext_prop->name_len + 14; in fill_ext_prop()
1737 usb_ext_prop_put_type(buf, ext_prop->type); in fill_ext_prop()
1738 ret = usb_ext_prop_put_name(buf, ext_prop->name, in fill_ext_prop()
1739 ext_prop->name_len); in fill_ext_prop()
1742 switch (ext_prop->type) { in fill_ext_prop()
1747 ext_prop->data, in fill_ext_prop()
1748 ext_prop->data_len); in fill_ext_prop()
1752 ext_prop->data, in fill_ext_prop()
1753 ext_prop->data_len); in fill_ext_prop()
1760 return -EINVAL; in fill_ext_prop()
1781 struct usb_request *req = cdev->req; in composite_setup()
1782 int value = -EOPNOTSUPP; in composite_setup()
1784 u16 w_index = le16_to_cpu(ctrl->wIndex); in composite_setup()
1786 u16 w_value = le16_to_cpu(ctrl->wValue); in composite_setup()
1787 u16 w_length = le16_to_cpu(ctrl->wLength); in composite_setup()
1793 if (ctrl->bRequestType & USB_DIR_IN) { in composite_setup()
1795 __le16 *temp = (__le16 *)&ctrl->wLength; in composite_setup()
1804 /* partial re-init of the response message; the function or the in composite_setup()
1805 * gadget might need to intercept e.g. a control-OUT completion in composite_setup()
1808 req->zero = 0; in composite_setup()
1809 req->context = cdev; in composite_setup()
1810 req->complete = composite_setup_complete; in composite_setup()
1811 req->length = 0; in composite_setup()
1812 gadget->ep0->driver_data = cdev; in composite_setup()
1815 * Don't let non-standard requests match any of the cases below in composite_setup()
1818 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) in composite_setup()
1821 switch (ctrl->bRequest) { in composite_setup()
1825 if (ctrl->bRequestType != USB_DIR_IN) in composite_setup()
1830 cdev->desc.bNumConfigurations = in composite_setup()
1832 cdev->desc.bMaxPacketSize0 = in composite_setup()
1833 cdev->gadget->ep0->maxpacket; in composite_setup()
1835 if (gadget->speed >= USB_SPEED_SUPER) { in composite_setup()
1836 cdev->desc.bcdUSB = cpu_to_le16(0x0320); in composite_setup()
1837 cdev->desc.bMaxPacketSize0 = 9; in composite_setup()
1839 cdev->desc.bcdUSB = cpu_to_le16(0x0210); in composite_setup()
1842 if (gadget->lpm_capable || cdev->use_webusb) in composite_setup()
1843 cdev->desc.bcdUSB = cpu_to_le16(0x0201); in composite_setup()
1845 cdev->desc.bcdUSB = cpu_to_le16(0x0200); in composite_setup()
1848 value = min_t(u16, w_length, sizeof(cdev->desc)); in composite_setup()
1849 memcpy(req->buf, &cdev->desc, value); in composite_setup()
1853 gadget->speed >= USB_SPEED_SUPER) in composite_setup()
1861 gadget->speed >= USB_SPEED_SUPER) in composite_setup()
1870 value = get_string(cdev, req->buf, in composite_setup()
1877 gadget->lpm_capable || cdev->use_webusb) { in composite_setup()
1887 if (cdev->config) in composite_setup()
1888 config = cdev->config; in composite_setup()
1891 &cdev->configs, in composite_setup()
1896 if (gadget->otg_caps && in composite_setup()
1897 (gadget->otg_caps->otg_rev >= 0x0200)) in composite_setup()
1905 memcpy(req->buf, config->descriptors[0], value); in composite_setup()
1913 if (ctrl->bRequestType != 0) in composite_setup()
1916 if (gadget->a_hnp_support) in composite_setup()
1918 else if (gadget->a_alt_hnp_support) in composite_setup()
1923 spin_lock(&cdev->lock); in composite_setup()
1925 spin_unlock(&cdev->lock); in composite_setup()
1928 if (ctrl->bRequestType != USB_DIR_IN) in composite_setup()
1930 if (cdev->config) in composite_setup()
1931 *(u8 *)req->buf = cdev->config->bConfigurationValue; in composite_setup()
1933 *(u8 *)req->buf = 0; in composite_setup()
1939 if (ctrl->bRequestType != USB_RECIP_INTERFACE) in composite_setup()
1941 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
1943 f = cdev->config->interface[intf]; in composite_setup()
1952 if (w_value && !f->get_alt) in composite_setup()
1955 spin_lock(&cdev->lock); in composite_setup()
1956 value = f->set_alt(f, w_index, w_value); in composite_setup()
1960 __func__, intf, f->name); in composite_setup()
1961 cdev->delayed_status++; in composite_setup()
1963 cdev->delayed_status); in composite_setup()
1965 spin_unlock(&cdev->lock); in composite_setup()
1968 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) in composite_setup()
1970 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
1972 f = cdev->config->interface[intf]; in composite_setup()
1976 value = f->get_alt ? f->get_alt(f, w_index) : 0; in composite_setup()
1979 *((u8 *)req->buf) = value; in composite_setup()
1983 if (gadget_is_otg(gadget) && gadget->hnp_polling_support && in composite_setup()
1985 if (ctrl->bRequestType != (USB_DIR_IN | in composite_setup()
1988 *((u8 *)req->buf) = gadget->host_request_flag; in composite_setup()
2002 if (ctrl->bRequestType != (USB_DIR_IN | USB_RECIP_INTERFACE)) in composite_setup()
2005 put_unaligned_le16(0, req->buf); in composite_setup()
2006 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
2008 f = cdev->config->interface[intf]; in composite_setup()
2012 if (f->get_status) { in composite_setup()
2013 status = f->get_status(f); in composite_setup()
2018 if (f->config->bmAttributes & USB_CONFIG_ATT_WAKEUP) { in composite_setup()
2020 if (f->func_wakeup_armed) in composite_setup()
2025 put_unaligned_le16(status & 0x0000ffff, req->buf); in composite_setup()
2036 if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_INTERFACE)) in composite_setup()
2040 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
2042 f = cdev->config->interface[intf]; in composite_setup()
2046 if (f->func_suspend) { in composite_setup()
2047 value = f->func_suspend(f, w_index >> 8); in composite_setup()
2049 } else if (ctrl->bRequest == USB_REQ_SET_FEATURE) { in composite_setup()
2050 if (!(f->config->bmAttributes & in composite_setup()
2055 f->func_wakeup_armed = !!(w_index & in composite_setup()
2059 if (f->suspend && !f->func_suspended) { in composite_setup()
2060 f->suspend(f); in composite_setup()
2061 f->func_suspended = true; in composite_setup()
2069 if (f->resume && f->func_suspended) { in composite_setup()
2070 f->resume(f); in composite_setup()
2071 f->func_suspended = false; in composite_setup()
2075 } else if (ctrl->bRequest == USB_REQ_CLEAR_FEATURE) { in composite_setup()
2076 f->func_wakeup_armed = false; in composite_setup()
2078 if (f->resume && f->func_suspended) { in composite_setup()
2079 f->resume(f); in composite_setup()
2080 f->func_suspended = false; in composite_setup()
2098 if (cdev->use_os_string && cdev->os_desc_config && in composite_setup()
2099 (ctrl->bRequestType & USB_TYPE_VENDOR) && in composite_setup()
2100 ctrl->bRequest == cdev->b_vendor_code) { in composite_setup()
2106 req = cdev->os_desc_req; in composite_setup()
2107 req->context = cdev; in composite_setup()
2108 req->complete = composite_setup_complete; in composite_setup()
2109 buf = req->buf; in composite_setup()
2110 os_desc_cfg = cdev->os_desc_config; in composite_setup()
2114 switch (ctrl->bRequestType & USB_RECIP_MASK) { in composite_setup()
2148 !os_desc_cfg->interface[interface]) in composite_setup()
2172 * https://wicg.github.io/webusb/#device-requests in composite_setup()
2174 if (cdev->use_webusb && in composite_setup()
2175 ctrl->bRequestType == (USB_DIR_IN | USB_TYPE_VENDOR) && in composite_setup()
2178 ctrl->bRequest == cdev->b_webusb_vendor_code) { in composite_setup()
2182 (struct webusb_url_descriptor *)cdev->req->buf; in composite_setup()
2184 url_descriptor->bDescriptorType = WEBUSB_URL_DESCRIPTOR_TYPE; in composite_setup()
2186 if (strncasecmp(cdev->landing_page, "https://", 8) == 0) { in composite_setup()
2188 url_descriptor->bScheme = WEBUSB_URL_SCHEME_HTTPS; in composite_setup()
2189 } else if (strncasecmp(cdev->landing_page, "http://", 7) == 0) { in composite_setup()
2191 url_descriptor->bScheme = WEBUSB_URL_SCHEME_HTTP; in composite_setup()
2194 url_descriptor->bScheme = WEBUSB_URL_SCHEME_NONE; in composite_setup()
2197 landing_page_length = strnlen(cdev->landing_page, in composite_setup()
2198 sizeof(url_descriptor->URL) in composite_setup()
2199 - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset); in composite_setup()
2203 - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset; in composite_setup()
2205 memcpy(url_descriptor->URL, in composite_setup()
2206 cdev->landing_page + landing_page_offset, in composite_setup()
2207 landing_page_length - landing_page_offset); in composite_setup()
2208 url_descriptor->bLength = landing_page_length in composite_setup()
2209 - landing_page_offset + WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH; in composite_setup()
2211 value = url_descriptor->bLength; in composite_setup()
2217 "non-core control req%02x.%02x v%04x i%04x l%d\n", in composite_setup()
2218 ctrl->bRequestType, ctrl->bRequest, in composite_setup()
2225 if (cdev->config) { in composite_setup()
2226 list_for_each_entry(f, &cdev->config->functions, list) in composite_setup()
2227 if (f->req_match && in composite_setup()
2228 f->req_match(f, ctrl, false)) in composite_setup()
2232 list_for_each_entry(c, &cdev->configs, list) in composite_setup()
2233 list_for_each_entry(f, &c->functions, list) in composite_setup()
2234 if (f->req_match && in composite_setup()
2235 f->req_match(f, ctrl, true)) in composite_setup()
2240 switch (ctrl->bRequestType & USB_RECIP_MASK) { in composite_setup()
2242 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) in composite_setup()
2244 f = cdev->config->interface[intf]; in composite_setup()
2248 if (!cdev->config) in composite_setup()
2251 list_for_each_entry(iter, &cdev->config->functions, list) { in composite_setup()
2252 if (test_bit(endp, iter->endpoints)) { in composite_setup()
2260 if (f && f->setup) in composite_setup()
2261 value = f->setup(f, ctrl); in composite_setup()
2265 c = cdev->config; in composite_setup()
2270 if (c->setup) { in composite_setup()
2271 value = c->setup(c, ctrl); in composite_setup()
2276 if (!list_is_singular(&c->functions)) in composite_setup()
2278 f = list_first_entry(&c->functions, struct usb_function, in composite_setup()
2280 if (f->setup) in composite_setup()
2281 value = f->setup(f, ctrl); in composite_setup()
2290 req->length = value; in composite_setup()
2291 req->context = cdev; in composite_setup()
2292 req->zero = value < w_length; in composite_setup()
2295 DBG(cdev, "ep_queue --> %d\n", value); in composite_setup()
2296 req->status = 0; in composite_setup()
2297 composite_setup_complete(gadget->ep0, req); in composite_setup()
2318 spin_lock_irqsave(&cdev->lock, flags); in __composite_disconnect()
2319 cdev->suspended = 0; in __composite_disconnect()
2320 if (cdev->config) in __composite_disconnect()
2322 if (cdev->driver->disconnect) in __composite_disconnect()
2323 cdev->driver->disconnect(cdev); in __composite_disconnect()
2324 spin_unlock_irqrestore(&cdev->lock, flags); in __composite_disconnect()
2344 /*-------------------------------------------------------------------------*/
2352 return sprintf(buf, "%d\n", cdev->suspended); in suspended_show()
2359 struct usb_gadget_strings *gstr = cdev->driver->strings[0]; in __composite_unbind()
2360 struct usb_string *dev_str = gstr->strings; in __composite_unbind()
2365 * state protected by cdev->lock. in __composite_unbind()
2367 WARN_ON(cdev->config); in __composite_unbind()
2369 while (!list_empty(&cdev->configs)) { in __composite_unbind()
2371 c = list_first_entry(&cdev->configs, in __composite_unbind()
2375 if (cdev->driver->unbind && unbind_driver) in __composite_unbind()
2376 cdev->driver->unbind(cdev); in __composite_unbind()
2380 if (dev_str[USB_GADGET_MANUFACTURER_IDX].s == cdev->def_manufacturer) in __composite_unbind()
2383 kfree(cdev->def_manufacturer); in __composite_unbind()
2407 idVendor = new->idVendor; in update_unchanged_dev_desc()
2408 idProduct = new->idProduct; in update_unchanged_dev_desc()
2409 bcdDevice = new->bcdDevice; in update_unchanged_dev_desc()
2410 iSerialNumber = new->iSerialNumber; in update_unchanged_dev_desc()
2411 iManufacturer = new->iManufacturer; in update_unchanged_dev_desc()
2412 iProduct = new->iProduct; in update_unchanged_dev_desc()
2416 new->idVendor = idVendor; in update_unchanged_dev_desc()
2418 new->idProduct = idProduct; in update_unchanged_dev_desc()
2420 new->bcdDevice = bcdDevice; in update_unchanged_dev_desc()
2422 new->bcdDevice = cpu_to_le16(get_default_bcdDevice()); in update_unchanged_dev_desc()
2424 new->iSerialNumber = iSerialNumber; in update_unchanged_dev_desc()
2426 new->iManufacturer = iManufacturer; in update_unchanged_dev_desc()
2428 new->iProduct = iProduct; in update_unchanged_dev_desc()
2434 struct usb_gadget *gadget = cdev->gadget; in composite_dev_prepare()
2435 int ret = -ENOMEM; in composite_dev_prepare()
2438 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); in composite_dev_prepare()
2439 if (!cdev->req) in composite_dev_prepare()
2440 return -ENOMEM; in composite_dev_prepare()
2442 cdev->req->buf = kzalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL); in composite_dev_prepare()
2443 if (!cdev->req->buf) in composite_dev_prepare()
2446 ret = device_create_file(&gadget->dev, &dev_attr_suspended); in composite_dev_prepare()
2450 cdev->req->complete = composite_setup_complete; in composite_dev_prepare()
2451 cdev->req->context = cdev; in composite_dev_prepare()
2452 gadget->ep0->driver_data = cdev; in composite_dev_prepare()
2454 cdev->driver = composite; in composite_dev_prepare()
2458 * more than 100mA from USB must report itself as bus-powered in in composite_dev_prepare()
2466 * drivers will zero ep->driver_data. in composite_dev_prepare()
2471 kfree(cdev->req->buf); in composite_dev_prepare()
2473 usb_ep_free_request(gadget->ep0, cdev->req); in composite_dev_prepare()
2474 cdev->req = NULL; in composite_dev_prepare()
2483 cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL); in composite_os_desc_req_prepare()
2484 if (!cdev->os_desc_req) { in composite_os_desc_req_prepare()
2485 ret = -ENOMEM; in composite_os_desc_req_prepare()
2489 cdev->os_desc_req->buf = kmalloc(USB_COMP_EP0_OS_DESC_BUFSIZ, in composite_os_desc_req_prepare()
2491 if (!cdev->os_desc_req->buf) { in composite_os_desc_req_prepare()
2492 ret = -ENOMEM; in composite_os_desc_req_prepare()
2493 usb_ep_free_request(ep0, cdev->os_desc_req); in composite_os_desc_req_prepare()
2496 cdev->os_desc_req->context = cdev; in composite_os_desc_req_prepare()
2497 cdev->os_desc_req->complete = composite_setup_complete; in composite_os_desc_req_prepare()
2507 list_for_each_entry_safe(uc, tmp, &cdev->gstrings, list) { in composite_dev_cleanup()
2508 list_del(&uc->list); in composite_dev_cleanup()
2511 if (cdev->os_desc_req) { in composite_dev_cleanup()
2512 if (cdev->os_desc_pending) in composite_dev_cleanup()
2513 usb_ep_dequeue(cdev->gadget->ep0, cdev->os_desc_req); in composite_dev_cleanup()
2515 kfree(cdev->os_desc_req->buf); in composite_dev_cleanup()
2516 cdev->os_desc_req->buf = NULL; in composite_dev_cleanup()
2517 usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req); in composite_dev_cleanup()
2518 cdev->os_desc_req = NULL; in composite_dev_cleanup()
2520 if (cdev->req) { in composite_dev_cleanup()
2521 if (cdev->setup_pending) in composite_dev_cleanup()
2522 usb_ep_dequeue(cdev->gadget->ep0, cdev->req); in composite_dev_cleanup()
2524 kfree(cdev->req->buf); in composite_dev_cleanup()
2525 cdev->req->buf = NULL; in composite_dev_cleanup()
2526 usb_ep_free_request(cdev->gadget->ep0, cdev->req); in composite_dev_cleanup()
2527 cdev->req = NULL; in composite_dev_cleanup()
2529 cdev->next_string_id = 0; in composite_dev_cleanup()
2530 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); in composite_dev_cleanup()
2542 &cdev->gadget->ep_list, ep_list) { in composite_dev_cleanup()
2543 if (ep->ops->dispose) in composite_dev_cleanup()
2544 ep->ops->dispose(ep); in composite_dev_cleanup()
2553 int status = -ENOMEM; in composite_bind()
2559 spin_lock_init(&cdev->lock); in composite_bind()
2560 cdev->gadget = gadget; in composite_bind()
2562 INIT_LIST_HEAD(&cdev->configs); in composite_bind()
2563 INIT_LIST_HEAD(&cdev->gstrings); in composite_bind()
2573 status = composite->bind(cdev); in composite_bind()
2577 if (cdev->use_os_string) { in composite_bind()
2578 status = composite_os_desc_req_prepare(cdev, gadget->ep0); in composite_bind()
2583 update_unchanged_dev_desc(&cdev->desc, composite->dev); in composite_bind()
2586 if (composite->needs_serial && !cdev->desc.iSerialNumber) in composite_bind()
2589 INFO(cdev, "%s ready\n", composite->name); in composite_bind()
2597 /*-------------------------------------------------------------------------*/
2608 if (cdev->config) { in composite_suspend()
2609 list_for_each_entry(f, &cdev->config->functions, list) { in composite_suspend()
2610 if (f->suspend) in composite_suspend()
2611 f->suspend(f); in composite_suspend()
2614 if (cdev->driver->suspend) in composite_suspend()
2615 cdev->driver->suspend(cdev); in composite_suspend()
2617 cdev->suspended = 1; in composite_suspend()
2619 if (cdev->config && in composite_suspend()
2620 cdev->config->bmAttributes & USB_CONFIG_ATT_SELFPOWER) in composite_suspend()
2636 if (cdev->driver->resume) in composite_resume()
2637 cdev->driver->resume(cdev); in composite_resume()
2638 if (cdev->config) { in composite_resume()
2639 list_for_each_entry(f, &cdev->config->functions, list) { in composite_resume()
2645 if (f->resume && !f->func_suspended) in composite_resume()
2646 f->resume(f); in composite_resume()
2649 maxpower = cdev->config->MaxPower ? in composite_resume()
2650 cdev->config->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW; in composite_resume()
2651 if (gadget->speed < USB_SPEED_SUPER) in composite_resume()
2657 !(cdev->config->bmAttributes & USB_CONFIG_ATT_SELFPOWER)) in composite_resume()
2669 cdev->suspended = 0; in composite_resume()
2672 /*-------------------------------------------------------------------------*/
2691 * usb_composite_probe() - register a composite driver
2710 if (!driver || !driver->dev || !driver->bind) in usb_composite_probe()
2711 return -EINVAL; in usb_composite_probe()
2713 if (!driver->name) in usb_composite_probe()
2714 driver->name = "composite"; in usb_composite_probe()
2716 driver->gadget_driver = composite_driver_template; in usb_composite_probe()
2717 gadget_driver = &driver->gadget_driver; in usb_composite_probe()
2719 gadget_driver->function = (char *) driver->name; in usb_composite_probe()
2720 gadget_driver->driver.name = driver->name; in usb_composite_probe()
2721 gadget_driver->max_speed = driver->max_speed; in usb_composite_probe()
2728 * usb_composite_unregister() - unregister a composite driver
2736 usb_gadget_unregister_driver(&driver->gadget_driver); in usb_composite_unregister()
2741 * usb_composite_setup_continue() - Continue with the control transfer
2753 struct usb_request *req = cdev->req; in usb_composite_setup_continue()
2757 spin_lock_irqsave(&cdev->lock, flags); in usb_composite_setup_continue()
2759 if (cdev->delayed_status == 0) { in usb_composite_setup_continue()
2762 } else if (--cdev->delayed_status == 0) { in usb_composite_setup_continue()
2764 req->length = 0; in usb_composite_setup_continue()
2765 req->context = cdev; in usb_composite_setup_continue()
2768 DBG(cdev, "ep_queue --> %d\n", value); in usb_composite_setup_continue()
2769 req->status = 0; in usb_composite_setup_continue()
2770 composite_setup_complete(cdev->gadget->ep0, req); in usb_composite_setup_continue()
2774 spin_unlock_irqrestore(&cdev->lock, flags); in usb_composite_setup_continue()
2780 return kasprintf(GFP_KERNEL, "%s %s with %s", init_utsname()->sysname, in composite_default_mfr()
2781 init_utsname()->release, gadget->name); in composite_default_mfr()
2787 struct usb_device_descriptor *desc = &cdev->desc; in usb_composite_overwrite_options()
2788 struct usb_gadget_strings *gstr = cdev->driver->strings[0]; in usb_composite_overwrite_options()
2789 struct usb_string *dev_str = gstr->strings; in usb_composite_overwrite_options()
2791 if (covr->idVendor) in usb_composite_overwrite_options()
2792 desc->idVendor = cpu_to_le16(covr->idVendor); in usb_composite_overwrite_options()
2794 if (covr->idProduct) in usb_composite_overwrite_options()
2795 desc->idProduct = cpu_to_le16(covr->idProduct); in usb_composite_overwrite_options()
2797 if (covr->bcdDevice) in usb_composite_overwrite_options()
2798 desc->bcdDevice = cpu_to_le16(covr->bcdDevice); in usb_composite_overwrite_options()
2800 if (covr->serial_number) { in usb_composite_overwrite_options()
2801 desc->iSerialNumber = dev_str[USB_GADGET_SERIAL_IDX].id; in usb_composite_overwrite_options()
2802 dev_str[USB_GADGET_SERIAL_IDX].s = covr->serial_number; in usb_composite_overwrite_options()
2804 if (covr->manufacturer) { in usb_composite_overwrite_options()
2805 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id; in usb_composite_overwrite_options()
2806 dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer; in usb_composite_overwrite_options()
2809 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id; in usb_composite_overwrite_options()
2810 cdev->def_manufacturer = composite_default_mfr(cdev->gadget); in usb_composite_overwrite_options()
2811 dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer; in usb_composite_overwrite_options()
2814 if (covr->product) { in usb_composite_overwrite_options()
2815 desc->iProduct = dev_str[USB_GADGET_PRODUCT_IDX].id; in usb_composite_overwrite_options()
2816 dev_str[USB_GADGET_PRODUCT_IDX].s = covr->product; in usb_composite_overwrite_options()