- 论坛徽章:
- 0
|
usb 协议规定了,每个usb 设备都得有些基本的元素,称为描述符,有四类描述符是任何一种usb 设备都得
有的.他们是,device descriptor,configuration descriptor,interface descriptor,endpoint
descriptor. 描述符里的冬冬是一个设备出厂的时候就被厂家给固化在设备里了.这种东西不管怎样也改变
不了,比如我有个Intel 的U 盘,那里边的固有的信息肯定是在Intel 出厂的时候就被烙在里边了,厂家早已
把它的一切,烙上Intel 印.所以当我插入U 盘,用cat /proc/scsi/scsi 命令看一下的话,"Vendor" 那一项显
示的肯定是Intel. 关于这几种描述符,usb core 在总线扫描那会就会去读取,会去获得里边的信息,其
中,device 描述符描述的是整个device, 注意了,这个device 和咱们一直讲的device 和driver 那里的
device 是不一样的.因为一个usb device 实际上指的是一种宏观上的概念,它可以是一种多功能的设备,
改革开放之后,多功能的东西越来越多了,比如外企常见的多功能一体机,就是集打印机,复印机,扫描仪,传
真机于一体的设备, 当然,这不属于usb 设备,但是usb 设备当然也有这种情况,比如电台DJ 可能会用到的,
一个键盘,上边带一个扬声器,它们用两个usb 接口接到usb hub 上去,而device 描述符描述的就是这整个
设备的特点.那么configuration 描述符呢,老实说,对我们了解U 盘驱动真是没有什么意义,但是作为一个
有责任心的男人,此刻,我必须为它多说几句,虽然只是很简单的说几句.一个设备可以有一种或者几种配置,
这能理解吧?没见过具体的usb 设备?那么好,手机见过吧,每个手机都会有多种配置,或者说"设定",比如,我
的这款,Nokia6300, 手机语言,可以设定为English, 繁体中文,简体中文,一旦选择了其中一种,那么手机里
边所显示的所有的信息都是该种语言/字体.还有最简单的例子,操作模式也有好几种,标准,无声,会议,etc.
基本上如果我设为"会议",那么就是只振动不发声,要是设为无声,那么就啥动静也不会有,只能凭感觉了,以
前去公司面试的话通常就是设为无声,因为觉得振动也不好,让人家面试官听到了还是不合适.那么usb 设备
的配置也是如此,不同的usb 设备当然有不同的配置了,或者说需要配置哪些东西也会不一样.好了,关于配
置,就说这么多,更多的我们暂时也不需要了解了.
对于usb 设备驱动程序编写者来说,更为关键的是下面两个,interface 和endpoint. 先说,interface. 第一
句,一个interface 对应一个usb 设备驱动程序.没错,还说前边那个例子,一个usb 设备,两种功能,一个键盘,
上面带一个扬声器,两个接口,那这样肯定得要两个驱动程序,一个是键盘驱动程序,一个是音频流驱动程序.
道上的兄弟喜欢把这样两个整合在一起的东西叫做一个设备,那好,让他们去叫吧,我门用interface 来区分
这两者行了吧.于是有了我们前面提到的那个数据结构,struct usb_interface. 它定义于
include/linux/usb.h:
71 /**
72 * struct usb_interface - what usb device drivers talk to
73 * @altsetting: array of interface structures, one for each alternate
74 * setting that may be selected. Each one includes a set of
75 * endpoint configurations. They will be in no particular order.
76 * @num_altsetting: number of altsettings defined.
77 * @cur_altsetting: the current altsetting.
78 * @driver: the USB driver that is bound to this interface.
79 * @minor: the minor number assigned to this interface, if this
80 * interface is bound to a driver that uses the USB major number.
81 * If this interface does not use the USB major, this field should
82 * be unused. The driver should set this value in the probe()
83 * function of the driver, after it has been assigned a minor
84 * number from the USB core by calling usb_register_dev().
85 * @condition: binding state of the interface: not bound, binding
86 * (in probe()), bound to a driver, or unbinding (in disconnect())
87 * @dev: driver model's view of this device |
|