http://blog.csdn.net/airk000/article/details/7887645
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,
- }
-
- };
- 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");
- if (IS_ERR(android_class))
- return PTR_ERR(android_class);
-
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
- if (!dev)
- return -ENOMEM;
-
- dev->functions = supported_functions;
-
-
-
-
-
-
-
-
-
-
- / &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);
-
-
-
-
-
-
-
-
- if (err) {
- class_destroy(android_class);
- kfree(dev);
- return err;
- }
-
- _android_dev = dev;
-
-
- composite_driver.setup = android_setup;
- composite_driver.disconnect = android_disconnect;
-
- platform_driver_probe(&android_platform_driver, android_probe);
-
-
-
-
-
-
-
-
-
-
-
-
- return usb_composite_probe(&android_usb_driver, 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);
我认为是有两个重点,一个是supported_functions,另一个是android_bind。下一篇博客继续分析。