MTP设备注册:
drivers\usb\gadget\function\f_mtp.c
/* file operations for /dev/mtp_usb */
static const struct file_operations mtp_fops = {
.owner = THIS_MODULE,
.read = mtp_read,
.write = mtp_write,
.unlocked_ioctl = mtp_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_mtp_ioctl,
#endif
.open = mtp_open,
.release = mtp_release,
};
static struct miscdevice mtp_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = mtp_shortname,
.fops = &mtp_fops,
};
device初始化流程,在开机时就会初始化
mtp_alloc_inst()
-->alloc_inst_mtp_ptp()
---->mtp_setup_configfs(fi_mtp)
------>__mtp_setup(fi_mtp)
--------->misc_register(&mtp_device);
__mtp_setup(fi_mtp)中会初始化send,receive work
INIT_WORK(&dev->send_file_work, send_file_work);
INIT_WORK(&dev->receive_file_work, receive_file_work);
以下是mtp_alloc_inst被调用流程,代码位于:
drivers/usb/gadget/configfs.c
drivers/usb/gadget/functions.c
gadget_cfs_init(void)
-->configfs_register_subsystem(&gadget_subsys);
static struct configfs_subsystem gadget_subsys = {
.su_group = {
.cg_item = {
.ci_namebuf = "usb_gadget",
.ci_type = &gadgets_type,},},
.su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),};
static struct config_item_type gadgets_type = {
.ct_group_ops = &gadgets_ops,
.ct_owner = THIS_MODULE,};
static struct configfs_group_operations gadgets_ops = {
.make_group = &gadgets_make,
.drop_item =