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"
36 int err = -ENODEV; in usb_open()
46 /* Curiouser and curiouser... NULL ->open() as "no device" ? */ in usb_open()
47 if (file->f_op->open) in usb_open()
48 err = file->f_op->open(inode, file); in usb_open()
70 if (!drv || !drv->devnode) in usb_devnode()
72 return drv->devnode(dev, mode); in usb_devnode()
80 kref_get(&usb_class->kref); in init_usb_class()
86 result = -ENOMEM; in init_usb_class()
90 kref_init(&usb_class->kref); in init_usb_class()
91 usb_class->class = class_create(THIS_MODULE, "usbmisc"); in init_usb_class()
92 if (IS_ERR(usb_class->class)) { in init_usb_class()
93 result = PTR_ERR(usb_class->class); in init_usb_class()
94 printk(KERN_ERR "class_create failed for usb devices\n"); in init_usb_class()
99 usb_class->class->devnode = usb_devnode; in init_usb_class()
108 class_destroy(usb_class->class); in release_usb_class()
116 kref_put(&usb_class->kref, release_usb_class); in destroy_usb_class()
124 error = register_chrdev(USB_MAJOR, "usb", &usb_fops); in usb_major_init()
126 printk(KERN_ERR "Unable to get major %d for usb devices\n", in usb_major_init()
134 unregister_chrdev(USB_MAJOR, "usb"); in usb_major_cleanup()
138 * usb_register_dev - register a USB device, and ask for a minor number
142 * This should be called by all USB drivers that use the USB major number.
146 * starting at the class_driver->minor_base.
148 * This function also creates a usb class device in the sysfs tree.
153 * Return: -EINVAL if something bad happens with trying to register a
160 int minor_base = class_driver->minor_base; in usb_register_dev()
173 if (class_driver->fops == NULL) in usb_register_dev()
174 return -EINVAL; in usb_register_dev()
175 if (intf->minor >= 0) in usb_register_dev()
176 return -EADDRINUSE; in usb_register_dev()
185 dev_dbg(&intf->dev, "looking for a minor, starting at %d\n", minor_base); in usb_register_dev()
192 usb_minors[minor] = class_driver->fops; in usb_register_dev()
193 intf->minor = minor; in usb_register_dev()
196 if (intf->minor < 0) { in usb_register_dev()
198 return -EXFULL; in usb_register_dev()
201 /* create a usb class device for this usb interface */ in usb_register_dev()
202 snprintf(name, sizeof(name), class_driver->name, minor - minor_base); in usb_register_dev()
203 intf->usb_dev = device_create(usb_class->class, &intf->dev, in usb_register_dev()
206 if (IS_ERR(intf->usb_dev)) { in usb_register_dev()
208 intf->minor = -1; in usb_register_dev()
209 retval = PTR_ERR(intf->usb_dev); in usb_register_dev()
217 * usb_deregister_dev - deregister a USB device's dynamic minor.
222 * when the USB driver is finished with the minor numbers gotten from a
226 * This function also removes the usb class device from the sysfs tree.
228 * This should be called by all drivers that use the USB major number.
233 if (intf->minor == -1) in usb_deregister_dev()
236 dev_dbg(&intf->dev, "removing %d minor\n", intf->minor); in usb_deregister_dev()
237 device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); in usb_deregister_dev()
240 usb_minors[intf->minor] = NULL; in usb_deregister_dev()
243 intf->usb_dev = NULL; in usb_deregister_dev()
244 intf->minor = -1; in usb_deregister_dev()