// SPDX-License-Identifier: GPL-2.0 /***************************************************************************** * USBLCD Kernel Driver * * Version 1.05 * * (C) 2005 Georges Toth <g.toth@e-biz.lu> * * * * This file is licensed under the GPL. See COPYING in the package. * * Based on usb-skeleton.c 2.0 by Greg Kroah-Hartman (greg@kroah.com) * * * * * * 28.02.05 Complete rewrite of the original usblcd.c driver, * * based on usb_skeleton.c. * * This new driver allows more than one USB-LCD to be connected * * and controlled, at once *
*****************************************************************************/ #include <linux/module.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/mutex.h> #include <linux/rwsem.h> #include <linux/uaccess.h> #include <linux/usb.h>
#define DRIVER_VERSION "USBLCD Driver Version 1.05"
struct usb_lcd { struct usb_device *udev; /* init: probe_lcd */ struct usb_interface *interface; /* the interface for
this device */ unsignedchar *bulk_in_buffer; /* the buffer to receive
data */
size_t bulk_in_size; /* the size of the
receive buffer */
__u8 bulk_in_endpointAddr; /* the address of the
bulk in endpoint */
__u8 bulk_out_endpointAddr; /* the address of the
bulk out endpoint */ struct kref kref; struct semaphore limit_sem; /* to stop writes at full throttle from
using up all RAM */ struct usb_anchor submitted; /* URBs to wait for
before suspend */ struct rw_semaphore io_rwsem; unsignedlong disconnected:1;
}; #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref)
if (dev->disconnected) {
retval = -ENODEV; goto out_up_io;
}
/* do a blocking bulk read to get data from the device */
retval = usb_bulk_msg(dev->udev,
usb_rcvbulkpipe(dev->udev,
dev->bulk_in_endpointAddr),
dev->bulk_in_buffer,
min(dev->bulk_in_size, count),
&bytes_read, 10000);
/* if the read was successful, copy the data to userspace */ if (!retval) { if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read))
retval = -EFAULT; else
retval = bytes_read;
}
/* verify that we actually have some data to write */ if (count == 0) gotoexit;
r = down_interruptible(&dev->limit_sem); if (r < 0) return -EINTR;
down_read(&dev->io_rwsem);
if (dev->disconnected) {
retval = -ENODEV; goto err_up_io;
}
/* create a urb, and a buffer for it, and copy the data to the urb */
urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) {
retval = -ENOMEM; goto err_up_io;
}
/* send the data out the bulk port */
retval = usb_submit_urb(urb, GFP_KERNEL); if (retval) {
dev_err(&dev->udev->dev, "%s - failed submitting write urb, error %d\n",
__func__, retval); goto error_unanchor;
}
/* release our reference to this urb,
the USB core will eventually free it entirely */
usb_free_urb(urb);
/* * 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
*/ staticstruct usb_class_driver lcd_class = {
.name = "lcd%d",
.fops = &lcd_fops,
.minor_base = USBLCD_MINOR,
};
if (le16_to_cpu(dev->udev->descriptor.idProduct) != 0x0001) {
dev_warn(&interface->dev, "USBLCD model not supported.\n");
retval = -ENODEV; goto error;
}
/* 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;
}
/* save our data pointer in this interface device */
usb_set_intfdata(interface, dev);
/* we can register the device now, as it is ready */
retval = usb_register_dev(interface, &lcd_class); if (retval) { /* something prevented us from registering this driver */
dev_err(&interface->dev, "Not able to get a minor for this device.\n"); goto error;
}
i = le16_to_cpu(dev->udev->descriptor.bcdDevice);
dev_info(&interface->dev, "USBLCD Version %1d%1d.%1d%1d found " "at address %d\n", (i & 0xF000)>>12, (i & 0xF00)>>8,
(i & 0xF0)>>4, (i & 0xF), dev->udev->devnum);
/* let the user know what node this device is now attached to */
dev_info(&interface->dev, "USB LCD device now attached to USBLCD-%d\n",
interface->minor); return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.