设为首页 加入收藏

TOP

Android 4.0 USB挂载内核驱动层流程分析
2014-11-24 08:07:59 来源: 作者: 【 】 浏览:1
Tags:Android 4.0 USB 内核 驱动 流程 分析

1.platform_device
在arch/arm/mach-msm/Board-xx.c中


static struct platform_device android_usb_device = {
.name = "android_usb",
.id = -1,
.dev = {
.platform_data = &android_usb_pdata, //@1
}


};
static struct android_usb_platform_data android_usb_pdata = {
.update_pid_and_serial_num = usb_diag_update_pid_and_serial_num,
};


在rpc_hsusb.c中:


int usb_diag_update_pid_and_serial_num(uint32_t pid, const char *snum)
{
int ret;


ret = msm_hsusb_send_productID(pid);
if (ret)
return ret;


if (!snum) {
ret = msm_hsusb_is_serial_num_null(1);
if (ret)
return ret;
return 0;
}


ret = msm_hsusb_is_serial_num_null(0);
if (ret)
return ret;
ret = msm_hsusb_send_serial_number(snum);
if (ret)
return ret;


return 0;
}


在内核初始化时,先注册了名为android_usb的设备。


2.platform_driver


在drivers/usb/gadget/Android.c中:


static struct platform_driver android_platform_driver = {
.driver = { .name = "android_usb"},
};


注册了名为android_usb的paltform_driver。但是并不像其他硬件驱动那样,有.probe函数用来匹配驱动。不要着急,慢慢看。


3.module_init


其实Android.c用的是module_init的方式:


static int __init init(void)
{
struct android_dev *dev;
int err;


android_class = class_create(THIS_MODULE, "android_usb"); //在sys/class下创建android_usb目录
if (IS_ERR(android_class)) //错误处理
return PTR_ERR(android_class);


dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;


dev->functions = supported_functions; //设备支持的一些功能,功能列表
/*
*static struct android_usb_function *supported_functions[] = {
* &rmnet_smd_function,
* &rmnet_sdio_function,
* &rmnet_smd_sdio_function,
* &rmnet_function,
* &diag_function,
* &serial_function,
* &adb_function,
* &ccid_function,
*// &acm_function,
* &mtp_function,
* &ptp_function,
* &rndis_function,
* &mass_storage_function,
* &accessory_function,
* NULL
*};
*/
INIT_LIST_HEAD(&dev->enabled_functions); //应该是加入到队列里的意思吧,使能这些功能
INIT_WORK(&dev->work, android_work);


err = android_create_device(dev); //创建dev,按内核目录来看:
/*
*localhost android_usb # ls
*android0 f_diag f_rmnet f_rndis
*f_accessory f_mass_storage f_rmnet_sdio f_serial
*f_adb f_mtp f_rmnet_smd
*f_ccid f_ptp f_rmnet_smd_sdio
*localhost android_usb #
*/
if (err) {
class_destroy(android_class);
kfree(dev);
return err;
}


_android_dev = dev;


/* Override composite driver functions */
composite_driver.setup = android_setup;
composite_driver.disconnect = android_disconnect;


platform_driver_probe(&android_platform_driver, android_probe); //驱动是通过platform_driver_probe方式进行匹配的,匹配函数位android_probe:
/*
*static int __devinit android_probe(struct platform_device *pdev)
*{
* struct android_usb_platform_data *pdata = pdev->dev.platform_data; //见@1
* struct android_dev *dev = _android_dev;
*
* dev->pdata = pdata;
*
* return 0;
*}
*/


return usb_composite_probe(&android_usb_driver, android_bind); //万能USB驱动,用android_bind进行绑定
}
module_init(init);


static void __exit cleanup(void)
{
usb_composite_unregister(&android_usb_driver);
class_destroy(android_class);
kfree(_android_dev);
_android_dev = NULL;
}
module_exit(cleanup);


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇jQuery取select标签被选项的值 下一篇Hadoop异步rpc通信机制--org.apac..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·求navicat for mysql (2025-12-26 13:21:33)
·有哪位大哥推荐一下m (2025-12-26 13:21:30)
·MySQL下载与安装教程 (2025-12-26 13:21:26)
·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)