关闭

Linux USB subsystem --- register generic usb driver

1636人阅读 评论(0) 收藏 举报

目的:对USB作深入学习,在此留下笔记。欢迎讨论。

[Linux 3.2] [driver/usb/core/driver.c]

函数:usb_register_device_driver


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

	if (usb_disabled())
		return -ENODEV;

	new_udriver->drvwrap.for_devices = 1;
	new_udriver->drvwrap.driver.name = (char *) new_udriver->name;
	new_udriver->drvwrap.driver.bus = &usb_bus_type;
	new_udriver->drvwrap.driver.probe = usb_probe_device;
	new_udriver->drvwrap.driver.remove = usb_unbind_device;
	new_udriver->drvwrap.driver.owner = owner;

	retval = driver_register(&new_udriver->drvwrap.driver);

	if (!retval) {
		pr_info("%s: registered new device driver %s\n",
			usbcore_name, new_udriver->name);
		usbfs_update_special();
	} else {
		printk(KERN_ERR "%s: error %d registering device "
			"	driver %s\n",
			usbcore_name, retval, new_udriver->name);
	}

	return retval;
}
EXPORT_SYMBOL_GPL(usb_register_device_driver);

此过程是注册一个usb的通用程驱动。驱动注册的过程与usbfs驱动注册类似。其结果是:在/sys/bus/usb/drivers/下面创建usb目录。在usb目录下面创建如下属性文件。

bind  uevent  unbind


至此,整个usb core的初始化过程完成。

后面将进入到USB host controller的初始化。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:397613次
    • 积分:5402
    • 等级:
    • 排名:第5147名
    • 原创:132篇
    • 转载:17篇
    • 译文:7篇
    • 评论:57条
    博客专栏
    最新评论