Chinaunix首页 | 论坛 | 博客
  • 博客访问: 139475
  • 博文数量: 41
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 307
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-15 18:48
文章分类

全部博文(41)

文章存档

2015年(5)

2014年(23)

2013年(13)

我的朋友

分类: LINUX

2014-01-08 10:01:29

每个usb设备,都可能会有多个接口,每个接口都实现了一个功能。
在linux上,每个usb设备是一个device,而每个接口也同样是一个device。
所有的usb设备的所对应的驱动是同一个驱动

struct usb_device_driver usb_generic_driver = {
.name = "usb",
.probe = generic_probe,
.disconnect = generic_disconnect,
#ifdef CONFIG_PM
.suspend = generic_suspend,
.resume = generic_resume,
#endif
.supports_autosuspend = 1,
};

但是每一个接口所对应的驱动则是单独的驱动。
我们看一下usb设备和usb接口的定义。如下:
struct usb_device {
int devnum;
char devpath[16];
u32 route;
enum usb_device_state state;
enum usb_device_speed speed;

struct usb_tt *tt;
int ttport;

unsigned int toggle[2];

struct usb_device *parent;
struct usb_bus *bus;
struct usb_host_endpoint ep0;

struct device dev;

struct usb_device_descriptor descriptor;
struct usb_host_config *config;

struct usb_host_config *actconfig;
struct usb_host_endpoint *ep_in[16];
struct usb_host_endpoint *ep_out[16];

char **rawdescriptors;

unsigned short bus_mA;
u8 portnum;
u8 level;

unsigned can_submit:1;
unsigned persist_enabled:1;
unsigned have_langid:1;
unsigned authorized:1;
unsigned authenticated:1;
unsigned wusb:1;
int string_langid;

/* static strings from the device */
char *product;
char *manufacturer;
char *serial;

struct list_head filelist;
#ifdef CONFIG_USB_DEVICE_CLASS
struct device *usb_classdev;
#endif
#ifdef CONFIG_USB_DEVICEFS
struct dentry *usbfs_dentry;
#endif

int maxchild;
struct usb_device *children[USB_MAXCHILDREN];

u32 quirks;
atomic_t urbnum;

unsigned long active_duration;

#ifdef CONFIG_PM
unsigned long last_busy;
int autosuspend_delay;
unsigned long connect_time;

unsigned do_remote_wakeup:1;
unsigned reset_resume:1;
#endif
struct wusb_dev *wusb_dev;
int slot_id;
};

struct usb_interface {
/* array of alternate settings for this interface,
* stored in no particular order */
struct usb_host_interface *altsetting;

struct usb_host_interface *cur_altsetting; /* the currently
* active alternate setting */
unsigned num_altsetting; /* number of alternate settings */

/* If there is an interface association descriptor then it will list
* the associated interfaces */
struct usb_interface_assoc_descriptor *intf_assoc;

int minor; /* minor number this interface is
* bound to */
enum usb_interface_condition condition; /* state of binding */
unsigned sysfs_files_created:1; /* the sysfs attributes exist */
unsigned ep_devs_created:1; /* endpoint "devices" exist */
unsigned unregistering:1; /* unregistration is in progress */
unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */
unsigned needs_altsetting0:1; /* switch to altsetting 0 is pending */
unsigned needs_binding:1; /* needs delayed unbind/rebind */
unsigned reset_running:1;
unsigned resetting_device:1; /* true: bandwidth alloc after reset */

struct device dev; /* interface specific device info */
struct device *usb_dev;
atomic_t pm_usage_cnt; /* usage counter for autosuspend */
struct work_struct reset_ws; /* for resets in atomic context */
};

我们可以看到,这两个定义里都有struct device。
不管是USB设备还是USB接口,都会被注册到同一个bus上,也就是usb_bus_type,其之间的区别会在match函数中区分,之后再去绑定不同的driver。
当一个USB设备被插入的时候,USB设备驱动,也就是usb_generic_driver会跟USB设备交互,得到其所有的各种描述符,并为每个接口都定义成为一个device,之后再加载到usb_bus上,让其去匹配其对应的接口驱动程序。
阅读(971) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~