1 #include <linux/kernel.h>
2 #include <linux/slab.h>
3 #include <linux/module.h>
6 #include <linux/usb/composite.h>
8 static LIST_HEAD(func_list
);
9 static DEFINE_MUTEX(func_lock
);
11 static struct usb_function_instance
*try_get_usb_function_instance(const char *name
)
13 struct usb_function_driver
*fd
;
14 struct usb_function_instance
*fi
;
16 fi
= ERR_PTR(-ENOENT
);
17 mutex_lock(&func_lock
);
18 list_for_each_entry(fd
, &func_list
, list
) {
20 if (strcmp(name
, fd
->name
))
23 if (!try_module_get(fd
->mod
)) {
27 fi
= fd
->alloc_inst();
34 mutex_unlock(&func_lock
);
38 struct usb_function_instance
*usb_get_function_instance(const char *name
)
40 struct usb_function_instance
*fi
;
43 fi
= try_get_usb_function_instance(name
);
49 ret
= request_module("usbfunc:%s", name
);
52 return try_get_usb_function_instance(name
);
54 EXPORT_SYMBOL_GPL(usb_get_function_instance
);
56 struct usb_function
*usb_get_function(struct usb_function_instance
*fi
)
58 struct usb_function
*f
;
60 f
= fi
->fd
->alloc_func(fi
);
66 EXPORT_SYMBOL_GPL(usb_get_function
);
68 void usb_put_function_instance(struct usb_function_instance
*fi
)
76 fi
->free_func_inst(fi
);
79 EXPORT_SYMBOL_GPL(usb_put_function_instance
);
81 void usb_put_function(struct usb_function
*f
)
88 EXPORT_SYMBOL_GPL(usb_put_function
);
90 int usb_function_register(struct usb_function_driver
*newf
)
92 struct usb_function_driver
*fd
;
97 mutex_lock(&func_lock
);
98 list_for_each_entry(fd
, &func_list
, list
) {
99 if (!strcmp(fd
->name
, newf
->name
))
103 list_add_tail(&newf
->list
, &func_list
);
105 mutex_unlock(&func_lock
);
108 EXPORT_SYMBOL_GPL(usb_function_register
);
110 void usb_function_unregister(struct usb_function_driver
*fd
)
112 mutex_lock(&func_lock
);
114 mutex_unlock(&func_lock
);
116 EXPORT_SYMBOL_GPL(usb_function_unregister
);