Linux USB subsystem --- register generic usb driver

目的:对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的初始化。

阅读更多
个人分类: Linux USB subsystem
所属专栏: Linux USB subsystem
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Linux USB subsystem --- register generic usb driver

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭