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

全部博文(32)

文章存档

2013年(17)

2012年(15)

我的朋友

分类: LINUX

2013-02-04 21:06:21

//注册usb驱动

/**
 * usb_register_driver - register a USB interface driver
 * @new_driver: USB operations for the interface driver
 * @owner: module owner of this driver.
 * @mod_name: module name string
 *
 * Registers a USB interface driver with the USB core.  The list of
 * unattached interfaces will be rescanned whenever a new driver is
 * added, allowing the new driver to attach to any recognized interfaces.
 * Returns a negative error code on failure and 0 on success.
 *
 * NOTE: if you want your driver to use the USB major number, you must call
 * usb_register_dev() to enable that functionality.  This function no longer
 * takes care of that.
 */

 
int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
            const char *mod_name)
{
    int retval = 0;

    if (usb_disabled())
        return -ENODEV;
//usb驱动的核心包含一个device_driver;
    new_driver->drvwrap.for_devices = 0;
    new_driver->drvwrap.driver.name = (char *) new_driver->name;
    new_driver->drvwrap.driver.bus = &usb_bus_type;//驱动的总线属性;
    new_driver->drvwrap.driver.probe = usb_probe_interface;
    new_driver->drvwrap.driver.remove = usb_unbind_interface;
    new_driver->drvwrap.driver.owner = owner;
    new_driver->drvwrap.driver.mod_name = mod_name;//模块的名字;
    spin_lock_init(&new_driver->dynids.lock);
    INIT_LIST_HEAD(&new_driver->dynids.list);

    retval = driver_register(&new_driver->drvwrap.driver);//报名(登记驱动)

    if (!retval) {
        pr_info("%s: registered new interface driver %s\n",
            usbcore_name, new_driver->name);
        usbfs_update_special();
        usb_create_newid_file(new_driver);//报名成功留下一个名字之类的东西吧,
    } else {
        printk(KERN_ERR "%s: error %d registering interface "
            "    driver %s\n",
            usbcore_name, retval, new_driver->name);
    }

    return retval;
}


阅读(2542) | 评论(0) | 转发(0) |
1

上一篇:driver_register

下一篇:H264

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