usb之functions

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

};

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值