Lines Matching +full:usb +full:- +full:c

1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/usb/core/file.c
5 * (C) Copyright Linus Torvalds 1999
6 * (C) Copyright Johannes Erdfelt 1999-2001
7 * (C) Copyright Andreas Gal 1999
8 * (C) Copyright Gregory P. Smith 1999
9 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
10 * (C) Copyright Randy Dunlap 2000
11 * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id,
13 * (C) Copyright Yggdrasil Computing, Inc. 2000
15 * (C) Copyright Greg Kroah-Hartman 2002-2003
25 #include <linux/usb.h>
27 #include "usb.h"
35 int err = -ENODEV; in usb_open()
45 /* Curiouser and curiouser... NULL ->open() as "no device" ? */ in usb_open()
46 if (file->f_op->open) in usb_open()
47 err = file->f_op->open(inode, file); in usb_open()
64 if (!drv || !drv->devnode) in usb_devnode()
66 return drv->devnode(dev, mode); in usb_devnode()
78 error = register_chrdev(USB_MAJOR, "usb", &usb_fops); in usb_major_init()
80 printk(KERN_ERR "Unable to get major %d for usb devices\n", in usb_major_init()
88 unregister_chrdev(USB_MAJOR, "usb"); in usb_major_cleanup()
92 * usb_register_dev - register a USB device, and ask for a minor number
96 * This should be called by all USB drivers that use the USB major number.
100 * starting at the class_driver->minor_base.
102 * This function also creates a usb class device in the sysfs tree.
107 * Return: -EINVAL if something bad happens with trying to register a
114 int minor_base = class_driver->minor_base; in usb_register_dev()
127 if (class_driver->fops == NULL) in usb_register_dev()
128 return -EINVAL; in usb_register_dev()
129 if (intf->minor >= 0) in usb_register_dev()
130 return -EADDRINUSE; in usb_register_dev()
132 dev_dbg(&intf->dev, "looking for a minor, starting at %d\n", minor_base); in usb_register_dev()
139 usb_minors[minor] = class_driver->fops; in usb_register_dev()
140 intf->minor = minor; in usb_register_dev()
143 if (intf->minor < 0) { in usb_register_dev()
145 return -EXFULL; in usb_register_dev()
148 /* create a usb class device for this usb interface */ in usb_register_dev()
149 snprintf(name, sizeof(name), class_driver->name, minor - minor_base); in usb_register_dev()
150 intf->usb_dev = device_create(&usbmisc_class, &intf->dev, in usb_register_dev()
153 if (IS_ERR(intf->usb_dev)) { in usb_register_dev()
155 intf->minor = -1; in usb_register_dev()
156 retval = PTR_ERR(intf->usb_dev); in usb_register_dev()
164 * usb_deregister_dev - deregister a USB device's dynamic minor.
169 * when the USB driver is finished with the minor numbers gotten from a
173 * This function also removes the usb class device from the sysfs tree.
175 * This should be called by all drivers that use the USB major number.
180 if (intf->minor == -1) in usb_deregister_dev()
183 dev_dbg(&intf->dev, "removing %d minor\n", intf->minor); in usb_deregister_dev()
184 device_destroy(&usbmisc_class, MKDEV(USB_MAJOR, intf->minor)); in usb_deregister_dev()
187 usb_minors[intf->minor] = NULL; in usb_deregister_dev()
190 intf->usb_dev = NULL; in usb_deregister_dev()
191 intf->minor = -1; in usb_deregister_dev()