1 #include <linux/configfs.h>
2 #include <linux/module.h>
3 #include <linux/slab.h>
4 #include <linux/device.h>
6 #include <linux/usb/composite.h>
7 #include <linux/usb/gadget_configfs.h>
10 #include "u_os_desc.h"
12 #ifdef CONFIG_USB_CONFIGFS_UEVENT
13 #include <linux/platform_device.h>
14 #include <linux/kdev_t.h>
15 #include <linux/usb/ch9.h>
17 #ifdef CONFIG_USB_CONFIGFS_F_ACC
18 extern int acc_ctrlrequest(struct usb_composite_dev *cdev,
19 const struct usb_ctrlrequest *ctrl);
20 void acc_disconnect(void);
22 static struct class *android_class;
23 static struct device *android_device;
26 struct device *create_function_device(char *name)
28 if (android_device && !IS_ERR(android_device))
29 return device_create(android_class, android_device,
30 MKDEV(0, index++), NULL, name);
32 return ERR_PTR(-EINVAL);
34 EXPORT_SYMBOL_GPL(create_function_device);
37 int check_user_usb_string(const char *name,
38 struct usb_gadget_strings *stringtab_dev)
40 unsigned primary_lang;
45 ret = kstrtou16(name, 0, &num);
49 primary_lang = num & 0x3ff;
52 /* simple sanity check for valid langid */
53 switch (primary_lang) {
62 stringtab_dev->language = num;
66 #define MAX_NAME_LEN 40
67 #define MAX_USB_STRING_LANGS 2
69 static const struct usb_descriptor_header *otg_desc[2];
72 struct config_group group;
73 struct config_group functions_group;
74 struct config_group configs_group;
75 struct config_group strings_group;
76 struct config_group os_desc_group;
77 struct config_group *default_groups[5];
80 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
81 struct list_head string_list;
82 struct list_head available_func;
85 struct usb_composite_driver composite;
86 struct usb_composite_dev cdev;
89 char qw_sign[OS_STRING_QW_SIGN_LEN];
90 #ifdef CONFIG_USB_CONFIGFS_UEVENT
93 struct work_struct work;
98 static inline struct gadget_info *to_gadget_info(struct config_item *item)
100 return container_of(to_config_group(item), struct gadget_info, group);
103 struct config_usb_cfg {
104 struct config_group group;
105 struct config_group strings_group;
106 struct config_group *default_groups[2];
107 struct list_head string_list;
108 struct usb_configuration c;
109 struct list_head func_list;
110 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
113 static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item)
115 return container_of(to_config_group(item), struct config_usb_cfg,
119 struct gadget_strings {
120 struct usb_gadget_strings stringtab_dev;
121 struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX];
126 struct config_group group;
127 struct list_head list;
131 struct config_group group;
134 struct gadget_config_name {
135 struct usb_gadget_strings stringtab_dev;
136 struct usb_string strings;
139 struct config_group group;
140 struct list_head list;
143 static int usb_string_copy(const char *s, char **s_copy)
147 char *copy = *s_copy;
152 str = kstrdup(s, GFP_KERNEL);
155 if (str[ret - 1] == '\n')
162 #define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \
163 static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \
166 return sprintf(page, "0x%02x\n", \
167 to_gadget_info(item)->cdev.desc.__name); \
170 #define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \
171 static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \
174 return sprintf(page, "0x%04x\n", \
175 le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \
179 #define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \
180 static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \
181 const char *page, size_t len) \
185 ret = kstrtou8(page, 0, &val); \
188 to_gadget_info(item)->cdev.desc._name = val; \
192 #define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \
193 static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \
194 const char *page, size_t len) \
198 ret = kstrtou16(page, 0, &val); \
201 to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \
205 #define GI_DEVICE_DESC_SIMPLE_RW(_name, _type) \
206 GI_DEVICE_DESC_SIMPLE_R_##_type(_name) \
207 GI_DEVICE_DESC_SIMPLE_W_##_type(_name)
209 GI_DEVICE_DESC_SIMPLE_R_u16(bcdUSB);
210 GI_DEVICE_DESC_SIMPLE_RW(bDeviceClass, u8);
211 GI_DEVICE_DESC_SIMPLE_RW(bDeviceSubClass, u8);
212 GI_DEVICE_DESC_SIMPLE_RW(bDeviceProtocol, u8);
213 GI_DEVICE_DESC_SIMPLE_RW(bMaxPacketSize0, u8);
214 GI_DEVICE_DESC_SIMPLE_RW(idVendor, u16);
215 GI_DEVICE_DESC_SIMPLE_RW(idProduct, u16);
216 GI_DEVICE_DESC_SIMPLE_R_u16(bcdDevice);
218 static ssize_t is_valid_bcd(u16 bcd_val)
220 if ((bcd_val & 0xf) > 9)
222 if (((bcd_val >> 4) & 0xf) > 9)
224 if (((bcd_val >> 8) & 0xf) > 9)
226 if (((bcd_val >> 12) & 0xf) > 9)
231 static ssize_t gadget_dev_desc_bcdDevice_store(struct config_item *item,
232 const char *page, size_t len)
237 ret = kstrtou16(page, 0, &bcdDevice);
240 ret = is_valid_bcd(bcdDevice);
244 to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice);
248 static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item,
249 const char *page, size_t len)
254 ret = kstrtou16(page, 0, &bcdUSB);
257 ret = is_valid_bcd(bcdUSB);
261 to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB);
265 static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page)
267 return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: "");
270 static int unregister_gadget(struct gadget_info *gi)
277 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
285 static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
286 const char *page, size_t len)
288 struct gadget_info *gi = to_gadget_info(item);
292 name = kstrdup(page, GFP_KERNEL);
295 if (name[len - 1] == '\n')
296 name[len - 1] = '\0';
298 mutex_lock(&gi->lock);
300 if (!strlen(name) || strcmp(name, "none") == 0) {
301 ret = unregister_gadget(gi);
309 ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver);
314 mutex_unlock(&gi->lock);
318 mutex_unlock(&gi->lock);
322 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass);
323 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass);
324 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol);
325 CONFIGFS_ATTR(gadget_dev_desc_, bMaxPacketSize0);
326 CONFIGFS_ATTR(gadget_dev_desc_, idVendor);
327 CONFIGFS_ATTR(gadget_dev_desc_, idProduct);
328 CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice);
329 CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB);
330 CONFIGFS_ATTR(gadget_dev_desc_, UDC);
332 static struct configfs_attribute *gadget_root_attrs[] = {
333 &gadget_dev_desc_attr_bDeviceClass,
334 &gadget_dev_desc_attr_bDeviceSubClass,
335 &gadget_dev_desc_attr_bDeviceProtocol,
336 &gadget_dev_desc_attr_bMaxPacketSize0,
337 &gadget_dev_desc_attr_idVendor,
338 &gadget_dev_desc_attr_idProduct,
339 &gadget_dev_desc_attr_bcdDevice,
340 &gadget_dev_desc_attr_bcdUSB,
341 &gadget_dev_desc_attr_UDC,
345 static inline struct gadget_strings *to_gadget_strings(struct config_item *item)
347 return container_of(to_config_group(item), struct gadget_strings,
351 static inline struct gadget_config_name *to_gadget_config_name(
352 struct config_item *item)
354 return container_of(to_config_group(item), struct gadget_config_name,
358 static inline struct usb_function_instance *to_usb_function_instance(
359 struct config_item *item)
361 return container_of(to_config_group(item),
362 struct usb_function_instance, group);
365 static void gadget_info_attr_release(struct config_item *item)
367 struct gadget_info *gi = to_gadget_info(item);
369 WARN_ON(!list_empty(&gi->cdev.configs));
370 WARN_ON(!list_empty(&gi->string_list));
371 WARN_ON(!list_empty(&gi->available_func));
372 kfree(gi->composite.gadget_driver.function);
376 static struct configfs_item_operations gadget_root_item_ops = {
377 .release = gadget_info_attr_release,
380 static void gadget_config_attr_release(struct config_item *item)
382 struct config_usb_cfg *cfg = to_config_usb_cfg(item);
384 WARN_ON(!list_empty(&cfg->c.functions));
385 list_del(&cfg->c.list);
390 static int config_usb_cfg_link(
391 struct config_item *usb_cfg_ci,
392 struct config_item *usb_func_ci)
394 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
395 struct usb_composite_dev *cdev = cfg->c.cdev;
396 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
398 struct config_group *group = to_config_group(usb_func_ci);
399 struct usb_function_instance *fi = container_of(group,
400 struct usb_function_instance, group);
401 struct usb_function_instance *a_fi;
402 struct usb_function *f;
405 mutex_lock(&gi->lock);
407 * Make sure this function is from within our _this_ gadget and not
408 * from another gadget or a random directory.
409 * Also a function instance can only be linked once.
411 list_for_each_entry(a_fi, &gi->available_func, cfs_list) {
420 list_for_each_entry(f, &cfg->func_list, list) {
427 f = usb_get_function(fi);
433 /* stash the function until we bind it to the gadget */
434 list_add_tail(&f->list, &cfg->func_list);
437 mutex_unlock(&gi->lock);
441 static int config_usb_cfg_unlink(
442 struct config_item *usb_cfg_ci,
443 struct config_item *usb_func_ci)
445 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
446 struct usb_composite_dev *cdev = cfg->c.cdev;
447 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
449 struct config_group *group = to_config_group(usb_func_ci);
450 struct usb_function_instance *fi = container_of(group,
451 struct usb_function_instance, group);
452 struct usb_function *f;
455 * ideally I would like to forbid to unlink functions while a gadget is
456 * bound to an UDC. Since this isn't possible at the moment, we simply
457 * force an unbind, the function is available here and then we can
458 * remove the function.
460 mutex_lock(&gi->lock);
462 unregister_gadget(gi);
463 WARN_ON(gi->udc_name);
465 list_for_each_entry(f, &cfg->func_list, list) {
469 mutex_unlock(&gi->lock);
473 mutex_unlock(&gi->lock);
474 WARN(1, "Unable to locate function to unbind\n");
478 static struct configfs_item_operations gadget_config_item_ops = {
479 .release = gadget_config_attr_release,
480 .allow_link = config_usb_cfg_link,
481 .drop_link = config_usb_cfg_unlink,
485 static ssize_t gadget_config_desc_MaxPower_show(struct config_item *item,
488 return sprintf(page, "%u\n", to_config_usb_cfg(item)->c.MaxPower);
491 static ssize_t gadget_config_desc_MaxPower_store(struct config_item *item,
492 const char *page, size_t len)
496 ret = kstrtou16(page, 0, &val);
499 if (DIV_ROUND_UP(val, 8) > 0xff)
501 to_config_usb_cfg(item)->c.MaxPower = val;
505 static ssize_t gadget_config_desc_bmAttributes_show(struct config_item *item,
508 return sprintf(page, "0x%02x\n",
509 to_config_usb_cfg(item)->c.bmAttributes);
512 static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item,
513 const char *page, size_t len)
517 ret = kstrtou8(page, 0, &val);
520 if (!(val & USB_CONFIG_ATT_ONE))
522 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER |
523 USB_CONFIG_ATT_WAKEUP))
525 to_config_usb_cfg(item)->c.bmAttributes = val;
529 CONFIGFS_ATTR(gadget_config_desc_, MaxPower);
530 CONFIGFS_ATTR(gadget_config_desc_, bmAttributes);
532 static struct configfs_attribute *gadget_config_attrs[] = {
533 &gadget_config_desc_attr_MaxPower,
534 &gadget_config_desc_attr_bmAttributes,
538 static struct config_item_type gadget_config_type = {
539 .ct_item_ops = &gadget_config_item_ops,
540 .ct_attrs = gadget_config_attrs,
541 .ct_owner = THIS_MODULE,
544 static struct config_item_type gadget_root_type = {
545 .ct_item_ops = &gadget_root_item_ops,
546 .ct_attrs = gadget_root_attrs,
547 .ct_owner = THIS_MODULE,
550 static void composite_init_dev(struct usb_composite_dev *cdev)
552 spin_lock_init(&cdev->lock);
553 INIT_LIST_HEAD(&cdev->configs);
554 INIT_LIST_HEAD(&cdev->gstrings);
557 static struct config_group *function_make(
558 struct config_group *group,
561 struct gadget_info *gi;
562 struct usb_function_instance *fi;
563 char buf[MAX_NAME_LEN];
568 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
569 if (ret >= MAX_NAME_LEN)
570 return ERR_PTR(-ENAMETOOLONG);
573 instance_name = strchr(func_name, '.');
574 if (!instance_name) {
575 pr_err("Unable to locate . in FUNC.INSTANCE\n");
576 return ERR_PTR(-EINVAL);
578 *instance_name = '\0';
581 fi = usb_get_function_instance(func_name);
585 ret = config_item_set_name(&fi->group.cg_item, "%s", name);
587 usb_put_function_instance(fi);
590 if (fi->set_inst_name) {
591 ret = fi->set_inst_name(fi, instance_name);
593 usb_put_function_instance(fi);
598 gi = container_of(group, struct gadget_info, functions_group);
600 mutex_lock(&gi->lock);
601 list_add_tail(&fi->cfs_list, &gi->available_func);
602 mutex_unlock(&gi->lock);
606 static void function_drop(
607 struct config_group *group,
608 struct config_item *item)
610 struct usb_function_instance *fi = to_usb_function_instance(item);
611 struct gadget_info *gi;
613 gi = container_of(group, struct gadget_info, functions_group);
615 mutex_lock(&gi->lock);
616 list_del(&fi->cfs_list);
617 mutex_unlock(&gi->lock);
618 config_item_put(item);
621 static struct configfs_group_operations functions_ops = {
622 .make_group = &function_make,
623 .drop_item = &function_drop,
626 static struct config_item_type functions_type = {
627 .ct_group_ops = &functions_ops,
628 .ct_owner = THIS_MODULE,
631 GS_STRINGS_RW(gadget_config_name, configuration);
633 static struct configfs_attribute *gadget_config_name_langid_attrs[] = {
634 &gadget_config_name_attr_configuration,
638 static void gadget_config_name_attr_release(struct config_item *item)
640 struct gadget_config_name *cn = to_gadget_config_name(item);
642 kfree(cn->configuration);
648 USB_CONFIG_STRING_RW_OPS(gadget_config_name);
649 USB_CONFIG_STRINGS_LANG(gadget_config_name, config_usb_cfg);
651 static struct config_group *config_desc_make(
652 struct config_group *group,
655 struct gadget_info *gi;
656 struct config_usb_cfg *cfg;
657 char buf[MAX_NAME_LEN];
662 gi = container_of(group, struct gadget_info, configs_group);
663 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
664 if (ret >= MAX_NAME_LEN)
665 return ERR_PTR(-ENAMETOOLONG);
667 num_str = strchr(buf, '.');
669 pr_err("Unable to locate . in name.bConfigurationValue\n");
670 return ERR_PTR(-EINVAL);
677 return ERR_PTR(-EINVAL);
679 ret = kstrtou8(num_str, 0, &num);
683 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
685 return ERR_PTR(-ENOMEM);
686 cfg->c.label = kstrdup(buf, GFP_KERNEL);
691 cfg->c.bConfigurationValue = num;
692 cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW;
693 cfg->c.bmAttributes = USB_CONFIG_ATT_ONE;
694 INIT_LIST_HEAD(&cfg->string_list);
695 INIT_LIST_HEAD(&cfg->func_list);
697 cfg->group.default_groups = cfg->default_groups;
698 cfg->default_groups[0] = &cfg->strings_group;
700 config_group_init_type_name(&cfg->group, name,
701 &gadget_config_type);
702 config_group_init_type_name(&cfg->strings_group, "strings",
703 &gadget_config_name_strings_type);
705 ret = usb_add_config_only(&gi->cdev, &cfg->c);
716 static void config_desc_drop(
717 struct config_group *group,
718 struct config_item *item)
720 config_item_put(item);
723 static struct configfs_group_operations config_desc_ops = {
724 .make_group = &config_desc_make,
725 .drop_item = &config_desc_drop,
728 static struct config_item_type config_desc_type = {
729 .ct_group_ops = &config_desc_ops,
730 .ct_owner = THIS_MODULE,
733 GS_STRINGS_RW(gadget_strings, manufacturer);
734 GS_STRINGS_RW(gadget_strings, product);
735 GS_STRINGS_RW(gadget_strings, serialnumber);
737 static struct configfs_attribute *gadget_strings_langid_attrs[] = {
738 &gadget_strings_attr_manufacturer,
739 &gadget_strings_attr_product,
740 &gadget_strings_attr_serialnumber,
744 static void gadget_strings_attr_release(struct config_item *item)
746 struct gadget_strings *gs = to_gadget_strings(item);
748 kfree(gs->manufacturer);
750 kfree(gs->serialnumber);
756 USB_CONFIG_STRING_RW_OPS(gadget_strings);
757 USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info);
759 static inline struct os_desc *to_os_desc(struct config_item *item)
761 return container_of(to_config_group(item), struct os_desc, group);
764 static inline struct gadget_info *os_desc_item_to_gadget_info(
765 struct config_item *item)
767 return to_gadget_info(to_os_desc(item)->group.cg_item.ci_parent);
770 static ssize_t os_desc_use_show(struct config_item *item, char *page)
772 return sprintf(page, "%d",
773 os_desc_item_to_gadget_info(item)->use_os_desc);
776 static ssize_t os_desc_use_store(struct config_item *item, const char *page,
779 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
783 mutex_lock(&gi->lock);
784 ret = strtobool(page, &use);
786 gi->use_os_desc = use;
789 mutex_unlock(&gi->lock);
794 static ssize_t os_desc_b_vendor_code_show(struct config_item *item, char *page)
796 return sprintf(page, "%d",
797 os_desc_item_to_gadget_info(item)->b_vendor_code);
800 static ssize_t os_desc_b_vendor_code_store(struct config_item *item,
801 const char *page, size_t len)
803 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
807 mutex_lock(&gi->lock);
808 ret = kstrtou8(page, 0, &b_vendor_code);
810 gi->b_vendor_code = b_vendor_code;
813 mutex_unlock(&gi->lock);
818 static ssize_t os_desc_qw_sign_show(struct config_item *item, char *page)
820 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
822 memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
823 return OS_STRING_QW_SIGN_LEN;
826 static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page,
829 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
832 l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1);
833 if (page[l - 1] == '\n')
836 mutex_lock(&gi->lock);
837 res = utf8s_to_utf16s(page, l,
838 UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign,
839 OS_STRING_QW_SIGN_LEN);
842 mutex_unlock(&gi->lock);
847 CONFIGFS_ATTR(os_desc_, use);
848 CONFIGFS_ATTR(os_desc_, b_vendor_code);
849 CONFIGFS_ATTR(os_desc_, qw_sign);
851 static struct configfs_attribute *os_desc_attrs[] = {
853 &os_desc_attr_b_vendor_code,
854 &os_desc_attr_qw_sign,
858 static void os_desc_attr_release(struct config_item *item)
860 struct os_desc *os_desc = to_os_desc(item);
864 static int os_desc_link(struct config_item *os_desc_ci,
865 struct config_item *usb_cfg_ci)
867 struct gadget_info *gi = container_of(to_config_group(os_desc_ci),
868 struct gadget_info, os_desc_group);
869 struct usb_composite_dev *cdev = &gi->cdev;
870 struct config_usb_cfg *c_target =
871 container_of(to_config_group(usb_cfg_ci),
872 struct config_usb_cfg, group);
873 struct usb_configuration *c;
876 mutex_lock(&gi->lock);
877 list_for_each_entry(c, &cdev->configs, list) {
878 if (c == &c_target->c)
881 if (c != &c_target->c) {
886 if (cdev->os_desc_config) {
891 cdev->os_desc_config = &c_target->c;
895 mutex_unlock(&gi->lock);
899 static int os_desc_unlink(struct config_item *os_desc_ci,
900 struct config_item *usb_cfg_ci)
902 struct gadget_info *gi = container_of(to_config_group(os_desc_ci),
903 struct gadget_info, os_desc_group);
904 struct usb_composite_dev *cdev = &gi->cdev;
906 mutex_lock(&gi->lock);
908 unregister_gadget(gi);
909 cdev->os_desc_config = NULL;
910 WARN_ON(gi->udc_name);
911 mutex_unlock(&gi->lock);
915 static struct configfs_item_operations os_desc_ops = {
916 .release = os_desc_attr_release,
917 .allow_link = os_desc_link,
918 .drop_link = os_desc_unlink,
921 static struct config_item_type os_desc_type = {
922 .ct_item_ops = &os_desc_ops,
923 .ct_attrs = os_desc_attrs,
924 .ct_owner = THIS_MODULE,
927 static inline struct usb_os_desc_ext_prop
928 *to_usb_os_desc_ext_prop(struct config_item *item)
930 return container_of(item, struct usb_os_desc_ext_prop, item);
933 static ssize_t ext_prop_type_show(struct config_item *item, char *page)
935 return sprintf(page, "%d", to_usb_os_desc_ext_prop(item)->type);
938 static ssize_t ext_prop_type_store(struct config_item *item,
939 const char *page, size_t len)
941 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
942 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
946 if (desc->opts_mutex)
947 mutex_lock(desc->opts_mutex);
948 ret = kstrtou8(page, 0, &type);
951 if (type < USB_EXT_PROP_UNICODE || type > USB_EXT_PROP_UNICODE_MULTI) {
956 if ((ext_prop->type == USB_EXT_PROP_BINARY ||
957 ext_prop->type == USB_EXT_PROP_LE32 ||
958 ext_prop->type == USB_EXT_PROP_BE32) &&
959 (type == USB_EXT_PROP_UNICODE ||
960 type == USB_EXT_PROP_UNICODE_ENV ||
961 type == USB_EXT_PROP_UNICODE_LINK))
962 ext_prop->data_len <<= 1;
963 else if ((ext_prop->type == USB_EXT_PROP_UNICODE ||
964 ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
965 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) &&
966 (type == USB_EXT_PROP_BINARY ||
967 type == USB_EXT_PROP_LE32 ||
968 type == USB_EXT_PROP_BE32))
969 ext_prop->data_len >>= 1;
970 ext_prop->type = type;
974 if (desc->opts_mutex)
975 mutex_unlock(desc->opts_mutex);
979 static ssize_t ext_prop_data_show(struct config_item *item, char *page)
981 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
982 int len = ext_prop->data_len;
984 if (ext_prop->type == USB_EXT_PROP_UNICODE ||
985 ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
986 ext_prop->type == USB_EXT_PROP_UNICODE_LINK)
988 memcpy(page, ext_prop->data, len);
993 static ssize_t ext_prop_data_store(struct config_item *item,
994 const char *page, size_t len)
996 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
997 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
999 size_t ret_len = len;
1001 if (page[len - 1] == '\n' || page[len - 1] == '\0')
1003 new_data = kmemdup(page, len, GFP_KERNEL);
1007 if (desc->opts_mutex)
1008 mutex_lock(desc->opts_mutex);
1009 kfree(ext_prop->data);
1010 ext_prop->data = new_data;
1011 desc->ext_prop_len -= ext_prop->data_len;
1012 ext_prop->data_len = len;
1013 desc->ext_prop_len += ext_prop->data_len;
1014 if (ext_prop->type == USB_EXT_PROP_UNICODE ||
1015 ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
1016 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) {
1017 desc->ext_prop_len -= ext_prop->data_len;
1018 ext_prop->data_len <<= 1;
1019 ext_prop->data_len += 2;
1020 desc->ext_prop_len += ext_prop->data_len;
1022 if (desc->opts_mutex)
1023 mutex_unlock(desc->opts_mutex);
1027 CONFIGFS_ATTR(ext_prop_, type);
1028 CONFIGFS_ATTR(ext_prop_, data);
1030 static struct configfs_attribute *ext_prop_attrs[] = {
1031 &ext_prop_attr_type,
1032 &ext_prop_attr_data,
1036 static void usb_os_desc_ext_prop_release(struct config_item *item)
1038 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1040 kfree(ext_prop); /* frees a whole chunk */
1043 static struct configfs_item_operations ext_prop_ops = {
1044 .release = usb_os_desc_ext_prop_release,
1047 static struct config_item *ext_prop_make(
1048 struct config_group *group,
1051 struct usb_os_desc_ext_prop *ext_prop;
1052 struct config_item_type *ext_prop_type;
1053 struct usb_os_desc *desc;
1056 vla_group(data_chunk);
1057 vla_item(data_chunk, struct usb_os_desc_ext_prop, ext_prop, 1);
1058 vla_item(data_chunk, struct config_item_type, ext_prop_type, 1);
1060 vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL);
1062 return ERR_PTR(-ENOMEM);
1064 ext_prop = vla_ptr(vlabuf, data_chunk, ext_prop);
1065 ext_prop_type = vla_ptr(vlabuf, data_chunk, ext_prop_type);
1067 desc = container_of(group, struct usb_os_desc, group);
1068 ext_prop_type->ct_item_ops = &ext_prop_ops;
1069 ext_prop_type->ct_attrs = ext_prop_attrs;
1070 ext_prop_type->ct_owner = desc->owner;
1072 config_item_init_type_name(&ext_prop->item, name, ext_prop_type);
1074 ext_prop->name = kstrdup(name, GFP_KERNEL);
1075 if (!ext_prop->name) {
1077 return ERR_PTR(-ENOMEM);
1079 desc->ext_prop_len += 14;
1080 ext_prop->name_len = 2 * strlen(ext_prop->name) + 2;
1081 if (desc->opts_mutex)
1082 mutex_lock(desc->opts_mutex);
1083 desc->ext_prop_len += ext_prop->name_len;
1084 list_add_tail(&ext_prop->entry, &desc->ext_prop);
1085 ++desc->ext_prop_count;
1086 if (desc->opts_mutex)
1087 mutex_unlock(desc->opts_mutex);
1089 return &ext_prop->item;
1092 static void ext_prop_drop(struct config_group *group, struct config_item *item)
1094 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1095 struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item);
1097 if (desc->opts_mutex)
1098 mutex_lock(desc->opts_mutex);
1099 list_del(&ext_prop->entry);
1100 --desc->ext_prop_count;
1101 kfree(ext_prop->name);
1102 desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14);
1103 if (desc->opts_mutex)
1104 mutex_unlock(desc->opts_mutex);
1105 config_item_put(item);
1108 static struct configfs_group_operations interf_grp_ops = {
1109 .make_item = &ext_prop_make,
1110 .drop_item = &ext_prop_drop,
1113 static ssize_t interf_grp_compatible_id_show(struct config_item *item,
1116 memcpy(page, to_usb_os_desc(item)->ext_compat_id, 8);
1120 static ssize_t interf_grp_compatible_id_store(struct config_item *item,
1121 const char *page, size_t len)
1123 struct usb_os_desc *desc = to_usb_os_desc(item);
1126 l = min_t(int, 8, len);
1127 if (page[l - 1] == '\n')
1129 if (desc->opts_mutex)
1130 mutex_lock(desc->opts_mutex);
1131 memcpy(desc->ext_compat_id, page, l);
1133 if (desc->opts_mutex)
1134 mutex_unlock(desc->opts_mutex);
1139 static ssize_t interf_grp_sub_compatible_id_show(struct config_item *item,
1142 memcpy(page, to_usb_os_desc(item)->ext_compat_id + 8, 8);
1146 static ssize_t interf_grp_sub_compatible_id_store(struct config_item *item,
1147 const char *page, size_t len)
1149 struct usb_os_desc *desc = to_usb_os_desc(item);
1152 l = min_t(int, 8, len);
1153 if (page[l - 1] == '\n')
1155 if (desc->opts_mutex)
1156 mutex_lock(desc->opts_mutex);
1157 memcpy(desc->ext_compat_id + 8, page, l);
1159 if (desc->opts_mutex)
1160 mutex_unlock(desc->opts_mutex);
1165 CONFIGFS_ATTR(interf_grp_, compatible_id);
1166 CONFIGFS_ATTR(interf_grp_, sub_compatible_id);
1168 static struct configfs_attribute *interf_grp_attrs[] = {
1169 &interf_grp_attr_compatible_id,
1170 &interf_grp_attr_sub_compatible_id,
1174 int usb_os_desc_prepare_interf_dir(struct config_group *parent,
1176 struct usb_os_desc **desc,
1178 struct module *owner)
1180 struct config_group **f_default_groups, *os_desc_group,
1182 struct config_item_type *os_desc_type, *interface_type;
1184 vla_group(data_chunk);
1185 vla_item(data_chunk, struct config_group *, f_default_groups, 2);
1186 vla_item(data_chunk, struct config_group, os_desc_group, 1);
1187 vla_item(data_chunk, struct config_group *, interface_groups,
1189 vla_item(data_chunk, struct config_item_type, os_desc_type, 1);
1190 vla_item(data_chunk, struct config_item_type, interface_type, 1);
1192 char *vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL);
1196 f_default_groups = vla_ptr(vlabuf, data_chunk, f_default_groups);
1197 os_desc_group = vla_ptr(vlabuf, data_chunk, os_desc_group);
1198 os_desc_type = vla_ptr(vlabuf, data_chunk, os_desc_type);
1199 interface_groups = vla_ptr(vlabuf, data_chunk, interface_groups);
1200 interface_type = vla_ptr(vlabuf, data_chunk, interface_type);
1202 parent->default_groups = f_default_groups;
1203 os_desc_type->ct_owner = owner;
1204 config_group_init_type_name(os_desc_group, "os_desc", os_desc_type);
1205 f_default_groups[0] = os_desc_group;
1207 os_desc_group->default_groups = interface_groups;
1208 interface_type->ct_group_ops = &interf_grp_ops;
1209 interface_type->ct_attrs = interf_grp_attrs;
1210 interface_type->ct_owner = owner;
1212 while (n_interf--) {
1213 struct usb_os_desc *d;
1217 config_group_init_type_name(&d->group, "", interface_type);
1218 config_item_set_name(&d->group.cg_item, "interface.%s",
1220 interface_groups[n_interf] = &d->group;
1225 EXPORT_SYMBOL(usb_os_desc_prepare_interf_dir);
1227 static int configfs_do_nothing(struct usb_composite_dev *cdev)
1233 int composite_dev_prepare(struct usb_composite_driver *composite,
1234 struct usb_composite_dev *dev);
1236 int composite_os_desc_req_prepare(struct usb_composite_dev *cdev,
1237 struct usb_ep *ep0);
1239 static void purge_configs_funcs(struct gadget_info *gi)
1241 struct usb_configuration *c;
1243 list_for_each_entry(c, &gi->cdev.configs, list) {
1244 struct usb_function *f, *tmp;
1245 struct config_usb_cfg *cfg;
1247 cfg = container_of(c, struct config_usb_cfg, c);
1249 list_for_each_entry_safe(f, tmp, &c->functions, list) {
1251 list_move_tail(&f->list, &cfg->func_list);
1253 dev_err(&gi->cdev.gadget->dev, "unbind function"
1254 " '%s'/%p\n", f->name, f);
1258 c->next_interface_id = 0;
1259 memset(c->interface, 0, sizeof(c->interface));
1266 static int configfs_composite_bind(struct usb_gadget *gadget,
1267 struct usb_gadget_driver *gdriver)
1269 struct usb_composite_driver *composite = to_cdriver(gdriver);
1270 struct gadget_info *gi = container_of(composite,
1271 struct gadget_info, composite);
1272 struct usb_composite_dev *cdev = &gi->cdev;
1273 struct usb_configuration *c;
1274 struct usb_string *s;
1278 /* the gi->lock is hold by the caller */
1279 cdev->gadget = gadget;
1280 set_gadget_data(gadget, cdev);
1281 ret = composite_dev_prepare(composite, cdev);
1284 /* and now the gadget bind */
1287 if (list_empty(&gi->cdev.configs)) {
1288 pr_err("Need at least one configuration in %s.\n",
1289 gi->composite.name);
1290 goto err_comp_cleanup;
1294 list_for_each_entry(c, &gi->cdev.configs, list) {
1295 struct config_usb_cfg *cfg;
1297 cfg = container_of(c, struct config_usb_cfg, c);
1298 if (list_empty(&cfg->func_list)) {
1299 pr_err("Config %s/%d of %s needs at least one function.\n",
1300 c->label, c->bConfigurationValue,
1301 gi->composite.name);
1302 goto err_comp_cleanup;
1306 /* init all strings */
1307 if (!list_empty(&gi->string_list)) {
1308 struct gadget_strings *gs;
1311 list_for_each_entry(gs, &gi->string_list, list) {
1313 gi->gstrings[i] = &gs->stringtab_dev;
1314 gs->stringtab_dev.strings = gs->strings;
1315 gs->strings[USB_GADGET_MANUFACTURER_IDX].s =
1317 gs->strings[USB_GADGET_PRODUCT_IDX].s = gs->product;
1318 gs->strings[USB_GADGET_SERIAL_IDX].s = gs->serialnumber;
1321 gi->gstrings[i] = NULL;
1322 s = usb_gstrings_attach(&gi->cdev, gi->gstrings,
1323 USB_GADGET_FIRST_AVAIL_IDX);
1326 goto err_comp_cleanup;
1329 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id;
1330 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id;
1331 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id;
1334 if (gi->use_os_desc) {
1335 cdev->use_os_string = true;
1336 cdev->b_vendor_code = gi->b_vendor_code;
1337 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
1340 if (gadget_is_otg(gadget) && !otg_desc[0]) {
1341 struct usb_descriptor_header *usb_desc;
1343 usb_desc = usb_otg_descriptor_alloc(gadget);
1346 goto err_comp_cleanup;
1348 usb_otg_descriptor_init(gadget, usb_desc);
1349 otg_desc[0] = usb_desc;
1353 /* Go through all configs, attach all functions */
1354 list_for_each_entry(c, &gi->cdev.configs, list) {
1355 struct config_usb_cfg *cfg;
1356 struct usb_function *f;
1357 struct usb_function *tmp;
1358 struct gadget_config_name *cn;
1360 if (gadget_is_otg(gadget))
1361 c->descriptors = otg_desc;
1363 cfg = container_of(c, struct config_usb_cfg, c);
1364 if (!list_empty(&cfg->string_list)) {
1366 list_for_each_entry(cn, &cfg->string_list, list) {
1367 cfg->gstrings[i] = &cn->stringtab_dev;
1368 cn->stringtab_dev.strings = &cn->strings;
1369 cn->strings.s = cn->configuration;
1372 cfg->gstrings[i] = NULL;
1373 s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1);
1376 goto err_comp_cleanup;
1378 c->iConfiguration = s[0].id;
1381 list_for_each_entry_safe(f, tmp, &cfg->func_list, list) {
1383 ret = usb_add_function(c, f);
1385 list_add(&f->list, &cfg->func_list);
1386 goto err_purge_funcs;
1389 usb_ep_autoconfig_reset(cdev->gadget);
1391 if (cdev->use_os_string) {
1392 ret = composite_os_desc_req_prepare(cdev, gadget->ep0);
1394 goto err_purge_funcs;
1397 usb_ep_autoconfig_reset(cdev->gadget);
1401 purge_configs_funcs(gi);
1403 composite_dev_cleanup(cdev);
1407 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1408 static void android_work(struct work_struct *data)
1410 struct gadget_info *gi = container_of(data, struct gadget_info, work);
1411 struct usb_composite_dev *cdev = &gi->cdev;
1412 char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
1413 char *connected[2] = { "USB_STATE=CONNECTED", NULL };
1414 char *configured[2] = { "USB_STATE=CONFIGURED", NULL };
1415 /* 0-connected 1-configured 2-disconnected*/
1416 bool status[3] = { false, false, false };
1417 unsigned long flags;
1418 bool uevent_sent = false;
1420 spin_lock_irqsave(&cdev->lock, flags);
1424 if (gi->connected != gi->sw_connected) {
1429 gi->sw_connected = gi->connected;
1431 spin_unlock_irqrestore(&cdev->lock, flags);
1434 kobject_uevent_env(&android_device->kobj,
1435 KOBJ_CHANGE, connected);
1436 pr_info("%s: sent uevent %s\n", __func__, connected[0]);
1441 kobject_uevent_env(&android_device->kobj,
1442 KOBJ_CHANGE, configured);
1443 pr_info("%s: sent uevent %s\n", __func__, configured[0]);
1448 kobject_uevent_env(&android_device->kobj,
1449 KOBJ_CHANGE, disconnected);
1450 pr_info("%s: sent uevent %s\n", __func__, disconnected[0]);
1455 pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
1456 gi->connected, gi->sw_connected, cdev->config);
1461 static void configfs_composite_unbind(struct usb_gadget *gadget)
1463 struct usb_composite_dev *cdev;
1464 struct gadget_info *gi;
1466 /* the gi->lock is hold by the caller */
1468 cdev = get_gadget_data(gadget);
1469 gi = container_of(cdev, struct gadget_info, cdev);
1473 purge_configs_funcs(gi);
1474 composite_dev_cleanup(cdev);
1475 usb_ep_autoconfig_reset(cdev->gadget);
1476 cdev->gadget = NULL;
1477 set_gadget_data(gadget, NULL);
1480 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1481 static int android_setup(struct usb_gadget *gadget,
1482 const struct usb_ctrlrequest *c)
1484 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1485 unsigned long flags;
1486 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
1487 int value = -EOPNOTSUPP;
1488 struct usb_function_instance *fi;
1490 spin_lock_irqsave(&cdev->lock, flags);
1491 if (!gi->connected) {
1493 schedule_work(&gi->work);
1495 spin_unlock_irqrestore(&cdev->lock, flags);
1496 list_for_each_entry(fi, &gi->available_func, cfs_list) {
1497 if (fi != NULL && fi->f != NULL && fi->f->setup != NULL) {
1498 value = fi->f->setup(fi->f, c);
1504 #ifdef CONFIG_USB_CONFIGFS_F_ACC
1506 value = acc_ctrlrequest(cdev, c);
1510 value = composite_setup(gadget, c);
1512 spin_lock_irqsave(&cdev->lock, flags);
1513 if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
1515 schedule_work(&gi->work);
1517 spin_unlock_irqrestore(&cdev->lock, flags);
1522 static void android_disconnect(struct usb_gadget *gadget)
1524 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1525 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
1527 /* accessory HID support can be active while the
1528 accessory function is not actually enabled,
1529 so we need to inform it when we are disconnected.
1532 #ifdef CONFIG_USB_CONFIGFS_F_ACC
1536 schedule_work(&gi->work);
1537 composite_disconnect(gadget);
1541 static const struct usb_gadget_driver configfs_driver_template = {
1542 .bind = configfs_composite_bind,
1543 .unbind = configfs_composite_unbind,
1544 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1545 .setup = android_setup,
1546 .disconnect = android_disconnect,
1548 .setup = composite_setup,
1549 .reset = composite_disconnect,
1550 .disconnect = composite_disconnect,
1552 .suspend = composite_suspend,
1553 .resume = composite_resume,
1555 .max_speed = USB_SPEED_SUPER,
1557 .owner = THIS_MODULE,
1558 .name = "configfs-gadget",
1562 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1563 static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
1566 struct gadget_info *dev = dev_get_drvdata(pdev);
1567 struct usb_composite_dev *cdev;
1568 char *state = "DISCONNECTED";
1569 unsigned long flags;
1579 spin_lock_irqsave(&cdev->lock, flags);
1581 state = "CONFIGURED";
1582 else if (dev->connected)
1583 state = "CONNECTED";
1584 spin_unlock_irqrestore(&cdev->lock, flags);
1586 return sprintf(buf, "%s\n", state);
1589 static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);
1591 static struct device_attribute *android_usb_attributes[] = {
1597 static struct config_group *gadgets_make(
1598 struct config_group *group,
1601 struct gadget_info *gi;
1602 struct device_attribute **attrs;
1603 struct device_attribute *attr;
1606 gi = kzalloc(sizeof(*gi), GFP_KERNEL);
1608 return ERR_PTR(-ENOMEM);
1609 gi->group.default_groups = gi->default_groups;
1610 gi->group.default_groups[0] = &gi->functions_group;
1611 gi->group.default_groups[1] = &gi->configs_group;
1612 gi->group.default_groups[2] = &gi->strings_group;
1613 gi->group.default_groups[3] = &gi->os_desc_group;
1615 config_group_init_type_name(&gi->functions_group, "functions",
1617 config_group_init_type_name(&gi->configs_group, "configs",
1619 config_group_init_type_name(&gi->strings_group, "strings",
1620 &gadget_strings_strings_type);
1621 config_group_init_type_name(&gi->os_desc_group, "os_desc",
1624 gi->composite.bind = configfs_do_nothing;
1625 gi->composite.unbind = configfs_do_nothing;
1626 gi->composite.suspend = NULL;
1627 gi->composite.resume = NULL;
1628 gi->composite.max_speed = USB_SPEED_SUPER;
1630 mutex_init(&gi->lock);
1631 INIT_LIST_HEAD(&gi->string_list);
1632 INIT_LIST_HEAD(&gi->available_func);
1634 composite_init_dev(&gi->cdev);
1635 gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE;
1636 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE;
1637 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice());
1639 gi->composite.gadget_driver = configfs_driver_template;
1641 gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL);
1642 gi->composite.name = gi->composite.gadget_driver.function;
1644 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1645 INIT_WORK(&gi->work, android_work);
1646 android_device = device_create(android_class, NULL,
1647 MKDEV(0, 0), NULL, "android0");
1648 if (IS_ERR(android_device))
1651 dev_set_drvdata(android_device, gi);
1653 attrs = android_usb_attributes;
1654 while ((attr = *attrs++)) {
1655 err = device_create_file(android_device, attr);
1661 if (!gi->composite.gadget_driver.function)
1664 config_group_init_type_name(&gi->group, name,
1669 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1670 attrs = android_usb_attributes;
1671 while ((attr = *attrs++))
1672 device_remove_file(android_device, attr);
1674 device_destroy(android_device->class,
1675 android_device->devt);
1679 return ERR_PTR(-ENOMEM);
1682 static void gadgets_drop(struct config_group *group, struct config_item *item)
1684 struct device_attribute **attrs;
1685 struct device_attribute *attr;
1687 config_item_put(item);
1689 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1690 attrs = android_usb_attributes;
1691 while ((attr = *attrs++))
1692 device_remove_file(android_device, attr);
1693 device_destroy(android_device->class, android_device->devt);
1697 static struct configfs_group_operations gadgets_ops = {
1698 .make_group = &gadgets_make,
1699 .drop_item = &gadgets_drop,
1702 static struct config_item_type gadgets_type = {
1703 .ct_group_ops = &gadgets_ops,
1704 .ct_owner = THIS_MODULE,
1707 static struct configfs_subsystem gadget_subsys = {
1710 .ci_namebuf = "usb_gadget",
1711 .ci_type = &gadgets_type,
1714 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
1717 void unregister_gadget_item(struct config_item *item)
1719 struct gadget_info *gi = to_gadget_info(item);
1721 unregister_gadget(gi);
1723 EXPORT_SYMBOL_GPL(unregister_gadget_item);
1725 static int __init gadget_cfs_init(void)
1729 config_group_init(&gadget_subsys.su_group);
1731 ret = configfs_register_subsystem(&gadget_subsys);
1733 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1734 android_class = class_create(THIS_MODULE, "android_usb");
1735 if (IS_ERR(android_class))
1736 return PTR_ERR(android_class);
1741 module_init(gadget_cfs_init);
1743 static void __exit gadget_cfs_exit(void)
1745 configfs_unregister_subsystem(&gadget_subsys);
1746 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1747 if (!IS_ERR(android_class))
1748 class_destroy(android_class);
1752 module_exit(gadget_cfs_exit);