基于android4.0的usb gadget分析
近来一直在打酱油,闲暇之余分析了下usb gadget驱动。每天的工作就是扯,工作吧,你不扯还不行,哎,所以近来工作很郁闷,不过也该走啦。离开这个让我几乎窒息的华为,一直不明白为什么还有 那么多的人挤着要进华为,哎,好啦,不扯啦,开始言归正转,分析下代码,不过我也是现学现卖,欢迎高手拍砖。
现总体看下gadget子系统。
| gadaet驱动 |(adb,大容量存储设备)
| gadget API |(对UDC控制器驱动操作函数的封装)
| UDC控制器驱动|(设备的控制器驱动)
不过这个架构在android系统中又复杂了很多。最新的android4.0和android2.3.7的代码结构已经不一样啦,这也是昨天 才发现的,所以今天看了一天android4.0的kernel,不过没有完全搞懂,学了一点就先记下来,当做笔记吧,也好供以后查看。
先贴几个重要的结构体再说:
- struct android_dev {
- struct android_usb_function **functions;//该android_dev支持的功能如adb,大容量存储
- struct list_head enabled_functions;// 开启的功能链表
- struct usb_composite_dev *cdev;//符合设备的dev
- struct device *dev;//支持设备驱动模型的dev
- bool enabled;
- struct mutex mutex;//操作该结构体是用到的互斥锁
- bool connected;//记录当前的连接状态
- bool sw_connected;//记录切换后的连接状态
- struct work_struct work;//支持的工作队列
- };
- struct android_usb_function {
- char *name;//该功能的名字
- void *config;//该功能所依赖的配置
- struct device *dev;//为设备驱动模型准备的device
- char *dev_name;
- struct device_attribute **attributes;
- /* 挂入android_dev中的enabled_functions的链表节点*/
- struct list_head enabled_list;
- /* 在绑定的时候,执行的初始化函数*/
- int (*init)(struct android_usb_function *, struct usb_composite_dev *);
- /* 在解除绑定时,执行清除的函数*/
- void (*cleanup)(struct android_usb_function *);
- /* 把该function绑定到特定的配置上,此时function相当一个接口*/
- int (*bind_config)(struct android_usb_function *, struct usb_configuration *);
- /* Optional: called when the configuration is removed */
- void (*unbind_config)(struct android_usb_function *, struct usb_configuration *);
- /* Optional: handle ctrl requests before the device is configured */
- int (*ctrlrequest)(struct android_usb_function *,
- struct usb_composite_dev *,
- const struct usb_ctrlrequest *);
- };
顺便补充下什么是符合设备?
Example: a device with a single configuration supporting both network
link and mass storage functions is a composite device. Those functions
might alternatively be packaged in individual configurations, but in
the composite model the host can use both functions at the same time.
link and mass storage functions is a composite device. Those functions
might alternatively be packaged in individual configurations, but in
the composite model the host can use both functions at the same time.
这点英语看懂了吧,这就是符合设备。
现贴这么多吧,等完全分析明白了再写个专题。
浙公网安备 33010602011771号