Chinaunix首页 | 论坛 | 博客
  • 博客访问: 216822
  • 博文数量: 32
  • 博客积分: 410
  • 博客等级: 一等列兵
  • 技术积分: 396
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-03 16:58
文章分类

全部博文(32)

文章存档

2013年(17)

2012年(15)

我的朋友

分类: LINUX

2013-04-16 11:01:40

linux的usb hubusb hub的设备驱动

       hub的设备出生后,就要找驱动;哪里找呢?看关键字<usb_device_type,for_devices>
看代码很多后,才发现,所谓usb驱动分为接口驱动和设备驱动,大多时候,网友口口相传驱动都指定为接口驱动;而我们这里讲的是设备驱动,据我对代码的查看,在usb hub驱动时找到一例;至于其他地方,我们不要去理会了,少则得,多则惑;

     后来,我界定,这种驱动还只是属于设备创建的一部分,它只是创建接口设备;
代码的起始点:retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);


点击(此处)折叠或打开

  1. struct usb_device_driver usb_generic_driver = {
  2.     .name = "usb",
  3.     .probe = generic_probe,
  4.     .disconnect = generic_disconnect,
  5. #ifdef CONFIG_PM
  6.     .suspend = generic_suspend,
  7.     .resume = generic_resume,
  8. #endif
  9.     .supports_autosuspend = 1,
  10. }

点击(此处)折叠或打开

  1. /**
  2.  * usb_register_device_driver - register a USB device (not interface) driver
  3.  * @new_udriver: USB operations for the device driver
  4.  * @owner: module owner of this driver.
  5.  *
  6.  * Registers a USB device driver with the USB core. The list of
  7.  * unattached devices will be rescanned whenever a new driver is
  8.  * added, allowing the new driver to attach to any recognized devices.
  9.  * Returns a negative error code on failure and 0 on success.
  10.  */
  11. int usb_register_device_driver(struct usb_device_driver *new_udriver,
  12.         struct module *owner)
  13. {
  14.     int retval = 0;

  15.     if (usb_disabled())
  16.         return -ENODEV;
  17. //对devices;主要是Mark一下,引起注意;
  18. //在总线匹配中,区分接口设备和usb设备<usb_device_type,>
  19.     new_udriver->drvwrap.for_devices = 1;
  20.     new_udriver->drvwrap.driver.name = (char *) new_udriver->name;
  21.     new_udriver->drvwrap.driver.bus = &usb_bus_type;//所属总线;
  22.     new_udriver->drvwrap.driver.probe = usb_probe_device;
  23.     new_udriver->drvwrap.driver.remove = usb_unbind_device;
  24.     new_udriver->drvwrap.driver.owner = owner;
  25. //通用设备驱动的注册
  26.     retval = driver_register(&new_udriver->drvwrap.driver);

  27.     if (!retval) {
  28.         pr_info("%s: registered new device driver %s\n",
  29.             usbcore_name, new_udriver->name);
  30.         usbfs_update_special();
  31.     } else {
  32.         printk(KERN_ERR "%s: error %d registering device "
  33.             " driver %s\n",
  34.             usbcore_name, retval, new_udriver->name);
  35.     }

  36.     return retval;
  37. }


      上面就是usb设备类型的驱动,只要是满足{usb_device_type,for_devices==1}的设备,都会来找他配对;然后生出{usb_if_device_type,for_devices==0}这样的设备;
usb_device_type,usb_if_device_type为usb设备的类型,用来总线匹配驱动。for_devices是驱动中设置,用来总线匹配匹配。
需要牢记一点,出生的设备最新还是需要在那根红线usb_bus_type上仔细找usb_device_match驱动usb_generic_driver;


     下一篇,就是讲usb_device_type设备的驱动匹配和函数调用;
阅读(1615) | 评论(0) | 转发(0) |
0

上一篇:usb hub

下一篇:usb hub 3 驱动的匹配:

给主人留下些什么吧!~~