Chinaunix首页 | 论坛 | 博客
  • 博客访问: 177868
  • 博文数量: 34
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 374
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-30 10:46
文章分类

全部博文(34)

文章存档

2018年(5)

2015年(13)

2014年(13)

2013年(3)

我的朋友

分类: 嵌入式

2015-06-15 09:45:23

Linux设备模型中的总线落实在USB子系统里就是usb_bus_type
    在文件 
drivers\usb\core\driver.c 中定义,
    在文件 drivers\usb\core\usb.c 的 usb_init() 函数中注册。 

struct bus_type usb_bus_type = {
.name = "usb",
.match = usb_device_match,
.uevent = usb_uevent,
};

bus_type 这里比较重要的元素match ,从字面意思理解及是 匹配,匹配么我们就要看挂接函数:usb_device_match()
// 函数原型  drivers\usb\core\driver.c

static int usb_device_match(struct device *dev, struct device_driver *drv)
{
/* devices and interfaces are handled separately */
if (is_usb_device(dev)) {
   /* interface drivers never match devices */
   if (!is_usb_device_driver(drv))
   return 0;

   /* TODO: Add real matching code */
   return 1;
} else if (is_usb_interface(dev)) {
    struct usb_interface *intf;
    struct usb_driver *usb_drv;
    const struct usb_device_id *id;

   /* device drivers never match interfaces */
   if (is_usb_device_driver(drv))
   return 0;

   intf = to_usb_interface(dev);
   usb_drv = to_usb_driver(drv);

    id = usb_match_id(intf, usb_drv->id_table);
    if (id)
    return 1;

    id = usb_match_dynamic_id(intf, usb_drv);
    if (id)
    return 1;
}
    return 0;
}
由usb_device_match可知 此处匹配的两个分支if else,这里引入的三个概念:usb device,usb device_driver, usb_interface.
直观上我们需要 usb_device 和usb_device_driver 匹配上,而usb_interface 需要另一种匹配,方式。因此我们的驱动匹配走的是if分支。
至于usb_interface的概念 暂且不提。

阅读(2521) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~