15 #include <linux/module.h>
16 #include <linux/kernel.h>
18 #include <linux/slab.h>
19 #include <linux/errno.h>
24 #define DRIVER_VERSION "USBLCD Driver Version 1.05"
26 #define USBLCD_MINOR 144
28 #define IOCTL_GET_HARD_VERSION 1
29 #define IOCTL_GET_DRV_VERSION 2
61 #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref)
63 #define USB_LCD_CONCURRENT_WRITES 5
65 static struct usb_driver lcd_driver;
68 static void lcd_delete(
struct kref *
kref)
85 subminor = iminor(inode);
90 printk(
KERN_ERR "USBLCD: %s - error, can't find device for minor %d\n",
96 dev = usb_get_intfdata(interface);
104 kref_get(&dev->
kref);
108 r = usb_autopm_get_interface(interface);
110 kref_put(&dev->
kref, lcd_delete);
122 static int lcd_release(
struct inode *inode,
struct file *file)
131 usb_autopm_put_interface(dev->
interface);
132 kref_put(&dev->
kref, lcd_delete);
136 static ssize_t lcd_read(
struct file *file,
char __user *
buffer,
137 size_t count, loff_t *ppos)
147 usb_rcvbulkpipe(dev->
udev,
164 static long lcd_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
179 (bcdDevice & 0xF000)>>12,
180 (bcdDevice & 0xF00)>>8,
181 (bcdDevice & 0xF0)>>4,
200 static void lcd_write_bulk_callback(
struct urb *
urb)
213 "nonzero write bulk status received: %d\n", status);
218 urb->transfer_buffer, urb->transfer_dma);
222 static ssize_t lcd_write(
struct file *file,
const char __user * user_buffer,
223 size_t count, loff_t *ppos)
227 struct urb *urb =
NULL;
260 usb_fill_bulk_urb(urb, dev->
udev,
261 usb_sndbulkpipe(dev->
udev,
263 buf, count, lcd_write_bulk_callback, dev);
264 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
272 "%s - failed submitting write urb, error %d\n",
298 .unlocked_ioctl = lcd_ioctl,
299 .release = lcd_release,
307 static struct usb_class_driver lcd_class = {
317 struct usb_host_interface *iface_desc;
326 dev_err(&interface->dev,
"Out of memory\n");
329 kref_init(&dev->
kref);
337 dev_warn(&interface->dev,
"USBLCD model not supported.\n");
344 iface_desc = interface->cur_altsetting;
345 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++
i) {
346 endpoint = &iface_desc->endpoint[
i].desc;
349 usb_endpoint_is_bulk_in(endpoint)) {
351 buffer_size = usb_endpoint_maxp(endpoint);
357 "Could not allocate bulk_in_buffer\n");
363 usb_endpoint_is_bulk_out(endpoint)) {
370 "Could not find both bulk-in and bulk-out endpoints\n");
375 usb_set_intfdata(interface, dev);
382 "Not able to get a minor for this device.\n");
383 usb_set_intfdata(interface,
NULL);
389 dev_info(&interface->dev,
"USBLCD Version %1d%1d.%1d%1d found "
390 "at address %d\n", (i & 0xF000)>>12, (i & 0xF00)>>8,
391 (i & 0xF0)>>4, (i & 0xF), dev->
udev->devnum);
394 dev_info(&interface->dev,
"USB LCD device now attached to USBLCD-%d\n",
400 kref_put(&dev->
kref, lcd_delete);
404 static void lcd_draw_down(
struct usb_lcd *dev)
415 struct usb_lcd *dev = usb_get_intfdata(intf);
431 int minor = interface->minor;
434 dev = usb_get_intfdata(interface);
435 usb_set_intfdata(interface,
NULL);
442 kref_put(&dev->
kref, lcd_delete);
444 dev_info(&interface->dev,
"USB LCD #%d now disconnected\n", minor);
447 static struct usb_driver lcd_driver = {
450 .disconnect = lcd_disconnect,
451 .suspend = lcd_suspend,
452 .resume = lcd_resume,
453 .id_table = id_table,
454 .supports_autosuspend = 1,