1、
late_initcall(init)-------------------------------kernel/driver/usb/gadget/android.c
-->platform_driver_register(&android_platform_driver)
-->.probe = android_probe
-->android_dev->functions= supported_functions
-->usb_composite_probe(&android_usb_driver)
-->usb_gadget_probe_driver(gadget_driver)
-->udc_bind_to_driver(udc, driver)
-->driver->bind(udc->gadget, driver)
2、
static structusb_composite_driver android_usb_driver= {
.name ="android_usb",
.dev =&device_desc,
.strings =dev_strings,
.bind =android_bind,
.unbind =android_usb_unbind,
.disconnect =android_disconnect,
.max_speed =USB_SPEED_SUPER
};
android_init_functions(dev->functions,cdev)
----->
static int android_init_functions(structandroid_usb_function **functions,
struct usb_composite_dev *cdev)
{
structandroid_dev *dev = cdev_to_android_dev(cdev);
structandroid_usb_function *f;
structdevice_attribute **attrs;
structdevice_attribute *attr;
interr = 0;
intindex = 1; /* index 0 is for android0 device */
for (; (f = *functions++);index++) {
f->dev_name =kasprintf(GFP_KERNEL, "f_%s", f->name);
f->android_dev= NULL;
if(!f->dev_name) {
err= -ENOMEM;
gotoerr_out;
}
f->dev= device_create(android_class,dev->dev,
MKDEV(0, index), f,f->dev_name);
if(IS_ERR(f->dev)) {
pr_err("%s:Failed to create dev %s", __func__,
f->dev_name);
err= PTR_ERR(f->dev);
f->dev= NULL;
gotoerr_create;
}
if(f->init) {
err= f->init(f, cdev);
if(err) {
pr_err("%s:Failed to init %s", __func__,
f->name);
gotoerr_init;
}
}
attrs= f->attributes;
if(attrs) {
while((attr = *attrs++) && !err)
err= device_create_file(f->dev, attr);
}
if(err) {
pr_err("%s:Failed to create function %s attributes",
__func__,f->name);
gotoerr_attrs;
}
}
return0;
err_attrs:
for(attr = *(attrs -= 2); attrs != f->attributes; attr = *(attrs--))
device_remove_file(f->dev,attr);
if(f->cleanup)
f->cleanup(f);
err_init:
device_destroy(android_class,f->dev->devt);
err_create:
f->dev= NULL;
kfree(f->dev_name);
err_out:
android_cleanup_functions(dev->functions);
returnerr;
}
3、
static structandroid_usb_function *supported_functions[]= {
&ffs_function,
&mbim_function,
&ecm_qc_function,
#ifdefCONFIG_SND_PCM
&audio_function,
#endif
&rmnet_smd_function,
&rmnet_function,
&gps_function,
&diag_function,
&qdss_function,
&serial_function,
#ifdefCONFIG_USB_YL_CHARGE_ONLY
&hid_function, //HID for charge only mode. linronghui.2013.11.05
#endif
&ccid_function,
&acm_function,
&mtp_function,
&ptp_function,
&rndis_function,
&rndis_qc_function,
&ecm_function,
&ncm_function,
#ifdefCONFIG_USB_YL_CDROM
&mass_storage_function,
#endif
&accessory_function,
#ifdefCONFIG_SND_PCM
&audio_source_function,
#endif
&uasp_function,
//&charger_function,
NULL
};