基于sdm660 androidO----MTP driver 分析

本文详细解析了基于sdm660平台Android O系统中MTP驱动的注册、初始化流程,包括MTP设备注册、工作队列的设置以及如何通过ioctl调用驱动进行文件传输。在MTP操作如拷贝、删除等过程中,通过MtpDevHandle与底层驱动进行交互,实现MTP指令的处理。
摘要由CSDN通过智能技术生成

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)中会初始化sendreceive 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 =

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值