Lines Matching +full:composite +full:- +full:in

1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/usb/composite.h>
24 return -EINVAL; in check_user_usb_string()
26 stringtab_dev->language = num; in check_user_usb_string()
47 struct usb_composite_driver composite; member
78 return container_of(cfg->c.cdev, struct gadget_info, cdev); in cfg_to_gadget_info()
110 return -EOVERFLOW; in usb_string_copy()
117 return -ENOMEM; in usb_string_copy()
120 if (str[ret - 1] == '\n') in usb_string_copy()
121 str[ret - 1] = '\0'; in usb_string_copy()
131 to_gadget_info(item)->cdev.desc.__name); \
139 le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \
152 to_gadget_info(item)->cdev.desc._name = val; \
165 to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \
185 return -EINVAL; in is_valid_bcd()
187 return -EINVAL; in is_valid_bcd()
189 return -EINVAL; in is_valid_bcd()
191 return -EINVAL; in is_valid_bcd()
208 to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); in gadget_dev_desc_bcdDevice_store()
225 to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); in gadget_dev_desc_bcdUSB_store()
235 mutex_lock(&gi->lock); in gadget_dev_desc_UDC_show()
236 udc_name = gi->composite.gadget_driver.udc_name; in gadget_dev_desc_UDC_show()
238 mutex_unlock(&gi->lock); in gadget_dev_desc_UDC_show()
247 if (!gi->composite.gadget_driver.udc_name) in unregister_gadget()
248 return -ENODEV; in unregister_gadget()
250 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver); in unregister_gadget()
253 kfree(gi->composite.gadget_driver.udc_name); in unregister_gadget()
254 gi->composite.gadget_driver.udc_name = NULL; in unregister_gadget()
266 return -EOVERFLOW; in gadget_dev_desc_UDC_store()
270 return -ENOMEM; in gadget_dev_desc_UDC_store()
271 if (name[len - 1] == '\n') in gadget_dev_desc_UDC_store()
272 name[len - 1] = '\0'; in gadget_dev_desc_UDC_store()
274 mutex_lock(&gi->lock); in gadget_dev_desc_UDC_store()
282 if (gi->composite.gadget_driver.udc_name) { in gadget_dev_desc_UDC_store()
283 ret = -EBUSY; in gadget_dev_desc_UDC_store()
286 gi->composite.gadget_driver.udc_name = name; in gadget_dev_desc_UDC_store()
287 ret = usb_gadget_register_driver(&gi->composite.gadget_driver); in gadget_dev_desc_UDC_store()
289 gi->composite.gadget_driver.udc_name = NULL; in gadget_dev_desc_UDC_store()
293 mutex_unlock(&gi->lock); in gadget_dev_desc_UDC_store()
297 mutex_unlock(&gi->lock); in gadget_dev_desc_UDC_store()
304 enum usb_device_speed speed = to_gadget_info(item)->composite.max_speed; in gadget_dev_desc_max_speed_show()
314 mutex_lock(&gi->lock); in gadget_dev_desc_max_speed_store()
317 if (gi->composite.gadget_driver.udc_name) in gadget_dev_desc_max_speed_store()
320 if (strncmp(page, "super-speed-plus", 16) == 0) in gadget_dev_desc_max_speed_store()
321 gi->composite.max_speed = USB_SPEED_SUPER_PLUS; in gadget_dev_desc_max_speed_store()
322 else if (strncmp(page, "super-speed", 11) == 0) in gadget_dev_desc_max_speed_store()
323 gi->composite.max_speed = USB_SPEED_SUPER; in gadget_dev_desc_max_speed_store()
324 else if (strncmp(page, "high-speed", 10) == 0) in gadget_dev_desc_max_speed_store()
325 gi->composite.max_speed = USB_SPEED_HIGH; in gadget_dev_desc_max_speed_store()
326 else if (strncmp(page, "full-speed", 10) == 0) in gadget_dev_desc_max_speed_store()
327 gi->composite.max_speed = USB_SPEED_FULL; in gadget_dev_desc_max_speed_store()
328 else if (strncmp(page, "low-speed", 9) == 0) in gadget_dev_desc_max_speed_store()
329 gi->composite.max_speed = USB_SPEED_LOW; in gadget_dev_desc_max_speed_store()
333 gi->composite.gadget_driver.max_speed = gi->composite.max_speed; in gadget_dev_desc_max_speed_store()
335 mutex_unlock(&gi->lock); in gadget_dev_desc_max_speed_store()
338 mutex_unlock(&gi->lock); in gadget_dev_desc_max_speed_store()
339 return -EINVAL; in gadget_dev_desc_max_speed_store()
391 WARN_ON(!list_empty(&gi->cdev.configs)); in gadget_info_attr_release()
392 WARN_ON(!list_empty(&gi->string_list)); in gadget_info_attr_release()
393 WARN_ON(!list_empty(&gi->available_func)); in gadget_info_attr_release()
394 kfree(gi->composite.gadget_driver.function); in gadget_info_attr_release()
406 WARN_ON(!list_empty(&cfg->c.functions)); in gadget_config_attr_release()
407 list_del(&cfg->c.list); in gadget_config_attr_release()
408 kfree(cfg->c.label); in gadget_config_attr_release()
425 mutex_lock(&gi->lock); in config_usb_cfg_link()
431 list_for_each_entry(iter, &gi->available_func, cfs_list) { in config_usb_cfg_link()
438 ret = -EINVAL; in config_usb_cfg_link()
442 list_for_each_entry(f, &cfg->func_list, list) { in config_usb_cfg_link()
443 if (f->fi == fi) { in config_usb_cfg_link()
444 ret = -EEXIST; in config_usb_cfg_link()
456 list_add_tail(&f->list, &cfg->func_list); in config_usb_cfg_link()
459 mutex_unlock(&gi->lock); in config_usb_cfg_link()
480 mutex_lock(&gi->lock); in config_usb_cfg_unlink()
481 if (gi->composite.gadget_driver.udc_name) in config_usb_cfg_unlink()
483 WARN_ON(gi->composite.gadget_driver.udc_name); in config_usb_cfg_unlink()
485 list_for_each_entry(f, &cfg->func_list, list) { in config_usb_cfg_unlink()
486 if (f->fi == fi) { in config_usb_cfg_unlink()
487 list_del(&f->list); in config_usb_cfg_unlink()
489 mutex_unlock(&gi->lock); in config_usb_cfg_unlink()
493 mutex_unlock(&gi->lock); in config_usb_cfg_unlink()
509 return sprintf(page, "%u\n", cfg->c.MaxPower); in gadget_config_desc_MaxPower_show()
522 return -ERANGE; in gadget_config_desc_MaxPower_store()
523 cfg->c.MaxPower = val; in gadget_config_desc_MaxPower_store()
532 return sprintf(page, "0x%02x\n", cfg->c.bmAttributes); in gadget_config_desc_bmAttributes_show()
545 return -EINVAL; in gadget_config_desc_bmAttributes_store()
548 return -EINVAL; in gadget_config_desc_bmAttributes_store()
549 cfg->c.bmAttributes = val; in gadget_config_desc_bmAttributes_store()
576 spin_lock_init(&cdev->lock); in composite_init_dev()
577 INIT_LIST_HEAD(&cdev->configs); in composite_init_dev()
578 INIT_LIST_HEAD(&cdev->gstrings); in composite_init_dev()
594 return ERR_PTR(-ENAMETOOLONG); in function_make()
599 pr_err("Unable to locate . in FUNC.INSTANCE\n"); in function_make()
600 return ERR_PTR(-EINVAL); in function_make()
609 ret = config_item_set_name(&fi->group.cg_item, "%s", name); in function_make()
614 if (fi->set_inst_name) { in function_make()
615 ret = fi->set_inst_name(fi, instance_name); in function_make()
624 mutex_lock(&gi->lock); in function_make()
625 list_add_tail(&fi->cfs_list, &gi->available_func); in function_make()
626 mutex_unlock(&gi->lock); in function_make()
627 return &fi->group; in function_make()
639 mutex_lock(&gi->lock); in function_drop()
640 list_del(&fi->cfs_list); in function_drop()
641 mutex_unlock(&gi->lock); in function_drop()
666 kfree(cn->configuration); in gadget_config_name_attr_release()
668 list_del(&cn->list); in gadget_config_name_attr_release()
689 return ERR_PTR(-ENAMETOOLONG); in config_desc_make()
693 pr_err("Unable to locate . in name.bConfigurationValue\n"); in config_desc_make()
694 return ERR_PTR(-EINVAL); in config_desc_make()
701 return ERR_PTR(-EINVAL); in config_desc_make()
709 return ERR_PTR(-ENOMEM); in config_desc_make()
710 cfg->c.label = kstrdup(buf, GFP_KERNEL); in config_desc_make()
711 if (!cfg->c.label) { in config_desc_make()
712 ret = -ENOMEM; in config_desc_make()
715 cfg->c.bConfigurationValue = num; in config_desc_make()
716 cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW; in config_desc_make()
717 cfg->c.bmAttributes = USB_CONFIG_ATT_ONE; in config_desc_make()
718 INIT_LIST_HEAD(&cfg->string_list); in config_desc_make()
719 INIT_LIST_HEAD(&cfg->func_list); in config_desc_make()
721 config_group_init_type_name(&cfg->group, name, in config_desc_make()
724 config_group_init_type_name(&cfg->strings_group, "strings", in config_desc_make()
726 configfs_add_default_group(&cfg->strings_group, &cfg->group); in config_desc_make()
728 ret = usb_add_config_only(&gi->cdev, &cfg->c); in config_desc_make()
732 return &cfg->group; in config_desc_make()
734 kfree(cfg->c.label); in config_desc_make()
771 kfree(gs->manufacturer); in gadget_strings_attr_release()
772 kfree(gs->product); in gadget_strings_attr_release()
773 kfree(gs->serialnumber); in gadget_strings_attr_release()
775 list_del(&gs->list); in gadget_strings_attr_release()
792 os_desc_item_to_gadget_info(item)->use_os_desc); in os_desc_use_show()
802 mutex_lock(&gi->lock); in os_desc_use_store()
805 gi->use_os_desc = use; in os_desc_use_store()
808 mutex_unlock(&gi->lock); in os_desc_use_store()
816 os_desc_item_to_gadget_info(item)->b_vendor_code); in os_desc_b_vendor_code_show()
826 mutex_lock(&gi->lock); in os_desc_b_vendor_code_store()
829 gi->b_vendor_code = b_vendor_code; in os_desc_b_vendor_code_store()
832 mutex_unlock(&gi->lock); in os_desc_b_vendor_code_store()
842 res = utf16s_to_utf8s((wchar_t *) gi->qw_sign, OS_STRING_QW_SIGN_LEN, in os_desc_qw_sign_show()
843 UTF16_LITTLE_ENDIAN, page, PAGE_SIZE - 1); in os_desc_qw_sign_show()
856 if (page[l - 1] == '\n') in os_desc_qw_sign_store()
857 --l; in os_desc_qw_sign_store()
859 mutex_lock(&gi->lock); in os_desc_qw_sign_store()
861 UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign, in os_desc_qw_sign_store()
865 mutex_unlock(&gi->lock); in os_desc_qw_sign_store()
885 struct usb_composite_dev *cdev = &gi->cdev; in os_desc_link()
890 mutex_lock(&gi->lock); in os_desc_link()
891 list_for_each_entry(iter, &cdev->configs, list) { in os_desc_link()
892 if (iter != &c_target->c) in os_desc_link()
898 ret = -EINVAL; in os_desc_link()
902 if (cdev->os_desc_config) { in os_desc_link()
903 ret = -EBUSY; in os_desc_link()
907 cdev->os_desc_config = &c_target->c; in os_desc_link()
911 mutex_unlock(&gi->lock); in os_desc_link()
919 struct usb_composite_dev *cdev = &gi->cdev; in os_desc_unlink()
921 mutex_lock(&gi->lock); in os_desc_unlink()
922 if (gi->composite.gadget_driver.udc_name) in os_desc_unlink()
924 cdev->os_desc_config = NULL; in os_desc_unlink()
925 WARN_ON(gi->composite.gadget_driver.udc_name); in os_desc_unlink()
926 mutex_unlock(&gi->lock); in os_desc_unlink()
948 return sprintf(page, "%d\n", to_usb_os_desc_ext_prop(item)->type); in ext_prop_type_show()
955 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); in ext_prop_type_store()
959 if (desc->opts_mutex) in ext_prop_type_store()
960 mutex_lock(desc->opts_mutex); in ext_prop_type_store()
965 ret = -EINVAL; in ext_prop_type_store()
969 if ((ext_prop->type == USB_EXT_PROP_BINARY || in ext_prop_type_store()
970 ext_prop->type == USB_EXT_PROP_LE32 || in ext_prop_type_store()
971 ext_prop->type == USB_EXT_PROP_BE32) && in ext_prop_type_store()
975 ext_prop->data_len <<= 1; in ext_prop_type_store()
976 else if ((ext_prop->type == USB_EXT_PROP_UNICODE || in ext_prop_type_store()
977 ext_prop->type == USB_EXT_PROP_UNICODE_ENV || in ext_prop_type_store()
978 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) && in ext_prop_type_store()
982 ext_prop->data_len >>= 1; in ext_prop_type_store()
983 ext_prop->type = type; in ext_prop_type_store()
987 if (desc->opts_mutex) in ext_prop_type_store()
988 mutex_unlock(desc->opts_mutex); in ext_prop_type_store()
995 int len = ext_prop->data_len; in ext_prop_data_show()
997 if (ext_prop->type == USB_EXT_PROP_UNICODE || in ext_prop_data_show()
998 ext_prop->type == USB_EXT_PROP_UNICODE_ENV || in ext_prop_data_show()
999 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) in ext_prop_data_show()
1001 memcpy(page, ext_prop->data, len); in ext_prop_data_show()
1010 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); in ext_prop_data_store()
1014 if (page[len - 1] == '\n' || page[len - 1] == '\0') in ext_prop_data_store()
1015 --len; in ext_prop_data_store()
1018 return -ENOMEM; in ext_prop_data_store()
1020 if (desc->opts_mutex) in ext_prop_data_store()
1021 mutex_lock(desc->opts_mutex); in ext_prop_data_store()
1022 kfree(ext_prop->data); in ext_prop_data_store()
1023 ext_prop->data = new_data; in ext_prop_data_store()
1024 desc->ext_prop_len -= ext_prop->data_len; in ext_prop_data_store()
1025 ext_prop->data_len = len; in ext_prop_data_store()
1026 desc->ext_prop_len += ext_prop->data_len; in ext_prop_data_store()
1027 if (ext_prop->type == USB_EXT_PROP_UNICODE || in ext_prop_data_store()
1028 ext_prop->type == USB_EXT_PROP_UNICODE_ENV || in ext_prop_data_store()
1029 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) { in ext_prop_data_store()
1030 desc->ext_prop_len -= ext_prop->data_len; in ext_prop_data_store()
1031 ext_prop->data_len <<= 1; in ext_prop_data_store()
1032 ext_prop->data_len += 2; in ext_prop_data_store()
1033 desc->ext_prop_len += ext_prop->data_len; in ext_prop_data_store()
1035 if (desc->opts_mutex) in ext_prop_data_store()
1036 mutex_unlock(desc->opts_mutex); in ext_prop_data_store()
1075 return ERR_PTR(-ENOMEM); in ext_prop_make()
1081 ext_prop_type->ct_item_ops = &ext_prop_ops; in ext_prop_make()
1082 ext_prop_type->ct_attrs = ext_prop_attrs; in ext_prop_make()
1083 ext_prop_type->ct_owner = desc->owner; in ext_prop_make()
1085 config_item_init_type_name(&ext_prop->item, name, ext_prop_type); in ext_prop_make()
1087 ext_prop->name = kstrdup(name, GFP_KERNEL); in ext_prop_make()
1088 if (!ext_prop->name) { in ext_prop_make()
1090 return ERR_PTR(-ENOMEM); in ext_prop_make()
1092 desc->ext_prop_len += 14; in ext_prop_make()
1093 ext_prop->name_len = 2 * strlen(ext_prop->name) + 2; in ext_prop_make()
1094 if (desc->opts_mutex) in ext_prop_make()
1095 mutex_lock(desc->opts_mutex); in ext_prop_make()
1096 desc->ext_prop_len += ext_prop->name_len; in ext_prop_make()
1097 list_add_tail(&ext_prop->entry, &desc->ext_prop); in ext_prop_make()
1098 ++desc->ext_prop_count; in ext_prop_make()
1099 if (desc->opts_mutex) in ext_prop_make()
1100 mutex_unlock(desc->opts_mutex); in ext_prop_make()
1102 return &ext_prop->item; in ext_prop_make()
1108 struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item); in ext_prop_drop()
1110 if (desc->opts_mutex) in ext_prop_drop()
1111 mutex_lock(desc->opts_mutex); in ext_prop_drop()
1112 list_del(&ext_prop->entry); in ext_prop_drop()
1113 --desc->ext_prop_count; in ext_prop_drop()
1114 kfree(ext_prop->name); in ext_prop_drop()
1115 desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14); in ext_prop_drop()
1116 if (desc->opts_mutex) in ext_prop_drop()
1117 mutex_unlock(desc->opts_mutex); in ext_prop_drop()
1129 memcpy(page, to_usb_os_desc(item)->ext_compat_id, 8); in interf_grp_compatible_id_show()
1140 if (page[l - 1] == '\n') in interf_grp_compatible_id_store()
1141 --l; in interf_grp_compatible_id_store()
1142 if (desc->opts_mutex) in interf_grp_compatible_id_store()
1143 mutex_lock(desc->opts_mutex); in interf_grp_compatible_id_store()
1144 memcpy(desc->ext_compat_id, page, l); in interf_grp_compatible_id_store()
1146 if (desc->opts_mutex) in interf_grp_compatible_id_store()
1147 mutex_unlock(desc->opts_mutex); in interf_grp_compatible_id_store()
1155 memcpy(page, to_usb_os_desc(item)->ext_compat_id + 8, 8); in interf_grp_sub_compatible_id_show()
1166 if (page[l - 1] == '\n') in interf_grp_sub_compatible_id_store()
1167 --l; in interf_grp_sub_compatible_id_store()
1168 if (desc->opts_mutex) in interf_grp_sub_compatible_id_store()
1169 mutex_lock(desc->opts_mutex); in interf_grp_sub_compatible_id_store()
1170 memcpy(desc->ext_compat_id + 8, page, l); in interf_grp_sub_compatible_id_store()
1172 if (desc->opts_mutex) in interf_grp_sub_compatible_id_store()
1173 mutex_unlock(desc->opts_mutex); in interf_grp_sub_compatible_id_store()
1204 return ERR_PTR(-ENOMEM); in usb_os_desc_prepare_interf_dir()
1210 os_desc_type->ct_owner = owner; in usb_os_desc_prepare_interf_dir()
1214 interface_type->ct_group_ops = &interf_grp_ops; in usb_os_desc_prepare_interf_dir()
1215 interface_type->ct_attrs = interf_grp_attrs; in usb_os_desc_prepare_interf_dir()
1216 interface_type->ct_owner = owner; in usb_os_desc_prepare_interf_dir()
1218 while (n_interf--) { in usb_os_desc_prepare_interf_dir()
1222 d->owner = owner; in usb_os_desc_prepare_interf_dir()
1223 config_group_init_type_name(&d->group, "", interface_type); in usb_os_desc_prepare_interf_dir()
1224 config_item_set_name(&d->group.cg_item, "interface.%s", in usb_os_desc_prepare_interf_dir()
1226 configfs_add_default_group(&d->group, os_desc_group); in usb_os_desc_prepare_interf_dir()
1236 return -EINVAL; in configfs_do_nothing()
1239 int composite_dev_prepare(struct usb_composite_driver *composite,
1249 list_for_each_entry(c, &gi->cdev.configs, list) { in purge_configs_funcs()
1255 list_for_each_entry_safe_reverse(f, tmp, &c->functions, list) { in purge_configs_funcs()
1257 list_move(&f->list, &cfg->func_list); in purge_configs_funcs()
1258 if (f->unbind) { in purge_configs_funcs()
1259 dev_dbg(&gi->cdev.gadget->dev, in purge_configs_funcs()
1261 f->name, f); in purge_configs_funcs()
1262 f->unbind(c, f); in purge_configs_funcs()
1265 c->next_interface_id = 0; in purge_configs_funcs()
1266 memset(c->interface, 0, sizeof(c->interface)); in purge_configs_funcs()
1267 c->superspeed_plus = 0; in purge_configs_funcs()
1268 c->superspeed = 0; in purge_configs_funcs()
1269 c->highspeed = 0; in purge_configs_funcs()
1270 c->fullspeed = 0; in purge_configs_funcs()
1277 struct usb_composite_driver *composite = to_cdriver(gdriver); in configfs_composite_bind() local
1278 struct gadget_info *gi = container_of(composite, in configfs_composite_bind()
1279 struct gadget_info, composite); in configfs_composite_bind()
1280 struct usb_composite_dev *cdev = &gi->cdev; in configfs_composite_bind()
1286 /* the gi->lock is hold by the caller */ in configfs_composite_bind()
1287 gi->unbind = 0; in configfs_composite_bind()
1288 cdev->gadget = gadget; in configfs_composite_bind()
1290 ret = composite_dev_prepare(composite, cdev); in configfs_composite_bind()
1294 ret = -EINVAL; in configfs_composite_bind()
1296 if (list_empty(&gi->cdev.configs)) { in configfs_composite_bind()
1297 pr_err("Need at least one configuration in %s.\n", in configfs_composite_bind()
1298 gi->composite.name); in configfs_composite_bind()
1303 list_for_each_entry(c, &gi->cdev.configs, list) { in configfs_composite_bind()
1307 if (list_empty(&cfg->func_list)) { in configfs_composite_bind()
1309 c->label, c->bConfigurationValue, in configfs_composite_bind()
1310 gi->composite.name); in configfs_composite_bind()
1316 if (!list_empty(&gi->string_list)) { in configfs_composite_bind()
1320 list_for_each_entry(gs, &gi->string_list, list) { in configfs_composite_bind()
1322 gi->gstrings[i] = &gs->stringtab_dev; in configfs_composite_bind()
1323 gs->stringtab_dev.strings = gs->strings; in configfs_composite_bind()
1324 gs->strings[USB_GADGET_MANUFACTURER_IDX].s = in configfs_composite_bind()
1325 gs->manufacturer; in configfs_composite_bind()
1326 gs->strings[USB_GADGET_PRODUCT_IDX].s = gs->product; in configfs_composite_bind()
1327 gs->strings[USB_GADGET_SERIAL_IDX].s = gs->serialnumber; in configfs_composite_bind()
1330 gi->gstrings[i] = NULL; in configfs_composite_bind()
1331 s = usb_gstrings_attach(&gi->cdev, gi->gstrings, in configfs_composite_bind()
1338 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id; in configfs_composite_bind()
1339 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id; in configfs_composite_bind()
1340 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id; in configfs_composite_bind()
1343 if (gi->use_os_desc) { in configfs_composite_bind()
1344 cdev->use_os_string = true; in configfs_composite_bind()
1345 cdev->b_vendor_code = gi->b_vendor_code; in configfs_composite_bind()
1346 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN); in configfs_composite_bind()
1354 ret = -ENOMEM; in configfs_composite_bind()
1363 list_for_each_entry(c, &gi->cdev.configs, list) { in configfs_composite_bind()
1370 c->descriptors = otg_desc; in configfs_composite_bind()
1373 if (!list_empty(&cfg->string_list)) { in configfs_composite_bind()
1375 list_for_each_entry(cn, &cfg->string_list, list) { in configfs_composite_bind()
1376 cfg->gstrings[i] = &cn->stringtab_dev; in configfs_composite_bind()
1377 cn->stringtab_dev.strings = &cn->strings; in configfs_composite_bind()
1378 cn->strings.s = cn->configuration; in configfs_composite_bind()
1381 cfg->gstrings[i] = NULL; in configfs_composite_bind()
1382 s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1); in configfs_composite_bind()
1387 c->iConfiguration = s[0].id; in configfs_composite_bind()
1390 list_for_each_entry_safe(f, tmp, &cfg->func_list, list) { in configfs_composite_bind()
1391 list_del(&f->list); in configfs_composite_bind()
1394 list_add(&f->list, &cfg->func_list); in configfs_composite_bind()
1398 ret = usb_gadget_check_config(cdev->gadget); in configfs_composite_bind()
1402 usb_ep_autoconfig_reset(cdev->gadget); in configfs_composite_bind()
1404 if (cdev->use_os_string) { in configfs_composite_bind()
1405 ret = composite_os_desc_req_prepare(cdev, gadget->ep0); in configfs_composite_bind()
1410 usb_ep_autoconfig_reset(cdev->gadget); in configfs_composite_bind()
1426 /* the gi->lock is hold by the caller */ in configfs_composite_unbind()
1430 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_unbind()
1431 gi->unbind = 1; in configfs_composite_unbind()
1432 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_unbind()
1438 usb_ep_autoconfig_reset(cdev->gadget); in configfs_composite_unbind()
1439 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_unbind()
1440 cdev->gadget = NULL; in configfs_composite_unbind()
1441 cdev->deactivations = 0; in configfs_composite_unbind()
1442 gadget->deactivated = false; in configfs_composite_unbind()
1444 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_unbind()
1460 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_setup()
1462 if (!cdev || gi->unbind) { in configfs_composite_setup()
1463 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_setup()
1468 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_setup()
1483 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_disconnect()
1485 if (!cdev || gi->unbind) { in configfs_composite_disconnect()
1486 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_disconnect()
1491 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_disconnect()
1505 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_reset()
1507 if (!cdev || gi->unbind) { in configfs_composite_reset()
1508 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_reset()
1513 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_reset()
1527 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_suspend()
1529 if (!cdev || gi->unbind) { in configfs_composite_suspend()
1530 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_suspend()
1535 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_suspend()
1549 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_resume()
1551 if (!cdev || gi->unbind) { in configfs_composite_resume()
1552 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_resume()
1557 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_resume()
1574 .name = "configfs-gadget",
1587 return ERR_PTR(-ENOMEM); in gadgets_make()
1589 config_group_init_type_name(&gi->group, name, &gadget_root_type); in gadgets_make()
1591 config_group_init_type_name(&gi->functions_group, "functions", in gadgets_make()
1593 configfs_add_default_group(&gi->functions_group, &gi->group); in gadgets_make()
1595 config_group_init_type_name(&gi->configs_group, "configs", in gadgets_make()
1597 configfs_add_default_group(&gi->configs_group, &gi->group); in gadgets_make()
1599 config_group_init_type_name(&gi->strings_group, "strings", in gadgets_make()
1601 configfs_add_default_group(&gi->strings_group, &gi->group); in gadgets_make()
1603 config_group_init_type_name(&gi->os_desc_group, "os_desc", in gadgets_make()
1605 configfs_add_default_group(&gi->os_desc_group, &gi->group); in gadgets_make()
1607 gi->composite.bind = configfs_do_nothing; in gadgets_make()
1608 gi->composite.unbind = configfs_do_nothing; in gadgets_make()
1609 gi->composite.suspend = NULL; in gadgets_make()
1610 gi->composite.resume = NULL; in gadgets_make()
1611 gi->composite.max_speed = USB_SPEED_SUPER_PLUS; in gadgets_make()
1613 spin_lock_init(&gi->spinlock); in gadgets_make()
1614 mutex_init(&gi->lock); in gadgets_make()
1615 INIT_LIST_HEAD(&gi->string_list); in gadgets_make()
1616 INIT_LIST_HEAD(&gi->available_func); in gadgets_make()
1618 composite_init_dev(&gi->cdev); in gadgets_make()
1619 gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE; in gadgets_make()
1620 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE; in gadgets_make()
1621 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice()); in gadgets_make()
1623 gi->composite.gadget_driver = configfs_driver_template; in gadgets_make()
1625 gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); in gadgets_make()
1626 gi->composite.name = gi->composite.gadget_driver.function; in gadgets_make()
1628 if (!gi->composite.gadget_driver.function) in gadgets_make()
1631 return &gi->group; in gadgets_make()
1634 return ERR_PTR(-ENOMEM); in gadgets_make()
1666 mutex_lock(&gi->lock); in unregister_gadget_item()
1668 mutex_unlock(&gi->lock); in unregister_gadget_item()