Chinaunix首页 | 论坛 | 博客
  • 博客访问: 404506
  • 博文数量: 42
  • 博客积分: 1030
  • 博客等级: 准尉
  • 技术积分: 816
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-06 17:16
文章分类

全部博文(42)

文章存档

2013年(1)

2012年(41)

分类: LINUX

2012-02-23 15:23:21

当USB设备被正确识别,并加载相关驱动,驱动程序的probe函数就会被调用,USB的probe函数对应struct usb_driver中的probe函数指针,在该函数中完成相关的初始化,固件加载等相关工作。该函数的原型为:

int (*probe)(struct usb_interface *intf, const struct usb_device_id *id)

intf对应当前USB接口的Interface,id对应该与该USB设备匹配的struct usb_device_id 即之前的定义的cy68013_table[0]

在probe函数中完成的工作有:

  • 初始化驱动的相关的数据元素,锁,互斥量等;
  • 更改USB接口的相关设置,获取接口的相关端点信息等;
  • 如果USB设备有固件程序,通过USB接口加载相关的设备固件;
  • 调用usb_set_intfdata函数保存该接口的到驱动的私有结构体中,供以后使用;
  • 调用usb_register_dev函数注册USB设备(只有USB设备不隶属于任何一种类作为字符设备使用的时候才用该函数)
使用usb_register_dev函数需要定义一个struct usb_class_driver 结构提供相关的信息给USB core:

  • char *name 设备的名称,该名称将出现在sysfs文件系统中;
  • struct file_operations *fops 字符设备的函数操作指针;
  • int minor_base 设备驱动的次编号,当作为字符设备的时候主编号固定为180
  1. 711 /*
  2. 712 * usb class driver info in order to get a minor number from the usb core,
  3. 713 * and to have the device registered with the driver core
  4. 714 */
  5. 715 static struct usb_class_driver cy68013_class = {
  6. 716 .name = "cy68013",
  7. 717 .fops = &cy68013_fops,
  8. 718 .minor_base = USB_CY68013_MINOR_BASE,
  9. 719 };
阅读(6359) | 评论(0) | 转发(3) |
给主人留下些什么吧!~~