drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c

Source file repositories/reference/linux-study-clean/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c

File Facts

System
Linux kernel
Corpus path
drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
Extension
.c
Size
50290 bytes
Lines
2023
Domain
Driver Families
Bucket
drivers/gpib
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations lpvo_fops = {
	.owner =	THIS_MODULE,
#if USER_DEVICE
	.read =	   lpvo_read,
	.write =   lpvo_write,
	.open =	   lpvo_open,
	.release = lpvo_release,
	.flush =   lpvo_flush,
	.llseek =  noop_llseek,
#endif
};

/*
 * usb class driver info in order to get a minor number from the usb core,
 * and to have the device registered with the driver core
 */
#if USER_DEVICE
static struct usb_class_driver lpvo_class = {
	.name =		       "lpvo_raw%d",
	.fops =		       &lpvo_fops,
	.minor_base =	     USB_LPVO_MINOR_BASE,
};
#endif

static int lpvo_probe(struct usb_interface *interface,
		      const struct usb_device_id *id)
{
	struct lpvo *dev;
	struct usb_endpoint_descriptor *bulk_in, *bulk_out;
	int retval;
	char *device_path;

	mutex_init(&minors_lock);   /* required for handling minor numbers table */

	/* allocate memory for our device state and initialize it */
	dev = kzalloc_obj(*dev);
	if (!dev)
		return -ENOMEM;

	kref_init(&dev->kref);
	sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
	mutex_init(&dev->io_mutex);
	spin_lock_init(&dev->err_lock);
	init_usb_anchor(&dev->submitted);
	init_waitqueue_head(&dev->bulk_in_wait);

	dev->udev = usb_get_dev(interface_to_usbdev(interface));
	dev->interface = interface;

	/* set up the endpoint information */
	/* use only the first bulk-in and bulk-out endpoints */
	retval = usb_find_common_endpoints(interface->cur_altsetting,
					   &bulk_in, &bulk_out, NULL, NULL);
	if (retval) {
		dev_err(&interface->dev,
			"Could not find both bulk-in and bulk-out endpoints\n");
		goto error;
	}

	dev->bulk_in_size = usb_endpoint_maxp(bulk_in);
	dev->bulk_in_endpoint_addr = bulk_in->bEndpointAddress;
	dev->bulk_in_buffer = kmalloc(dev->bulk_in_size, GFP_KERNEL);
	if (!dev->bulk_in_buffer) {
		retval = -ENOMEM;
		goto error;
	}
	dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!dev->bulk_in_urb) {
		retval = -ENOMEM;
		goto error;
	}

	dev->bulk_out_endpoint_addr = bulk_out->bEndpointAddress;

	/* save our data pointer in this interface device */
	usb_set_intfdata(interface, dev);

	/* let the world know */

	device_path = kobject_get_path(&dev->udev->dev.kobj, GFP_KERNEL);
	dev_dbg(&interface->dev, "New lpvo_usb_device -> bus: %d  dev: %d  path: %s\n",
		dev->udev->bus->busnum, dev->udev->devnum, device_path);
	kfree(device_path);

#if USER_DEVICE
	/* we can register the device now, as it is ready */
	retval = usb_register_dev(interface, &lpvo_class);
	if (retval) {
		/* something prevented us from registering this driver */
		dev_err(&interface->dev,

Annotation

Implementation Notes