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

};

### USB Slave Mode Driver Implementation and Documentation In the context of embedded systems, particularly those based on Linux or other real-time operating systems (RTOS), implementing a USB slave mode driver involves configuring the device to act as a peripheral rather than a host. This configuration allows the device to be controlled by an external master device such as a computer. The Linux kernel provides comprehensive support for both USB host and gadget (slave) modes through its Gadget framework[^1]. For devices that need to operate in slave mode, developers can leverage this framework to implement custom drivers tailored to specific hardware requirements. A typical implementation process includes: #### Registering the Gadget with the System To integrate a new USB function into the system, one must register it using the `usb_gadget_register_driver` call within the driver initialization code. This registration informs the core about available functions and endpoints supported by the device. ```c static int __init my_usb_slave_init(void) { struct usb_function *func; func = usb_get_function_instance("my_func"); if (!func) return -ENOMEM; /* Register our gadget */ return usb_gadget_register_driver(&my_gadget); } module_init(my_usb_slave_init); ``` #### Configuring Endpoints Endpoints define how data is transferred between the host and the device. Developers configure these according to the protocol being implemented—such as bulk transfers for file transfer protocols like Mass Storage Class (MSC). For detailed guidance on writing USB gadgets under Linux, refer to official documentation provided alongside source distributions which cover setup procedures along with examples illustrating common use cases[^2]. However, regarding Xilinx-specific implementations mentioned indirectly via another reference point related to DMA operations, there appears no direct mention of USB slave functionality specifically addressed therein[^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值