打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
linux usb 设备驱动和接口驱动
http://blog.chinaunix.net/uid-9185047-id-445204.html
2011-04-11

每个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上,让其去匹配其对应的接口驱动程序。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Linux设备驱动程序学习(17)-USB 驱动程序(二)
USB驱动程序笔记
Linux下USB内核之学习笔记
Linux USB gadget设备驱动解析(3)-- 驱动结构分析—嵌入式学院(华清远见旗下品牌)
USB设备驱动开发-USB Gadget Driver(1)
Linux I2C驱动(1)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服